ethtool.h 16 KB

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