ethtool.h 16 KB

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