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