1616#include "wx_lib.h"
1717#include "wx_ptp.h"
1818#include "wx_hw.h"
19+ #include "wx_vf_lib.h"
1920
2021/* Lookup table mapping the HW PTYPE to the bit field for decoding */
2122static struct wx_dec_ptype wx_ptype_lookup [256 ] = {
@@ -832,6 +833,36 @@ static bool wx_clean_tx_irq(struct wx_q_vector *q_vector,
832833 return !!budget ;
833834}
834835
836+ static void wx_update_rx_dim_sample (struct wx_q_vector * q_vector )
837+ {
838+ struct dim_sample sample = {};
839+
840+ dim_update_sample (q_vector -> total_events ,
841+ q_vector -> rx .total_packets ,
842+ q_vector -> rx .total_bytes ,
843+ & sample );
844+
845+ net_dim (& q_vector -> rx .dim , & sample );
846+ }
847+
848+ static void wx_update_tx_dim_sample (struct wx_q_vector * q_vector )
849+ {
850+ struct dim_sample sample = {};
851+
852+ dim_update_sample (q_vector -> total_events ,
853+ q_vector -> tx .total_packets ,
854+ q_vector -> tx .total_bytes ,
855+ & sample );
856+
857+ net_dim (& q_vector -> tx .dim , & sample );
858+ }
859+
860+ static void wx_update_dim_sample (struct wx_q_vector * q_vector )
861+ {
862+ wx_update_rx_dim_sample (q_vector );
863+ wx_update_tx_dim_sample (q_vector );
864+ }
865+
835866/**
836867 * wx_poll - NAPI polling RX/TX cleanup routine
837868 * @napi: napi struct with our devices info in it
@@ -878,6 +909,8 @@ static int wx_poll(struct napi_struct *napi, int budget)
878909
879910 /* all work done, exit the polling mode */
880911 if (likely (napi_complete_done (napi , work_done ))) {
912+ if (wx -> rx_itr_setting == 1 )
913+ wx_update_dim_sample (q_vector );
881914 if (netif_running (wx -> netdev ))
882915 wx_intr_enable (wx , WX_INTR_Q (q_vector -> v_idx ));
883916 }
@@ -1591,13 +1624,74 @@ netdev_tx_t wx_xmit_frame(struct sk_buff *skb,
15911624}
15921625EXPORT_SYMBOL (wx_xmit_frame );
15931626
1627+ static void wx_set_itr (struct wx_q_vector * q_vector )
1628+ {
1629+ struct wx * wx = q_vector -> wx ;
1630+ u32 new_itr ;
1631+
1632+ /* use the smallest value of new ITR delay calculations */
1633+ new_itr = min (q_vector -> rx .itr , q_vector -> tx .itr );
1634+ new_itr <<= 2 ;
1635+
1636+ if (new_itr != q_vector -> itr ) {
1637+ /* save the algorithm value here */
1638+ q_vector -> itr = new_itr ;
1639+
1640+ if (wx -> pdev -> is_virtfn )
1641+ wx_write_eitr_vf (q_vector );
1642+ else
1643+ wx_write_eitr (q_vector );
1644+ }
1645+ }
1646+
1647+ static void wx_rx_dim_work (struct work_struct * work )
1648+ {
1649+ struct dim * dim = container_of (work , struct dim , work );
1650+ struct dim_cq_moder rx_moder ;
1651+ struct wx_ring_container * rx ;
1652+ struct wx_q_vector * q_vector ;
1653+
1654+ rx = container_of (dim , struct wx_ring_container , dim );
1655+
1656+ rx_moder = net_dim_get_rx_moderation (dim -> mode , dim -> profile_ix );
1657+ rx -> itr = rx_moder .usec ;
1658+
1659+ q_vector = container_of (rx , struct wx_q_vector , rx );
1660+ wx_set_itr (q_vector );
1661+
1662+ dim -> state = DIM_START_MEASURE ;
1663+ }
1664+
1665+ static void wx_tx_dim_work (struct work_struct * work )
1666+ {
1667+ struct dim * dim = container_of (work , struct dim , work );
1668+ struct dim_cq_moder tx_moder ;
1669+ struct wx_ring_container * tx ;
1670+ struct wx_q_vector * q_vector ;
1671+
1672+ tx = container_of (dim , struct wx_ring_container , dim );
1673+
1674+ tx_moder = net_dim_get_tx_moderation (dim -> mode , dim -> profile_ix );
1675+ tx -> itr = tx_moder .usec ;
1676+
1677+ q_vector = container_of (tx , struct wx_q_vector , tx );
1678+ wx_set_itr (q_vector );
1679+
1680+ dim -> state = DIM_START_MEASURE ;
1681+ }
1682+
15941683void wx_napi_enable_all (struct wx * wx )
15951684{
15961685 struct wx_q_vector * q_vector ;
15971686 int q_idx ;
15981687
15991688 for (q_idx = 0 ; q_idx < wx -> num_q_vectors ; q_idx ++ ) {
16001689 q_vector = wx -> q_vector [q_idx ];
1690+
1691+ INIT_WORK (& q_vector -> rx .dim .work , wx_rx_dim_work );
1692+ INIT_WORK (& q_vector -> tx .dim .work , wx_tx_dim_work );
1693+ q_vector -> rx .dim .mode = DIM_CQ_PERIOD_MODE_START_FROM_CQE ;
1694+ q_vector -> tx .dim .mode = DIM_CQ_PERIOD_MODE_START_FROM_CQE ;
16011695 napi_enable (& q_vector -> napi );
16021696 }
16031697}
@@ -1611,6 +1705,8 @@ void wx_napi_disable_all(struct wx *wx)
16111705 for (q_idx = 0 ; q_idx < wx -> num_q_vectors ; q_idx ++ ) {
16121706 q_vector = wx -> q_vector [q_idx ];
16131707 napi_disable (& q_vector -> napi );
1708+ cancel_work_sync (& q_vector -> rx .dim .work );
1709+ cancel_work_sync (& q_vector -> tx .dim .work );
16141710 }
16151711}
16161712EXPORT_SYMBOL (wx_napi_disable_all );
@@ -2197,8 +2293,10 @@ irqreturn_t wx_msix_clean_rings(int __always_unused irq, void *data)
21972293 struct wx_q_vector * q_vector = data ;
21982294
21992295 /* EIAM disabled interrupts (on this vector) for us */
2200- if (q_vector -> rx .ring || q_vector -> tx .ring )
2296+ if (q_vector -> rx .ring || q_vector -> tx .ring ) {
22012297 napi_schedule_irqoff (& q_vector -> napi );
2298+ q_vector -> total_events ++ ;
2299+ }
22022300
22032301 return IRQ_HANDLED ;
22042302}
0 commit comments