提交 0a0ab1d2 编写于 作者: E Eli Cohen 提交者: Saeed Mahameed

net/mlx5: E-Switch, Avoid redundant memory allocation

struct esw_mc_addr is a small struct that can be part of struct
mlx5_eswitch. Define it as a field and not as a pointer and save the
kzalloc call and then error flow handling.
Signed-off-by: NEli Cohen <eli@mellanox.com>
Signed-off-by: NSaeed Mahameed <saeedm@mellanox.com>
上级 0f6e4cf6
...@@ -53,13 +53,6 @@ struct esw_uc_addr { ...@@ -53,13 +53,6 @@ struct esw_uc_addr {
u32 vport; u32 vport;
}; };
/* E-Switch MC FDB table hash node */
struct esw_mc_addr { /* SRIOV only */
struct l2addr_node node;
struct mlx5_flow_handle *uplink_rule; /* Forward to uplink rule */
u32 refcnt;
};
/* Vport UC/MC hash node */ /* Vport UC/MC hash node */
struct vport_addr { struct vport_addr {
struct l2addr_node node; struct l2addr_node node;
...@@ -817,7 +810,7 @@ static void esw_update_vport_mc_promisc(struct mlx5_eswitch *esw, u32 vport_num) ...@@ -817,7 +810,7 @@ static void esw_update_vport_mc_promisc(struct mlx5_eswitch *esw, u32 vport_num)
static void esw_apply_vport_rx_mode(struct mlx5_eswitch *esw, u32 vport_num, static void esw_apply_vport_rx_mode(struct mlx5_eswitch *esw, u32 vport_num,
bool promisc, bool mc_promisc) bool promisc, bool mc_promisc)
{ {
struct esw_mc_addr *allmulti_addr = esw->mc_promisc; struct esw_mc_addr *allmulti_addr = &esw->mc_promisc;
struct mlx5_vport *vport = &esw->vports[vport_num]; struct mlx5_vport *vport = &esw->vports[vport_num];
if (IS_ERR_OR_NULL(vport->allmulti_rule) != mc_promisc) if (IS_ERR_OR_NULL(vport->allmulti_rule) != mc_promisc)
...@@ -1688,7 +1681,7 @@ void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw) ...@@ -1688,7 +1681,7 @@ void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw)
esw_info(esw->dev, "disable SRIOV: active vports(%d) mode(%d)\n", esw_info(esw->dev, "disable SRIOV: active vports(%d) mode(%d)\n",
esw->enabled_vports, esw->mode); esw->enabled_vports, esw->mode);
mc_promisc = esw->mc_promisc; mc_promisc = &esw->mc_promisc;
nvports = esw->enabled_vports; nvports = esw->enabled_vports;
for (i = 0; i < esw->total_vports; i++) for (i = 0; i < esw->total_vports; i++)
...@@ -1732,7 +1725,6 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev) ...@@ -1732,7 +1725,6 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)
{ {
int l2_table_size = 1 << MLX5_CAP_GEN(dev, log_max_l2_table); int l2_table_size = 1 << MLX5_CAP_GEN(dev, log_max_l2_table);
int total_vports = MLX5_TOTAL_VPORTS(dev); int total_vports = MLX5_TOTAL_VPORTS(dev);
struct esw_mc_addr *mc_promisc;
struct mlx5_eswitch *esw; struct mlx5_eswitch *esw;
int vport_num; int vport_num;
int err; int err;
...@@ -1761,13 +1753,6 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev) ...@@ -1761,13 +1753,6 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)
} }
esw->l2_table.size = l2_table_size; esw->l2_table.size = l2_table_size;
mc_promisc = kzalloc(sizeof(*mc_promisc), GFP_KERNEL);
if (!mc_promisc) {
err = -ENOMEM;
goto abort;
}
esw->mc_promisc = mc_promisc;
esw->work_queue = create_singlethread_workqueue("mlx5_esw_wq"); esw->work_queue = create_singlethread_workqueue("mlx5_esw_wq");
if (!esw->work_queue) { if (!esw->work_queue) {
err = -ENOMEM; err = -ENOMEM;
...@@ -1835,7 +1820,6 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw) ...@@ -1835,7 +1820,6 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw)
esw->dev->priv.eswitch = NULL; esw->dev->priv.eswitch = NULL;
destroy_workqueue(esw->work_queue); destroy_workqueue(esw->work_queue);
kfree(esw->l2_table.bitmap); kfree(esw->l2_table.bitmap);
kfree(esw->mc_promisc);
kfree(esw->offloads.vport_reps); kfree(esw->offloads.vport_reps);
kfree(esw->vports); kfree(esw->vports);
kfree(esw); kfree(esw);
......
...@@ -212,6 +212,13 @@ struct mlx5_esw_offload { ...@@ -212,6 +212,13 @@ struct mlx5_esw_offload {
u8 encap; u8 encap;
}; };
/* E-Switch MC FDB table hash node */
struct esw_mc_addr { /* SRIOV only */
struct l2addr_node node;
struct mlx5_flow_handle *uplink_rule; /* Forward to uplink rule */
u32 refcnt;
};
struct mlx5_eswitch { struct mlx5_eswitch {
struct mlx5_core_dev *dev; struct mlx5_core_dev *dev;
struct mlx5_l2_table l2_table; struct mlx5_l2_table l2_table;
...@@ -225,7 +232,7 @@ struct mlx5_eswitch { ...@@ -225,7 +232,7 @@ struct mlx5_eswitch {
* and async SRIOV admin state changes * and async SRIOV admin state changes
*/ */
struct mutex state_lock; struct mutex state_lock;
struct esw_mc_addr *mc_promisc; struct esw_mc_addr mc_promisc;
struct { struct {
bool enabled; bool enabled;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册