phylink.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. #ifndef NETDEV_PCS_H
  2. #define NETDEV_PCS_H
  3. #include <linux/phy.h>
  4. #include <linux/spinlock.h>
  5. #include <linux/workqueue.h>
  6. struct device_node;
  7. struct ethtool_cmd;
  8. struct fwnode_handle;
  9. struct net_device;
  10. enum {
  11. MLO_PAUSE_NONE,
  12. MLO_PAUSE_RX = BIT(0),
  13. MLO_PAUSE_TX = BIT(1),
  14. MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX,
  15. MLO_PAUSE_AN = BIT(2),
  16. MLO_AN_PHY = 0, /* Conventional PHY */
  17. MLO_AN_FIXED, /* Fixed-link mode */
  18. MLO_AN_INBAND, /* In-band protocol */
  19. /* MAC_SYM_PAUSE and MAC_ASYM_PAUSE are used when configuring our
  20. * autonegotiation advertisement. They correspond to the PAUSE and
  21. * ASM_DIR bits defined by 802.3, respectively.
  22. *
  23. * The following table lists the values of tx_pause and rx_pause which
  24. * might be requested in mac_link_up. The exact values depend on either
  25. * the results of autonegotation (if MLO_PAUSE_AN is set) or user
  26. * configuration (if MLO_PAUSE_AN is not set).
  27. *
  28. * MAC_SYM_PAUSE MAC_ASYM_PAUSE MLO_PAUSE_AN tx_pause/rx_pause
  29. * ============= ============== ============ ==================
  30. * 0 0 0 0/0
  31. * 0 0 1 0/0
  32. * 0 1 0 0/0, 0/1, 1/0, 1/1
  33. * 0 1 1 0/0, 1/0
  34. * 1 0 0 0/0, 1/1
  35. * 1 0 1 0/0, 1/1
  36. * 1 1 0 0/0, 0/1, 1/0, 1/1
  37. * 1 1 1 0/0, 0/1, 1/1
  38. *
  39. * If you set MAC_ASYM_PAUSE, the user may request any combination of
  40. * tx_pause and rx_pause. You do not have to support these
  41. * combinations.
  42. *
  43. * However, you should support combinations of tx_pause and rx_pause
  44. * which might be the result of autonegotation. For example, don't set
  45. * MAC_SYM_PAUSE unless your device can support tx_pause and rx_pause
  46. * at the same time.
  47. */
  48. MAC_SYM_PAUSE = BIT(0),
  49. MAC_ASYM_PAUSE = BIT(1),
  50. MAC_10HD = BIT(2),
  51. MAC_10FD = BIT(3),
  52. MAC_10 = MAC_10HD | MAC_10FD,
  53. MAC_100HD = BIT(4),
  54. MAC_100FD = BIT(5),
  55. MAC_100 = MAC_100HD | MAC_100FD,
  56. MAC_1000HD = BIT(6),
  57. MAC_1000FD = BIT(7),
  58. MAC_1000 = MAC_1000HD | MAC_1000FD,
  59. MAC_2500FD = BIT(8),
  60. MAC_5000FD = BIT(9),
  61. MAC_10000FD = BIT(10),
  62. MAC_20000FD = BIT(11),
  63. MAC_25000FD = BIT(12),
  64. MAC_40000FD = BIT(13),
  65. MAC_50000FD = BIT(14),
  66. MAC_56000FD = BIT(15),
  67. MAC_100000FD = BIT(16),
  68. MAC_200000FD = BIT(17),
  69. MAC_400000FD = BIT(18),
  70. };
  71. static inline bool phylink_autoneg_inband(unsigned int mode)
  72. {
  73. return mode == MLO_AN_INBAND;
  74. }
  75. /**
  76. * struct phylink_link_state - link state structure
  77. * @advertising: ethtool bitmask containing advertised link modes
  78. * @lp_advertising: ethtool bitmask containing link partner advertised link
  79. * modes
  80. * @interface: link &typedef phy_interface_t mode
  81. * @speed: link speed, one of the SPEED_* constants.
  82. * @duplex: link duplex mode, one of DUPLEX_* constants.
  83. * @pause: link pause state, described by MLO_PAUSE_* constants.
  84. * @rate_matching: rate matching being performed, one of the RATE_MATCH_*
  85. * constants. If rate matching is taking place, then the speed/duplex of
  86. * the medium link mode (@speed and @duplex) and the speed/duplex of the phy
  87. * interface mode (@interface) are different.
  88. * @link: true if the link is up.
  89. * @an_enabled: true if autonegotiation is enabled/desired.
  90. * @an_complete: true if autonegotiation has completed.
  91. */
  92. struct phylink_link_state {
  93. __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
  94. __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
  95. phy_interface_t interface;
  96. int speed;
  97. int duplex;
  98. int pause;
  99. int rate_matching;
  100. unsigned int link:1;
  101. unsigned int an_enabled:1;
  102. unsigned int an_complete:1;
  103. };
  104. enum phylink_op_type {
  105. PHYLINK_NETDEV = 0,
  106. PHYLINK_DEV,
  107. };
  108. /**
  109. * struct phylink_config - PHYLINK configuration structure
  110. * @dev: a pointer to a struct device associated with the MAC
  111. * @type: operation type of PHYLINK instance
  112. * @legacy_pre_march2020: driver has not been updated for March 2020 updates
  113. * (See commit 7cceb599d15d ("net: phylink: avoid mac_config calls")
  114. * @poll_fixed_state: if true, starts link_poll,
  115. * if MAC link is at %MLO_AN_FIXED mode.
  116. * @mac_managed_pm: if true, indicate the MAC driver is responsible for PHY PM.
  117. * @ovr_an_inband: if true, override PCS to MLO_AN_INBAND
  118. * @get_fixed_state: callback to execute to determine the fixed link state,
  119. * if MAC link is at %MLO_AN_FIXED mode.
  120. * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx
  121. * are supported by the MAC/PCS.
  122. * @mac_capabilities: MAC pause/speed/duplex capabilities.
  123. */
  124. struct phylink_config {
  125. struct device *dev;
  126. enum phylink_op_type type;
  127. bool legacy_pre_march2020;
  128. bool poll_fixed_state;
  129. bool mac_managed_pm;
  130. bool ovr_an_inband;
  131. void (*get_fixed_state)(struct phylink_config *config,
  132. struct phylink_link_state *state);
  133. DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
  134. unsigned long mac_capabilities;
  135. };
  136. /**
  137. * struct phylink_mac_ops - MAC operations structure.
  138. * @validate: Validate and update the link configuration.
  139. * @mac_select_pcs: Select a PCS for the interface mode.
  140. * @mac_pcs_get_state: Read the current link state from the hardware.
  141. * @mac_prepare: prepare for a major reconfiguration of the interface.
  142. * @mac_config: configure the MAC for the selected mode and state.
  143. * @mac_finish: finish a major reconfiguration of the interface.
  144. * @mac_an_restart: restart 802.3z BaseX autonegotiation.
  145. * @mac_link_down: take the link down.
  146. * @mac_link_up: allow the link to come up.
  147. *
  148. * The individual methods are described more fully below.
  149. */
  150. struct phylink_mac_ops {
  151. void (*validate)(struct phylink_config *config,
  152. unsigned long *supported,
  153. struct phylink_link_state *state);
  154. struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config,
  155. phy_interface_t interface);
  156. void (*mac_pcs_get_state)(struct phylink_config *config,
  157. struct phylink_link_state *state);
  158. int (*mac_prepare)(struct phylink_config *config, unsigned int mode,
  159. phy_interface_t iface);
  160. void (*mac_config)(struct phylink_config *config, unsigned int mode,
  161. const struct phylink_link_state *state);
  162. int (*mac_finish)(struct phylink_config *config, unsigned int mode,
  163. phy_interface_t iface);
  164. void (*mac_an_restart)(struct phylink_config *config);
  165. void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
  166. phy_interface_t interface);
  167. void (*mac_link_up)(struct phylink_config *config,
  168. struct phy_device *phy, unsigned int mode,
  169. phy_interface_t interface, int speed, int duplex,
  170. bool tx_pause, bool rx_pause);
  171. };
  172. #if 0 /* For kernel-doc purposes only. */
  173. /**
  174. * validate - Validate and update the link configuration
  175. * @config: a pointer to a &struct phylink_config.
  176. * @supported: ethtool bitmask for supported link modes.
  177. * @state: a pointer to a &struct phylink_link_state.
  178. *
  179. * Clear bits in the @supported and @state->advertising masks that
  180. * are not supportable by the MAC.
  181. *
  182. * Note that the PHY may be able to transform from one connection
  183. * technology to another, so, eg, don't clear 1000BaseX just
  184. * because the MAC is unable to BaseX mode. This is more about
  185. * clearing unsupported speeds and duplex settings. The port modes
  186. * should not be cleared; phylink_set_port_modes() will help with this.
  187. *
  188. * When @config->supported_interfaces has been set, phylink will iterate
  189. * over the supported interfaces to determine the full capability of the
  190. * MAC. The validation function must not print errors if @state->interface
  191. * is set to an unexpected value.
  192. *
  193. * When @config->supported_interfaces is empty, phylink will call this
  194. * function with @state->interface set to %PHY_INTERFACE_MODE_NA, and
  195. * expects the MAC driver to return all supported link modes.
  196. *
  197. * If the @state->interface mode is not supported, then the @supported
  198. * mask must be cleared.
  199. */
  200. void validate(struct phylink_config *config, unsigned long *supported,
  201. struct phylink_link_state *state);
  202. /**
  203. * mac_select_pcs: Select a PCS for the interface mode.
  204. * @config: a pointer to a &struct phylink_config.
  205. * @interface: PHY interface mode for PCS
  206. *
  207. * Return the &struct phylink_pcs for the specified interface mode, or
  208. * NULL if none is required, or an error pointer on error.
  209. *
  210. * This must not modify any state. It is used to query which PCS should
  211. * be used. Phylink will use this during validation to ensure that the
  212. * configuration is valid, and when setting a configuration to internally
  213. * set the PCS that will be used.
  214. */
  215. struct phylink_pcs *mac_select_pcs(struct phylink_config *config,
  216. phy_interface_t interface);
  217. /**
  218. * mac_pcs_get_state() - Read the current inband link state from the hardware
  219. * @config: a pointer to a &struct phylink_config.
  220. * @state: a pointer to a &struct phylink_link_state.
  221. *
  222. * Read the current inband link state from the MAC PCS, reporting the
  223. * current speed in @state->speed, duplex mode in @state->duplex, pause
  224. * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
  225. * negotiation completion state in @state->an_complete, and link up state
  226. * in @state->link. If possible, @state->lp_advertising should also be
  227. * populated.
  228. *
  229. * Note: This is a legacy method. This function will not be called unless
  230. * legacy_pre_march2020 is set in &struct phylink_config and there is no
  231. * PCS attached.
  232. */
  233. void mac_pcs_get_state(struct phylink_config *config,
  234. struct phylink_link_state *state);
  235. /**
  236. * mac_prepare() - prepare to change the PHY interface mode
  237. * @config: a pointer to a &struct phylink_config.
  238. * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
  239. * @iface: interface mode to switch to
  240. *
  241. * phylink will call this method at the beginning of a full initialisation
  242. * of the link, which includes changing the interface mode or at initial
  243. * startup time. It may be called for the current mode. The MAC driver
  244. * should perform whatever actions are required, e.g. disabling the
  245. * Serdes PHY.
  246. *
  247. * This will be the first call in the sequence:
  248. * - mac_prepare()
  249. * - mac_config()
  250. * - pcs_config()
  251. * - possible pcs_an_restart()
  252. * - mac_finish()
  253. *
  254. * Returns zero on success, or negative errno on failure which will be
  255. * reported to the kernel log.
  256. */
  257. int mac_prepare(struct phylink_config *config, unsigned int mode,
  258. phy_interface_t iface);
  259. /**
  260. * mac_config() - configure the MAC for the selected mode and state
  261. * @config: a pointer to a &struct phylink_config.
  262. * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
  263. * @state: a pointer to a &struct phylink_link_state.
  264. *
  265. * Note - not all members of @state are valid. In particular,
  266. * @state->lp_advertising, @state->link, @state->an_complete are never
  267. * guaranteed to be correct, and so any mac_config() implementation must
  268. * never reference these fields.
  269. *
  270. * Note: For legacy March 2020 drivers (drivers with legacy_pre_march2020 set
  271. * in their &phylnk_config and which don't have a PCS), this function will be
  272. * called on each link up event, and to also change the in-band advert. For
  273. * non-legacy drivers, it will only be called to reconfigure the MAC for a
  274. * "major" change in e.g. interface mode. It will not be called for changes
  275. * in speed, duplex or pause modes or to change the in-band advertisement.
  276. * In any case, it is strongly preferred that speed, duplex and pause settings
  277. * are handled in the mac_link_up() method and not in this method.
  278. *
  279. * (this requires a rewrite - please refer to mac_link_up() for situations
  280. * where the PCS and MAC are not tightly integrated.)
  281. *
  282. * In all negotiation modes, as defined by @mode, @state->pause indicates the
  283. * pause settings which should be applied as follows. If %MLO_PAUSE_AN is not
  284. * set, %MLO_PAUSE_TX and %MLO_PAUSE_RX indicate whether the MAC should send
  285. * pause frames and/or act on received pause frames respectively. Otherwise,
  286. * the results of in-band negotiation/status from the MAC PCS should be used
  287. * to control the MAC pause mode settings.
  288. *
  289. * The action performed depends on the currently selected mode:
  290. *
  291. * %MLO_AN_FIXED, %MLO_AN_PHY:
  292. * Configure for non-inband negotiation mode, where the link settings
  293. * are completely communicated via mac_link_up(). The physical link
  294. * protocol from the MAC is specified by @state->interface.
  295. *
  296. * @state->advertising may be used, but is not required.
  297. *
  298. * Older drivers (prior to the mac_link_up() change) may use @state->speed,
  299. * @state->duplex and @state->pause to configure the MAC, but this is
  300. * deprecated; such drivers should be converted to use mac_link_up().
  301. *
  302. * Other members of @state must be ignored.
  303. *
  304. * Valid state members: interface, advertising.
  305. * Deprecated state members: speed, duplex, pause.
  306. *
  307. * %MLO_AN_INBAND:
  308. * place the link in an inband negotiation mode (such as 802.3z
  309. * 1000base-X or Cisco SGMII mode depending on the @state->interface
  310. * mode). In both cases, link state management (whether the link
  311. * is up or not) is performed by the MAC, and reported via the
  312. * mac_pcs_get_state() callback. Changes in link state must be made
  313. * by calling phylink_mac_change().
  314. *
  315. * Interface mode specific details are mentioned below.
  316. *
  317. * If in 802.3z mode, the link speed is fixed, dependent on the
  318. * @state->interface. Duplex and pause modes are negotiated via
  319. * the in-band configuration word. Advertised pause modes are set
  320. * according to the @state->an_enabled and @state->advertising
  321. * flags. Beware of MACs which only support full duplex at gigabit
  322. * and higher speeds.
  323. *
  324. * If in Cisco SGMII mode, the link speed and duplex mode are passed
  325. * in the serial bitstream 16-bit configuration word, and the MAC
  326. * should be configured to read these bits and acknowledge the
  327. * configuration word. Nothing is advertised by the MAC. The MAC is
  328. * responsible for reading the configuration word and configuring
  329. * itself accordingly.
  330. *
  331. * Valid state members: interface, an_enabled, pause, advertising.
  332. *
  333. * Implementations are expected to update the MAC to reflect the
  334. * requested settings - i.o.w., if nothing has changed between two
  335. * calls, no action is expected. If only flow control settings have
  336. * changed, flow control should be updated *without* taking the link
  337. * down. This "update" behaviour is critical to avoid bouncing the
  338. * link up status.
  339. */
  340. void mac_config(struct phylink_config *config, unsigned int mode,
  341. const struct phylink_link_state *state);
  342. /**
  343. * mac_finish() - finish a to change the PHY interface mode
  344. * @config: a pointer to a &struct phylink_config.
  345. * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
  346. * @iface: interface mode to switch to
  347. *
  348. * phylink will call this if it called mac_prepare() to allow the MAC to
  349. * complete any necessary steps after the MAC and PCS have been configured
  350. * for the @mode and @iface. E.g. a MAC driver may wish to re-enable the
  351. * Serdes PHY here if it was previously disabled by mac_prepare().
  352. *
  353. * Returns zero on success, or negative errno on failure which will be
  354. * reported to the kernel log.
  355. */
  356. int mac_finish(struct phylink_config *config, unsigned int mode,
  357. phy_interface_t iface);
  358. /**
  359. * mac_an_restart() - restart 802.3z BaseX autonegotiation
  360. * @config: a pointer to a &struct phylink_config.
  361. *
  362. * Note: This is a legacy method. This function will not be called unless
  363. * legacy_pre_march2020 is set in &struct phylink_config and there is no
  364. * PCS attached.
  365. */
  366. void mac_an_restart(struct phylink_config *config);
  367. /**
  368. * mac_link_down() - take the link down
  369. * @config: a pointer to a &struct phylink_config.
  370. * @mode: link autonegotiation mode
  371. * @interface: link &typedef phy_interface_t mode
  372. *
  373. * If @mode is not an in-band negotiation mode (as defined by
  374. * phylink_autoneg_inband()), force the link down and disable any
  375. * Energy Efficient Ethernet MAC configuration. Interface type
  376. * selection must be done in mac_config().
  377. */
  378. void mac_link_down(struct phylink_config *config, unsigned int mode,
  379. phy_interface_t interface);
  380. /**
  381. * mac_link_up() - allow the link to come up
  382. * @config: a pointer to a &struct phylink_config.
  383. * @phy: any attached phy
  384. * @mode: link autonegotiation mode
  385. * @interface: link &typedef phy_interface_t mode
  386. * @speed: link speed
  387. * @duplex: link duplex
  388. * @tx_pause: link transmit pause enablement status
  389. * @rx_pause: link receive pause enablement status
  390. *
  391. * Configure the MAC for an established link.
  392. *
  393. * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link
  394. * settings, and should be used to configure the MAC block appropriately
  395. * where these settings are not automatically conveyed from the PCS block,
  396. * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode))
  397. * is disabled.
  398. *
  399. * Note that when 802.3z in-band negotiation is in use, it is possible
  400. * that the user wishes to override the pause settings, and this should
  401. * be allowed when considering the implementation of this method.
  402. *
  403. * If in-band negotiation mode is disabled, allow the link to come up. If
  404. * @phy is non-%NULL, configure Energy Efficient Ethernet by calling
  405. * phy_init_eee() and perform appropriate MAC configuration for EEE.
  406. * Interface type selection must be done in mac_config().
  407. */
  408. void mac_link_up(struct phylink_config *config, struct phy_device *phy,
  409. unsigned int mode, phy_interface_t interface,
  410. int speed, int duplex, bool tx_pause, bool rx_pause);
  411. #endif
  412. struct phylink_pcs_ops;
  413. /**
  414. * struct phylink_pcs - PHYLINK PCS instance
  415. * @ops: a pointer to the &struct phylink_pcs_ops structure
  416. * @poll: poll the PCS for link changes
  417. *
  418. * This structure is designed to be embedded within the PCS private data,
  419. * and will be passed between phylink and the PCS.
  420. */
  421. struct phylink_pcs {
  422. const struct phylink_pcs_ops *ops;
  423. bool poll;
  424. };
  425. /**
  426. * struct phylink_pcs_ops - MAC PCS operations structure.
  427. * @pcs_validate: validate the link configuration.
  428. * @pcs_get_state: read the current MAC PCS link state from the hardware.
  429. * @pcs_config: configure the MAC PCS for the selected mode and state.
  430. * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
  431. * @pcs_link_up: program the PCS for the resolved link configuration
  432. * (where necessary).
  433. */
  434. struct phylink_pcs_ops {
  435. int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
  436. const struct phylink_link_state *state);
  437. void (*pcs_get_state)(struct phylink_pcs *pcs,
  438. struct phylink_link_state *state);
  439. int (*pcs_config)(struct phylink_pcs *pcs, unsigned int mode,
  440. phy_interface_t interface,
  441. const unsigned long *advertising,
  442. bool permit_pause_to_mac);
  443. void (*pcs_an_restart)(struct phylink_pcs *pcs);
  444. void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int mode,
  445. phy_interface_t interface, int speed, int duplex);
  446. };
  447. #if 0 /* For kernel-doc purposes only. */
  448. /**
  449. * pcs_validate() - validate the link configuration.
  450. * @pcs: a pointer to a &struct phylink_pcs.
  451. * @supported: ethtool bitmask for supported link modes.
  452. * @state: a const pointer to a &struct phylink_link_state.
  453. *
  454. * Validate the interface mode, and advertising's autoneg bit, removing any
  455. * media ethtool link modes that would not be supportable from the supported
  456. * mask. Phylink will propagate the changes to the advertising mask. See the
  457. * &struct phylink_mac_ops validate() method.
  458. *
  459. * Returns -EINVAL if the interface mode/autoneg mode is not supported.
  460. * Returns non-zero positive if the link state can be supported.
  461. */
  462. int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
  463. const struct phylink_link_state *state);
  464. /**
  465. * pcs_get_state() - Read the current inband link state from the hardware
  466. * @pcs: a pointer to a &struct phylink_pcs.
  467. * @state: a pointer to a &struct phylink_link_state.
  468. *
  469. * Read the current inband link state from the MAC PCS, reporting the
  470. * current speed in @state->speed, duplex mode in @state->duplex, pause
  471. * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
  472. * negotiation completion state in @state->an_complete, and link up state
  473. * in @state->link. If possible, @state->lp_advertising should also be
  474. * populated.
  475. *
  476. * When present, this overrides mac_pcs_get_state() in &struct
  477. * phylink_mac_ops.
  478. */
  479. void pcs_get_state(struct phylink_pcs *pcs,
  480. struct phylink_link_state *state);
  481. /**
  482. * pcs_config() - Configure the PCS mode and advertisement
  483. * @pcs: a pointer to a &struct phylink_pcs.
  484. * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
  485. * @interface: interface mode to be used
  486. * @advertising: adertisement ethtool link mode mask
  487. * @permit_pause_to_mac: permit forwarding pause resolution to MAC
  488. *
  489. * Configure the PCS for the operating mode, the interface mode, and set
  490. * the advertisement mask. @permit_pause_to_mac indicates whether the
  491. * hardware may forward the pause mode resolution to the MAC.
  492. *
  493. * When operating in %MLO_AN_INBAND, inband should always be enabled,
  494. * otherwise inband should be disabled.
  495. *
  496. * For SGMII, there is no advertisement from the MAC side, the PCS should
  497. * be programmed to acknowledge the inband word from the PHY.
  498. *
  499. * For 1000BASE-X, the advertisement should be programmed into the PCS.
  500. *
  501. * For most 10GBASE-R, there is no advertisement.
  502. */
  503. int pcs_config(struct phylink_pcs *pcs, unsigned int mode,
  504. phy_interface_t interface, const unsigned long *advertising,
  505. bool permit_pause_to_mac);
  506. /**
  507. * pcs_an_restart() - restart 802.3z BaseX autonegotiation
  508. * @pcs: a pointer to a &struct phylink_pcs.
  509. *
  510. * When PCS ops are present, this overrides mac_an_restart() in &struct
  511. * phylink_mac_ops.
  512. */
  513. void pcs_an_restart(struct phylink_pcs *pcs);
  514. /**
  515. * pcs_link_up() - program the PCS for the resolved link configuration
  516. * @pcs: a pointer to a &struct phylink_pcs.
  517. * @mode: link autonegotiation mode
  518. * @interface: link &typedef phy_interface_t mode
  519. * @speed: link speed
  520. * @duplex: link duplex
  521. *
  522. * This call will be made just before mac_link_up() to inform the PCS of
  523. * the resolved link parameters. For example, a PCS operating in SGMII
  524. * mode without in-band AN needs to be manually configured for the link
  525. * and duplex setting. Otherwise, this should be a no-op.
  526. */
  527. void pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
  528. phy_interface_t interface, int speed, int duplex);
  529. #endif
  530. void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
  531. unsigned long phylink_get_capabilities(phy_interface_t interface,
  532. unsigned long mac_capabilities,
  533. int rate_matching);
  534. void phylink_generic_validate(struct phylink_config *config,
  535. unsigned long *supported,
  536. struct phylink_link_state *state);
  537. struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
  538. phy_interface_t iface,
  539. const struct phylink_mac_ops *mac_ops);
  540. void phylink_destroy(struct phylink *);
  541. bool phylink_expects_phy(struct phylink *pl);
  542. int phylink_connect_phy(struct phylink *, struct phy_device *);
  543. int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
  544. int phylink_fwnode_phy_connect(struct phylink *pl,
  545. struct fwnode_handle *fwnode,
  546. u32 flags);
  547. void phylink_disconnect_phy(struct phylink *);
  548. void phylink_mac_change(struct phylink *, bool up);
  549. void phylink_start(struct phylink *);
  550. void phylink_stop(struct phylink *);
  551. void phylink_suspend(struct phylink *pl, bool mac_wol);
  552. void phylink_resume(struct phylink *pl);
  553. void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
  554. int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
  555. int phylink_ethtool_ksettings_get(struct phylink *,
  556. struct ethtool_link_ksettings *);
  557. int phylink_ethtool_ksettings_set(struct phylink *,
  558. const struct ethtool_link_ksettings *);
  559. int phylink_ethtool_nway_reset(struct phylink *);
  560. void phylink_ethtool_get_pauseparam(struct phylink *,
  561. struct ethtool_pauseparam *);
  562. int phylink_ethtool_set_pauseparam(struct phylink *,
  563. struct ethtool_pauseparam *);
  564. int phylink_get_eee_err(struct phylink *);
  565. int phylink_init_eee(struct phylink *, bool);
  566. int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
  567. int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
  568. int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
  569. int phylink_speed_down(struct phylink *pl, bool sync);
  570. int phylink_speed_up(struct phylink *pl);
  571. #define phylink_zero(bm) \
  572. bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
  573. #define __phylink_do_bit(op, bm, mode) \
  574. op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
  575. #define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
  576. #define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
  577. #define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
  578. void phylink_set_port_modes(unsigned long *bits);
  579. void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
  580. u16 bmsr, u16 lpa);
  581. void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
  582. struct phylink_link_state *state);
  583. int phylink_mii_c22_pcs_encode_advertisement(phy_interface_t interface,
  584. const unsigned long *advertising);
  585. int phylink_mii_c22_pcs_config(struct mdio_device *pcs, unsigned int mode,
  586. phy_interface_t interface,
  587. const unsigned long *advertising);
  588. void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs);
  589. void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs,
  590. struct phylink_link_state *state);
  591. void phylink_decode_usxgmii_word(struct phylink_link_state *state,
  592. uint16_t lpa);
  593. #endif