4.10 Credit Based Traffic Shaping
The LAN8670/1/2 implements a hardware credit based traffic shaper (CBS) to control the station’s transmit bandwidth. A hardware credit counter is used to enable and disable the ability to transmit packets onto the medium. The PHY decrements the credit counter during transmit and increments the counter when the PHY is receiving data or the medium is idle. When the credit counter is below the stop threshold, the PHY does not have enough credits to transmit. The PHY will then hold the MAC off from transmitting by asserting the MII CRS or RMII CRSDV pin. When the PHY is not transmitting, it will accumulate credits. Once the credit counter exceeds the start threshold, CRS/CRSDV will operate normally. Once the PHY allows the MAC to begin transmitting a packet, the entire packet will be transmitted even if the credit counter decrements below the stop threshold while it is transmitting.
The credit based traffic shaper is enabled by setting the CBS Enable (CBSEN) bit in the Credit Based Shaper Control (CBSCTRL) register. The credit based traffic shaper may be used with or without PLCA.
The transmit stop threshold is configurable in the Stop Threshold (STOPTHR) bit field in the Credit Based Shaper Stop Threshold High/Low (CBSSPTHH/CBSSPTHL) registers. The Start Threshold (STARTTHR) field in the Credit Based Shaper Start Threshold High/Low (CBSSTTHH/CBSSTTHL) registers is used to configure the transmit start threshold.
The Falling Slope (FALLSLP) field of the Credit Based Shaper Slope Control (CBSSLPCTL) register configures the rate at which the credit counter loses credits when transmitting. Similarly, the Rising Slope (RISESLP) field configures the rate at which the credit counter will accumulate credits when the medium is idle or the PHY is receiving data. When PLCA is enabled, credits may additionally be accumulated at an accelerated rate when no transmission is detected within each PLCA bus cycle. The rate at which credits are accumulated for each empty PLCA bus cycle is configured by the Empty Cycle Credits (ECCRDS) field of the Credit Based Shaper Control register.
The credit counter will saturate and stop accumulating credits when the limit set by the Top Limit (TOPLIMIT) field in the Credit Based Shaper Top Limit High/Low (CBSTPLMTH/CBSTPLMTL) registers is reached. Likewise, the credit counter will saturate and stop losing credits at the limit set by the Bottom Limit (BOTLIMIT) field in the Credit Based Shaper Bottom Limit High/Low (CBSBTLMTH/CBSBTLMTL) registers. This prevents the credit counter from incrementing or decrementing into an overflow condition. The saturation of the credit counter also prevents the PHY from delaying transmission of a packet too long or transmitting a burst of packets. For example, the PHY may lose a significant number of credits by transmitting a maximal size packet. If the credit counter were not limited by a lower bound, it may take a significant amount of time for the PHY to accumulate enough credits to transmit another packet. Similarly, if the PHY has not transmitted in a long time, it may accumulate too many credits allowing it to transmit multiple frames if the credit counter were not limited by an upper bound. By controlling the top and bottom limits of the credit counter, the credit based shaper may be configured to transmit at the desired rate.
For debug or monitoring purposes, the current value of the credit counter may be obtained by reading the Credit Counter (CREDITCTR) field of the Credit Based Shaper Counter High/Low (CBSCRCTRH/CBSCRCTRL) registers.