ethtool.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * ethtool.h: Defines for Linux ethtool.
  4. *
  5. * Copyright (C) 1998 David S. Miller (davem@redhat.com)
  6. * Copyright 2001 Jeff Garzik <jgarzik@pobox.com>
  7. * Portions Copyright 2001 Sun Microsystems (thockin@sun.com)
  8. * Portions Copyright 2002 Intel (eli.kupermann@intel.com,
  9. * christopher.leech@intel.com,
  10. * scott.feldman@intel.com)
  11. * Portions Copyright (C) Sun Microsystems 2008
  12. */
  13. #ifndef _LINUX_ETHTOOL_H
  14. #define _LINUX_ETHTOOL_H
  15. #include <linux/bitmap.h>
  16. #include <linux/compat.h>
  17. #include <uapi/linux/ethtool.h>
  18. #ifdef CONFIG_COMPAT
  19. struct compat_ethtool_rx_flow_spec {
  20. u32 flow_type;
  21. union ethtool_flow_union h_u;
  22. struct ethtool_flow_ext h_ext;
  23. union ethtool_flow_union m_u;
  24. struct ethtool_flow_ext m_ext;
  25. compat_u64 ring_cookie;
  26. u32 location;
  27. };
  28. struct compat_ethtool_rxnfc {
  29. u32 cmd;
  30. u32 flow_type;
  31. compat_u64 data;
  32. struct compat_ethtool_rx_flow_spec fs;
  33. u32 rule_cnt;
  34. u32 rule_locs[0];
  35. };
  36. #endif /* CONFIG_COMPAT */
  37. #include <linux/rculist.h>
  38. /**
  39. * enum ethtool_phys_id_state - indicator state for physical identification
  40. * @ETHTOOL_ID_INACTIVE: Physical ID indicator should be deactivated
  41. * @ETHTOOL_ID_ACTIVE: Physical ID indicator should be activated
  42. * @ETHTOOL_ID_ON: LED should be turned on (used iff %ETHTOOL_ID_ACTIVE
  43. * is not supported)
  44. * @ETHTOOL_ID_OFF: LED should be turned off (used iff %ETHTOOL_ID_ACTIVE
  45. * is not supported)
  46. */
  47. enum ethtool_phys_id_state {
  48. ETHTOOL_ID_INACTIVE,
  49. ETHTOOL_ID_ACTIVE,
  50. ETHTOOL_ID_ON,
  51. ETHTOOL_ID_OFF
  52. };
  53. enum {
  54. ETH_RSS_HASH_TOP_BIT, /* Configurable RSS hash function - Toeplitz */
  55. ETH_RSS_HASH_XOR_BIT, /* Configurable RSS hash function - Xor */
  56. ETH_RSS_HASH_CRC32_BIT, /* Configurable RSS hash function - Crc32 */
  57. /*
  58. * Add your fresh new hash function bits above and remember to update
  59. * rss_hash_func_strings[] in ethtool.c
  60. */
  61. ETH_RSS_HASH_FUNCS_COUNT
  62. };
  63. #define __ETH_RSS_HASH_BIT(bit) ((u32)1 << (bit))
  64. #define __ETH_RSS_HASH(name) __ETH_RSS_HASH_BIT(ETH_RSS_HASH_##name##_BIT)
  65. #define ETH_RSS_HASH_TOP __ETH_RSS_HASH(TOP)
  66. #define ETH_RSS_HASH_XOR __ETH_RSS_HASH(XOR)
  67. #define ETH_RSS_HASH_CRC32 __ETH_RSS_HASH(CRC32)
  68. #define ETH_RSS_HASH_UNKNOWN 0
  69. #define ETH_RSS_HASH_NO_CHANGE 0
  70. struct net_device;
  71. /* Some generic methods drivers may use in their ethtool_ops */
  72. u32 ethtool_op_get_link(struct net_device *dev);
  73. int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *eti);
  74. /**
  75. * ethtool_rxfh_indir_default - get default value for RX flow hash indirection
  76. * @index: Index in RX flow hash indirection table
  77. * @n_rx_rings: Number of RX rings to use
  78. *
  79. * This function provides the default policy for RX flow hash indirection.
  80. */
  81. static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings)
  82. {
  83. return index % n_rx_rings;
  84. }
  85. /* number of link mode bits/ulongs handled internally by kernel */
  86. #define __ETHTOOL_LINK_MODE_MASK_NBITS \
  87. (__ETHTOOL_LINK_MODE_LAST + 1)
  88. /* declare a link mode bitmap */
  89. #define __ETHTOOL_DECLARE_LINK_MODE_MASK(name) \
  90. DECLARE_BITMAP(name, __ETHTOOL_LINK_MODE_MASK_NBITS)
  91. /* drivers must ignore base.cmd and base.link_mode_masks_nwords
  92. * fields, but they are allowed to overwrite them (will be ignored).
  93. */
  94. struct ethtool_link_ksettings {
  95. struct ethtool_link_settings base;
  96. struct {
  97. __ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
  98. __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
  99. __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
  100. } link_modes;
  101. };
  102. /**
  103. * ethtool_link_ksettings_zero_link_mode - clear link_ksettings link mode mask
  104. * @ptr : pointer to struct ethtool_link_ksettings
  105. * @name : one of supported/advertising/lp_advertising
  106. */
  107. #define ethtool_link_ksettings_zero_link_mode(ptr, name) \
  108. bitmap_zero((ptr)->link_modes.name, __ETHTOOL_LINK_MODE_MASK_NBITS)
  109. /**
  110. * ethtool_link_ksettings_add_link_mode - set bit in link_ksettings
  111. * link mode mask
  112. * @ptr : pointer to struct ethtool_link_ksettings
  113. * @name : one of supported/advertising/lp_advertising
  114. * @mode : one of the ETHTOOL_LINK_MODE_*_BIT
  115. * (not atomic, no bound checking)
  116. */
  117. #define ethtool_link_ksettings_add_link_mode(ptr, name, mode) \
  118. __set_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name)
  119. /**
  120. * ethtool_link_ksettings_del_link_mode - clear bit in link_ksettings
  121. * link mode mask
  122. * @ptr : pointer to struct ethtool_link_ksettings
  123. * @name : one of supported/advertising/lp_advertising
  124. * @mode : one of the ETHTOOL_LINK_MODE_*_BIT
  125. * (not atomic, no bound checking)
  126. */
  127. #define ethtool_link_ksettings_del_link_mode(ptr, name, mode) \
  128. __clear_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name)
  129. /**
  130. * ethtool_link_ksettings_test_link_mode - test bit in ksettings link mode mask
  131. * @ptr : pointer to struct ethtool_link_ksettings
  132. * @name : one of supported/advertising/lp_advertising
  133. * @mode : one of the ETHTOOL_LINK_MODE_*_BIT
  134. * (not atomic, no bound checking)
  135. *
  136. * Returns true/false.
  137. */
  138. #define ethtool_link_ksettings_test_link_mode(ptr, name, mode) \
  139. test_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name)
  140. extern int
  141. __ethtool_get_link_ksettings(struct net_device *dev,
  142. struct ethtool_link_ksettings *link_ksettings);
  143. /**
  144. * ethtool_intersect_link_masks - Given two link masks, AND them together
  145. * @dst: first mask and where result is stored
  146. * @src: second mask to intersect with
  147. *
  148. * Given two link mode masks, AND them together and save the result in dst.
  149. */
  150. void ethtool_intersect_link_masks(struct ethtool_link_ksettings *dst,
  151. struct ethtool_link_ksettings *src);
  152. void ethtool_convert_legacy_u32_to_link_mode(unsigned long *dst,
  153. u32 legacy_u32);
  154. /* return false if src had higher bits set. lower bits always updated. */
  155. bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
  156. const unsigned long *src);
  157. /**
  158. * struct ethtool_ops - optional netdev operations
  159. * @get_settings: DEPRECATED, use %get_link_ksettings/%set_link_ksettings
  160. * API. Get various device settings including Ethernet link
  161. * settings. The @cmd parameter is expected to have been cleared
  162. * before get_settings is called. Returns a negative error code
  163. * or zero.
  164. * @set_settings: DEPRECATED, use %get_link_ksettings/%set_link_ksettings
  165. * API. Set various device settings including Ethernet link
  166. * settings. Returns a negative error code or zero.
  167. * @get_drvinfo: Report driver/device information. Should only set the
  168. * @driver, @version, @fw_version and @bus_info fields. If not
  169. * implemented, the @driver and @bus_info fields will be filled in
  170. * according to the netdev's parent device.
  171. * @get_regs_len: Get buffer length required for @get_regs
  172. * @get_regs: Get device registers
  173. * @get_wol: Report whether Wake-on-Lan is enabled
  174. * @set_wol: Turn Wake-on-Lan on or off. Returns a negative error code
  175. * or zero.
  176. * @get_msglevel: Report driver message level. This should be the value
  177. * of the @msg_enable field used by netif logging functions.
  178. * @set_msglevel: Set driver message level
  179. * @nway_reset: Restart autonegotiation. Returns a negative error code
  180. * or zero.
  181. * @get_link: Report whether physical link is up. Will only be called if
  182. * the netdev is up. Should usually be set to ethtool_op_get_link(),
  183. * which uses netif_carrier_ok().
  184. * @get_eeprom: Read data from the device EEPROM.
  185. * Should fill in the magic field. Don't need to check len for zero
  186. * or wraparound. Fill in the data argument with the eeprom values
  187. * from offset to offset + len. Update len to the amount read.
  188. * Returns an error or zero.
  189. * @set_eeprom: Write data to the device EEPROM.
  190. * Should validate the magic field. Don't need to check len for zero
  191. * or wraparound. Update len to the amount written. Returns an error
  192. * or zero.
  193. * @get_coalesce: Get interrupt coalescing parameters. Returns a negative
  194. * error code or zero.
  195. * @set_coalesce: Set interrupt coalescing parameters. Returns a negative
  196. * error code or zero.
  197. * @get_ringparam: Report ring sizes
  198. * @set_ringparam: Set ring sizes. Returns a negative error code or zero.
  199. * @get_pauseparam: Report pause parameters
  200. * @set_pauseparam: Set pause parameters. Returns a negative error code
  201. * or zero.
  202. * @self_test: Run specified self-tests
  203. * @get_strings: Return a set of strings that describe the requested objects
  204. * @set_phys_id: Identify the physical devices, e.g. by flashing an LED
  205. * attached to it. The implementation may update the indicator
  206. * asynchronously or synchronously, but in either case it must return
  207. * quickly. It is initially called with the argument %ETHTOOL_ID_ACTIVE,
  208. * and must either activate asynchronous updates and return zero, return
  209. * a negative error or return a positive frequency for synchronous
  210. * indication (e.g. 1 for one on/off cycle per second). If it returns
  211. * a frequency then it will be called again at intervals with the
  212. * argument %ETHTOOL_ID_ON or %ETHTOOL_ID_OFF and should set the state of
  213. * the indicator accordingly. Finally, it is called with the argument
  214. * %ETHTOOL_ID_INACTIVE and must deactivate the indicator. Returns a
  215. * negative error code or zero.
  216. * @get_ethtool_stats: Return extended statistics about the device.
  217. * This is only useful if the device maintains statistics not
  218. * included in &struct rtnl_link_stats64.
  219. * @begin: Function to be called before any other operation. Returns a
  220. * negative error code or zero.
  221. * @complete: Function to be called after any other operation except
  222. * @begin. Will be called even if the other operation failed.
  223. * @get_priv_flags: Report driver-specific feature flags.
  224. * @set_priv_flags: Set driver-specific feature flags. Returns a negative
  225. * error code or zero.
  226. * @get_sset_count: Get number of strings that @get_strings will write.
  227. * @get_rxnfc: Get RX flow classification rules. Returns a negative
  228. * error code or zero.
  229. * @set_rxnfc: Set RX flow classification rules. Returns a negative
  230. * error code or zero.
  231. * @flash_device: Write a firmware image to device's flash memory.
  232. * Returns a negative error code or zero.
  233. * @reset: Reset (part of) the device, as specified by a bitmask of
  234. * flags from &enum ethtool_reset_flags. Returns a negative
  235. * error code or zero.
  236. * @get_rxfh_key_size: Get the size of the RX flow hash key.
  237. * Returns zero if not supported for this specific device.
  238. * @get_rxfh_indir_size: Get the size of the RX flow hash indirection table.
  239. * Returns zero if not supported for this specific device.
  240. * @get_rxfh: Get the contents of the RX flow hash indirection table, hash key
  241. * and/or hash function.
  242. * Returns a negative error code or zero.
  243. * @set_rxfh: Set the contents of the RX flow hash indirection table, hash
  244. * key, and/or hash function. Arguments which are set to %NULL or zero
  245. * will remain unchanged.
  246. * Returns a negative error code or zero. An error code must be returned
  247. * if at least one unsupported change was requested.
  248. * @get_channels: Get number of channels.
  249. * @set_channels: Set number of channels. Returns a negative error code or
  250. * zero.
  251. * @get_dump_flag: Get dump flag indicating current dump length, version,
  252. * and flag of the device.
  253. * @get_dump_data: Get dump data.
  254. * @set_dump: Set dump specific flags to the device.
  255. * @get_ts_info: Get the time stamping and PTP hardware clock capabilities.
  256. * Drivers supporting transmit time stamps in software should set this to
  257. * ethtool_op_get_ts_info().
  258. * @get_module_info: Get the size and type of the eeprom contained within
  259. * a plug-in module.
  260. * @get_module_eeprom: Get the eeprom information from the plug-in module
  261. * @get_eee: Get Energy-Efficient (EEE) supported and status.
  262. * @set_eee: Set EEE status (enable/disable) as well as LPI timers.
  263. * @get_per_queue_coalesce: Get interrupt coalescing parameters per queue.
  264. * It must check that the given queue number is valid. If neither a RX nor
  265. * a TX queue has this number, return -EINVAL. If only a RX queue or a TX
  266. * queue has this number, set the inapplicable fields to ~0 and return 0.
  267. * Returns a negative error code or zero.
  268. * @set_per_queue_coalesce: Set interrupt coalescing parameters per queue.
  269. * It must check that the given queue number is valid. If neither a RX nor
  270. * a TX queue has this number, return -EINVAL. If only a RX queue or a TX
  271. * queue has this number, ignore the inapplicable fields.
  272. * Returns a negative error code or zero.
  273. * @get_link_ksettings: When defined, takes precedence over the
  274. * %get_settings method. Get various device settings
  275. * including Ethernet link settings. The %cmd and
  276. * %link_mode_masks_nwords fields should be ignored (use
  277. * %__ETHTOOL_LINK_MODE_MASK_NBITS instead of the latter), any
  278. * change to them will be overwritten by kernel. Returns a
  279. * negative error code or zero.
  280. * @set_link_ksettings: When defined, takes precedence over the
  281. * %set_settings method. Set various device settings including
  282. * Ethernet link settings. The %cmd and %link_mode_masks_nwords
  283. * fields should be ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS
  284. * instead of the latter), any change to them will be overwritten
  285. * by kernel. Returns a negative error code or zero.
  286. * @get_fecparam: Get the network device Forward Error Correction parameters.
  287. * @set_fecparam: Set the network device Forward Error Correction parameters.
  288. * @get_ethtool_phy_stats: Return extended statistics about the PHY device.
  289. * This is only useful if the device maintains PHY statistics and
  290. * cannot use the standard PHY library helpers.
  291. *
  292. * All operations are optional (i.e. the function pointer may be set
  293. * to %NULL) and callers must take this into account. Callers must
  294. * hold the RTNL lock.
  295. *
  296. * See the structures used by these operations for further documentation.
  297. * Note that for all operations using a structure ending with a zero-
  298. * length array, the array is allocated separately in the kernel and
  299. * is passed to the driver as an additional parameter.
  300. *
  301. * See &struct net_device and &struct net_device_ops for documentation
  302. * of the generic netdev features interface.
  303. */
  304. struct ethtool_ops {
  305. int (*get_settings)(struct net_device *, struct ethtool_cmd *);
  306. int (*set_settings)(struct net_device *, struct ethtool_cmd *);
  307. void (*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);
  308. int (*get_regs_len)(struct net_device *);
  309. void (*get_regs)(struct net_device *, struct ethtool_regs *, void *);
  310. void (*get_wol)(struct net_device *, struct ethtool_wolinfo *);
  311. int (*set_wol)(struct net_device *, struct ethtool_wolinfo *);
  312. u32 (*get_msglevel)(struct net_device *);
  313. void (*set_msglevel)(struct net_device *, u32);
  314. int (*nway_reset)(struct net_device *);
  315. u32 (*get_link)(struct net_device *);
  316. int (*get_eeprom_len)(struct net_device *);
  317. int (*get_eeprom)(struct net_device *,
  318. struct ethtool_eeprom *, u8 *);
  319. int (*set_eeprom)(struct net_device *,
  320. struct ethtool_eeprom *, u8 *);
  321. int (*get_coalesce)(struct net_device *, struct ethtool_coalesce *);
  322. int (*set_coalesce)(struct net_device *, struct ethtool_coalesce *);
  323. void (*get_ringparam)(struct net_device *,
  324. struct ethtool_ringparam *);
  325. int (*set_ringparam)(struct net_device *,
  326. struct ethtool_ringparam *);
  327. void (*get_pauseparam)(struct net_device *,
  328. struct ethtool_pauseparam*);
  329. int (*set_pauseparam)(struct net_device *,
  330. struct ethtool_pauseparam*);
  331. void (*self_test)(struct net_device *, struct ethtool_test *, u64 *);
  332. void (*get_strings)(struct net_device *, u32 stringset, u8 *);
  333. int (*set_phys_id)(struct net_device *, enum ethtool_phys_id_state);
  334. void (*get_ethtool_stats)(struct net_device *,
  335. struct ethtool_stats *, u64 *);
  336. int (*begin)(struct net_device *);
  337. void (*complete)(struct net_device *);
  338. u32 (*get_priv_flags)(struct net_device *);
  339. int (*set_priv_flags)(struct net_device *, u32);
  340. int (*get_sset_count)(struct net_device *, int);
  341. int (*get_rxnfc)(struct net_device *,
  342. struct ethtool_rxnfc *, u32 *rule_locs);
  343. int (*set_rxnfc)(struct net_device *, struct ethtool_rxnfc *);
  344. int (*flash_device)(struct net_device *, struct ethtool_flash *);
  345. int (*reset)(struct net_device *, u32 *);
  346. u32 (*get_rxfh_key_size)(struct net_device *);
  347. u32 (*get_rxfh_indir_size)(struct net_device *);
  348. int (*get_rxfh)(struct net_device *, u32 *indir, u8 *key,
  349. u8 *hfunc);
  350. int (*set_rxfh)(struct net_device *, const u32 *indir,
  351. const u8 *key, const u8 hfunc);
  352. int (*get_rxfh_context)(struct net_device *, u32 *indir, u8 *key,
  353. u8 *hfunc, u32 rss_context);
  354. int (*set_rxfh_context)(struct net_device *, const u32 *indir,
  355. const u8 *key, const u8 hfunc,
  356. u32 *rss_context, bool delete);
  357. void (*get_channels)(struct net_device *, struct ethtool_channels *);
  358. int (*set_channels)(struct net_device *, struct ethtool_channels *);
  359. int (*get_dump_flag)(struct net_device *, struct ethtool_dump *);
  360. int (*get_dump_data)(struct net_device *,
  361. struct ethtool_dump *, void *);
  362. int (*set_dump)(struct net_device *, struct ethtool_dump *);
  363. int (*get_ts_info)(struct net_device *, struct ethtool_ts_info *);
  364. int (*get_module_info)(struct net_device *,
  365. struct ethtool_modinfo *);
  366. int (*get_module_eeprom)(struct net_device *,
  367. struct ethtool_eeprom *, u8 *);
  368. int (*get_eee)(struct net_device *, struct ethtool_eee *);
  369. int (*set_eee)(struct net_device *, struct ethtool_eee *);
  370. int (*get_tunable)(struct net_device *,
  371. const struct ethtool_tunable *, void *);
  372. int (*set_tunable)(struct net_device *,
  373. const struct ethtool_tunable *, const void *);
  374. int (*get_per_queue_coalesce)(struct net_device *, u32,
  375. struct ethtool_coalesce *);
  376. int (*set_per_queue_coalesce)(struct net_device *, u32,
  377. struct ethtool_coalesce *);
  378. int (*get_link_ksettings)(struct net_device *,
  379. struct ethtool_link_ksettings *);
  380. int (*set_link_ksettings)(struct net_device *,
  381. const struct ethtool_link_ksettings *);
  382. int (*get_fecparam)(struct net_device *,
  383. struct ethtool_fecparam *);
  384. int (*set_fecparam)(struct net_device *,
  385. struct ethtool_fecparam *);
  386. void (*get_ethtool_phy_stats)(struct net_device *,
  387. struct ethtool_stats *, u64 *);
  388. };
  389. #endif /* _LINUX_ETHTOOL_H */