Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 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; |
Russell King | 8fa7b9b | 2017-12-01 10:25:09 +0000 | [diff] [blame] | 10 | struct fwnode_handle; |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 11 | struct net_device; |
| 12 | |
| 13 | enum { |
| 14 | MLO_PAUSE_NONE, |
Russell King | 4e5aeb4 | 2020-02-15 15:49:53 +0000 | [diff] [blame] | 15 | MLO_PAUSE_RX = BIT(0), |
| 16 | MLO_PAUSE_TX = BIT(1), |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 17 | MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX, |
Russell King | 4e5aeb4 | 2020-02-15 15:49:53 +0000 | [diff] [blame] | 18 | MLO_PAUSE_AN = BIT(2), |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 19 | |
| 20 | MLO_AN_PHY = 0, /* Conventional PHY */ |
| 21 | MLO_AN_FIXED, /* Fixed-link mode */ |
Russell King | 86a362c | 2017-12-01 10:24:26 +0000 | [diff] [blame] | 22 | MLO_AN_INBAND, /* In-band protocol */ |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | static inline bool phylink_autoneg_inband(unsigned int mode) |
| 26 | { |
Russell King | 86a362c | 2017-12-01 10:24:26 +0000 | [diff] [blame] | 27 | return mode == MLO_AN_INBAND; |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 28 | } |
| 29 | |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 30 | /** |
| 31 | * struct phylink_link_state - link state structure |
| 32 | * @advertising: ethtool bitmask containing advertised link modes |
| 33 | * @lp_advertising: ethtool bitmask containing link partner advertised link |
| 34 | * modes |
| 35 | * @interface: link &typedef phy_interface_t mode |
| 36 | * @speed: link speed, one of the SPEED_* constants. |
| 37 | * @duplex: link duplex mode, one of DUPLEX_* constants. |
| 38 | * @pause: link pause state, described by MLO_PAUSE_* constants. |
| 39 | * @link: true if the link is up. |
| 40 | * @an_enabled: true if autonegotiation is enabled/desired. |
| 41 | * @an_complete: true if autonegotiation has completed. |
| 42 | */ |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 43 | struct phylink_link_state { |
| 44 | __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising); |
| 45 | __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising); |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 46 | phy_interface_t interface; |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 47 | int speed; |
| 48 | int duplex; |
| 49 | int pause; |
| 50 | unsigned int link:1; |
| 51 | unsigned int an_enabled:1; |
| 52 | unsigned int an_complete:1; |
| 53 | }; |
| 54 | |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 55 | enum phylink_op_type { |
| 56 | PHYLINK_NETDEV = 0, |
Ioana Ciornei | 43de619 | 2019-05-28 20:38:13 +0300 | [diff] [blame] | 57 | PHYLINK_DEV, |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /** |
| 61 | * struct phylink_config - PHYLINK configuration structure |
| 62 | * @dev: a pointer to a struct device associated with the MAC |
| 63 | * @type: operation type of PHYLINK instance |
Vladimir Oltean | 1511ed0 | 2020-01-06 03:34:11 +0200 | [diff] [blame] | 64 | * @pcs_poll: MAC PCS cannot provide link change interrupt |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 65 | */ |
| 66 | struct phylink_config { |
| 67 | struct device *dev; |
| 68 | enum phylink_op_type type; |
Vladimir Oltean | 1511ed0 | 2020-01-06 03:34:11 +0200 | [diff] [blame] | 69 | bool pcs_poll; |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 70 | }; |
| 71 | |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 72 | /** |
| 73 | * struct phylink_mac_ops - MAC operations structure. |
| 74 | * @validate: Validate and update the link configuration. |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 75 | * @mac_pcs_get_state: Read the current link state from the hardware. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 76 | * @mac_config: configure the MAC for the selected mode and state. |
| 77 | * @mac_an_restart: restart 802.3z BaseX autonegotiation. |
| 78 | * @mac_link_down: take the link down. |
| 79 | * @mac_link_up: allow the link to come up. |
| 80 | * |
| 81 | * The individual methods are described more fully below. |
| 82 | */ |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 83 | struct phylink_mac_ops { |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 84 | void (*validate)(struct phylink_config *config, |
| 85 | unsigned long *supported, |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 86 | struct phylink_link_state *state); |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 87 | void (*mac_pcs_get_state)(struct phylink_config *config, |
| 88 | struct phylink_link_state *state); |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 89 | void (*mac_config)(struct phylink_config *config, unsigned int mode, |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 90 | const struct phylink_link_state *state); |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 91 | void (*mac_an_restart)(struct phylink_config *config); |
| 92 | void (*mac_link_down)(struct phylink_config *config, unsigned int mode, |
Florian Fainelli | c6ab300 | 2018-03-28 15:44:15 -0700 | [diff] [blame] | 93 | phy_interface_t interface); |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 94 | void (*mac_link_up)(struct phylink_config *config, |
| 95 | struct phy_device *phy, unsigned int mode, |
| 96 | phy_interface_t interface, int speed, int duplex, |
| 97 | bool tx_pause, bool rx_pause); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 100 | #if 0 /* For kernel-doc purposes only. */ |
| 101 | /** |
| 102 | * validate - Validate and update the link configuration |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 103 | * @config: a pointer to a &struct phylink_config. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 104 | * @supported: ethtool bitmask for supported link modes. |
| 105 | * @state: a pointer to a &struct phylink_link_state. |
| 106 | * |
| 107 | * Clear bits in the @supported and @state->advertising masks that |
| 108 | * are not supportable by the MAC. |
| 109 | * |
| 110 | * Note that the PHY may be able to transform from one connection |
| 111 | * technology to another, so, eg, don't clear 1000BaseX just |
| 112 | * because the MAC is unable to BaseX mode. This is more about |
Russell King | 32e454e | 2019-06-25 10:44:33 +0100 | [diff] [blame] | 113 | * clearing unsupported speeds and duplex settings. The port modes |
| 114 | * should not be cleared; phylink_set_port_modes() will help with this. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 115 | * |
| 116 | * If the @state->interface mode is %PHY_INTERFACE_MODE_1000BASEX |
| 117 | * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode |
| 118 | * based on @state->advertising and/or @state->speed and update |
Russell King | 32e454e | 2019-06-25 10:44:33 +0100 | [diff] [blame] | 119 | * @state->interface accordingly. See phylink_helper_basex_speed(). |
| 120 | * |
| 121 | * When @state->interface is %PHY_INTERFACE_MODE_NA, phylink expects the |
| 122 | * MAC driver to return all supported link modes. |
| 123 | * |
| 124 | * If the @state->interface mode is not supported, then the @supported |
| 125 | * mask must be cleared. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 126 | */ |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 127 | void validate(struct phylink_config *config, unsigned long *supported, |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 128 | struct phylink_link_state *state); |
| 129 | |
| 130 | /** |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 131 | * mac_pcs_get_state() - Read the current inband link state from the hardware |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 132 | * @config: a pointer to a &struct phylink_config. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 133 | * @state: a pointer to a &struct phylink_link_state. |
| 134 | * |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 135 | * Read the current inband link state from the MAC PCS, reporting the |
| 136 | * current speed in @state->speed, duplex mode in @state->duplex, pause |
| 137 | * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits, |
| 138 | * negotiation completion state in @state->an_complete, and link up state |
| 139 | * in @state->link. If possible, @state->lp_advertising should also be |
| 140 | * populated. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 141 | */ |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 142 | void mac_pcs_get_state(struct phylink_config *config, |
| 143 | struct phylink_link_state *state); |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * mac_config() - configure the MAC for the selected mode and state |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 147 | * @config: a pointer to a &struct phylink_config. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 148 | * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND. |
| 149 | * @state: a pointer to a &struct phylink_link_state. |
| 150 | * |
Russell King - ARM Linux admin | 4add7009 | 2019-06-14 11:37:49 +0100 | [diff] [blame] | 151 | * Note - not all members of @state are valid. In particular, |
| 152 | * @state->lp_advertising, @state->link, @state->an_complete are never |
| 153 | * guaranteed to be correct, and so any mac_config() implementation must |
| 154 | * never reference these fields. |
| 155 | * |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 156 | * (this requires a rewrite - please refer to mac_link_up() for situations |
| 157 | * where the PCS and MAC are not tightly integrated.) |
| 158 | * |
Russell King | b70486f | 2020-02-15 15:50:09 +0000 | [diff] [blame] | 159 | * In all negotiation modes, as defined by @mode, @state->pause indicates the |
| 160 | * pause settings which should be applied as follows. If %MLO_PAUSE_AN is not |
| 161 | * set, %MLO_PAUSE_TX and %MLO_PAUSE_RX indicate whether the MAC should send |
| 162 | * pause frames and/or act on received pause frames respectively. Otherwise, |
| 163 | * the results of in-band negotiation/status from the MAC PCS should be used |
| 164 | * to control the MAC pause mode settings. |
| 165 | * |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 166 | * The action performed depends on the currently selected mode: |
| 167 | * |
| 168 | * %MLO_AN_FIXED, %MLO_AN_PHY: |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 169 | * Configure for non-inband negotiation mode, where the link settings |
| 170 | * are completely communicated via mac_link_up(). The physical link |
| 171 | * protocol from the MAC is specified by @state->interface. |
Russell King - ARM Linux admin | 4add7009 | 2019-06-14 11:37:49 +0100 | [diff] [blame] | 172 | * |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 173 | * @state->advertising may be used, but is not required. |
| 174 | * |
| 175 | * Older drivers (prior to the mac_link_up() change) may use @state->speed, |
| 176 | * @state->duplex and @state->pause to configure the MAC, but this is |
| 177 | * deprecated; such drivers should be converted to use mac_link_up(). |
| 178 | * |
| 179 | * Other members of @state must be ignored. |
| 180 | * |
| 181 | * Valid state members: interface, advertising. |
| 182 | * Deprecated state members: speed, duplex, pause. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 183 | * |
| 184 | * %MLO_AN_INBAND: |
| 185 | * place the link in an inband negotiation mode (such as 802.3z |
| 186 | * 1000base-X or Cisco SGMII mode depending on the @state->interface |
| 187 | * mode). In both cases, link state management (whether the link |
| 188 | * is up or not) is performed by the MAC, and reported via the |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 189 | * mac_pcs_get_state() callback. Changes in link state must be made |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 190 | * by calling phylink_mac_change(). |
| 191 | * |
Russell King | b70486f | 2020-02-15 15:50:09 +0000 | [diff] [blame] | 192 | * Interface mode specific details are mentioned below. |
| 193 | * |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 194 | * If in 802.3z mode, the link speed is fixed, dependent on the |
Russell King | b70486f | 2020-02-15 15:50:09 +0000 | [diff] [blame] | 195 | * @state->interface. Duplex and pause modes are negotiated via |
| 196 | * the in-band configuration word. Advertised pause modes are set |
| 197 | * according to the @state->an_enabled and @state->advertising |
| 198 | * flags. Beware of MACs which only support full duplex at gigabit |
| 199 | * and higher speeds. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 200 | * |
| 201 | * If in Cisco SGMII mode, the link speed and duplex mode are passed |
| 202 | * in the serial bitstream 16-bit configuration word, and the MAC |
| 203 | * should be configured to read these bits and acknowledge the |
| 204 | * configuration word. Nothing is advertised by the MAC. The MAC is |
| 205 | * responsible for reading the configuration word and configuring |
| 206 | * itself accordingly. |
Russell King | 0e29ae030 | 2019-02-22 11:31:41 +0000 | [diff] [blame] | 207 | * |
Russell King - ARM Linux admin | 4add7009 | 2019-06-14 11:37:49 +0100 | [diff] [blame] | 208 | * Valid state members: interface, an_enabled, pause, advertising. |
| 209 | * |
Russell King | 0e29ae030 | 2019-02-22 11:31:41 +0000 | [diff] [blame] | 210 | * Implementations are expected to update the MAC to reflect the |
| 211 | * requested settings - i.o.w., if nothing has changed between two |
| 212 | * calls, no action is expected. If only flow control settings have |
| 213 | * changed, flow control should be updated *without* taking the link |
| 214 | * down. This "update" behaviour is critical to avoid bouncing the |
| 215 | * link up status. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 216 | */ |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 217 | void mac_config(struct phylink_config *config, unsigned int mode, |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 218 | const struct phylink_link_state *state); |
| 219 | |
| 220 | /** |
| 221 | * mac_an_restart() - restart 802.3z BaseX autonegotiation |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 222 | * @config: a pointer to a &struct phylink_config. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 223 | */ |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 224 | void mac_an_restart(struct phylink_config *config); |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 225 | |
| 226 | /** |
| 227 | * mac_link_down() - take the link down |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 228 | * @config: a pointer to a &struct phylink_config. |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 229 | * @mode: link autonegotiation mode |
Florian Fainelli | c6ab300 | 2018-03-28 15:44:15 -0700 | [diff] [blame] | 230 | * @interface: link &typedef phy_interface_t mode |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 231 | * |
| 232 | * If @mode is not an in-band negotiation mode (as defined by |
| 233 | * phylink_autoneg_inband()), force the link down and disable any |
Florian Fainelli | c6ab300 | 2018-03-28 15:44:15 -0700 | [diff] [blame] | 234 | * Energy Efficient Ethernet MAC configuration. Interface type |
| 235 | * selection must be done in mac_config(). |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 236 | */ |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 237 | void mac_link_down(struct phylink_config *config, unsigned int mode, |
Florian Fainelli | c6ab300 | 2018-03-28 15:44:15 -0700 | [diff] [blame] | 238 | phy_interface_t interface); |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 239 | |
| 240 | /** |
| 241 | * mac_link_up() - allow the link to come up |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 242 | * @config: a pointer to a &struct phylink_config. |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 243 | * @phy: any attached phy |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 244 | * @mode: link autonegotiation mode |
Florian Fainelli | c6ab300 | 2018-03-28 15:44:15 -0700 | [diff] [blame] | 245 | * @interface: link &typedef phy_interface_t mode |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 246 | * @speed: link speed |
| 247 | * @duplex: link duplex |
| 248 | * @tx_pause: link transmit pause enablement status |
| 249 | * @rx_pause: link receive pause enablement status |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 250 | * |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 251 | * Configure the MAC for an established link. |
| 252 | * |
| 253 | * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link |
| 254 | * settings, and should be used to configure the MAC block appropriately |
| 255 | * where these settings are not automatically conveyed from the PCS block, |
| 256 | * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode)) |
| 257 | * is disabled. |
| 258 | * |
| 259 | * Note that when 802.3z in-band negotiation is in use, it is possible |
| 260 | * that the user wishes to override the pause settings, and this should |
| 261 | * be allowed when considering the implementation of this method. |
| 262 | * |
| 263 | * If in-band negotiation mode is disabled, allow the link to come up. If |
| 264 | * @phy is non-%NULL, configure Energy Efficient Ethernet by calling |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 265 | * phy_init_eee() and perform appropriate MAC configuration for EEE. |
Florian Fainelli | c6ab300 | 2018-03-28 15:44:15 -0700 | [diff] [blame] | 266 | * Interface type selection must be done in mac_config(). |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 267 | */ |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 268 | void mac_link_up(struct phylink_config *config, struct phy_device *phy, |
| 269 | unsigned int mode, phy_interface_t interface, |
| 270 | int speed, int duplex, bool tx_pause, bool rx_pause); |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame] | 271 | #endif |
| 272 | |
Russell King | 4c0d6d3 | 2020-03-30 18:44:55 +0100 | [diff] [blame] | 273 | /** |
| 274 | * struct phylink_pcs_ops - MAC PCS operations structure. |
| 275 | * @pcs_get_state: read the current MAC PCS link state from the hardware. |
| 276 | * @pcs_config: configure the MAC PCS for the selected mode and state. |
| 277 | * @pcs_an_restart: restart 802.3z BaseX autonegotiation. |
| 278 | * @pcs_link_up: program the PCS for the resolved link configuration |
| 279 | * (where necessary). |
| 280 | */ |
| 281 | struct phylink_pcs_ops { |
| 282 | void (*pcs_get_state)(struct phylink_config *config, |
| 283 | struct phylink_link_state *state); |
| 284 | int (*pcs_config)(struct phylink_config *config, unsigned int mode, |
| 285 | phy_interface_t interface, |
| 286 | const unsigned long *advertising); |
| 287 | void (*pcs_an_restart)(struct phylink_config *config); |
| 288 | void (*pcs_link_up)(struct phylink_config *config, unsigned int mode, |
| 289 | phy_interface_t interface, int speed, int duplex); |
| 290 | }; |
| 291 | |
| 292 | #if 0 /* For kernel-doc purposes only. */ |
| 293 | /** |
| 294 | * pcs_get_state() - Read the current inband link state from the hardware |
| 295 | * @config: a pointer to a &struct phylink_config. |
| 296 | * @state: a pointer to a &struct phylink_link_state. |
| 297 | * |
| 298 | * Read the current inband link state from the MAC PCS, reporting the |
| 299 | * current speed in @state->speed, duplex mode in @state->duplex, pause |
| 300 | * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits, |
| 301 | * negotiation completion state in @state->an_complete, and link up state |
| 302 | * in @state->link. If possible, @state->lp_advertising should also be |
| 303 | * populated. |
| 304 | * |
| 305 | * When present, this overrides mac_pcs_get_state() in &struct |
| 306 | * phylink_mac_ops. |
| 307 | */ |
| 308 | void pcs_get_state(struct phylink_config *config, |
| 309 | struct phylink_link_state *state); |
| 310 | |
| 311 | /** |
| 312 | * pcs_config() - Configure the PCS mode and advertisement |
| 313 | * @config: a pointer to a &struct phylink_config. |
| 314 | * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND. |
| 315 | * @interface: interface mode to be used |
| 316 | * @advertising: adertisement ethtool link mode mask |
| 317 | * |
| 318 | * Configure the PCS for the operating mode, the interface mode, and set |
| 319 | * the advertisement mask. |
| 320 | * |
| 321 | * When operating in %MLO_AN_INBAND, inband should always be enabled, |
| 322 | * otherwise inband should be disabled. |
| 323 | * |
| 324 | * For SGMII, there is no advertisement from the MAC side, the PCS should |
| 325 | * be programmed to acknowledge the inband word from the PHY. |
| 326 | * |
| 327 | * For 1000BASE-X, the advertisement should be programmed into the PCS. |
| 328 | * |
| 329 | * For most 10GBASE-R, there is no advertisement. |
| 330 | */ |
| 331 | int (*pcs_config)(struct phylink_config *config, unsigned int mode, |
| 332 | phy_interface_t interface, const unsigned long *advertising); |
| 333 | |
| 334 | /** |
| 335 | * pcs_an_restart() - restart 802.3z BaseX autonegotiation |
| 336 | * @config: a pointer to a &struct phylink_config. |
| 337 | * |
| 338 | * When PCS ops are present, this overrides mac_an_restart() in &struct |
| 339 | * phylink_mac_ops. |
| 340 | */ |
| 341 | void (*pcs_an_restart)(struct phylink_config *config); |
| 342 | |
| 343 | /** |
| 344 | * pcs_link_up() - program the PCS for the resolved link configuration |
| 345 | * @config: a pointer to a &struct phylink_config. |
| 346 | * @mode: link autonegotiation mode |
| 347 | * @interface: link &typedef phy_interface_t mode |
| 348 | * @speed: link speed |
| 349 | * @duplex: link duplex |
| 350 | * |
| 351 | * This call will be made just before mac_link_up() to inform the PCS of |
| 352 | * the resolved link parameters. For example, a PCS operating in SGMII |
| 353 | * mode without in-band AN needs to be manually configured for the link |
| 354 | * and duplex setting. Otherwise, this should be a no-op. |
| 355 | */ |
| 356 | void (*pcs_link_up)(struct phylink_config *config, unsigned int mode, |
| 357 | phy_interface_t interface, int speed, int duplex); |
| 358 | #endif |
| 359 | |
Ioana Ciornei | 44cc27e | 2019-05-28 20:38:12 +0300 | [diff] [blame] | 360 | struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *, |
| 361 | phy_interface_t iface, |
Russell King | e7765d6 | 2020-03-30 18:44:50 +0100 | [diff] [blame] | 362 | const struct phylink_mac_ops *mac_ops); |
Russell King | 4c0d6d3 | 2020-03-30 18:44:55 +0100 | [diff] [blame] | 363 | void phylink_add_pcs(struct phylink *, const struct phylink_pcs_ops *ops); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 364 | void phylink_destroy(struct phylink *); |
| 365 | |
| 366 | int phylink_connect_phy(struct phylink *, struct phy_device *); |
Florian Fainelli | 0a62964 | 2017-12-12 16:00:25 -0800 | [diff] [blame] | 367 | int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 368 | void phylink_disconnect_phy(struct phylink *); |
Florian Fainelli | 1ac63e3 | 2017-12-12 16:00:28 -0800 | [diff] [blame] | 369 | int phylink_fixed_state_cb(struct phylink *, |
| 370 | void (*cb)(struct net_device *dev, |
| 371 | struct phylink_link_state *)); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 372 | |
| 373 | void phylink_mac_change(struct phylink *, bool up); |
| 374 | |
| 375 | void phylink_start(struct phylink *); |
| 376 | void phylink_stop(struct phylink *); |
| 377 | |
| 378 | void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *); |
| 379 | int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *); |
| 380 | |
| 381 | int phylink_ethtool_ksettings_get(struct phylink *, |
| 382 | struct ethtool_link_ksettings *); |
| 383 | int phylink_ethtool_ksettings_set(struct phylink *, |
| 384 | const struct ethtool_link_ksettings *); |
| 385 | int phylink_ethtool_nway_reset(struct phylink *); |
| 386 | void phylink_ethtool_get_pauseparam(struct phylink *, |
| 387 | struct ethtool_pauseparam *); |
| 388 | int phylink_ethtool_set_pauseparam(struct phylink *, |
| 389 | struct ethtool_pauseparam *); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 390 | int phylink_get_eee_err(struct phylink *); |
Russell King | 86e5813 | 2019-02-11 11:46:06 +0000 | [diff] [blame] | 391 | int phylink_init_eee(struct phylink *, bool); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 392 | int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *); |
| 393 | int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *); |
| 394 | int phylink_mii_ioctl(struct phylink *, struct ifreq *, int); |
| 395 | |
| 396 | #define phylink_zero(bm) \ |
| 397 | bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS) |
| 398 | #define __phylink_do_bit(op, bm, mode) \ |
| 399 | op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm) |
| 400 | |
| 401 | #define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode) |
| 402 | #define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode) |
| 403 | #define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode) |
| 404 | |
| 405 | void phylink_set_port_modes(unsigned long *bits); |
Russell King | 624c0f0 | 2018-08-09 15:38:38 +0200 | [diff] [blame] | 406 | void phylink_helper_basex_speed(struct phylink_link_state *state); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 407 | |
Russell King | 74db1c1 | 2020-03-17 14:52:36 +0000 | [diff] [blame] | 408 | void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs, |
| 409 | struct phylink_link_state *state); |
| 410 | int phylink_mii_c22_pcs_set_advertisement(struct mdio_device *pcs, |
Russell King | 0bd2740 | 2020-03-30 18:44:44 +0100 | [diff] [blame] | 411 | phy_interface_t interface, |
| 412 | const unsigned long *advertising); |
Russell King | 74db1c1 | 2020-03-17 14:52:36 +0000 | [diff] [blame] | 413 | void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs); |
| 414 | |
Russell King | b8679ef | 2020-03-17 14:52:41 +0000 | [diff] [blame] | 415 | void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs, |
| 416 | struct phylink_link_state *state); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 417 | #endif |