Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 6fdca3c5ab55d6a74277efcae2db9828f567a06a 845 lines 34 kB view raw
1#ifndef NETDEV_PCS_H 2#define NETDEV_PCS_H 3 4#include <linux/phy.h> 5#include <linux/spinlock.h> 6#include <linux/workqueue.h> 7 8#include <net/eee.h> 9 10struct device_node; 11struct ethtool_cmd; 12struct fwnode_handle; 13struct net_device; 14struct phylink; 15 16enum { 17 MLO_PAUSE_NONE, 18 MLO_PAUSE_RX = BIT(0), 19 MLO_PAUSE_TX = BIT(1), 20 MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX, 21 MLO_PAUSE_AN = BIT(2), 22 23 MLO_AN_PHY = 0, /* Conventional PHY */ 24 MLO_AN_FIXED, /* Fixed-link mode */ 25 MLO_AN_INBAND, /* In-band protocol */ 26 27 /* PCS "negotiation" mode. 28 * PHYLINK_PCS_NEG_NONE - protocol has no inband capability 29 * PHYLINK_PCS_NEG_OUTBAND - some out of band or fixed link setting 30 * PHYLINK_PCS_NEG_INBAND_DISABLED - inband mode disabled, e.g. 31 * 1000base-X with autoneg off 32 * PHYLINK_PCS_NEG_INBAND_ENABLED - inband mode enabled 33 * Additionally, this can be tested using bitmasks: 34 * PHYLINK_PCS_NEG_INBAND - inband mode selected 35 * PHYLINK_PCS_NEG_ENABLED - negotiation mode enabled 36 */ 37 PHYLINK_PCS_NEG_NONE = 0, 38 PHYLINK_PCS_NEG_ENABLED = BIT(4), 39 PHYLINK_PCS_NEG_OUTBAND = BIT(5), 40 PHYLINK_PCS_NEG_INBAND = BIT(6), 41 PHYLINK_PCS_NEG_INBAND_DISABLED = PHYLINK_PCS_NEG_INBAND, 42 PHYLINK_PCS_NEG_INBAND_ENABLED = PHYLINK_PCS_NEG_INBAND | 43 PHYLINK_PCS_NEG_ENABLED, 44 45 /* MAC_SYM_PAUSE and MAC_ASYM_PAUSE are used when configuring our 46 * autonegotiation advertisement. They correspond to the PAUSE and 47 * ASM_DIR bits defined by 802.3, respectively. 48 * 49 * The following table lists the values of tx_pause and rx_pause which 50 * might be requested in mac_link_up. The exact values depend on either 51 * the results of autonegotation (if MLO_PAUSE_AN is set) or user 52 * configuration (if MLO_PAUSE_AN is not set). 53 * 54 * MAC_SYM_PAUSE MAC_ASYM_PAUSE MLO_PAUSE_AN tx_pause/rx_pause 55 * ============= ============== ============ ================== 56 * 0 0 0 0/0 57 * 0 0 1 0/0 58 * 0 1 0 0/0, 0/1, 1/0, 1/1 59 * 0 1 1 0/0, 1/0 60 * 1 0 0 0/0, 1/1 61 * 1 0 1 0/0, 1/1 62 * 1 1 0 0/0, 0/1, 1/0, 1/1 63 * 1 1 1 0/0, 0/1, 1/1 64 * 65 * If you set MAC_ASYM_PAUSE, the user may request any combination of 66 * tx_pause and rx_pause. You do not have to support these 67 * combinations. 68 * 69 * However, you should support combinations of tx_pause and rx_pause 70 * which might be the result of autonegotation. For example, don't set 71 * MAC_SYM_PAUSE unless your device can support tx_pause and rx_pause 72 * at the same time. 73 */ 74 MAC_SYM_PAUSE = BIT(0), 75 MAC_ASYM_PAUSE = BIT(1), 76 MAC_10HD = BIT(2), 77 MAC_10FD = BIT(3), 78 MAC_10 = MAC_10HD | MAC_10FD, 79 MAC_100HD = BIT(4), 80 MAC_100FD = BIT(5), 81 MAC_100 = MAC_100HD | MAC_100FD, 82 MAC_1000HD = BIT(6), 83 MAC_1000FD = BIT(7), 84 MAC_1000 = MAC_1000HD | MAC_1000FD, 85 MAC_2500FD = BIT(8), 86 MAC_5000FD = BIT(9), 87 MAC_10000FD = BIT(10), 88 MAC_20000FD = BIT(11), 89 MAC_25000FD = BIT(12), 90 MAC_40000FD = BIT(13), 91 MAC_50000FD = BIT(14), 92 MAC_56000FD = BIT(15), 93 MAC_80000FD = BIT(16), 94 MAC_100000FD = BIT(17), 95 MAC_200000FD = BIT(18), 96 MAC_400000FD = BIT(19), 97}; 98 99static inline bool phylink_autoneg_inband(unsigned int mode) 100{ 101 return mode == MLO_AN_INBAND; 102} 103 104/** 105 * struct phylink_link_state - link state structure 106 * @advertising: ethtool bitmask containing advertised link modes 107 * @lp_advertising: ethtool bitmask containing link partner advertised link 108 * modes 109 * @interface: link &typedef phy_interface_t mode 110 * @speed: link speed, one of the SPEED_* constants. 111 * @duplex: link duplex mode, one of DUPLEX_* constants. 112 * @pause: link pause state, described by MLO_PAUSE_* constants. 113 * @rate_matching: rate matching being performed, one of the RATE_MATCH_* 114 * constants. If rate matching is taking place, then the speed/duplex of 115 * the medium link mode (@speed and @duplex) and the speed/duplex of the phy 116 * interface mode (@interface) are different. 117 * @link: true if the link is up. 118 * @an_complete: true if autonegotiation has completed. 119 */ 120struct phylink_link_state { 121 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising); 122 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising); 123 phy_interface_t interface; 124 int speed; 125 int duplex; 126 int pause; 127 int rate_matching; 128 unsigned int link:1; 129 unsigned int an_complete:1; 130}; 131 132enum phylink_op_type { 133 PHYLINK_NETDEV = 0, 134 PHYLINK_DEV, 135}; 136 137/** 138 * struct phylink_config - PHYLINK configuration structure 139 * @dev: a pointer to a struct device associated with the MAC 140 * @type: operation type of PHYLINK instance 141 * @poll_fixed_state: if true, starts link_poll, 142 * if MAC link is at %MLO_AN_FIXED mode. 143 * @mac_managed_pm: if true, indicate the MAC driver is responsible for PHY PM. 144 * @mac_requires_rxc: if true, the MAC always requires a receive clock from PHY. 145 * The PHY driver should start the clock signal as soon as 146 * possible and avoid stopping it during suspend events. 147 * @default_an_inband: if true, defaults to MLO_AN_INBAND rather than 148 * MLO_AN_PHY. A fixed-link specification will override. 149 * @eee_rx_clk_stop_enable: if true, PHY can stop the receive clock during LPI 150 * @get_fixed_state: callback to execute to determine the fixed link state, 151 * if MAC link is at %MLO_AN_FIXED mode. 152 * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx 153 * are supported by the MAC/PCS. 154 * @lpi_interfaces: bitmap describing which PHY interface modes can support 155 * LPI signalling. 156 * @mac_capabilities: MAC pause/speed/duplex capabilities. 157 * @lpi_capabilities: MAC speeds which can support LPI signalling 158 * @lpi_timer_default: Default EEE LPI timer setting. 159 * @eee_enabled_default: If set, EEE will be enabled by phylink at creation time 160 * @wol_phy_legacy: Use Wake-on-Lan with PHY even if phy_can_wakeup() is false 161 * @wol_phy_speed_ctrl: Use phy speed control on suspend/resume 162 * @wol_mac_support: Bitmask of MAC supported %WAKE_* options 163 */ 164struct phylink_config { 165 struct device *dev; 166 enum phylink_op_type type; 167 bool poll_fixed_state; 168 bool mac_managed_pm; 169 bool mac_requires_rxc; 170 bool default_an_inband; 171 bool eee_rx_clk_stop_enable; 172 void (*get_fixed_state)(struct phylink_config *config, 173 struct phylink_link_state *state); 174 DECLARE_PHY_INTERFACE_MASK(supported_interfaces); 175 DECLARE_PHY_INTERFACE_MASK(lpi_interfaces); 176 unsigned long mac_capabilities; 177 unsigned long lpi_capabilities; 178 u32 lpi_timer_default; 179 bool eee_enabled_default; 180 181 /* Wake-on-Lan support */ 182 bool wol_phy_legacy; 183 bool wol_phy_speed_ctrl; 184 u32 wol_mac_support; 185}; 186 187void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed); 188 189/** 190 * struct phylink_mac_ops - MAC operations structure. 191 * @mac_get_caps: Get MAC capabilities for interface mode. 192 * @mac_select_pcs: Select a PCS for the interface mode. 193 * @mac_prepare: prepare for a major reconfiguration of the interface. 194 * @mac_config: configure the MAC for the selected mode and state. 195 * @mac_finish: finish a major reconfiguration of the interface. 196 * @mac_link_down: take the link down. 197 * @mac_link_up: allow the link to come up. 198 * @mac_disable_tx_lpi: disable LPI. 199 * @mac_enable_tx_lpi: enable and configure LPI. 200 * @mac_wol_set: configure Wake-on-Lan settings at the MAC. 201 * 202 * The individual methods are described more fully below. 203 */ 204struct phylink_mac_ops { 205 unsigned long (*mac_get_caps)(struct phylink_config *config, 206 phy_interface_t interface); 207 struct phylink_pcs *(*mac_select_pcs)(struct phylink_config *config, 208 phy_interface_t interface); 209 int (*mac_prepare)(struct phylink_config *config, unsigned int mode, 210 phy_interface_t iface); 211 void (*mac_config)(struct phylink_config *config, unsigned int mode, 212 const struct phylink_link_state *state); 213 int (*mac_finish)(struct phylink_config *config, unsigned int mode, 214 phy_interface_t iface); 215 void (*mac_link_down)(struct phylink_config *config, unsigned int mode, 216 phy_interface_t interface); 217 void (*mac_link_up)(struct phylink_config *config, 218 struct phy_device *phy, unsigned int mode, 219 phy_interface_t interface, int speed, int duplex, 220 bool tx_pause, bool rx_pause); 221 void (*mac_disable_tx_lpi)(struct phylink_config *config); 222 int (*mac_enable_tx_lpi)(struct phylink_config *config, u32 timer, 223 bool tx_clk_stop); 224 225 int (*mac_wol_set)(struct phylink_config *config, u32 wolopts, 226 const u8 *sopass); 227}; 228 229#if 0 /* For kernel-doc purposes only. */ 230/** 231 * mac_get_caps: Get MAC capabilities for interface mode. 232 * @config: a pointer to a &struct phylink_config. 233 * @interface: PHY interface mode. 234 * 235 * Optional method. When not provided, config->mac_capabilities will be used. 236 * When implemented, this returns the MAC capabilities for the specified 237 * interface mode where there is some special handling required by the MAC 238 * driver (e.g. not supporting half-duplex in certain interface modes.) 239 */ 240unsigned long mac_get_caps(struct phylink_config *config, 241 phy_interface_t interface); 242/** 243 * mac_select_pcs: Select a PCS for the interface mode. 244 * @config: a pointer to a &struct phylink_config. 245 * @interface: PHY interface mode for PCS 246 * 247 * Return the &struct phylink_pcs for the specified interface mode, or 248 * NULL if none is required, or an error pointer on error. 249 * 250 * This must not modify any state. It is used to query which PCS should 251 * be used. Phylink will use this during validation to ensure that the 252 * configuration is valid, and when setting a configuration to internally 253 * set the PCS that will be used. 254 */ 255struct phylink_pcs *mac_select_pcs(struct phylink_config *config, 256 phy_interface_t interface); 257 258/** 259 * mac_prepare() - prepare to change the PHY interface mode 260 * @config: a pointer to a &struct phylink_config. 261 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND. 262 * @iface: interface mode to switch to 263 * 264 * phylink will call this method at the beginning of a full initialisation 265 * of the link, which includes changing the interface mode or at initial 266 * startup time. It may be called for the current mode. The MAC driver 267 * should perform whatever actions are required, e.g. disabling the 268 * Serdes PHY. 269 * 270 * This will be the first call in the sequence: 271 * - mac_prepare() 272 * - mac_config() 273 * - pcs_config() 274 * - possible pcs_an_restart() 275 * - mac_finish() 276 * 277 * Returns zero on success, or negative errno on failure which will be 278 * reported to the kernel log. 279 */ 280int mac_prepare(struct phylink_config *config, unsigned int mode, 281 phy_interface_t iface); 282 283/** 284 * mac_config() - configure the MAC for the selected mode and state 285 * @config: a pointer to a &struct phylink_config. 286 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND. 287 * @state: a pointer to a &struct phylink_link_state. 288 * 289 * Note - not all members of @state are valid. In particular, 290 * @state->lp_advertising, @state->link, @state->an_complete are never 291 * guaranteed to be correct, and so any mac_config() implementation must 292 * never reference these fields. 293 * 294 * This will only be called to reconfigure the MAC for a "major" change in 295 * e.g. interface mode. It will not be called for changes in speed, duplex 296 * or pause modes or to change the in-band advertisement. 297 * 298 * In all negotiation modes, as defined by @mode, @state->pause indicates the 299 * pause settings which should be applied as follows. If %MLO_PAUSE_AN is not 300 * set, %MLO_PAUSE_TX and %MLO_PAUSE_RX indicate whether the MAC should send 301 * pause frames and/or act on received pause frames respectively. Otherwise, 302 * the results of in-band negotiation/status from the MAC PCS should be used 303 * to control the MAC pause mode settings. 304 * 305 * The action performed depends on the currently selected mode: 306 * 307 * %MLO_AN_FIXED, %MLO_AN_PHY: 308 * Configure for non-inband negotiation mode, where the link settings 309 * are completely communicated via mac_link_up(). The physical link 310 * protocol from the MAC is specified by @state->interface. 311 * 312 * @state->advertising may be used, but is not required. 313 * 314 * Older drivers (prior to the mac_link_up() change) may use @state->speed, 315 * @state->duplex and @state->pause to configure the MAC, but this is 316 * deprecated; such drivers should be converted to use mac_link_up(). 317 * 318 * Other members of @state must be ignored. 319 * 320 * Valid state members: interface, advertising. 321 * Deprecated state members: speed, duplex, pause. 322 * 323 * %MLO_AN_INBAND: 324 * place the link in an inband negotiation mode (such as 802.3z 325 * 1000base-X or Cisco SGMII mode depending on the @state->interface 326 * mode). In both cases, link state management (whether the link 327 * is up or not) is performed by the MAC, and reported via the 328 * pcs_get_state() callback. Changes in link state must be made 329 * by calling phylink_mac_change(). 330 * 331 * Interface mode specific details are mentioned below. 332 * 333 * If in 802.3z mode, the link speed is fixed, dependent on the 334 * @state->interface. Duplex and pause modes are negotiated via 335 * the in-band configuration word. Advertised pause modes are set 336 * according to @state->advertising. Beware of MACs which only 337 * support full duplex at gigabit and higher speeds. 338 * 339 * If in Cisco SGMII mode, the link speed and duplex mode are passed 340 * in the serial bitstream 16-bit configuration word, and the MAC 341 * should be configured to read these bits and acknowledge the 342 * configuration word. Nothing is advertised by the MAC. The MAC is 343 * responsible for reading the configuration word and configuring 344 * itself accordingly. 345 * 346 * Valid state members: interface, pause, advertising. 347 * 348 * Implementations are expected to update the MAC to reflect the 349 * requested settings - i.o.w., if nothing has changed between two 350 * calls, no action is expected. If only flow control settings have 351 * changed, flow control should be updated *without* taking the link 352 * down. This "update" behaviour is critical to avoid bouncing the 353 * link up status. 354 */ 355void mac_config(struct phylink_config *config, unsigned int mode, 356 const struct phylink_link_state *state); 357 358/** 359 * mac_finish() - finish a to change the PHY interface mode 360 * @config: a pointer to a &struct phylink_config. 361 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND. 362 * @iface: interface mode to switch to 363 * 364 * phylink will call this if it called mac_prepare() to allow the MAC to 365 * complete any necessary steps after the MAC and PCS have been configured 366 * for the @mode and @iface. E.g. a MAC driver may wish to re-enable the 367 * Serdes PHY here if it was previously disabled by mac_prepare(). 368 * 369 * Returns zero on success, or negative errno on failure which will be 370 * reported to the kernel log. 371 */ 372int mac_finish(struct phylink_config *config, unsigned int mode, 373 phy_interface_t iface); 374 375/** 376 * mac_link_down() - notification that the link has gone down 377 * @config: a pointer to a &struct phylink_config. 378 * @mode: link autonegotiation mode 379 * @interface: link &typedef phy_interface_t mode 380 * 381 * Notifies the MAC that the link has gone down. This will not be called 382 * unless mac_link_up() has been previously called. 383 * 384 * The MAC should stop processing packets for transmission and reception. 385 * phylink will have called netif_carrier_off() to notify the networking 386 * stack that the link has gone down, so MAC drivers should not make this 387 * call. 388 * 389 * If @mode is %MLO_AN_INBAND, then this function must not prevent the 390 * link coming up. 391 */ 392void mac_link_down(struct phylink_config *config, unsigned int mode, 393 phy_interface_t interface); 394 395/** 396 * mac_link_up() - notification that the link has come up 397 * @config: a pointer to a &struct phylink_config. 398 * @phy: any attached phy (deprecated - please use LPI interfaces) 399 * @mode: link autonegotiation mode 400 * @interface: link &typedef phy_interface_t mode 401 * @speed: link speed 402 * @duplex: link duplex 403 * @tx_pause: link transmit pause enablement status 404 * @rx_pause: link receive pause enablement status 405 * 406 * Notifies the MAC that the link has come up, and the parameters of the 407 * link as seen from the MACs point of view. If mac_link_up() has been 408 * called previously, there will be an intervening call to mac_link_down() 409 * before this method will be subsequently called. 410 * 411 * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link 412 * settings, and should be used to configure the MAC block appropriately 413 * where these settings are not automatically conveyed from the PCS block, 414 * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode)) 415 * is disabled. 416 * 417 * Note that when 802.3z in-band negotiation is in use, it is possible 418 * that the user wishes to override the pause settings, and this should 419 * be allowed when considering the implementation of this method. 420 * 421 * Once configured, the MAC may begin to process packets for transmission 422 * and reception. 423 * 424 * Interface type selection must be done in mac_config(). 425 */ 426void mac_link_up(struct phylink_config *config, struct phy_device *phy, 427 unsigned int mode, phy_interface_t interface, 428 int speed, int duplex, bool tx_pause, bool rx_pause); 429 430/** 431 * mac_disable_tx_lpi() - disable LPI generation at the MAC 432 * @config: a pointer to a &struct phylink_config. 433 * 434 * Disable generation of LPI at the MAC, effectively preventing the MAC 435 * from indicating that it is idle. 436 */ 437void mac_disable_tx_lpi(struct phylink_config *config); 438 439/** 440 * mac_enable_tx_lpi() - configure and enable LPI generation at the MAC 441 * @config: a pointer to a &struct phylink_config. 442 * @timer: LPI timeout in microseconds. 443 * @tx_clk_stop: allow xMII transmit clock to be stopped during LPI 444 * 445 * Configure the LPI timeout accordingly. This will only be called when 446 * the link is already up, to cater for situations where the hardware 447 * needs to be programmed according to the link speed. 448 * 449 * Enable LPI generation at the MAC, and configure whether the xMII transmit 450 * clock may be stopped. 451 * 452 * Returns: 0 on success. Please consult with rmk before returning an error. 453 */ 454int mac_enable_tx_lpi(struct phylink_config *config, u32 timer, 455 bool tx_clk_stop); 456 457/** 458 * mac_wol_set() - configure the Wake-on-Lan parameters 459 * @config: a pointer to a &struct phylink_config. 460 * @wolopts: Bitmask of %WAKE_* flags for enabled Wake-On-Lan modes. 461 * @sopass: SecureOn(tm) password; meaningful only for %WAKE_MAGICSECURE 462 * 463 * Enable the specified Wake-on-Lan options at the MAC. Options that the 464 * PHY can handle will have been removed from @wolopts. 465 * 466 * The presence of this method enables phylink-managed WoL support. 467 * 468 * Returns: 0 on success. 469 */ 470int (*mac_wol_set)(struct phylink_config *config, u32 wolopts, 471 const u8 *sopass); 472#endif 473 474struct phylink_pcs_ops; 475 476/** 477 * struct phylink_pcs - PHYLINK PCS instance 478 * @supported_interfaces: describing which PHY_INTERFACE_MODE_xxx 479 * are supported by this PCS. 480 * @ops: a pointer to the &struct phylink_pcs_ops structure 481 * @phylink: pointer to &struct phylink_config 482 * @poll: poll the PCS for link changes 483 * @rxc_always_on: The MAC driver requires the reference clock 484 * to always be on. Standalone PCS drivers which 485 * do not have access to a PHY device can check 486 * this instead of PHY_F_RXC_ALWAYS_ON. 487 * 488 * This structure is designed to be embedded within the PCS private data, 489 * and will be passed between phylink and the PCS. 490 * 491 * The @phylink member is private to phylink and must not be touched by 492 * the PCS driver. 493 */ 494struct phylink_pcs { 495 DECLARE_PHY_INTERFACE_MASK(supported_interfaces); 496 const struct phylink_pcs_ops *ops; 497 struct phylink *phylink; 498 bool poll; 499 bool rxc_always_on; 500}; 501 502/** 503 * struct phylink_pcs_ops - MAC PCS operations structure. 504 * @pcs_validate: validate the link configuration. 505 * @pcs_inband_caps: query inband support for interface mode. 506 * @pcs_enable: enable the PCS. 507 * @pcs_disable: disable the PCS. 508 * @pcs_pre_config: pre-mac_config method (for errata) 509 * @pcs_post_config: post-mac_config method (for arrata) 510 * @pcs_get_state: read the current MAC PCS link state from the hardware. 511 * @pcs_config: configure the MAC PCS for the selected mode and state. 512 * @pcs_an_restart: restart 802.3z BaseX autonegotiation. 513 * @pcs_link_up: program the PCS for the resolved link configuration 514 * (where necessary). 515 * @pcs_disable_eee: optional notification to PCS that EEE has been disabled 516 * at the MAC. 517 * @pcs_enable_eee: optional notification to PCS that EEE will be enabled at 518 * the MAC. 519 * @pcs_pre_init: configure PCS components necessary for MAC hardware 520 * initialization e.g. RX clock for stmmac. 521 */ 522struct phylink_pcs_ops { 523 int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported, 524 const struct phylink_link_state *state); 525 unsigned int (*pcs_inband_caps)(struct phylink_pcs *pcs, 526 phy_interface_t interface); 527 int (*pcs_enable)(struct phylink_pcs *pcs); 528 void (*pcs_disable)(struct phylink_pcs *pcs); 529 void (*pcs_pre_config)(struct phylink_pcs *pcs, 530 phy_interface_t interface); 531 int (*pcs_post_config)(struct phylink_pcs *pcs, 532 phy_interface_t interface); 533 void (*pcs_get_state)(struct phylink_pcs *pcs, unsigned int neg_mode, 534 struct phylink_link_state *state); 535 int (*pcs_config)(struct phylink_pcs *pcs, unsigned int neg_mode, 536 phy_interface_t interface, 537 const unsigned long *advertising, 538 bool permit_pause_to_mac); 539 void (*pcs_an_restart)(struct phylink_pcs *pcs); 540 void (*pcs_link_up)(struct phylink_pcs *pcs, unsigned int neg_mode, 541 phy_interface_t interface, int speed, int duplex); 542 void (*pcs_disable_eee)(struct phylink_pcs *pcs); 543 void (*pcs_enable_eee)(struct phylink_pcs *pcs); 544 int (*pcs_pre_init)(struct phylink_pcs *pcs); 545}; 546 547#if 0 /* For kernel-doc purposes only. */ 548/** 549 * pcs_validate() - validate the link configuration. 550 * @pcs: a pointer to a &struct phylink_pcs. 551 * @supported: ethtool bitmask for supported link modes. 552 * @state: a const pointer to a &struct phylink_link_state. 553 * 554 * Validate the interface mode, and advertising's autoneg bit, removing any 555 * media ethtool link modes that would not be supportable from the supported 556 * mask. Phylink will propagate the changes to the advertising mask. See the 557 * &struct phylink_mac_ops validate() method. 558 * 559 * Returns -EINVAL if the interface mode/autoneg mode is not supported. 560 * Returns non-zero positive if the link state can be supported. 561 */ 562int pcs_validate(struct phylink_pcs *pcs, unsigned long *supported, 563 const struct phylink_link_state *state); 564 565/** 566 * pcs_inband_caps - query PCS in-band capabilities for interface mode. 567 * @pcs: a pointer to a &struct phylink_pcs. 568 * @interface: interface mode to be queried 569 * 570 * Returns zero if it is unknown what in-band signalling is supported by the 571 * PHY (e.g. because the PHY driver doesn't implement the method.) Otherwise, 572 * returns a bit mask of the LINK_INBAND_* values from 573 * &enum link_inband_signalling to describe which inband modes are supported 574 * for this interface mode. 575 */ 576unsigned int pcs_inband_caps(struct phylink_pcs *pcs, 577 phy_interface_t interface); 578 579/** 580 * pcs_enable() - enable the PCS. 581 * @pcs: a pointer to a &struct phylink_pcs. 582 */ 583int pcs_enable(struct phylink_pcs *pcs); 584 585/** 586 * pcs_disable() - disable the PCS. 587 * @pcs: a pointer to a &struct phylink_pcs. 588 */ 589void pcs_disable(struct phylink_pcs *pcs); 590 591/** 592 * pcs_get_state() - Read the current inband link state from the hardware 593 * @pcs: a pointer to a &struct phylink_pcs. 594 * @neg_mode: link negotiation mode (PHYLINK_PCS_NEG_xxx) 595 * @state: a pointer to a &struct phylink_link_state. 596 * 597 * Read the current inband link state from the MAC PCS, reporting the 598 * current speed in @state->speed, duplex mode in @state->duplex, pause 599 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits, 600 * negotiation completion state in @state->an_complete, and link up state 601 * in @state->link. If possible, @state->lp_advertising should also be 602 * populated. 603 * 604 * Note that the @neg_mode parameter is always the PHYLINK_PCS_NEG_xxx 605 * state, not MLO_AN_xxx. 606 */ 607void pcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode, 608 struct phylink_link_state *state); 609 610/** 611 * pcs_config() - Configure the PCS mode and advertisement 612 * @pcs: a pointer to a &struct phylink_pcs. 613 * @neg_mode: link negotiation mode (see below) 614 * @interface: interface mode to be used 615 * @advertising: adertisement ethtool link mode mask 616 * @permit_pause_to_mac: permit forwarding pause resolution to MAC 617 * 618 * Configure the PCS for the operating mode, the interface mode, and set 619 * the advertisement mask. @permit_pause_to_mac indicates whether the 620 * hardware may forward the pause mode resolution to the MAC. 621 * 622 * When operating in %MLO_AN_INBAND, inband should always be enabled, 623 * otherwise inband should be disabled. 624 * 625 * For SGMII, there is no advertisement from the MAC side, the PCS should 626 * be programmed to acknowledge the inband word from the PHY. 627 * 628 * For 1000BASE-X, the advertisement should be programmed into the PCS. 629 * 630 * For most 10GBASE-R, there is no advertisement. 631 * 632 * The %neg_mode argument should be tested via the phylink_mode_*() family of 633 * functions, or for PCS that set pcs->neg_mode true, should be tested 634 * against the PHYLINK_PCS_NEG_* definitions. 635 * 636 * pcs_config() will be called when configuration of the PCS is required 637 * or when the advertisement is possibly updated. It must not unnecessarily 638 * disrupt an established link. 639 * 640 * When an autonegotiation restart is required for 802.3z modes, .pcs_config() 641 * should return a positive non-zero integer (e.g. 1) to indicate to phylink 642 * to call the pcs_an_restart() method. 643 */ 644int pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, 645 phy_interface_t interface, const unsigned long *advertising, 646 bool permit_pause_to_mac); 647 648/** 649 * pcs_an_restart() - restart 802.3z BaseX autonegotiation 650 * @pcs: a pointer to a &struct phylink_pcs. 651 * 652 * When PCS ops are present, this overrides mac_an_restart() in &struct 653 * phylink_mac_ops. 654 */ 655void pcs_an_restart(struct phylink_pcs *pcs); 656 657/** 658 * pcs_link_up() - program the PCS for the resolved link configuration 659 * @pcs: a pointer to a &struct phylink_pcs. 660 * @neg_mode: link negotiation mode (see below) 661 * @interface: link &typedef phy_interface_t mode 662 * @speed: link speed 663 * @duplex: link duplex 664 * 665 * This call will be made just before mac_link_up() to inform the PCS of 666 * the resolved link parameters. For example, a PCS operating in SGMII 667 * mode without in-band AN needs to be manually configured for the link 668 * and duplex setting. Otherwise, this should be a no-op. 669 * 670 * The %mode argument should be tested via the phylink_mode_*() family of 671 * functions, or for PCS that set pcs->neg_mode true, should be tested 672 * against the PHYLINK_PCS_NEG_* definitions. 673 */ 674void pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode, 675 phy_interface_t interface, int speed, int duplex); 676 677/** 678 * pcs_disable_eee() - Disable EEE at the PCS 679 * @pcs: a pointer to a &struct phylink_pcs 680 * 681 * Optional method informing the PCS that EEE has been disabled at the MAC. 682 */ 683void pcs_disable_eee(struct phylink_pcs *pcs); 684 685/** 686 * pcs_enable_eee() - Enable EEE at the PCS 687 * @pcs: a pointer to a &struct phylink_pcs 688 * 689 * Optional method informing the PCS that EEE is about to be enabled at the MAC. 690 */ 691void pcs_enable_eee(struct phylink_pcs *pcs); 692 693/** 694 * pcs_pre_init() - Configure PCS components necessary for MAC initialization 695 * @pcs: a pointer to a &struct phylink_pcs. 696 * 697 * This function can be called by MAC drivers through the 698 * phylink_pcs_pre_init() wrapper, before their hardware is initialized. It 699 * should not be called after the link is brought up, as reconfiguring the PCS 700 * at this point could break the link. 701 * 702 * Some MAC devices require specific hardware initialization to be performed by 703 * their associated PCS device before they can properly initialize their own 704 * hardware. An example of this is the initialization of stmmac controllers, 705 * which requires an active REF_CLK signal to be provided by the PHY/PCS. 706 * 707 * By calling phylink_pcs_pre_init(), MAC drivers can ensure that the PCS is 708 * setup in a way that allows for successful hardware initialization. 709 * 710 * The specific configuration performed by pcs_pre_init() is dependent on the 711 * model of PCS and the requirements of the MAC device attached to it. PCS 712 * driver authors should consider whether their target device is to be used in 713 * conjunction with a MAC device whose driver calls phylink_pcs_pre_init(). MAC 714 * driver authors should document their requirements for the PCS 715 * pre-initialization. 716 * 717 */ 718int pcs_pre_init(struct phylink_pcs *pcs); 719 720#endif 721 722struct phylink *phylink_create(struct phylink_config *, 723 const struct fwnode_handle *, 724 phy_interface_t, 725 const struct phylink_mac_ops *); 726void phylink_destroy(struct phylink *); 727bool phylink_expects_phy(struct phylink *pl); 728 729int phylink_connect_phy(struct phylink *, struct phy_device *); 730int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags); 731int phylink_fwnode_phy_connect(struct phylink *pl, 732 const struct fwnode_handle *fwnode, 733 u32 flags); 734void phylink_disconnect_phy(struct phylink *); 735int phylink_set_fixed_link(struct phylink *, 736 const struct phylink_link_state *); 737 738void phylink_mac_change(struct phylink *, bool up); 739void phylink_pcs_change(struct phylink_pcs *, bool up); 740 741int phylink_pcs_pre_init(struct phylink *pl, struct phylink_pcs *pcs); 742 743void phylink_start(struct phylink *); 744void phylink_stop(struct phylink *); 745 746void phylink_rx_clk_stop_block(struct phylink *); 747void phylink_rx_clk_stop_unblock(struct phylink *); 748 749void phylink_suspend(struct phylink *pl, bool mac_wol); 750void phylink_prepare_resume(struct phylink *pl); 751void phylink_resume(struct phylink *pl); 752 753void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *); 754int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *); 755 756int phylink_ethtool_ksettings_get(struct phylink *, 757 struct ethtool_link_ksettings *); 758int phylink_ethtool_ksettings_set(struct phylink *, 759 const struct ethtool_link_ksettings *); 760int phylink_ethtool_nway_reset(struct phylink *); 761void phylink_ethtool_get_pauseparam(struct phylink *, 762 struct ethtool_pauseparam *); 763int phylink_ethtool_set_pauseparam(struct phylink *, 764 struct ethtool_pauseparam *); 765int phylink_get_eee_err(struct phylink *); 766int phylink_ethtool_get_eee(struct phylink *link, struct ethtool_keee *eee); 767int phylink_ethtool_set_eee(struct phylink *link, struct ethtool_keee *eee); 768int phylink_mii_ioctl(struct phylink *, struct ifreq *, int); 769int phylink_speed_down(struct phylink *pl, bool sync); 770int phylink_speed_up(struct phylink *pl); 771 772#define phylink_zero(bm) \ 773 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS) 774#define __phylink_do_bit(op, bm, mode) \ 775 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm) 776 777#define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode) 778#define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode) 779#define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode) 780 781void phylink_set_port_modes(unsigned long *bits); 782 783/** 784 * phylink_get_link_timer_ns - return the PCS link timer value 785 * @interface: link &typedef phy_interface_t mode 786 * 787 * Return the PCS link timer setting in nanoseconds for the PHY @interface 788 * mode, or -EINVAL if not appropriate. 789 */ 790static inline int phylink_get_link_timer_ns(phy_interface_t interface) 791{ 792 switch (interface) { 793 case PHY_INTERFACE_MODE_SGMII: 794 case PHY_INTERFACE_MODE_QSGMII: 795 case PHY_INTERFACE_MODE_USXGMII: 796 case PHY_INTERFACE_MODE_10G_QXGMII: 797 return 1600000; 798 799 case PHY_INTERFACE_MODE_1000BASEX: 800 case PHY_INTERFACE_MODE_2500BASEX: 801 return 10000000; 802 803 default: 804 return -EINVAL; 805 } 806} 807 808/** 809 * phylink_mac_implements_lpi() - determine if MAC implements LPI ops 810 * @ops: phylink_mac_ops structure 811 * 812 * Returns true if the phylink MAC operations structure indicates that the 813 * LPI operations have been implemented, false otherwise. 814 */ 815static inline bool phylink_mac_implements_lpi(const struct phylink_mac_ops *ops) 816{ 817 return ops && ops->mac_disable_tx_lpi && ops->mac_enable_tx_lpi; 818} 819 820void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state, 821 unsigned int neg_mode, u16 bmsr, u16 lpa); 822void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs, 823 unsigned int neg_mode, 824 struct phylink_link_state *state); 825int phylink_mii_c22_pcs_encode_advertisement(phy_interface_t interface, 826 const unsigned long *advertising); 827int phylink_mii_c22_pcs_config(struct mdio_device *pcs, 828 phy_interface_t interface, 829 const unsigned long *advertising, 830 unsigned int neg_mode); 831void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs); 832 833void phylink_resolve_c73(struct phylink_link_state *state); 834 835void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs, 836 struct phylink_link_state *state); 837 838void phylink_decode_usxgmii_word(struct phylink_link_state *state, 839 uint16_t lpa); 840 841void phylink_replay_link_begin(struct phylink *pl); 842 843void phylink_replay_link_end(struct phylink *pl); 844 845#endif