Updated the Readme
[dante-enablement/k2g-dante-enablement.git] / 0004-drivers-net-ethernet-ti-netcp_core.c-tx-tmr.patch
1 From 80e83dccc4a4e3f1b6f599aa98739610e267ea86 Mon Sep 17 00:00:00 2001
2 From: Grygorii Strashko <grygorii.strashko@ti.com>
3 Date: Thu, 22 Oct 2020 15:46:09 +0300
4 Subject: [PATCH] drivers/net/ethernet/ti/netcp_core.c tx tmr
6 Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
7 ---
8  drivers/net/ethernet/ti/netcp.h       |  5 +++
9  drivers/net/ethernet/ti/netcp_core.c  | 47 +++++++++++++++++++++++++++
10  drivers/net/ethernet/ti/netcp_ethss.c | 27 +++++++++++++++
11  3 files changed, 79 insertions(+)
13 diff --git a/drivers/net/ethernet/ti/netcp.h b/drivers/net/ethernet/ti/netcp.h
14 index fcb249c72274..3154808caf5d 100644
15 --- a/drivers/net/ethernet/ti/netcp.h
16 +++ b/drivers/net/ethernet/ti/netcp.h
17 @@ -130,6 +130,11 @@ struct netcp_intf {
18         /* DMA configuration data */
19         u32                     msg_enable;
20         u32                     rx_queue_depths[KNAV_DMA_FDQ_PER_CHAN];
21 +       struct hrtimer tx_hr_timer;
22 +       unsigned long tx_pace_timeout;
23 +       struct hrtimer rx_hr_timer;
24 +       unsigned long rx_pace_timeout;
25 +
26  };
27  
28  #define        NETCP_PSDATA_LEN                KNAV_DMA_NUM_PS_WORDS
29 diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c
30 index a1d335a3c5e4..9727a9717895 100644
31 --- a/drivers/net/ethernet/ti/netcp_core.c
32 +++ b/drivers/net/ethernet/ti/netcp_core.c
33 @@ -24,6 +24,8 @@
34  #include <linux/of_net.h>
35  #include <linux/of_address.h>
36  #include <linux/if_vlan.h>
37 +#include <linux/hrtimer.h>
38 +#include <linux/ktime.h>
39  #include <linux/pm_runtime.h>
40  #include <linux/platform_device.h>
41  #include <linux/soc/ti/knav_qmss.h>
42 @@ -958,19 +960,41 @@ static void netcp_rxpool_refill(struct netcp_intf *netcp)
43         } /* end for fdqs */
44  }
45  
46 +#define TX_TIMEOUT   1000000L  //1msec expressed in nano seconds
47 +
48 +#define TIMER_CALLBACK
49 +
50 +enum hrtimer_restart rx_timer_callback(struct hrtimer *timer)
51 +{
52 +       struct netcp_intf *netcp = container_of(timer, struct netcp_intf, rx_hr_timer);
53 +
54 +       knav_queue_enable_notify(netcp->rx_queue);
55 +       return HRTIMER_NORESTART;
56 +}
57 +
58  /* NAPI poll */
59  static int netcp_rx_poll(struct napi_struct *napi, int budget)
60  {
61         struct netcp_intf *netcp = container_of(napi, struct netcp_intf,
62                                                 rx_napi);
63         unsigned int packets;
64 +       ktime_t ktime;
65  
66         packets = netcp_process_rx_packets(netcp, budget);
67  
68         netcp_rxpool_refill(netcp);
69         if (packets < budget) {
70                 napi_complete_done(&netcp->rx_napi, packets);
71 +#ifdef TIMER_CALLBACK
72 +               if (netcp->rx_pace_timeout) {
73 +                       ktime = ktime_set(0, netcp->rx_pace_timeout);
74 +                       hrtimer_start(&netcp->rx_hr_timer, ktime, HRTIMER_MODE_REL);
75 +               } else {
76 +                       knav_queue_enable_notify(netcp->rx_queue);
77 +               }
78 +#else
79                 knav_queue_enable_notify(netcp->rx_queue);
80 +#endif
81         }
82  
83         return packets;
84 @@ -1069,16 +1093,34 @@ static int netcp_process_tx_compl_packets(struct netcp_intf *netcp,
85         return pkts;
86  }
87  
88 +enum hrtimer_restart tx_timer_callback(struct hrtimer *timer)
89 +{
90 +       struct netcp_intf *netcp = container_of(timer, struct netcp_intf, tx_hr_timer);
91 +
92 +       knav_queue_enable_notify(netcp->tx_compl_q);
93 +       return HRTIMER_NORESTART;
94 +}
95 +
96  static int netcp_tx_poll(struct napi_struct *napi, int budget)
97  {
98         int packets;
99         struct netcp_intf *netcp = container_of(napi, struct netcp_intf,
100                                                 tx_napi);
101 +       ktime_t ktime;
102  
103         packets = netcp_process_tx_compl_packets(netcp, budget);
104         if (packets < budget) {
105                 napi_complete(&netcp->tx_napi);
106 +#ifdef TIMER_CALLBACK
107 +               if (netcp->tx_pace_timeout) {
108 +                       ktime = ktime_set(0, netcp->tx_pace_timeout);
109 +                       hrtimer_start(&netcp->tx_hr_timer, ktime, HRTIMER_MODE_REL);
110 +               }  else {
111 +                       knav_queue_enable_notify(netcp->tx_compl_q);
112 +               }
113 +#else
114                 knav_queue_enable_notify(netcp->tx_compl_q);
115 +#endif
116         }
117  
118         return packets;
119 @@ -2116,6 +2158,11 @@ static int netcp_create_interface(struct netcp_device *netcp_device,
120         netif_napi_add(ndev, &netcp->rx_napi, netcp_rx_poll, NETCP_NAPI_WEIGHT);
121         netif_tx_napi_add(ndev, &netcp->tx_napi, netcp_tx_poll, NETCP_NAPI_WEIGHT);
122  
123 +       hrtimer_init(&netcp->tx_hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
124 +       netcp->tx_hr_timer.function = &tx_timer_callback;
125 +       hrtimer_init(&netcp->rx_hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
126 +       netcp->rx_hr_timer.function = &rx_timer_callback;
128         /* Register the network device */
129         ndev->dev_id            = 0;
130         ndev->watchdog_timeo    = NETCP_TX_TIMEOUT;
131 diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c
132 index c8290bd049f6..ae3737a951d3 100644
133 --- a/drivers/net/ethernet/ti/netcp_ethss.c
134 +++ b/drivers/net/ethernet/ti/netcp_ethss.c
135 @@ -1894,6 +1894,31 @@ static int keystone_get_ts_info(struct net_device *ndev,
136  }
137  #endif /* CONFIG_TI_CPTS */
138  
139 +int keystone_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *coal)
140 +{
141 +       struct netcp_intf *netcp = netdev_priv(ndev);
143 +       if (coal->rx_coalesce_usecs && coal->rx_coalesce_usecs < 500)
144 +               coal->rx_coalesce_usecs = 500;
146 +       if (coal->tx_coalesce_usecs && coal->tx_coalesce_usecs < 500)
147 +               coal->tx_coalesce_usecs = 500;
149 +       netcp->tx_pace_timeout = coal->tx_coalesce_usecs * 1000;
150 +       netcp->rx_pace_timeout = coal->rx_coalesce_usecs * 1000;
152 +       return 0;
153 +}
155 +int keystone_get_coalesce(struct net_device *ndev, struct ethtool_coalesce *coal)
156 +{
157 +       struct netcp_intf *netcp = netdev_priv(ndev);
159 +       coal->rx_coalesce_usecs = netcp->rx_pace_timeout/1000;
160 +       coal->tx_coalesce_usecs = netcp->tx_pace_timeout/1000;
161 +       return 0;
162 +}
164  static const struct ethtool_ops keystone_ethtool_ops = {
165         .get_drvinfo            = keystone_get_drvinfo,
166         .get_link               = ethtool_op_get_link,
167 @@ -1905,6 +1930,8 @@ static const struct ethtool_ops keystone_ethtool_ops = {
168         .get_link_ksettings     = keystone_get_link_ksettings,
169         .set_link_ksettings     = keystone_set_link_ksettings,
170         .get_ts_info            = keystone_get_ts_info,
171 +       .get_coalesce           = keystone_get_coalesce,
172 +       .set_coalesce           = keystone_set_coalesce,
173  };
174  
175  static void gbe_set_slave_mac(struct gbe_slave *slave,
176 -- 
177 2.17.1