diff options
Diffstat (limited to 'include/linux/phylink.h')
-rw-r--r-- | include/linux/phylink.h | 201 |
1 files changed, 143 insertions, 58 deletions
diff --git a/include/linux/phylink.h b/include/linux/phylink.h index af67edd4ae38..bd137c273d38 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h | |||
@@ -7,6 +7,7 @@ | |||
7 | 7 | ||
8 | struct device_node; | 8 | struct device_node; |
9 | struct ethtool_cmd; | 9 | struct ethtool_cmd; |
10 | struct fwnode_handle; | ||
10 | struct net_device; | 11 | struct net_device; |
11 | 12 | ||
12 | enum { | 13 | enum { |
@@ -20,19 +21,31 @@ enum { | |||
20 | 21 | ||
21 | MLO_AN_PHY = 0, /* Conventional PHY */ | 22 | MLO_AN_PHY = 0, /* Conventional PHY */ |
22 | MLO_AN_FIXED, /* Fixed-link mode */ | 23 | MLO_AN_FIXED, /* Fixed-link mode */ |
23 | MLO_AN_SGMII, /* Cisco SGMII protocol */ | 24 | MLO_AN_INBAND, /* In-band protocol */ |
24 | MLO_AN_8023Z, /* 1000base-X protocol */ | ||
25 | }; | 25 | }; |
26 | 26 | ||
27 | static inline bool phylink_autoneg_inband(unsigned int mode) | 27 | static inline bool phylink_autoneg_inband(unsigned int mode) |
28 | { | 28 | { |
29 | return mode == MLO_AN_SGMII || mode == MLO_AN_8023Z; | 29 | return mode == MLO_AN_INBAND; |
30 | } | 30 | } |
31 | 31 | ||
32 | /** | ||
33 | * struct phylink_link_state - link state structure | ||
34 | * @advertising: ethtool bitmask containing advertised link modes | ||
35 | * @lp_advertising: ethtool bitmask containing link partner advertised link | ||
36 | * modes | ||
37 | * @interface: link &typedef phy_interface_t mode | ||
38 | * @speed: link speed, one of the SPEED_* constants. | ||
39 | * @duplex: link duplex mode, one of DUPLEX_* constants. | ||
40 | * @pause: link pause state, described by MLO_PAUSE_* constants. | ||
41 | * @link: true if the link is up. | ||
42 | * @an_enabled: true if autonegotiation is enabled/desired. | ||
43 | * @an_complete: true if autonegotiation has completed. | ||
44 | */ | ||
32 | struct phylink_link_state { | 45 | struct phylink_link_state { |
33 | __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising); | 46 | __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising); |
34 | __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising); | 47 | __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising); |
35 | phy_interface_t interface; /* PHY_INTERFACE_xxx */ | 48 | phy_interface_t interface; |
36 | int speed; | 49 | int speed; |
37 | int duplex; | 50 | int duplex; |
38 | int pause; | 51 | int pause; |
@@ -41,72 +54,145 @@ struct phylink_link_state { | |||
41 | unsigned int an_complete:1; | 54 | unsigned int an_complete:1; |
42 | }; | 55 | }; |
43 | 56 | ||
57 | /** | ||
58 | * struct phylink_mac_ops - MAC operations structure. | ||
59 | * @validate: Validate and update the link configuration. | ||
60 | * @mac_link_state: Read the current link state from the hardware. | ||
61 | * @mac_config: configure the MAC for the selected mode and state. | ||
62 | * @mac_an_restart: restart 802.3z BaseX autonegotiation. | ||
63 | * @mac_link_down: take the link down. | ||
64 | * @mac_link_up: allow the link to come up. | ||
65 | * | ||
66 | * The individual methods are described more fully below. | ||
67 | */ | ||
44 | struct phylink_mac_ops { | 68 | struct phylink_mac_ops { |
45 | /** | ||
46 | * validate: validate and update the link configuration | ||
47 | * @ndev: net_device structure associated with MAC | ||
48 | * @config: configuration to validate | ||
49 | * | ||
50 | * Update the %config->supported and %config->advertised masks | ||
51 | * clearing bits that can not be supported. | ||
52 | * | ||
53 | * Note: the PHY may be able to transform from one connection | ||
54 | * technology to another, so, eg, don't clear 1000BaseX just | ||
55 | * because the MAC is unable to support it. This is more about | ||
56 | * clearing unsupported speeds and duplex settings. | ||
57 | * | ||
58 | * If the %config->interface mode is %PHY_INTERFACE_MODE_1000BASEX | ||
59 | * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode | ||
60 | * based on %config->advertised and/or %config->speed. | ||
61 | */ | ||
62 | void (*validate)(struct net_device *ndev, unsigned long *supported, | 69 | void (*validate)(struct net_device *ndev, unsigned long *supported, |
63 | struct phylink_link_state *state); | 70 | struct phylink_link_state *state); |
64 | 71 | int (*mac_link_state)(struct net_device *ndev, | |
65 | /* Read the current link state from the hardware */ | 72 | struct phylink_link_state *state); |
66 | int (*mac_link_state)(struct net_device *, struct phylink_link_state *); | ||
67 | |||
68 | /* Configure the MAC */ | ||
69 | /** | ||
70 | * mac_config: configure the MAC for the selected mode and state | ||
71 | * @ndev: net_device structure for the MAC | ||
72 | * @mode: one of MLO_AN_FIXED, MLO_AN_PHY, MLO_AN_8023Z, MLO_AN_SGMII | ||
73 | * @state: state structure | ||
74 | * | ||
75 | * The action performed depends on the currently selected mode: | ||
76 | * | ||
77 | * %MLO_AN_FIXED, %MLO_AN_PHY: | ||
78 | * set the specified speed, duplex, pause mode, and phy interface | ||
79 | * mode in the provided @state. | ||
80 | * %MLO_AN_8023Z: | ||
81 | * place the link in 1000base-X mode, advertising the parameters | ||
82 | * given in advertising in @state. | ||
83 | * %MLO_AN_SGMII: | ||
84 | * place the link in Cisco SGMII mode - there is no advertisment | ||
85 | * to make as the PHY communicates the speed and duplex to the | ||
86 | * MAC over the in-band control word. Configuration of the pause | ||
87 | * mode is as per MLO_AN_PHY since this is not included. | ||
88 | */ | ||
89 | void (*mac_config)(struct net_device *ndev, unsigned int mode, | 73 | void (*mac_config)(struct net_device *ndev, unsigned int mode, |
90 | const struct phylink_link_state *state); | 74 | const struct phylink_link_state *state); |
91 | |||
92 | /** | ||
93 | * mac_an_restart: restart 802.3z BaseX autonegotiation | ||
94 | * @ndev: net_device structure for the MAC | ||
95 | */ | ||
96 | void (*mac_an_restart)(struct net_device *ndev); | 75 | void (*mac_an_restart)(struct net_device *ndev); |
97 | 76 | void (*mac_link_down)(struct net_device *ndev, unsigned int mode); | |
98 | void (*mac_link_down)(struct net_device *, unsigned int mode); | 77 | void (*mac_link_up)(struct net_device *ndev, unsigned int mode, |
99 | void (*mac_link_up)(struct net_device *, unsigned int mode, | 78 | struct phy_device *phy); |
100 | struct phy_device *); | ||
101 | }; | 79 | }; |
102 | 80 | ||
103 | struct phylink *phylink_create(struct net_device *, struct device_node *, | 81 | #if 0 /* For kernel-doc purposes only. */ |
82 | /** | ||
83 | * validate - Validate and update the link configuration | ||
84 | * @ndev: a pointer to a &struct net_device for the MAC. | ||
85 | * @supported: ethtool bitmask for supported link modes. | ||
86 | * @state: a pointer to a &struct phylink_link_state. | ||
87 | * | ||
88 | * Clear bits in the @supported and @state->advertising masks that | ||
89 | * are not supportable by the MAC. | ||
90 | * | ||
91 | * Note that the PHY may be able to transform from one connection | ||
92 | * technology to another, so, eg, don't clear 1000BaseX just | ||
93 | * because the MAC is unable to BaseX mode. This is more about | ||
94 | * clearing unsupported speeds and duplex settings. | ||
95 | * | ||
96 | * If the @state->interface mode is %PHY_INTERFACE_MODE_1000BASEX | ||
97 | * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode | ||
98 | * based on @state->advertising and/or @state->speed and update | ||
99 | * @state->interface accordingly. | ||
100 | */ | ||
101 | void validate(struct net_device *ndev, unsigned long *supported, | ||
102 | struct phylink_link_state *state); | ||
103 | |||
104 | /** | ||
105 | * mac_link_state() - Read the current link state from the hardware | ||
106 | * @ndev: a pointer to a &struct net_device for the MAC. | ||
107 | * @state: a pointer to a &struct phylink_link_state. | ||
108 | * | ||
109 | * Read the current link state from the MAC, reporting the current | ||
110 | * speed in @state->speed, duplex mode in @state->duplex, pause mode | ||
111 | * in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits, | ||
112 | * negotiation completion state in @state->an_complete, and link | ||
113 | * up state in @state->link. | ||
114 | */ | ||
115 | int mac_link_state(struct net_device *ndev, | ||
116 | struct phylink_link_state *state); | ||
117 | |||
118 | /** | ||
119 | * mac_config() - configure the MAC for the selected mode and state | ||
120 | * @ndev: a pointer to a &struct net_device for the MAC. | ||
121 | * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND. | ||
122 | * @state: a pointer to a &struct phylink_link_state. | ||
123 | * | ||
124 | * The action performed depends on the currently selected mode: | ||
125 | * | ||
126 | * %MLO_AN_FIXED, %MLO_AN_PHY: | ||
127 | * Configure the specified @state->speed, @state->duplex and | ||
128 | * @state->pause (%MLO_PAUSE_TX / %MLO_PAUSE_RX) mode. | ||
129 | * | ||
130 | * %MLO_AN_INBAND: | ||
131 | * place the link in an inband negotiation mode (such as 802.3z | ||
132 | * 1000base-X or Cisco SGMII mode depending on the @state->interface | ||
133 | * mode). In both cases, link state management (whether the link | ||
134 | * is up or not) is performed by the MAC, and reported via the | ||
135 | * mac_link_state() callback. Changes in link state must be made | ||
136 | * by calling phylink_mac_change(). | ||
137 | * | ||
138 | * If in 802.3z mode, the link speed is fixed, dependent on the | ||
139 | * @state->interface. Duplex is negotiated, and pause is advertised | ||
140 | * according to @state->an_enabled, @state->pause and | ||
141 | * @state->advertising flags. Beware of MACs which only support full | ||
142 | * duplex at gigabit and higher speeds. | ||
143 | * | ||
144 | * If in Cisco SGMII mode, the link speed and duplex mode are passed | ||
145 | * in the serial bitstream 16-bit configuration word, and the MAC | ||
146 | * should be configured to read these bits and acknowledge the | ||
147 | * configuration word. Nothing is advertised by the MAC. The MAC is | ||
148 | * responsible for reading the configuration word and configuring | ||
149 | * itself accordingly. | ||
150 | */ | ||
151 | void mac_config(struct net_device *ndev, unsigned int mode, | ||
152 | const struct phylink_link_state *state); | ||
153 | |||
154 | /** | ||
155 | * mac_an_restart() - restart 802.3z BaseX autonegotiation | ||
156 | * @ndev: a pointer to a &struct net_device for the MAC. | ||
157 | */ | ||
158 | void mac_an_restart(struct net_device *ndev); | ||
159 | |||
160 | /** | ||
161 | * mac_link_down() - take the link down | ||
162 | * @ndev: a pointer to a &struct net_device for the MAC. | ||
163 | * @mode: link autonegotiation mode | ||
164 | * | ||
165 | * If @mode is not an in-band negotiation mode (as defined by | ||
166 | * phylink_autoneg_inband()), force the link down and disable any | ||
167 | * Energy Efficient Ethernet MAC configuration. | ||
168 | */ | ||
169 | void mac_link_down(struct net_device *ndev, unsigned int mode); | ||
170 | |||
171 | /** | ||
172 | * mac_link_up() - allow the link to come up | ||
173 | * @ndev: a pointer to a &struct net_device for the MAC. | ||
174 | * @mode: link autonegotiation mode | ||
175 | * @phy: any attached phy | ||
176 | * | ||
177 | * If @mode is not an in-band negotiation mode (as defined by | ||
178 | * phylink_autoneg_inband()), allow the link to come up. If @phy | ||
179 | * is non-%NULL, configure Energy Efficient Ethernet by calling | ||
180 | * phy_init_eee() and perform appropriate MAC configuration for EEE. | ||
181 | */ | ||
182 | void mac_link_up(struct net_device *ndev, unsigned int mode, | ||
183 | struct phy_device *phy); | ||
184 | #endif | ||
185 | |||
186 | struct phylink *phylink_create(struct net_device *, struct fwnode_handle *, | ||
104 | phy_interface_t iface, const struct phylink_mac_ops *ops); | 187 | phy_interface_t iface, const struct phylink_mac_ops *ops); |
105 | void phylink_destroy(struct phylink *); | 188 | void phylink_destroy(struct phylink *); |
106 | 189 | ||
107 | int phylink_connect_phy(struct phylink *, struct phy_device *); | 190 | int phylink_connect_phy(struct phylink *, struct phy_device *); |
108 | int phylink_of_phy_connect(struct phylink *, struct device_node *); | 191 | int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags); |
109 | void phylink_disconnect_phy(struct phylink *); | 192 | void phylink_disconnect_phy(struct phylink *); |
193 | int phylink_fixed_state_cb(struct phylink *, | ||
194 | void (*cb)(struct net_device *dev, | ||
195 | struct phylink_link_state *)); | ||
110 | 196 | ||
111 | void phylink_mac_change(struct phylink *, bool up); | 197 | void phylink_mac_change(struct phylink *, bool up); |
112 | 198 | ||
@@ -128,7 +214,6 @@ int phylink_ethtool_set_pauseparam(struct phylink *, | |||
128 | int phylink_ethtool_get_module_info(struct phylink *, struct ethtool_modinfo *); | 214 | int phylink_ethtool_get_module_info(struct phylink *, struct ethtool_modinfo *); |
129 | int phylink_ethtool_get_module_eeprom(struct phylink *, | 215 | int phylink_ethtool_get_module_eeprom(struct phylink *, |
130 | struct ethtool_eeprom *, u8 *); | 216 | struct ethtool_eeprom *, u8 *); |
131 | int phylink_init_eee(struct phylink *, bool); | ||
132 | int phylink_get_eee_err(struct phylink *); | 217 | int phylink_get_eee_err(struct phylink *); |
133 | int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *); | 218 | int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *); |
134 | int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *); | 219 | int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *); |