2 *******************************************************************************
3 Copyright (C) 2015 Annapurna Labs Ltd.
5 This file may be licensed under the terms of the Annapurna Labs Commercial
8 Alternatively, this file can be distributed under the terms of the GNU General
9 Public License V2 as published by the Free Software Foundation and can be
10 found at http://www.gnu.org/licenses/gpl-2.0.html
12 Alternatively, redistribution and use in source and binary forms, with or
13 without modification, are permitted provided that the following conditions are
16 * Redistributions of source code must retain the above copyright notice,
17 this list of conditions and the following disclaimer.
19 * Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in
21 the documentation and/or other materials provided with the
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
28 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *******************************************************************************/
37 * @defgroup group_eth_kr_api API
38 * Ethernet KR auto-neg and link-training driver API
41 * @file al_hal_eth_kr.h
43 * @brief Header file for KR driver
48 #ifndef __AL_HAL_ETH_KR_H__
49 #define __AL_HAL_ETH_KR_H__
51 #include "al_hal_eth.h"
59 /* AN (Auto-negotiation) Advertisement Registers */
60 struct al_eth_an_adv {
61 /* constant value defining 802.3ap support.
62 * The suggested value is 0x01.*/
63 uint8_t selector_field;
64 /* Contains arbitrary data. */
66 /* pause capability. */
68 /* Set to 1 to indicate a Remote Fault condition.
69 * Set to 0 to indicate normal operation.*/
71 /* Should always be set to 0. */
73 /* Set to 1 to indicate that the device has next pages to send.
74 * Set to 0 to indicate that that device has no next pages to send. */
76 /* Must be set to an arbitrary value.
77 * Two devices must have a different nonce for autonegotiation to
78 * operate (a loopback will not allow autonegotiation to complete). */
79 uint8_t transmitted_nonce;
81 #define AL_ETH_AN_TECH_1000BASE_KX AL_BIT(0)
82 #define AL_ETH_AN_TECH_10GBASE_KX4 AL_BIT(1)
83 #define AL_ETH_AN_TECH_10GBASE_KR AL_BIT(2)
84 #define AL_ETH_AN_TECH_40GBASE_KR4 AL_BIT(3)
85 #define AL_ETH_AN_TECH_40GBASE_CR4 AL_BIT(4)
86 #define AL_ETH_AN_TECH_100GBASE_CR AL_BIT(5)
87 uint8_t fec_capability;
90 /* AN next page fields */
92 /* These bits can be used as message code field or unformatted code field.
93 * When msg_page is true, these bits represent message code field.
94 * Predefined message code field Code Field should be used as specified in the standard
96 * For the null message code the value is 0x01.
98 uint16_t unformatted_code_field;
99 /* Flag to keep track of the state of the local device's Toggle bit.
100 * Initial value is taken from base page. Set to 0.
103 /* Acknowledge 2 is used to indicate that the receiver is able to act on the information
104 * (or perform the task) defined in the message.
108 /* If the device does not have any more Next Pages to send, set to AL_FALSE */
110 uint16_t unformatted_code_field1;
111 uint16_t unformatted_code_field2;
114 enum al_eth_kr_cl72_cstate {
115 C72_CSTATE_NOT_UPDATED = 0,
116 C72_CSTATE_UPDATED = 1,
121 enum al_eth_kr_cl72_coef_op {
122 AL_PHY_KR_COEF_UP_HOLD = 0,
123 AL_PHY_KR_COEF_UP_INC = 1,
124 AL_PHY_KR_COEF_UP_DEC = 2,
125 AL_PHY_KR_COEF_UP_RESERVED = 3
128 struct al_eth_kr_coef_up_data {
129 enum al_eth_kr_cl72_coef_op c_zero;
130 enum al_eth_kr_cl72_coef_op c_plus;
131 enum al_eth_kr_cl72_coef_op c_minus;
136 struct al_eth_kr_status_report_data {
137 enum al_eth_kr_cl72_cstate c_zero;
138 enum al_eth_kr_cl72_cstate c_plus;
139 enum al_eth_kr_cl72_cstate c_minus;
140 al_bool receiver_ready;
143 enum al_eth_an_lt_lane {
144 AL_ETH_AN__LT_LANE_0,
145 AL_ETH_AN__LT_LANE_1,
146 AL_ETH_AN__LT_LANE_2,
147 AL_ETH_AN__LT_LANE_3,
151 * get the last received coefficient update message from the link partner
153 * @param adapter pointer to the private structure
154 * @param lane lane number
155 * @param lpcoeff coeff update received
158 void al_eth_lp_coeff_up_get(
159 struct al_hal_eth_adapter *adapter,
160 enum al_eth_an_lt_lane lane,
161 struct al_eth_kr_coef_up_data *lpcoeff);
164 * get the last received status report message from the link partner
166 * @param adapter pointer to the private structure
167 * @param lane lane number
168 * @param status status report received
171 void al_eth_lp_status_report_get(
172 struct al_hal_eth_adapter *adapter,
173 enum al_eth_an_lt_lane lane,
174 struct al_eth_kr_status_report_data *status);
177 * set the coefficient data for the next message that will be sent to lp
179 * @param adapter pointer to the private structure
180 * @param lane lane number
181 * @param ldcoeff coeff update to send
184 void al_eth_ld_coeff_up_set(
185 struct al_hal_eth_adapter *adapter,
186 enum al_eth_an_lt_lane lane,
187 struct al_eth_kr_coef_up_data *ldcoeff);
190 * set the status report message for the next message that will be sent to lp
192 * @param adapter pointer to the private structure
193 * @param lane lane number
194 * @param status status report to send
197 void al_eth_ld_status_report_set(
198 struct al_hal_eth_adapter *adapter,
199 enum al_eth_an_lt_lane lane,
200 struct al_eth_kr_status_report_data *status);
203 * get the receiver frame lock status
205 * @param adapter pointer to the private structure
206 * @param lane lane number
208 * @return true if Training frame delineation is detected, otherwise false.
210 al_bool al_eth_kr_receiver_frame_lock_get(struct al_hal_eth_adapter *adapter,
211 enum al_eth_an_lt_lane lane);
214 * get the start up protocol progress status
216 * @param adapter pointer to the private structure
217 * @param lane lane number
219 * @return true if the startup protocol is in progress.
221 al_bool al_eth_kr_startup_proto_prog_get(struct al_hal_eth_adapter *adapter,
222 enum al_eth_an_lt_lane lane);
225 * indicate the receiver is ready (the link training is completed)
227 * @param adapter pointer to the private structure
228 * @param lane lane number
231 void al_eth_receiver_ready_set(struct al_hal_eth_adapter *adapter,
232 enum al_eth_an_lt_lane lane);
235 * read Training failure status.
237 * @param adapter pointer to the private structure
238 * @param lane lane number
240 *@return true if Training failure has been detected.
242 al_bool al_eth_kr_training_status_fail_get(struct al_hal_eth_adapter *adapter,
243 enum al_eth_an_lt_lane lane);
245 /****************************** auto negotiation *******************************/
247 * Initialize Auto-negotiation
248 * - Program Ability Registers (Advertisement Registers)
249 * - Clear Status latches
250 * @param adapter pointer to the private structure
251 * @param an_adv pointer to the AN Advertisement Registers structure
252 * when NULL, the registers will not be updated.
254 * @return 0 on success. otherwise on failure.
256 int al_eth_kr_an_init(struct al_hal_eth_adapter *adapter,
257 struct al_eth_an_adv *an_adv);
260 * Enable/Restart Auto-negotiation
262 * @param adapter pointer to the private structure
263 * @param lane lane number
264 * @param lt_enable initialize link training as well
266 * @return 0 on success. otherwise on failure.
268 int al_eth_kr_an_start(struct al_hal_eth_adapter *adapter,
269 enum al_eth_an_lt_lane lane,
270 al_bool next_page_enable,
274 int al_eth_kr_next_page_write(struct al_hal_eth_adapter *adapter,
275 struct al_eth_an_np *np);
277 int al_eth_kr_next_page_read(struct al_hal_eth_adapter *adapter,
278 struct al_eth_an_np *np);
281 * Stop Auto-negotiation
283 * Stopping the auto-negotiation will prevent the mac from sending the last page
284 * to the link partner in case it start the AN again. It must be called after
285 * link training is completed or the software will lose sync with the HW state
288 * @param adapter pointer to the private structure
291 void al_eth_kr_an_stop(struct al_hal_eth_adapter *adapter);
294 * Check Auto-negotiation event done
296 * @param adapter pointer to the private structure
297 * @param page_received Set to true if the AN page received indication is set.
298 * Set to false otherwise.
299 * @param an_completed Set to true of the AN completed indication is set.
300 * Set to false otherwise.
301 * @param error Set to true if any error encountered
304 void al_eth_kr_an_status_check(struct al_hal_eth_adapter *adapter,
305 al_bool *page_received,
306 al_bool *an_completed,
310 * Read the remote auto-negotiation advertising.
311 * This function is safe to called after al_eth_kr_an_status_check returned
312 * with page_received set.
314 * @param adapter pointer to the private structure
315 * @param an_adv pointer to the AN Advertisement Registers structure
318 void al_eth_kr_an_read_adv(struct al_hal_eth_adapter *adapter,
319 struct al_eth_an_adv *an_adv);
321 /****************************** link training **********************************/
323 * Initialize Link-training.
324 * Clear the status register and set the local coefficient update and status
327 * @param adapter pointer to the private structure
328 * @param lane lane number
331 void al_eth_kr_lt_initialize(struct al_hal_eth_adapter *adapter,
332 enum al_eth_an_lt_lane lane);
335 * Wait for frame lock.
337 * @param adapter pointer to the private structure
338 * @param lane lane number
339 * @param timeout timeout in usec.
341 * @return true if frame lock received. false otherwise.
343 al_bool al_eth_kr_lt_frame_lock_wait(struct al_hal_eth_adapter *adapter,
344 enum al_eth_an_lt_lane lane,
348 * reset the 10GBase- KR startup protocol and begin its operation
350 * @param adapter pointer to the private structure
351 * @param lane lane number
354 void al_eth_kr_lt_restart(struct al_hal_eth_adapter *adapter,
355 enum al_eth_an_lt_lane lane);
358 * reset the 10GBase- KR startup protocol and end its operation
360 * @param adapter pointer to the private structure
361 * @param lane lane number
364 void al_eth_kr_lt_stop(struct al_hal_eth_adapter *adapter,
365 enum al_eth_an_lt_lane lane);
371 #endif /*__AL_HAL_ETH_KR_H__*/
372 /** @} end of Ethernet kr group */