From: Petr Machata <pe...@nvidia.com>

So far, port buffers were always autoconfigured. When dcbnl_setbuffer
callback is implemented, it will allow the user to change the buffer size
configuration by hand. The sizes therefore need to be a configuration
parameter, not always deduced, and therefore belong to struct
mlxsw_sp_hdroom, where the configuration routine should take them from.

Update mlxsw_sp_port_headroom_set() to update these sizes. Have the
function update the sizes even for the case that a given buffer is not
used.

Additionally, change the loop iteration end to DCBX_MAX_BUFFERS instead of
IEEE_8021QAZ_MAX_TCS. The value is the same, but the semantics differ.

Signed-off-by: Petr Machata <pe...@nvidia.com>
Reviewed-by: Jiri Pirko <j...@nvidia.com>
Signed-off-by: Ido Schimmel <ido...@nvidia.com>
---
 .../net/ethernet/mellanox/mlxsw/spectrum.c    | 19 ++++++++++++++-----
 .../net/ethernet/mellanox/mlxsw/spectrum.h    |  2 ++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index f891ddf19dbc..533793a15621 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -671,19 +671,28 @@ int mlxsw_sp_port_headroom_set(struct mlxsw_sp_port 
*mlxsw_sp_port,
        if (err)
                return err;
 
-       for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
+       for (i = 0; i < DCBX_MAX_BUFFERS; i++) {
                struct mlxsw_sp_hdroom_buf *buf = &hdroom->bufs.buf[i];
                u16 thres_cells;
                u16 delay_cells;
                u16 total_cells;
 
-               if (!mlxsw_sp_hdroom_buf_is_used(hdroom, i))
-                       continue;
+               if (!mlxsw_sp_hdroom_buf_is_used(hdroom, i)) {
+                       thres_cells = 0;
+                       delay_cells = 0;
+               } else if (buf->lossy) {
+                       thres_cells = mlxsw_sp_pg_buf_threshold_get(mlxsw_sp, 
hdroom->mtu);
+                       delay_cells = 0;
+               } else {
+                       thres_cells = mlxsw_sp_pg_buf_threshold_get(mlxsw_sp, 
hdroom->mtu);
+                       delay_cells = mlxsw_sp_hdroom_buf_delay_get(mlxsw_sp, 
hdroom);
+               }
 
-               thres_cells = mlxsw_sp_pg_buf_threshold_get(mlxsw_sp, 
hdroom->mtu);
                thres_cells = mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, 
thres_cells);
-               delay_cells = mlxsw_sp_hdroom_buf_delay_get(mlxsw_sp, hdroom);
                delay_cells = mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, 
delay_cells);
+
+               buf->thres_cells = thres_cells;
+               buf->size_cells = thres_cells + delay_cells;
                total_cells = thres_cells + delay_cells;
 
                taken_headroom_cells += total_cells;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
index 5245367d6fb2..b3c9cdcc7a06 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -447,6 +447,8 @@ struct mlxsw_sp_hdroom_prio {
 };
 
 struct mlxsw_sp_hdroom_buf {
+       u32 thres_cells;
+       u32 size_cells;
        bool lossy;
 };
 
-- 
2.26.2

Reply via email to