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; |
| 10 | struct net_device; |
| 11 | |
| 12 | enum { |
| 13 | MLO_PAUSE_NONE, |
| 14 | MLO_PAUSE_ASYM = BIT(0), |
| 15 | MLO_PAUSE_SYM = BIT(1), |
| 16 | MLO_PAUSE_RX = BIT(2), |
| 17 | MLO_PAUSE_TX = BIT(3), |
| 18 | MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX, |
| 19 | MLO_PAUSE_AN = BIT(4), |
| 20 | |
| 21 | MLO_AN_PHY = 0, /* Conventional PHY */ |
| 22 | MLO_AN_FIXED, /* Fixed-link mode */ |
Russell King | 86a362c | 2017-12-01 10:24:26 +0000 | [diff] [blame] | 23 | MLO_AN_INBAND, /* In-band protocol */ |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | static inline bool phylink_autoneg_inband(unsigned int mode) |
| 27 | { |
Russell King | 86a362c | 2017-12-01 10:24:26 +0000 | [diff] [blame] | 28 | return mode == MLO_AN_INBAND; |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 29 | } |
| 30 | |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame^] | 31 | /** |
| 32 | * struct phylink_link_state - link state structure |
| 33 | * @advertising: ethtool bitmask containing advertised link modes |
| 34 | * @lp_advertising: ethtool bitmask containing link partner advertised link |
| 35 | * modes |
| 36 | * @interface: link &typedef phy_interface_t mode |
| 37 | * @speed: link speed, one of the SPEED_* constants. |
| 38 | * @duplex: link duplex mode, one of DUPLEX_* constants. |
| 39 | * @pause: link pause state, described by MLO_PAUSE_* constants. |
| 40 | * @link: true if the link is up. |
| 41 | * @an_enabled: true if autonegotiation is enabled/desired. |
| 42 | * @an_complete: true if autonegotiation has completed. |
| 43 | */ |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 44 | struct phylink_link_state { |
| 45 | __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising); |
| 46 | __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising); |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame^] | 47 | phy_interface_t interface; |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 48 | int speed; |
| 49 | int duplex; |
| 50 | int pause; |
| 51 | unsigned int link:1; |
| 52 | unsigned int an_enabled:1; |
| 53 | unsigned int an_complete:1; |
| 54 | }; |
| 55 | |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame^] | 56 | /** |
| 57 | * struct phylink_mac_ops - MAC operations structure. |
| 58 | * @validate: Validate and update the link configuration. |
| 59 | * @mac_link_state: Read the current link state from the hardware. |
| 60 | * @mac_config: configure the MAC for the selected mode and state. |
| 61 | * @mac_an_restart: restart 802.3z BaseX autonegotiation. |
| 62 | * @mac_link_down: take the link down. |
| 63 | * @mac_link_up: allow the link to come up. |
| 64 | * |
| 65 | * The individual methods are described more fully below. |
| 66 | */ |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 67 | struct phylink_mac_ops { |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 68 | void (*validate)(struct net_device *ndev, unsigned long *supported, |
| 69 | struct phylink_link_state *state); |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame^] | 70 | int (*mac_link_state)(struct net_device *ndev, |
| 71 | struct phylink_link_state *state); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 72 | void (*mac_config)(struct net_device *ndev, unsigned int mode, |
| 73 | const struct phylink_link_state *state); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 74 | void (*mac_an_restart)(struct net_device *ndev); |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame^] | 75 | void (*mac_link_down)(struct net_device *ndev, unsigned int mode); |
| 76 | void (*mac_link_up)(struct net_device *ndev, unsigned int mode, |
| 77 | struct phy_device *phy); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 78 | }; |
| 79 | |
Russell King | 8796c89 | 2017-12-01 10:24:47 +0000 | [diff] [blame^] | 80 | #if 0 /* For kernel-doc purposes only. */ |
| 81 | /** |
| 82 | * validate - Validate and update the link configuration |
| 83 | * @ndev: a pointer to a &struct net_device for the MAC. |
| 84 | * @supported: ethtool bitmask for supported link modes. |
| 85 | * @state: a pointer to a &struct phylink_link_state. |
| 86 | * |
| 87 | * Clear bits in the @supported and @state->advertising masks that |
| 88 | * are not supportable by the MAC. |
| 89 | * |
| 90 | * Note that the PHY may be able to transform from one connection |
| 91 | * technology to another, so, eg, don't clear 1000BaseX just |
| 92 | * because the MAC is unable to BaseX mode. This is more about |
| 93 | * clearing unsupported speeds and duplex settings. |
| 94 | * |
| 95 | * If the @state->interface mode is %PHY_INTERFACE_MODE_1000BASEX |
| 96 | * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode |
| 97 | * based on @state->advertising and/or @state->speed and update |
| 98 | * @state->interface accordingly. |
| 99 | */ |
| 100 | void validate(struct net_device *ndev, unsigned long *supported, |
| 101 | struct phylink_link_state *state); |
| 102 | |
| 103 | /** |
| 104 | * mac_link_state() - Read the current link state from the hardware |
| 105 | * @ndev: a pointer to a &struct net_device for the MAC. |
| 106 | * @state: a pointer to a &struct phylink_link_state. |
| 107 | * |
| 108 | * Read the current link state from the MAC, reporting the current |
| 109 | * speed in @state->speed, duplex mode in @state->duplex, pause mode |
| 110 | * in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits, |
| 111 | * negotiation completion state in @state->an_complete, and link |
| 112 | * up state in @state->link. |
| 113 | */ |
| 114 | int mac_link_state(struct net_device *ndev, |
| 115 | struct phylink_link_state *state); |
| 116 | |
| 117 | /** |
| 118 | * mac_config() - configure the MAC for the selected mode and state |
| 119 | * @ndev: a pointer to a &struct net_device for the MAC. |
| 120 | * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND. |
| 121 | * @state: a pointer to a &struct phylink_link_state. |
| 122 | * |
| 123 | * The action performed depends on the currently selected mode: |
| 124 | * |
| 125 | * %MLO_AN_FIXED, %MLO_AN_PHY: |
| 126 | * Configure the specified @state->speed, @state->duplex and |
| 127 | * @state->pause (%MLO_PAUSE_TX / %MLO_PAUSE_RX) mode. |
| 128 | * |
| 129 | * %MLO_AN_INBAND: |
| 130 | * place the link in an inband negotiation mode (such as 802.3z |
| 131 | * 1000base-X or Cisco SGMII mode depending on the @state->interface |
| 132 | * mode). In both cases, link state management (whether the link |
| 133 | * is up or not) is performed by the MAC, and reported via the |
| 134 | * mac_link_state() callback. Changes in link state must be made |
| 135 | * by calling phylink_mac_change(). |
| 136 | * |
| 137 | * If in 802.3z mode, the link speed is fixed, dependent on the |
| 138 | * @state->interface. Duplex is negotiated, and pause is advertised |
| 139 | * according to @state->an_enabled, @state->pause and |
| 140 | * @state->advertising flags. Beware of MACs which only support full |
| 141 | * duplex at gigabit and higher speeds. |
| 142 | * |
| 143 | * If in Cisco SGMII mode, the link speed and duplex mode are passed |
| 144 | * in the serial bitstream 16-bit configuration word, and the MAC |
| 145 | * should be configured to read these bits and acknowledge the |
| 146 | * configuration word. Nothing is advertised by the MAC. The MAC is |
| 147 | * responsible for reading the configuration word and configuring |
| 148 | * itself accordingly. |
| 149 | */ |
| 150 | void mac_config(struct net_device *ndev, unsigned int mode, |
| 151 | const struct phylink_link_state *state); |
| 152 | |
| 153 | /** |
| 154 | * mac_an_restart() - restart 802.3z BaseX autonegotiation |
| 155 | * @ndev: a pointer to a &struct net_device for the MAC. |
| 156 | */ |
| 157 | void mac_an_restart(struct net_device *ndev); |
| 158 | |
| 159 | /** |
| 160 | * mac_link_down() - take the link down |
| 161 | * @ndev: a pointer to a &struct net_device for the MAC. |
| 162 | * @mode: link autonegotiation mode |
| 163 | * |
| 164 | * If @mode is not an in-band negotiation mode (as defined by |
| 165 | * phylink_autoneg_inband()), force the link down and disable any |
| 166 | * Energy Efficient Ethernet MAC configuration. |
| 167 | */ |
| 168 | void mac_link_down(struct net_device *ndev, unsigned int mode); |
| 169 | |
| 170 | /** |
| 171 | * mac_link_up() - allow the link to come up |
| 172 | * @ndev: a pointer to a &struct net_device for the MAC. |
| 173 | * @mode: link autonegotiation mode |
| 174 | * @phy: any attached phy |
| 175 | * |
| 176 | * If @mode is not an in-band negotiation mode (as defined by |
| 177 | * phylink_autoneg_inband()), allow the link to come up. If @phy |
| 178 | * is non-%NULL, configure Energy Efficient Ethernet by calling |
| 179 | * phy_init_eee() and perform appropriate MAC configuration for EEE. |
| 180 | */ |
| 181 | void mac_link_up(struct net_device *ndev, unsigned int mode, |
| 182 | struct phy_device *phy); |
| 183 | #endif |
| 184 | |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 185 | struct phylink *phylink_create(struct net_device *, struct device_node *, |
| 186 | phy_interface_t iface, const struct phylink_mac_ops *ops); |
| 187 | void phylink_destroy(struct phylink *); |
| 188 | |
| 189 | int phylink_connect_phy(struct phylink *, struct phy_device *); |
| 190 | int phylink_of_phy_connect(struct phylink *, struct device_node *); |
| 191 | void phylink_disconnect_phy(struct phylink *); |
| 192 | |
| 193 | void phylink_mac_change(struct phylink *, bool up); |
| 194 | |
| 195 | void phylink_start(struct phylink *); |
| 196 | void phylink_stop(struct phylink *); |
| 197 | |
| 198 | void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *); |
| 199 | int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *); |
| 200 | |
| 201 | int phylink_ethtool_ksettings_get(struct phylink *, |
| 202 | struct ethtool_link_ksettings *); |
| 203 | int phylink_ethtool_ksettings_set(struct phylink *, |
| 204 | const struct ethtool_link_ksettings *); |
| 205 | int phylink_ethtool_nway_reset(struct phylink *); |
| 206 | void phylink_ethtool_get_pauseparam(struct phylink *, |
| 207 | struct ethtool_pauseparam *); |
| 208 | int phylink_ethtool_set_pauseparam(struct phylink *, |
| 209 | struct ethtool_pauseparam *); |
Russell King | 770a1ad | 2017-07-25 15:03:23 +0100 | [diff] [blame] | 210 | int phylink_ethtool_get_module_info(struct phylink *, struct ethtool_modinfo *); |
| 211 | int phylink_ethtool_get_module_eeprom(struct phylink *, |
| 212 | struct ethtool_eeprom *, u8 *); |
Russell King | 9525ae8 | 2017-07-25 15:03:13 +0100 | [diff] [blame] | 213 | int phylink_get_eee_err(struct phylink *); |
| 214 | int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *); |
| 215 | int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *); |
| 216 | int phylink_mii_ioctl(struct phylink *, struct ifreq *, int); |
| 217 | |
| 218 | #define phylink_zero(bm) \ |
| 219 | bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS) |
| 220 | #define __phylink_do_bit(op, bm, mode) \ |
| 221 | op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm) |
| 222 | |
| 223 | #define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode) |
| 224 | #define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode) |
| 225 | #define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode) |
| 226 | |
| 227 | void phylink_set_port_modes(unsigned long *bits); |
| 228 | |
| 229 | #endif |