lkml.org 
[lkml]   [2022]   [Jul]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[net-next PATCH v2 09/15] net: dsa: qca8k: move port FDB function to common code
    Date
    The same port FDB function are used by drivers based on qca8k family
    switch. Move them to common code to make them accessible also by other
    drivers.

    Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
    ---
    drivers/net/dsa/qca/qca8k-8xxx.c | 61 ------------------------------
    drivers/net/dsa/qca/qca8k-common.c | 61 ++++++++++++++++++++++++++++++
    drivers/net/dsa/qca/qca8k.h | 12 ++++++
    3 files changed, 73 insertions(+), 61 deletions(-)

    diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
    index 95bf65121ed6..4de69a79cc5c 100644
    --- a/drivers/net/dsa/qca/qca8k-8xxx.c
    +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
    @@ -1575,67 +1575,6 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data)
    return ret;
    }

    -static int
    -qca8k_port_fdb_insert(struct qca8k_priv *priv, const u8 *addr,
    - u16 port_mask, u16 vid)
    -{
    - /* Set the vid to the port vlan id if no vid is set */
    - if (!vid)
    - vid = QCA8K_PORT_VID_DEF;
    -
    - return qca8k_fdb_add(priv, addr, port_mask, vid,
    - QCA8K_ATU_STATUS_STATIC);
    -}
    -
    -static int
    -qca8k_port_fdb_add(struct dsa_switch *ds, int port,
    - const unsigned char *addr, u16 vid,
    - struct dsa_db db)
    -{
    - struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
    - u16 port_mask = BIT(port);
    -
    - return qca8k_port_fdb_insert(priv, addr, port_mask, vid);
    -}
    -
    -static int
    -qca8k_port_fdb_del(struct dsa_switch *ds, int port,
    - const unsigned char *addr, u16 vid,
    - struct dsa_db db)
    -{
    - struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
    - u16 port_mask = BIT(port);
    -
    - if (!vid)
    - vid = QCA8K_PORT_VID_DEF;
    -
    - return qca8k_fdb_del(priv, addr, port_mask, vid);
    -}
    -
    -static int
    -qca8k_port_fdb_dump(struct dsa_switch *ds, int port,
    - dsa_fdb_dump_cb_t *cb, void *data)
    -{
    - struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
    - struct qca8k_fdb _fdb = { 0 };
    - int cnt = QCA8K_NUM_FDB_RECORDS;
    - bool is_static;
    - int ret = 0;
    -
    - mutex_lock(&priv->reg_mutex);
    - while (cnt-- && !qca8k_fdb_next(priv, &_fdb, port)) {
    - if (!_fdb.aging)
    - break;
    - is_static = (_fdb.aging == QCA8K_ATU_STATUS_STATIC);
    - ret = cb(_fdb.mac, _fdb.vid, is_static, data);
    - if (ret)
    - break;
    - }
    - mutex_unlock(&priv->reg_mutex);
    -
    - return 0;
    -}
    -
    static int
    qca8k_port_mdb_add(struct dsa_switch *ds, int port,
    const struct switchdev_obj_port_mdb *mdb,
    diff --git a/drivers/net/dsa/qca/qca8k-common.c b/drivers/net/dsa/qca/qca8k-common.c
    index 598d6577835a..f35287c9f4bb 100644
    --- a/drivers/net/dsa/qca/qca8k-common.c
    +++ b/drivers/net/dsa/qca/qca8k-common.c
    @@ -813,3 +813,64 @@ qca8k_port_max_mtu(struct dsa_switch *ds, int port)
    {
    return QCA8K_MAX_MTU;
    }
    +
    +int
    +qca8k_port_fdb_insert(struct qca8k_priv *priv, const u8 *addr,
    + u16 port_mask, u16 vid)
    +{
    + /* Set the vid to the port vlan id if no vid is set */
    + if (!vid)
    + vid = QCA8K_PORT_VID_DEF;
    +
    + return qca8k_fdb_add(priv, addr, port_mask, vid,
    + QCA8K_ATU_STATUS_STATIC);
    +}
    +
    +int
    +qca8k_port_fdb_add(struct dsa_switch *ds, int port,
    + const unsigned char *addr, u16 vid,
    + struct dsa_db db)
    +{
    + struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
    + u16 port_mask = BIT(port);
    +
    + return qca8k_port_fdb_insert(priv, addr, port_mask, vid);
    +}
    +
    +int
    +qca8k_port_fdb_del(struct dsa_switch *ds, int port,
    + const unsigned char *addr, u16 vid,
    + struct dsa_db db)
    +{
    + struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
    + u16 port_mask = BIT(port);
    +
    + if (!vid)
    + vid = QCA8K_PORT_VID_DEF;
    +
    + return qca8k_fdb_del(priv, addr, port_mask, vid);
    +}
    +
    +int
    +qca8k_port_fdb_dump(struct dsa_switch *ds, int port,
    + dsa_fdb_dump_cb_t *cb, void *data)
    +{
    + struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
    + struct qca8k_fdb _fdb = { 0 };
    + int cnt = QCA8K_NUM_FDB_RECORDS;
    + bool is_static;
    + int ret = 0;
    +
    + mutex_lock(&priv->reg_mutex);
    + while (cnt-- && !qca8k_fdb_next(priv, &_fdb, port)) {
    + if (!_fdb.aging)
    + break;
    + is_static = (_fdb.aging == QCA8K_ATU_STATUS_STATIC);
    + ret = cb(_fdb.mac, _fdb.vid, is_static, data);
    + if (ret)
    + break;
    + }
    + mutex_unlock(&priv->reg_mutex);
    +
    + return 0;
    +}
    diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h
    index bc9078ae2b70..a5fa9ee31a79 100644
    --- a/drivers/net/dsa/qca/qca8k.h
    +++ b/drivers/net/dsa/qca/qca8k.h
    @@ -482,4 +482,16 @@ void qca8k_port_disable(struct dsa_switch *ds, int port);
    int qca8k_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu);
    int qca8k_port_max_mtu(struct dsa_switch *ds, int port);

    +/* Common FDB function */
    +int qca8k_port_fdb_insert(struct qca8k_priv *priv, const u8 *addr,
    + u16 port_mask, u16 vid);
    +int qca8k_port_fdb_add(struct dsa_switch *ds, int port,
    + const unsigned char *addr, u16 vid,
    + struct dsa_db db);
    +int qca8k_port_fdb_del(struct dsa_switch *ds, int port,
    + const unsigned char *addr, u16 vid,
    + struct dsa_db db);
    +int qca8k_port_fdb_dump(struct dsa_switch *ds, int port,
    + dsa_fdb_dump_cb_t *cb, void *data);
    +
    #endif /* __QCA8K_H */
    --
    2.36.1
    \
     
     \ /
      Last update: 2022-07-19 03:17    [W:4.250 / U:1.724 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site