mlxsw: spectrum_buffers: Reject overlarge headroom size requests
authorPetr Machata <petrm@mellanox.com>
Wed, 20 Feb 2019 19:32:29 +0000 (19:32 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 21 Feb 2019 23:57:46 +0000 (15:57 -0800)
cap_max_headroom_size holds maximum headroom size supported.
Overstepping that limit might under certain conditions lead to ASIC
freeze.

Query and store the value, and add mlxsw_sp_sb_max_headroom_cells() for
obtaining the stored value. In __mlxsw_sp_port_headroom_set(), reject
requests where the total port buffer is larger than the advertised
maximum.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/resources.h
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/spectrum.h
drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c

index b8b3a01c2a9ee0e281ef67d603a1822e38e62ee0..773ef7fdb2850cf8286e9ec0e6df74d3a6406210 100644 (file)
@@ -26,6 +26,7 @@ enum mlxsw_res_id {
        MLXSW_RES_ID_MAX_LAG_MEMBERS,
        MLXSW_RES_ID_MAX_BUFFER_SIZE,
        MLXSW_RES_ID_CELL_SIZE,
+       MLXSW_RES_ID_MAX_HEADROOM_SIZE,
        MLXSW_RES_ID_ACL_MAX_TCAM_REGIONS,
        MLXSW_RES_ID_ACL_MAX_TCAM_RULES,
        MLXSW_RES_ID_ACL_MAX_REGIONS,
@@ -79,6 +80,7 @@ static u16 mlxsw_res_ids[] = {
        [MLXSW_RES_ID_MAX_LAG_MEMBERS] = 0x2521,
        [MLXSW_RES_ID_MAX_BUFFER_SIZE] = 0x2802,        /* Bytes */
        [MLXSW_RES_ID_CELL_SIZE] = 0x2803,      /* Bytes */
+       [MLXSW_RES_ID_MAX_HEADROOM_SIZE] = 0x2811,      /* Bytes */
        [MLXSW_RES_ID_ACL_MAX_TCAM_REGIONS] = 0x2901,
        [MLXSW_RES_ID_ACL_MAX_TCAM_RULES] = 0x2902,
        [MLXSW_RES_ID_ACL_MAX_REGIONS] = 0x2903,
index c1ec4f89973b83b981c2acd199db4a2deee92292..f018b0607daca39eba4b5c4f578cbf06bff21c46 100644 (file)
@@ -852,8 +852,12 @@ int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
        u8 pfc_en = !!my_pfc ? my_pfc->pfc_en : 0;
        u16 delay = !!my_pfc ? my_pfc->delay : 0;
        char pbmc_pl[MLXSW_REG_PBMC_LEN];
+       u32 taken_headroom_cells = 0;
+       u32 max_headroom_cells;
        int i, j, err;
 
+       max_headroom_cells = mlxsw_sp_sb_max_headroom_cells(mlxsw_sp);
+
        mlxsw_reg_pbmc_pack(pbmc_pl, mlxsw_sp_port->local_port, 0, 0);
        err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(pbmc), pbmc_pl);
        if (err)
@@ -864,6 +868,7 @@ int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
                bool pfc = false;
                u16 thres_cells;
                u16 delay_cells;
+               u16 total_cells;
                bool lossy;
 
                for (j = 0; j < IEEE_8021QAZ_MAX_TCS; j++) {
@@ -881,7 +886,13 @@ int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
                thres_cells = mlxsw_sp_pg_buf_threshold_get(mlxsw_sp, mtu);
                delay_cells = mlxsw_sp_pg_buf_delay_get(mlxsw_sp, mtu, delay,
                                                        pfc, pause_en);
-               mlxsw_sp_pg_buf_pack(pbmc_pl, i, thres_cells + delay_cells,
+               total_cells = thres_cells + delay_cells;
+
+               taken_headroom_cells += total_cells;
+               if (taken_headroom_cells > max_headroom_cells)
+                       return -ENOBUFS;
+
+               mlxsw_sp_pg_buf_pack(pbmc_pl, i, total_cells,
                                     thres_cells, lossy);
        }
 
index 976843917c95d091dc47b8d6ec1f0ca88d114298..8bb83d0facc2dc1c1057c74eff35408336096b5b 100644 (file)
@@ -373,6 +373,7 @@ int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
                                     u32 *p_cur, u32 *p_max);
 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
+u32 mlxsw_sp_sb_max_headroom_cells(const struct mlxsw_sp *mlxsw_sp);
 
 extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals;
 extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals;
index 65ef4a9f6afb25e73ded2a891e845bba7f73c4be..9a79b5e1159743a9b619407cd3b9b9af065c97ca 100644 (file)
@@ -85,6 +85,7 @@ struct mlxsw_sp_sb {
        struct mlxsw_sp_sb_pr *prs;
        struct mlxsw_sp_sb_port *ports;
        u32 cell_size;
+       u32 max_headroom_cells;
        u64 sb_size;
 };
 
@@ -113,6 +114,11 @@ u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes)
        return DIV_ROUND_UP(bytes, mlxsw_sp->sb->cell_size);
 }
 
+u32 mlxsw_sp_sb_max_headroom_cells(const struct mlxsw_sp *mlxsw_sp)
+{
+       return mlxsw_sp->sb->max_headroom_cells;
+}
+
 static struct mlxsw_sp_sb_pr *mlxsw_sp_sb_pr_get(struct mlxsw_sp *mlxsw_sp,
                                                 u16 pool_index)
 {
@@ -789,6 +795,7 @@ const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals = {
 
 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp)
 {
+       u32 max_headroom_size;
        u16 ing_pool_count;
        u16 eg_pool_count;
        int err;
@@ -799,12 +806,21 @@ int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp)
        if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_BUFFER_SIZE))
                return -EIO;
 
+       if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_HEADROOM_SIZE))
+               return -EIO;
+
        mlxsw_sp->sb = kzalloc(sizeof(*mlxsw_sp->sb), GFP_KERNEL);
        if (!mlxsw_sp->sb)
                return -ENOMEM;
        mlxsw_sp->sb->cell_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, CELL_SIZE);
        mlxsw_sp->sb->sb_size = MLXSW_CORE_RES_GET(mlxsw_sp->core,
                                                   MAX_BUFFER_SIZE);
+       max_headroom_size = MLXSW_CORE_RES_GET(mlxsw_sp->core,
+                                              MAX_HEADROOM_SIZE);
+       /* Round down, because this limit must not be overstepped. */
+       mlxsw_sp->sb->max_headroom_cells = max_headroom_size /
+                                               mlxsw_sp->sb->cell_size;
+
        err = mlxsw_sp_sb_ports_init(mlxsw_sp);
        if (err)
                goto err_sb_ports_init;