Path: blob/main/sys/contrib/alpine-hal/eth/al_hal_eth_kr.h
48255 views
/*-1*******************************************************************************2Copyright (C) 2015 Annapurna Labs Ltd.34This file may be licensed under the terms of the Annapurna Labs Commercial5License Agreement.67Alternatively, this file can be distributed under the terms of the GNU General8Public License V2 as published by the Free Software Foundation and can be9found at http://www.gnu.org/licenses/gpl-2.0.html1011Alternatively, redistribution and use in source and binary forms, with or12without modification, are permitted provided that the following conditions are13met:1415* Redistributions of source code must retain the above copyright notice,16this list of conditions and the following disclaimer.1718* Redistributions in binary form must reproduce the above copyright19notice, this list of conditions and the following disclaimer in20the documentation and/or other materials provided with the21distribution.2223THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND24ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED25WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE26DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR27ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES28(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;29LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON30ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT31(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS32SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.3334*******************************************************************************/35/**36* @defgroup group_eth_kr_api API37* Ethernet KR auto-neg and link-training driver API38* @ingroup group_eth39* @{40* @file al_hal_eth_kr.h41*42* @brief Header file for KR driver43*44*45*/4647#ifndef __AL_HAL_ETH_KR_H__48#define __AL_HAL_ETH_KR_H__4950#include "al_hal_eth.h"5152/* *INDENT-OFF* */53#ifdef __cplusplus54extern "C" {55#endif56/* *INDENT-ON* */5758/* AN (Auto-negotiation) Advertisement Registers */59struct al_eth_an_adv {60/* constant value defining 802.3ap support.61* The suggested value is 0x01.*/62uint8_t selector_field;63/* Contains arbitrary data. */64uint8_t echoed_nonce;65/* pause capability. */66uint8_t capability;67/* Set to 1 to indicate a Remote Fault condition.68* Set to 0 to indicate normal operation.*/69uint8_t remote_fault;70/* Should always be set to 0. */71uint8_t acknowledge;72/* Set to 1 to indicate that the device has next pages to send.73* Set to 0 to indicate that that device has no next pages to send. */74uint8_t next_page;75/* Must be set to an arbitrary value.76* Two devices must have a different nonce for autonegotiation to77* operate (a loopback will not allow autonegotiation to complete). */78uint8_t transmitted_nonce;79uint32_t technology;80#define AL_ETH_AN_TECH_1000BASE_KX AL_BIT(0)81#define AL_ETH_AN_TECH_10GBASE_KX4 AL_BIT(1)82#define AL_ETH_AN_TECH_10GBASE_KR AL_BIT(2)83#define AL_ETH_AN_TECH_40GBASE_KR4 AL_BIT(3)84#define AL_ETH_AN_TECH_40GBASE_CR4 AL_BIT(4)85#define AL_ETH_AN_TECH_100GBASE_CR AL_BIT(5)86uint8_t fec_capability;87};8889/* AN next page fields */90struct al_eth_an_np {91/* These bits can be used as message code field or unformatted code field.92* When msg_page is true, these bits represent message code field.93* Predefined message code field Code Field should be used as specified in the standard94* 802.3ap.95* For the null message code the value is 0x01.96*/97uint16_t unformatted_code_field;98/* Flag to keep track of the state of the local device's Toggle bit.99* Initial value is taken from base page. Set to 0.100*/101al_bool toggle;102/* Acknowledge 2 is used to indicate that the receiver is able to act on the information103* (or perform the task) defined in the message.104*/105al_bool ack2;106al_bool msg_page;107/* If the device does not have any more Next Pages to send, set to AL_FALSE */108al_bool next_page;109uint16_t unformatted_code_field1;110uint16_t unformatted_code_field2;111};112113enum al_eth_kr_cl72_cstate {114C72_CSTATE_NOT_UPDATED = 0,115C72_CSTATE_UPDATED = 1,116C72_CSTATE_MIN = 2,117C72_CSTATE_MAX = 3,118};119120enum al_eth_kr_cl72_coef_op {121AL_PHY_KR_COEF_UP_HOLD = 0,122AL_PHY_KR_COEF_UP_INC = 1,123AL_PHY_KR_COEF_UP_DEC = 2,124AL_PHY_KR_COEF_UP_RESERVED = 3125};126127struct al_eth_kr_coef_up_data {128enum al_eth_kr_cl72_coef_op c_zero;129enum al_eth_kr_cl72_coef_op c_plus;130enum al_eth_kr_cl72_coef_op c_minus;131al_bool preset;132al_bool initialize;133};134135struct al_eth_kr_status_report_data {136enum al_eth_kr_cl72_cstate c_zero;137enum al_eth_kr_cl72_cstate c_plus;138enum al_eth_kr_cl72_cstate c_minus;139al_bool receiver_ready;140};141142enum al_eth_an_lt_lane {143AL_ETH_AN__LT_LANE_0,144AL_ETH_AN__LT_LANE_1,145AL_ETH_AN__LT_LANE_2,146AL_ETH_AN__LT_LANE_3,147};148149/**150* get the last received coefficient update message from the link partner151*152* @param adapter pointer to the private structure153* @param lane lane number154* @param lpcoeff coeff update received155*156*/157void al_eth_lp_coeff_up_get(158struct al_hal_eth_adapter *adapter,159enum al_eth_an_lt_lane lane,160struct al_eth_kr_coef_up_data *lpcoeff);161162/**163* get the last received status report message from the link partner164*165* @param adapter pointer to the private structure166* @param lane lane number167* @param status status report received168*169*/170void al_eth_lp_status_report_get(171struct al_hal_eth_adapter *adapter,172enum al_eth_an_lt_lane lane,173struct al_eth_kr_status_report_data *status);174175/**176* set the coefficient data for the next message that will be sent to lp177*178* @param adapter pointer to the private structure179* @param lane lane number180* @param ldcoeff coeff update to send181*182*/183void al_eth_ld_coeff_up_set(184struct al_hal_eth_adapter *adapter,185enum al_eth_an_lt_lane lane,186struct al_eth_kr_coef_up_data *ldcoeff);187188/**189* set the status report message for the next message that will be sent to lp190*191* @param adapter pointer to the private structure192* @param lane lane number193* @param status status report to send194*195*/196void al_eth_ld_status_report_set(197struct al_hal_eth_adapter *adapter,198enum al_eth_an_lt_lane lane,199struct al_eth_kr_status_report_data *status);200201/**202* get the receiver frame lock status203*204* @param adapter pointer to the private structure205* @param lane lane number206*207* @return true if Training frame delineation is detected, otherwise false.208*/209al_bool al_eth_kr_receiver_frame_lock_get(struct al_hal_eth_adapter *adapter,210enum al_eth_an_lt_lane lane);211212/**213* get the start up protocol progress status214*215* @param adapter pointer to the private structure216* @param lane lane number217*218* @return true if the startup protocol is in progress.219*/220al_bool al_eth_kr_startup_proto_prog_get(struct al_hal_eth_adapter *adapter,221enum al_eth_an_lt_lane lane);222223/**224* indicate the receiver is ready (the link training is completed)225*226* @param adapter pointer to the private structure227* @param lane lane number228*229*/230void al_eth_receiver_ready_set(struct al_hal_eth_adapter *adapter,231enum al_eth_an_lt_lane lane);232233/**234* read Training failure status.235*236* @param adapter pointer to the private structure237* @param lane lane number238*239*@return true if Training failure has been detected.240*/241al_bool al_eth_kr_training_status_fail_get(struct al_hal_eth_adapter *adapter,242enum al_eth_an_lt_lane lane);243244/****************************** auto negotiation *******************************/245/**246* Initialize Auto-negotiation247* - Program Ability Registers (Advertisement Registers)248* - Clear Status latches249* @param adapter pointer to the private structure250* @param an_adv pointer to the AN Advertisement Registers structure251* when NULL, the registers will not be updated.252*253* @return 0 on success. otherwise on failure.254*/255int al_eth_kr_an_init(struct al_hal_eth_adapter *adapter,256struct al_eth_an_adv *an_adv);257258/**259* Enable/Restart Auto-negotiation260*261* @param adapter pointer to the private structure262* @param lane lane number263* @param lt_enable initialize link training as well264*265* @return 0 on success. otherwise on failure.266*/267int al_eth_kr_an_start(struct al_hal_eth_adapter *adapter,268enum al_eth_an_lt_lane lane,269al_bool next_page_enable,270al_bool lt_enable);271272273int al_eth_kr_next_page_write(struct al_hal_eth_adapter *adapter,274struct al_eth_an_np *np);275276int al_eth_kr_next_page_read(struct al_hal_eth_adapter *adapter,277struct al_eth_an_np *np);278279/**280* Stop Auto-negotiation281*282* Stopping the auto-negotiation will prevent the mac from sending the last page283* to the link partner in case it start the AN again. It must be called after284* link training is completed or the software will lose sync with the HW state285* machine286*287* @param adapter pointer to the private structure288*289*/290void al_eth_kr_an_stop(struct al_hal_eth_adapter *adapter);291292/**293* Check Auto-negotiation event done294*295* @param adapter pointer to the private structure296* @param page_received Set to true if the AN page received indication is set.297* Set to false otherwise.298* @param an_completed Set to true of the AN completed indication is set.299* Set to false otherwise.300* @param error Set to true if any error encountered301*302*/303void al_eth_kr_an_status_check(struct al_hal_eth_adapter *adapter,304al_bool *page_received,305al_bool *an_completed,306al_bool *error);307308/**309* Read the remote auto-negotiation advertising.310* This function is safe to called after al_eth_kr_an_status_check returned311* with page_received set.312*313* @param adapter pointer to the private structure314* @param an_adv pointer to the AN Advertisement Registers structure315*316*/317void al_eth_kr_an_read_adv(struct al_hal_eth_adapter *adapter,318struct al_eth_an_adv *an_adv);319320/****************************** link training **********************************/321/**322* Initialize Link-training.323* Clear the status register and set the local coefficient update and status324* to zero.325*326* @param adapter pointer to the private structure327* @param lane lane number328*329*/330void al_eth_kr_lt_initialize(struct al_hal_eth_adapter *adapter,331enum al_eth_an_lt_lane lane);332333/**334* Wait for frame lock.335*336* @param adapter pointer to the private structure337* @param lane lane number338* @param timeout timeout in usec.339*340* @return true if frame lock received. false otherwise.341*/342al_bool al_eth_kr_lt_frame_lock_wait(struct al_hal_eth_adapter *adapter,343enum al_eth_an_lt_lane lane,344uint32_t timeout);345346/**347* reset the 10GBase- KR startup protocol and begin its operation348*349* @param adapter pointer to the private structure350* @param lane lane number351*352*/353void al_eth_kr_lt_restart(struct al_hal_eth_adapter *adapter,354enum al_eth_an_lt_lane lane);355356/**357* reset the 10GBase- KR startup protocol and end its operation358*359* @param adapter pointer to the private structure360* @param lane lane number361*362*/363void al_eth_kr_lt_stop(struct al_hal_eth_adapter *adapter,364enum al_eth_an_lt_lane lane);365366#ifdef __cplusplus367}368#endif369/* *INDENT-ON* */370#endif /*__AL_HAL_ETH_KR_H__*/371/** @} end of Ethernet kr group */372373374