|
8 | 8 | #include "wx_type.h" |
9 | 9 | #include "wx_ethtool.h" |
10 | 10 | #include "wx_hw.h" |
| 11 | +#include "wx_lib.h" |
11 | 12 |
|
12 | 13 | struct wx_stats { |
13 | 14 | char stat_string[ETH_GSTRING_LEN]; |
@@ -247,3 +248,103 @@ void wx_get_ringparam(struct net_device *netdev, |
247 | 248 | ring->rx_jumbo_pending = 0; |
248 | 249 | } |
249 | 250 | EXPORT_SYMBOL(wx_get_ringparam); |
| 251 | + |
| 252 | +int wx_get_coalesce(struct net_device *netdev, |
| 253 | + struct ethtool_coalesce *ec, |
| 254 | + struct kernel_ethtool_coalesce *kernel_coal, |
| 255 | + struct netlink_ext_ack *extack) |
| 256 | +{ |
| 257 | + struct wx *wx = netdev_priv(netdev); |
| 258 | + |
| 259 | + ec->tx_max_coalesced_frames_irq = wx->tx_work_limit; |
| 260 | + /* only valid if in constant ITR mode */ |
| 261 | + if (wx->rx_itr_setting <= 1) |
| 262 | + ec->rx_coalesce_usecs = wx->rx_itr_setting; |
| 263 | + else |
| 264 | + ec->rx_coalesce_usecs = wx->rx_itr_setting >> 2; |
| 265 | + |
| 266 | + /* if in mixed tx/rx queues per vector mode, report only rx settings */ |
| 267 | + if (wx->q_vector[0]->tx.count && wx->q_vector[0]->rx.count) |
| 268 | + return 0; |
| 269 | + |
| 270 | + /* only valid if in constant ITR mode */ |
| 271 | + if (wx->tx_itr_setting <= 1) |
| 272 | + ec->tx_coalesce_usecs = wx->tx_itr_setting; |
| 273 | + else |
| 274 | + ec->tx_coalesce_usecs = wx->tx_itr_setting >> 2; |
| 275 | + |
| 276 | + return 0; |
| 277 | +} |
| 278 | +EXPORT_SYMBOL(wx_get_coalesce); |
| 279 | + |
| 280 | +int wx_set_coalesce(struct net_device *netdev, |
| 281 | + struct ethtool_coalesce *ec, |
| 282 | + struct kernel_ethtool_coalesce *kernel_coal, |
| 283 | + struct netlink_ext_ack *extack) |
| 284 | +{ |
| 285 | + struct wx *wx = netdev_priv(netdev); |
| 286 | + u16 tx_itr_param, rx_itr_param; |
| 287 | + struct wx_q_vector *q_vector; |
| 288 | + u16 max_eitr; |
| 289 | + int i; |
| 290 | + |
| 291 | + if (wx->q_vector[0]->tx.count && wx->q_vector[0]->rx.count) { |
| 292 | + /* reject Tx specific changes in case of mixed RxTx vectors */ |
| 293 | + if (ec->tx_coalesce_usecs) |
| 294 | + return -EOPNOTSUPP; |
| 295 | + } |
| 296 | + |
| 297 | + if (ec->tx_max_coalesced_frames_irq) |
| 298 | + wx->tx_work_limit = ec->tx_max_coalesced_frames_irq; |
| 299 | + |
| 300 | + if (wx->mac.type == wx_mac_sp) |
| 301 | + max_eitr = WX_SP_MAX_EITR; |
| 302 | + else |
| 303 | + max_eitr = WX_EM_MAX_EITR; |
| 304 | + |
| 305 | + if ((ec->rx_coalesce_usecs > (max_eitr >> 2)) || |
| 306 | + (ec->tx_coalesce_usecs > (max_eitr >> 2))) |
| 307 | + return -EINVAL; |
| 308 | + |
| 309 | + if (ec->rx_coalesce_usecs > 1) |
| 310 | + wx->rx_itr_setting = ec->rx_coalesce_usecs << 2; |
| 311 | + else |
| 312 | + wx->rx_itr_setting = ec->rx_coalesce_usecs; |
| 313 | + |
| 314 | + if (wx->rx_itr_setting == 1) |
| 315 | + rx_itr_param = WX_20K_ITR; |
| 316 | + else |
| 317 | + rx_itr_param = wx->rx_itr_setting; |
| 318 | + |
| 319 | + if (ec->tx_coalesce_usecs > 1) |
| 320 | + wx->tx_itr_setting = ec->tx_coalesce_usecs << 2; |
| 321 | + else |
| 322 | + wx->tx_itr_setting = ec->tx_coalesce_usecs; |
| 323 | + |
| 324 | + if (wx->tx_itr_setting == 1) { |
| 325 | + if (wx->mac.type == wx_mac_sp) |
| 326 | + tx_itr_param = WX_12K_ITR; |
| 327 | + else |
| 328 | + tx_itr_param = WX_20K_ITR; |
| 329 | + } else { |
| 330 | + tx_itr_param = wx->tx_itr_setting; |
| 331 | + } |
| 332 | + |
| 333 | + /* mixed Rx/Tx */ |
| 334 | + if (wx->q_vector[0]->tx.count && wx->q_vector[0]->rx.count) |
| 335 | + wx->tx_itr_setting = wx->rx_itr_setting; |
| 336 | + |
| 337 | + for (i = 0; i < wx->num_q_vectors; i++) { |
| 338 | + q_vector = wx->q_vector[i]; |
| 339 | + if (q_vector->tx.count && !q_vector->rx.count) |
| 340 | + /* tx only */ |
| 341 | + q_vector->itr = tx_itr_param; |
| 342 | + else |
| 343 | + /* rx only or mixed */ |
| 344 | + q_vector->itr = rx_itr_param; |
| 345 | + wx_write_eitr(q_vector); |
| 346 | + } |
| 347 | + |
| 348 | + return 0; |
| 349 | +} |
| 350 | +EXPORT_SYMBOL(wx_set_coalesce); |
0 commit comments