]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
mlxsw: spectrum_buffer: Reduce scope of shared buffer struct
authorIdo Schimmel <idosch@mellanox.com>
Tue, 16 May 2017 17:38:24 +0000 (19:38 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 17 May 2017 18:06:54 +0000 (14:06 -0400)
The shared buffer structure ('mlxsw_sp_sb') doesn't need to be
accessible to anyone, but the shared buffer code located at
spectrum_buffers.c

Make this apparent and reduce its scope by defining it there.

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

index 0c23bc1e946df52c729471be138eae3b8de783ad..976f5b6435761bd0f3ed31da6067df5d43826163 100644 (file)
@@ -110,43 +110,6 @@ static inline bool mlxsw_sp_fid_is_vfid(u16 fid)
        return fid >= MLXSW_SP_VFID_BASE && fid < MLXSW_SP_DUMMY_FID;
 }
 
-struct mlxsw_sp_sb_pr {
-       enum mlxsw_reg_sbpr_mode mode;
-       u32 size;
-};
-
-struct mlxsw_cp_sb_occ {
-       u32 cur;
-       u32 max;
-};
-
-struct mlxsw_sp_sb_cm {
-       u32 min_buff;
-       u32 max_buff;
-       u8 pool;
-       struct mlxsw_cp_sb_occ occ;
-};
-
-struct mlxsw_sp_sb_pm {
-       u32 min_buff;
-       u32 max_buff;
-       struct mlxsw_cp_sb_occ occ;
-};
-
-#define MLXSW_SP_SB_POOL_COUNT 4
-#define MLXSW_SP_SB_TC_COUNT   8
-
-struct mlxsw_sp_sb_port {
-       struct mlxsw_sp_sb_cm cms[2][MLXSW_SP_SB_TC_COUNT];
-       struct mlxsw_sp_sb_pm pms[2][MLXSW_SP_SB_POOL_COUNT];
-};
-
-struct mlxsw_sp_sb {
-       struct mlxsw_sp_sb_pr prs[2][MLXSW_SP_SB_POOL_COUNT];
-       struct mlxsw_sp_sb_port *ports;
-       u32 cell_size;
-};
-
 #define MLXSW_SP_PREFIX_COUNT (sizeof(struct in6_addr) * BITS_PER_BYTE)
 
 struct mlxsw_sp_prefix_usage {
@@ -231,6 +194,7 @@ struct mlxsw_sp_router {
        bool aborted;
 };
 
+struct mlxsw_sp_sb;
 struct mlxsw_sp_acl;
 struct mlxsw_sp_counter_pool;
 
@@ -261,7 +225,7 @@ struct mlxsw_sp {
        struct mlxsw_sp_upper master_bridge;
        struct mlxsw_sp_upper *lags;
        u8 *port_to_module;
-       struct mlxsw_sp_sb sb;
+       struct mlxsw_sp_sb *sb;
        struct mlxsw_sp_router router;
        struct mlxsw_sp_acl *acl;
        struct {
@@ -282,18 +246,6 @@ mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
        return &mlxsw_sp->lags[lag_id];
 }
 
-static inline u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp,
-                                      u32 cells)
-{
-       return mlxsw_sp->sb.cell_size * cells;
-}
-
-static inline u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp,
-                                      u32 bytes)
-{
-       return DIV_ROUND_UP(bytes, mlxsw_sp->sb.cell_size);
-}
-
 struct mlxsw_sp_port_pcpu_stats {
        u64                     rx_packets;
        u64                     rx_bytes;
@@ -515,6 +467,8 @@ int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
                                     unsigned int sb_index, u16 tc_index,
                                     enum devlink_sb_pool_type pool_type,
                                     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);
 
 int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
 void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
index 997189cfe7fd58c7e93419d69cf609420eb1633f..93728c694e6df9985cadfccf72ab6f3a9f52f8da 100644 (file)
 #include "port.h"
 #include "reg.h"
 
+struct mlxsw_sp_sb_pr {
+       enum mlxsw_reg_sbpr_mode mode;
+       u32 size;
+};
+
+struct mlxsw_cp_sb_occ {
+       u32 cur;
+       u32 max;
+};
+
+struct mlxsw_sp_sb_cm {
+       u32 min_buff;
+       u32 max_buff;
+       u8 pool;
+       struct mlxsw_cp_sb_occ occ;
+};
+
+struct mlxsw_sp_sb_pm {
+       u32 min_buff;
+       u32 max_buff;
+       struct mlxsw_cp_sb_occ occ;
+};
+
+#define MLXSW_SP_SB_POOL_COUNT 4
+#define MLXSW_SP_SB_TC_COUNT   8
+
+struct mlxsw_sp_sb_port {
+       struct mlxsw_sp_sb_cm cms[2][MLXSW_SP_SB_TC_COUNT];
+       struct mlxsw_sp_sb_pm pms[2][MLXSW_SP_SB_POOL_COUNT];
+};
+
+struct mlxsw_sp_sb {
+       struct mlxsw_sp_sb_pr prs[2][MLXSW_SP_SB_POOL_COUNT];
+       struct mlxsw_sp_sb_port *ports;
+       u32 cell_size;
+};
+
+u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells)
+{
+       return mlxsw_sp->sb->cell_size * cells;
+}
+
+u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes)
+{
+       return DIV_ROUND_UP(bytes, mlxsw_sp->sb->cell_size);
+}
+
 static struct mlxsw_sp_sb_pr *mlxsw_sp_sb_pr_get(struct mlxsw_sp *mlxsw_sp,
                                                 u8 pool,
                                                 enum mlxsw_reg_sbxx_dir dir)
 {
-       return &mlxsw_sp->sb.prs[dir][pool];
+       return &mlxsw_sp->sb->prs[dir][pool];
 }
 
 static struct mlxsw_sp_sb_cm *mlxsw_sp_sb_cm_get(struct mlxsw_sp *mlxsw_sp,
                                                 u8 local_port, u8 pg_buff,
                                                 enum mlxsw_reg_sbxx_dir dir)
 {
-       return &mlxsw_sp->sb.ports[local_port].cms[dir][pg_buff];
+       return &mlxsw_sp->sb->ports[local_port].cms[dir][pg_buff];
 }
 
 static struct mlxsw_sp_sb_pm *mlxsw_sp_sb_pm_get(struct mlxsw_sp *mlxsw_sp,
                                                 u8 local_port, u8 pool,
                                                 enum mlxsw_reg_sbxx_dir dir)
 {
-       return &mlxsw_sp->sb.ports[local_port].pms[dir][pool];
+       return &mlxsw_sp->sb->ports[local_port].pms[dir][pool];
 }
 
 static int mlxsw_sp_sb_pr_write(struct mlxsw_sp *mlxsw_sp, u8 pool,
@@ -215,16 +262,17 @@ static int mlxsw_sp_sb_ports_init(struct mlxsw_sp *mlxsw_sp)
 {
        unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core);
 
-       mlxsw_sp->sb.ports = kcalloc(max_ports, sizeof(struct mlxsw_sp_sb_port),
-                                    GFP_KERNEL);
-       if (!mlxsw_sp->sb.ports)
+       mlxsw_sp->sb->ports = kcalloc(max_ports,
+                                     sizeof(struct mlxsw_sp_sb_port),
+                                     GFP_KERNEL);
+       if (!mlxsw_sp->sb->ports)
                return -ENOMEM;
        return 0;
 }
 
 static void mlxsw_sp_sb_ports_fini(struct mlxsw_sp *mlxsw_sp)
 {
-       kfree(mlxsw_sp->sb.ports);
+       kfree(mlxsw_sp->sb->ports);
 }
 
 #define MLXSW_SP_SB_PR_INGRESS_SIZE    12440000
@@ -551,15 +599,19 @@ int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp)
 
        if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, CELL_SIZE))
                return -EIO;
-       mlxsw_sp->sb.cell_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, CELL_SIZE);
 
        if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_BUFFER_SIZE))
                return -EIO;
        sb_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_BUFFER_SIZE);
 
+       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);
+
        err = mlxsw_sp_sb_ports_init(mlxsw_sp);
        if (err)
-               return err;
+               goto err_sb_ports_init;
        err = mlxsw_sp_sb_prs_init(mlxsw_sp);
        if (err)
                goto err_sb_prs_init;
@@ -584,6 +636,8 @@ err_sb_mms_init:
 err_sb_cpu_port_sb_cms_init:
 err_sb_prs_init:
        mlxsw_sp_sb_ports_fini(mlxsw_sp);
+err_sb_ports_init:
+       kfree(mlxsw_sp->sb);
        return err;
 }
 
@@ -591,6 +645,7 @@ void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp)
 {
        devlink_sb_unregister(priv_to_devlink(mlxsw_sp->core), 0);
        mlxsw_sp_sb_ports_fini(mlxsw_sp);
+       kfree(mlxsw_sp->sb);
 }
 
 int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port)