ethtool.h 17 KB

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