lan966x_cbs.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include "lan966x_main.h"
  3. int lan966x_cbs_add(struct lan966x_port *port,
  4. struct tc_cbs_qopt_offload *qopt)
  5. {
  6. struct lan966x *lan966x = port->lan966x;
  7. u32 cir, cbs;
  8. u8 se_idx;
  9. /* Check for invalid values */
  10. if (qopt->idleslope <= 0 ||
  11. qopt->sendslope >= 0 ||
  12. qopt->locredit >= qopt->hicredit)
  13. return -EINVAL;
  14. se_idx = SE_IDX_QUEUE + port->chip_port * NUM_PRIO_QUEUES + qopt->queue;
  15. cir = qopt->idleslope;
  16. cbs = (qopt->idleslope - qopt->sendslope) *
  17. (qopt->hicredit - qopt->locredit) /
  18. -qopt->sendslope;
  19. /* Rate unit is 100 kbps */
  20. cir = DIV_ROUND_UP(cir, 100);
  21. /* Avoid using zero rate */
  22. cir = cir ?: 1;
  23. /* Burst unit is 4kB */
  24. cbs = DIV_ROUND_UP(cbs, 4096);
  25. /* Avoid using zero burst */
  26. cbs = cbs ?: 1;
  27. /* Check that actually the result can be written */
  28. if (cir > GENMASK(15, 0) ||
  29. cbs > GENMASK(6, 0))
  30. return -EINVAL;
  31. lan_rmw(QSYS_SE_CFG_SE_AVB_ENA_SET(1) |
  32. QSYS_SE_CFG_SE_FRM_MODE_SET(1),
  33. QSYS_SE_CFG_SE_AVB_ENA |
  34. QSYS_SE_CFG_SE_FRM_MODE,
  35. lan966x, QSYS_SE_CFG(se_idx));
  36. lan_wr(QSYS_CIR_CFG_CIR_RATE_SET(cir) |
  37. QSYS_CIR_CFG_CIR_BURST_SET(cbs),
  38. lan966x, QSYS_CIR_CFG(se_idx));
  39. return 0;
  40. }
  41. int lan966x_cbs_del(struct lan966x_port *port,
  42. struct tc_cbs_qopt_offload *qopt)
  43. {
  44. struct lan966x *lan966x = port->lan966x;
  45. u8 se_idx;
  46. se_idx = SE_IDX_QUEUE + port->chip_port * NUM_PRIO_QUEUES + qopt->queue;
  47. lan_rmw(QSYS_SE_CFG_SE_AVB_ENA_SET(1) |
  48. QSYS_SE_CFG_SE_FRM_MODE_SET(0),
  49. QSYS_SE_CFG_SE_AVB_ENA |
  50. QSYS_SE_CFG_SE_FRM_MODE,
  51. lan966x, QSYS_SE_CFG(se_idx));
  52. lan_wr(QSYS_CIR_CFG_CIR_RATE_SET(0) |
  53. QSYS_CIR_CFG_CIR_BURST_SET(0),
  54. lan966x, QSYS_CIR_CFG(se_idx));
  55. return 0;
  56. }