Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1 | /* |
| 2 | * ethtool.c: Linux ethernet device configuration tool. |
| 3 | * |
| 4 | * Copyright (C) 1998 David S. Miller (davem@dm.cobaltmicro.com) |
| 5 | * Portions Copyright 2001 Sun Microsystems |
| 6 | * Kernel 2.4 update Copyright 2001 Jeff Garzik <jgarzik@mandrakesoft.com> |
| 7 | * Wake-on-LAN,natsemi,misc support by Tim Hockin <thockin@sun.com> |
| 8 | * Portions Copyright 2002 Intel |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 9 | * Portions Copyright (C) Sun Microsystems 2008 |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 10 | * do_test support by Eli Kupermann <eli.kupermann@intel.com> |
| 11 | * ETHTOOL_PHYS_ID support by Chris Leech <christopher.leech@intel.com> |
| 12 | * e1000 support by Scott Feldman <scott.feldman@intel.com> |
| 13 | * e100 support by Wen Tao <wen-hwa.tao@intel.com> |
Nicholas Nunley | fb522ac | 2006-09-19 11:27:35 -0700 | [diff] [blame] | 14 | * ixgb support by Nicholas Nunley <Nicholas.d.nunley@intel.com> |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 15 | * amd8111e support by Reeja John <reeja.john@amd.com> |
Andi Kleen | 527a562 | 2005-06-13 21:06:47 +0200 | [diff] [blame] | 16 | * long arguments by Andi Kleen. |
Steve Glendinning | a5f8ce2 | 2007-07-16 20:04:40 +0100 | [diff] [blame] | 17 | * SMSC LAN911x support by Steve Glendinning <steve.glendinning@smsc.com> |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 18 | * Rx Network Flow Control configuration support <santwona.behera@sun.com> |
Ben Hutchings | 65c3763 | 2010-09-23 22:50:12 +0100 | [diff] [blame] | 19 | * Various features by Ben Hutchings <bhutchings@solarflare.com>; |
| 20 | * Copyright 2009, 2010 Solarflare Communications |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 21 | * MDI-X set support by Jesse Brandeburg <jesse.brandeburg@intel.com> |
| 22 | * Copyright 2012 Intel Corporation |
Shrikrishna Khare | 009799a | 2015-09-23 15:19:12 -0700 | [diff] [blame] | 23 | * vmxnet3 support by Shrikrishna Khare <skhare@vmware.com> |
Ben Hutchings | 5b9541d | 2016-06-26 17:27:22 +0200 | [diff] [blame] | 24 | * Various features by Ben Hutchings <ben@decadent.org.uk>; |
| 25 | * Copyright 2008-2010, 2013-2016 Ben Hutchings |
Vidya Sagar Ravipati | 59a0467 | 2016-08-28 23:56:50 -0700 | [diff] [blame] | 26 | * QSFP+/QSFP28 DOM support by Vidya Sagar Ravipati <vidya@cumulusnetworks.com> |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 27 | * |
| 28 | * TODO: |
Ben Hutchings | f3393b2 | 2010-12-15 19:21:07 +0000 | [diff] [blame] | 29 | * * show settings for all devices |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 30 | */ |
| 31 | |
Ben Hutchings | 5ba70c0 | 2011-11-01 16:48:31 +0000 | [diff] [blame] | 32 | #include "internal.h" |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 33 | #include <string.h> |
| 34 | #include <stdlib.h> |
Stephen Hemminger | fd3dc7b | 2006-10-23 10:57:03 -0700 | [diff] [blame] | 35 | #include <sys/stat.h> |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 36 | #include <stdio.h> |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 37 | #include <stddef.h> |
Edward Cree | b56b951 | 2016-03-17 19:17:16 +0000 | [diff] [blame] | 38 | #include <stdbool.h> |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 39 | #include <errno.h> |
Jeff Garzik | a97a2ec | 2009-03-06 06:12:13 -0500 | [diff] [blame] | 40 | #include <sys/utsname.h> |
Jay Fenlason | 35f0808 | 2009-07-17 15:08:41 -0400 | [diff] [blame] | 41 | #include <limits.h> |
Ben Hutchings | 97d0ee2 | 2010-06-25 15:49:45 +0100 | [diff] [blame] | 42 | #include <ctype.h> |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 43 | |
Ben Hutchings | 58fad3a | 2010-07-22 20:11:39 +0100 | [diff] [blame] | 44 | #include <sys/socket.h> |
| 45 | #include <netinet/in.h> |
| 46 | #include <arpa/inet.h> |
| 47 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 48 | #include <linux/sockios.h> |
David Decotigny | 225fdc6 | 2016-06-26 10:52:59 +0200 | [diff] [blame] | 49 | #include <linux/netlink.h> |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 50 | |
Stephen Hemminger | fef1c4a | 2010-11-16 19:14:33 +0000 | [diff] [blame] | 51 | #ifndef MAX_ADDR_LEN |
| 52 | #define MAX_ADDR_LEN 32 |
| 53 | #endif |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 54 | |
Ben Hutchings | 97d0ee2 | 2010-06-25 15:49:45 +0100 | [diff] [blame] | 55 | #ifndef HAVE_NETIF_MSG |
| 56 | enum { |
| 57 | NETIF_MSG_DRV = 0x0001, |
| 58 | NETIF_MSG_PROBE = 0x0002, |
| 59 | NETIF_MSG_LINK = 0x0004, |
| 60 | NETIF_MSG_TIMER = 0x0008, |
| 61 | NETIF_MSG_IFDOWN = 0x0010, |
| 62 | NETIF_MSG_IFUP = 0x0020, |
| 63 | NETIF_MSG_RX_ERR = 0x0040, |
| 64 | NETIF_MSG_TX_ERR = 0x0080, |
| 65 | NETIF_MSG_TX_QUEUED = 0x0100, |
| 66 | NETIF_MSG_INTR = 0x0200, |
| 67 | NETIF_MSG_TX_DONE = 0x0400, |
| 68 | NETIF_MSG_RX_STATUS = 0x0800, |
| 69 | NETIF_MSG_PKTDATA = 0x1000, |
| 70 | NETIF_MSG_HW = 0x2000, |
| 71 | NETIF_MSG_WOL = 0x4000, |
| 72 | }; |
| 73 | #endif |
| 74 | |
David Decotigny | 225fdc6 | 2016-06-26 10:52:59 +0200 | [diff] [blame] | 75 | #ifndef NETLINK_GENERIC |
| 76 | #define NETLINK_GENERIC 16 |
| 77 | #endif |
| 78 | |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 79 | #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) |
| 80 | |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 81 | static void exit_bad_args(void) __attribute__((noreturn)); |
Ben Hutchings | 24d71eb | 2010-06-25 15:48:46 +0100 | [diff] [blame] | 82 | |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 83 | static void exit_bad_args(void) |
| 84 | { |
| 85 | fprintf(stderr, |
| 86 | "ethtool: bad command line argument(s)\n" |
| 87 | "For more information run ethtool -h\n"); |
| 88 | exit(1); |
| 89 | } |
| 90 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 91 | typedef enum { |
| 92 | CMDL_NONE, |
| 93 | CMDL_BOOL, |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 94 | CMDL_S32, |
Ben Hutchings | bec0363 | 2011-06-06 11:35:19 +0100 | [diff] [blame] | 95 | CMDL_U8, |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 96 | CMDL_U16, |
| 97 | CMDL_U32, |
| 98 | CMDL_U64, |
| 99 | CMDL_BE16, |
Ben Hutchings | 58fad3a | 2010-07-22 20:11:39 +0100 | [diff] [blame] | 100 | CMDL_IP4, |
Stephen Hemminger | fd3dc7b | 2006-10-23 10:57:03 -0700 | [diff] [blame] | 101 | CMDL_STR, |
Ben Hutchings | 99a2b6b | 2010-06-25 15:49:19 +0100 | [diff] [blame] | 102 | CMDL_FLAG, |
Ben Hutchings | 9362cee | 2010-09-23 22:49:10 +0100 | [diff] [blame] | 103 | CMDL_MAC, |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 104 | } cmdline_type_t; |
| 105 | |
| 106 | struct cmdline_info { |
| 107 | const char *name; |
| 108 | cmdline_type_t type; |
Ben Hutchings | 9362cee | 2010-09-23 22:49:10 +0100 | [diff] [blame] | 109 | /* Points to int (BOOL), s32, u16, u32 (U32/FLAG/IP4), u64, |
| 110 | * char * (STR) or u8[6] (MAC). For FLAG, the value accumulates |
| 111 | * all flags to be set. */ |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 112 | void *wanted_val; |
| 113 | void *ioctl_val; |
Ben Hutchings | 99a2b6b | 2010-06-25 15:49:19 +0100 | [diff] [blame] | 114 | /* For FLAG, the flag value to be set/cleared */ |
| 115 | u32 flag_val; |
Ben Hutchings | 967cb31 | 2010-09-23 22:48:14 +0100 | [diff] [blame] | 116 | /* For FLAG, points to u32 and accumulates all flags seen. |
| 117 | * For anything else, points to int and is set if the option is |
| 118 | * seen. */ |
| 119 | void *seen_val; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 120 | }; |
| 121 | |
Ben Hutchings | 5ec0d81 | 2011-10-31 22:50:25 +0000 | [diff] [blame] | 122 | struct flag_info { |
| 123 | const char *name; |
| 124 | u32 value; |
| 125 | }; |
| 126 | |
Ben Hutchings | 5ec0d81 | 2011-10-31 22:50:25 +0000 | [diff] [blame] | 127 | static const struct flag_info flags_msglvl[] = { |
| 128 | { "drv", NETIF_MSG_DRV }, |
| 129 | { "probe", NETIF_MSG_PROBE }, |
| 130 | { "link", NETIF_MSG_LINK }, |
| 131 | { "timer", NETIF_MSG_TIMER }, |
| 132 | { "ifdown", NETIF_MSG_IFDOWN }, |
| 133 | { "ifup", NETIF_MSG_IFUP }, |
| 134 | { "rx_err", NETIF_MSG_RX_ERR }, |
| 135 | { "tx_err", NETIF_MSG_TX_ERR }, |
| 136 | { "tx_queued", NETIF_MSG_TX_QUEUED }, |
| 137 | { "intr", NETIF_MSG_INTR }, |
| 138 | { "tx_done", NETIF_MSG_TX_DONE }, |
| 139 | { "rx_status", NETIF_MSG_RX_STATUS }, |
| 140 | { "pktdata", NETIF_MSG_PKTDATA }, |
| 141 | { "hw", NETIF_MSG_HW }, |
| 142 | { "wol", NETIF_MSG_WOL }, |
Ben Hutchings | 97d0ee2 | 2010-06-25 15:49:45 +0100 | [diff] [blame] | 143 | }; |
| 144 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 145 | struct off_flag_def { |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 146 | const char *short_name; |
| 147 | const char *long_name; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 148 | const char *kernel_name; |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 149 | u32 get_cmd, set_cmd; |
| 150 | u32 value; |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 151 | /* For features exposed through ETHTOOL_GFLAGS, the oldest |
| 152 | * kernel version for which we can trust the result. Where |
| 153 | * the flag was added at the same time the kernel started |
| 154 | * supporting the feature, this is 0 (to allow for backports). |
| 155 | * Where the feature was supported before the flag was added, |
| 156 | * it is the version that introduced the flag. |
| 157 | */ |
| 158 | u32 min_kernel_ver; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 159 | }; |
| 160 | static const struct off_flag_def off_flag_def[] = { |
| 161 | { "rx", "rx-checksumming", "rx-checksum", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 162 | ETHTOOL_GRXCSUM, ETHTOOL_SRXCSUM, ETH_FLAG_RXCSUM, 0 }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 163 | { "tx", "tx-checksumming", "tx-checksum-*", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 164 | ETHTOOL_GTXCSUM, ETHTOOL_STXCSUM, ETH_FLAG_TXCSUM, 0 }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 165 | { "sg", "scatter-gather", "tx-scatter-gather*", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 166 | ETHTOOL_GSG, ETHTOOL_SSG, ETH_FLAG_SG, 0 }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 167 | { "tso", "tcp-segmentation-offload", "tx-tcp*-segmentation", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 168 | ETHTOOL_GTSO, ETHTOOL_STSO, ETH_FLAG_TSO, 0 }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 169 | { "ufo", "udp-fragmentation-offload", "tx-udp-fragmentation", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 170 | ETHTOOL_GUFO, ETHTOOL_SUFO, ETH_FLAG_UFO, 0 }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 171 | { "gso", "generic-segmentation-offload", "tx-generic-segmentation", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 172 | ETHTOOL_GGSO, ETHTOOL_SGSO, ETH_FLAG_GSO, 0 }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 173 | { "gro", "generic-receive-offload", "rx-gro", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 174 | ETHTOOL_GGRO, ETHTOOL_SGRO, ETH_FLAG_GRO, 0 }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 175 | { "lro", "large-receive-offload", "rx-lro", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 176 | 0, 0, ETH_FLAG_LRO, |
| 177 | KERNEL_VERSION(2,6,24) }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 178 | { "rxvlan", "rx-vlan-offload", "rx-vlan-hw-parse", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 179 | 0, 0, ETH_FLAG_RXVLAN, |
| 180 | KERNEL_VERSION(2,6,37) }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 181 | { "txvlan", "tx-vlan-offload", "tx-vlan-hw-insert", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 182 | 0, 0, ETH_FLAG_TXVLAN, |
| 183 | KERNEL_VERSION(2,6,37) }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 184 | { "ntuple", "ntuple-filters", "rx-ntuple-filter", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 185 | 0, 0, ETH_FLAG_NTUPLE, 0 }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 186 | { "rxhash", "receive-hashing", "rx-hashing", |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 187 | 0, 0, ETH_FLAG_RXHASH, 0 }, |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 188 | }; |
| 189 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 190 | struct feature_def { |
| 191 | char name[ETH_GSTRING_LEN]; |
| 192 | int off_flag_index; /* index in off_flag_def; negative if none match */ |
| 193 | }; |
| 194 | |
| 195 | struct feature_defs { |
| 196 | size_t n_features; |
| 197 | /* Number of features each offload flag is associated with */ |
| 198 | unsigned int off_flag_matched[ARRAY_SIZE(off_flag_def)]; |
| 199 | /* Name and offload flag index for each feature */ |
| 200 | struct feature_def def[0]; |
| 201 | }; |
| 202 | |
| 203 | #define FEATURE_BITS_TO_BLOCKS(n_bits) DIV_ROUND_UP(n_bits, 32U) |
| 204 | #define FEATURE_WORD(blocks, index, field) ((blocks)[(index) / 32U].field) |
| 205 | #define FEATURE_FIELD_FLAG(index) (1U << (index) % 32U) |
| 206 | #define FEATURE_BIT_SET(blocks, index, field) \ |
| 207 | (FEATURE_WORD(blocks, index, field) |= FEATURE_FIELD_FLAG(index)) |
| 208 | #define FEATURE_BIT_CLEAR(blocks, index, field) \ |
| 209 | (FEATURE_WORD(blocks, index, filed) &= ~FEATURE_FIELD_FLAG(index)) |
| 210 | #define FEATURE_BIT_IS_SET(blocks, index, field) \ |
| 211 | (FEATURE_WORD(blocks, index, field) & FEATURE_FIELD_FLAG(index)) |
| 212 | |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 213 | static long long |
| 214 | get_int_range(char *str, int base, long long min, long long max) |
| 215 | { |
| 216 | long long v; |
| 217 | char *endp; |
| 218 | |
| 219 | if (!str) |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 220 | exit_bad_args(); |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 221 | errno = 0; |
| 222 | v = strtoll(str, &endp, base); |
| 223 | if (errno || *endp || v < min || v > max) |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 224 | exit_bad_args(); |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 225 | return v; |
| 226 | } |
| 227 | |
| 228 | static unsigned long long |
| 229 | get_uint_range(char *str, int base, unsigned long long max) |
| 230 | { |
| 231 | unsigned long long v; |
| 232 | char *endp; |
| 233 | |
| 234 | if (!str) |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 235 | exit_bad_args(); |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 236 | errno = 0; |
| 237 | v = strtoull(str, &endp, base); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 238 | if (errno || *endp || v > max) |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 239 | exit_bad_args(); |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 240 | return v; |
| 241 | } |
| 242 | |
Jay Fenlason | 35f0808 | 2009-07-17 15:08:41 -0400 | [diff] [blame] | 243 | static int get_int(char *str, int base) |
| 244 | { |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 245 | return get_int_range(str, base, INT_MIN, INT_MAX); |
Jay Fenlason | 35f0808 | 2009-07-17 15:08:41 -0400 | [diff] [blame] | 246 | } |
| 247 | |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 248 | static u32 get_u32(char *str, int base) |
| 249 | { |
| 250 | return get_uint_range(str, base, 0xffffffff); |
| 251 | } |
| 252 | |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 253 | static void get_mac_addr(char *src, unsigned char *dest) |
| 254 | { |
| 255 | int count; |
| 256 | int i; |
| 257 | int buf[ETH_ALEN]; |
| 258 | |
| 259 | count = sscanf(src, "%2x:%2x:%2x:%2x:%2x:%2x", |
| 260 | &buf[0], &buf[1], &buf[2], &buf[3], &buf[4], &buf[5]); |
| 261 | if (count != ETH_ALEN) |
| 262 | exit_bad_args(); |
| 263 | |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 264 | for (i = 0; i < count; i++) |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 265 | dest[i] = buf[i]; |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 266 | } |
| 267 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 268 | static int parse_hex_u32_bitmap(const char *s, |
| 269 | unsigned int nbits, u32 *result) |
| 270 | { |
| 271 | const unsigned int nwords = __KERNEL_DIV_ROUND_UP(nbits, 32); |
| 272 | size_t slen = strlen(s); |
| 273 | size_t i; |
| 274 | |
| 275 | /* ignore optional '0x' prefix */ |
| 276 | if ((slen > 2) && (strncasecmp(s, "0x", 2) == 0)) { |
| 277 | slen -= 2; |
| 278 | s += 2; |
| 279 | } |
| 280 | |
| 281 | if (slen > 8 * nwords) /* up to 2 digits per byte */ |
| 282 | return -1; |
| 283 | |
| 284 | memset(result, 0, 4 * nwords); |
| 285 | for (i = 0; i < slen; ++i) { |
| 286 | const unsigned int shift = (slen - 1 - i) * 4; |
| 287 | u32 *dest = &result[shift / 32]; |
| 288 | u32 nibble; |
| 289 | |
| 290 | if ('a' <= s[i] && s[i] <= 'f') |
| 291 | nibble = 0xa + (s[i] - 'a'); |
| 292 | else if ('A' <= s[i] && s[i] <= 'F') |
| 293 | nibble = 0xa + (s[i] - 'A'); |
| 294 | else if ('0' <= s[i] && s[i] <= '9') |
| 295 | nibble = (s[i] - '0'); |
| 296 | else |
| 297 | return -1; |
| 298 | |
| 299 | *dest |= (nibble << (shift % 32)); |
| 300 | } |
| 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 305 | static void parse_generic_cmdline(struct cmd_context *ctx, |
| 306 | int *changed, |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 307 | struct cmdline_info *info, |
| 308 | unsigned int n_info) |
| 309 | { |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 310 | int argc = ctx->argc; |
| 311 | char **argp = ctx->argp; |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 312 | int i, idx; |
Jay Fenlason | 35f0808 | 2009-07-17 15:08:41 -0400 | [diff] [blame] | 313 | int found; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 314 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 315 | for (i = 0; i < argc; i++) { |
Jay Fenlason | 35f0808 | 2009-07-17 15:08:41 -0400 | [diff] [blame] | 316 | found = 0; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 317 | for (idx = 0; idx < n_info; idx++) { |
| 318 | if (!strcmp(info[idx].name, argp[i])) { |
Jay Fenlason | 35f0808 | 2009-07-17 15:08:41 -0400 | [diff] [blame] | 319 | found = 1; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 320 | *changed = 1; |
Ben Hutchings | 967cb31 | 2010-09-23 22:48:14 +0100 | [diff] [blame] | 321 | if (info[idx].type != CMDL_FLAG && |
| 322 | info[idx].seen_val) |
| 323 | *(int *)info[idx].seen_val = 1; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 324 | i += 1; |
| 325 | if (i >= argc) |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 326 | exit_bad_args(); |
Stephen Hemminger | fd3dc7b | 2006-10-23 10:57:03 -0700 | [diff] [blame] | 327 | switch (info[idx].type) { |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 328 | case CMDL_BOOL: { |
| 329 | int *p = info[idx].wanted_val; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 330 | if (!strcmp(argp[i], "on")) |
| 331 | *p = 1; |
| 332 | else if (!strcmp(argp[i], "off")) |
| 333 | *p = 0; |
| 334 | else |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 335 | exit_bad_args(); |
Stephen Hemminger | fd3dc7b | 2006-10-23 10:57:03 -0700 | [diff] [blame] | 336 | break; |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 337 | } |
| 338 | case CMDL_S32: { |
| 339 | s32 *p = info[idx].wanted_val; |
| 340 | *p = get_int_range(argp[i], 0, |
| 341 | -0x80000000LL, |
| 342 | 0x7fffffff); |
Stephen Hemminger | fd3dc7b | 2006-10-23 10:57:03 -0700 | [diff] [blame] | 343 | break; |
| 344 | } |
Ben Hutchings | bec0363 | 2011-06-06 11:35:19 +0100 | [diff] [blame] | 345 | case CMDL_U8: { |
| 346 | u8 *p = info[idx].wanted_val; |
| 347 | *p = get_uint_range(argp[i], 0, 0xff); |
| 348 | break; |
| 349 | } |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 350 | case CMDL_U16: { |
| 351 | u16 *p = info[idx].wanted_val; |
| 352 | *p = get_uint_range(argp[i], 0, 0xffff); |
| 353 | break; |
| 354 | } |
| 355 | case CMDL_U32: { |
| 356 | u32 *p = info[idx].wanted_val; |
| 357 | *p = get_uint_range(argp[i], 0, |
| 358 | 0xffffffff); |
| 359 | break; |
| 360 | } |
| 361 | case CMDL_U64: { |
| 362 | u64 *p = info[idx].wanted_val; |
| 363 | *p = get_uint_range( |
| 364 | argp[i], 0, |
| 365 | 0xffffffffffffffffLL); |
| 366 | break; |
| 367 | } |
| 368 | case CMDL_BE16: { |
| 369 | u16 *p = info[idx].wanted_val; |
| 370 | *p = cpu_to_be16( |
| 371 | get_uint_range(argp[i], 0, |
| 372 | 0xffff)); |
| 373 | break; |
| 374 | } |
Ben Hutchings | 58fad3a | 2010-07-22 20:11:39 +0100 | [diff] [blame] | 375 | case CMDL_IP4: { |
Ben Hutchings | 18caa78 | 2010-06-25 15:46:58 +0100 | [diff] [blame] | 376 | u32 *p = info[idx].wanted_val; |
Ben Hutchings | 58fad3a | 2010-07-22 20:11:39 +0100 | [diff] [blame] | 377 | struct in_addr in; |
| 378 | if (!inet_aton(argp[i], &in)) |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 379 | exit_bad_args(); |
Ben Hutchings | 58fad3a | 2010-07-22 20:11:39 +0100 | [diff] [blame] | 380 | *p = in.s_addr; |
PJ Waskiewicz | e2b0502 | 2009-12-23 23:22:08 -0800 | [diff] [blame] | 381 | break; |
| 382 | } |
Ben Hutchings | 9362cee | 2010-09-23 22:49:10 +0100 | [diff] [blame] | 383 | case CMDL_MAC: |
| 384 | get_mac_addr(argp[i], |
| 385 | info[idx].wanted_val); |
| 386 | break; |
Ben Hutchings | 99a2b6b | 2010-06-25 15:49:19 +0100 | [diff] [blame] | 387 | case CMDL_FLAG: { |
| 388 | u32 *p; |
Ben Hutchings | 967cb31 | 2010-09-23 22:48:14 +0100 | [diff] [blame] | 389 | p = info[idx].seen_val; |
Ben Hutchings | 99a2b6b | 2010-06-25 15:49:19 +0100 | [diff] [blame] | 390 | *p |= info[idx].flag_val; |
Ben Hutchings | 967cb31 | 2010-09-23 22:48:14 +0100 | [diff] [blame] | 391 | if (!strcmp(argp[i], "on")) { |
| 392 | p = info[idx].wanted_val; |
| 393 | *p |= info[idx].flag_val; |
| 394 | } else if (strcmp(argp[i], "off")) { |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 395 | exit_bad_args(); |
Ben Hutchings | 967cb31 | 2010-09-23 22:48:14 +0100 | [diff] [blame] | 396 | } |
Ben Hutchings | 99a2b6b | 2010-06-25 15:49:19 +0100 | [diff] [blame] | 397 | break; |
| 398 | } |
Stephen Hemminger | fd3dc7b | 2006-10-23 10:57:03 -0700 | [diff] [blame] | 399 | case CMDL_STR: { |
| 400 | char **s = info[idx].wanted_val; |
| 401 | *s = strdup(argp[i]); |
| 402 | break; |
| 403 | } |
| 404 | default: |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 405 | exit_bad_args(); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 406 | } |
Jay Fenlason | 35f0808 | 2009-07-17 15:08:41 -0400 | [diff] [blame] | 407 | break; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 408 | } |
| 409 | } |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 410 | if (!found) |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 411 | exit_bad_args(); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
Ben Hutchings | 5ec0d81 | 2011-10-31 22:50:25 +0000 | [diff] [blame] | 415 | static void flag_to_cmdline_info(const char *name, u32 value, |
| 416 | u32 *wanted, u32 *mask, |
| 417 | struct cmdline_info *cli) |
| 418 | { |
| 419 | memset(cli, 0, sizeof(*cli)); |
| 420 | cli->name = name; |
| 421 | cli->type = CMDL_FLAG; |
| 422 | cli->flag_val = value; |
| 423 | cli->wanted_val = wanted; |
| 424 | cli->seen_val = mask; |
| 425 | } |
| 426 | |
Ben Hutchings | 99a2b6b | 2010-06-25 15:49:19 +0100 | [diff] [blame] | 427 | static void |
Ben Hutchings | 5ec0d81 | 2011-10-31 22:50:25 +0000 | [diff] [blame] | 428 | print_flags(const struct flag_info *info, unsigned int n_info, u32 value) |
Ben Hutchings | 99a2b6b | 2010-06-25 15:49:19 +0100 | [diff] [blame] | 429 | { |
| 430 | const char *sep = ""; |
| 431 | |
| 432 | while (n_info) { |
Ben Hutchings | 5ec0d81 | 2011-10-31 22:50:25 +0000 | [diff] [blame] | 433 | if (value & info->value) { |
Ben Hutchings | 99a2b6b | 2010-06-25 15:49:19 +0100 | [diff] [blame] | 434 | printf("%s%s", sep, info->name); |
| 435 | sep = " "; |
Ben Hutchings | 5ec0d81 | 2011-10-31 22:50:25 +0000 | [diff] [blame] | 436 | value &= ~info->value; |
Ben Hutchings | 99a2b6b | 2010-06-25 15:49:19 +0100 | [diff] [blame] | 437 | } |
| 438 | ++info; |
| 439 | --n_info; |
| 440 | } |
| 441 | |
| 442 | /* Print any unrecognised flags in hex */ |
| 443 | if (value) |
| 444 | printf("%s%#x", sep, value); |
| 445 | } |
| 446 | |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 447 | static int rxflow_str_to_type(const char *str) |
| 448 | { |
| 449 | int flow_type = 0; |
| 450 | |
| 451 | if (!strcmp(str, "tcp4")) |
| 452 | flow_type = TCP_V4_FLOW; |
| 453 | else if (!strcmp(str, "udp4")) |
| 454 | flow_type = UDP_V4_FLOW; |
Alexander Duyck | b400111 | 2011-04-21 13:40:20 -0700 | [diff] [blame] | 455 | else if (!strcmp(str, "ah4") || !strcmp(str, "esp4")) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 456 | flow_type = AH_ESP_V4_FLOW; |
| 457 | else if (!strcmp(str, "sctp4")) |
| 458 | flow_type = SCTP_V4_FLOW; |
| 459 | else if (!strcmp(str, "tcp6")) |
| 460 | flow_type = TCP_V6_FLOW; |
| 461 | else if (!strcmp(str, "udp6")) |
| 462 | flow_type = UDP_V6_FLOW; |
Alexander Duyck | b400111 | 2011-04-21 13:40:20 -0700 | [diff] [blame] | 463 | else if (!strcmp(str, "ah6") || !strcmp(str, "esp6")) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 464 | flow_type = AH_ESP_V6_FLOW; |
| 465 | else if (!strcmp(str, "sctp6")) |
| 466 | flow_type = SCTP_V6_FLOW; |
Ben Hutchings | f5286cd | 2010-09-23 22:49:43 +0100 | [diff] [blame] | 467 | else if (!strcmp(str, "ether")) |
| 468 | flow_type = ETHER_FLOW; |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 469 | |
| 470 | return flow_type; |
| 471 | } |
| 472 | |
Maciej Żenczykowski | d5432a9 | 2019-10-17 11:20:50 -0700 | [diff] [blame] | 473 | static int do_version(struct cmd_context *ctx maybe_unused) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 474 | { |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 475 | fprintf(stdout, |
Florian Fainelli | 875616d | 2014-02-27 15:43:01 -0800 | [diff] [blame] | 476 | PACKAGE " version " VERSION |
| 477 | #ifndef ETHTOOL_ENABLE_PRETTY_DUMP |
| 478 | " (pretty dumps disabled)" |
| 479 | #endif |
| 480 | "\n"); |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 481 | return 0; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 482 | } |
| 483 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 484 | /* link mode routines */ |
Ben Hutchings | d6c816b | 2011-06-01 23:27:17 +0100 | [diff] [blame] | 485 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 486 | static ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_modes); |
| 487 | static ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_flags); |
| 488 | |
| 489 | static void init_global_link_mode_masks(void) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 490 | { |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 491 | static const enum ethtool_link_mode_bit_indices |
| 492 | all_advertised_modes_bits[] = { |
| 493 | ETHTOOL_LINK_MODE_10baseT_Half_BIT, |
| 494 | ETHTOOL_LINK_MODE_10baseT_Full_BIT, |
| 495 | ETHTOOL_LINK_MODE_100baseT_Half_BIT, |
| 496 | ETHTOOL_LINK_MODE_100baseT_Full_BIT, |
| 497 | ETHTOOL_LINK_MODE_1000baseT_Half_BIT, |
| 498 | ETHTOOL_LINK_MODE_1000baseT_Full_BIT, |
| 499 | ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, |
| 500 | ETHTOOL_LINK_MODE_2500baseX_Full_BIT, |
| 501 | ETHTOOL_LINK_MODE_10000baseT_Full_BIT, |
| 502 | ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, |
| 503 | ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, |
| 504 | ETHTOOL_LINK_MODE_10000baseR_FEC_BIT, |
| 505 | ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT, |
| 506 | ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT, |
| 507 | ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT, |
| 508 | ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT, |
| 509 | ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT, |
| 510 | ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT, |
| 511 | ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT, |
| 512 | ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT, |
| 513 | ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT, |
| 514 | ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT, |
Vidya Sagar Ravipati | ac2f96d | 2016-08-23 06:30:33 -0700 | [diff] [blame] | 515 | ETHTOOL_LINK_MODE_25000baseCR_Full_BIT, |
| 516 | ETHTOOL_LINK_MODE_25000baseKR_Full_BIT, |
| 517 | ETHTOOL_LINK_MODE_25000baseSR_Full_BIT, |
| 518 | ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT, |
| 519 | ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT, |
| 520 | ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT, |
| 521 | ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT, |
| 522 | ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT, |
| 523 | ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT, |
| 524 | ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT, |
Vidya Sagar Ravipati | 59a0467 | 2016-08-28 23:56:50 -0700 | [diff] [blame] | 525 | ETHTOOL_LINK_MODE_1000baseX_Full_BIT, |
| 526 | ETHTOOL_LINK_MODE_10000baseCR_Full_BIT, |
| 527 | ETHTOOL_LINK_MODE_10000baseSR_Full_BIT, |
| 528 | ETHTOOL_LINK_MODE_10000baseLR_Full_BIT, |
| 529 | ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT, |
| 530 | ETHTOOL_LINK_MODE_10000baseER_Full_BIT, |
Pavel Belous | 64dfc5e | 2017-01-30 20:03:30 +0300 | [diff] [blame] | 531 | ETHTOOL_LINK_MODE_2500baseT_Full_BIT, |
| 532 | ETHTOOL_LINK_MODE_5000baseT_Full_BIT, |
Aya Levin | caa4bbe | 2019-02-25 17:44:34 +0200 | [diff] [blame] | 533 | ETHTOOL_LINK_MODE_50000baseKR_Full_BIT, |
| 534 | ETHTOOL_LINK_MODE_50000baseSR_Full_BIT, |
| 535 | ETHTOOL_LINK_MODE_50000baseCR_Full_BIT, |
| 536 | ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT, |
| 537 | ETHTOOL_LINK_MODE_50000baseDR_Full_BIT, |
| 538 | ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT, |
| 539 | ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT, |
| 540 | ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT, |
| 541 | ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT, |
| 542 | ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT, |
| 543 | ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT, |
| 544 | ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT, |
| 545 | ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT, |
| 546 | ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT, |
| 547 | ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT, |
Andrew Lunn | 2bce6d9 | 2019-05-31 15:57:48 +0200 | [diff] [blame] | 548 | ETHTOOL_LINK_MODE_100baseT1_Full_BIT, |
| 549 | ETHTOOL_LINK_MODE_1000baseT1_Full_BIT, |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 550 | }; |
| 551 | static const enum ethtool_link_mode_bit_indices |
| 552 | additional_advertised_flags_bits[] = { |
| 553 | ETHTOOL_LINK_MODE_Autoneg_BIT, |
| 554 | ETHTOOL_LINK_MODE_TP_BIT, |
| 555 | ETHTOOL_LINK_MODE_AUI_BIT, |
| 556 | ETHTOOL_LINK_MODE_MII_BIT, |
| 557 | ETHTOOL_LINK_MODE_FIBRE_BIT, |
| 558 | ETHTOOL_LINK_MODE_BNC_BIT, |
| 559 | ETHTOOL_LINK_MODE_Pause_BIT, |
| 560 | ETHTOOL_LINK_MODE_Asym_Pause_BIT, |
| 561 | ETHTOOL_LINK_MODE_Backplane_BIT, |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 562 | ETHTOOL_LINK_MODE_FEC_NONE_BIT, |
| 563 | ETHTOOL_LINK_MODE_FEC_RS_BIT, |
| 564 | ETHTOOL_LINK_MODE_FEC_BASER_BIT, |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 565 | }; |
| 566 | unsigned int i; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 567 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 568 | ethtool_link_mode_zero(all_advertised_modes); |
| 569 | ethtool_link_mode_zero(all_advertised_flags); |
| 570 | for (i = 0; i < ARRAY_SIZE(all_advertised_modes_bits); ++i) { |
| 571 | ethtool_link_mode_set_bit(all_advertised_modes_bits[i], |
| 572 | all_advertised_modes); |
| 573 | ethtool_link_mode_set_bit(all_advertised_modes_bits[i], |
| 574 | all_advertised_flags); |
| 575 | } |
| 576 | |
| 577 | for (i = 0; i < ARRAY_SIZE(additional_advertised_flags_bits); ++i) { |
| 578 | ethtool_link_mode_set_bit( |
| 579 | additional_advertised_flags_bits[i], |
| 580 | all_advertised_flags); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | static void dump_link_caps(const char *prefix, const char *an_prefix, |
| 585 | const u32 *mask, int link_mode_only); |
| 586 | |
| 587 | static void dump_supported(const struct ethtool_link_usettings *link_usettings) |
| 588 | { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 589 | fprintf(stdout, " Supported ports: [ "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 590 | if (ethtool_link_mode_test_bit( |
| 591 | ETHTOOL_LINK_MODE_TP_BIT, |
| 592 | link_usettings->link_modes.supported)) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 593 | fprintf(stdout, "TP "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 594 | if (ethtool_link_mode_test_bit( |
| 595 | ETHTOOL_LINK_MODE_AUI_BIT, |
| 596 | link_usettings->link_modes.supported)) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 597 | fprintf(stdout, "AUI "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 598 | if (ethtool_link_mode_test_bit( |
| 599 | ETHTOOL_LINK_MODE_BNC_BIT, |
| 600 | link_usettings->link_modes.supported)) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 601 | fprintf(stdout, "BNC "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 602 | if (ethtool_link_mode_test_bit( |
| 603 | ETHTOOL_LINK_MODE_MII_BIT, |
| 604 | link_usettings->link_modes.supported)) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 605 | fprintf(stdout, "MII "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 606 | if (ethtool_link_mode_test_bit( |
| 607 | ETHTOOL_LINK_MODE_FIBRE_BIT, |
| 608 | link_usettings->link_modes.supported)) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 609 | fprintf(stdout, "FIBRE "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 610 | if (ethtool_link_mode_test_bit( |
| 611 | ETHTOOL_LINK_MODE_Backplane_BIT, |
| 612 | link_usettings->link_modes.supported)) |
Ivan Vecera | 6cb4322 | 2014-02-20 18:48:56 +0100 | [diff] [blame] | 613 | fprintf(stdout, "Backplane "); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 614 | fprintf(stdout, "]\n"); |
| 615 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 616 | dump_link_caps("Supported", "Supports", |
| 617 | link_usettings->link_modes.supported, 0); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 618 | } |
| 619 | |
Ben Hutchings | d6c816b | 2011-06-01 23:27:17 +0100 | [diff] [blame] | 620 | /* Print link capability flags (supported, advertised or lp_advertised). |
| 621 | * Assumes that the corresponding SUPPORTED and ADVERTISED flags are equal. |
| 622 | */ |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 623 | static void dump_link_caps(const char *prefix, const char *an_prefix, |
| 624 | const u32 *mask, int link_mode_only) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 625 | { |
Ben Hutchings | 74c4280 | 2012-06-08 19:19:08 +0100 | [diff] [blame] | 626 | static const struct { |
| 627 | int same_line; /* print on same line as previous */ |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 628 | unsigned int bit_index; |
Ben Hutchings | 74c4280 | 2012-06-08 19:19:08 +0100 | [diff] [blame] | 629 | const char *name; |
| 630 | } mode_defs[] = { |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 631 | { 0, ETHTOOL_LINK_MODE_10baseT_Half_BIT, |
| 632 | "10baseT/Half" }, |
| 633 | { 1, ETHTOOL_LINK_MODE_10baseT_Full_BIT, |
| 634 | "10baseT/Full" }, |
| 635 | { 0, ETHTOOL_LINK_MODE_100baseT_Half_BIT, |
| 636 | "100baseT/Half" }, |
| 637 | { 1, ETHTOOL_LINK_MODE_100baseT_Full_BIT, |
| 638 | "100baseT/Full" }, |
Andrew Lunn | 2bce6d9 | 2019-05-31 15:57:48 +0200 | [diff] [blame] | 639 | { 0, ETHTOOL_LINK_MODE_100baseT1_Full_BIT, |
| 640 | "100baseT1/Full" }, |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 641 | { 0, ETHTOOL_LINK_MODE_1000baseT_Half_BIT, |
| 642 | "1000baseT/Half" }, |
| 643 | { 1, ETHTOOL_LINK_MODE_1000baseT_Full_BIT, |
| 644 | "1000baseT/Full" }, |
Andrew Lunn | 2bce6d9 | 2019-05-31 15:57:48 +0200 | [diff] [blame] | 645 | { 0, ETHTOOL_LINK_MODE_1000baseT1_Full_BIT, |
| 646 | "1000baseT1/Full" }, |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 647 | { 0, ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, |
| 648 | "1000baseKX/Full" }, |
| 649 | { 0, ETHTOOL_LINK_MODE_2500baseX_Full_BIT, |
| 650 | "2500baseX/Full" }, |
| 651 | { 0, ETHTOOL_LINK_MODE_10000baseT_Full_BIT, |
| 652 | "10000baseT/Full" }, |
| 653 | { 0, ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, |
| 654 | "10000baseKX4/Full" }, |
| 655 | { 0, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, |
| 656 | "10000baseKR/Full" }, |
Michal Kubecek | 085813b | 2019-02-27 14:49:04 +0100 | [diff] [blame] | 657 | { 0, ETHTOOL_LINK_MODE_10000baseR_FEC_BIT, |
| 658 | "10000baseR_FEC" }, |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 659 | { 0, ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT, |
| 660 | "20000baseMLD2/Full" }, |
| 661 | { 0, ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT, |
| 662 | "20000baseKR2/Full" }, |
| 663 | { 0, ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT, |
| 664 | "40000baseKR4/Full" }, |
| 665 | { 0, ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT, |
| 666 | "40000baseCR4/Full" }, |
| 667 | { 0, ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT, |
| 668 | "40000baseSR4/Full" }, |
| 669 | { 0, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT, |
| 670 | "40000baseLR4/Full" }, |
| 671 | { 0, ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT, |
| 672 | "56000baseKR4/Full" }, |
| 673 | { 0, ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT, |
| 674 | "56000baseCR4/Full" }, |
| 675 | { 0, ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT, |
| 676 | "56000baseSR4/Full" }, |
| 677 | { 0, ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT, |
| 678 | "56000baseLR4/Full" }, |
Vidya Sagar Ravipati | ac2f96d | 2016-08-23 06:30:33 -0700 | [diff] [blame] | 679 | { 0, ETHTOOL_LINK_MODE_25000baseCR_Full_BIT, |
| 680 | "25000baseCR/Full" }, |
| 681 | { 0, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT, |
| 682 | "25000baseKR/Full" }, |
| 683 | { 0, ETHTOOL_LINK_MODE_25000baseSR_Full_BIT, |
| 684 | "25000baseSR/Full" }, |
| 685 | { 0, ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT, |
| 686 | "50000baseCR2/Full" }, |
| 687 | { 0, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT, |
| 688 | "50000baseKR2/Full" }, |
| 689 | { 0, ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT, |
| 690 | "100000baseKR4/Full" }, |
| 691 | { 0, ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT, |
| 692 | "100000baseSR4/Full" }, |
| 693 | { 0, ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT, |
| 694 | "100000baseCR4/Full" }, |
| 695 | { 0, ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT, |
| 696 | "100000baseLR4_ER4/Full" }, |
| 697 | { 0, ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT, |
| 698 | "50000baseSR2/Full" }, |
Vidya Sagar Ravipati | 59a0467 | 2016-08-28 23:56:50 -0700 | [diff] [blame] | 699 | { 0, ETHTOOL_LINK_MODE_1000baseX_Full_BIT, |
| 700 | "1000baseX/Full" }, |
| 701 | { 0, ETHTOOL_LINK_MODE_10000baseCR_Full_BIT, |
| 702 | "10000baseCR/Full" }, |
| 703 | { 0, ETHTOOL_LINK_MODE_10000baseSR_Full_BIT, |
| 704 | "10000baseSR/Full" }, |
| 705 | { 0, ETHTOOL_LINK_MODE_10000baseLR_Full_BIT, |
| 706 | "10000baseLR/Full" }, |
| 707 | { 0, ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT, |
| 708 | "10000baseLRM/Full" }, |
| 709 | { 0, ETHTOOL_LINK_MODE_10000baseER_Full_BIT, |
| 710 | "10000baseER/Full" }, |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 711 | { 0, ETHTOOL_LINK_MODE_2500baseT_Full_BIT, |
| 712 | "2500baseT/Full" }, |
| 713 | { 0, ETHTOOL_LINK_MODE_5000baseT_Full_BIT, |
| 714 | "5000baseT/Full" }, |
Aya Levin | caa4bbe | 2019-02-25 17:44:34 +0200 | [diff] [blame] | 715 | { 0, ETHTOOL_LINK_MODE_50000baseKR_Full_BIT, |
| 716 | "50000baseKR/Full" }, |
| 717 | { 0, ETHTOOL_LINK_MODE_50000baseSR_Full_BIT, |
| 718 | "50000baseSR/Full" }, |
| 719 | { 0, ETHTOOL_LINK_MODE_50000baseCR_Full_BIT, |
| 720 | "50000baseCR/Full" }, |
| 721 | { 0, ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT, |
| 722 | "50000baseLR_ER_FR/Full" }, |
| 723 | { 0, ETHTOOL_LINK_MODE_50000baseDR_Full_BIT, |
| 724 | "50000baseDR/Full" }, |
| 725 | { 0, ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT, |
| 726 | "100000baseKR2/Full" }, |
| 727 | { 0, ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT, |
| 728 | "100000baseSR2/Full" }, |
| 729 | { 0, ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT, |
| 730 | "100000baseCR2/Full" }, |
| 731 | { 0, ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT, |
| 732 | "100000baseLR2_ER2_FR2/Full" }, |
| 733 | { 0, ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT, |
| 734 | "100000baseDR2/Full" }, |
| 735 | { 0, ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT, |
| 736 | "200000baseKR4/Full" }, |
| 737 | { 0, ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT, |
| 738 | "200000baseSR4/Full" }, |
| 739 | { 0, ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT, |
| 740 | "200000baseLR4_ER4_FR4/Full" }, |
| 741 | { 0, ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT, |
| 742 | "200000baseDR4/Full" }, |
| 743 | { 0, ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT, |
| 744 | "200000baseCR4/Full" }, |
Ben Hutchings | 74c4280 | 2012-06-08 19:19:08 +0100 | [diff] [blame] | 745 | }; |
Ben Hutchings | d6c816b | 2011-06-01 23:27:17 +0100 | [diff] [blame] | 746 | int indent; |
Ben Hutchings | 74c4280 | 2012-06-08 19:19:08 +0100 | [diff] [blame] | 747 | int did1, new_line_pend, i; |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 748 | int fecreported = 0; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 749 | |
Ben Hutchings | d6c816b | 2011-06-01 23:27:17 +0100 | [diff] [blame] | 750 | /* Indent just like the separate functions used to */ |
| 751 | indent = strlen(prefix) + 14; |
| 752 | if (indent < 24) |
| 753 | indent = 24; |
| 754 | |
| 755 | fprintf(stdout, " %s link modes:%*s", prefix, |
Ben Hutchings | 4292820 | 2011-06-02 20:20:12 +0100 | [diff] [blame] | 756 | indent - (int)strlen(prefix) - 12, ""); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 757 | did1 = 0; |
Ben Hutchings | 74c4280 | 2012-06-08 19:19:08 +0100 | [diff] [blame] | 758 | new_line_pend = 0; |
| 759 | for (i = 0; i < ARRAY_SIZE(mode_defs); i++) { |
| 760 | if (did1 && !mode_defs[i].same_line) |
| 761 | new_line_pend = 1; |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 762 | if (ethtool_link_mode_test_bit(mode_defs[i].bit_index, |
| 763 | mask)) { |
Ben Hutchings | 74c4280 | 2012-06-08 19:19:08 +0100 | [diff] [blame] | 764 | if (new_line_pend) { |
| 765 | fprintf(stdout, "\n"); |
| 766 | fprintf(stdout, " %*s", indent, ""); |
| 767 | new_line_pend = 0; |
| 768 | } |
| 769 | did1++; |
| 770 | fprintf(stdout, "%s ", mode_defs[i].name); |
| 771 | } |
Yaniv Rosner | 42a76be | 2011-06-05 20:39:43 +0300 | [diff] [blame] | 772 | } |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 773 | if (did1 == 0) |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 774 | fprintf(stdout, "Not reported"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 775 | fprintf(stdout, "\n"); |
| 776 | |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 777 | if (!link_mode_only) { |
| 778 | fprintf(stdout, " %s pause frame use: ", prefix); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 779 | if (ethtool_link_mode_test_bit( |
| 780 | ETHTOOL_LINK_MODE_Pause_BIT, mask)) { |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 781 | fprintf(stdout, "Symmetric"); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 782 | if (ethtool_link_mode_test_bit( |
| 783 | ETHTOOL_LINK_MODE_Asym_Pause_BIT, mask)) |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 784 | fprintf(stdout, " Receive-only"); |
| 785 | fprintf(stdout, "\n"); |
| 786 | } else { |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 787 | if (ethtool_link_mode_test_bit( |
| 788 | ETHTOOL_LINK_MODE_Asym_Pause_BIT, mask)) |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 789 | fprintf(stdout, "Transmit-only\n"); |
| 790 | else |
| 791 | fprintf(stdout, "No\n"); |
| 792 | } |
| 793 | |
| 794 | fprintf(stdout, " %s auto-negotiation: ", an_prefix); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 795 | if (ethtool_link_mode_test_bit( |
| 796 | ETHTOOL_LINK_MODE_Autoneg_BIT, mask)) |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 797 | fprintf(stdout, "Yes\n"); |
Ben Hutchings | 0bae924 | 2009-04-30 13:38:06 +0100 | [diff] [blame] | 798 | else |
| 799 | fprintf(stdout, "No\n"); |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 800 | |
| 801 | fprintf(stdout, " %s FEC modes:", prefix); |
| 802 | if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_NONE_BIT, |
| 803 | mask)) { |
| 804 | fprintf(stdout, " None"); |
| 805 | fecreported = 1; |
| 806 | } |
| 807 | if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_BASER_BIT, |
| 808 | mask)) { |
| 809 | fprintf(stdout, " BaseR"); |
| 810 | fecreported = 1; |
| 811 | } |
| 812 | if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_RS_BIT, |
| 813 | mask)) { |
| 814 | fprintf(stdout, " RS"); |
| 815 | fecreported = 1; |
| 816 | } |
| 817 | if (!fecreported) |
| 818 | fprintf(stdout, " Not reported"); |
| 819 | fprintf(stdout, "\n"); |
Ben Hutchings | 0bae924 | 2009-04-30 13:38:06 +0100 | [diff] [blame] | 820 | } |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 821 | } |
| 822 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 823 | static int |
| 824 | dump_link_usettings(const struct ethtool_link_usettings *link_usettings) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 825 | { |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 826 | dump_supported(link_usettings); |
| 827 | dump_link_caps("Advertised", "Advertised", |
| 828 | link_usettings->link_modes.advertising, 0); |
| 829 | if (!ethtool_link_mode_is_empty( |
| 830 | link_usettings->link_modes.lp_advertising)) |
Ben Hutchings | d6c816b | 2011-06-01 23:27:17 +0100 | [diff] [blame] | 831 | dump_link_caps("Link partner advertised", |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 832 | "Link partner advertised", |
| 833 | link_usettings->link_modes.lp_advertising, 0); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 834 | |
| 835 | fprintf(stdout, " Speed: "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 836 | if (link_usettings->base.speed == 0 |
| 837 | || link_usettings->base.speed == (u16)(-1) |
| 838 | || link_usettings->base.speed == (u32)(-1)) |
Ben Hutchings | 580cc50 | 2009-01-09 13:16:14 +0000 | [diff] [blame] | 839 | fprintf(stdout, "Unknown!\n"); |
| 840 | else |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 841 | fprintf(stdout, "%uMb/s\n", link_usettings->base.speed); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 842 | |
| 843 | fprintf(stdout, " Duplex: "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 844 | switch (link_usettings->base.duplex) { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 845 | case DUPLEX_HALF: |
| 846 | fprintf(stdout, "Half\n"); |
| 847 | break; |
| 848 | case DUPLEX_FULL: |
| 849 | fprintf(stdout, "Full\n"); |
| 850 | break; |
| 851 | default: |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 852 | fprintf(stdout, "Unknown! (%i)\n", link_usettings->base.duplex); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 853 | break; |
| 854 | }; |
| 855 | |
| 856 | fprintf(stdout, " Port: "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 857 | switch (link_usettings->base.port) { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 858 | case PORT_TP: |
| 859 | fprintf(stdout, "Twisted Pair\n"); |
| 860 | break; |
| 861 | case PORT_AUI: |
| 862 | fprintf(stdout, "AUI\n"); |
| 863 | break; |
| 864 | case PORT_BNC: |
| 865 | fprintf(stdout, "BNC\n"); |
| 866 | break; |
| 867 | case PORT_MII: |
| 868 | fprintf(stdout, "MII\n"); |
| 869 | break; |
| 870 | case PORT_FIBRE: |
| 871 | fprintf(stdout, "FIBRE\n"); |
| 872 | break; |
Ben Hutchings | f58f264 | 2009-12-01 16:06:55 +0000 | [diff] [blame] | 873 | case PORT_DA: |
| 874 | fprintf(stdout, "Direct Attach Copper\n"); |
| 875 | break; |
| 876 | case PORT_NONE: |
| 877 | fprintf(stdout, "None\n"); |
| 878 | break; |
Ben Hutchings | 6a8940f | 2009-04-30 13:37:14 +0100 | [diff] [blame] | 879 | case PORT_OTHER: |
| 880 | fprintf(stdout, "Other\n"); |
| 881 | break; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 882 | default: |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 883 | fprintf(stdout, "Unknown! (%i)\n", link_usettings->base.port); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 884 | break; |
| 885 | }; |
| 886 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 887 | fprintf(stdout, " PHYAD: %d\n", link_usettings->base.phy_address); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 888 | fprintf(stdout, " Transceiver: "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 889 | switch (link_usettings->deprecated.transceiver) { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 890 | case XCVR_INTERNAL: |
| 891 | fprintf(stdout, "internal\n"); |
| 892 | break; |
| 893 | case XCVR_EXTERNAL: |
| 894 | fprintf(stdout, "external\n"); |
| 895 | break; |
| 896 | default: |
| 897 | fprintf(stdout, "Unknown!\n"); |
| 898 | break; |
| 899 | }; |
| 900 | |
| 901 | fprintf(stdout, " Auto-negotiation: %s\n", |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 902 | (link_usettings->base.autoneg == AUTONEG_DISABLE) ? |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 903 | "off" : "on"); |
Ben Hutchings | da7d16a | 2009-12-01 16:00:30 +0000 | [diff] [blame] | 904 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 905 | if (link_usettings->base.port == PORT_TP) { |
Ben Hutchings | da7d16a | 2009-12-01 16:00:30 +0000 | [diff] [blame] | 906 | fprintf(stdout, " MDI-X: "); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 907 | if (link_usettings->base.eth_tp_mdix_ctrl == ETH_TP_MDI) { |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 908 | fprintf(stdout, "off (forced)\n"); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 909 | } else if (link_usettings->base.eth_tp_mdix_ctrl |
| 910 | == ETH_TP_MDI_X) { |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 911 | fprintf(stdout, "on (forced)\n"); |
| 912 | } else { |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 913 | switch (link_usettings->base.eth_tp_mdix) { |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 914 | case ETH_TP_MDI: |
| 915 | fprintf(stdout, "off"); |
| 916 | break; |
| 917 | case ETH_TP_MDI_X: |
| 918 | fprintf(stdout, "on"); |
| 919 | break; |
| 920 | default: |
| 921 | fprintf(stdout, "Unknown"); |
| 922 | break; |
| 923 | } |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 924 | if (link_usettings->base.eth_tp_mdix_ctrl |
| 925 | == ETH_TP_MDI_AUTO) |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 926 | fprintf(stdout, " (auto)"); |
| 927 | fprintf(stdout, "\n"); |
Ben Hutchings | da7d16a | 2009-12-01 16:00:30 +0000 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | static int dump_drvinfo(struct ethtool_drvinfo *info) |
| 935 | { |
| 936 | fprintf(stdout, |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 937 | "driver: %.*s\n" |
| 938 | "version: %.*s\n" |
| 939 | "firmware-version: %.*s\n" |
Hariprasad Shenai | cc1b687 | 2015-02-09 12:07:31 +0530 | [diff] [blame] | 940 | "expansion-rom-version: %.*s\n" |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 941 | "bus-info: %.*s\n" |
Ben Hutchings | c5bcaca | 2011-03-18 22:35:44 +0000 | [diff] [blame] | 942 | "supports-statistics: %s\n" |
| 943 | "supports-test: %s\n" |
| 944 | "supports-eeprom-access: %s\n" |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 945 | "supports-register-dump: %s\n" |
| 946 | "supports-priv-flags: %s\n", |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 947 | (int)sizeof(info->driver), info->driver, |
| 948 | (int)sizeof(info->version), info->version, |
| 949 | (int)sizeof(info->fw_version), info->fw_version, |
Hariprasad Shenai | cc1b687 | 2015-02-09 12:07:31 +0530 | [diff] [blame] | 950 | (int)sizeof(info->erom_version), info->erom_version, |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 951 | (int)sizeof(info->bus_info), info->bus_info, |
Ben Hutchings | c5bcaca | 2011-03-18 22:35:44 +0000 | [diff] [blame] | 952 | info->n_stats ? "yes" : "no", |
| 953 | info->testinfo_len ? "yes" : "no", |
| 954 | info->eedump_len ? "yes" : "no", |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 955 | info->regdump_len ? "yes" : "no", |
| 956 | info->n_priv_flags ? "yes" : "no"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
Jeff Garzik | a4f48f0 | 2005-10-25 02:06:01 -0400 | [diff] [blame] | 961 | static int parse_wolopts(char *optstr, u32 *data) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 962 | { |
| 963 | *data = 0; |
| 964 | while (*optstr) { |
| 965 | switch (*optstr) { |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 966 | case 'p': |
| 967 | *data |= WAKE_PHY; |
| 968 | break; |
| 969 | case 'u': |
| 970 | *data |= WAKE_UCAST; |
| 971 | break; |
| 972 | case 'm': |
| 973 | *data |= WAKE_MCAST; |
| 974 | break; |
| 975 | case 'b': |
| 976 | *data |= WAKE_BCAST; |
| 977 | break; |
| 978 | case 'a': |
| 979 | *data |= WAKE_ARP; |
| 980 | break; |
| 981 | case 'g': |
| 982 | *data |= WAKE_MAGIC; |
| 983 | break; |
| 984 | case 's': |
| 985 | *data |= WAKE_MAGICSECURE; |
| 986 | break; |
Florian Fainelli | eff0bb3 | 2018-08-09 11:04:01 -0700 | [diff] [blame] | 987 | case 'f': |
| 988 | *data |= WAKE_FILTER; |
| 989 | break; |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 990 | case 'd': |
| 991 | *data = 0; |
| 992 | break; |
| 993 | default: |
| 994 | return -1; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 995 | } |
| 996 | optstr++; |
| 997 | } |
| 998 | return 0; |
| 999 | } |
| 1000 | |
| 1001 | static char *unparse_wolopts(int wolopts) |
| 1002 | { |
| 1003 | static char buf[16]; |
| 1004 | char *p = buf; |
| 1005 | |
| 1006 | memset(buf, 0, sizeof(buf)); |
| 1007 | |
| 1008 | if (wolopts) { |
| 1009 | if (wolopts & WAKE_PHY) |
| 1010 | *p++ = 'p'; |
| 1011 | if (wolopts & WAKE_UCAST) |
| 1012 | *p++ = 'u'; |
| 1013 | if (wolopts & WAKE_MCAST) |
| 1014 | *p++ = 'm'; |
| 1015 | if (wolopts & WAKE_BCAST) |
| 1016 | *p++ = 'b'; |
| 1017 | if (wolopts & WAKE_ARP) |
| 1018 | *p++ = 'a'; |
| 1019 | if (wolopts & WAKE_MAGIC) |
| 1020 | *p++ = 'g'; |
| 1021 | if (wolopts & WAKE_MAGICSECURE) |
| 1022 | *p++ = 's'; |
Florian Fainelli | eff0bb3 | 2018-08-09 11:04:01 -0700 | [diff] [blame] | 1023 | if (wolopts & WAKE_FILTER) |
| 1024 | *p++ = 'f'; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1025 | } else { |
| 1026 | *p = 'd'; |
| 1027 | } |
| 1028 | |
| 1029 | return buf; |
| 1030 | } |
| 1031 | |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 1032 | static int dump_wol(struct ethtool_wolinfo *wol) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1033 | { |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 1034 | fprintf(stdout, " Supports Wake-on: %s\n", |
| 1035 | unparse_wolopts(wol->supported)); |
| 1036 | fprintf(stdout, " Wake-on: %s\n", |
| 1037 | unparse_wolopts(wol->wolopts)); |
| 1038 | if (wol->supported & WAKE_MAGICSECURE) { |
| 1039 | int i; |
| 1040 | int delim = 0; |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1041 | |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 1042 | fprintf(stdout, " SecureOn password: "); |
| 1043 | for (i = 0; i < SOPASS_MAX; i++) { |
| 1044 | fprintf(stdout, "%s%02x", delim?":":"", wol->sopass[i]); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1045 | delim = 1; |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 1046 | } |
| 1047 | fprintf(stdout, "\n"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1048 | } |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 1049 | |
| 1050 | return 0; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1051 | } |
| 1052 | |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1053 | static int parse_rxfhashopts(char *optstr, u32 *data) |
| 1054 | { |
| 1055 | *data = 0; |
| 1056 | while (*optstr) { |
| 1057 | switch (*optstr) { |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1058 | case 'm': |
| 1059 | *data |= RXH_L2DA; |
| 1060 | break; |
| 1061 | case 'v': |
| 1062 | *data |= RXH_VLAN; |
| 1063 | break; |
| 1064 | case 't': |
| 1065 | *data |= RXH_L3_PROTO; |
| 1066 | break; |
| 1067 | case 's': |
| 1068 | *data |= RXH_IP_SRC; |
| 1069 | break; |
| 1070 | case 'd': |
| 1071 | *data |= RXH_IP_DST; |
| 1072 | break; |
| 1073 | case 'f': |
| 1074 | *data |= RXH_L4_B_0_1; |
| 1075 | break; |
| 1076 | case 'n': |
| 1077 | *data |= RXH_L4_B_2_3; |
| 1078 | break; |
| 1079 | case 'r': |
| 1080 | *data |= RXH_DISCARD; |
| 1081 | break; |
| 1082 | default: |
| 1083 | return -1; |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1084 | } |
| 1085 | optstr++; |
| 1086 | } |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static char *unparse_rxfhashopts(u64 opts) |
| 1091 | { |
| 1092 | static char buf[300]; |
| 1093 | |
| 1094 | memset(buf, 0, sizeof(buf)); |
| 1095 | |
| 1096 | if (opts) { |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1097 | if (opts & RXH_L2DA) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1098 | strcat(buf, "L2DA\n"); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1099 | if (opts & RXH_VLAN) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1100 | strcat(buf, "VLAN tag\n"); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1101 | if (opts & RXH_L3_PROTO) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1102 | strcat(buf, "L3 proto\n"); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1103 | if (opts & RXH_IP_SRC) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1104 | strcat(buf, "IP SA\n"); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1105 | if (opts & RXH_IP_DST) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1106 | strcat(buf, "IP DA\n"); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1107 | if (opts & RXH_L4_B_0_1) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1108 | strcat(buf, "L4 bytes 0 & 1 [TCP/UDP src port]\n"); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1109 | if (opts & RXH_L4_B_2_3) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1110 | strcat(buf, "L4 bytes 2 & 3 [TCP/UDP dst port]\n"); |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1111 | } else { |
| 1112 | sprintf(buf, "None"); |
| 1113 | } |
| 1114 | |
| 1115 | return buf; |
| 1116 | } |
| 1117 | |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 1118 | static int convert_string_to_hashkey(char *rss_hkey, u32 key_size, |
| 1119 | const char *rss_hkey_string) |
| 1120 | { |
| 1121 | u32 i = 0; |
| 1122 | int hex_byte, len; |
| 1123 | |
| 1124 | do { |
| 1125 | if (i > (key_size - 1)) { |
| 1126 | fprintf(stderr, |
| 1127 | "Key is too long for device (%u > %u)\n", |
| 1128 | i + 1, key_size); |
| 1129 | goto err; |
| 1130 | } |
| 1131 | |
| 1132 | if (sscanf(rss_hkey_string, "%2x%n", &hex_byte, &len) < 1 || |
| 1133 | len != 2) { |
| 1134 | fprintf(stderr, "Invalid RSS hash key format\n"); |
| 1135 | goto err; |
| 1136 | } |
| 1137 | |
| 1138 | rss_hkey[i++] = hex_byte; |
| 1139 | rss_hkey_string += 2; |
| 1140 | |
| 1141 | if (*rss_hkey_string == ':') { |
| 1142 | rss_hkey_string++; |
| 1143 | } else if (*rss_hkey_string != '\0') { |
| 1144 | fprintf(stderr, "Invalid RSS hash key format\n"); |
| 1145 | goto err; |
| 1146 | } |
| 1147 | |
| 1148 | } while (*rss_hkey_string); |
| 1149 | |
| 1150 | if (i != key_size) { |
| 1151 | fprintf(stderr, "Key is too short for device (%u < %u)\n", |
| 1152 | i, key_size); |
| 1153 | goto err; |
| 1154 | } |
| 1155 | |
| 1156 | return 0; |
| 1157 | err: |
| 1158 | return 2; |
| 1159 | } |
| 1160 | |
| 1161 | static int parse_hkey(char **rss_hkey, u32 key_size, |
| 1162 | const char *rss_hkey_string) |
| 1163 | { |
| 1164 | if (!key_size) { |
| 1165 | fprintf(stderr, |
| 1166 | "Cannot set RX flow hash configuration:\n" |
| 1167 | " Hash key setting not supported\n"); |
| 1168 | return 1; |
| 1169 | } |
| 1170 | |
| 1171 | *rss_hkey = malloc(key_size); |
| 1172 | if (!(*rss_hkey)) { |
| 1173 | perror("Cannot allocate memory for RSS hash key"); |
| 1174 | return 1; |
| 1175 | } |
| 1176 | |
| 1177 | if (convert_string_to_hashkey(*rss_hkey, key_size, |
| 1178 | rss_hkey_string)) { |
| 1179 | free(*rss_hkey); |
| 1180 | *rss_hkey = NULL; |
| 1181 | return 2; |
| 1182 | } |
| 1183 | return 0; |
| 1184 | } |
| 1185 | |
Ben Hutchings | 02af8c2 | 2011-10-31 23:06:52 +0000 | [diff] [blame] | 1186 | static const struct { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1187 | const char *name; |
| 1188 | int (*func)(struct ethtool_drvinfo *info, struct ethtool_regs *regs); |
| 1189 | |
| 1190 | } driver_list[] = { |
Florian Fainelli | 875616d | 2014-02-27 15:43:01 -0800 | [diff] [blame] | 1191 | #ifdef ETHTOOL_ENABLE_PRETTY_DUMP |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1192 | { "8139cp", realtek_dump_regs }, |
| 1193 | { "8139too", realtek_dump_regs }, |
| 1194 | { "r8169", realtek_dump_regs }, |
| 1195 | { "de2104x", de2104x_dump_regs }, |
| 1196 | { "e1000", e1000_dump_regs }, |
Auke Kok | e52c3a0 | 2007-10-04 11:37:31 -0700 | [diff] [blame] | 1197 | { "e1000e", e1000_dump_regs }, |
Nicholas Nunley | ae5505e | 2007-08-15 10:44:01 -0700 | [diff] [blame] | 1198 | { "igb", igb_dump_regs }, |
Nicholas Nunley | fb522ac | 2006-09-19 11:27:35 -0700 | [diff] [blame] | 1199 | { "ixgb", ixgb_dump_regs }, |
Nicholas Nunley | 4b448ec | 2007-08-15 10:44:11 -0700 | [diff] [blame] | 1200 | { "ixgbe", ixgbe_dump_regs }, |
Jacob Keller | 5c271a2 | 2013-08-27 17:08:49 -0700 | [diff] [blame] | 1201 | { "ixgbevf", ixgbevf_dump_regs }, |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1202 | { "natsemi", natsemi_dump_regs }, |
| 1203 | { "e100", e100_dump_regs }, |
| 1204 | { "amd8111e", amd8111e_dump_regs }, |
| 1205 | { "pcnet32", pcnet32_dump_regs }, |
| 1206 | { "fec_8xx", fec_8xx_dump_regs }, |
Eugene Surovegin | a69768a | 2005-10-25 02:29:27 -0400 | [diff] [blame] | 1207 | { "ibm_emac", ibm_emac_dump_regs }, |
Michael Chan | 14004d1 | 2005-11-08 12:24:23 -0800 | [diff] [blame] | 1208 | { "tg3", tg3_dump_regs }, |
Stephen Hemminger | 8f3b48b | 2006-08-23 14:16:09 -0700 | [diff] [blame] | 1209 | { "skge", skge_dump_regs }, |
Stephen Hemminger | ad70259 | 2006-09-26 13:09:14 -0700 | [diff] [blame] | 1210 | { "sky2", sky2_dump_regs }, |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 1211 | { "vioc", vioc_dump_regs }, |
| 1212 | { "smsc911x", smsc911x_dump_regs }, |
| 1213 | { "at76c50x-usb", at76c50x_usb_dump_regs }, |
| 1214 | { "sfc", sfc_dump_regs }, |
Giuseppe CAVALLARO | 02ea0ac | 2010-10-13 10:52:25 +0200 | [diff] [blame] | 1215 | { "st_mac100", st_mac100_dump_regs }, |
| 1216 | { "st_gmac", st_gmac_dump_regs }, |
Mark Einon | 08f7d49 | 2012-10-30 21:57:23 +0000 | [diff] [blame] | 1217 | { "et131x", et131x_dump_regs }, |
Vince Bridgers | 0bbd4f5 | 2014-06-22 19:16:59 -0500 | [diff] [blame] | 1218 | { "altera_tse", altera_tse_dump_regs }, |
Shrikrishna Khare | 009799a | 2015-09-23 15:19:12 -0700 | [diff] [blame] | 1219 | { "vmxnet3", vmxnet3_dump_regs }, |
Taku Izumi | acc3d3a | 2016-11-16 09:55:32 +0900 | [diff] [blame] | 1220 | { "fjes", fjes_dump_regs }, |
Raghuram Chary J | bf66874 | 2018-04-05 11:41:28 +0530 | [diff] [blame] | 1221 | { "lan78xx", lan78xx_dump_regs }, |
Vivien Didelot | cb8e980 | 2018-12-18 14:06:35 -0500 | [diff] [blame] | 1222 | { "dsa", dsa_dump_regs }, |
Vivien Didelot | 8612d8b | 2019-02-14 11:15:36 -0500 | [diff] [blame] | 1223 | { "fec", fec_dump_regs }, |
Florian Fainelli | 875616d | 2014-02-27 15:43:01 -0800 | [diff] [blame] | 1224 | #endif |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1225 | }; |
| 1226 | |
Ben Hutchings | 2038e9e | 2012-02-17 21:30:06 +0000 | [diff] [blame] | 1227 | void dump_hex(FILE *file, const u8 *data, int len, int offset) |
Stuart Hodgson | 0d53f25 | 2012-05-18 15:58:24 +0100 | [diff] [blame] | 1228 | { |
| 1229 | int i; |
| 1230 | |
Ben Hutchings | 2038e9e | 2012-02-17 21:30:06 +0000 | [diff] [blame] | 1231 | fprintf(file, "Offset\t\tValues\n"); |
| 1232 | fprintf(file, "------\t\t------"); |
Stuart Hodgson | 0d53f25 | 2012-05-18 15:58:24 +0100 | [diff] [blame] | 1233 | for (i = 0; i < len; i++) { |
| 1234 | if (i % 16 == 0) |
Ben Hutchings | 2038e9e | 2012-02-17 21:30:06 +0000 | [diff] [blame] | 1235 | fprintf(file, "\n0x%04x:\t\t", i + offset); |
| 1236 | fprintf(file, "%02x ", data[i]); |
Stuart Hodgson | 0d53f25 | 2012-05-18 15:58:24 +0100 | [diff] [blame] | 1237 | } |
Ben Hutchings | 2038e9e | 2012-02-17 21:30:06 +0000 | [diff] [blame] | 1238 | fprintf(file, "\n"); |
Stuart Hodgson | 0d53f25 | 2012-05-18 15:58:24 +0100 | [diff] [blame] | 1239 | } |
| 1240 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1241 | static int dump_regs(int gregs_dump_raw, int gregs_dump_hex, |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1242 | struct ethtool_drvinfo *info, struct ethtool_regs *regs) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1243 | { |
| 1244 | int i; |
| 1245 | |
| 1246 | if (gregs_dump_raw) { |
| 1247 | fwrite(regs->data, regs->len, 1, stdout); |
Vivien Didelot | 3870efc | 2019-08-02 15:34:54 -0400 | [diff] [blame] | 1248 | goto nested; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1249 | } |
| 1250 | |
Stephen Hemminger | 5ab06db | 2006-10-23 10:58:37 -0700 | [diff] [blame] | 1251 | if (!gregs_dump_hex) |
| 1252 | for (i = 0; i < ARRAY_SIZE(driver_list); i++) |
| 1253 | if (!strncmp(driver_list[i].name, info->driver, |
Ben Hutchings | 963faa0 | 2012-10-10 22:19:15 +0100 | [diff] [blame] | 1254 | ETHTOOL_BUSINFO_LEN)) { |
| 1255 | if (driver_list[i].func(info, regs) == 0) |
Vivien Didelot | 3870efc | 2019-08-02 15:34:54 -0400 | [diff] [blame] | 1256 | goto nested; |
Ben Hutchings | 963faa0 | 2012-10-10 22:19:15 +0100 | [diff] [blame] | 1257 | /* This version (or some other |
| 1258 | * variation in the dump format) is |
| 1259 | * not handled; fall back to hex |
| 1260 | */ |
| 1261 | break; |
| 1262 | } |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1263 | |
Ben Hutchings | 2038e9e | 2012-02-17 21:30:06 +0000 | [diff] [blame] | 1264 | dump_hex(stdout, regs->data, regs->len, 0); |
Stuart Hodgson | 0d53f25 | 2012-05-18 15:58:24 +0100 | [diff] [blame] | 1265 | |
Vivien Didelot | 3870efc | 2019-08-02 15:34:54 -0400 | [diff] [blame] | 1266 | nested: |
| 1267 | /* Recurse dump if some drvinfo and regs structures are nested */ |
| 1268 | if (info->regdump_len > regs->len + sizeof(*info) + sizeof(*regs)) { |
| 1269 | info = (struct ethtool_drvinfo *)(®s->data[0] + regs->len); |
| 1270 | regs = (struct ethtool_regs *)(®s->data[0] + regs->len + sizeof(*info)); |
| 1271 | |
| 1272 | return dump_regs(gregs_dump_raw, gregs_dump_hex, info, regs); |
| 1273 | } |
| 1274 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1275 | return 0; |
| 1276 | } |
| 1277 | |
Maciej Żenczykowski | 302e91a | 2019-10-17 11:20:52 -0700 | [diff] [blame] | 1278 | static int dump_eeprom(int geeprom_dump_raw, |
| 1279 | struct ethtool_drvinfo *info maybe_unused, |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1280 | struct ethtool_eeprom *ee) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1281 | { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1282 | if (geeprom_dump_raw) { |
| 1283 | fwrite(ee->data, 1, ee->len, stdout); |
| 1284 | return 0; |
| 1285 | } |
Ben Hutchings | 9832a4c | 2014-04-21 22:51:46 +0100 | [diff] [blame] | 1286 | #ifdef ETHTOOL_ENABLE_PRETTY_DUMP |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1287 | if (!strncmp("natsemi", info->driver, ETHTOOL_BUSINFO_LEN)) { |
| 1288 | return natsemi_dump_eeprom(info, ee); |
| 1289 | } else if (!strncmp("tg3", info->driver, ETHTOOL_BUSINFO_LEN)) { |
| 1290 | return tg3_dump_eeprom(info, ee); |
| 1291 | } |
Florian Fainelli | 875616d | 2014-02-27 15:43:01 -0800 | [diff] [blame] | 1292 | #endif |
Ben Hutchings | 2038e9e | 2012-02-17 21:30:06 +0000 | [diff] [blame] | 1293 | dump_hex(stdout, ee->data, ee->len, ee->offset); |
Stuart Hodgson | 0d53f25 | 2012-05-18 15:58:24 +0100 | [diff] [blame] | 1294 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1295 | return 0; |
| 1296 | } |
| 1297 | |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 1298 | static int dump_test(struct ethtool_test *test, |
| 1299 | struct ethtool_gstrings *strings) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1300 | { |
| 1301 | int i, rc; |
| 1302 | |
| 1303 | rc = test->flags & ETH_TEST_FL_FAILED; |
| 1304 | fprintf(stdout, "The test result is %s\n", rc ? "FAIL" : "PASS"); |
| 1305 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1306 | if (test->flags & ETH_TEST_FL_EXTERNAL_LB) |
Sucheta Chakraborty | beceb09 | 2011-09-20 03:31:34 -0700 | [diff] [blame] | 1307 | fprintf(stdout, "External loopback test was %sexecuted\n", |
| 1308 | (test->flags & ETH_TEST_FL_EXTERNAL_LB_DONE) ? |
| 1309 | "" : "not "); |
| 1310 | |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 1311 | if (strings->len) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1312 | fprintf(stdout, "The test extra info:\n"); |
| 1313 | |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 1314 | for (i = 0; i < strings->len; i++) { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1315 | fprintf(stdout, "%s\t %d\n", |
| 1316 | (char *)(strings->data + i * ETH_GSTRING_LEN), |
| 1317 | (u32) test->data[i]); |
| 1318 | } |
| 1319 | |
| 1320 | fprintf(stdout, "\n"); |
| 1321 | return rc; |
| 1322 | } |
| 1323 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1324 | static int dump_pause(const struct ethtool_pauseparam *epause, |
| 1325 | u32 advertising, u32 lp_advertising) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1326 | { |
| 1327 | fprintf(stdout, |
| 1328 | "Autonegotiate: %s\n" |
| 1329 | "RX: %s\n" |
| 1330 | "TX: %s\n", |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1331 | epause->autoneg ? "on" : "off", |
| 1332 | epause->rx_pause ? "on" : "off", |
| 1333 | epause->tx_pause ? "on" : "off"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1334 | |
Ben Hutchings | 6e50ac0 | 2011-10-19 20:52:12 +0100 | [diff] [blame] | 1335 | if (lp_advertising) { |
| 1336 | int an_rx = 0, an_tx = 0; |
| 1337 | |
| 1338 | /* Work out negotiated pause frame usage per |
| 1339 | * IEEE 802.3-2005 table 28B-3. |
| 1340 | */ |
| 1341 | if (advertising & lp_advertising & ADVERTISED_Pause) { |
| 1342 | an_tx = 1; |
| 1343 | an_rx = 1; |
| 1344 | } else if (advertising & lp_advertising & |
| 1345 | ADVERTISED_Asym_Pause) { |
| 1346 | if (advertising & ADVERTISED_Pause) |
| 1347 | an_rx = 1; |
| 1348 | else if (lp_advertising & ADVERTISED_Pause) |
| 1349 | an_tx = 1; |
| 1350 | } |
| 1351 | |
| 1352 | fprintf(stdout, |
| 1353 | "RX negotiated: %s\n" |
| 1354 | "TX negotiated: %s\n", |
| 1355 | an_rx ? "on" : "off", |
| 1356 | an_tx ? "on" : "off"); |
| 1357 | } |
| 1358 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1359 | fprintf(stdout, "\n"); |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1363 | static int dump_ring(const struct ethtool_ringparam *ering) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1364 | { |
| 1365 | fprintf(stdout, |
| 1366 | "Pre-set maximums:\n" |
| 1367 | "RX: %u\n" |
| 1368 | "RX Mini: %u\n" |
| 1369 | "RX Jumbo: %u\n" |
| 1370 | "TX: %u\n", |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1371 | ering->rx_max_pending, |
| 1372 | ering->rx_mini_max_pending, |
| 1373 | ering->rx_jumbo_max_pending, |
| 1374 | ering->tx_max_pending); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1375 | |
| 1376 | fprintf(stdout, |
| 1377 | "Current hardware settings:\n" |
| 1378 | "RX: %u\n" |
| 1379 | "RX Mini: %u\n" |
| 1380 | "RX Jumbo: %u\n" |
| 1381 | "TX: %u\n", |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1382 | ering->rx_pending, |
| 1383 | ering->rx_mini_pending, |
| 1384 | ering->rx_jumbo_pending, |
| 1385 | ering->tx_pending); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1386 | |
| 1387 | fprintf(stdout, "\n"); |
| 1388 | return 0; |
| 1389 | } |
| 1390 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1391 | static int dump_channels(const struct ethtool_channels *echannels) |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 1392 | { |
| 1393 | fprintf(stdout, |
| 1394 | "Pre-set maximums:\n" |
| 1395 | "RX: %u\n" |
| 1396 | "TX: %u\n" |
| 1397 | "Other: %u\n" |
| 1398 | "Combined: %u\n", |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1399 | echannels->max_rx, echannels->max_tx, |
| 1400 | echannels->max_other, |
| 1401 | echannels->max_combined); |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 1402 | |
| 1403 | fprintf(stdout, |
| 1404 | "Current hardware settings:\n" |
| 1405 | "RX: %u\n" |
| 1406 | "TX: %u\n" |
| 1407 | "Other: %u\n" |
| 1408 | "Combined: %u\n", |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1409 | echannels->rx_count, echannels->tx_count, |
| 1410 | echannels->other_count, |
| 1411 | echannels->combined_count); |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 1412 | |
| 1413 | fprintf(stdout, "\n"); |
| 1414 | return 0; |
| 1415 | } |
| 1416 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1417 | static int dump_coalesce(const struct ethtool_coalesce *ecoal) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1418 | { |
| 1419 | fprintf(stdout, "Adaptive RX: %s TX: %s\n", |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1420 | ecoal->use_adaptive_rx_coalesce ? "on" : "off", |
| 1421 | ecoal->use_adaptive_tx_coalesce ? "on" : "off"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1422 | |
| 1423 | fprintf(stdout, |
| 1424 | "stats-block-usecs: %u\n" |
| 1425 | "sample-interval: %u\n" |
| 1426 | "pkt-rate-low: %u\n" |
| 1427 | "pkt-rate-high: %u\n" |
| 1428 | "\n" |
| 1429 | "rx-usecs: %u\n" |
| 1430 | "rx-frames: %u\n" |
| 1431 | "rx-usecs-irq: %u\n" |
| 1432 | "rx-frames-irq: %u\n" |
| 1433 | "\n" |
| 1434 | "tx-usecs: %u\n" |
| 1435 | "tx-frames: %u\n" |
| 1436 | "tx-usecs-irq: %u\n" |
| 1437 | "tx-frames-irq: %u\n" |
| 1438 | "\n" |
| 1439 | "rx-usecs-low: %u\n" |
Nicholas Nunley | 66501a7 | 2019-03-01 00:15:32 -0800 | [diff] [blame] | 1440 | "rx-frames-low: %u\n" |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1441 | "tx-usecs-low: %u\n" |
Nicholas Nunley | 66501a7 | 2019-03-01 00:15:32 -0800 | [diff] [blame] | 1442 | "tx-frames-low: %u\n" |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1443 | "\n" |
| 1444 | "rx-usecs-high: %u\n" |
Nicholas Nunley | 66501a7 | 2019-03-01 00:15:32 -0800 | [diff] [blame] | 1445 | "rx-frames-high: %u\n" |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1446 | "tx-usecs-high: %u\n" |
Nicholas Nunley | 66501a7 | 2019-03-01 00:15:32 -0800 | [diff] [blame] | 1447 | "tx-frames-high: %u\n" |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1448 | "\n", |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1449 | ecoal->stats_block_coalesce_usecs, |
| 1450 | ecoal->rate_sample_interval, |
| 1451 | ecoal->pkt_rate_low, |
| 1452 | ecoal->pkt_rate_high, |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1453 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1454 | ecoal->rx_coalesce_usecs, |
| 1455 | ecoal->rx_max_coalesced_frames, |
| 1456 | ecoal->rx_coalesce_usecs_irq, |
| 1457 | ecoal->rx_max_coalesced_frames_irq, |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1458 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1459 | ecoal->tx_coalesce_usecs, |
| 1460 | ecoal->tx_max_coalesced_frames, |
| 1461 | ecoal->tx_coalesce_usecs_irq, |
| 1462 | ecoal->tx_max_coalesced_frames_irq, |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1463 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1464 | ecoal->rx_coalesce_usecs_low, |
| 1465 | ecoal->rx_max_coalesced_frames_low, |
| 1466 | ecoal->tx_coalesce_usecs_low, |
| 1467 | ecoal->tx_max_coalesced_frames_low, |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1468 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1469 | ecoal->rx_coalesce_usecs_high, |
| 1470 | ecoal->rx_max_coalesced_frames_high, |
| 1471 | ecoal->tx_coalesce_usecs_high, |
| 1472 | ecoal->tx_max_coalesced_frames_high); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1473 | |
| 1474 | return 0; |
| 1475 | } |
| 1476 | |
Nicholas Nunley | 52ecd6e | 2019-03-01 00:15:30 -0800 | [diff] [blame] | 1477 | void dump_per_queue_coalesce(struct ethtool_per_queue_op *per_queue_opt, |
| 1478 | __u32 *queue_mask, int n_queues) |
| 1479 | { |
| 1480 | struct ethtool_coalesce *ecoal; |
| 1481 | int i, idx = 0; |
| 1482 | |
| 1483 | ecoal = (struct ethtool_coalesce *)(per_queue_opt + 1); |
| 1484 | for (i = 0; i < __KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32); i++) { |
| 1485 | int queue = i * 32; |
| 1486 | __u32 mask = queue_mask[i]; |
| 1487 | |
| 1488 | while (mask > 0) { |
| 1489 | if (mask & 0x1) { |
| 1490 | fprintf(stdout, "Queue: %d\n", queue); |
| 1491 | dump_coalesce(ecoal + idx); |
| 1492 | idx++; |
| 1493 | } |
| 1494 | mask = mask >> 1; |
| 1495 | queue++; |
| 1496 | } |
| 1497 | if (idx == n_queues) |
| 1498 | break; |
| 1499 | } |
| 1500 | } |
| 1501 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 1502 | struct feature_state { |
| 1503 | u32 off_flags; |
| 1504 | struct ethtool_gfeatures features; |
| 1505 | }; |
| 1506 | |
| 1507 | static void dump_one_feature(const char *indent, const char *name, |
| 1508 | const struct feature_state *state, |
| 1509 | const struct feature_state *ref_state, |
| 1510 | u32 index) |
| 1511 | { |
| 1512 | if (ref_state && |
| 1513 | !(FEATURE_BIT_IS_SET(state->features.features, index, active) ^ |
| 1514 | FEATURE_BIT_IS_SET(ref_state->features.features, index, active))) |
| 1515 | return; |
| 1516 | |
| 1517 | printf("%s%s: %s%s\n", |
| 1518 | indent, name, |
| 1519 | FEATURE_BIT_IS_SET(state->features.features, index, active) ? |
| 1520 | "on" : "off", |
| 1521 | (!FEATURE_BIT_IS_SET(state->features.features, index, available) |
| 1522 | || FEATURE_BIT_IS_SET(state->features.features, index, |
| 1523 | never_changed)) |
| 1524 | ? " [fixed]" |
| 1525 | : (FEATURE_BIT_IS_SET(state->features.features, index, requested) |
| 1526 | ^ FEATURE_BIT_IS_SET(state->features.features, index, active)) |
| 1527 | ? (FEATURE_BIT_IS_SET(state->features.features, index, requested) |
| 1528 | ? " [requested on]" : " [requested off]") |
| 1529 | : ""); |
| 1530 | } |
| 1531 | |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 1532 | static int linux_version_code(void) |
| 1533 | { |
| 1534 | struct utsname utsname; |
| 1535 | unsigned version, patchlevel, sublevel = 0; |
| 1536 | |
| 1537 | if (uname(&utsname)) |
| 1538 | return -1; |
| 1539 | if (sscanf(utsname.release, "%u.%u.%u", &version, &patchlevel, &sublevel) < 2) |
| 1540 | return -1; |
| 1541 | return KERNEL_VERSION(version, patchlevel, sublevel); |
| 1542 | } |
| 1543 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 1544 | static void dump_features(const struct feature_defs *defs, |
| 1545 | const struct feature_state *state, |
| 1546 | const struct feature_state *ref_state) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1547 | { |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 1548 | int kernel_ver = linux_version_code(); |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 1549 | u32 value; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 1550 | int indent; |
| 1551 | int i, j; |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 1552 | |
| 1553 | for (i = 0; i < ARRAY_SIZE(off_flag_def); i++) { |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 1554 | /* Don't show features whose state is unknown on this |
| 1555 | * kernel version |
| 1556 | */ |
| 1557 | if (defs->off_flag_matched[i] == 0 && |
Ivan Vecera | 8f05538 | 2018-11-29 16:36:53 +0100 | [diff] [blame] | 1558 | ((off_flag_def[i].get_cmd == 0 && |
| 1559 | kernel_ver < off_flag_def[i].min_kernel_ver) || |
| 1560 | (off_flag_def[i].get_cmd == ETHTOOL_GUFO && |
| 1561 | kernel_ver >= KERNEL_VERSION(4, 14, 0)))) |
Ben Hutchings | ec0ff77 | 2013-09-19 22:12:46 +0100 | [diff] [blame] | 1562 | continue; |
| 1563 | |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 1564 | value = off_flag_def[i].value; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 1565 | |
| 1566 | /* If this offload flag matches exactly one generic |
| 1567 | * feature then it's redundant to show the flag and |
| 1568 | * feature states separately. Otherwise, show the |
| 1569 | * flag state first. |
| 1570 | */ |
| 1571 | if (defs->off_flag_matched[i] != 1 && |
| 1572 | (!ref_state || |
| 1573 | (state->off_flags ^ ref_state->off_flags) & value)) { |
| 1574 | printf("%s: %s\n", |
| 1575 | off_flag_def[i].long_name, |
| 1576 | (state->off_flags & value) ? "on" : "off"); |
| 1577 | indent = 1; |
| 1578 | } else { |
| 1579 | indent = 0; |
| 1580 | } |
| 1581 | |
| 1582 | /* Show matching features */ |
| 1583 | for (j = 0; j < defs->n_features; j++) { |
| 1584 | if (defs->def[j].off_flag_index != i) |
| 1585 | continue; |
| 1586 | if (defs->off_flag_matched[i] != 1) |
| 1587 | /* Show all matching feature states */ |
| 1588 | dump_one_feature(indent ? "\t" : "", |
| 1589 | defs->def[j].name, |
| 1590 | state, ref_state, j); |
| 1591 | else |
| 1592 | /* Show full state with the old flag name */ |
| 1593 | dump_one_feature("", off_flag_def[i].long_name, |
| 1594 | state, ref_state, j); |
| 1595 | } |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 1596 | } |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1597 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 1598 | /* Show all unmatched features that have non-null names */ |
| 1599 | for (j = 0; j < defs->n_features; j++) |
| 1600 | if (defs->def[j].off_flag_index < 0 && defs->def[j].name[0]) |
| 1601 | dump_one_feature("", defs->def[j].name, |
| 1602 | state, ref_state, j); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1603 | } |
| 1604 | |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1605 | static int dump_rxfhash(int fhash, u64 val) |
| 1606 | { |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 1607 | switch (fhash & ~FLOW_RSS) { |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1608 | case TCP_V4_FLOW: |
| 1609 | fprintf(stdout, "TCP over IPV4 flows"); |
| 1610 | break; |
| 1611 | case UDP_V4_FLOW: |
| 1612 | fprintf(stdout, "UDP over IPV4 flows"); |
| 1613 | break; |
| 1614 | case SCTP_V4_FLOW: |
| 1615 | fprintf(stdout, "SCTP over IPV4 flows"); |
| 1616 | break; |
| 1617 | case AH_ESP_V4_FLOW: |
Alexander Duyck | b400111 | 2011-04-21 13:40:20 -0700 | [diff] [blame] | 1618 | case AH_V4_FLOW: |
| 1619 | case ESP_V4_FLOW: |
| 1620 | fprintf(stdout, "IPSEC AH/ESP over IPV4 flows"); |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1621 | break; |
| 1622 | case TCP_V6_FLOW: |
| 1623 | fprintf(stdout, "TCP over IPV6 flows"); |
| 1624 | break; |
| 1625 | case UDP_V6_FLOW: |
| 1626 | fprintf(stdout, "UDP over IPV6 flows"); |
| 1627 | break; |
| 1628 | case SCTP_V6_FLOW: |
| 1629 | fprintf(stdout, "SCTP over IPV6 flows"); |
| 1630 | break; |
| 1631 | case AH_ESP_V6_FLOW: |
Alexander Duyck | b400111 | 2011-04-21 13:40:20 -0700 | [diff] [blame] | 1632 | case AH_V6_FLOW: |
| 1633 | case ESP_V6_FLOW: |
| 1634 | fprintf(stdout, "IPSEC AH/ESP over IPV6 flows"); |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1635 | break; |
| 1636 | default: |
| 1637 | break; |
| 1638 | } |
| 1639 | |
| 1640 | if (val & RXH_DISCARD) { |
| 1641 | fprintf(stdout, " - All matching flows discarded on RX\n"); |
| 1642 | return 0; |
| 1643 | } |
| 1644 | fprintf(stdout, " use these fields for computing Hash flow key:\n"); |
| 1645 | |
| 1646 | fprintf(stdout, "%s\n", unparse_rxfhashopts(val)); |
Jeff Garzik | a97a2ec | 2009-03-06 06:12:13 -0500 | [diff] [blame] | 1647 | |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 1648 | return 0; |
| 1649 | } |
| 1650 | |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 1651 | static void dump_eeecmd(struct ethtool_eee *ep) |
| 1652 | { |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 1653 | ETHTOOL_DECLARE_LINK_MODE_MASK(link_mode); |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 1654 | |
| 1655 | fprintf(stdout, " EEE status: "); |
| 1656 | if (!ep->supported) { |
| 1657 | fprintf(stdout, "not supported\n"); |
| 1658 | return; |
| 1659 | } else if (!ep->eee_enabled) { |
| 1660 | fprintf(stdout, "disabled\n"); |
| 1661 | } else { |
| 1662 | fprintf(stdout, "enabled - "); |
| 1663 | if (ep->eee_active) |
| 1664 | fprintf(stdout, "active\n"); |
| 1665 | else |
| 1666 | fprintf(stdout, "inactive\n"); |
| 1667 | } |
| 1668 | |
| 1669 | fprintf(stdout, " Tx LPI:"); |
| 1670 | if (ep->tx_lpi_enabled) |
| 1671 | fprintf(stdout, " %d (us)\n", ep->tx_lpi_timer); |
| 1672 | else |
| 1673 | fprintf(stdout, " disabled\n"); |
| 1674 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 1675 | ethtool_link_mode_zero(link_mode); |
| 1676 | |
| 1677 | link_mode[0] = ep->supported; |
| 1678 | dump_link_caps("Supported EEE", "", link_mode, 1); |
| 1679 | |
| 1680 | link_mode[0] = ep->advertised; |
| 1681 | dump_link_caps("Advertised EEE", "", link_mode, 1); |
| 1682 | |
| 1683 | link_mode[0] = ep->lp_advertised; |
| 1684 | dump_link_caps("Link partner advertised EEE", "", link_mode, 1); |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 1685 | } |
| 1686 | |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 1687 | static void dump_fec(u32 fec) |
| 1688 | { |
| 1689 | if (fec & ETHTOOL_FEC_NONE) |
| 1690 | fprintf(stdout, " None"); |
| 1691 | if (fec & ETHTOOL_FEC_AUTO) |
| 1692 | fprintf(stdout, " Auto"); |
| 1693 | if (fec & ETHTOOL_FEC_OFF) |
| 1694 | fprintf(stdout, " Off"); |
| 1695 | if (fec & ETHTOOL_FEC_BASER) |
| 1696 | fprintf(stdout, " BaseR"); |
| 1697 | if (fec & ETHTOOL_FEC_RS) |
| 1698 | fprintf(stdout, " RS"); |
| 1699 | } |
| 1700 | |
Richard Cochran | 0fdcc8c | 2012-04-03 19:58:23 +0200 | [diff] [blame] | 1701 | #define N_SOTS 7 |
| 1702 | |
| 1703 | static char *so_timestamping_labels[N_SOTS] = { |
| 1704 | "hardware-transmit (SOF_TIMESTAMPING_TX_HARDWARE)", |
| 1705 | "software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE)", |
| 1706 | "hardware-receive (SOF_TIMESTAMPING_RX_HARDWARE)", |
| 1707 | "software-receive (SOF_TIMESTAMPING_RX_SOFTWARE)", |
| 1708 | "software-system-clock (SOF_TIMESTAMPING_SOFTWARE)", |
| 1709 | "hardware-legacy-clock (SOF_TIMESTAMPING_SYS_HARDWARE)", |
| 1710 | "hardware-raw-clock (SOF_TIMESTAMPING_RAW_HARDWARE)", |
| 1711 | }; |
| 1712 | |
| 1713 | #define N_TX_TYPES (HWTSTAMP_TX_ONESTEP_SYNC + 1) |
| 1714 | |
| 1715 | static char *tx_type_labels[N_TX_TYPES] = { |
| 1716 | "off (HWTSTAMP_TX_OFF)", |
| 1717 | "on (HWTSTAMP_TX_ON)", |
| 1718 | "one-step-sync (HWTSTAMP_TX_ONESTEP_SYNC)", |
| 1719 | }; |
| 1720 | |
Miroslav Lichvar | d976d5d | 2017-05-23 16:29:30 +0200 | [diff] [blame] | 1721 | #define N_RX_FILTERS (HWTSTAMP_FILTER_NTP_ALL + 1) |
Richard Cochran | 0fdcc8c | 2012-04-03 19:58:23 +0200 | [diff] [blame] | 1722 | |
| 1723 | static char *rx_filter_labels[N_RX_FILTERS] = { |
| 1724 | "none (HWTSTAMP_FILTER_NONE)", |
| 1725 | "all (HWTSTAMP_FILTER_ALL)", |
| 1726 | "some (HWTSTAMP_FILTER_SOME)", |
| 1727 | "ptpv1-l4-event (HWTSTAMP_FILTER_PTP_V1_L4_EVENT)", |
| 1728 | "ptpv1-l4-sync (HWTSTAMP_FILTER_PTP_V1_L4_SYNC)", |
| 1729 | "ptpv1-l4-delay-req (HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ)", |
| 1730 | "ptpv2-l4-event (HWTSTAMP_FILTER_PTP_V2_L4_EVENT)", |
| 1731 | "ptpv2-l4-sync (HWTSTAMP_FILTER_PTP_V2_L4_SYNC)", |
| 1732 | "ptpv2-l4-delay-req (HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ)", |
| 1733 | "ptpv2-l2-event (HWTSTAMP_FILTER_PTP_V2_L2_EVENT)", |
| 1734 | "ptpv2-l2-sync (HWTSTAMP_FILTER_PTP_V2_L2_SYNC)", |
| 1735 | "ptpv2-l2-delay-req (HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ)", |
| 1736 | "ptpv2-event (HWTSTAMP_FILTER_PTP_V2_EVENT)", |
| 1737 | "ptpv2-sync (HWTSTAMP_FILTER_PTP_V2_SYNC)", |
| 1738 | "ptpv2-delay-req (HWTSTAMP_FILTER_PTP_V2_DELAY_REQ)", |
Miroslav Lichvar | d976d5d | 2017-05-23 16:29:30 +0200 | [diff] [blame] | 1739 | "ntp-all (HWTSTAMP_FILTER_NTP_ALL)", |
Richard Cochran | 0fdcc8c | 2012-04-03 19:58:23 +0200 | [diff] [blame] | 1740 | }; |
| 1741 | |
| 1742 | static int dump_tsinfo(const struct ethtool_ts_info *info) |
| 1743 | { |
| 1744 | int i; |
| 1745 | |
| 1746 | fprintf(stdout, "Capabilities:\n"); |
| 1747 | |
| 1748 | for (i = 0; i < N_SOTS; i++) { |
| 1749 | if (info->so_timestamping & (1 << i)) |
| 1750 | fprintf(stdout, "\t%s\n", so_timestamping_labels[i]); |
| 1751 | } |
| 1752 | |
| 1753 | fprintf(stdout, "PTP Hardware Clock: "); |
| 1754 | |
| 1755 | if (info->phc_index < 0) |
| 1756 | fprintf(stdout, "none\n"); |
| 1757 | else |
| 1758 | fprintf(stdout, "%d\n", info->phc_index); |
| 1759 | |
| 1760 | fprintf(stdout, "Hardware Transmit Timestamp Modes:"); |
| 1761 | |
| 1762 | if (!info->tx_types) |
| 1763 | fprintf(stdout, " none\n"); |
| 1764 | else |
| 1765 | fprintf(stdout, "\n"); |
| 1766 | |
| 1767 | for (i = 0; i < N_TX_TYPES; i++) { |
| 1768 | if (info->tx_types & (1 << i)) |
| 1769 | fprintf(stdout, "\t%s\n", tx_type_labels[i]); |
| 1770 | } |
| 1771 | |
| 1772 | fprintf(stdout, "Hardware Receive Filter Modes:"); |
| 1773 | |
| 1774 | if (!info->rx_filters) |
| 1775 | fprintf(stdout, " none\n"); |
| 1776 | else |
| 1777 | fprintf(stdout, "\n"); |
| 1778 | |
| 1779 | for (i = 0; i < N_RX_FILTERS; i++) { |
| 1780 | if (info->rx_filters & (1 << i)) |
| 1781 | fprintf(stdout, "\t%s\n", rx_filter_labels[i]); |
| 1782 | } |
| 1783 | |
| 1784 | return 0; |
| 1785 | } |
| 1786 | |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 1787 | static struct ethtool_gstrings * |
| 1788 | get_stringset(struct cmd_context *ctx, enum ethtool_stringset set_id, |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 1789 | ptrdiff_t drvinfo_offset, int null_terminate) |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 1790 | { |
| 1791 | struct { |
| 1792 | struct ethtool_sset_info hdr; |
| 1793 | u32 buf[1]; |
| 1794 | } sset_info; |
| 1795 | struct ethtool_drvinfo drvinfo; |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 1796 | u32 len, i; |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 1797 | struct ethtool_gstrings *strings; |
| 1798 | |
| 1799 | sset_info.hdr.cmd = ETHTOOL_GSSET_INFO; |
| 1800 | sset_info.hdr.reserved = 0; |
| 1801 | sset_info.hdr.sset_mask = 1ULL << set_id; |
| 1802 | if (send_ioctl(ctx, &sset_info) == 0) { |
| 1803 | len = sset_info.hdr.sset_mask ? sset_info.hdr.data[0] : 0; |
| 1804 | } else if (errno == EOPNOTSUPP && drvinfo_offset != 0) { |
| 1805 | /* Fallback for old kernel versions */ |
| 1806 | drvinfo.cmd = ETHTOOL_GDRVINFO; |
| 1807 | if (send_ioctl(ctx, &drvinfo)) |
| 1808 | return NULL; |
| 1809 | len = *(u32 *)((char *)&drvinfo + drvinfo_offset); |
| 1810 | } else { |
| 1811 | return NULL; |
| 1812 | } |
| 1813 | |
| 1814 | strings = calloc(1, sizeof(*strings) + len * ETH_GSTRING_LEN); |
| 1815 | if (!strings) |
| 1816 | return NULL; |
| 1817 | |
| 1818 | strings->cmd = ETHTOOL_GSTRINGS; |
| 1819 | strings->string_set = set_id; |
| 1820 | strings->len = len; |
| 1821 | if (len != 0 && send_ioctl(ctx, strings)) { |
| 1822 | free(strings); |
| 1823 | return NULL; |
| 1824 | } |
| 1825 | |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 1826 | if (null_terminate) |
| 1827 | for (i = 0; i < len; i++) |
| 1828 | strings->data[(i + 1) * ETH_GSTRING_LEN - 1] = 0; |
| 1829 | |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 1830 | return strings; |
| 1831 | } |
| 1832 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 1833 | static struct feature_defs *get_feature_defs(struct cmd_context *ctx) |
| 1834 | { |
| 1835 | struct ethtool_gstrings *names; |
| 1836 | struct feature_defs *defs; |
| 1837 | u32 n_features; |
| 1838 | int i, j; |
| 1839 | |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 1840 | names = get_stringset(ctx, ETH_SS_FEATURES, 0, 1); |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 1841 | if (names) { |
| 1842 | n_features = names->len; |
| 1843 | } else if (errno == EOPNOTSUPP || errno == EINVAL) { |
| 1844 | /* Kernel doesn't support named features; not an error */ |
| 1845 | n_features = 0; |
Ben Hutchings | 1eef677 | 2012-06-13 00:57:06 +0100 | [diff] [blame] | 1846 | } else if (errno == EPERM) { |
| 1847 | /* Kernel bug: ETHTOOL_GSSET_INFO was privileged. |
| 1848 | * Work around it. */ |
| 1849 | n_features = 0; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 1850 | } else { |
| 1851 | return NULL; |
| 1852 | } |
| 1853 | |
| 1854 | defs = malloc(sizeof(*defs) + sizeof(defs->def[0]) * n_features); |
John W. Linville | 9674a82 | 2016-09-30 14:57:27 -0400 | [diff] [blame] | 1855 | if (!defs) { |
| 1856 | free(names); |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 1857 | return NULL; |
John W. Linville | 9674a82 | 2016-09-30 14:57:27 -0400 | [diff] [blame] | 1858 | } |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 1859 | |
| 1860 | defs->n_features = n_features; |
| 1861 | memset(defs->off_flag_matched, 0, sizeof(defs->off_flag_matched)); |
| 1862 | |
| 1863 | /* Copy out feature names and find those associated with legacy flags */ |
| 1864 | for (i = 0; i < defs->n_features; i++) { |
| 1865 | memcpy(defs->def[i].name, names->data + i * ETH_GSTRING_LEN, |
| 1866 | ETH_GSTRING_LEN); |
| 1867 | defs->def[i].off_flag_index = -1; |
| 1868 | |
| 1869 | for (j = 0; |
| 1870 | j < ARRAY_SIZE(off_flag_def) && |
| 1871 | defs->def[i].off_flag_index < 0; |
| 1872 | j++) { |
| 1873 | const char *pattern = |
| 1874 | off_flag_def[j].kernel_name; |
| 1875 | const char *name = defs->def[i].name; |
| 1876 | for (;;) { |
| 1877 | if (*pattern == '*') { |
| 1878 | /* There is only one wildcard; so |
| 1879 | * switch to a suffix comparison */ |
| 1880 | size_t pattern_len = |
| 1881 | strlen(pattern + 1); |
| 1882 | size_t name_len = strlen(name); |
| 1883 | if (name_len < pattern_len) |
| 1884 | break; /* name is too short */ |
| 1885 | name += name_len - pattern_len; |
| 1886 | ++pattern; |
| 1887 | } else if (*pattern != *name) { |
| 1888 | break; /* mismatch */ |
| 1889 | } else if (*pattern == 0) { |
| 1890 | defs->def[i].off_flag_index = j; |
| 1891 | defs->off_flag_matched[j]++; |
| 1892 | break; |
| 1893 | } else { |
| 1894 | ++name; |
| 1895 | ++pattern; |
| 1896 | } |
| 1897 | } |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | free(names); |
| 1902 | return defs; |
| 1903 | } |
| 1904 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 1905 | static int do_gdrv(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1906 | { |
| 1907 | int err; |
| 1908 | struct ethtool_drvinfo drvinfo; |
| 1909 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 1910 | if (ctx->argc != 0) |
| 1911 | exit_bad_args(); |
| 1912 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1913 | drvinfo.cmd = ETHTOOL_GDRVINFO; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 1914 | err = send_ioctl(ctx, &drvinfo); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1915 | if (err < 0) { |
| 1916 | perror("Cannot get driver information"); |
| 1917 | return 71; |
| 1918 | } |
| 1919 | return dump_drvinfo(&drvinfo); |
| 1920 | } |
| 1921 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 1922 | static int do_gpause(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1923 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1924 | struct ethtool_pauseparam epause; |
Ben Hutchings | 6e50ac0 | 2011-10-19 20:52:12 +0100 | [diff] [blame] | 1925 | struct ethtool_cmd ecmd; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1926 | int err; |
| 1927 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 1928 | if (ctx->argc != 0) |
| 1929 | exit_bad_args(); |
| 1930 | |
Ben Hutchings | 743eb0b | 2011-10-29 02:36:48 +0100 | [diff] [blame] | 1931 | fprintf(stdout, "Pause parameters for %s:\n", ctx->devname); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1932 | |
| 1933 | epause.cmd = ETHTOOL_GPAUSEPARAM; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 1934 | err = send_ioctl(ctx, &epause); |
Ben Hutchings | 6e50ac0 | 2011-10-19 20:52:12 +0100 | [diff] [blame] | 1935 | if (err) { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1936 | perror("Cannot get device pause settings"); |
| 1937 | return 76; |
| 1938 | } |
| 1939 | |
Ben Hutchings | 6e50ac0 | 2011-10-19 20:52:12 +0100 | [diff] [blame] | 1940 | if (epause.autoneg) { |
| 1941 | ecmd.cmd = ETHTOOL_GSET; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 1942 | err = send_ioctl(ctx, &ecmd); |
Ben Hutchings | 6e50ac0 | 2011-10-19 20:52:12 +0100 | [diff] [blame] | 1943 | if (err) { |
| 1944 | perror("Cannot get device settings"); |
| 1945 | return 1; |
| 1946 | } |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1947 | dump_pause(&epause, ecmd.advertising, ecmd.lp_advertising); |
Ben Hutchings | 6e50ac0 | 2011-10-19 20:52:12 +0100 | [diff] [blame] | 1948 | } else { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1949 | dump_pause(&epause, 0, 0); |
Ben Hutchings | 6e50ac0 | 2011-10-19 20:52:12 +0100 | [diff] [blame] | 1950 | } |
| 1951 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1952 | return 0; |
| 1953 | } |
| 1954 | |
| 1955 | static void do_generic_set1(struct cmdline_info *info, int *changed_out) |
| 1956 | { |
| 1957 | int wanted, *v1, *v2; |
| 1958 | |
| 1959 | v1 = info->wanted_val; |
| 1960 | wanted = *v1; |
| 1961 | |
| 1962 | if (wanted < 0) |
| 1963 | return; |
| 1964 | |
| 1965 | v2 = info->ioctl_val; |
| 1966 | if (wanted == *v2) { |
| 1967 | fprintf(stderr, "%s unmodified, ignoring\n", info->name); |
| 1968 | } else { |
| 1969 | *v2 = wanted; |
| 1970 | *changed_out = 1; |
| 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | static void do_generic_set(struct cmdline_info *info, |
| 1975 | unsigned int n_info, |
| 1976 | int *changed_out) |
| 1977 | { |
| 1978 | unsigned int i; |
| 1979 | |
| 1980 | for (i = 0; i < n_info; i++) |
| 1981 | do_generic_set1(&info[i], changed_out); |
| 1982 | } |
| 1983 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 1984 | static int do_spause(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1985 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 1986 | struct ethtool_pauseparam epause; |
| 1987 | int gpause_changed = 0; |
| 1988 | int pause_autoneg_wanted = -1; |
| 1989 | int pause_rx_wanted = -1; |
| 1990 | int pause_tx_wanted = -1; |
| 1991 | struct cmdline_info cmdline_pause[] = { |
| 1992 | { "autoneg", CMDL_BOOL, &pause_autoneg_wanted, |
| 1993 | &epause.autoneg }, |
| 1994 | { "rx", CMDL_BOOL, &pause_rx_wanted, &epause.rx_pause }, |
| 1995 | { "tx", CMDL_BOOL, &pause_tx_wanted, &epause.tx_pause }, |
| 1996 | }; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 1997 | int err, changed = 0; |
| 1998 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 1999 | parse_generic_cmdline(ctx, &gpause_changed, |
| 2000 | cmdline_pause, ARRAY_SIZE(cmdline_pause)); |
| 2001 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2002 | epause.cmd = ETHTOOL_GPAUSEPARAM; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2003 | err = send_ioctl(ctx, &epause); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2004 | if (err) { |
| 2005 | perror("Cannot get device pause settings"); |
| 2006 | return 77; |
| 2007 | } |
| 2008 | |
| 2009 | do_generic_set(cmdline_pause, ARRAY_SIZE(cmdline_pause), &changed); |
| 2010 | |
| 2011 | if (!changed) { |
| 2012 | fprintf(stderr, "no pause parameters changed, aborting\n"); |
| 2013 | return 78; |
| 2014 | } |
| 2015 | |
| 2016 | epause.cmd = ETHTOOL_SPAUSEPARAM; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2017 | err = send_ioctl(ctx, &epause); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2018 | if (err) { |
| 2019 | perror("Cannot set device pause parameters"); |
| 2020 | return 79; |
| 2021 | } |
| 2022 | |
| 2023 | return 0; |
| 2024 | } |
| 2025 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2026 | static int do_sring(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2027 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2028 | struct ethtool_ringparam ering; |
| 2029 | int gring_changed = 0; |
| 2030 | s32 ring_rx_wanted = -1; |
| 2031 | s32 ring_rx_mini_wanted = -1; |
| 2032 | s32 ring_rx_jumbo_wanted = -1; |
| 2033 | s32 ring_tx_wanted = -1; |
| 2034 | struct cmdline_info cmdline_ring[] = { |
| 2035 | { "rx", CMDL_S32, &ring_rx_wanted, &ering.rx_pending }, |
| 2036 | { "rx-mini", CMDL_S32, &ring_rx_mini_wanted, |
| 2037 | &ering.rx_mini_pending }, |
| 2038 | { "rx-jumbo", CMDL_S32, &ring_rx_jumbo_wanted, |
| 2039 | &ering.rx_jumbo_pending }, |
| 2040 | { "tx", CMDL_S32, &ring_tx_wanted, &ering.tx_pending }, |
| 2041 | }; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2042 | int err, changed = 0; |
| 2043 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2044 | parse_generic_cmdline(ctx, &gring_changed, |
| 2045 | cmdline_ring, ARRAY_SIZE(cmdline_ring)); |
| 2046 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2047 | ering.cmd = ETHTOOL_GRINGPARAM; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2048 | err = send_ioctl(ctx, &ering); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2049 | if (err) { |
| 2050 | perror("Cannot get device ring settings"); |
| 2051 | return 76; |
| 2052 | } |
| 2053 | |
| 2054 | do_generic_set(cmdline_ring, ARRAY_SIZE(cmdline_ring), &changed); |
| 2055 | |
| 2056 | if (!changed) { |
| 2057 | fprintf(stderr, "no ring parameters changed, aborting\n"); |
| 2058 | return 80; |
| 2059 | } |
| 2060 | |
| 2061 | ering.cmd = ETHTOOL_SRINGPARAM; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2062 | err = send_ioctl(ctx, &ering); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2063 | if (err) { |
| 2064 | perror("Cannot set device ring parameters"); |
| 2065 | return 81; |
| 2066 | } |
| 2067 | |
| 2068 | return 0; |
| 2069 | } |
| 2070 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2071 | static int do_gring(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2072 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2073 | struct ethtool_ringparam ering; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2074 | int err; |
| 2075 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2076 | if (ctx->argc != 0) |
| 2077 | exit_bad_args(); |
| 2078 | |
Ben Hutchings | 743eb0b | 2011-10-29 02:36:48 +0100 | [diff] [blame] | 2079 | fprintf(stdout, "Ring parameters for %s:\n", ctx->devname); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2080 | |
| 2081 | ering.cmd = ETHTOOL_GRINGPARAM; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2082 | err = send_ioctl(ctx, &ering); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2083 | if (err == 0) { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2084 | err = dump_ring(&ering); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2085 | if (err) |
| 2086 | return err; |
| 2087 | } else { |
| 2088 | perror("Cannot get device ring settings"); |
| 2089 | return 76; |
| 2090 | } |
| 2091 | |
| 2092 | return 0; |
| 2093 | } |
| 2094 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2095 | static int do_schannels(struct cmd_context *ctx) |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2096 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2097 | struct ethtool_channels echannels; |
| 2098 | int gchannels_changed; |
| 2099 | s32 channels_rx_wanted = -1; |
| 2100 | s32 channels_tx_wanted = -1; |
| 2101 | s32 channels_other_wanted = -1; |
| 2102 | s32 channels_combined_wanted = -1; |
| 2103 | struct cmdline_info cmdline_channels[] = { |
| 2104 | { "rx", CMDL_S32, &channels_rx_wanted, &echannels.rx_count }, |
| 2105 | { "tx", CMDL_S32, &channels_tx_wanted, &echannels.tx_count }, |
| 2106 | { "other", CMDL_S32, &channels_other_wanted, |
| 2107 | &echannels.other_count }, |
| 2108 | { "combined", CMDL_S32, &channels_combined_wanted, |
| 2109 | &echannels.combined_count }, |
| 2110 | }; |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2111 | int err, changed = 0; |
| 2112 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2113 | parse_generic_cmdline(ctx, &gchannels_changed, |
Ben Hutchings | c816d66 | 2011-10-31 22:30:38 +0000 | [diff] [blame] | 2114 | cmdline_channels, ARRAY_SIZE(cmdline_channels)); |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2115 | |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2116 | echannels.cmd = ETHTOOL_GCHANNELS; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2117 | err = send_ioctl(ctx, &echannels); |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2118 | if (err) { |
| 2119 | perror("Cannot get device channel parameters"); |
| 2120 | return 1; |
| 2121 | } |
| 2122 | |
| 2123 | do_generic_set(cmdline_channels, ARRAY_SIZE(cmdline_channels), |
| 2124 | &changed); |
| 2125 | |
| 2126 | if (!changed) { |
Ben Greear | 5954d26 | 2017-10-19 14:01:19 -0700 | [diff] [blame] | 2127 | fprintf(stderr, "no channel parameters changed.\n"); |
Jakub Kicinski | 410e33b | 2017-07-18 19:02:32 -0700 | [diff] [blame] | 2128 | fprintf(stderr, "current values: rx %u tx %u other %u" |
Amos Kong | 72b683b | 2014-04-18 09:39:59 +0800 | [diff] [blame] | 2129 | " combined %u\n", echannels.rx_count, |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2130 | echannels.tx_count, echannels.other_count, |
| 2131 | echannels.combined_count); |
Ben Greear | 5954d26 | 2017-10-19 14:01:19 -0700 | [diff] [blame] | 2132 | return 0; |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | echannels.cmd = ETHTOOL_SCHANNELS; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2136 | err = send_ioctl(ctx, &echannels); |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2137 | if (err) { |
| 2138 | perror("Cannot set device channel parameters"); |
| 2139 | return 1; |
| 2140 | } |
| 2141 | |
| 2142 | return 0; |
| 2143 | } |
| 2144 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2145 | static int do_gchannels(struct cmd_context *ctx) |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2146 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2147 | struct ethtool_channels echannels; |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2148 | int err; |
| 2149 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2150 | if (ctx->argc != 0) |
| 2151 | exit_bad_args(); |
| 2152 | |
Ben Hutchings | 743eb0b | 2011-10-29 02:36:48 +0100 | [diff] [blame] | 2153 | fprintf(stdout, "Channel parameters for %s:\n", ctx->devname); |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2154 | |
| 2155 | echannels.cmd = ETHTOOL_GCHANNELS; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2156 | err = send_ioctl(ctx, &echannels); |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2157 | if (err == 0) { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2158 | err = dump_channels(&echannels); |
Sucheta Chakraborty | ca91080 | 2011-10-07 04:58:50 -0700 | [diff] [blame] | 2159 | if (err) |
| 2160 | return err; |
| 2161 | } else { |
| 2162 | perror("Cannot get device channel parameters\n"); |
| 2163 | return 1; |
| 2164 | } |
| 2165 | return 0; |
| 2166 | |
| 2167 | } |
| 2168 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2169 | static int do_gcoalesce(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2170 | { |
Maciej Żenczykowski | 0cb963e | 2018-12-14 17:19:23 -0800 | [diff] [blame] | 2171 | struct ethtool_coalesce ecoal = {}; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2172 | int err; |
| 2173 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2174 | if (ctx->argc != 0) |
| 2175 | exit_bad_args(); |
| 2176 | |
Ben Hutchings | 743eb0b | 2011-10-29 02:36:48 +0100 | [diff] [blame] | 2177 | fprintf(stdout, "Coalesce parameters for %s:\n", ctx->devname); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2178 | |
| 2179 | ecoal.cmd = ETHTOOL_GCOALESCE; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2180 | err = send_ioctl(ctx, &ecoal); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2181 | if (err == 0) { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2182 | err = dump_coalesce(&ecoal); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2183 | if (err) |
| 2184 | return err; |
| 2185 | } else { |
| 2186 | perror("Cannot get device coalesce settings"); |
| 2187 | return 82; |
| 2188 | } |
| 2189 | |
| 2190 | return 0; |
| 2191 | } |
| 2192 | |
Nicholas Nunley | 8fb3b26 | 2019-03-01 00:15:28 -0800 | [diff] [blame] | 2193 | #define DECLARE_COALESCE_OPTION_VARS() \ |
| 2194 | s32 coal_stats_wanted = -1; \ |
| 2195 | int coal_adaptive_rx_wanted = -1; \ |
| 2196 | int coal_adaptive_tx_wanted = -1; \ |
| 2197 | s32 coal_sample_rate_wanted = -1; \ |
| 2198 | s32 coal_pkt_rate_low_wanted = -1; \ |
| 2199 | s32 coal_pkt_rate_high_wanted = -1; \ |
| 2200 | s32 coal_rx_usec_wanted = -1; \ |
| 2201 | s32 coal_rx_frames_wanted = -1; \ |
| 2202 | s32 coal_rx_usec_irq_wanted = -1; \ |
| 2203 | s32 coal_rx_frames_irq_wanted = -1; \ |
| 2204 | s32 coal_tx_usec_wanted = -1; \ |
| 2205 | s32 coal_tx_frames_wanted = -1; \ |
| 2206 | s32 coal_tx_usec_irq_wanted = -1; \ |
| 2207 | s32 coal_tx_frames_irq_wanted = -1; \ |
| 2208 | s32 coal_rx_usec_low_wanted = -1; \ |
| 2209 | s32 coal_rx_frames_low_wanted = -1; \ |
| 2210 | s32 coal_tx_usec_low_wanted = -1; \ |
| 2211 | s32 coal_tx_frames_low_wanted = -1; \ |
| 2212 | s32 coal_rx_usec_high_wanted = -1; \ |
| 2213 | s32 coal_rx_frames_high_wanted = -1; \ |
| 2214 | s32 coal_tx_usec_high_wanted = -1; \ |
| 2215 | s32 coal_tx_frames_high_wanted = -1 |
| 2216 | |
| 2217 | #define COALESCE_CMDLINE_INFO(__ecoal) \ |
| 2218 | { \ |
| 2219 | { "adaptive-rx", CMDL_BOOL, &coal_adaptive_rx_wanted, \ |
| 2220 | &__ecoal.use_adaptive_rx_coalesce }, \ |
| 2221 | { "adaptive-tx", CMDL_BOOL, &coal_adaptive_tx_wanted, \ |
| 2222 | &__ecoal.use_adaptive_tx_coalesce }, \ |
| 2223 | { "sample-interval", CMDL_S32, &coal_sample_rate_wanted, \ |
| 2224 | &__ecoal.rate_sample_interval }, \ |
| 2225 | { "stats-block-usecs", CMDL_S32, &coal_stats_wanted, \ |
| 2226 | &__ecoal.stats_block_coalesce_usecs }, \ |
| 2227 | { "pkt-rate-low", CMDL_S32, &coal_pkt_rate_low_wanted, \ |
| 2228 | &__ecoal.pkt_rate_low }, \ |
| 2229 | { "pkt-rate-high", CMDL_S32, &coal_pkt_rate_high_wanted, \ |
| 2230 | &__ecoal.pkt_rate_high }, \ |
| 2231 | { "rx-usecs", CMDL_S32, &coal_rx_usec_wanted, \ |
| 2232 | &__ecoal.rx_coalesce_usecs }, \ |
| 2233 | { "rx-frames", CMDL_S32, &coal_rx_frames_wanted, \ |
| 2234 | &__ecoal.rx_max_coalesced_frames }, \ |
| 2235 | { "rx-usecs-irq", CMDL_S32, &coal_rx_usec_irq_wanted, \ |
| 2236 | &__ecoal.rx_coalesce_usecs_irq }, \ |
| 2237 | { "rx-frames-irq", CMDL_S32, &coal_rx_frames_irq_wanted, \ |
| 2238 | &__ecoal.rx_max_coalesced_frames_irq }, \ |
| 2239 | { "tx-usecs", CMDL_S32, &coal_tx_usec_wanted, \ |
| 2240 | &__ecoal.tx_coalesce_usecs }, \ |
| 2241 | { "tx-frames", CMDL_S32, &coal_tx_frames_wanted, \ |
| 2242 | &__ecoal.tx_max_coalesced_frames }, \ |
| 2243 | { "tx-usecs-irq", CMDL_S32, &coal_tx_usec_irq_wanted, \ |
| 2244 | &__ecoal.tx_coalesce_usecs_irq }, \ |
| 2245 | { "tx-frames-irq", CMDL_S32, &coal_tx_frames_irq_wanted, \ |
| 2246 | &__ecoal.tx_max_coalesced_frames_irq }, \ |
| 2247 | { "rx-usecs-low", CMDL_S32, &coal_rx_usec_low_wanted, \ |
| 2248 | &__ecoal.rx_coalesce_usecs_low }, \ |
| 2249 | { "rx-frames-low", CMDL_S32, &coal_rx_frames_low_wanted, \ |
| 2250 | &__ecoal.rx_max_coalesced_frames_low }, \ |
| 2251 | { "tx-usecs-low", CMDL_S32, &coal_tx_usec_low_wanted, \ |
| 2252 | &__ecoal.tx_coalesce_usecs_low }, \ |
| 2253 | { "tx-frames-low", CMDL_S32, &coal_tx_frames_low_wanted, \ |
| 2254 | &__ecoal.tx_max_coalesced_frames_low }, \ |
| 2255 | { "rx-usecs-high", CMDL_S32, &coal_rx_usec_high_wanted, \ |
| 2256 | &__ecoal.rx_coalesce_usecs_high }, \ |
| 2257 | { "rx-frames-high", CMDL_S32, &coal_rx_frames_high_wanted, \ |
| 2258 | &__ecoal.rx_max_coalesced_frames_high }, \ |
| 2259 | { "tx-usecs-high", CMDL_S32, &coal_tx_usec_high_wanted, \ |
| 2260 | &__ecoal.tx_coalesce_usecs_high }, \ |
| 2261 | { "tx-frames-high", CMDL_S32, &coal_tx_frames_high_wanted, \ |
| 2262 | &__ecoal.tx_max_coalesced_frames_high }, \ |
| 2263 | } |
| 2264 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2265 | static int do_scoalesce(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2266 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2267 | struct ethtool_coalesce ecoal; |
| 2268 | int gcoalesce_changed = 0; |
Nicholas Nunley | 8fb3b26 | 2019-03-01 00:15:28 -0800 | [diff] [blame] | 2269 | DECLARE_COALESCE_OPTION_VARS(); |
| 2270 | struct cmdline_info cmdline_coalesce[] = COALESCE_CMDLINE_INFO(ecoal); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2271 | int err, changed = 0; |
| 2272 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2273 | parse_generic_cmdline(ctx, &gcoalesce_changed, |
| 2274 | cmdline_coalesce, ARRAY_SIZE(cmdline_coalesce)); |
| 2275 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2276 | ecoal.cmd = ETHTOOL_GCOALESCE; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2277 | err = send_ioctl(ctx, &ecoal); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2278 | if (err) { |
| 2279 | perror("Cannot get device coalesce settings"); |
| 2280 | return 76; |
| 2281 | } |
| 2282 | |
| 2283 | do_generic_set(cmdline_coalesce, ARRAY_SIZE(cmdline_coalesce), |
| 2284 | &changed); |
| 2285 | |
| 2286 | if (!changed) { |
Auke Kok | 2b91ca4 | 2007-11-12 10:28:42 -0800 | [diff] [blame] | 2287 | fprintf(stderr, "no coalesce parameters changed, aborting\n"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2288 | return 80; |
| 2289 | } |
| 2290 | |
| 2291 | ecoal.cmd = ETHTOOL_SCOALESCE; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2292 | err = send_ioctl(ctx, &ecoal); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2293 | if (err) { |
Auke Kok | 2b91ca4 | 2007-11-12 10:28:42 -0800 | [diff] [blame] | 2294 | perror("Cannot set device coalesce parameters"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2295 | return 81; |
| 2296 | } |
| 2297 | |
| 2298 | return 0; |
| 2299 | } |
| 2300 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2301 | static struct feature_state * |
| 2302 | get_features(struct cmd_context *ctx, const struct feature_defs *defs) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2303 | { |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2304 | struct feature_state *state; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2305 | struct ethtool_value eval; |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 2306 | int err, allfail = 1; |
Ben Hutchings | 5bebf1e | 2011-10-27 14:17:59 +0100 | [diff] [blame] | 2307 | u32 value; |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 2308 | int i; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2309 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2310 | state = malloc(sizeof(*state) + |
| 2311 | FEATURE_BITS_TO_BLOCKS(defs->n_features) * |
| 2312 | sizeof(state->features.features[0])); |
| 2313 | if (!state) |
| 2314 | return NULL; |
| 2315 | |
| 2316 | state->off_flags = 0; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2317 | |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 2318 | for (i = 0; i < ARRAY_SIZE(off_flag_def); i++) { |
| 2319 | value = off_flag_def[i].value; |
| 2320 | if (!off_flag_def[i].get_cmd) |
| 2321 | continue; |
| 2322 | eval.cmd = off_flag_def[i].get_cmd; |
| 2323 | err = send_ioctl(ctx, &eval); |
| 2324 | if (err) { |
Shaker Daibes | d5d35d8 | 2017-09-18 10:35:38 +0300 | [diff] [blame] | 2325 | if (errno == EOPNOTSUPP && |
| 2326 | off_flag_def[i].get_cmd == ETHTOOL_GUFO) |
| 2327 | continue; |
| 2328 | |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 2329 | fprintf(stderr, |
| 2330 | "Cannot get device %s settings: %m\n", |
| 2331 | off_flag_def[i].long_name); |
| 2332 | } else { |
| 2333 | if (eval.data) |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2334 | state->off_flags |= value; |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 2335 | allfail = 0; |
| 2336 | } |
$B5HF#1QL@(B | 20fd164 | 2006-08-22 11:40:04 +0900 | [diff] [blame] | 2337 | } |
| 2338 | |
Ben Hutchings | c36a51c | 2008-04-17 13:11:21 +0100 | [diff] [blame] | 2339 | eval.cmd = ETHTOOL_GFLAGS; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2340 | err = send_ioctl(ctx, &eval); |
Ben Hutchings | c36a51c | 2008-04-17 13:11:21 +0100 | [diff] [blame] | 2341 | if (err) { |
| 2342 | perror("Cannot get device flags"); |
| 2343 | } else { |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2344 | state->off_flags |= eval.data & ETH_FLAG_EXT_MASK; |
Jeff Garzik | 5c368cd | 2009-03-06 05:58:15 -0500 | [diff] [blame] | 2345 | allfail = 0; |
| 2346 | } |
| 2347 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2348 | if (defs->n_features) { |
| 2349 | state->features.cmd = ETHTOOL_GFEATURES; |
| 2350 | state->features.size = FEATURE_BITS_TO_BLOCKS(defs->n_features); |
| 2351 | err = send_ioctl(ctx, &state->features); |
| 2352 | if (err) |
| 2353 | perror("Cannot get device generic features"); |
| 2354 | else |
| 2355 | allfail = 0; |
| 2356 | } |
| 2357 | |
| 2358 | if (allfail) { |
| 2359 | free(state); |
| 2360 | return NULL; |
| 2361 | } |
| 2362 | |
| 2363 | return state; |
Ben Hutchings | 5bebf1e | 2011-10-27 14:17:59 +0100 | [diff] [blame] | 2364 | } |
| 2365 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2366 | static int do_gfeatures(struct cmd_context *ctx) |
Ben Hutchings | 5bebf1e | 2011-10-27 14:17:59 +0100 | [diff] [blame] | 2367 | { |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2368 | struct feature_defs *defs; |
| 2369 | struct feature_state *features; |
Ben Hutchings | 5bebf1e | 2011-10-27 14:17:59 +0100 | [diff] [blame] | 2370 | |
| 2371 | if (ctx->argc != 0) |
| 2372 | exit_bad_args(); |
| 2373 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2374 | defs = get_feature_defs(ctx); |
Ben Hutchings | 1eef677 | 2012-06-13 00:57:06 +0100 | [diff] [blame] | 2375 | if (!defs) { |
| 2376 | perror("Cannot get device feature names"); |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2377 | return 1; |
Ben Hutchings | 1eef677 | 2012-06-13 00:57:06 +0100 | [diff] [blame] | 2378 | } |
Ben Hutchings | 5bebf1e | 2011-10-27 14:17:59 +0100 | [diff] [blame] | 2379 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2380 | fprintf(stdout, "Features for %s:\n", ctx->devname); |
| 2381 | |
| 2382 | features = get_features(ctx, defs); |
| 2383 | if (!features) { |
| 2384 | fprintf(stdout, "no feature info available\n"); |
John W. Linville | 210ffb1 | 2016-09-29 15:26:55 -0400 | [diff] [blame] | 2385 | free(defs); |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2386 | return 1; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2387 | } |
| 2388 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2389 | dump_features(defs, features, NULL); |
John W. Linville | 210ffb1 | 2016-09-29 15:26:55 -0400 | [diff] [blame] | 2390 | free(features); |
| 2391 | free(defs); |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2392 | return 0; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2393 | } |
| 2394 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2395 | static int do_sfeatures(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2396 | { |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2397 | struct feature_defs *defs; |
| 2398 | int any_changed = 0, any_mismatch = 0; |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2399 | u32 off_flags_wanted = 0; |
| 2400 | u32 off_flags_mask = 0; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2401 | struct ethtool_sfeatures *efeatures; |
| 2402 | struct cmdline_info *cmdline_features; |
| 2403 | struct feature_state *old_state, *new_state; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2404 | struct ethtool_value eval; |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2405 | int err, rc; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2406 | int i, j; |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 2407 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2408 | defs = get_feature_defs(ctx); |
Ben Hutchings | 1eef677 | 2012-06-13 00:57:06 +0100 | [diff] [blame] | 2409 | if (!defs) { |
| 2410 | perror("Cannot get device feature names"); |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2411 | return 1; |
Ben Hutchings | 1eef677 | 2012-06-13 00:57:06 +0100 | [diff] [blame] | 2412 | } |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2413 | if (defs->n_features) { |
| 2414 | efeatures = malloc(sizeof(*efeatures) + |
| 2415 | FEATURE_BITS_TO_BLOCKS(defs->n_features) * |
| 2416 | sizeof(efeatures->features[0])); |
| 2417 | if (!efeatures) { |
| 2418 | perror("Cannot parse arguments"); |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2419 | rc = 1; |
| 2420 | goto err; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2421 | } |
| 2422 | efeatures->cmd = ETHTOOL_SFEATURES; |
| 2423 | efeatures->size = FEATURE_BITS_TO_BLOCKS(defs->n_features); |
| 2424 | memset(efeatures->features, 0, |
| 2425 | FEATURE_BITS_TO_BLOCKS(defs->n_features) * |
| 2426 | sizeof(efeatures->features[0])); |
| 2427 | } else { |
| 2428 | efeatures = NULL; |
| 2429 | } |
| 2430 | |
| 2431 | /* Generate cmdline_info for legacy flags and kernel-named |
| 2432 | * features, and parse our arguments. |
| 2433 | */ |
| 2434 | cmdline_features = calloc(ARRAY_SIZE(off_flag_def) + defs->n_features, |
| 2435 | sizeof(cmdline_features[0])); |
| 2436 | if (!cmdline_features) { |
| 2437 | perror("Cannot parse arguments"); |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2438 | rc = 1; |
| 2439 | goto err; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2440 | } |
Ben Hutchings | e5c984a | 2011-05-13 23:25:26 +0100 | [diff] [blame] | 2441 | for (i = 0; i < ARRAY_SIZE(off_flag_def); i++) |
| 2442 | flag_to_cmdline_info(off_flag_def[i].short_name, |
| 2443 | off_flag_def[i].value, |
| 2444 | &off_flags_wanted, &off_flags_mask, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2445 | &cmdline_features[i]); |
| 2446 | for (i = 0; i < defs->n_features; i++) |
| 2447 | flag_to_cmdline_info( |
| 2448 | defs->def[i].name, FEATURE_FIELD_FLAG(i), |
| 2449 | &FEATURE_WORD(efeatures->features, i, requested), |
| 2450 | &FEATURE_WORD(efeatures->features, i, valid), |
| 2451 | &cmdline_features[ARRAY_SIZE(off_flag_def) + i]); |
| 2452 | parse_generic_cmdline(ctx, &any_changed, cmdline_features, |
| 2453 | ARRAY_SIZE(off_flag_def) + defs->n_features); |
| 2454 | free(cmdline_features); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2455 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2456 | if (!any_changed) { |
| 2457 | fprintf(stdout, "no features changed\n"); |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2458 | rc = 0; |
| 2459 | goto err; |
Ben Hutchings | 5bebf1e | 2011-10-27 14:17:59 +0100 | [diff] [blame] | 2460 | } |
| 2461 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2462 | old_state = get_features(ctx, defs); |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2463 | if (!old_state) { |
| 2464 | rc = 1; |
| 2465 | goto err; |
| 2466 | } |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2467 | |
Ben Hutchings | b982755 | 2012-07-16 21:48:39 +0100 | [diff] [blame] | 2468 | if (efeatures) { |
| 2469 | /* For each offload that the user specified, update any |
| 2470 | * related features that the user did not specify and that |
| 2471 | * are not fixed. Warn if all related features are fixed. |
| 2472 | */ |
| 2473 | for (i = 0; i < ARRAY_SIZE(off_flag_def); i++) { |
| 2474 | int fixed = 1; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2475 | |
Ben Hutchings | b982755 | 2012-07-16 21:48:39 +0100 | [diff] [blame] | 2476 | if (!(off_flags_mask & off_flag_def[i].value)) |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2477 | continue; |
| 2478 | |
Ben Hutchings | b982755 | 2012-07-16 21:48:39 +0100 | [diff] [blame] | 2479 | for (j = 0; j < defs->n_features; j++) { |
| 2480 | if (defs->def[j].off_flag_index != i || |
| 2481 | !FEATURE_BIT_IS_SET( |
| 2482 | old_state->features.features, |
| 2483 | j, available) || |
| 2484 | FEATURE_BIT_IS_SET( |
| 2485 | old_state->features.features, |
| 2486 | j, never_changed)) |
| 2487 | continue; |
| 2488 | |
| 2489 | fixed = 0; |
| 2490 | if (!FEATURE_BIT_IS_SET(efeatures->features, |
| 2491 | j, valid)) { |
| 2492 | FEATURE_BIT_SET(efeatures->features, |
| 2493 | j, valid); |
| 2494 | if (off_flags_wanted & |
| 2495 | off_flag_def[i].value) |
| 2496 | FEATURE_BIT_SET( |
| 2497 | efeatures->features, |
| 2498 | j, requested); |
| 2499 | } |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2500 | } |
Ben Hutchings | b982755 | 2012-07-16 21:48:39 +0100 | [diff] [blame] | 2501 | |
| 2502 | if (fixed) |
| 2503 | fprintf(stderr, "Cannot change %s\n", |
| 2504 | off_flag_def[i].long_name); |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2505 | } |
| 2506 | |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2507 | err = send_ioctl(ctx, efeatures); |
| 2508 | if (err < 0) { |
| 2509 | perror("Cannot set device feature settings"); |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2510 | rc = 1; |
| 2511 | goto err; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2512 | } |
| 2513 | } else { |
| 2514 | for (i = 0; i < ARRAY_SIZE(off_flag_def); i++) { |
| 2515 | if (!off_flag_def[i].set_cmd) |
| 2516 | continue; |
| 2517 | if (off_flags_mask & off_flag_def[i].value) { |
| 2518 | eval.cmd = off_flag_def[i].set_cmd; |
| 2519 | eval.data = !!(off_flags_wanted & |
| 2520 | off_flag_def[i].value); |
| 2521 | err = send_ioctl(ctx, &eval); |
| 2522 | if (err) { |
| 2523 | fprintf(stderr, |
| 2524 | "Cannot set device %s settings: %m\n", |
| 2525 | off_flag_def[i].long_name); |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2526 | rc = 1; |
| 2527 | goto err; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2528 | } |
| 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | if (off_flags_mask & ETH_FLAG_EXT_MASK) { |
| 2533 | eval.cmd = ETHTOOL_SFLAGS; |
| 2534 | eval.data = (old_state->off_flags & ~off_flags_mask & |
| 2535 | ETH_FLAG_EXT_MASK); |
| 2536 | eval.data |= off_flags_wanted & ETH_FLAG_EXT_MASK; |
| 2537 | |
| 2538 | err = send_ioctl(ctx, &eval); |
| 2539 | if (err) { |
| 2540 | perror("Cannot set device flag settings"); |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2541 | rc = 92; |
| 2542 | goto err; |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2543 | } |
| 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | /* Compare new state with requested state */ |
| 2548 | new_state = get_features(ctx, defs); |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2549 | if (!new_state) { |
| 2550 | rc = 1; |
| 2551 | goto err; |
| 2552 | } |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2553 | any_changed = new_state->off_flags != old_state->off_flags; |
| 2554 | any_mismatch = (new_state->off_flags != |
| 2555 | ((old_state->off_flags & ~off_flags_mask) | |
| 2556 | off_flags_wanted)); |
| 2557 | for (i = 0; i < FEATURE_BITS_TO_BLOCKS(defs->n_features); i++) { |
| 2558 | if (new_state->features.features[i].active != |
| 2559 | old_state->features.features[i].active) |
| 2560 | any_changed = 1; |
| 2561 | if (new_state->features.features[i].active != |
| 2562 | ((old_state->features.features[i].active & |
| 2563 | ~efeatures->features[i].valid) | |
| 2564 | efeatures->features[i].requested)) |
| 2565 | any_mismatch = 1; |
| 2566 | } |
| 2567 | if (any_mismatch) { |
| 2568 | if (!any_changed) { |
Ben Hutchings | 5bebf1e | 2011-10-27 14:17:59 +0100 | [diff] [blame] | 2569 | fprintf(stderr, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2570 | "Could not change any device features\n"); |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2571 | rc = 1; |
| 2572 | goto err; |
Ben Hutchings | 5bebf1e | 2011-10-27 14:17:59 +0100 | [diff] [blame] | 2573 | } |
| 2574 | printf("Actual changes:\n"); |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 2575 | dump_features(defs, new_state, old_state); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2576 | } |
| 2577 | |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2578 | rc = 0; |
| 2579 | |
| 2580 | err: |
| 2581 | free(defs); |
John W. Linville | f237896 | 2016-09-30 14:50:26 -0400 | [diff] [blame] | 2582 | if (efeatures) |
| 2583 | free(efeatures); |
John W. Linville | aab2c23 | 2016-09-30 14:33:35 -0400 | [diff] [blame] | 2584 | return rc; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2585 | } |
| 2586 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 2587 | static struct ethtool_link_usettings * |
| 2588 | do_ioctl_glinksettings(struct cmd_context *ctx) |
| 2589 | { |
| 2590 | int err; |
| 2591 | struct { |
| 2592 | struct ethtool_link_settings req; |
| 2593 | __u32 link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32]; |
| 2594 | } ecmd; |
| 2595 | struct ethtool_link_usettings *link_usettings; |
| 2596 | unsigned int u32_offs; |
| 2597 | |
| 2598 | /* Handshake with kernel to determine number of words for link |
| 2599 | * mode bitmaps. When requested number of bitmap words is not |
| 2600 | * the one expected by kernel, the latter returns the integer |
| 2601 | * opposite of what it is expecting. We request length 0 below |
| 2602 | * (aka. invalid bitmap length) to get this info. |
| 2603 | */ |
| 2604 | memset(&ecmd, 0, sizeof(ecmd)); |
| 2605 | ecmd.req.cmd = ETHTOOL_GLINKSETTINGS; |
| 2606 | err = send_ioctl(ctx, &ecmd); |
| 2607 | if (err < 0) |
| 2608 | return NULL; |
| 2609 | |
| 2610 | /* see above: we expect a strictly negative value from kernel. |
| 2611 | */ |
| 2612 | if (ecmd.req.link_mode_masks_nwords >= 0 |
| 2613 | || ecmd.req.cmd != ETHTOOL_GLINKSETTINGS) |
| 2614 | return NULL; |
| 2615 | |
| 2616 | /* got the real ecmd.req.link_mode_masks_nwords, |
| 2617 | * now send the real request |
| 2618 | */ |
| 2619 | ecmd.req.cmd = ETHTOOL_GLINKSETTINGS; |
| 2620 | ecmd.req.link_mode_masks_nwords = -ecmd.req.link_mode_masks_nwords; |
| 2621 | err = send_ioctl(ctx, &ecmd); |
| 2622 | if (err < 0) |
| 2623 | return NULL; |
| 2624 | |
| 2625 | if (ecmd.req.link_mode_masks_nwords <= 0 |
| 2626 | || ecmd.req.cmd != ETHTOOL_GLINKSETTINGS) |
| 2627 | return NULL; |
| 2628 | |
| 2629 | /* Convert to usettings struct */ |
| 2630 | link_usettings = calloc(1, sizeof(*link_usettings)); |
| 2631 | if (link_usettings == NULL) |
| 2632 | return NULL; |
| 2633 | |
| 2634 | /* keep transceiver 0 */ |
| 2635 | memcpy(&link_usettings->base, &ecmd.req, sizeof(link_usettings->base)); |
| 2636 | |
| 2637 | /* copy link mode bitmaps */ |
| 2638 | u32_offs = 0; |
| 2639 | memcpy(link_usettings->link_modes.supported, |
| 2640 | &ecmd.link_mode_data[u32_offs], |
| 2641 | 4 * ecmd.req.link_mode_masks_nwords); |
| 2642 | |
| 2643 | u32_offs += ecmd.req.link_mode_masks_nwords; |
| 2644 | memcpy(link_usettings->link_modes.advertising, |
| 2645 | &ecmd.link_mode_data[u32_offs], |
| 2646 | 4 * ecmd.req.link_mode_masks_nwords); |
| 2647 | |
| 2648 | u32_offs += ecmd.req.link_mode_masks_nwords; |
| 2649 | memcpy(link_usettings->link_modes.lp_advertising, |
| 2650 | &ecmd.link_mode_data[u32_offs], |
| 2651 | 4 * ecmd.req.link_mode_masks_nwords); |
| 2652 | |
| 2653 | return link_usettings; |
| 2654 | } |
| 2655 | |
| 2656 | static int |
| 2657 | do_ioctl_slinksettings(struct cmd_context *ctx, |
| 2658 | const struct ethtool_link_usettings *link_usettings) |
| 2659 | { |
| 2660 | struct { |
| 2661 | struct ethtool_link_settings req; |
| 2662 | __u32 link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32]; |
| 2663 | } ecmd; |
| 2664 | unsigned int u32_offs; |
| 2665 | |
| 2666 | /* refuse to send ETHTOOL_SLINKSETTINGS ioctl if |
| 2667 | * link_usettings was retrieved with ETHTOOL_GSET |
| 2668 | */ |
| 2669 | if (link_usettings->base.cmd != ETHTOOL_GLINKSETTINGS) |
| 2670 | return -1; |
| 2671 | |
| 2672 | /* refuse to send ETHTOOL_SLINKSETTINGS ioctl if deprecated fields |
| 2673 | * were set |
| 2674 | */ |
| 2675 | if (link_usettings->deprecated.transceiver) |
| 2676 | return -1; |
| 2677 | |
| 2678 | if (link_usettings->base.link_mode_masks_nwords <= 0) |
| 2679 | return -1; |
| 2680 | |
| 2681 | memcpy(&ecmd.req, &link_usettings->base, sizeof(ecmd.req)); |
| 2682 | ecmd.req.cmd = ETHTOOL_SLINKSETTINGS; |
| 2683 | |
| 2684 | /* copy link mode bitmaps */ |
| 2685 | u32_offs = 0; |
| 2686 | memcpy(&ecmd.link_mode_data[u32_offs], |
| 2687 | link_usettings->link_modes.supported, |
| 2688 | 4 * ecmd.req.link_mode_masks_nwords); |
| 2689 | |
| 2690 | u32_offs += ecmd.req.link_mode_masks_nwords; |
| 2691 | memcpy(&ecmd.link_mode_data[u32_offs], |
| 2692 | link_usettings->link_modes.advertising, |
| 2693 | 4 * ecmd.req.link_mode_masks_nwords); |
| 2694 | |
| 2695 | u32_offs += ecmd.req.link_mode_masks_nwords; |
| 2696 | memcpy(&ecmd.link_mode_data[u32_offs], |
| 2697 | link_usettings->link_modes.lp_advertising, |
| 2698 | 4 * ecmd.req.link_mode_masks_nwords); |
| 2699 | |
| 2700 | return send_ioctl(ctx, &ecmd); |
| 2701 | } |
| 2702 | |
| 2703 | static struct ethtool_link_usettings * |
| 2704 | do_ioctl_gset(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2705 | { |
| 2706 | int err; |
| 2707 | struct ethtool_cmd ecmd; |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 2708 | struct ethtool_link_usettings *link_usettings; |
| 2709 | |
| 2710 | memset(&ecmd, 0, sizeof(ecmd)); |
| 2711 | ecmd.cmd = ETHTOOL_GSET; |
| 2712 | err = send_ioctl(ctx, &ecmd); |
| 2713 | if (err < 0) |
| 2714 | return NULL; |
| 2715 | |
| 2716 | link_usettings = calloc(1, sizeof(*link_usettings)); |
| 2717 | if (link_usettings == NULL) |
| 2718 | return NULL; |
| 2719 | |
| 2720 | /* remember that ETHTOOL_GSET was used */ |
| 2721 | link_usettings->base.cmd = ETHTOOL_GSET; |
| 2722 | |
| 2723 | link_usettings->base.link_mode_masks_nwords = 1; |
| 2724 | link_usettings->link_modes.supported[0] = ecmd.supported; |
| 2725 | link_usettings->link_modes.advertising[0] = ecmd.advertising; |
| 2726 | link_usettings->link_modes.lp_advertising[0] = ecmd.lp_advertising; |
| 2727 | link_usettings->base.speed = ethtool_cmd_speed(&ecmd); |
| 2728 | link_usettings->base.duplex = ecmd.duplex; |
| 2729 | link_usettings->base.port = ecmd.port; |
| 2730 | link_usettings->base.phy_address = ecmd.phy_address; |
| 2731 | link_usettings->deprecated.transceiver = ecmd.transceiver; |
| 2732 | link_usettings->base.autoneg = ecmd.autoneg; |
| 2733 | link_usettings->base.mdio_support = ecmd.mdio_support; |
| 2734 | /* ignored (fully deprecated): maxrxpkt, maxtxpkt */ |
| 2735 | link_usettings->base.eth_tp_mdix = ecmd.eth_tp_mdix; |
| 2736 | link_usettings->base.eth_tp_mdix_ctrl = ecmd.eth_tp_mdix_ctrl; |
| 2737 | |
| 2738 | return link_usettings; |
| 2739 | } |
| 2740 | |
| 2741 | static bool ethtool_link_mode_is_backward_compatible(const u32 *mask) |
| 2742 | { |
| 2743 | unsigned int i; |
| 2744 | |
| 2745 | for (i = 1; i < ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32; ++i) |
| 2746 | if (mask[i]) |
| 2747 | return false; |
| 2748 | |
| 2749 | return true; |
| 2750 | } |
| 2751 | |
| 2752 | static int |
| 2753 | do_ioctl_sset(struct cmd_context *ctx, |
| 2754 | const struct ethtool_link_usettings *link_usettings) |
| 2755 | { |
| 2756 | struct ethtool_cmd ecmd; |
| 2757 | |
| 2758 | /* refuse to send ETHTOOL_SSET ioctl if link_usettings was |
| 2759 | * retrieved with ETHTOOL_GLINKSETTINGS |
| 2760 | */ |
| 2761 | if (link_usettings->base.cmd != ETHTOOL_GSET) |
| 2762 | return -1; |
| 2763 | |
| 2764 | if (link_usettings->base.link_mode_masks_nwords <= 0) |
| 2765 | return -1; |
| 2766 | |
| 2767 | /* refuse to sset if any bit > 31 is set */ |
| 2768 | if (!ethtool_link_mode_is_backward_compatible( |
| 2769 | link_usettings->link_modes.supported)) |
| 2770 | return -1; |
| 2771 | if (!ethtool_link_mode_is_backward_compatible( |
| 2772 | link_usettings->link_modes.advertising)) |
| 2773 | return -1; |
| 2774 | if (!ethtool_link_mode_is_backward_compatible( |
| 2775 | link_usettings->link_modes.lp_advertising)) |
| 2776 | return -1; |
| 2777 | |
| 2778 | memset(&ecmd, 0, sizeof(ecmd)); |
| 2779 | ecmd.cmd = ETHTOOL_SSET; |
| 2780 | |
| 2781 | ecmd.supported = link_usettings->link_modes.supported[0]; |
| 2782 | ecmd.advertising = link_usettings->link_modes.advertising[0]; |
| 2783 | ecmd.lp_advertising = link_usettings->link_modes.lp_advertising[0]; |
| 2784 | ethtool_cmd_speed_set(&ecmd, link_usettings->base.speed); |
| 2785 | ecmd.duplex = link_usettings->base.duplex; |
| 2786 | ecmd.port = link_usettings->base.port; |
| 2787 | ecmd.phy_address = link_usettings->base.phy_address; |
| 2788 | ecmd.transceiver = link_usettings->deprecated.transceiver; |
| 2789 | ecmd.autoneg = link_usettings->base.autoneg; |
| 2790 | ecmd.mdio_support = link_usettings->base.mdio_support; |
| 2791 | /* ignored (fully deprecated): maxrxpkt, maxtxpkt */ |
| 2792 | ecmd.eth_tp_mdix = link_usettings->base.eth_tp_mdix; |
| 2793 | ecmd.eth_tp_mdix_ctrl = link_usettings->base.eth_tp_mdix_ctrl; |
| 2794 | return send_ioctl(ctx, &ecmd); |
| 2795 | } |
| 2796 | |
| 2797 | static int do_gset(struct cmd_context *ctx) |
| 2798 | { |
| 2799 | int err; |
| 2800 | struct ethtool_link_usettings *link_usettings; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2801 | struct ethtool_wolinfo wolinfo; |
| 2802 | struct ethtool_value edata; |
| 2803 | int allfail = 1; |
| 2804 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2805 | if (ctx->argc != 0) |
| 2806 | exit_bad_args(); |
| 2807 | |
Ben Hutchings | 743eb0b | 2011-10-29 02:36:48 +0100 | [diff] [blame] | 2808 | fprintf(stdout, "Settings for %s:\n", ctx->devname); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2809 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 2810 | link_usettings = do_ioctl_glinksettings(ctx); |
| 2811 | if (link_usettings == NULL) |
| 2812 | link_usettings = do_ioctl_gset(ctx); |
| 2813 | if (link_usettings != NULL) { |
| 2814 | err = dump_link_usettings(link_usettings); |
| 2815 | free(link_usettings); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2816 | if (err) |
| 2817 | return err; |
| 2818 | allfail = 0; |
| 2819 | } else if (errno != EOPNOTSUPP) { |
| 2820 | perror("Cannot get device settings"); |
| 2821 | } |
| 2822 | |
| 2823 | wolinfo.cmd = ETHTOOL_GWOL; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2824 | err = send_ioctl(ctx, &wolinfo); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2825 | if (err == 0) { |
| 2826 | err = dump_wol(&wolinfo); |
| 2827 | if (err) |
| 2828 | return err; |
| 2829 | allfail = 0; |
| 2830 | } else if (errno != EOPNOTSUPP) { |
| 2831 | perror("Cannot get wake-on-lan settings"); |
| 2832 | } |
| 2833 | |
| 2834 | edata.cmd = ETHTOOL_GMSGLVL; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2835 | err = send_ioctl(ctx, &edata); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2836 | if (err == 0) { |
Ben Hutchings | 97d0ee2 | 2010-06-25 15:49:45 +0100 | [diff] [blame] | 2837 | fprintf(stdout, " Current message level: 0x%08x (%d)\n" |
| 2838 | " ", |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2839 | edata.data, edata.data); |
Ben Hutchings | 5ec0d81 | 2011-10-31 22:50:25 +0000 | [diff] [blame] | 2840 | print_flags(flags_msglvl, ARRAY_SIZE(flags_msglvl), |
Ben Hutchings | 97d0ee2 | 2010-06-25 15:49:45 +0100 | [diff] [blame] | 2841 | edata.data); |
| 2842 | fprintf(stdout, "\n"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2843 | allfail = 0; |
| 2844 | } else if (errno != EOPNOTSUPP) { |
| 2845 | perror("Cannot get message level"); |
| 2846 | } |
| 2847 | |
| 2848 | edata.cmd = ETHTOOL_GLINK; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2849 | err = send_ioctl(ctx, &edata); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2850 | if (err == 0) { |
| 2851 | fprintf(stdout, " Link detected: %s\n", |
| 2852 | edata.data ? "yes":"no"); |
| 2853 | allfail = 0; |
| 2854 | } else if (errno != EOPNOTSUPP) { |
| 2855 | perror("Cannot get link status"); |
| 2856 | } |
| 2857 | |
| 2858 | if (allfail) { |
| 2859 | fprintf(stdout, "No data available\n"); |
| 2860 | return 75; |
| 2861 | } |
| 2862 | return 0; |
| 2863 | } |
| 2864 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 2865 | static int do_sset(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2866 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2867 | int speed_wanted = -1; |
| 2868 | int duplex_wanted = -1; |
| 2869 | int port_wanted = -1; |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 2870 | int mdix_wanted = -1; |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2871 | int autoneg_wanted = -1; |
| 2872 | int phyad_wanted = -1; |
| 2873 | int xcvr_wanted = -1; |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 2874 | u32 *full_advertising_wanted = NULL; |
| 2875 | u32 *advertising_wanted = NULL; |
| 2876 | ETHTOOL_DECLARE_LINK_MODE_MASK(mask_full_advertising_wanted); |
| 2877 | ETHTOOL_DECLARE_LINK_MODE_MASK(mask_advertising_wanted); |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 2878 | int gset_changed = 0; /* did anything in GSET change? */ |
| 2879 | u32 wol_wanted = 0; |
| 2880 | int wol_change = 0; |
| 2881 | u8 sopass_wanted[SOPASS_MAX]; |
| 2882 | int sopass_change = 0; |
| 2883 | int gwol_changed = 0; /* did anything in GWOL change? */ |
| 2884 | int msglvl_changed = 0; |
| 2885 | u32 msglvl_wanted = 0; |
| 2886 | u32 msglvl_mask = 0; |
Ben Hutchings | 5ec0d81 | 2011-10-31 22:50:25 +0000 | [diff] [blame] | 2887 | struct cmdline_info cmdline_msglvl[ARRAY_SIZE(flags_msglvl)]; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2888 | int argc = ctx->argc; |
| 2889 | char **argp = ctx->argp; |
| 2890 | int i; |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 2891 | int err = 0; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 2892 | |
Ben Hutchings | 5ec0d81 | 2011-10-31 22:50:25 +0000 | [diff] [blame] | 2893 | for (i = 0; i < ARRAY_SIZE(flags_msglvl); i++) |
| 2894 | flag_to_cmdline_info(flags_msglvl[i].name, |
| 2895 | flags_msglvl[i].value, |
| 2896 | &msglvl_wanted, &msglvl_mask, |
| 2897 | &cmdline_msglvl[i]); |
| 2898 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2899 | for (i = 0; i < argc; i++) { |
| 2900 | if (!strcmp(argp[i], "speed")) { |
| 2901 | gset_changed = 1; |
| 2902 | i += 1; |
| 2903 | if (i >= argc) |
| 2904 | exit_bad_args(); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 2905 | speed_wanted = get_int(argp[i], 10); |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2906 | } else if (!strcmp(argp[i], "duplex")) { |
| 2907 | gset_changed = 1; |
| 2908 | i += 1; |
| 2909 | if (i >= argc) |
| 2910 | exit_bad_args(); |
| 2911 | if (!strcmp(argp[i], "half")) |
| 2912 | duplex_wanted = DUPLEX_HALF; |
| 2913 | else if (!strcmp(argp[i], "full")) |
| 2914 | duplex_wanted = DUPLEX_FULL; |
| 2915 | else |
| 2916 | exit_bad_args(); |
| 2917 | } else if (!strcmp(argp[i], "port")) { |
| 2918 | gset_changed = 1; |
| 2919 | i += 1; |
| 2920 | if (i >= argc) |
| 2921 | exit_bad_args(); |
| 2922 | if (!strcmp(argp[i], "tp")) |
| 2923 | port_wanted = PORT_TP; |
| 2924 | else if (!strcmp(argp[i], "aui")) |
| 2925 | port_wanted = PORT_AUI; |
| 2926 | else if (!strcmp(argp[i], "bnc")) |
| 2927 | port_wanted = PORT_BNC; |
| 2928 | else if (!strcmp(argp[i], "mii")) |
| 2929 | port_wanted = PORT_MII; |
| 2930 | else if (!strcmp(argp[i], "fibre")) |
| 2931 | port_wanted = PORT_FIBRE; |
| 2932 | else |
| 2933 | exit_bad_args(); |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 2934 | } else if (!strcmp(argp[i], "mdix")) { |
| 2935 | gset_changed = 1; |
| 2936 | i += 1; |
| 2937 | if (i >= argc) |
| 2938 | exit_bad_args(); |
| 2939 | if (!strcmp(argp[i], "auto")) |
| 2940 | mdix_wanted = ETH_TP_MDI_AUTO; |
| 2941 | else if (!strcmp(argp[i], "on")) |
| 2942 | mdix_wanted = ETH_TP_MDI_X; |
| 2943 | else if (!strcmp(argp[i], "off")) |
| 2944 | mdix_wanted = ETH_TP_MDI; |
| 2945 | else |
| 2946 | exit_bad_args(); |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2947 | } else if (!strcmp(argp[i], "autoneg")) { |
| 2948 | i += 1; |
| 2949 | if (i >= argc) |
| 2950 | exit_bad_args(); |
| 2951 | if (!strcmp(argp[i], "on")) { |
| 2952 | gset_changed = 1; |
| 2953 | autoneg_wanted = AUTONEG_ENABLE; |
| 2954 | } else if (!strcmp(argp[i], "off")) { |
| 2955 | gset_changed = 1; |
| 2956 | autoneg_wanted = AUTONEG_DISABLE; |
| 2957 | } else { |
| 2958 | exit_bad_args(); |
| 2959 | } |
| 2960 | } else if (!strcmp(argp[i], "advertise")) { |
| 2961 | gset_changed = 1; |
| 2962 | i += 1; |
| 2963 | if (i >= argc) |
| 2964 | exit_bad_args(); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 2965 | if (parse_hex_u32_bitmap( |
| 2966 | argp[i], |
| 2967 | ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NBITS, |
| 2968 | mask_full_advertising_wanted)) |
| 2969 | exit_bad_args(); |
| 2970 | full_advertising_wanted = mask_full_advertising_wanted; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 2971 | } else if (!strcmp(argp[i], "phyad")) { |
| 2972 | gset_changed = 1; |
| 2973 | i += 1; |
| 2974 | if (i >= argc) |
| 2975 | exit_bad_args(); |
| 2976 | phyad_wanted = get_int(argp[i], 0); |
| 2977 | } else if (!strcmp(argp[i], "xcvr")) { |
| 2978 | gset_changed = 1; |
| 2979 | i += 1; |
| 2980 | if (i >= argc) |
| 2981 | exit_bad_args(); |
| 2982 | if (!strcmp(argp[i], "internal")) |
| 2983 | xcvr_wanted = XCVR_INTERNAL; |
| 2984 | else if (!strcmp(argp[i], "external")) |
| 2985 | xcvr_wanted = XCVR_EXTERNAL; |
| 2986 | else |
| 2987 | exit_bad_args(); |
| 2988 | } else if (!strcmp(argp[i], "wol")) { |
| 2989 | gwol_changed = 1; |
| 2990 | i++; |
| 2991 | if (i >= argc) |
| 2992 | exit_bad_args(); |
| 2993 | if (parse_wolopts(argp[i], &wol_wanted) < 0) |
| 2994 | exit_bad_args(); |
| 2995 | wol_change = 1; |
| 2996 | } else if (!strcmp(argp[i], "sopass")) { |
| 2997 | gwol_changed = 1; |
| 2998 | i++; |
| 2999 | if (i >= argc) |
| 3000 | exit_bad_args(); |
| 3001 | get_mac_addr(argp[i], sopass_wanted); |
| 3002 | sopass_change = 1; |
| 3003 | } else if (!strcmp(argp[i], "msglvl")) { |
| 3004 | i++; |
| 3005 | if (i >= argc) |
| 3006 | exit_bad_args(); |
| 3007 | if (isdigit((unsigned char)argp[i][0])) { |
| 3008 | msglvl_changed = 1; |
| 3009 | msglvl_mask = ~0; |
| 3010 | msglvl_wanted = |
| 3011 | get_uint_range(argp[i], 0, |
| 3012 | 0xffffffff); |
| 3013 | } else { |
| 3014 | ctx->argc -= i; |
| 3015 | ctx->argp += i; |
| 3016 | parse_generic_cmdline( |
| 3017 | ctx, &msglvl_changed, |
| 3018 | cmdline_msglvl, |
| 3019 | ARRAY_SIZE(cmdline_msglvl)); |
| 3020 | break; |
| 3021 | } |
| 3022 | } else { |
| 3023 | exit_bad_args(); |
| 3024 | } |
| 3025 | } |
| 3026 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3027 | if (full_advertising_wanted == NULL) { |
Johan Gunnarsson | 517f88b | 2012-08-24 13:32:45 +0200 | [diff] [blame] | 3028 | /* User didn't supply a full advertisement bitfield: |
| 3029 | * construct one from the specified speed and duplex. |
| 3030 | */ |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3031 | int adv_bit = -1; |
| 3032 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3033 | if (speed_wanted == SPEED_10 && duplex_wanted == DUPLEX_HALF) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3034 | adv_bit = ETHTOOL_LINK_MODE_10baseT_Half_BIT; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3035 | else if (speed_wanted == SPEED_10 && |
| 3036 | duplex_wanted == DUPLEX_FULL) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3037 | adv_bit = ETHTOOL_LINK_MODE_10baseT_Full_BIT; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3038 | else if (speed_wanted == SPEED_100 && |
| 3039 | duplex_wanted == DUPLEX_HALF) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3040 | adv_bit = ETHTOOL_LINK_MODE_100baseT_Half_BIT; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3041 | else if (speed_wanted == SPEED_100 && |
| 3042 | duplex_wanted == DUPLEX_FULL) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3043 | adv_bit = ETHTOOL_LINK_MODE_100baseT_Full_BIT; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3044 | else if (speed_wanted == SPEED_1000 && |
| 3045 | duplex_wanted == DUPLEX_HALF) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3046 | adv_bit = ETHTOOL_LINK_MODE_1000baseT_Half_BIT; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3047 | else if (speed_wanted == SPEED_1000 && |
| 3048 | duplex_wanted == DUPLEX_FULL) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3049 | adv_bit = ETHTOOL_LINK_MODE_1000baseT_Full_BIT; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3050 | else if (speed_wanted == SPEED_2500 && |
| 3051 | duplex_wanted == DUPLEX_FULL) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3052 | adv_bit = ETHTOOL_LINK_MODE_2500baseX_Full_BIT; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3053 | else if (speed_wanted == SPEED_10000 && |
| 3054 | duplex_wanted == DUPLEX_FULL) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3055 | adv_bit = ETHTOOL_LINK_MODE_10000baseT_Full_BIT; |
| 3056 | |
| 3057 | if (adv_bit >= 0) { |
| 3058 | advertising_wanted = mask_advertising_wanted; |
| 3059 | ethtool_link_mode_zero(advertising_wanted); |
| 3060 | ethtool_link_mode_set_bit( |
| 3061 | adv_bit, advertising_wanted); |
| 3062 | } |
| 3063 | /* otherwise: auto negotiate without forcing, |
| 3064 | * all supported speed will be assigned below |
| 3065 | */ |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3066 | } |
| 3067 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3068 | if (gset_changed) { |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3069 | struct ethtool_link_usettings *link_usettings; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3070 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3071 | link_usettings = do_ioctl_glinksettings(ctx); |
| 3072 | if (link_usettings == NULL) |
| 3073 | link_usettings = do_ioctl_gset(ctx); |
| 3074 | if (link_usettings == NULL) { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3075 | perror("Cannot get current device settings"); |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3076 | err = -1; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3077 | } else { |
| 3078 | /* Change everything the user specified. */ |
| 3079 | if (speed_wanted != -1) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3080 | link_usettings->base.speed = speed_wanted; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3081 | if (duplex_wanted != -1) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3082 | link_usettings->base.duplex = duplex_wanted; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3083 | if (port_wanted != -1) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3084 | link_usettings->base.port = port_wanted; |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 3085 | if (mdix_wanted != -1) { |
| 3086 | /* check driver supports MDI-X */ |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3087 | if (link_usettings->base.eth_tp_mdix_ctrl |
| 3088 | != ETH_TP_MDI_INVALID) |
| 3089 | link_usettings->base.eth_tp_mdix_ctrl |
| 3090 | = mdix_wanted; |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 3091 | else |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3092 | fprintf(stderr, |
| 3093 | "setting MDI not supported\n"); |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 3094 | } |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3095 | if (autoneg_wanted != -1) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3096 | link_usettings->base.autoneg = autoneg_wanted; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3097 | if (phyad_wanted != -1) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3098 | link_usettings->base.phy_address = phyad_wanted; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3099 | if (xcvr_wanted != -1) |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3100 | link_usettings->deprecated.transceiver |
| 3101 | = xcvr_wanted; |
Ben Hutchings | 1f4ae80 | 2011-02-17 18:51:15 +0000 | [diff] [blame] | 3102 | /* XXX If the user specified speed or duplex |
| 3103 | * then we should mask the advertised modes |
| 3104 | * accordingly. For now, warn that we aren't |
| 3105 | * doing that. |
| 3106 | */ |
| 3107 | if ((speed_wanted != -1 || duplex_wanted != -1) && |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3108 | link_usettings->base.autoneg && |
| 3109 | advertising_wanted == NULL) { |
Ben Hutchings | 1f4ae80 | 2011-02-17 18:51:15 +0000 | [diff] [blame] | 3110 | fprintf(stderr, "Cannot advertise"); |
| 3111 | if (speed_wanted >= 0) |
| 3112 | fprintf(stderr, " speed %d", |
| 3113 | speed_wanted); |
| 3114 | if (duplex_wanted >= 0) |
| 3115 | fprintf(stderr, " duplex %s", |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3116 | duplex_wanted ? |
Ben Hutchings | 1f4ae80 | 2011-02-17 18:51:15 +0000 | [diff] [blame] | 3117 | "full" : "half"); |
| 3118 | fprintf(stderr, "\n"); |
| 3119 | } |
| 3120 | if (autoneg_wanted == AUTONEG_ENABLE && |
Michael Chan | 1352322 | 2016-11-22 18:55:47 -0500 | [diff] [blame] | 3121 | advertising_wanted == NULL && |
| 3122 | full_advertising_wanted == NULL) { |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3123 | unsigned int i; |
| 3124 | |
Johan Gunnarsson | 517f88b | 2012-08-24 13:32:45 +0200 | [diff] [blame] | 3125 | /* Auto negotiation enabled, but with |
| 3126 | * unspecified speed and duplex: enable all |
| 3127 | * supported speeds and duplexes. |
| 3128 | */ |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3129 | ethtool_link_mode_for_each_u32(i) { |
| 3130 | u32 sup = link_usettings->link_modes.supported[i]; |
| 3131 | u32 *adv = link_usettings->link_modes.advertising + i; |
| 3132 | |
| 3133 | *adv = ((*adv & ~all_advertised_modes[i]) |
| 3134 | | (sup & all_advertised_modes[i])); |
| 3135 | } |
Johan Gunnarsson | 517f88b | 2012-08-24 13:32:45 +0200 | [diff] [blame] | 3136 | |
| 3137 | /* If driver supports unknown flags, we cannot |
| 3138 | * be sure that we enable all link modes. |
| 3139 | */ |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3140 | ethtool_link_mode_for_each_u32(i) { |
| 3141 | u32 sup = link_usettings->link_modes.supported[i]; |
| 3142 | |
| 3143 | if ((sup & all_advertised_flags[i]) != sup) { |
| 3144 | fprintf(stderr, "Driver supports one or more unknown flags\n"); |
| 3145 | break; |
| 3146 | } |
Johan Gunnarsson | 517f88b | 2012-08-24 13:32:45 +0200 | [diff] [blame] | 3147 | } |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3148 | } else if (advertising_wanted != NULL) { |
| 3149 | unsigned int i; |
| 3150 | |
Johan Gunnarsson | 517f88b | 2012-08-24 13:32:45 +0200 | [diff] [blame] | 3151 | /* Enable all requested modes */ |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3152 | ethtool_link_mode_for_each_u32(i) { |
| 3153 | u32 *adv = link_usettings->link_modes.advertising + i; |
| 3154 | |
| 3155 | *adv = ((*adv & ~all_advertised_modes[i]) |
| 3156 | | advertising_wanted[i]); |
| 3157 | } |
| 3158 | } else if (full_advertising_wanted != NULL) { |
| 3159 | ethtool_link_mode_copy( |
| 3160 | link_usettings->link_modes.advertising, |
| 3161 | full_advertising_wanted); |
Michael Chan | af2dbf7 | 2005-10-07 13:45:10 -0700 | [diff] [blame] | 3162 | } |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3163 | |
| 3164 | /* Try to perform the update. */ |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 3165 | if (link_usettings->base.cmd == ETHTOOL_GLINKSETTINGS) |
| 3166 | err = do_ioctl_slinksettings(ctx, |
| 3167 | link_usettings); |
| 3168 | else |
| 3169 | err = do_ioctl_sset(ctx, link_usettings); |
| 3170 | free(link_usettings); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3171 | if (err < 0) |
| 3172 | perror("Cannot set new settings"); |
| 3173 | } |
| 3174 | if (err < 0) { |
| 3175 | if (speed_wanted != -1) |
| 3176 | fprintf(stderr, " not setting speed\n"); |
| 3177 | if (duplex_wanted != -1) |
| 3178 | fprintf(stderr, " not setting duplex\n"); |
| 3179 | if (port_wanted != -1) |
| 3180 | fprintf(stderr, " not setting port\n"); |
| 3181 | if (autoneg_wanted != -1) |
| 3182 | fprintf(stderr, " not setting autoneg\n"); |
| 3183 | if (phyad_wanted != -1) |
| 3184 | fprintf(stderr, " not setting phy_address\n"); |
| 3185 | if (xcvr_wanted != -1) |
| 3186 | fprintf(stderr, " not setting transceiver\n"); |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 3187 | if (mdix_wanted != -1) |
| 3188 | fprintf(stderr, " not setting mdix\n"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | if (gwol_changed) { |
| 3193 | struct ethtool_wolinfo wol; |
| 3194 | |
| 3195 | wol.cmd = ETHTOOL_GWOL; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3196 | err = send_ioctl(ctx, &wol); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3197 | if (err < 0) { |
| 3198 | perror("Cannot get current wake-on-lan settings"); |
| 3199 | } else { |
| 3200 | /* Change everything the user specified. */ |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3201 | if (wol_change) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3202 | wol.wolopts = wol_wanted; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3203 | if (sopass_change) { |
| 3204 | int i; |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3205 | for (i = 0; i < SOPASS_MAX; i++) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3206 | wol.sopass[i] = sopass_wanted[i]; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | /* Try to perform the update. */ |
| 3210 | wol.cmd = ETHTOOL_SWOL; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3211 | err = send_ioctl(ctx, &wol); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3212 | if (err < 0) |
| 3213 | perror("Cannot set new wake-on-lan settings"); |
| 3214 | } |
| 3215 | if (err < 0) { |
| 3216 | if (wol_change) |
| 3217 | fprintf(stderr, " not setting wol\n"); |
| 3218 | if (sopass_change) |
| 3219 | fprintf(stderr, " not setting sopass\n"); |
| 3220 | } |
| 3221 | } |
| 3222 | |
Ben Hutchings | 97d0ee2 | 2010-06-25 15:49:45 +0100 | [diff] [blame] | 3223 | if (msglvl_changed) { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3224 | struct ethtool_value edata; |
| 3225 | |
Ben Hutchings | 97d0ee2 | 2010-06-25 15:49:45 +0100 | [diff] [blame] | 3226 | edata.cmd = ETHTOOL_GMSGLVL; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3227 | err = send_ioctl(ctx, &edata); |
Ben Hutchings | 97d0ee2 | 2010-06-25 15:49:45 +0100 | [diff] [blame] | 3228 | if (err < 0) { |
| 3229 | perror("Cannot get msglvl"); |
| 3230 | } else { |
| 3231 | edata.cmd = ETHTOOL_SMSGLVL; |
Ben Hutchings | 967cb31 | 2010-09-23 22:48:14 +0100 | [diff] [blame] | 3232 | edata.data = ((edata.data & ~msglvl_mask) | |
Ben Hutchings | 97d0ee2 | 2010-06-25 15:49:45 +0100 | [diff] [blame] | 3233 | msglvl_wanted); |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3234 | err = send_ioctl(ctx, &edata); |
Ben Hutchings | 97d0ee2 | 2010-06-25 15:49:45 +0100 | [diff] [blame] | 3235 | if (err < 0) |
| 3236 | perror("Cannot set new msglvl"); |
| 3237 | } |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | return 0; |
| 3241 | } |
| 3242 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3243 | static int do_gregs(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3244 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3245 | int gregs_changed = 0; |
| 3246 | int gregs_dump_raw = 0; |
| 3247 | int gregs_dump_hex = 0; |
| 3248 | char *gregs_dump_file = NULL; |
| 3249 | struct cmdline_info cmdline_gregs[] = { |
| 3250 | { "raw", CMDL_BOOL, &gregs_dump_raw, NULL }, |
| 3251 | { "hex", CMDL_BOOL, &gregs_dump_hex, NULL }, |
| 3252 | { "file", CMDL_STR, &gregs_dump_file, NULL }, |
| 3253 | }; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3254 | int err; |
| 3255 | struct ethtool_drvinfo drvinfo; |
| 3256 | struct ethtool_regs *regs; |
| 3257 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3258 | parse_generic_cmdline(ctx, &gregs_changed, |
| 3259 | cmdline_gregs, ARRAY_SIZE(cmdline_gregs)); |
| 3260 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3261 | drvinfo.cmd = ETHTOOL_GDRVINFO; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3262 | err = send_ioctl(ctx, &drvinfo); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3263 | if (err < 0) { |
| 3264 | perror("Cannot get driver information"); |
| 3265 | return 72; |
| 3266 | } |
| 3267 | |
| 3268 | regs = calloc(1, sizeof(*regs)+drvinfo.regdump_len); |
| 3269 | if (!regs) { |
| 3270 | perror("Cannot allocate memory for register dump"); |
| 3271 | return 73; |
| 3272 | } |
| 3273 | regs->cmd = ETHTOOL_GREGS; |
| 3274 | regs->len = drvinfo.regdump_len; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3275 | err = send_ioctl(ctx, regs); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3276 | if (err < 0) { |
| 3277 | perror("Cannot get register dump"); |
| 3278 | free(regs); |
| 3279 | return 74; |
| 3280 | } |
David Decotigny | be4c2d0 | 2016-03-11 09:58:16 -0800 | [diff] [blame] | 3281 | |
| 3282 | if (!gregs_dump_raw && gregs_dump_file != NULL) { |
| 3283 | /* overwrite reg values from file dump */ |
| 3284 | FILE *f = fopen(gregs_dump_file, "r"); |
Ivan Vecera | b610b27 | 2018-06-08 11:20:08 +0200 | [diff] [blame] | 3285 | struct ethtool_regs *nregs; |
David Decotigny | be4c2d0 | 2016-03-11 09:58:16 -0800 | [diff] [blame] | 3286 | struct stat st; |
| 3287 | size_t nread; |
| 3288 | |
| 3289 | if (!f || fstat(fileno(f), &st) < 0) { |
| 3290 | fprintf(stderr, "Can't open '%s': %s\n", |
| 3291 | gregs_dump_file, strerror(errno)); |
Ivan Vecera | b610b27 | 2018-06-08 11:20:08 +0200 | [diff] [blame] | 3292 | if (f) |
| 3293 | fclose(f); |
David Decotigny | be4c2d0 | 2016-03-11 09:58:16 -0800 | [diff] [blame] | 3294 | free(regs); |
| 3295 | return 75; |
| 3296 | } |
| 3297 | |
Ivan Vecera | b610b27 | 2018-06-08 11:20:08 +0200 | [diff] [blame] | 3298 | nregs = realloc(regs, sizeof(*regs) + st.st_size); |
| 3299 | if (!nregs) { |
| 3300 | perror("Cannot allocate memory for register dump"); |
| 3301 | free(regs); /* was not freed by realloc */ |
| 3302 | return 73; |
| 3303 | } |
| 3304 | regs = nregs; |
David Decotigny | be4c2d0 | 2016-03-11 09:58:16 -0800 | [diff] [blame] | 3305 | regs->len = st.st_size; |
| 3306 | nread = fread(regs->data, regs->len, 1, f); |
| 3307 | fclose(f); |
| 3308 | if (nread != 1) { |
| 3309 | free(regs); |
| 3310 | return 75; |
| 3311 | } |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3312 | } |
David Decotigny | be4c2d0 | 2016-03-11 09:58:16 -0800 | [diff] [blame] | 3313 | |
| 3314 | if (dump_regs(gregs_dump_raw, gregs_dump_hex, |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3315 | &drvinfo, regs) < 0) { |
Ben Hutchings | 963faa0 | 2012-10-10 22:19:15 +0100 | [diff] [blame] | 3316 | fprintf(stderr, "Cannot dump registers\n"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3317 | free(regs); |
| 3318 | return 75; |
| 3319 | } |
| 3320 | free(regs); |
| 3321 | |
| 3322 | return 0; |
| 3323 | } |
| 3324 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3325 | static int do_nway_rst(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3326 | { |
| 3327 | struct ethtool_value edata; |
| 3328 | int err; |
| 3329 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3330 | if (ctx->argc != 0) |
| 3331 | exit_bad_args(); |
| 3332 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3333 | edata.cmd = ETHTOOL_NWAY_RST; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3334 | err = send_ioctl(ctx, &edata); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3335 | if (err < 0) |
| 3336 | perror("Cannot restart autonegotiation"); |
| 3337 | |
| 3338 | return err; |
| 3339 | } |
| 3340 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3341 | static int do_geeprom(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3342 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3343 | int geeprom_changed = 0; |
| 3344 | int geeprom_dump_raw = 0; |
| 3345 | u32 geeprom_offset = 0; |
| 3346 | u32 geeprom_length = -1; |
| 3347 | struct cmdline_info cmdline_geeprom[] = { |
| 3348 | { "offset", CMDL_U32, &geeprom_offset, NULL }, |
| 3349 | { "length", CMDL_U32, &geeprom_length, NULL }, |
| 3350 | { "raw", CMDL_BOOL, &geeprom_dump_raw, NULL }, |
| 3351 | }; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3352 | int err; |
| 3353 | struct ethtool_drvinfo drvinfo; |
| 3354 | struct ethtool_eeprom *eeprom; |
| 3355 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3356 | parse_generic_cmdline(ctx, &geeprom_changed, |
| 3357 | cmdline_geeprom, ARRAY_SIZE(cmdline_geeprom)); |
| 3358 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3359 | drvinfo.cmd = ETHTOOL_GDRVINFO; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3360 | err = send_ioctl(ctx, &drvinfo); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3361 | if (err < 0) { |
| 3362 | perror("Cannot get driver information"); |
| 3363 | return 74; |
| 3364 | } |
| 3365 | |
Ben Hutchings | bec0363 | 2011-06-06 11:35:19 +0100 | [diff] [blame] | 3366 | if (geeprom_length == -1) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3367 | geeprom_length = drvinfo.eedump_len; |
| 3368 | |
| 3369 | if (drvinfo.eedump_len < geeprom_offset + geeprom_length) |
| 3370 | geeprom_length = drvinfo.eedump_len - geeprom_offset; |
| 3371 | |
| 3372 | eeprom = calloc(1, sizeof(*eeprom)+geeprom_length); |
| 3373 | if (!eeprom) { |
| 3374 | perror("Cannot allocate memory for EEPROM data"); |
| 3375 | return 75; |
| 3376 | } |
| 3377 | eeprom->cmd = ETHTOOL_GEEPROM; |
| 3378 | eeprom->len = geeprom_length; |
| 3379 | eeprom->offset = geeprom_offset; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3380 | err = send_ioctl(ctx, eeprom); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3381 | if (err < 0) { |
| 3382 | perror("Cannot get EEPROM data"); |
| 3383 | free(eeprom); |
| 3384 | return 74; |
| 3385 | } |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3386 | err = dump_eeprom(geeprom_dump_raw, &drvinfo, eeprom); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3387 | free(eeprom); |
| 3388 | |
| 3389 | return err; |
| 3390 | } |
| 3391 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3392 | static int do_seeprom(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3393 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3394 | int seeprom_changed = 0; |
| 3395 | u32 seeprom_magic = 0; |
| 3396 | u32 seeprom_length = -1; |
| 3397 | u32 seeprom_offset = 0; |
| 3398 | u8 seeprom_value = 0; |
| 3399 | int seeprom_value_seen = 0; |
| 3400 | struct cmdline_info cmdline_seeprom[] = { |
| 3401 | { "magic", CMDL_U32, &seeprom_magic, NULL }, |
| 3402 | { "offset", CMDL_U32, &seeprom_offset, NULL }, |
| 3403 | { "length", CMDL_U32, &seeprom_length, NULL }, |
| 3404 | { "value", CMDL_U8, &seeprom_value, NULL, |
| 3405 | 0, &seeprom_value_seen }, |
| 3406 | }; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3407 | int err; |
Mandeep Singh Baines | 2121eea | 2008-06-18 10:38:02 -0700 | [diff] [blame] | 3408 | struct ethtool_drvinfo drvinfo; |
| 3409 | struct ethtool_eeprom *eeprom; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3410 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3411 | parse_generic_cmdline(ctx, &seeprom_changed, |
| 3412 | cmdline_seeprom, ARRAY_SIZE(cmdline_seeprom)); |
| 3413 | |
Mandeep Singh Baines | 2121eea | 2008-06-18 10:38:02 -0700 | [diff] [blame] | 3414 | drvinfo.cmd = ETHTOOL_GDRVINFO; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3415 | err = send_ioctl(ctx, &drvinfo); |
Mandeep Singh Baines | 2121eea | 2008-06-18 10:38:02 -0700 | [diff] [blame] | 3416 | if (err < 0) { |
| 3417 | perror("Cannot get driver information"); |
| 3418 | return 74; |
| 3419 | } |
| 3420 | |
Ben Hutchings | bec0363 | 2011-06-06 11:35:19 +0100 | [diff] [blame] | 3421 | if (seeprom_value_seen) |
Mandeep Singh Baines | 2121eea | 2008-06-18 10:38:02 -0700 | [diff] [blame] | 3422 | seeprom_length = 1; |
| 3423 | |
Ben Hutchings | bec0363 | 2011-06-06 11:35:19 +0100 | [diff] [blame] | 3424 | if (seeprom_length == -1) |
Mandeep Singh Baines | 2121eea | 2008-06-18 10:38:02 -0700 | [diff] [blame] | 3425 | seeprom_length = drvinfo.eedump_len; |
| 3426 | |
David Decotigny | b03c8b4 | 2016-03-11 09:58:17 -0800 | [diff] [blame] | 3427 | if (drvinfo.eedump_len < seeprom_offset + seeprom_length) { |
| 3428 | fprintf(stderr, "offset & length out of bounds\n"); |
| 3429 | return 1; |
| 3430 | } |
Mandeep Singh Baines | 2121eea | 2008-06-18 10:38:02 -0700 | [diff] [blame] | 3431 | |
| 3432 | eeprom = calloc(1, sizeof(*eeprom)+seeprom_length); |
| 3433 | if (!eeprom) { |
| 3434 | perror("Cannot allocate memory for EEPROM data"); |
| 3435 | return 75; |
| 3436 | } |
| 3437 | |
| 3438 | eeprom->cmd = ETHTOOL_SEEPROM; |
| 3439 | eeprom->len = seeprom_length; |
| 3440 | eeprom->offset = seeprom_offset; |
| 3441 | eeprom->magic = seeprom_magic; |
| 3442 | eeprom->data[0] = seeprom_value; |
| 3443 | |
| 3444 | /* Multi-byte write: read input from stdin */ |
David Decotigny | b03c8b4 | 2016-03-11 09:58:17 -0800 | [diff] [blame] | 3445 | if (!seeprom_value_seen) { |
| 3446 | if (fread(eeprom->data, eeprom->len, 1, stdin) != 1) { |
| 3447 | fprintf(stderr, "not enough data from stdin\n"); |
| 3448 | free(eeprom); |
| 3449 | return 75; |
| 3450 | } |
| 3451 | if ((fgetc(stdin) != EOF) || !feof(stdin)) { |
| 3452 | fprintf(stderr, "too much data from stdin\n"); |
| 3453 | free(eeprom); |
| 3454 | return 75; |
| 3455 | } |
| 3456 | } |
Mandeep Singh Baines | 2121eea | 2008-06-18 10:38:02 -0700 | [diff] [blame] | 3457 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3458 | err = send_ioctl(ctx, eeprom); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3459 | if (err < 0) { |
| 3460 | perror("Cannot set EEPROM data"); |
Mandeep Singh Baines | 2121eea | 2008-06-18 10:38:02 -0700 | [diff] [blame] | 3461 | err = 87; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3462 | } |
Mandeep Singh Baines | 2121eea | 2008-06-18 10:38:02 -0700 | [diff] [blame] | 3463 | free(eeprom); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3464 | |
| 3465 | return err; |
| 3466 | } |
| 3467 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3468 | static int do_test(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3469 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3470 | enum { |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3471 | ONLINE = 0, |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3472 | OFFLINE, |
| 3473 | EXTERNAL_LB, |
| 3474 | } test_type; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3475 | int err; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3476 | struct ethtool_test *test; |
| 3477 | struct ethtool_gstrings *strings; |
| 3478 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3479 | if (ctx->argc > 1) |
| 3480 | exit_bad_args(); |
| 3481 | if (ctx->argc == 1) { |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3482 | if (!strcmp(ctx->argp[0], "online")) |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3483 | test_type = ONLINE; |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3484 | else if (!strcmp(*ctx->argp, "offline")) |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3485 | test_type = OFFLINE; |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3486 | else if (!strcmp(*ctx->argp, "external_lb")) |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3487 | test_type = EXTERNAL_LB; |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3488 | else |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3489 | exit_bad_args(); |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3490 | } else { |
| 3491 | test_type = OFFLINE; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3492 | } |
| 3493 | |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3494 | strings = get_stringset(ctx, ETH_SS_TEST, |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 3495 | offsetof(struct ethtool_drvinfo, testinfo_len), |
| 3496 | 1); |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3497 | if (!strings) { |
| 3498 | perror("Cannot get strings"); |
| 3499 | return 74; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3500 | } |
| 3501 | |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3502 | test = calloc(1, sizeof(*test) + strings->len * sizeof(u64)); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3503 | if (!test) { |
| 3504 | perror("Cannot allocate memory for test info"); |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3505 | free(strings); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3506 | return 73; |
| 3507 | } |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3508 | memset(test->data, 0, strings->len * sizeof(u64)); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3509 | test->cmd = ETHTOOL_TEST; |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3510 | test->len = strings->len; |
Sucheta Chakraborty | beceb09 | 2011-09-20 03:31:34 -0700 | [diff] [blame] | 3511 | if (test_type == EXTERNAL_LB) |
| 3512 | test->flags = (ETH_TEST_FL_OFFLINE | ETH_TEST_FL_EXTERNAL_LB); |
| 3513 | else if (test_type == OFFLINE) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3514 | test->flags = ETH_TEST_FL_OFFLINE; |
| 3515 | else |
| 3516 | test->flags = 0; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3517 | err = send_ioctl(ctx, test); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3518 | if (err < 0) { |
| 3519 | perror("Cannot test"); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3520 | free(test); |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3521 | free(strings); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3522 | return 74; |
| 3523 | } |
| 3524 | |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3525 | err = dump_test(test, strings); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3526 | free(test); |
| 3527 | free(strings); |
| 3528 | |
| 3529 | return err; |
| 3530 | } |
| 3531 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3532 | static int do_phys_id(struct cmd_context *ctx) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3533 | { |
| 3534 | int err; |
| 3535 | struct ethtool_value edata; |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3536 | int phys_id_time; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3537 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3538 | if (ctx->argc > 1) |
| 3539 | exit_bad_args(); |
| 3540 | if (ctx->argc == 1) |
| 3541 | phys_id_time = get_int(*ctx->argp, 0); |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3542 | else |
| 3543 | phys_id_time = 0; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3544 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3545 | edata.cmd = ETHTOOL_PHYS_ID; |
| 3546 | edata.data = phys_id_time; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3547 | err = send_ioctl(ctx, &edata); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3548 | if (err < 0) |
| 3549 | perror("Cannot identify NIC"); |
| 3550 | |
| 3551 | return err; |
| 3552 | } |
| 3553 | |
Ben Hutchings | 395d830 | 2016-03-13 15:56:41 +0000 | [diff] [blame] | 3554 | static int do_gstats(struct cmd_context *ctx, int cmd, int stringset, |
| 3555 | const char *name) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3556 | { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3557 | struct ethtool_gstrings *strings; |
| 3558 | struct ethtool_stats *stats; |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3559 | unsigned int n_stats, sz_stats, i; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3560 | int err; |
| 3561 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3562 | if (ctx->argc != 0) |
| 3563 | exit_bad_args(); |
| 3564 | |
Ben Hutchings | 395d830 | 2016-03-13 15:56:41 +0000 | [diff] [blame] | 3565 | strings = get_stringset(ctx, stringset, |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 3566 | offsetof(struct ethtool_drvinfo, n_stats), |
| 3567 | 0); |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3568 | if (!strings) { |
| 3569 | perror("Cannot get stats strings information"); |
| 3570 | return 96; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3571 | } |
| 3572 | |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3573 | n_stats = strings->len; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3574 | if (n_stats < 1) { |
| 3575 | fprintf(stderr, "no stats available\n"); |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3576 | free(strings); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3577 | return 94; |
| 3578 | } |
| 3579 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3580 | sz_stats = n_stats * sizeof(u64); |
| 3581 | |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3582 | stats = calloc(1, sz_stats + sizeof(struct ethtool_stats)); |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3583 | if (!stats) { |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3584 | fprintf(stderr, "no memory available\n"); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3585 | free(strings); |
Ben Hutchings | d7c4a37 | 2011-11-30 01:46:36 +0000 | [diff] [blame] | 3586 | return 95; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3587 | } |
| 3588 | |
Ben Hutchings | 395d830 | 2016-03-13 15:56:41 +0000 | [diff] [blame] | 3589 | stats->cmd = cmd; |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3590 | stats->n_stats = n_stats; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3591 | err = send_ioctl(ctx, stats); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3592 | if (err < 0) { |
| 3593 | perror("Cannot get stats information"); |
| 3594 | free(strings); |
| 3595 | free(stats); |
| 3596 | return 97; |
| 3597 | } |
| 3598 | |
| 3599 | /* todo - pretty-print the strings per-driver */ |
Ben Hutchings | 395d830 | 2016-03-13 15:56:41 +0000 | [diff] [blame] | 3600 | fprintf(stdout, "%s statistics:\n", name); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3601 | for (i = 0; i < n_stats; i++) { |
Stephen Hemminger | 7764430 | 2007-01-11 15:36:10 -0800 | [diff] [blame] | 3602 | fprintf(stdout, " %.*s: %llu\n", |
Jeff Garzik | ba2f54b | 2007-07-26 13:24:59 -0400 | [diff] [blame] | 3603 | ETH_GSTRING_LEN, |
Stephen Hemminger | 7764430 | 2007-01-11 15:36:10 -0800 | [diff] [blame] | 3604 | &strings->data[i * ETH_GSTRING_LEN], |
| 3605 | stats->data[i]); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 3606 | } |
| 3607 | free(strings); |
| 3608 | free(stats); |
| 3609 | |
| 3610 | return 0; |
| 3611 | } |
| 3612 | |
Ben Hutchings | 395d830 | 2016-03-13 15:56:41 +0000 | [diff] [blame] | 3613 | static int do_gnicstats(struct cmd_context *ctx) |
| 3614 | { |
| 3615 | return do_gstats(ctx, ETHTOOL_GSTATS, ETH_SS_STATS, "NIC"); |
| 3616 | } |
| 3617 | |
Andrew Lunn | 8b4b823 | 2015-12-23 12:58:31 +0100 | [diff] [blame] | 3618 | static int do_gphystats(struct cmd_context *ctx) |
| 3619 | { |
Ben Hutchings | 395d830 | 2016-03-13 15:56:41 +0000 | [diff] [blame] | 3620 | return do_gstats(ctx, ETHTOOL_GPHYSTATS, ETH_SS_PHY_STATS, "PHY"); |
Andrew Lunn | 8b4b823 | 2015-12-23 12:58:31 +0100 | [diff] [blame] | 3621 | } |
| 3622 | |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 3623 | static int do_srxntuple(struct cmd_context *ctx, |
| 3624 | struct ethtool_rx_flow_spec *rx_rule_fs); |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3625 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3626 | static int do_srxclass(struct cmd_context *ctx) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3627 | { |
| 3628 | int err; |
| 3629 | |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 3630 | if (ctx->argc < 2) |
| 3631 | exit_bad_args(); |
| 3632 | |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3633 | if (!strcmp(ctx->argp[0], "rx-flow-hash")) { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3634 | int rx_fhash_set; |
| 3635 | u32 rx_fhash_val; |
| 3636 | struct ethtool_rxnfc nfccmd; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3637 | bool flow_rss = false; |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3638 | |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3639 | if (ctx->argc == 5) { |
| 3640 | if (strcmp(ctx->argp[3], "context")) |
| 3641 | exit_bad_args(); |
| 3642 | flow_rss = true; |
| 3643 | nfccmd.rss_context = get_u32(ctx->argp[4], 0); |
| 3644 | } else if (ctx->argc != 3) { |
| 3645 | exit_bad_args(); |
| 3646 | } |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3647 | rx_fhash_set = rxflow_str_to_type(ctx->argp[1]); |
| 3648 | if (!rx_fhash_set) |
| 3649 | exit_bad_args(); |
| 3650 | if (parse_rxfhashopts(ctx->argp[2], &rx_fhash_val) < 0) |
| 3651 | exit_bad_args(); |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3652 | |
| 3653 | nfccmd.cmd = ETHTOOL_SRXFH; |
| 3654 | nfccmd.flow_type = rx_fhash_set; |
| 3655 | nfccmd.data = rx_fhash_val; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3656 | if (flow_rss) |
| 3657 | nfccmd.flow_type |= FLOW_RSS; |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3658 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3659 | err = send_ioctl(ctx, &nfccmd); |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3660 | if (err < 0) |
| 3661 | perror("Cannot change RX network flow hashing options"); |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 3662 | } else if (!strcmp(ctx->argp[0], "flow-type")) { |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 3663 | struct ethtool_rx_flow_spec rx_rule_fs; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3664 | __u32 rss_context = 0; |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 3665 | |
| 3666 | ctx->argc--; |
| 3667 | ctx->argp++; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3668 | if (rxclass_parse_ruleopts(ctx, &rx_rule_fs, &rss_context) < 0) |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 3669 | exit_bad_args(); |
| 3670 | |
| 3671 | /* attempt to add rule via N-tuple specifier */ |
| 3672 | err = do_srxntuple(ctx, &rx_rule_fs); |
| 3673 | if (!err) |
| 3674 | return 0; |
| 3675 | |
| 3676 | /* attempt to add rule via network flow classifier */ |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3677 | err = rxclass_rule_ins(ctx, &rx_rule_fs, rss_context); |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 3678 | if (err < 0) { |
| 3679 | fprintf(stderr, "Cannot insert" |
| 3680 | " classification rule\n"); |
| 3681 | return 1; |
| 3682 | } |
| 3683 | } else if (!strcmp(ctx->argp[0], "delete")) { |
| 3684 | int rx_class_rule_del = |
| 3685 | get_uint_range(ctx->argp[1], 0, INT_MAX); |
| 3686 | |
| 3687 | err = rxclass_rule_del(ctx, rx_class_rule_del); |
| 3688 | |
| 3689 | if (err < 0) { |
| 3690 | fprintf(stderr, "Cannot delete" |
| 3691 | " classification rule\n"); |
| 3692 | return 1; |
| 3693 | } |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3694 | } else { |
| 3695 | exit_bad_args(); |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | return 0; |
| 3699 | } |
| 3700 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3701 | static int do_grxclass(struct cmd_context *ctx) |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3702 | { |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3703 | struct ethtool_rxnfc nfccmd; |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3704 | int err; |
| 3705 | |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3706 | if (ctx->argc > 0 && !strcmp(ctx->argp[0], "rx-flow-hash")) { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3707 | int rx_fhash_get; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3708 | bool flow_rss = false; |
| 3709 | |
| 3710 | if (ctx->argc == 4) { |
| 3711 | if (strcmp(ctx->argp[2], "context")) |
| 3712 | exit_bad_args(); |
| 3713 | flow_rss = true; |
| 3714 | nfccmd.rss_context = get_u32(ctx->argp[3], 0); |
| 3715 | } else if (ctx->argc != 2) { |
| 3716 | exit_bad_args(); |
| 3717 | } |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 3718 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3719 | rx_fhash_get = rxflow_str_to_type(ctx->argp[1]); |
| 3720 | if (!rx_fhash_get) |
| 3721 | exit_bad_args(); |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3722 | |
| 3723 | nfccmd.cmd = ETHTOOL_GRXFH; |
| 3724 | nfccmd.flow_type = rx_fhash_get; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3725 | if (flow_rss) |
| 3726 | nfccmd.flow_type |= FLOW_RSS; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3727 | err = send_ioctl(ctx, &nfccmd); |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3728 | if (err < 0) { |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3729 | perror("Cannot get RX network flow hashing options"); |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3730 | } else { |
| 3731 | if (flow_rss) |
| 3732 | fprintf(stdout, "For RSS context %u:\n", |
| 3733 | nfccmd.rss_context); |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3734 | dump_rxfhash(rx_fhash_get, nfccmd.data); |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3735 | } |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 3736 | } else if (ctx->argc == 2 && !strcmp(ctx->argp[0], "rule")) { |
| 3737 | int rx_class_rule_get = |
| 3738 | get_uint_range(ctx->argp[1], 0, INT_MAX); |
| 3739 | |
| 3740 | err = rxclass_rule_get(ctx, rx_class_rule_get); |
| 3741 | if (err < 0) |
| 3742 | fprintf(stderr, "Cannot get RX classification rule\n"); |
| 3743 | } else if (ctx->argc == 0) { |
| 3744 | nfccmd.cmd = ETHTOOL_GRXRINGS; |
| 3745 | err = send_ioctl(ctx, &nfccmd); |
| 3746 | if (err < 0) |
| 3747 | perror("Cannot get RX rings"); |
| 3748 | else |
| 3749 | fprintf(stdout, "%d RX rings available\n", |
| 3750 | (int)nfccmd.data); |
| 3751 | |
| 3752 | err = rxclass_rule_getall(ctx); |
| 3753 | if (err < 0) |
| 3754 | fprintf(stderr, "RX classification rule retrieval failed\n"); |
| 3755 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 3756 | } else { |
| 3757 | exit_bad_args(); |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3758 | } |
| 3759 | |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 3760 | return err ? 1 : 0; |
Santwona Behera | 1bd8712 | 2008-06-27 17:06:20 -0700 | [diff] [blame] | 3761 | } |
| 3762 | |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3763 | static void print_indir_table(struct cmd_context *ctx, |
| 3764 | struct ethtool_rxnfc *ring_count, |
| 3765 | u32 indir_size, u32 *indir) |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3766 | { |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3767 | u32 i; |
| 3768 | |
| 3769 | printf("RX flow hash indirection table for %s with %llu RX ring(s):\n", |
| 3770 | ctx->devname, ring_count->data); |
| 3771 | |
| 3772 | if (!indir_size) |
| 3773 | printf("Operation not supported\n"); |
| 3774 | |
| 3775 | for (i = 0; i < indir_size; i++) { |
| 3776 | if (i % 8 == 0) |
| 3777 | printf("%5u: ", i); |
| 3778 | printf(" %5u", indir[i]); |
Ben Hutchings | 530765b | 2015-04-05 03:00:52 +0100 | [diff] [blame] | 3779 | if (i % 8 == 7 || i == indir_size - 1) |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3780 | fputc('\n', stdout); |
| 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | static int do_grxfhindir(struct cmd_context *ctx, |
| 3785 | struct ethtool_rxnfc *ring_count) |
| 3786 | { |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3787 | struct ethtool_rxfh_indir indir_head; |
| 3788 | struct ethtool_rxfh_indir *indir; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3789 | int err; |
| 3790 | |
| 3791 | indir_head.cmd = ETHTOOL_GRXFHINDIR; |
| 3792 | indir_head.size = 0; |
| 3793 | err = send_ioctl(ctx, &indir_head); |
| 3794 | if (err < 0) { |
| 3795 | perror("Cannot get RX flow hash indirection table size"); |
| 3796 | return 1; |
| 3797 | } |
| 3798 | |
| 3799 | indir = malloc(sizeof(*indir) + |
| 3800 | indir_head.size * sizeof(*indir->ring_index)); |
| 3801 | if (!indir) { |
| 3802 | perror("Cannot allocate memory for indirection table"); |
| 3803 | return 1; |
| 3804 | } |
| 3805 | |
| 3806 | indir->cmd = ETHTOOL_GRXFHINDIR; |
| 3807 | indir->size = indir_head.size; |
| 3808 | err = send_ioctl(ctx, indir); |
| 3809 | if (err < 0) { |
| 3810 | perror("Cannot get RX flow hash indirection table"); |
| 3811 | free(indir); |
| 3812 | return 1; |
| 3813 | } |
| 3814 | |
| 3815 | print_indir_table(ctx, ring_count, indir->size, indir->ring_index); |
| 3816 | |
| 3817 | free(indir); |
| 3818 | return 0; |
| 3819 | } |
| 3820 | |
| 3821 | static int do_grxfh(struct cmd_context *ctx) |
| 3822 | { |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 3823 | struct ethtool_gstrings *hfuncs = NULL; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3824 | struct ethtool_rxfh rss_head = {0}; |
| 3825 | struct ethtool_rxnfc ring_count; |
| 3826 | struct ethtool_rxfh *rss; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3827 | u32 rss_context = 0; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3828 | u32 i, indir_bytes; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3829 | int arg_num = 0; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3830 | char *hkey; |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3831 | int err; |
| 3832 | |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3833 | while (arg_num < ctx->argc) { |
| 3834 | if (!strcmp(ctx->argp[arg_num], "context")) { |
| 3835 | ++arg_num; |
| 3836 | rss_context = get_int_range(ctx->argp[arg_num], 0, 1, |
| 3837 | ETH_RXFH_CONTEXT_ALLOC - 1); |
| 3838 | ++arg_num; |
| 3839 | } else { |
| 3840 | exit_bad_args(); |
| 3841 | } |
| 3842 | } |
| 3843 | |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3844 | ring_count.cmd = ETHTOOL_GRXRINGS; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 3845 | err = send_ioctl(ctx, &ring_count); |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3846 | if (err < 0) { |
| 3847 | perror("Cannot get RX ring count"); |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3848 | return 1; |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3849 | } |
| 3850 | |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3851 | rss_head.cmd = ETHTOOL_GRSSH; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3852 | rss_head.rss_context = rss_context; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3853 | err = send_ioctl(ctx, &rss_head); |
Edward Cree | 7984d34 | 2018-03-19 16:52:06 +0000 | [diff] [blame] | 3854 | if (err < 0 && errno == EOPNOTSUPP && !rss_context) { |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3855 | return do_grxfhindir(ctx, &ring_count); |
| 3856 | } else if (err < 0) { |
| 3857 | perror("Cannot get RX flow hash indir size and/or key size"); |
| 3858 | return 1; |
| 3859 | } |
| 3860 | |
| 3861 | rss = calloc(1, sizeof(*rss) + |
| 3862 | rss_head.indir_size * sizeof(rss_head.rss_config[0]) + |
| 3863 | rss_head.key_size); |
| 3864 | if (!rss) { |
| 3865 | perror("Cannot allocate memory for RX flow hash config"); |
| 3866 | return 1; |
| 3867 | } |
| 3868 | |
| 3869 | rss->cmd = ETHTOOL_GRSSH; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 3870 | rss->rss_context = rss_context; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3871 | rss->indir_size = rss_head.indir_size; |
| 3872 | rss->key_size = rss_head.key_size; |
| 3873 | err = send_ioctl(ctx, rss); |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3874 | if (err < 0) { |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3875 | perror("Cannot get RX flow hash configuration"); |
| 3876 | free(rss); |
| 3877 | return 1; |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3878 | } |
| 3879 | |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3880 | print_indir_table(ctx, &ring_count, rss->indir_size, rss->rss_config); |
| 3881 | |
| 3882 | indir_bytes = rss->indir_size * sizeof(rss->rss_config[0]); |
| 3883 | hkey = ((char *)rss->rss_config + indir_bytes); |
| 3884 | |
| 3885 | printf("RSS hash key:\n"); |
| 3886 | if (!rss->key_size) |
| 3887 | printf("Operation not supported\n"); |
| 3888 | |
| 3889 | for (i = 0; i < rss->key_size; i++) { |
| 3890 | if (i == (rss->key_size - 1)) |
| 3891 | printf("%02x\n", (u8) hkey[i]); |
| 3892 | else |
| 3893 | printf("%02x:", (u8) hkey[i]); |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3894 | } |
| 3895 | |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 3896 | printf("RSS hash function:\n"); |
| 3897 | if (!rss->hfunc) { |
| 3898 | printf(" Operation not supported\n"); |
| 3899 | goto out; |
| 3900 | } |
| 3901 | |
| 3902 | hfuncs = get_stringset(ctx, ETH_SS_RSS_HASH_FUNCS, 0, 1); |
| 3903 | if (!hfuncs) { |
| 3904 | perror("Cannot get hash functions names"); |
| 3905 | free(rss); |
| 3906 | return 1; |
| 3907 | } |
| 3908 | |
| 3909 | for (i = 0; i < hfuncs->len; i++) |
| 3910 | printf(" %s: %s\n", |
| 3911 | (const char *)hfuncs->data + i * ETH_GSTRING_LEN, |
| 3912 | (rss->hfunc & (1 << i)) ? "on" : "off"); |
| 3913 | |
| 3914 | out: |
| 3915 | free(hfuncs); |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3916 | free(rss); |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3917 | return 0; |
| 3918 | } |
| 3919 | |
Jacob Keller | 9cdf033 | 2016-02-08 16:05:06 -0800 | [diff] [blame] | 3920 | static int fill_indir_table(u32 *indir_size, u32 *indir, int rxfhindir_default, |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 3921 | int rxfhindir_start, int rxfhindir_equal, |
| 3922 | char **rxfhindir_weight, u32 num_weights) |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3923 | { |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3924 | u32 i; |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 3925 | |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3926 | if (rxfhindir_equal) { |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3927 | for (i = 0; i < *indir_size; i++) |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 3928 | indir[i] = rxfhindir_start + (i % rxfhindir_equal); |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3929 | } else if (rxfhindir_weight) { |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3930 | u32 j, weight, sum = 0, partial = 0; |
| 3931 | |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3932 | for (j = 0; j < num_weights; j++) { |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3933 | weight = get_u32(rxfhindir_weight[j], 0); |
| 3934 | sum += weight; |
| 3935 | } |
| 3936 | |
| 3937 | if (sum == 0) { |
| 3938 | fprintf(stderr, |
| 3939 | "At least one weight must be non-zero\n"); |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3940 | return 2; |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3941 | } |
| 3942 | |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3943 | if (sum > *indir_size) { |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3944 | fprintf(stderr, |
| 3945 | "Total weight exceeds the size of the " |
| 3946 | "indirection table\n"); |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3947 | return 2; |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | j = -1; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3951 | for (i = 0; i < *indir_size; i++) { |
| 3952 | while (i >= (*indir_size) * partial / sum) { |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3953 | j += 1; |
| 3954 | weight = get_u32(rxfhindir_weight[j], 0); |
| 3955 | partial += weight; |
| 3956 | } |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 3957 | indir[i] = rxfhindir_start + j; |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 3958 | } |
Jacob Keller | 9cdf033 | 2016-02-08 16:05:06 -0800 | [diff] [blame] | 3959 | } else if (rxfhindir_default) { |
| 3960 | /* "*indir_size == 0" ==> reset indir to default */ |
| 3961 | *indir_size = 0; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3962 | } else { |
| 3963 | *indir_size = ETH_RXFH_INDIR_NO_CHANGE; |
| 3964 | } |
| 3965 | |
| 3966 | return 0; |
| 3967 | } |
| 3968 | |
Jacob Keller | 9cdf033 | 2016-02-08 16:05:06 -0800 | [diff] [blame] | 3969 | static int do_srxfhindir(struct cmd_context *ctx, int rxfhindir_default, |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 3970 | int rxfhindir_start, int rxfhindir_equal, |
| 3971 | char **rxfhindir_weight, u32 num_weights) |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3972 | { |
| 3973 | struct ethtool_rxfh_indir indir_head; |
| 3974 | struct ethtool_rxfh_indir *indir; |
| 3975 | int err; |
| 3976 | |
| 3977 | indir_head.cmd = ETHTOOL_GRXFHINDIR; |
| 3978 | indir_head.size = 0; |
| 3979 | err = send_ioctl(ctx, &indir_head); |
| 3980 | if (err < 0) { |
| 3981 | perror("Cannot get RX flow hash indirection table size"); |
| 3982 | return 1; |
| 3983 | } |
| 3984 | |
| 3985 | indir = malloc(sizeof(*indir) + |
| 3986 | indir_head.size * sizeof(*indir->ring_index)); |
| 3987 | |
| 3988 | if (!indir) { |
| 3989 | perror("Cannot allocate memory for indirection table"); |
| 3990 | return 1; |
| 3991 | } |
| 3992 | |
| 3993 | indir->cmd = ETHTOOL_SRXFHINDIR; |
| 3994 | indir->size = indir_head.size; |
| 3995 | |
Jacob Keller | 9cdf033 | 2016-02-08 16:05:06 -0800 | [diff] [blame] | 3996 | if (fill_indir_table(&indir->size, indir->ring_index, |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 3997 | rxfhindir_default, rxfhindir_start, |
| 3998 | rxfhindir_equal, rxfhindir_weight, num_weights)) { |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 3999 | free(indir); |
| 4000 | return 1; |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 4001 | } |
| 4002 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4003 | err = send_ioctl(ctx, indir); |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 4004 | if (err < 0) { |
| 4005 | perror("Cannot set RX flow hash indirection table"); |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4006 | free(indir); |
| 4007 | return 1; |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 4008 | } |
| 4009 | |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4010 | free(indir); |
Ben Hutchings | 048038f | 2010-06-30 16:13:12 +0100 | [diff] [blame] | 4011 | return 0; |
| 4012 | } |
| 4013 | |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4014 | static int do_srxfh(struct cmd_context *ctx) |
| 4015 | { |
| 4016 | struct ethtool_rxfh rss_head = {0}; |
Ivan Vecera | e0fabbc | 2018-06-08 11:20:09 +0200 | [diff] [blame] | 4017 | struct ethtool_rxfh *rss = NULL; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4018 | struct ethtool_rxnfc ring_count; |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 4019 | int rxfhindir_equal = 0, rxfhindir_default = 0, rxfhindir_start = 0; |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4020 | struct ethtool_gstrings *hfuncs = NULL; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4021 | char **rxfhindir_weight = NULL; |
| 4022 | char *rxfhindir_key = NULL; |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4023 | char *req_hfunc_name = NULL; |
| 4024 | char *hfunc_name = NULL; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4025 | char *hkey = NULL; |
| 4026 | int err = 0; |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4027 | int i; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4028 | u32 arg_num = 0, indir_bytes = 0; |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4029 | u32 req_hfunc = 0; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4030 | u32 entry_size = sizeof(rss_head.rss_config[0]); |
| 4031 | u32 num_weights = 0; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 4032 | u32 rss_context = 0; |
| 4033 | int delete = 0; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4034 | |
Jacob Keller | 9cdf033 | 2016-02-08 16:05:06 -0800 | [diff] [blame] | 4035 | if (ctx->argc < 1) |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4036 | exit_bad_args(); |
| 4037 | |
| 4038 | while (arg_num < ctx->argc) { |
| 4039 | if (!strcmp(ctx->argp[arg_num], "equal")) { |
| 4040 | ++arg_num; |
| 4041 | rxfhindir_equal = get_int_range(ctx->argp[arg_num], |
| 4042 | 0, 1, INT_MAX); |
| 4043 | ++arg_num; |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 4044 | } else if (!strcmp(ctx->argp[arg_num], "start")) { |
| 4045 | ++arg_num; |
| 4046 | rxfhindir_start = get_int_range(ctx->argp[arg_num], |
| 4047 | 0, 0, INT_MAX); |
| 4048 | ++arg_num; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4049 | } else if (!strcmp(ctx->argp[arg_num], "weight")) { |
| 4050 | ++arg_num; |
| 4051 | rxfhindir_weight = ctx->argp + arg_num; |
| 4052 | while (arg_num < ctx->argc && |
| 4053 | isdigit((unsigned char)ctx->argp[arg_num][0])) { |
| 4054 | ++arg_num; |
| 4055 | ++num_weights; |
| 4056 | } |
| 4057 | if (!num_weights) |
| 4058 | exit_bad_args(); |
| 4059 | } else if (!strcmp(ctx->argp[arg_num], "hkey")) { |
| 4060 | ++arg_num; |
| 4061 | rxfhindir_key = ctx->argp[arg_num]; |
| 4062 | if (!rxfhindir_key) |
| 4063 | exit_bad_args(); |
| 4064 | ++arg_num; |
Jacob Keller | 9cdf033 | 2016-02-08 16:05:06 -0800 | [diff] [blame] | 4065 | } else if (!strcmp(ctx->argp[arg_num], "default")) { |
| 4066 | ++arg_num; |
| 4067 | rxfhindir_default = 1; |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4068 | } else if (!strcmp(ctx->argp[arg_num], "hfunc")) { |
| 4069 | ++arg_num; |
| 4070 | req_hfunc_name = ctx->argp[arg_num]; |
| 4071 | if (!req_hfunc_name) |
| 4072 | exit_bad_args(); |
| 4073 | ++arg_num; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 4074 | } else if (!strcmp(ctx->argp[arg_num], "context")) { |
| 4075 | ++arg_num; |
| 4076 | if(!strcmp(ctx->argp[arg_num], "new")) |
| 4077 | rss_context = ETH_RXFH_CONTEXT_ALLOC; |
| 4078 | else |
| 4079 | rss_context = get_int_range( |
| 4080 | ctx->argp[arg_num], 0, 1, |
| 4081 | ETH_RXFH_CONTEXT_ALLOC - 1); |
| 4082 | ++arg_num; |
| 4083 | } else if (!strcmp(ctx->argp[arg_num], "delete")) { |
| 4084 | ++arg_num; |
| 4085 | delete = 1; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4086 | } else { |
| 4087 | exit_bad_args(); |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | if (rxfhindir_equal && rxfhindir_weight) { |
| 4092 | fprintf(stderr, |
| 4093 | "Equal and weight options are mutually exclusive\n"); |
| 4094 | return 1; |
| 4095 | } |
| 4096 | |
Jacob Keller | 9cdf033 | 2016-02-08 16:05:06 -0800 | [diff] [blame] | 4097 | if (rxfhindir_equal && rxfhindir_default) { |
| 4098 | fprintf(stderr, |
| 4099 | "Equal and default options are mutually exclusive\n"); |
| 4100 | return 1; |
| 4101 | } |
| 4102 | |
| 4103 | if (rxfhindir_weight && rxfhindir_default) { |
| 4104 | fprintf(stderr, |
| 4105 | "Weight and default options are mutually exclusive\n"); |
| 4106 | return 1; |
| 4107 | } |
| 4108 | |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 4109 | if (rxfhindir_start && rxfhindir_default) { |
| 4110 | fprintf(stderr, |
| 4111 | "Start and default options are mutually exclusive\n"); |
| 4112 | return 1; |
| 4113 | } |
| 4114 | |
| 4115 | if (rxfhindir_start && !(rxfhindir_equal || rxfhindir_weight)) { |
| 4116 | fprintf(stderr, |
| 4117 | "Start must be used with equal or weight options\n"); |
| 4118 | return 1; |
| 4119 | } |
| 4120 | |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 4121 | if (rxfhindir_default && rss_context) { |
| 4122 | fprintf(stderr, |
| 4123 | "Default and context options are mutually exclusive\n"); |
| 4124 | return 1; |
| 4125 | } |
| 4126 | |
| 4127 | if (delete && !rss_context) { |
| 4128 | fprintf(stderr, "Delete option requires context option\n"); |
| 4129 | return 1; |
| 4130 | } |
| 4131 | |
| 4132 | if (delete && rxfhindir_weight) { |
| 4133 | fprintf(stderr, |
| 4134 | "Delete and weight options are mutually exclusive\n"); |
| 4135 | return 1; |
| 4136 | } |
| 4137 | |
| 4138 | if (delete && rxfhindir_equal) { |
| 4139 | fprintf(stderr, |
| 4140 | "Delete and equal options are mutually exclusive\n"); |
| 4141 | return 1; |
| 4142 | } |
| 4143 | |
| 4144 | if (delete && rxfhindir_default) { |
| 4145 | fprintf(stderr, |
| 4146 | "Delete and default options are mutually exclusive\n"); |
| 4147 | return 1; |
| 4148 | } |
| 4149 | |
| 4150 | if (delete && rxfhindir_key) { |
| 4151 | fprintf(stderr, |
| 4152 | "Delete and hkey options are mutually exclusive\n"); |
| 4153 | return 1; |
| 4154 | } |
| 4155 | |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4156 | ring_count.cmd = ETHTOOL_GRXRINGS; |
| 4157 | err = send_ioctl(ctx, &ring_count); |
| 4158 | if (err < 0) { |
| 4159 | perror("Cannot get RX ring count"); |
| 4160 | return 1; |
| 4161 | } |
| 4162 | |
| 4163 | rss_head.cmd = ETHTOOL_GRSSH; |
| 4164 | err = send_ioctl(ctx, &rss_head); |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4165 | if (err < 0 && errno == EOPNOTSUPP && !rxfhindir_key && |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 4166 | !req_hfunc_name && !rss_context) { |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 4167 | return do_srxfhindir(ctx, rxfhindir_default, rxfhindir_start, |
| 4168 | rxfhindir_equal, rxfhindir_weight, |
| 4169 | num_weights); |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4170 | } else if (err < 0) { |
| 4171 | perror("Cannot get RX flow hash indir size and key size"); |
| 4172 | return 1; |
| 4173 | } |
| 4174 | |
| 4175 | if (rxfhindir_key) { |
| 4176 | err = parse_hkey(&hkey, rss_head.key_size, |
| 4177 | rxfhindir_key); |
| 4178 | if (err) |
| 4179 | return err; |
| 4180 | } |
| 4181 | |
| 4182 | if (rxfhindir_equal || rxfhindir_weight) |
| 4183 | indir_bytes = rss_head.indir_size * entry_size; |
| 4184 | |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4185 | if (rss_head.hfunc && req_hfunc_name) { |
| 4186 | hfuncs = get_stringset(ctx, ETH_SS_RSS_HASH_FUNCS, 0, 1); |
| 4187 | if (!hfuncs) { |
| 4188 | perror("Cannot get hash functions names"); |
Ivan Vecera | e0fabbc | 2018-06-08 11:20:09 +0200 | [diff] [blame] | 4189 | err = 1; |
| 4190 | goto free; |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | for (i = 0; i < hfuncs->len && !req_hfunc ; i++) { |
| 4194 | hfunc_name = (char *)(hfuncs->data + |
| 4195 | i * ETH_GSTRING_LEN); |
| 4196 | if (!strncmp(hfunc_name, req_hfunc_name, |
| 4197 | ETH_GSTRING_LEN)) |
| 4198 | req_hfunc = (u32)1 << i; |
| 4199 | } |
| 4200 | |
| 4201 | if (!req_hfunc) { |
| 4202 | fprintf(stderr, |
| 4203 | "Unknown hash function: %s\n", req_hfunc_name); |
Ivan Vecera | e0fabbc | 2018-06-08 11:20:09 +0200 | [diff] [blame] | 4204 | err = 1; |
| 4205 | goto free; |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4206 | } |
| 4207 | } |
| 4208 | |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4209 | rss = calloc(1, sizeof(*rss) + indir_bytes + rss_head.key_size); |
| 4210 | if (!rss) { |
| 4211 | perror("Cannot allocate memory for RX flow hash config"); |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4212 | err = 1; |
| 4213 | goto free; |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4214 | } |
| 4215 | rss->cmd = ETHTOOL_SRSSH; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 4216 | rss->rss_context = rss_context; |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4217 | rss->hfunc = req_hfunc; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 4218 | if (delete) { |
| 4219 | rss->indir_size = rss->key_size = 0; |
| 4220 | } else { |
| 4221 | rss->indir_size = rss_head.indir_size; |
| 4222 | rss->key_size = rss_head.key_size; |
| 4223 | if (fill_indir_table(&rss->indir_size, rss->rss_config, |
Jonathan Lemon | 8c8bfaa | 2019-04-01 11:42:45 -0700 | [diff] [blame] | 4224 | rxfhindir_default, rxfhindir_start, |
| 4225 | rxfhindir_equal, rxfhindir_weight, |
| 4226 | num_weights)) { |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 4227 | err = 1; |
| 4228 | goto free; |
| 4229 | } |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | if (hkey) |
| 4233 | memcpy((char *)rss->rss_config + indir_bytes, |
| 4234 | hkey, rss->key_size); |
| 4235 | else |
| 4236 | rss->key_size = 0; |
| 4237 | |
| 4238 | err = send_ioctl(ctx, rss); |
| 4239 | if (err < 0) { |
| 4240 | perror("Cannot set RX flow hash configuration"); |
| 4241 | err = 1; |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 4242 | } else if (rss_context == ETH_RXFH_CONTEXT_ALLOC) { |
| 4243 | printf("New RSS context is %d\n", rss->rss_context); |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | free: |
Ivan Vecera | e0fabbc | 2018-06-08 11:20:09 +0200 | [diff] [blame] | 4247 | free(hkey); |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4248 | free(rss); |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 4249 | free(hfuncs); |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 4250 | return err; |
| 4251 | } |
| 4252 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4253 | static int do_flash(struct cmd_context *ctx) |
Ajit Khaparde | 9efed0a | 2009-09-03 08:33:08 +0530 | [diff] [blame] | 4254 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 4255 | char *flash_file; |
| 4256 | int flash_region; |
Ajit Khaparde | 9efed0a | 2009-09-03 08:33:08 +0530 | [diff] [blame] | 4257 | struct ethtool_flash efl; |
| 4258 | int err; |
| 4259 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 4260 | if (ctx->argc < 1 || ctx->argc > 2) |
Ben Hutchings | 97a8e6a | 2011-02-21 18:47:58 +0000 | [diff] [blame] | 4261 | exit_bad_args(); |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 4262 | flash_file = ctx->argp[0]; |
| 4263 | if (ctx->argc == 2) { |
| 4264 | flash_region = strtol(ctx->argp[1], NULL, 0); |
| 4265 | if (flash_region < 0) |
| 4266 | exit_bad_args(); |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 4267 | } else { |
| 4268 | flash_region = -1; |
Ajit Khaparde | 9efed0a | 2009-09-03 08:33:08 +0530 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | if (strlen(flash_file) > ETHTOOL_FLASH_MAX_FILENAME - 1) { |
| 4272 | fprintf(stdout, "Filename too long\n"); |
| 4273 | return 99; |
| 4274 | } |
| 4275 | |
| 4276 | efl.cmd = ETHTOOL_FLASHDEV; |
| 4277 | strcpy(efl.data, flash_file); |
| 4278 | |
| 4279 | if (flash_region < 0) |
| 4280 | efl.region = ETHTOOL_FLASH_ALL_REGIONS; |
| 4281 | else |
| 4282 | efl.region = flash_region; |
| 4283 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4284 | err = send_ioctl(ctx, &efl); |
Ajit Khaparde | 9efed0a | 2009-09-03 08:33:08 +0530 | [diff] [blame] | 4285 | if (err < 0) |
| 4286 | perror("Flashing failed"); |
| 4287 | |
| 4288 | return err; |
| 4289 | } |
| 4290 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4291 | static int do_permaddr(struct cmd_context *ctx) |
Stephen Hemminger | fef1c4a | 2010-11-16 19:14:33 +0000 | [diff] [blame] | 4292 | { |
| 4293 | int i, err; |
| 4294 | struct ethtool_perm_addr *epaddr; |
| 4295 | |
| 4296 | epaddr = malloc(sizeof(struct ethtool_perm_addr) + MAX_ADDR_LEN); |
John W. Linville | d70e1eb | 2016-09-29 14:05:41 -0400 | [diff] [blame] | 4297 | if (!epaddr) { |
| 4298 | perror("Cannot allocate memory for operation"); |
| 4299 | return 1; |
| 4300 | } |
| 4301 | |
Stephen Hemminger | fef1c4a | 2010-11-16 19:14:33 +0000 | [diff] [blame] | 4302 | epaddr->cmd = ETHTOOL_GPERMADDR; |
| 4303 | epaddr->size = MAX_ADDR_LEN; |
Stephen Hemminger | fef1c4a | 2010-11-16 19:14:33 +0000 | [diff] [blame] | 4304 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4305 | err = send_ioctl(ctx, epaddr); |
Stephen Hemminger | fef1c4a | 2010-11-16 19:14:33 +0000 | [diff] [blame] | 4306 | if (err < 0) |
| 4307 | perror("Cannot read permanent address"); |
| 4308 | else { |
| 4309 | printf("Permanent address:"); |
| 4310 | for (i = 0; i < epaddr->size; i++) |
| 4311 | printf("%c%02x", (i == 0) ? ' ' : ':', |
| 4312 | epaddr->data[i]); |
| 4313 | printf("\n"); |
| 4314 | } |
| 4315 | free(epaddr); |
| 4316 | |
| 4317 | return err; |
| 4318 | } |
| 4319 | |
Edward Cree | b56b951 | 2016-03-17 19:17:16 +0000 | [diff] [blame] | 4320 | static bool flow_type_is_ntuple_supported(__u32 flow_type) |
| 4321 | { |
| 4322 | switch (flow_type) { |
| 4323 | case TCP_V4_FLOW: |
| 4324 | case UDP_V4_FLOW: |
| 4325 | case SCTP_V4_FLOW: |
| 4326 | case AH_V4_FLOW: |
| 4327 | case ESP_V4_FLOW: |
| 4328 | case IPV4_USER_FLOW: |
| 4329 | case ETHER_FLOW: |
| 4330 | return true; |
| 4331 | default: |
| 4332 | return false; |
| 4333 | } |
| 4334 | } |
| 4335 | |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4336 | static int flow_spec_to_ntuple(struct ethtool_rx_flow_spec *fsp, |
| 4337 | struct ethtool_rx_ntuple_flow_spec *ntuple) |
| 4338 | { |
| 4339 | size_t i; |
| 4340 | |
| 4341 | /* verify location is not specified */ |
Ben Hutchings | 578e6a5 | 2012-01-03 20:21:45 +0000 | [diff] [blame] | 4342 | if (fsp->location != RX_CLS_LOC_ANY) |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4343 | return -1; |
| 4344 | |
Yan Burman | b29aa90 | 2012-12-11 14:03:56 +0200 | [diff] [blame] | 4345 | /* destination MAC address in L3/L4 rules is not supported by ntuple */ |
| 4346 | if (fsp->flow_type & FLOW_MAC_EXT) |
| 4347 | return -1; |
| 4348 | |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4349 | /* verify ring cookie can transfer to action */ |
| 4350 | if (fsp->ring_cookie > INT_MAX && fsp->ring_cookie < (u64)(-2)) |
| 4351 | return -1; |
| 4352 | |
| 4353 | /* verify only one field is setting data field */ |
| 4354 | if ((fsp->flow_type & FLOW_EXT) && |
| 4355 | (fsp->m_ext.data[0] || fsp->m_ext.data[1]) && |
| 4356 | fsp->m_ext.vlan_etype) |
| 4357 | return -1; |
| 4358 | |
Edward Cree | b56b951 | 2016-03-17 19:17:16 +0000 | [diff] [blame] | 4359 | /* IPv6 flow types are not supported by ntuple */ |
| 4360 | if (!flow_type_is_ntuple_supported(fsp->flow_type & ~FLOW_EXT)) |
| 4361 | return -1; |
| 4362 | |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4363 | /* Set entire ntuple to ~0 to guarantee all masks are set */ |
| 4364 | memset(ntuple, ~0, sizeof(*ntuple)); |
| 4365 | |
| 4366 | /* set non-filter values */ |
| 4367 | ntuple->flow_type = fsp->flow_type; |
| 4368 | ntuple->action = fsp->ring_cookie; |
| 4369 | |
| 4370 | /* |
| 4371 | * Copy over header union, they are identical in layout however |
| 4372 | * the ntuple union contains additional padding on the end |
| 4373 | */ |
| 4374 | memcpy(&ntuple->h_u, &fsp->h_u, sizeof(fsp->h_u)); |
| 4375 | |
| 4376 | /* |
| 4377 | * The same rule mentioned above applies to the mask union. However, |
| 4378 | * in addition we need to invert the mask bits to match the ntuple |
| 4379 | * mask which is 1 for masked, versus 0 for masked as seen in nfc. |
| 4380 | */ |
| 4381 | memcpy(&ntuple->m_u, &fsp->m_u, sizeof(fsp->m_u)); |
| 4382 | for (i = 0; i < sizeof(fsp->m_u); i++) |
| 4383 | ntuple->m_u.hdata[i] ^= 0xFF; |
| 4384 | |
| 4385 | /* copy extended fields */ |
| 4386 | if (fsp->flow_type & FLOW_EXT) { |
| 4387 | ntuple->vlan_tag = |
| 4388 | ntohs(fsp->h_ext.vlan_tci); |
| 4389 | ntuple->vlan_tag_mask = |
| 4390 | ~ntohs(fsp->m_ext.vlan_tci); |
| 4391 | if (fsp->m_ext.vlan_etype) { |
| 4392 | /* |
| 4393 | * vlan_etype and user data are mutually exclusive |
| 4394 | * in ntuple configuration as they occupy the same |
| 4395 | * space. |
| 4396 | */ |
| 4397 | if (fsp->m_ext.data[0] || fsp->m_ext.data[1]) |
| 4398 | return -1; |
| 4399 | ntuple->data = |
| 4400 | ntohl(fsp->h_ext.vlan_etype); |
| 4401 | ntuple->data_mask = |
| 4402 | ~(u64)ntohl(fsp->m_ext.vlan_etype); |
| 4403 | } else { |
| 4404 | ntuple->data = |
| 4405 | (u64)ntohl(fsp->h_ext.data[0]) << 32; |
| 4406 | ntuple->data |= |
| 4407 | (u64)ntohl(fsp->h_ext.data[1]); |
| 4408 | ntuple->data_mask = |
| 4409 | (u64)ntohl(~fsp->m_ext.data[0]) << 32; |
| 4410 | ntuple->data_mask |= |
| 4411 | (u64)ntohl(~fsp->m_ext.data[1]); |
| 4412 | } |
| 4413 | } |
| 4414 | |
Sebastian Pöhn | aa41a26 | 2011-05-23 15:53:55 +0200 | [diff] [blame] | 4415 | /* Mask out the extended bit, because ntuple does not know it! */ |
| 4416 | ntuple->flow_type &= ~FLOW_EXT; |
| 4417 | |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4418 | return 0; |
| 4419 | } |
| 4420 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 4421 | static int do_srxntuple(struct cmd_context *ctx, |
| 4422 | struct ethtool_rx_flow_spec *rx_rule_fs) |
Peter Waskiewicz | b26637b | 2010-02-03 23:51:01 -0800 | [diff] [blame] | 4423 | { |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4424 | struct ethtool_rx_ntuple ntuplecmd; |
| 4425 | struct ethtool_value eval; |
| 4426 | int err; |
| 4427 | |
| 4428 | /* attempt to convert the flow classifier to an ntuple classifier */ |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 4429 | err = flow_spec_to_ntuple(rx_rule_fs, &ntuplecmd.fs); |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4430 | if (err) |
| 4431 | return -1; |
| 4432 | |
| 4433 | /* |
| 4434 | * Check to see if the flag is set for N-tuple, this allows |
| 4435 | * us to avoid the possible EINVAL response for the N-tuple |
| 4436 | * flag not being set on the device |
| 4437 | */ |
| 4438 | eval.cmd = ETHTOOL_GFLAGS; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4439 | err = send_ioctl(ctx, &eval); |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4440 | if (err || !(eval.data & ETH_FLAG_NTUPLE)) |
| 4441 | return -1; |
| 4442 | |
| 4443 | /* send rule via N-tuple */ |
| 4444 | ntuplecmd.cmd = ETHTOOL_SRXNTUPLE; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4445 | err = send_ioctl(ctx, &ntuplecmd); |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4446 | |
| 4447 | /* |
Ville Skyttä | 500a9f4 | 2013-12-15 14:19:31 +0200 | [diff] [blame] | 4448 | * Display error only if response is something other than op not |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4449 | * supported. It is possible that the interface uses the network |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 4450 | * flow classifier interface instead of N-tuple. |
| 4451 | */ |
Ben Hutchings | a0e0cc4 | 2011-05-13 01:52:27 +0100 | [diff] [blame] | 4452 | if (err < 0) { |
| 4453 | if (errno != EOPNOTSUPP) |
| 4454 | perror("Cannot add new rule via N-tuple"); |
| 4455 | return -1; |
| 4456 | } |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4457 | |
Ben Hutchings | a0e0cc4 | 2011-05-13 01:52:27 +0100 | [diff] [blame] | 4458 | return 0; |
Alexander Duyck | 8d63f72 | 2011-05-04 11:41:51 -0700 | [diff] [blame] | 4459 | } |
| 4460 | |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 4461 | static int do_writefwdump(struct ethtool_dump *dump, const char *dump_file) |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4462 | { |
| 4463 | int err = 0; |
| 4464 | FILE *f; |
| 4465 | size_t bytes; |
| 4466 | |
| 4467 | f = fopen(dump_file, "wb+"); |
| 4468 | |
| 4469 | if (!f) { |
| 4470 | fprintf(stderr, "Can't open file %s: %s\n", |
| 4471 | dump_file, strerror(errno)); |
| 4472 | return 1; |
| 4473 | } |
| 4474 | bytes = fwrite(dump->data, 1, dump->len, f); |
| 4475 | if (bytes != dump->len) { |
| 4476 | fprintf(stderr, "Can not write all of dump data\n"); |
| 4477 | err = 1; |
| 4478 | } |
| 4479 | if (fclose(f)) { |
| 4480 | fprintf(stderr, "Can't close file %s: %s\n", |
| 4481 | dump_file, strerror(errno)); |
| 4482 | err = 1; |
| 4483 | } |
| 4484 | return err; |
| 4485 | } |
| 4486 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4487 | static int do_getfwdump(struct cmd_context *ctx) |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4488 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 4489 | u32 dump_flag; |
| 4490 | char *dump_file; |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4491 | int err; |
| 4492 | struct ethtool_dump edata; |
| 4493 | struct ethtool_dump *data; |
| 4494 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 4495 | if (ctx->argc == 2 && !strcmp(ctx->argp[0], "data")) { |
| 4496 | dump_flag = ETHTOOL_GET_DUMP_DATA; |
| 4497 | dump_file = ctx->argp[1]; |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 4498 | } else if (ctx->argc == 0) { |
| 4499 | dump_flag = 0; |
| 4500 | dump_file = NULL; |
| 4501 | } else { |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 4502 | exit_bad_args(); |
| 4503 | } |
| 4504 | |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4505 | edata.cmd = ETHTOOL_GET_DUMP_FLAG; |
| 4506 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4507 | err = send_ioctl(ctx, &edata); |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4508 | if (err < 0) { |
| 4509 | perror("Can not get dump level\n"); |
| 4510 | return 1; |
| 4511 | } |
| 4512 | if (dump_flag != ETHTOOL_GET_DUMP_DATA) { |
| 4513 | fprintf(stdout, "flag: %u, version: %u, length: %u\n", |
| 4514 | edata.flag, edata.version, edata.len); |
| 4515 | return 0; |
| 4516 | } |
| 4517 | data = calloc(1, offsetof(struct ethtool_dump, data) + edata.len); |
| 4518 | if (!data) { |
| 4519 | perror("Can not allocate enough memory\n"); |
| 4520 | return 1; |
| 4521 | } |
| 4522 | data->cmd = ETHTOOL_GET_DUMP_DATA; |
| 4523 | data->len = edata.len; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4524 | err = send_ioctl(ctx, data); |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4525 | if (err < 0) { |
| 4526 | perror("Can not get dump data\n"); |
| 4527 | err = 1; |
| 4528 | goto free; |
| 4529 | } |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 4530 | err = do_writefwdump(data, dump_file); |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4531 | free: |
| 4532 | free(data); |
| 4533 | return err; |
| 4534 | } |
| 4535 | |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4536 | static int do_setfwdump(struct cmd_context *ctx) |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4537 | { |
Ben Hutchings | 52adc49 | 2011-10-31 22:28:20 +0000 | [diff] [blame] | 4538 | u32 dump_flag; |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4539 | int err; |
| 4540 | struct ethtool_dump dump; |
| 4541 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 4542 | if (ctx->argc != 1) |
| 4543 | exit_bad_args(); |
| 4544 | dump_flag = get_u32(ctx->argp[0], 0); |
| 4545 | |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4546 | dump.cmd = ETHTOOL_SET_DUMP; |
| 4547 | dump.flag = dump_flag; |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 4548 | err = send_ioctl(ctx, &dump); |
Anirban Chakraborty | 95b924e | 2011-06-02 12:00:26 -0700 | [diff] [blame] | 4549 | if (err < 0) { |
| 4550 | perror("Can not set dump level\n"); |
| 4551 | return 1; |
| 4552 | } |
| 4553 | return 0; |
| 4554 | } |
| 4555 | |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4556 | static int do_gprivflags(struct cmd_context *ctx) |
| 4557 | { |
| 4558 | struct ethtool_gstrings *strings; |
| 4559 | struct ethtool_value flags; |
| 4560 | unsigned int i; |
John W. Linville | 69fd6d4 | 2016-09-29 14:30:31 -0400 | [diff] [blame] | 4561 | int max_len = 0, cur_len, rc; |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4562 | |
| 4563 | if (ctx->argc != 0) |
| 4564 | exit_bad_args(); |
| 4565 | |
| 4566 | strings = get_stringset(ctx, ETH_SS_PRIV_FLAGS, |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 4567 | offsetof(struct ethtool_drvinfo, n_priv_flags), |
| 4568 | 1); |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4569 | if (!strings) { |
| 4570 | perror("Cannot get private flag names"); |
| 4571 | return 1; |
| 4572 | } |
| 4573 | if (strings->len == 0) { |
| 4574 | fprintf(stderr, "No private flags defined\n"); |
John W. Linville | 69fd6d4 | 2016-09-29 14:30:31 -0400 | [diff] [blame] | 4575 | rc = 1; |
| 4576 | goto err; |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4577 | } |
| 4578 | if (strings->len > 32) { |
| 4579 | /* ETHTOOL_GPFLAGS can only cover 32 flags */ |
| 4580 | fprintf(stderr, "Only showing first 32 private flags\n"); |
| 4581 | strings->len = 32; |
| 4582 | } |
| 4583 | |
| 4584 | flags.cmd = ETHTOOL_GPFLAGS; |
| 4585 | if (send_ioctl(ctx, &flags)) { |
| 4586 | perror("Cannot get private flags"); |
John W. Linville | 69fd6d4 | 2016-09-29 14:30:31 -0400 | [diff] [blame] | 4587 | rc = 1; |
| 4588 | goto err; |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4589 | } |
| 4590 | |
Yuval Mintz | 49ef792 | 2013-05-26 07:55:55 +0300 | [diff] [blame] | 4591 | /* Find longest string and align all strings accordingly */ |
| 4592 | for (i = 0; i < strings->len; i++) { |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 4593 | cur_len = strlen((const char *)strings->data + |
Yuval Mintz | 49ef792 | 2013-05-26 07:55:55 +0300 | [diff] [blame] | 4594 | i * ETH_GSTRING_LEN); |
| 4595 | if (cur_len > max_len) |
| 4596 | max_len = cur_len; |
| 4597 | } |
| 4598 | |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4599 | printf("Private flags for %s:\n", ctx->devname); |
| 4600 | for (i = 0; i < strings->len; i++) |
Yuval Mintz | 49ef792 | 2013-05-26 07:55:55 +0300 | [diff] [blame] | 4601 | printf("%-*s: %s\n", |
| 4602 | max_len, |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4603 | (const char *)strings->data + i * ETH_GSTRING_LEN, |
| 4604 | (flags.data & (1U << i)) ? "on" : "off"); |
| 4605 | |
John W. Linville | 69fd6d4 | 2016-09-29 14:30:31 -0400 | [diff] [blame] | 4606 | rc = 0; |
| 4607 | |
| 4608 | err: |
| 4609 | free(strings); |
| 4610 | return rc; |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | static int do_sprivflags(struct cmd_context *ctx) |
| 4614 | { |
| 4615 | struct ethtool_gstrings *strings; |
| 4616 | struct cmdline_info *cmdline; |
| 4617 | struct ethtool_value flags; |
| 4618 | u32 wanted_flags = 0, seen_flags = 0; |
John W. Linville | ecbd5ea | 2016-09-30 14:57:27 -0400 | [diff] [blame] | 4619 | int any_changed, rc; |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4620 | unsigned int i; |
| 4621 | |
| 4622 | strings = get_stringset(ctx, ETH_SS_PRIV_FLAGS, |
Ben Hutchings | a983fb7 | 2012-06-14 20:34:35 +0100 | [diff] [blame] | 4623 | offsetof(struct ethtool_drvinfo, n_priv_flags), |
| 4624 | 1); |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4625 | if (!strings) { |
| 4626 | perror("Cannot get private flag names"); |
| 4627 | return 1; |
| 4628 | } |
| 4629 | if (strings->len == 0) { |
| 4630 | fprintf(stderr, "No private flags defined\n"); |
John W. Linville | ecbd5ea | 2016-09-30 14:57:27 -0400 | [diff] [blame] | 4631 | rc = 1; |
| 4632 | goto err; |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4633 | } |
| 4634 | if (strings->len > 32) { |
| 4635 | /* ETHTOOL_{G,S}PFLAGS can only cover 32 flags */ |
| 4636 | fprintf(stderr, "Only setting first 32 private flags\n"); |
| 4637 | strings->len = 32; |
| 4638 | } |
| 4639 | |
| 4640 | cmdline = calloc(strings->len, sizeof(*cmdline)); |
| 4641 | if (!cmdline) { |
| 4642 | perror("Cannot parse arguments"); |
John W. Linville | ecbd5ea | 2016-09-30 14:57:27 -0400 | [diff] [blame] | 4643 | rc = 1; |
| 4644 | goto err; |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4645 | } |
| 4646 | for (i = 0; i < strings->len; i++) { |
| 4647 | cmdline[i].name = ((const char *)strings->data + |
| 4648 | i * ETH_GSTRING_LEN); |
| 4649 | cmdline[i].type = CMDL_FLAG; |
| 4650 | cmdline[i].wanted_val = &wanted_flags; |
| 4651 | cmdline[i].flag_val = 1U << i; |
| 4652 | cmdline[i].seen_val = &seen_flags; |
| 4653 | } |
| 4654 | parse_generic_cmdline(ctx, &any_changed, cmdline, strings->len); |
Yuval Mintz | c9fb993 | 2013-06-12 14:59:58 +0300 | [diff] [blame] | 4655 | free(cmdline); |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4656 | |
| 4657 | flags.cmd = ETHTOOL_GPFLAGS; |
| 4658 | if (send_ioctl(ctx, &flags)) { |
| 4659 | perror("Cannot get private flags"); |
John W. Linville | ecbd5ea | 2016-09-30 14:57:27 -0400 | [diff] [blame] | 4660 | rc = 1; |
| 4661 | goto err; |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | flags.cmd = ETHTOOL_SPFLAGS; |
| 4665 | flags.data = (flags.data & ~seen_flags) | wanted_flags; |
| 4666 | if (send_ioctl(ctx, &flags)) { |
| 4667 | perror("Cannot set private flags"); |
John W. Linville | ecbd5ea | 2016-09-30 14:57:27 -0400 | [diff] [blame] | 4668 | rc = 1; |
| 4669 | goto err; |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4670 | } |
| 4671 | |
John W. Linville | ecbd5ea | 2016-09-30 14:57:27 -0400 | [diff] [blame] | 4672 | rc = 0; |
| 4673 | err: |
| 4674 | free(strings); |
| 4675 | return rc; |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 4676 | } |
| 4677 | |
Richard Cochran | 0fdcc8c | 2012-04-03 19:58:23 +0200 | [diff] [blame] | 4678 | static int do_tsinfo(struct cmd_context *ctx) |
| 4679 | { |
| 4680 | struct ethtool_ts_info info; |
| 4681 | |
| 4682 | if (ctx->argc != 0) |
| 4683 | exit_bad_args(); |
| 4684 | |
| 4685 | fprintf(stdout, "Time stamping parameters for %s:\n", ctx->devname); |
| 4686 | info.cmd = ETHTOOL_GET_TS_INFO; |
| 4687 | if (send_ioctl(ctx, &info)) { |
| 4688 | perror("Cannot get device time stamping settings"); |
| 4689 | return -1; |
| 4690 | } |
| 4691 | dump_tsinfo(&info); |
| 4692 | return 0; |
| 4693 | } |
| 4694 | |
Stuart Hodgson | 2edf567 | 2012-05-18 15:58:45 +0100 | [diff] [blame] | 4695 | static int do_getmodule(struct cmd_context *ctx) |
| 4696 | { |
| 4697 | struct ethtool_modinfo modinfo; |
| 4698 | struct ethtool_eeprom *eeprom; |
| 4699 | u32 geeprom_offset = 0; |
| 4700 | u32 geeprom_length = -1; |
| 4701 | int geeprom_changed = 0; |
| 4702 | int geeprom_dump_raw = 0; |
| 4703 | int geeprom_dump_hex = 0; |
| 4704 | int err; |
| 4705 | |
| 4706 | struct cmdline_info cmdline_geeprom[] = { |
| 4707 | { "offset", CMDL_U32, &geeprom_offset, NULL }, |
| 4708 | { "length", CMDL_U32, &geeprom_length, NULL }, |
| 4709 | { "raw", CMDL_BOOL, &geeprom_dump_raw, NULL }, |
| 4710 | { "hex", CMDL_BOOL, &geeprom_dump_hex, NULL }, |
| 4711 | }; |
| 4712 | |
| 4713 | parse_generic_cmdline(ctx, &geeprom_changed, |
| 4714 | cmdline_geeprom, ARRAY_SIZE(cmdline_geeprom)); |
| 4715 | |
| 4716 | if (geeprom_dump_raw && geeprom_dump_hex) { |
| 4717 | printf("Hex and raw dump cannot be specified together\n"); |
| 4718 | return 1; |
| 4719 | } |
| 4720 | |
| 4721 | modinfo.cmd = ETHTOOL_GMODULEINFO; |
| 4722 | err = send_ioctl(ctx, &modinfo); |
| 4723 | if (err < 0) { |
| 4724 | perror("Cannot get module EEPROM information"); |
| 4725 | return 1; |
| 4726 | } |
| 4727 | |
| 4728 | if (geeprom_length == -1) |
| 4729 | geeprom_length = modinfo.eeprom_len; |
| 4730 | |
| 4731 | if (modinfo.eeprom_len < geeprom_offset + geeprom_length) |
| 4732 | geeprom_length = modinfo.eeprom_len - geeprom_offset; |
| 4733 | |
| 4734 | eeprom = calloc(1, sizeof(*eeprom)+geeprom_length); |
| 4735 | if (!eeprom) { |
| 4736 | perror("Cannot allocate memory for Module EEPROM data"); |
| 4737 | return 1; |
| 4738 | } |
| 4739 | |
| 4740 | eeprom->cmd = ETHTOOL_GMODULEEEPROM; |
| 4741 | eeprom->len = geeprom_length; |
| 4742 | eeprom->offset = geeprom_offset; |
| 4743 | err = send_ioctl(ctx, eeprom); |
| 4744 | if (err < 0) { |
| 4745 | perror("Cannot get Module EEPROM data"); |
| 4746 | free(eeprom); |
| 4747 | return 1; |
| 4748 | } |
| 4749 | |
Aurelien Guillaume | 749f387 | 2012-12-02 21:21:01 +0100 | [diff] [blame] | 4750 | /* |
| 4751 | * SFF-8079 EEPROM layout contains the memory available at A0 address on |
| 4752 | * the PHY EEPROM. |
| 4753 | * SFF-8472 defines a virtual extension of the EEPROM, where the |
| 4754 | * microcontroller on the SFP/SFP+ generates a page at the A2 address, |
| 4755 | * which contains data relative to optical diagnostics. |
| 4756 | * The current kernel implementation returns a blob, which contains: |
| 4757 | * - ETH_MODULE_SFF_8079 => The A0 page only. |
| 4758 | * - ETH_MODULE_SFF_8472 => The A0 and A2 page concatenated. |
| 4759 | */ |
Stuart Hodgson | 2edf567 | 2012-05-18 15:58:45 +0100 | [diff] [blame] | 4760 | if (geeprom_dump_raw) { |
| 4761 | fwrite(eeprom->data, 1, eeprom->len, stdout); |
| 4762 | } else { |
| 4763 | if (eeprom->offset != 0 || |
| 4764 | (eeprom->len != modinfo.eeprom_len)) { |
| 4765 | geeprom_dump_hex = 1; |
| 4766 | } else if (!geeprom_dump_hex) { |
| 4767 | switch (modinfo.type) { |
Florian Fainelli | 875616d | 2014-02-27 15:43:01 -0800 | [diff] [blame] | 4768 | #ifdef ETHTOOL_ENABLE_PRETTY_DUMP |
Stuart Hodgson | 2edf567 | 2012-05-18 15:58:45 +0100 | [diff] [blame] | 4769 | case ETH_MODULE_SFF_8079: |
Aurelien Guillaume | 749f387 | 2012-12-02 21:21:01 +0100 | [diff] [blame] | 4770 | sff8079_show_all(eeprom->data); |
| 4771 | break; |
Stuart Hodgson | 2edf567 | 2012-05-18 15:58:45 +0100 | [diff] [blame] | 4772 | case ETH_MODULE_SFF_8472: |
| 4773 | sff8079_show_all(eeprom->data); |
Aurelien Guillaume | 749f387 | 2012-12-02 21:21:01 +0100 | [diff] [blame] | 4774 | sff8472_show_all(eeprom->data); |
Stuart Hodgson | 2edf567 | 2012-05-18 15:58:45 +0100 | [diff] [blame] | 4775 | break; |
Vidya Sagar Ravipati | a5e73bb | 2016-08-23 06:30:32 -0700 | [diff] [blame] | 4776 | case ETH_MODULE_SFF_8436: |
| 4777 | case ETH_MODULE_SFF_8636: |
| 4778 | sff8636_show_all(eeprom->data, |
| 4779 | modinfo.eeprom_len); |
| 4780 | break; |
Florian Fainelli | 875616d | 2014-02-27 15:43:01 -0800 | [diff] [blame] | 4781 | #endif |
Stuart Hodgson | 2edf567 | 2012-05-18 15:58:45 +0100 | [diff] [blame] | 4782 | default: |
| 4783 | geeprom_dump_hex = 1; |
| 4784 | break; |
| 4785 | } |
| 4786 | } |
| 4787 | if (geeprom_dump_hex) |
Ben Hutchings | 2038e9e | 2012-02-17 21:30:06 +0000 | [diff] [blame] | 4788 | dump_hex(stdout, eeprom->data, |
| 4789 | eeprom->len, eeprom->offset); |
Stuart Hodgson | 2edf567 | 2012-05-18 15:58:45 +0100 | [diff] [blame] | 4790 | } |
| 4791 | |
| 4792 | free(eeprom); |
| 4793 | |
| 4794 | return 0; |
| 4795 | } |
| 4796 | |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 4797 | static int do_geee(struct cmd_context *ctx) |
| 4798 | { |
| 4799 | struct ethtool_eee eeecmd; |
| 4800 | |
| 4801 | if (ctx->argc != 0) |
| 4802 | exit_bad_args(); |
| 4803 | |
| 4804 | eeecmd.cmd = ETHTOOL_GEEE; |
| 4805 | if (send_ioctl(ctx, &eeecmd)) { |
| 4806 | perror("Cannot get EEE settings"); |
| 4807 | return 1; |
| 4808 | } |
| 4809 | |
| 4810 | fprintf(stdout, "EEE Settings for %s:\n", ctx->devname); |
| 4811 | dump_eeecmd(&eeecmd); |
| 4812 | |
| 4813 | return 0; |
| 4814 | } |
| 4815 | |
| 4816 | static int do_seee(struct cmd_context *ctx) |
| 4817 | { |
| 4818 | int adv_c = -1, lpi_c = -1, lpi_time_c = -1, eee_c = -1; |
Bruce Allan | 70a58ff | 2012-09-18 20:20:19 -0700 | [diff] [blame] | 4819 | int change = -1, change2 = 0; |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 4820 | struct ethtool_eee eeecmd; |
| 4821 | struct cmdline_info cmdline_eee[] = { |
| 4822 | { "advertise", CMDL_U32, &adv_c, &eeecmd.advertised }, |
| 4823 | { "tx-lpi", CMDL_BOOL, &lpi_c, &eeecmd.tx_lpi_enabled }, |
| 4824 | { "tx-timer", CMDL_U32, &lpi_time_c, &eeecmd.tx_lpi_timer}, |
| 4825 | { "eee", CMDL_BOOL, &eee_c, &eeecmd.eee_enabled}, |
| 4826 | }; |
| 4827 | |
| 4828 | if (ctx->argc == 0) |
| 4829 | exit_bad_args(); |
| 4830 | |
| 4831 | parse_generic_cmdline(ctx, &change, cmdline_eee, |
| 4832 | ARRAY_SIZE(cmdline_eee)); |
| 4833 | |
| 4834 | eeecmd.cmd = ETHTOOL_GEEE; |
| 4835 | if (send_ioctl(ctx, &eeecmd)) { |
| 4836 | perror("Cannot get EEE settings"); |
| 4837 | return 1; |
| 4838 | } |
| 4839 | |
| 4840 | do_generic_set(cmdline_eee, ARRAY_SIZE(cmdline_eee), &change2); |
| 4841 | |
| 4842 | if (change2) { |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 4843 | eeecmd.cmd = ETHTOOL_SEEE; |
| 4844 | if (send_ioctl(ctx, &eeecmd)) { |
| 4845 | perror("Cannot set EEE settings"); |
| 4846 | return 1; |
| 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | return 0; |
| 4851 | } |
| 4852 | |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 4853 | static int do_get_phy_tunable(struct cmd_context *ctx) |
| 4854 | { |
| 4855 | int argc = ctx->argc; |
| 4856 | char **argp = ctx->argp; |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 4857 | |
| 4858 | if (argc < 1) |
| 4859 | exit_bad_args(); |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 4860 | |
Heiner Kallweit | 34a6dce | 2019-03-29 20:15:16 +0100 | [diff] [blame] | 4861 | if (!strcmp(argp[0], "downshift")) { |
Michal Kubecek | ef49e58 | 2018-05-09 14:01:46 +0200 | [diff] [blame] | 4862 | struct { |
| 4863 | struct ethtool_tunable ds; |
Heiner Kallweit | 34a6dce | 2019-03-29 20:15:16 +0100 | [diff] [blame] | 4864 | u8 count; |
Michal Kubecek | ef49e58 | 2018-05-09 14:01:46 +0200 | [diff] [blame] | 4865 | } cont; |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 4866 | |
Michal Kubecek | ef49e58 | 2018-05-09 14:01:46 +0200 | [diff] [blame] | 4867 | cont.ds.cmd = ETHTOOL_PHY_GTUNABLE; |
| 4868 | cont.ds.id = ETHTOOL_PHY_DOWNSHIFT; |
| 4869 | cont.ds.type_id = ETHTOOL_TUNABLE_U8; |
| 4870 | cont.ds.len = 1; |
Ivan Vecera | 7530346 | 2018-06-08 11:20:05 +0200 | [diff] [blame] | 4871 | if (send_ioctl(ctx, &cont.ds) < 0) { |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 4872 | perror("Cannot Get PHY downshift count"); |
| 4873 | return 87; |
| 4874 | } |
Heiner Kallweit | 34a6dce | 2019-03-29 20:15:16 +0100 | [diff] [blame] | 4875 | if (cont.count) |
| 4876 | fprintf(stdout, "Downshift count: %d\n", cont.count); |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 4877 | else |
| 4878 | fprintf(stdout, "Downshift disabled\n"); |
Heiner Kallweit | 27c7bb1 | 2019-03-29 20:15:54 +0100 | [diff] [blame] | 4879 | } else if (!strcmp(argp[0], "fast-link-down")) { |
| 4880 | struct { |
| 4881 | struct ethtool_tunable fld; |
| 4882 | u8 msecs; |
| 4883 | } cont; |
| 4884 | |
| 4885 | cont.fld.cmd = ETHTOOL_PHY_GTUNABLE; |
| 4886 | cont.fld.id = ETHTOOL_PHY_FAST_LINK_DOWN; |
| 4887 | cont.fld.type_id = ETHTOOL_TUNABLE_U8; |
| 4888 | cont.fld.len = 1; |
| 4889 | if (send_ioctl(ctx, &cont.fld) < 0) { |
| 4890 | perror("Cannot Get PHY Fast Link Down value"); |
| 4891 | return 87; |
| 4892 | } |
| 4893 | |
| 4894 | if (cont.msecs == ETHTOOL_PHY_FAST_LINK_DOWN_ON) |
| 4895 | fprintf(stdout, "Fast Link Down enabled\n"); |
| 4896 | else if (cont.msecs == ETHTOOL_PHY_FAST_LINK_DOWN_OFF) |
| 4897 | fprintf(stdout, "Fast Link Down disabled\n"); |
| 4898 | else |
| 4899 | fprintf(stdout, "Fast Link Down enabled, %d msecs\n", |
| 4900 | cont.msecs); |
Alexandru Ardelean | e568431 | 2019-09-20 12:44:31 +0300 | [diff] [blame] | 4901 | } else if (!strcmp(argp[0], "energy-detect-power-down")) { |
| 4902 | struct { |
| 4903 | struct ethtool_tunable ds; |
| 4904 | u16 msecs; |
| 4905 | } cont; |
| 4906 | |
| 4907 | cont.ds.cmd = ETHTOOL_PHY_GTUNABLE; |
| 4908 | cont.ds.id = ETHTOOL_PHY_EDPD; |
| 4909 | cont.ds.type_id = ETHTOOL_TUNABLE_U16; |
| 4910 | cont.ds.len = 2; |
| 4911 | if (send_ioctl(ctx, &cont.ds) < 0) { |
| 4912 | perror("Cannot Get PHY Energy Detect Power Down value"); |
| 4913 | return 87; |
| 4914 | } |
| 4915 | |
| 4916 | if (cont.msecs == ETHTOOL_PHY_EDPD_DISABLE) |
| 4917 | fprintf(stdout, "Energy Detect Power Down: disabled\n"); |
| 4918 | else if (cont.msecs == ETHTOOL_PHY_EDPD_NO_TX) |
| 4919 | fprintf(stdout, |
| 4920 | "Energy Detect Power Down: enabled, TX disabled\n"); |
| 4921 | else |
| 4922 | fprintf(stdout, |
| 4923 | "Energy Detect Power Down: enabled, TX %u msecs\n", |
| 4924 | cont.msecs); |
Heiner Kallweit | 34a6dce | 2019-03-29 20:15:16 +0100 | [diff] [blame] | 4925 | } else { |
| 4926 | exit_bad_args(); |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 4927 | } |
| 4928 | |
Ivan Vecera | 7530346 | 2018-06-08 11:20:05 +0200 | [diff] [blame] | 4929 | return 0; |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 4930 | } |
| 4931 | |
Scott Branden | 1d3761c | 2017-12-12 12:20:03 -0800 | [diff] [blame] | 4932 | static __u32 parse_reset(char *val, __u32 bitset, char *arg, __u32 *data) |
| 4933 | { |
| 4934 | __u32 bitval = 0; |
| 4935 | int i; |
| 4936 | |
| 4937 | /* Check for component match */ |
| 4938 | for (i = 0; val[i] != '\0'; i++) |
| 4939 | if (arg[i] != val[i]) |
| 4940 | return 0; |
| 4941 | |
| 4942 | /* Check if component has -shared specified or not */ |
| 4943 | if (arg[i] == '\0') |
| 4944 | bitval = bitset; |
| 4945 | else if (!strcmp(arg+i, "-shared")) |
| 4946 | bitval = bitset << ETH_RESET_SHARED_SHIFT; |
| 4947 | |
| 4948 | if (bitval) { |
| 4949 | *data |= bitval; |
| 4950 | return 1; |
| 4951 | } |
| 4952 | return 0; |
| 4953 | } |
| 4954 | |
| 4955 | static int do_reset(struct cmd_context *ctx) |
| 4956 | { |
| 4957 | struct ethtool_value resetinfo; |
| 4958 | __u32 data; |
| 4959 | int argc = ctx->argc; |
| 4960 | char **argp = ctx->argp; |
| 4961 | int i; |
| 4962 | |
| 4963 | if (argc == 0) |
| 4964 | exit_bad_args(); |
| 4965 | |
| 4966 | data = 0; |
| 4967 | |
| 4968 | for (i = 0; i < argc; i++) { |
| 4969 | if (!strcmp(argp[i], "flags")) { |
| 4970 | __u32 flags; |
| 4971 | |
| 4972 | i++; |
| 4973 | if (i >= argc) |
| 4974 | exit_bad_args(); |
| 4975 | flags = strtoul(argp[i], NULL, 0); |
| 4976 | if (flags == 0) |
| 4977 | exit_bad_args(); |
| 4978 | else |
| 4979 | data |= flags; |
| 4980 | } else if (parse_reset("mgmt", ETH_RESET_MGMT, |
| 4981 | argp[i], &data)) { |
| 4982 | } else if (parse_reset("irq", ETH_RESET_IRQ, |
| 4983 | argp[i], &data)) { |
| 4984 | } else if (parse_reset("dma", ETH_RESET_DMA, |
| 4985 | argp[i], &data)) { |
| 4986 | } else if (parse_reset("filter", ETH_RESET_FILTER, |
| 4987 | argp[i], &data)) { |
| 4988 | } else if (parse_reset("offload", ETH_RESET_OFFLOAD, |
| 4989 | argp[i], &data)) { |
| 4990 | } else if (parse_reset("mac", ETH_RESET_MAC, |
| 4991 | argp[i], &data)) { |
| 4992 | } else if (parse_reset("phy", ETH_RESET_PHY, |
| 4993 | argp[i], &data)) { |
| 4994 | } else if (parse_reset("ram", ETH_RESET_RAM, |
| 4995 | argp[i], &data)) { |
| 4996 | } else if (parse_reset("ap", ETH_RESET_AP, |
| 4997 | argp[i], &data)) { |
| 4998 | } else if (!strcmp(argp[i], "dedicated")) { |
| 4999 | data |= ETH_RESET_DEDICATED; |
| 5000 | } else if (!strcmp(argp[i], "all")) { |
| 5001 | data |= ETH_RESET_ALL; |
| 5002 | } else { |
| 5003 | exit_bad_args(); |
| 5004 | } |
| 5005 | } |
| 5006 | |
| 5007 | resetinfo.cmd = ETHTOOL_RESET; |
| 5008 | resetinfo.data = data; |
| 5009 | fprintf(stdout, "ETHTOOL_RESET 0x%x\n", resetinfo.data); |
| 5010 | |
| 5011 | if (send_ioctl(ctx, &resetinfo)) { |
| 5012 | perror("Cannot issue ETHTOOL_RESET"); |
| 5013 | return 1; |
| 5014 | } |
| 5015 | |
| 5016 | fprintf(stdout, "Components reset: 0x%x\n", data & ~resetinfo.data); |
| 5017 | if (resetinfo.data) |
| 5018 | fprintf(stdout, "Components not reset: 0x%x\n", resetinfo.data); |
| 5019 | |
| 5020 | return 0; |
| 5021 | } |
| 5022 | |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5023 | static int parse_named_bool(struct cmd_context *ctx, const char *name, u8 *on) |
| 5024 | { |
| 5025 | if (ctx->argc < 2) |
| 5026 | return 0; |
| 5027 | |
| 5028 | if (strcmp(*ctx->argp, name)) |
| 5029 | return 0; |
| 5030 | |
| 5031 | if (!strcmp(*(ctx->argp + 1), "on")) { |
| 5032 | *on = 1; |
| 5033 | } else if (!strcmp(*(ctx->argp + 1), "off")) { |
| 5034 | *on = 0; |
| 5035 | } else { |
| 5036 | fprintf(stderr, "Invalid boolean\n"); |
| 5037 | exit_bad_args(); |
| 5038 | } |
| 5039 | |
| 5040 | ctx->argc -= 2; |
| 5041 | ctx->argp += 2; |
| 5042 | |
| 5043 | return 1; |
| 5044 | } |
| 5045 | |
Alexandru Ardelean | e568431 | 2019-09-20 12:44:31 +0300 | [diff] [blame] | 5046 | static int parse_named_uint(struct cmd_context *ctx, |
| 5047 | const char *name, |
| 5048 | unsigned long long *val, |
| 5049 | unsigned long long max) |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5050 | { |
| 5051 | if (ctx->argc < 2) |
| 5052 | return 0; |
| 5053 | |
| 5054 | if (strcmp(*ctx->argp, name)) |
| 5055 | return 0; |
| 5056 | |
Alexandru Ardelean | e568431 | 2019-09-20 12:44:31 +0300 | [diff] [blame] | 5057 | *val = get_uint_range(*(ctx->argp + 1), 0, max); |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5058 | |
| 5059 | ctx->argc -= 2; |
| 5060 | ctx->argp += 2; |
| 5061 | |
| 5062 | return 1; |
| 5063 | } |
| 5064 | |
Alexandru Ardelean | e568431 | 2019-09-20 12:44:31 +0300 | [diff] [blame] | 5065 | static int parse_named_u8(struct cmd_context *ctx, const char *name, u8 *val) |
| 5066 | { |
| 5067 | unsigned long long val1; |
| 5068 | int ret; |
| 5069 | |
| 5070 | ret = parse_named_uint(ctx, name, &val1, 0xff); |
| 5071 | if (ret) |
| 5072 | *val = val1; |
| 5073 | |
| 5074 | return ret; |
| 5075 | } |
| 5076 | |
| 5077 | static int parse_named_u16(struct cmd_context *ctx, const char *name, u16 *val) |
| 5078 | { |
| 5079 | unsigned long long val1; |
| 5080 | int ret; |
| 5081 | |
| 5082 | ret = parse_named_uint(ctx, name, &val1, 0xffff); |
| 5083 | if (ret) |
| 5084 | *val = val1; |
| 5085 | |
| 5086 | return ret; |
| 5087 | } |
| 5088 | |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5089 | static int do_set_phy_tunable(struct cmd_context *ctx) |
| 5090 | { |
| 5091 | int err = 0; |
| 5092 | u8 ds_cnt = DOWNSHIFT_DEV_DEFAULT_COUNT; |
| 5093 | u8 ds_changed = 0, ds_has_cnt = 0, ds_enable = 0; |
Heiner Kallweit | 27c7bb1 | 2019-03-29 20:15:54 +0100 | [diff] [blame] | 5094 | u8 fld_changed = 0, fld_enable = 0; |
| 5095 | u8 fld_msecs = ETHTOOL_PHY_FAST_LINK_DOWN_ON; |
Alexandru Ardelean | e568431 | 2019-09-20 12:44:31 +0300 | [diff] [blame] | 5096 | u8 edpd_changed = 0, edpd_enable = 0; |
| 5097 | u16 edpd_tx_interval = ETHTOOL_PHY_EDPD_DFLT_TX_MSECS; |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5098 | |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5099 | /* Parse arguments */ |
Heiner Kallweit | 34a6dce | 2019-03-29 20:15:16 +0100 | [diff] [blame] | 5100 | if (parse_named_bool(ctx, "downshift", &ds_enable)) { |
| 5101 | ds_changed = 1; |
| 5102 | ds_has_cnt = parse_named_u8(ctx, "count", &ds_cnt); |
Heiner Kallweit | 27c7bb1 | 2019-03-29 20:15:54 +0100 | [diff] [blame] | 5103 | } else if (parse_named_bool(ctx, "fast-link-down", &fld_enable)) { |
| 5104 | fld_changed = 1; |
| 5105 | if (fld_enable) |
| 5106 | parse_named_u8(ctx, "msecs", &fld_msecs); |
Alexandru Ardelean | e568431 | 2019-09-20 12:44:31 +0300 | [diff] [blame] | 5107 | } else if (parse_named_bool(ctx, "energy-detect-power-down", |
| 5108 | &edpd_enable)) { |
| 5109 | edpd_changed = 1; |
| 5110 | if (edpd_enable) |
| 5111 | parse_named_u16(ctx, "msecs", &edpd_tx_interval); |
Heiner Kallweit | 34a6dce | 2019-03-29 20:15:16 +0100 | [diff] [blame] | 5112 | } else { |
| 5113 | exit_bad_args(); |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5114 | } |
| 5115 | |
| 5116 | /* Validate parameters */ |
| 5117 | if (ds_changed) { |
| 5118 | if (!ds_enable && ds_has_cnt) { |
| 5119 | fprintf(stderr, "'count' may not be set when downshift " |
| 5120 | "is off.\n"); |
| 5121 | exit_bad_args(); |
| 5122 | } |
| 5123 | |
| 5124 | if (ds_enable && ds_has_cnt && ds_cnt == 0) { |
| 5125 | fprintf(stderr, "'count' may not be zero.\n"); |
| 5126 | exit_bad_args(); |
| 5127 | } |
| 5128 | |
| 5129 | if (!ds_enable) |
| 5130 | ds_cnt = DOWNSHIFT_DEV_DISABLE; |
Heiner Kallweit | 27c7bb1 | 2019-03-29 20:15:54 +0100 | [diff] [blame] | 5131 | } else if (fld_changed) { |
| 5132 | if (!fld_enable) |
| 5133 | fld_msecs = ETHTOOL_PHY_FAST_LINK_DOWN_OFF; |
| 5134 | else if (fld_msecs == ETHTOOL_PHY_FAST_LINK_DOWN_OFF) |
| 5135 | exit_bad_args(); |
Alexandru Ardelean | e568431 | 2019-09-20 12:44:31 +0300 | [diff] [blame] | 5136 | } else if (edpd_changed) { |
| 5137 | if (!edpd_enable) |
| 5138 | edpd_tx_interval = ETHTOOL_PHY_EDPD_DISABLE; |
| 5139 | else if (edpd_tx_interval == 0) |
| 5140 | edpd_tx_interval = ETHTOOL_PHY_EDPD_NO_TX; |
| 5141 | else if (edpd_tx_interval > ETHTOOL_PHY_EDPD_NO_TX) { |
| 5142 | fprintf(stderr, "'msecs' max value is %d.\n", |
| 5143 | (ETHTOOL_PHY_EDPD_NO_TX - 1)); |
| 5144 | exit_bad_args(); |
| 5145 | } |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | /* Do it */ |
| 5149 | if (ds_changed) { |
Michal Kubecek | ef49e58 | 2018-05-09 14:01:46 +0200 | [diff] [blame] | 5150 | struct { |
| 5151 | struct ethtool_tunable ds; |
Heiner Kallweit | 34a6dce | 2019-03-29 20:15:16 +0100 | [diff] [blame] | 5152 | u8 count; |
Michal Kubecek | ef49e58 | 2018-05-09 14:01:46 +0200 | [diff] [blame] | 5153 | } cont; |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5154 | |
Michal Kubecek | ef49e58 | 2018-05-09 14:01:46 +0200 | [diff] [blame] | 5155 | cont.ds.cmd = ETHTOOL_PHY_STUNABLE; |
| 5156 | cont.ds.id = ETHTOOL_PHY_DOWNSHIFT; |
| 5157 | cont.ds.type_id = ETHTOOL_TUNABLE_U8; |
| 5158 | cont.ds.len = 1; |
Heiner Kallweit | 34a6dce | 2019-03-29 20:15:16 +0100 | [diff] [blame] | 5159 | cont.count = ds_cnt; |
Michal Kubecek | ef49e58 | 2018-05-09 14:01:46 +0200 | [diff] [blame] | 5160 | err = send_ioctl(ctx, &cont.ds); |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5161 | if (err < 0) { |
| 5162 | perror("Cannot Set PHY downshift count"); |
| 5163 | err = 87; |
| 5164 | } |
Heiner Kallweit | 27c7bb1 | 2019-03-29 20:15:54 +0100 | [diff] [blame] | 5165 | } else if (fld_changed) { |
| 5166 | struct { |
| 5167 | struct ethtool_tunable fld; |
| 5168 | u8 msecs; |
| 5169 | } cont; |
| 5170 | |
| 5171 | cont.fld.cmd = ETHTOOL_PHY_STUNABLE; |
| 5172 | cont.fld.id = ETHTOOL_PHY_FAST_LINK_DOWN; |
| 5173 | cont.fld.type_id = ETHTOOL_TUNABLE_U8; |
| 5174 | cont.fld.len = 1; |
| 5175 | cont.msecs = fld_msecs; |
| 5176 | err = send_ioctl(ctx, &cont.fld); |
| 5177 | if (err < 0) { |
| 5178 | perror("Cannot Set PHY Fast Link Down value"); |
| 5179 | err = 87; |
| 5180 | } |
Alexandru Ardelean | e568431 | 2019-09-20 12:44:31 +0300 | [diff] [blame] | 5181 | } else if (edpd_changed) { |
| 5182 | struct { |
| 5183 | struct ethtool_tunable fld; |
| 5184 | u16 msecs; |
| 5185 | } cont; |
| 5186 | |
| 5187 | cont.fld.cmd = ETHTOOL_PHY_STUNABLE; |
| 5188 | cont.fld.id = ETHTOOL_PHY_EDPD; |
| 5189 | cont.fld.type_id = ETHTOOL_TUNABLE_U16; |
| 5190 | cont.fld.len = 2; |
| 5191 | cont.msecs = edpd_tx_interval; |
| 5192 | err = send_ioctl(ctx, &cont.fld); |
| 5193 | if (err < 0) { |
| 5194 | perror("Cannot Set PHY Energy Detect Power Down"); |
| 5195 | err = 87; |
| 5196 | } |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | return err; |
| 5200 | } |
| 5201 | |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 5202 | static int fecmode_str_to_type(const char *str) |
| 5203 | { |
Edward Cree | d4b9f3f | 2018-09-05 18:54:57 +0100 | [diff] [blame] | 5204 | if (!strcasecmp(str, "auto")) |
| 5205 | return ETHTOOL_FEC_AUTO; |
| 5206 | if (!strcasecmp(str, "off")) |
| 5207 | return ETHTOOL_FEC_OFF; |
| 5208 | if (!strcasecmp(str, "rs")) |
| 5209 | return ETHTOOL_FEC_RS; |
| 5210 | if (!strcasecmp(str, "baser")) |
| 5211 | return ETHTOOL_FEC_BASER; |
| 5212 | |
| 5213 | return 0; |
| 5214 | } |
| 5215 | |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 5216 | static int do_gfec(struct cmd_context *ctx) |
| 5217 | { |
| 5218 | struct ethtool_fecparam feccmd = { 0 }; |
| 5219 | int rv; |
| 5220 | |
| 5221 | if (ctx->argc != 0) |
| 5222 | exit_bad_args(); |
| 5223 | |
| 5224 | feccmd.cmd = ETHTOOL_GFECPARAM; |
| 5225 | rv = send_ioctl(ctx, &feccmd); |
| 5226 | if (rv != 0) { |
| 5227 | perror("Cannot get FEC settings"); |
| 5228 | return rv; |
| 5229 | } |
| 5230 | |
| 5231 | fprintf(stdout, "FEC parameters for %s:\n", ctx->devname); |
| 5232 | fprintf(stdout, "Configured FEC encodings:"); |
| 5233 | dump_fec(feccmd.fec); |
| 5234 | fprintf(stdout, "\n"); |
| 5235 | |
| 5236 | fprintf(stdout, "Active FEC encoding:"); |
| 5237 | dump_fec(feccmd.active_fec); |
| 5238 | fprintf(stdout, "\n"); |
| 5239 | |
| 5240 | return 0; |
| 5241 | } |
| 5242 | |
| 5243 | static int do_sfec(struct cmd_context *ctx) |
| 5244 | { |
Edward Cree | 98c148e | 2018-09-19 17:06:25 +0100 | [diff] [blame] | 5245 | enum { ARG_NONE, ARG_ENCODING } state = ARG_NONE; |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 5246 | struct ethtool_fecparam feccmd; |
Edward Cree | 98c148e | 2018-09-19 17:06:25 +0100 | [diff] [blame] | 5247 | int fecmode = 0, newmode; |
| 5248 | int rv, i; |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 5249 | |
Edward Cree | 98c148e | 2018-09-19 17:06:25 +0100 | [diff] [blame] | 5250 | for (i = 0; i < ctx->argc; i++) { |
| 5251 | if (!strcmp(ctx->argp[i], "encoding")) { |
| 5252 | state = ARG_ENCODING; |
| 5253 | continue; |
| 5254 | } |
| 5255 | if (state == ARG_ENCODING) { |
| 5256 | newmode = fecmode_str_to_type(ctx->argp[i]); |
| 5257 | if (!newmode) |
| 5258 | exit_bad_args(); |
| 5259 | fecmode |= newmode; |
| 5260 | continue; |
| 5261 | } |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 5262 | exit_bad_args(); |
Edward Cree | 98c148e | 2018-09-19 17:06:25 +0100 | [diff] [blame] | 5263 | } |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 5264 | |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 5265 | if (!fecmode) |
| 5266 | exit_bad_args(); |
| 5267 | |
| 5268 | feccmd.cmd = ETHTOOL_SFECPARAM; |
| 5269 | feccmd.fec = fecmode; |
| 5270 | rv = send_ioctl(ctx, &feccmd); |
| 5271 | if (rv != 0) { |
| 5272 | perror("Cannot set FEC settings"); |
| 5273 | return rv; |
| 5274 | } |
| 5275 | |
| 5276 | return 0; |
| 5277 | } |
| 5278 | |
Nicholas Nunley | 9ecd542 | 2019-03-01 00:15:29 -0800 | [diff] [blame] | 5279 | static int do_perqueue(struct cmd_context *ctx); |
| 5280 | |
Ben Hutchings | dfacc4a | 2011-10-31 18:29:35 +0000 | [diff] [blame] | 5281 | #ifndef TEST_ETHTOOL |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 5282 | int send_ioctl(struct cmd_context *ctx, void *cmd) |
Jeff Garzik | a97a2ec | 2009-03-06 06:12:13 -0500 | [diff] [blame] | 5283 | { |
Ben Hutchings | 37897ca | 2011-10-29 02:33:30 +0100 | [diff] [blame] | 5284 | ctx->ifr.ifr_data = cmd; |
| 5285 | return ioctl(ctx->fd, SIOCETHTOOL, &ctx->ifr); |
Jeff Garzik | a97a2ec | 2009-03-06 06:12:13 -0500 | [diff] [blame] | 5286 | } |
Ben Hutchings | dfacc4a | 2011-10-31 18:29:35 +0000 | [diff] [blame] | 5287 | #endif |
Jeff Garzik | a97a2ec | 2009-03-06 06:12:13 -0500 | [diff] [blame] | 5288 | |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5289 | static int show_usage(struct cmd_context *ctx); |
| 5290 | |
| 5291 | static const struct option { |
| 5292 | const char *opts; |
| 5293 | int want_device; |
| 5294 | int (*func)(struct cmd_context *); |
| 5295 | char *help; |
| 5296 | char *opthelp; |
| 5297 | } args[] = { |
| 5298 | { "-s|--change", 1, do_sset, "Change generic options", |
| 5299 | " [ speed %d ]\n" |
| 5300 | " [ duplex half|full ]\n" |
| 5301 | " [ port tp|aui|bnc|mii|fibre ]\n" |
Jesse Brandeburg | 75e6791 | 2012-08-21 01:37:16 -0700 | [diff] [blame] | 5302 | " [ mdix auto|on|off ]\n" |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5303 | " [ autoneg on|off ]\n" |
| 5304 | " [ advertise %x ]\n" |
| 5305 | " [ phyad %d ]\n" |
| 5306 | " [ xcvr internal|external ]\n" |
Michal Kubecek | b3086af | 2018-08-17 15:21:07 +0200 | [diff] [blame] | 5307 | " [ wol p|u|m|b|a|g|s|f|d... ]\n" |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5308 | " [ sopass %x:%x:%x:%x:%x:%x ]\n" |
| 5309 | " [ msglvl %d | msglvl type on|off ... ]\n" }, |
| 5310 | { "-a|--show-pause", 1, do_gpause, "Show pause options" }, |
| 5311 | { "-A|--pause", 1, do_spause, "Set pause options", |
| 5312 | " [ autoneg on|off ]\n" |
| 5313 | " [ rx on|off ]\n" |
| 5314 | " [ tx on|off ]\n" }, |
| 5315 | { "-c|--show-coalesce", 1, do_gcoalesce, "Show coalesce options" }, |
| 5316 | { "-C|--coalesce", 1, do_scoalesce, "Set coalesce options", |
| 5317 | " [adaptive-rx on|off]\n" |
| 5318 | " [adaptive-tx on|off]\n" |
| 5319 | " [rx-usecs N]\n" |
| 5320 | " [rx-frames N]\n" |
| 5321 | " [rx-usecs-irq N]\n" |
| 5322 | " [rx-frames-irq N]\n" |
| 5323 | " [tx-usecs N]\n" |
| 5324 | " [tx-frames N]\n" |
| 5325 | " [tx-usecs-irq N]\n" |
| 5326 | " [tx-frames-irq N]\n" |
| 5327 | " [stats-block-usecs N]\n" |
| 5328 | " [pkt-rate-low N]\n" |
| 5329 | " [rx-usecs-low N]\n" |
| 5330 | " [rx-frames-low N]\n" |
| 5331 | " [tx-usecs-low N]\n" |
| 5332 | " [tx-frames-low N]\n" |
| 5333 | " [pkt-rate-high N]\n" |
| 5334 | " [rx-usecs-high N]\n" |
| 5335 | " [rx-frames-high N]\n" |
| 5336 | " [tx-usecs-high N]\n" |
| 5337 | " [tx-frames-high N]\n" |
Scott Branden | c0b078c | 2017-12-12 12:20:01 -0800 | [diff] [blame] | 5338 | " [sample-interval N]\n" }, |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5339 | { "-g|--show-ring", 1, do_gring, "Query RX/TX ring parameters" }, |
| 5340 | { "-G|--set-ring", 1, do_sring, "Set RX/TX ring parameters", |
| 5341 | " [ rx N ]\n" |
| 5342 | " [ rx-mini N ]\n" |
| 5343 | " [ rx-jumbo N ]\n" |
| 5344 | " [ tx N ]\n" }, |
Ben Hutchings | 6042804 | 2012-06-01 23:08:32 +0100 | [diff] [blame] | 5345 | { "-k|--show-features|--show-offload", 1, do_gfeatures, |
| 5346 | "Get state of protocol offload and other features" }, |
| 5347 | { "-K|--features|--offload", 1, do_sfeatures, |
| 5348 | "Set protocol offload and other features", |
| 5349 | " FEATURE on|off ...\n" }, |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5350 | { "-i|--driver", 1, do_gdrv, "Show driver information" }, |
| 5351 | { "-d|--register-dump", 1, do_gregs, "Do a register dump", |
| 5352 | " [ raw on|off ]\n" |
| 5353 | " [ file FILENAME ]\n" }, |
| 5354 | { "-e|--eeprom-dump", 1, do_geeprom, "Do a EEPROM dump", |
| 5355 | " [ raw on|off ]\n" |
| 5356 | " [ offset N ]\n" |
| 5357 | " [ length N ]\n" }, |
| 5358 | { "-E|--change-eeprom", 1, do_seeprom, |
| 5359 | "Change bytes in device EEPROM", |
| 5360 | " [ magic N ]\n" |
| 5361 | " [ offset N ]\n" |
| 5362 | " [ length N ]\n" |
| 5363 | " [ value N ]\n" }, |
| 5364 | { "-r|--negotiate", 1, do_nway_rst, "Restart N-WAY negotiation" }, |
| 5365 | { "-p|--identify", 1, do_phys_id, |
| 5366 | "Show visible port identification (e.g. blinking)", |
| 5367 | " [ TIME-IN-SECONDS ]\n" }, |
| 5368 | { "-t|--test", 1, do_test, "Execute adapter self test", |
| 5369 | " [ online | offline | external_lb ]\n" }, |
Ben Hutchings | 395d830 | 2016-03-13 15:56:41 +0000 | [diff] [blame] | 5370 | { "-S|--statistics", 1, do_gnicstats, "Show adapter statistics" }, |
Ben Hutchings | 0fd1951 | 2016-03-13 15:51:58 +0000 | [diff] [blame] | 5371 | { "--phy-statistics", 1, do_gphystats, |
Andrew Lunn | 8b4b823 | 2015-12-23 12:58:31 +0100 | [diff] [blame] | 5372 | "Show phy statistics" }, |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 5373 | { "-n|-u|--show-nfc|--show-ntuple", 1, do_grxclass, |
| 5374 | "Show Rx network flow classification options or rules", |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5375 | " [ rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|" |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 5376 | "tcp6|udp6|ah6|esp6|sctp6 [context %d] |\n" |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 5377 | " rule %d ]\n" }, |
| 5378 | { "-N|-U|--config-nfc|--config-ntuple", 1, do_srxclass, |
| 5379 | "Configure Rx network flow classification options or rules", |
| 5380 | " rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|" |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 5381 | "tcp6|udp6|ah6|esp6|sctp6 m|v|t|s|d|f|n|r... [context %d] |\n" |
Edward Cree | 0c4866c | 2016-03-17 19:17:32 +0000 | [diff] [blame] | 5382 | " flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4|" |
| 5383 | "ip6|tcp6|udp6|ah6|esp6|sctp6\n" |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5384 | " [ src %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n" |
| 5385 | " [ dst %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n" |
| 5386 | " [ proto %d [m %x] ]\n" |
Ben Hutchings | 7d42905 | 2016-06-26 00:58:10 +0200 | [diff] [blame] | 5387 | " [ src-ip IP-ADDRESS [m IP-ADDRESS] ]\n" |
| 5388 | " [ dst-ip IP-ADDRESS [m IP-ADDRESS] ]\n" |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5389 | " [ tos %d [m %x] ]\n" |
Edward Cree | 0c4866c | 2016-03-17 19:17:32 +0000 | [diff] [blame] | 5390 | " [ tclass %d [m %x] ]\n" |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5391 | " [ l4proto %d [m %x] ]\n" |
| 5392 | " [ src-port %d [m %x] ]\n" |
| 5393 | " [ dst-port %d [m %x] ]\n" |
| 5394 | " [ spi %d [m %x] ]\n" |
| 5395 | " [ vlan-etype %x [m %x] ]\n" |
| 5396 | " [ vlan %x [m %x] ]\n" |
| 5397 | " [ user-def %x [m %x] ]\n" |
Yan Burman | b29aa90 | 2012-12-11 14:03:56 +0200 | [diff] [blame] | 5398 | " [ dst-mac %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n" |
Jacob Keller | c837bea | 2018-02-26 10:49:55 -0800 | [diff] [blame] | 5399 | " [ action %d ] | [ vf %d queue %d ]\n" |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 5400 | " [ context %d ]\n" |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 5401 | " [ loc %d]] |\n" |
| 5402 | " delete %d\n" }, |
Richard Cochran | 0fdcc8c | 2012-04-03 19:58:23 +0200 | [diff] [blame] | 5403 | { "-T|--show-time-stamping", 1, do_tsinfo, |
| 5404 | "Show time stamping capabilities" }, |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 5405 | { "-x|--show-rxfh-indir|--show-rxfh", 1, do_grxfh, |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 5406 | "Show Rx flow hash indirection table and/or RSS hash key", |
| 5407 | " [ context %d ]\n" }, |
Venkat Duvvuru | 86c0326 | 2014-07-22 17:51:07 +0530 | [diff] [blame] | 5408 | { "-X|--set-rxfh-indir|--rxfh", 1, do_srxfh, |
Ivan Vecera | 23efab9 | 2017-02-20 15:13:52 +0100 | [diff] [blame] | 5409 | "Set Rx flow hash indirection table and/or RSS hash key", |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 5410 | " [ context %d|new ]\n" |
Ivan Vecera | 23efab9 | 2017-02-20 15:13:52 +0100 | [diff] [blame] | 5411 | " [ equal N | weight W0 W1 ... | default ]\n" |
Gal Pressman | b888f35 | 2017-03-08 16:03:51 +0200 | [diff] [blame] | 5412 | " [ hkey %x:%x:%x:%x:%x:.... ]\n" |
Edward Cree | f5d55b9 | 2018-03-09 15:04:12 +0000 | [diff] [blame] | 5413 | " [ hfunc FUNC ]\n" |
| 5414 | " [ delete ]\n" }, |
Ben Hutchings | 52e837f | 2012-01-21 00:35:55 +0000 | [diff] [blame] | 5415 | { "-f|--flash", 1, do_flash, |
| 5416 | "Flash firmware image from the specified file to a region on the device", |
| 5417 | " FILENAME [ REGION-NUMBER-TO-FLASH ]\n" }, |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5418 | { "-P|--show-permaddr", 1, do_permaddr, |
| 5419 | "Show permanent hardware address" }, |
| 5420 | { "-w|--get-dump", 1, do_getfwdump, |
| 5421 | "Get dump flag, data", |
| 5422 | " [ data FILENAME ]\n" }, |
| 5423 | { "-W|--set-dump", 1, do_setfwdump, |
| 5424 | "Set dump flag of the device", |
| 5425 | " N\n"}, |
| 5426 | { "-l|--show-channels", 1, do_gchannels, "Query Channels" }, |
| 5427 | { "-L|--set-channels", 1, do_schannels, "Set Channels", |
| 5428 | " [ rx N ]\n" |
| 5429 | " [ tx N ]\n" |
| 5430 | " [ other N ]\n" |
| 5431 | " [ combined N ]\n" }, |
Gal Pressman | 5a20e54 | 2017-10-26 17:44:43 +0300 | [diff] [blame] | 5432 | { "--show-priv-flags", 1, do_gprivflags, "Query private flags" }, |
Ben Hutchings | e1ee596 | 2011-11-30 02:29:21 +0000 | [diff] [blame] | 5433 | { "--set-priv-flags", 1, do_sprivflags, "Set private flags", |
| 5434 | " FLAG on|off ...\n" }, |
Aurelien Guillaume | 749f387 | 2012-12-02 21:21:01 +0100 | [diff] [blame] | 5435 | { "-m|--dump-module-eeprom|--module-info", 1, do_getmodule, |
| 5436 | "Query/Decode Module EEPROM information and optical diagnostics if available", |
Stuart Hodgson | 2edf567 | 2012-05-18 15:58:45 +0100 | [diff] [blame] | 5437 | " [ raw on|off ]\n" |
| 5438 | " [ hex on|off ]\n" |
| 5439 | " [ offset N ]\n" |
| 5440 | " [ length N ]\n" }, |
Yuval Mintz | a9fc827 | 2012-06-10 11:48:08 +0300 | [diff] [blame] | 5441 | { "--show-eee", 1, do_geee, "Show EEE settings"}, |
| 5442 | { "--set-eee", 1, do_seee, "Set EEE settings", |
| 5443 | " [ eee on|off ]\n" |
| 5444 | " [ advertise %x ]\n" |
| 5445 | " [ tx-lpi on|off ]\n" |
| 5446 | " [ tx-timer %d ]\n"}, |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5447 | { "--set-phy-tunable", 1, do_set_phy_tunable, "Set PHY tunable", |
Heiner Kallweit | 27c7bb1 | 2019-03-29 20:15:54 +0100 | [diff] [blame] | 5448 | " [ downshift on|off [count N] ]\n" |
Alexandru Ardelean | e568431 | 2019-09-20 12:44:31 +0300 | [diff] [blame] | 5449 | " [ fast-link-down on|off [msecs N] ]\n" |
| 5450 | " [ energy-detect-power-down on|off [msecs N] ]\n"}, |
Raju Lakkaraju | b0fe96d | 2016-11-24 09:56:51 +0100 | [diff] [blame] | 5451 | { "--get-phy-tunable", 1, do_get_phy_tunable, "Get PHY tunable", |
Heiner Kallweit | 27c7bb1 | 2019-03-29 20:15:54 +0100 | [diff] [blame] | 5452 | " [ downshift ]\n" |
Alexandru Ardelean | e568431 | 2019-09-20 12:44:31 +0300 | [diff] [blame] | 5453 | " [ fast-link-down ]\n" |
| 5454 | " [ energy-detect-power-down ]\n"}, |
Scott Branden | 1d3761c | 2017-12-12 12:20:03 -0800 | [diff] [blame] | 5455 | { "--reset", 1, do_reset, "Reset components", |
| 5456 | " [ flags %x ]\n" |
| 5457 | " [ mgmt ]\n" |
| 5458 | " [ mgmt-shared ]\n" |
| 5459 | " [ irq ]\n" |
| 5460 | " [ irq-shared ]\n" |
| 5461 | " [ dma ]\n" |
| 5462 | " [ dma-shared ]\n" |
| 5463 | " [ filter ]\n" |
| 5464 | " [ filter-shared ]\n" |
| 5465 | " [ offload ]\n" |
| 5466 | " [ offload-shared ]\n" |
| 5467 | " [ mac ]\n" |
| 5468 | " [ mac-shared ]\n" |
| 5469 | " [ phy ]\n" |
| 5470 | " [ phy-shared ]\n" |
| 5471 | " [ ram ]\n" |
| 5472 | " [ ram-shared ]\n" |
| 5473 | " [ ap ]\n" |
| 5474 | " [ ap-shared ]\n" |
| 5475 | " [ dedicated ]\n" |
| 5476 | " [ all ]\n"}, |
Dustin Byford | 8db75d1 | 2017-12-18 14:57:41 -0800 | [diff] [blame] | 5477 | { "--show-fec", 1, do_gfec, "Show FEC settings"}, |
| 5478 | { "--set-fec", 1, do_sfec, "Set FEC settings", |
Edward Cree | 98c148e | 2018-09-19 17:06:25 +0100 | [diff] [blame] | 5479 | " [ encoding auto|off|rs|baser [...]]\n"}, |
Nicholas Nunley | 52ecd6e | 2019-03-01 00:15:30 -0800 | [diff] [blame] | 5480 | { "-Q|--per-queue", 1, do_perqueue, "Apply per-queue command." |
Nicholas Nunley | 759d695 | 2019-03-01 00:15:31 -0800 | [diff] [blame] | 5481 | "The supported sub commands include --show-coalesce, --coalesce", |
Nicholas Nunley | 9ecd542 | 2019-03-01 00:15:29 -0800 | [diff] [blame] | 5482 | " [queue_mask %x] SUB_COMMAND\n"}, |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5483 | { "-h|--help", 0, show_usage, "Show this help" }, |
| 5484 | { "--version", 0, do_version, "Show version number" }, |
| 5485 | {} |
| 5486 | }; |
| 5487 | |
Maciej Żenczykowski | d5432a9 | 2019-10-17 11:20:50 -0700 | [diff] [blame] | 5488 | static int show_usage(struct cmd_context *ctx maybe_unused) |
Ben Hutchings | 56b1148 | 2011-10-31 23:44:42 +0000 | [diff] [blame] | 5489 | { |
| 5490 | int i; |
| 5491 | |
| 5492 | /* ethtool -h */ |
| 5493 | fprintf(stdout, PACKAGE " version " VERSION "\n"); |
| 5494 | fprintf(stdout, |
| 5495 | "Usage:\n" |
| 5496 | " ethtool DEVNAME\t" |
| 5497 | "Display standard information about device\n"); |
| 5498 | for (i = 0; args[i].opts; i++) { |
| 5499 | fputs(" ethtool ", stdout); |
| 5500 | fprintf(stdout, "%s %s\t%s\n", |
| 5501 | args[i].opts, |
| 5502 | args[i].want_device ? "DEVNAME" : "\t", |
| 5503 | args[i].help); |
| 5504 | if (args[i].opthelp) |
| 5505 | fputs(args[i].opthelp, stdout); |
| 5506 | } |
| 5507 | |
| 5508 | return 0; |
| 5509 | } |
| 5510 | |
Maciej Żenczykowski | 2054a8c | 2019-10-17 11:20:51 -0700 | [diff] [blame] | 5511 | static int find_option(char *arg) |
Nicholas Nunley | 37abfb6 | 2019-03-01 00:15:27 -0800 | [diff] [blame] | 5512 | { |
| 5513 | const char *opt; |
| 5514 | size_t len; |
| 5515 | int k; |
| 5516 | |
| 5517 | for (k = 0; args[k].opts; k++) { |
| 5518 | opt = args[k].opts; |
| 5519 | for (;;) { |
| 5520 | len = strcspn(opt, "|"); |
Maciej Żenczykowski | 2054a8c | 2019-10-17 11:20:51 -0700 | [diff] [blame] | 5521 | if (strncmp(arg, opt, len) == 0 && arg[len] == 0) |
Nicholas Nunley | 37abfb6 | 2019-03-01 00:15:27 -0800 | [diff] [blame] | 5522 | return k; |
| 5523 | |
| 5524 | if (opt[len] == 0) |
| 5525 | break; |
| 5526 | opt += len + 1; |
| 5527 | } |
| 5528 | } |
| 5529 | |
| 5530 | return -1; |
| 5531 | } |
| 5532 | |
Nicholas Nunley | 9ecd542 | 2019-03-01 00:15:29 -0800 | [diff] [blame] | 5533 | #define MAX(x, y) (x > y ? x : y) |
| 5534 | |
| 5535 | static int find_max_num_queues(struct cmd_context *ctx) |
| 5536 | { |
| 5537 | struct ethtool_channels echannels; |
| 5538 | |
| 5539 | echannels.cmd = ETHTOOL_GCHANNELS; |
| 5540 | if (send_ioctl(ctx, &echannels)) |
| 5541 | return -1; |
| 5542 | |
| 5543 | return MAX(echannels.rx_count, echannels.tx_count) + |
| 5544 | echannels.combined_count; |
| 5545 | } |
| 5546 | |
Nicholas Nunley | 52ecd6e | 2019-03-01 00:15:30 -0800 | [diff] [blame] | 5547 | static struct ethtool_per_queue_op * |
| 5548 | get_per_queue_coalesce(struct cmd_context *ctx, __u32 *queue_mask, int n_queues) |
| 5549 | { |
| 5550 | struct ethtool_per_queue_op *per_queue_opt; |
| 5551 | |
| 5552 | per_queue_opt = malloc(sizeof(*per_queue_opt) + n_queues * |
| 5553 | sizeof(struct ethtool_coalesce)); |
| 5554 | if (!per_queue_opt) |
| 5555 | return NULL; |
| 5556 | |
| 5557 | memcpy(per_queue_opt->queue_mask, queue_mask, |
| 5558 | __KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32) * sizeof(__u32)); |
| 5559 | per_queue_opt->cmd = ETHTOOL_PERQUEUE; |
| 5560 | per_queue_opt->sub_command = ETHTOOL_GCOALESCE; |
| 5561 | if (send_ioctl(ctx, per_queue_opt)) { |
| 5562 | free(per_queue_opt); |
| 5563 | perror("Cannot get device per queue parameters"); |
| 5564 | return NULL; |
| 5565 | } |
| 5566 | |
| 5567 | return per_queue_opt; |
| 5568 | } |
| 5569 | |
Nicholas Nunley | 759d695 | 2019-03-01 00:15:31 -0800 | [diff] [blame] | 5570 | static void set_per_queue_coalesce(struct cmd_context *ctx, |
| 5571 | struct ethtool_per_queue_op *per_queue_opt, |
| 5572 | int n_queues) |
| 5573 | { |
| 5574 | struct ethtool_coalesce ecoal; |
| 5575 | DECLARE_COALESCE_OPTION_VARS(); |
| 5576 | struct cmdline_info cmdline_coalesce[] = COALESCE_CMDLINE_INFO(ecoal); |
| 5577 | __u32 *queue_mask = per_queue_opt->queue_mask; |
| 5578 | struct ethtool_coalesce *ecoal_q; |
| 5579 | int gcoalesce_changed = 0; |
| 5580 | int i, idx = 0; |
| 5581 | |
| 5582 | parse_generic_cmdline(ctx, &gcoalesce_changed, |
| 5583 | cmdline_coalesce, ARRAY_SIZE(cmdline_coalesce)); |
| 5584 | |
| 5585 | ecoal_q = (struct ethtool_coalesce *)(per_queue_opt + 1); |
| 5586 | for (i = 0; i < __KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32); i++) { |
| 5587 | int queue = i * 32; |
| 5588 | __u32 mask = queue_mask[i]; |
| 5589 | |
| 5590 | while (mask > 0) { |
| 5591 | if (mask & 0x1) { |
| 5592 | int changed = 0; |
| 5593 | |
| 5594 | memcpy(&ecoal, ecoal_q + idx, |
| 5595 | sizeof(struct ethtool_coalesce)); |
| 5596 | do_generic_set(cmdline_coalesce, |
| 5597 | ARRAY_SIZE(cmdline_coalesce), |
| 5598 | &changed); |
| 5599 | if (!changed) |
| 5600 | fprintf(stderr, |
| 5601 | "Queue %d, no coalesce parameters changed\n", |
| 5602 | queue); |
| 5603 | memcpy(ecoal_q + idx, &ecoal, |
| 5604 | sizeof(struct ethtool_coalesce)); |
| 5605 | idx++; |
| 5606 | } |
| 5607 | mask = mask >> 1; |
| 5608 | queue++; |
| 5609 | } |
| 5610 | if (idx == n_queues) |
| 5611 | break; |
| 5612 | } |
| 5613 | |
| 5614 | per_queue_opt->cmd = ETHTOOL_PERQUEUE; |
| 5615 | per_queue_opt->sub_command = ETHTOOL_SCOALESCE; |
| 5616 | |
| 5617 | if (send_ioctl(ctx, per_queue_opt)) |
| 5618 | perror("Cannot set device per queue parameters"); |
| 5619 | } |
| 5620 | |
Nicholas Nunley | 9ecd542 | 2019-03-01 00:15:29 -0800 | [diff] [blame] | 5621 | static int do_perqueue(struct cmd_context *ctx) |
| 5622 | { |
Nicholas Nunley | 52ecd6e | 2019-03-01 00:15:30 -0800 | [diff] [blame] | 5623 | struct ethtool_per_queue_op *per_queue_opt; |
Nicholas Nunley | 9ecd542 | 2019-03-01 00:15:29 -0800 | [diff] [blame] | 5624 | __u32 queue_mask[__KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32)] = {0}; |
| 5625 | int i, n_queues = 0; |
| 5626 | |
| 5627 | if (ctx->argc == 0) |
| 5628 | exit_bad_args(); |
| 5629 | |
| 5630 | /* |
| 5631 | * The sub commands will be applied to |
| 5632 | * all queues if no queue_mask set |
| 5633 | */ |
| 5634 | if (strncmp(*ctx->argp, "queue_mask", 11)) { |
| 5635 | n_queues = find_max_num_queues(ctx); |
| 5636 | if (n_queues < 0) { |
| 5637 | perror("Cannot get number of queues"); |
| 5638 | return -EFAULT; |
| 5639 | } else if (n_queues > MAX_NUM_QUEUE) { |
| 5640 | n_queues = MAX_NUM_QUEUE; |
| 5641 | } |
| 5642 | for (i = 0; i < n_queues / 32; i++) |
| 5643 | queue_mask[i] = ~0; |
| 5644 | if (n_queues % 32) |
| 5645 | queue_mask[i] = (1 << (n_queues - i * 32)) - 1; |
| 5646 | fprintf(stdout, |
| 5647 | "The sub commands will be applied to all %d queues\n", |
| 5648 | n_queues); |
| 5649 | } else { |
| 5650 | ctx->argc--; |
| 5651 | ctx->argp++; |
| 5652 | if (parse_hex_u32_bitmap(*ctx->argp, MAX_NUM_QUEUE, |
| 5653 | queue_mask)) { |
| 5654 | fprintf(stdout, "Invalid queue mask\n"); |
| 5655 | return -1; |
| 5656 | } |
| 5657 | for (i = 0; i < __KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32); i++) { |
| 5658 | __u32 mask = queue_mask[i]; |
| 5659 | |
| 5660 | while (mask > 0) { |
| 5661 | if (mask & 0x1) |
| 5662 | n_queues++; |
| 5663 | mask = mask >> 1; |
| 5664 | } |
| 5665 | } |
| 5666 | ctx->argc--; |
| 5667 | ctx->argp++; |
| 5668 | } |
| 5669 | |
Maciej Żenczykowski | 2054a8c | 2019-10-17 11:20:51 -0700 | [diff] [blame] | 5670 | i = find_option(ctx->argp[0]); |
Nicholas Nunley | 9ecd542 | 2019-03-01 00:15:29 -0800 | [diff] [blame] | 5671 | if (i < 0) |
| 5672 | exit_bad_args(); |
| 5673 | |
Nicholas Nunley | 52ecd6e | 2019-03-01 00:15:30 -0800 | [diff] [blame] | 5674 | if (strstr(args[i].opts, "--show-coalesce") != NULL) { |
| 5675 | per_queue_opt = get_per_queue_coalesce(ctx, queue_mask, |
| 5676 | n_queues); |
| 5677 | if (per_queue_opt == NULL) { |
| 5678 | perror("Cannot get device per queue parameters"); |
| 5679 | return -EFAULT; |
| 5680 | } |
| 5681 | dump_per_queue_coalesce(per_queue_opt, queue_mask, n_queues); |
| 5682 | free(per_queue_opt); |
Nicholas Nunley | 759d695 | 2019-03-01 00:15:31 -0800 | [diff] [blame] | 5683 | } else if (strstr(args[i].opts, "--coalesce") != NULL) { |
| 5684 | ctx->argc--; |
| 5685 | ctx->argp++; |
| 5686 | per_queue_opt = get_per_queue_coalesce(ctx, queue_mask, |
| 5687 | n_queues); |
| 5688 | if (per_queue_opt == NULL) { |
| 5689 | perror("Cannot get device per queue parameters"); |
| 5690 | return -EFAULT; |
| 5691 | } |
| 5692 | set_per_queue_coalesce(ctx, per_queue_opt, n_queues); |
| 5693 | free(per_queue_opt); |
Nicholas Nunley | 52ecd6e | 2019-03-01 00:15:30 -0800 | [diff] [blame] | 5694 | } else { |
| 5695 | perror("The subcommand is not supported yet"); |
| 5696 | return -EOPNOTSUPP; |
| 5697 | } |
Nicholas Nunley | 9ecd542 | 2019-03-01 00:15:29 -0800 | [diff] [blame] | 5698 | |
Nicholas Nunley | 52ecd6e | 2019-03-01 00:15:30 -0800 | [diff] [blame] | 5699 | return 0; |
Nicholas Nunley | 9ecd542 | 2019-03-01 00:15:29 -0800 | [diff] [blame] | 5700 | } |
| 5701 | |
Ben Hutchings | dfacc4a | 2011-10-31 18:29:35 +0000 | [diff] [blame] | 5702 | int main(int argc, char **argp) |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 5703 | { |
Ben Hutchings | c62ebdd | 2011-10-27 20:14:19 +0100 | [diff] [blame] | 5704 | int (*func)(struct cmd_context *); |
| 5705 | int want_device; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 5706 | struct cmd_context ctx; |
| 5707 | int k; |
| 5708 | |
David Decotigny | 33133ab | 2016-03-25 09:21:01 -0700 | [diff] [blame] | 5709 | init_global_link_mode_masks(); |
| 5710 | |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 5711 | /* Skip command name */ |
| 5712 | argp++; |
| 5713 | argc--; |
| 5714 | |
| 5715 | /* First argument must be either a valid option or a device |
| 5716 | * name to get settings for (which we don't expect to begin |
| 5717 | * with '-'). |
| 5718 | */ |
| 5719 | if (argc == 0) |
| 5720 | exit_bad_args(); |
Nicholas Nunley | 37abfb6 | 2019-03-01 00:15:27 -0800 | [diff] [blame] | 5721 | |
Maciej Żenczykowski | 2054a8c | 2019-10-17 11:20:51 -0700 | [diff] [blame] | 5722 | k = find_option(*argp); |
Nicholas Nunley | 37abfb6 | 2019-03-01 00:15:27 -0800 | [diff] [blame] | 5723 | if (k >= 0) { |
| 5724 | argp++; |
| 5725 | argc--; |
| 5726 | func = args[k].func; |
| 5727 | want_device = args[k].want_device; |
| 5728 | goto opt_found; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 5729 | } |
Ben Hutchings | c62ebdd | 2011-10-27 20:14:19 +0100 | [diff] [blame] | 5730 | if ((*argp)[0] == '-') |
| 5731 | exit_bad_args(); |
| 5732 | func = do_gset; |
| 5733 | want_device = 1; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 5734 | |
Ben Hutchings | c62ebdd | 2011-10-27 20:14:19 +0100 | [diff] [blame] | 5735 | opt_found: |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 5736 | if (want_device) { |
Ben Hutchings | 743eb0b | 2011-10-29 02:36:48 +0100 | [diff] [blame] | 5737 | ctx.devname = *argp++; |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 5738 | argc--; |
| 5739 | |
Ben Hutchings | 743eb0b | 2011-10-29 02:36:48 +0100 | [diff] [blame] | 5740 | if (ctx.devname == NULL) |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 5741 | exit_bad_args(); |
Ben Hutchings | 743eb0b | 2011-10-29 02:36:48 +0100 | [diff] [blame] | 5742 | if (strlen(ctx.devname) >= IFNAMSIZ) |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 5743 | exit_bad_args(); |
| 5744 | |
| 5745 | /* Setup our control structures. */ |
| 5746 | memset(&ctx.ifr, 0, sizeof(ctx.ifr)); |
Ben Hutchings | 743eb0b | 2011-10-29 02:36:48 +0100 | [diff] [blame] | 5747 | strcpy(ctx.ifr.ifr_name, ctx.devname); |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 5748 | |
| 5749 | /* Open control socket. */ |
| 5750 | ctx.fd = socket(AF_INET, SOCK_DGRAM, 0); |
David Decotigny | 225fdc6 | 2016-06-26 10:52:59 +0200 | [diff] [blame] | 5751 | if (ctx.fd < 0) |
| 5752 | ctx.fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); |
Ben Hutchings | 127f806 | 2011-10-29 01:15:34 +0100 | [diff] [blame] | 5753 | if (ctx.fd < 0) { |
| 5754 | perror("Cannot get control socket"); |
| 5755 | return 70; |
| 5756 | } |
| 5757 | } else { |
| 5758 | ctx.fd = -1; |
| 5759 | } |
| 5760 | |
| 5761 | ctx.argc = argc; |
| 5762 | ctx.argp = argp; |
| 5763 | |
| 5764 | return func(&ctx); |
Jeff Garzik | 32c8037 | 2005-10-25 01:56:48 -0400 | [diff] [blame] | 5765 | } |