mlxsw: core: Add devlink shared buffer occupancy callbacks
authorJiri Pirko <jiri@mellanox.com>
Thu, 14 Apr 2016 16:19:25 +0000 (18:19 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 14 Apr 2016 20:22:05 +0000 (16:22 -0400)
Add middle layer in mlxsw core code to forward shared buffer occupancy
calls into specific ASIC drivers.

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

index 1278260..63a9777 100644 (file)
@@ -911,15 +911,73 @@ mlxsw_devlink_sb_tc_pool_bind_set(struct devlink_port *devlink_port,
                                                 pool_index, threshold);
 }
 
+static int mlxsw_devlink_sb_occ_snapshot(struct devlink *devlink,
+                                        unsigned int sb_index)
+{
+       struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
+       struct mlxsw_driver *mlxsw_driver = mlxsw_core->driver;
+
+       if (!mlxsw_driver->sb_occ_snapshot)
+               return -EOPNOTSUPP;
+       return mlxsw_driver->sb_occ_snapshot(mlxsw_core, sb_index);
+}
+
+static int mlxsw_devlink_sb_occ_max_clear(struct devlink *devlink,
+                                         unsigned int sb_index)
+{
+       struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
+       struct mlxsw_driver *mlxsw_driver = mlxsw_core->driver;
+
+       if (!mlxsw_driver->sb_occ_max_clear)
+               return -EOPNOTSUPP;
+       return mlxsw_driver->sb_occ_max_clear(mlxsw_core, sb_index);
+}
+
+static int
+mlxsw_devlink_sb_occ_port_pool_get(struct devlink_port *devlink_port,
+                                  unsigned int sb_index, u16 pool_index,
+                                  u32 *p_cur, u32 *p_max)
+{
+       struct mlxsw_core *mlxsw_core = devlink_priv(devlink_port->devlink);
+       struct mlxsw_driver *mlxsw_driver = mlxsw_core->driver;
+       struct mlxsw_core_port *mlxsw_core_port = __dl_port(devlink_port);
+
+       if (!mlxsw_driver->sb_occ_port_pool_get)
+               return -EOPNOTSUPP;
+       return mlxsw_driver->sb_occ_port_pool_get(mlxsw_core_port, sb_index,
+                                                 pool_index, p_cur, p_max);
+}
+
+static int
+mlxsw_devlink_sb_occ_tc_port_bind_get(struct devlink_port *devlink_port,
+                                     unsigned int sb_index, u16 tc_index,
+                                     enum devlink_sb_pool_type pool_type,
+                                     u32 *p_cur, u32 *p_max)
+{
+       struct mlxsw_core *mlxsw_core = devlink_priv(devlink_port->devlink);
+       struct mlxsw_driver *mlxsw_driver = mlxsw_core->driver;
+       struct mlxsw_core_port *mlxsw_core_port = __dl_port(devlink_port);
+
+       if (!mlxsw_driver->sb_occ_tc_port_bind_get)
+               return -EOPNOTSUPP;
+       return mlxsw_driver->sb_occ_tc_port_bind_get(mlxsw_core_port,
+                                                    sb_index, tc_index,
+                                                    pool_type, p_cur, p_max);
+}
+
 static const struct devlink_ops mlxsw_devlink_ops = {
-       .port_split             = mlxsw_devlink_port_split,
-       .port_unsplit           = mlxsw_devlink_port_unsplit,
-       .sb_pool_get            = mlxsw_devlink_sb_pool_get,
-       .sb_pool_set            = mlxsw_devlink_sb_pool_set,
-       .sb_port_pool_get       = mlxsw_devlink_sb_port_pool_get,
-       .sb_port_pool_set       = mlxsw_devlink_sb_port_pool_set,
-       .sb_tc_pool_bind_get    = mlxsw_devlink_sb_tc_pool_bind_get,
-       .sb_tc_pool_bind_set    = mlxsw_devlink_sb_tc_pool_bind_set,
+       .port_split                     = mlxsw_devlink_port_split,
+       .port_unsplit                   = mlxsw_devlink_port_unsplit,
+       .sb_pool_get                    = mlxsw_devlink_sb_pool_get,
+       .sb_pool_set                    = mlxsw_devlink_sb_pool_set,
+       .sb_port_pool_get               = mlxsw_devlink_sb_port_pool_get,
+       .sb_port_pool_set               = mlxsw_devlink_sb_port_pool_set,
+       .sb_tc_pool_bind_get            = mlxsw_devlink_sb_tc_pool_bind_get,
+       .sb_tc_pool_bind_set            = mlxsw_devlink_sb_tc_pool_bind_set,
+       .sb_occ_snapshot                = mlxsw_devlink_sb_occ_snapshot,
+       .sb_occ_max_clear               = mlxsw_devlink_sb_occ_max_clear,
+       .sb_occ_port_pool_get           = mlxsw_devlink_sb_occ_port_pool_get,
+       .sb_occ_tc_port_bind_get        = mlxsw_devlink_sb_occ_tc_port_bind_get,
 };
 
 int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
index d0c471f..377dacc 100644 (file)
@@ -229,6 +229,17 @@ struct mlxsw_driver {
                                   unsigned int sb_index, u16 tc_index,
                                   enum devlink_sb_pool_type pool_type,
                                   u16 pool_index, u32 threshold);
+       int (*sb_occ_snapshot)(struct mlxsw_core *mlxsw_core,
+                              unsigned int sb_index);
+       int (*sb_occ_max_clear)(struct mlxsw_core *mlxsw_core,
+                               unsigned int sb_index);
+       int (*sb_occ_port_pool_get)(struct mlxsw_core_port *mlxsw_core_port,
+                                   unsigned int sb_index, u16 pool_index,
+                                   u32 *p_cur, u32 *p_max);
+       int (*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);
        void (*txhdr_construct)(struct sk_buff *skb,
                                const struct mlxsw_tx_info *tx_info);
        u8 txhdr_len;