aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>2017-02-21 05:28:04 -0500
committerDavid S. Miller <davem@davemloft.net>2017-02-21 13:16:14 -0500
commitab42676af052e6d3502b31c2dc6b07af08ff126f (patch)
tree6581425291a2e1102bb18fbc9964c3192c33ad11
parentf8b0d5f8cc10f43642f97db6b37d60d765cff34a (diff)
net: mvpp2: handle too large value in mvpp2_rx_time_coal_set()
When configuring the MVPP2_ISR_RX_THRESHOLD_REG with the RX coalescing time threshold, we do not check for the maximum allowed value supported by the driver, which means we might overflow and use a bogus value. This commit adds a check for this situation, and if a value higher than what is supported by the hardware is provided, then we use the maximum value supported by the hardware. In order to achieve this in a way that avoids overflow and rounding errors, we introduce two utility functions mvpp2_usec_to_cycles() and cycles_to_usec(). Many thanks to Russell King for suggesting this implementation. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Acked-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/marvell/mvpp2.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index 679811db51a1..47fb949178b1 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -154,6 +154,7 @@
154 154
155/* Interrupt Cause and Mask registers */ 155/* Interrupt Cause and Mask registers */
156#define MVPP2_ISR_RX_THRESHOLD_REG(rxq) (0x5200 + 4 * (rxq)) 156#define MVPP2_ISR_RX_THRESHOLD_REG(rxq) (0x5200 + 4 * (rxq))
157#define MVPP2_MAX_ISR_RX_THRESHOLD 0xfffff0
157#define MVPP2_ISR_RXQ_GROUP_REG(rxq) (0x5400 + 4 * (rxq)) 158#define MVPP2_ISR_RXQ_GROUP_REG(rxq) (0x5400 + 4 * (rxq))
158#define MVPP2_ISR_ENABLE_REG(port) (0x5420 + 4 * (port)) 159#define MVPP2_ISR_ENABLE_REG(port) (0x5420 + 4 * (port))
159#define MVPP2_ISR_ENABLE_INTERRUPT(mask) ((mask) & 0xffff) 160#define MVPP2_ISR_ENABLE_INTERRUPT(mask) ((mask) & 0xffff)
@@ -4389,13 +4390,39 @@ static void mvpp2_rx_pkts_coal_set(struct mvpp2_port *port,
4389 rxq->pkts_coal); 4390 rxq->pkts_coal);
4390} 4391}
4391 4392
4393static u32 mvpp2_usec_to_cycles(u32 usec, unsigned long clk_hz)
4394{
4395 u64 tmp = (u64)clk_hz * usec;
4396
4397 do_div(tmp, USEC_PER_SEC);
4398
4399 return tmp > U32_MAX ? U32_MAX : tmp;
4400}
4401
4402static u32 mvpp2_cycles_to_usec(u32 cycles, unsigned long clk_hz)
4403{
4404 u64 tmp = (u64)cycles * USEC_PER_SEC;
4405
4406 do_div(tmp, clk_hz);
4407
4408 return tmp > U32_MAX ? U32_MAX : tmp;
4409}
4410
4392/* Set the time delay in usec before Rx interrupt */ 4411/* Set the time delay in usec before Rx interrupt */
4393static void mvpp2_rx_time_coal_set(struct mvpp2_port *port, 4412static void mvpp2_rx_time_coal_set(struct mvpp2_port *port,
4394 struct mvpp2_rx_queue *rxq) 4413 struct mvpp2_rx_queue *rxq)
4395{ 4414{
4396 u32 val; 4415 unsigned long freq = port->priv->tclk;
4416 u32 val = mvpp2_usec_to_cycles(rxq->time_coal, freq);
4417
4418 if (val > MVPP2_MAX_ISR_RX_THRESHOLD) {
4419 rxq->time_coal =
4420 mvpp2_cycles_to_usec(MVPP2_MAX_ISR_RX_THRESHOLD, freq);
4421
4422 /* re-evaluate to get actual register value */
4423 val = mvpp2_usec_to_cycles(rxq->time_coal, freq);
4424 }
4397 4425
4398 val = (port->priv->tclk / USEC_PER_SEC) * rxq->time_coal;
4399 mvpp2_write(port->priv, MVPP2_ISR_RX_THRESHOLD_REG(rxq->id), val); 4426 mvpp2_write(port->priv, MVPP2_ISR_RX_THRESHOLD_REG(rxq->id), val);
4400} 4427}
4401 4428