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