Re: [PATCH v3 net-next 5/8] net: dsa: felix: support psfp filter on vsc9959

Vladimir Oltean
2021-08-31T07:55:00Z

On Tue, Aug 31, 2021 at 11:45:33AM +0800, Xiaoliang Yang wrote:
> +static int vsc9959_mact_stream_set(struct ocelot *ocelot,
> + struct felix_stream *stream,
> + struct netlink_ext_ack *extack)
> +{
> + struct ocelot_mact_entry entry;
> + u32 row, col, reg, dst_idx;
> + int ret;
> +
> + /* Stream identification desn't support to add a stream with non
> + * existent MAC (The MAC entry has not been learned in MAC table).
> + */

Who will add the MAC entry to the MAC table in this design? The user?

> + ret = ocelot_mact_lookup(ocelot, stream->dmac, stream->vid, &row, &col);
> + if (ret) {
> + if (extack)
> + NL_SET_ERR_MSG_MOD(extack, "Stream is not learned in MAC table");
> + return -EOPNOTSUPP;
> + }
> +
> + ocelot_rmw(ocelot,
> + (stream->sfid_valid ? ANA_TABLES_STREAMDATA_SFID_VALID : 0) |
> + ANA_TABLES_STREAMDATA_SFID(stream->sfid),
> + ANA_TABLES_STREAMDATA_SFID_VALID |
> + ANA_TABLES_STREAMDATA_SFID_M,
> + ANA_TABLES_STREAMDATA);
> +
> + reg = ocelot_read(ocelot, ANA_TABLES_STREAMDATA);
> + reg &= (ANA_TABLES_STREAMDATA_SFID_VALID | ANA_TABLES_STREAMDATA_SSID_VALID);
> + entry.type = (reg ? ENTRYTYPE_LOCKED : ENTRYTYPE_NORMAL);

So if the STREAMDATA entry for this SFID was valid, you mark the MAC
table entry as static, otherwise you mark it as ageable? Why?

> + ether_addr_copy(entry.mac, stream->dmac);
> + entry.vid = stream->vid;
> +
> + reg = ocelot_read(ocelot, ANA_TABLES_MACACCESS);
> + dst_idx = (reg & ANA_TABLES_MACACCESS_DEST_IDX_M) >> 3;
> +
> + ocelot_mact_write(ocelot, dst_idx, &entry, row, col);
> +
> + return 0;
> +}
> +
> +static int vsc9959_stream_table_add(struct ocelot *ocelot,
> + struct list_head *stream_list,
> + struct felix_stream *stream,
> + struct netlink_ext_ack *extack)
> +{
> + struct felix_stream *stream_entry;
> + int ret;
> +
> + stream_entry = kzalloc(sizeof(*stream_entry), GFP_KERNEL);
> + if (!stream_entry)
> + return -ENOMEM;
> +
> + memcpy(stream_entry, stream, sizeof(*stream_entry));
> +
> + ret = vsc9959_mact_stream_set(ocelot, stream, extack);
> + if (ret) {
> + kfree(stream_entry);
> + return ret;
> + }
> +
> + list_add_tail(&stream_entry->list, stream_list);
> +
> + return 0;
> +}
> +
> +static bool vsc9959_stream_table_lookup(struct list_head *stream_list,
> + struct felix_stream *stream)
> +{
> + struct felix_stream *tmp;
> +
> + list_for_each_entry(tmp, stream_list, list)
> + if (ether_addr_equal(tmp->dmac, stream->dmac) &&
> + tmp->vid == stream->vid)
> + return true;
> +
> + return false;
> +}
> +
> +static struct felix_stream *
> +vsc9959_stream_table_get(struct list_head *stream_list, unsigned long id)
> +{
> + struct felix_stream *tmp;
> +
> + list_for_each_entry(tmp, stream_list, list)
> + if (tmp->id == id)
> + return tmp;
> +
> + return NULL;
> +}
> +
> +static void vsc9959_stream_table_del(struct ocelot *ocelot,
> + struct felix_stream *stream)
> +{
> + vsc9959_mact_stream_set(ocelot, stream, NULL);
> +
> + list_del(&stream->list);
> + kfree(stream);
> +}
> +
> +static u32 vsc9959_sfi_access_status(struct ocelot *ocelot)
> +{
> + return ocelot_read(ocelot, ANA_TABLES_SFIDACCESS);
> +}
> +
> +static int vsc9959_psfp_sfi_set(struct ocelot *ocelot,
> + struct felix_stream_filter *sfi)
> +{
> + u32 val;
> +
> + if (sfi->index > VSC9959_PSFP_SFID_MAX)
> + return -EINVAL;
> +
> + if (!sfi->enable) {
> + ocelot_write(ocelot, ANA_TABLES_SFIDTIDX_SFID_INDEX(sfi->index),
> + ANA_TABLES_SFIDTIDX);
> +
> + val = ANA_TABLES_SFIDACCESS_SFID_TBL_CMD(SFIDACCESS_CMD_WRITE);
> + ocelot_write(ocelot, val, ANA_TABLES_SFIDACCESS);
> +
> + return readx_poll_timeout(vsc9959_sfi_access_status, ocelot, val,
> + (!ANA_TABLES_SFIDACCESS_SFID_TBL_CMD(val)),
> + 10, 100000);
> + }
> +
> + if (sfi->sgid > VSC9959_PSFP_GATE_ID_MAX ||
> + sfi->fmid > VSC9959_PSFP_POLICER_MAX)
> + return -EINVAL;
> +
> + ocelot_write(ocelot,
> + (sfi->sg_valid ? ANA_TABLES_SFIDTIDX_SGID_VALID : 0) |
> + ANA_TABLES_SFIDTIDX_SGID(sfi->sgid) |
> + (sfi->fm_valid ? ANA_TABLES_SFIDTIDX_POL_ENA : 0) |
> + ANA_TABLES_SFIDTIDX_POL_IDX(sfi->fmid) |
> + ANA_TABLES_SFIDTIDX_SFID_INDEX(sfi->index),
> + ANA_TABLES_SFIDTIDX);
> +
> + ocelot_write(ocelot,
> + (sfi->prio_valid ? ANA_TABLES_SFIDACCESS_IGR_PRIO_MATCH_ENA : 0) |
> + ANA_TABLES_SFIDACCESS_IGR_PRIO(sfi->prio) |
> + ANA_TABLES_SFIDACCESS_MAX_SDU_LEN(sfi->maxsdu) |
> + ANA_TABLES_SFIDACCESS_SFID_TBL_CMD(SFIDACCESS_CMD_WRITE),
> + ANA_TABLES_SFIDACCESS);
> +
> + return readx_poll_timeout(vsc9959_sfi_access_status, ocelot, val,
> + (!ANA_TABLES_SFIDACCESS_SFID_TBL_CMD(val)),
> + 10, 100000);
> +}
> +
> +static int vsc9959_psfp_sfi_table_add(struct ocelot *ocelot,
> + struct felix_stream_filter *sfi)
> +{
> + struct felix_stream_filter *sfi_entry, *tmp;
> + struct list_head *pos, *q, *last;
> + struct ocelot_psfp_list *psfp;
> + u32 insert = 0;
> + int ret;
> +
> + psfp = &ocelot->psfp;
> + last = &psfp->sfi_list;
> +
> + list_for_each_safe(pos, q, &psfp->sfi_list) {
> + tmp = list_entry(pos, struct felix_stream_filter, list);
> + if (sfi->sg_valid == tmp->sg_valid &&
> + sfi->fm_valid == tmp->fm_valid &&
> + tmp->sgid == sfi->sgid &&
> + tmp->fmid == sfi->fmid) {
> + sfi->index = tmp->index;
> + refcount_inc(&tmp->refcount);
> + return 0;
> + }
> + /* Make sure that the index is increasing in order. */
> + if (tmp->index == insert) {
> + last = pos;
> + insert++;
> + }
> + }
> + sfi->index = insert;
> +
> + sfi_entry = kzalloc(sizeof(*sfi_entry), GFP_KERNEL);
> + if (!sfi_entry)
> + return -ENOMEM;
> +
> + memcpy(sfi_entry, sfi, sizeof(*sfi_entry));
> + refcount_set(&sfi_entry->refcount, 1);
> +
> + ret = vsc9959_psfp_sfi_set(ocelot, sfi_entry);
> + if (ret) {
> + kfree(sfi_entry);
> + return ret;
> + }
> +
> + list_add(&sfi_entry->list, last);
> +
> + return 0;
> +}
> +
> +static struct felix_stream_filter *
> +vsc9959_psfp_sfi_table_get(struct list_head *sfi_list, u32 index)

This function needs to be introduced in the patch where it is used,
otherwise:
https://patchwork.hopto.org/static/nipa/539543/12466413/build_32bit/stderr

> +{
> + struct felix_stream_filter *tmp;
> +
> + list_for_each_entry(tmp, sfi_list, list)
> + if (tmp->index == index)
> + return tmp;
> +
> + return NULL;
> +}