aboutsummaryrefslogtreecommitdiff
path: root/include/linux/glob.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/glob.h')
0 files changed, 0 insertions, 0 deletions
cord_ipv6_entry_compare, }; static const struct mlxsw_sp_nve_mc_record_ops * mlxsw_sp_nve_mc_record_ops_arr[] = { [MLXSW_SP_L3_PROTO_IPV4] = &mlxsw_sp_nve_mc_record_ipv4_ops, [MLXSW_SP_L3_PROTO_IPV6] = &mlxsw_sp_nve_mc_record_ipv6_ops, }; int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip, enum mlxsw_sp_l3proto proto, union mlxsw_sp_l3addr *addr) { switch (proto) { case MLXSW_SP_L3_PROTO_IPV4: addr->addr4 = cpu_to_be32(uip); return 0; default: WARN_ON(1); return -EINVAL; } } static struct mlxsw_sp_nve_mc_list * mlxsw_sp_nve_mc_list_find(struct mlxsw_sp *mlxsw_sp, const struct mlxsw_sp_nve_mc_list_key *key) { struct mlxsw_sp_nve *nve = mlxsw_sp->nve; return rhashtable_lookup_fast(&nve->mc_list_ht, key, mlxsw_sp_nve_mc_list_ht_params); } static struct mlxsw_sp_nve_mc_list * mlxsw_sp_nve_mc_list_create(struct mlxsw_sp *mlxsw_sp, const struct mlxsw_sp_nve_mc_list_key *key) { struct mlxsw_sp_nve *nve = mlxsw_sp->nve; struct mlxsw_sp_nve_mc_list *mc_list; int err; mc_list = kmalloc(sizeof(*mc_list), GFP_KERNEL); if (!mc_list) return ERR_PTR(-ENOMEM); INIT_LIST_HEAD(&mc_list->records_list); mc_list->key = *key; err = rhashtable_insert_fast(&nve->mc_list_ht, &mc_list->ht_node, mlxsw_sp_nve_mc_list_ht_params); if (err) goto err_rhashtable_insert; return mc_list; err_rhashtable_insert: kfree(mc_list); return ERR_PTR(err); } static void mlxsw_sp_nve_mc_list_destroy(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_nve_mc_list *mc_list) { struct mlxsw_sp_nve *nve = mlxsw_sp->nve; rhashtable_remove_fast(&nve->mc_list_ht, &mc_list->ht_node, mlxsw_sp_nve_mc_list_ht_params); WARN_ON(!list_empty(&mc_list->records_list)); kfree(mc_list); } static struct mlxsw_sp_nve_mc_list * mlxsw_sp_nve_mc_list_get(struct mlxsw_sp *mlxsw_sp, const struct mlxsw_sp_nve_mc_list_key *key) { struct mlxsw_sp_nve_mc_list *mc_list; mc_list = mlxsw_sp_nve_mc_list_find(mlxsw_sp, key); if (mc_list) return mc_list; return mlxsw_sp_nve_mc_list_create(mlxsw_sp, key); } static void mlxsw_sp_nve_mc_list_put(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_nve_mc_list *mc_list) { if (!list_empty(&mc_list->records_list)) return; mlxsw_sp_nve_mc_list_destroy(mlxsw_sp, mc_list); } static struct mlxsw_sp_nve_mc_record * mlxsw_sp_nve_mc_record_create(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_nve_mc_list *mc_list, enum mlxsw_sp_l3proto proto) { unsigned int num_max_entries = mlxsw_sp->nve->num_max_mc_entries[proto]; struct mlxsw_sp_nve_mc_record *mc_record; int err; mc_record = kzalloc(struct_size(mc_record, entries, num_max_entries), GFP_KERNEL); if (!mc_record) return ERR_PTR(-ENOMEM); err = mlxsw_sp_kvdl_alloc(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT, 1, &mc_record->kvdl_index); if (err) goto err_kvdl_alloc; mc_record->ops = mlxsw_sp_nve_mc_record_ops_arr[proto]; mc_record->mlxsw_sp = mlxsw_sp; mc_record->mc_list = mc_list; mc_record->proto = proto; list_add_tail(&mc_record->list, &mc_list->records_list); return mc_record; err_kvdl_alloc: kfree(mc_record); return ERR_PTR(err); } static void mlxsw_sp_nve_mc_record_destroy(struct mlxsw_sp_nve_mc_record *mc_record) { struct mlxsw_sp *mlxsw_sp = mc_record->mlxsw_sp; list_del(&mc_record->list); mlxsw_sp_kvdl_free(mlxsw_sp, MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT, 1, mc_record->kvdl_index); WARN_ON(mc_record->num_entries); kfree(mc_record); } static struct mlxsw_sp_nve_mc_record * mlxsw_sp_nve_mc_record_get(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_nve_mc_list *mc_list, enum mlxsw_sp_l3proto proto) { struct mlxsw_sp_nve_mc_record *mc_record; list_for_each_entry_reverse(mc_record, &mc_list->records_list, list) { unsigned int num_entries = mc_record->num_entries; struct mlxsw_sp_nve *nve = mlxsw_sp->nve; if (mc_record->proto == proto && num_entries < nve->num_max_mc_entries[proto]) return mc_record; } return mlxsw_sp_nve_mc_record_create(mlxsw_sp, mc_list, proto); } static void mlxsw_sp_nve_mc_record_put(struct mlxsw_sp_nve_mc_record *mc_record) { if (mc_record->num_entries != 0) return; mlxsw_sp_nve_mc_record_destroy(mc_record); } static struct mlxsw_sp_nve_mc_entry * mlxsw_sp_nve_mc_free_entry_find(struct mlxsw_sp_nve_mc_record *mc_record) { struct mlxsw_sp_nve *nve = mc_record->mlxsw_sp->nve; unsigned int num_max_entries; int i; num_max_entries = nve->num_max_mc_entries[mc_record->proto]; for (i = 0; i < num_max_entries; i++) { if (mc_record->entries[i].valid) continue; return &mc_record->entries[i]; } return NULL; } static int mlxsw_sp_nve_mc_record_refresh(struct mlxsw_sp_nve_mc_record *mc_record) { enum mlxsw_reg_tnumt_record_type type = mc_record->ops->type; struct mlxsw_sp_nve_mc_list *mc_list = mc_record->mc_list; struct mlxsw_sp *mlxsw_sp = mc_record->mlxsw_sp; char tnumt_pl[MLXSW_REG_TNUMT_LEN]; unsigned int num_max_entries; unsigned int num_entries = 0; u32 next_kvdl_index = 0; bool next_valid = false; int i; if (!list_is_last(&mc_record->list, &mc_list->records_list)) { struct mlxsw_sp_nve_mc_record *next_record; next_record = list_next_entry(mc_record, list); next_kvdl_index = next_record->kvdl_index; next_valid = true; } mlxsw_reg_tnumt_pack(tnumt_pl, type, MLXSW_REG_TUNNEL_PORT_NVE, mc_record->kvdl_index, next_valid, next_kvdl_index, mc_record->num_entries); num_max_entries = mlxsw_sp->nve->num_max_mc_entries[mc_record->proto]; for (i = 0; i < num_max_entries; i++) { struct mlxsw_sp_nve_mc_entry *mc_entry; mc_entry = &mc_record->entries[i]; if (!mc_entry->valid) continue; mc_record->ops->entry_set(mc_record, mc_entry, tnumt_pl, num_entries++); } WARN_ON(num_entries != mc_record->num_entries); return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(tnumt), tnumt_pl); } static bool mlxsw_sp_nve_mc_record_is_first(struct mlxsw_sp_nve_mc_record *mc_record) { struct mlxsw_sp_nve_mc_list *mc_list = mc_record->mc_list; struct mlxsw_sp_nve_mc_record *first_record; first_record = list_first_entry(&mc_list->records_list, struct mlxsw_sp_nve_mc_record, list); return mc_record == first_record; } static struct mlxsw_sp_nve_mc_entry * mlxsw_sp_nve_mc_entry_find(struct mlxsw_sp_nve_mc_record *mc_record, union mlxsw_sp_l3addr *addr) { struct mlxsw_sp_nve *nve = mc_record->mlxsw_sp->nve; unsigned int num_max_entries; int i; num_max_entries = nve->num_max_mc_entries[mc_record->proto]; for (i = 0; i < num_max_entries; i++) { struct mlxsw_sp_nve_mc_entry *mc_entry; mc_entry = &mc_record->entries[i]; if (!mc_entry->valid) continue; if (mc_record->ops->entry_compare(mc_record, mc_entry, addr)) return mc_entry; } return NULL; } static int mlxsw_sp_nve_mc_record_ip_add(struct mlxsw_sp_nve_mc_record *mc_record, union mlxsw_sp_l3addr *addr) { struct mlxsw_sp_nve_mc_entry *mc_entry = NULL; int err; mc_entry = mlxsw_sp_nve_mc_free_entry_find(mc_record); if (WARN_ON(!mc_entry)) return -EINVAL; err = mc_record->ops->entry_add(mc_record, mc_entry, addr); if (err) return err; mc_record->num_entries++; mc_entry->valid = true; err = mlxsw_sp_nve_mc_record_refresh(mc_record); if (err) goto err_record_refresh; /* If this is a new record and not the first one, then we need to * update the next pointer of the previous entry */ if (mc_record->num_entries != 1 || mlxsw_sp_nve_mc_record_is_first(mc_record)) return 0; err = mlxsw_sp_nve_mc_record_refresh(list_prev_entry(mc_record, list)); if (err) goto err_prev_record_refresh; return 0; err_prev_record_refresh: err_record_refresh: mc_entry->valid = false; mc_record->num_entries--; mc_record->ops->entry_del(mc_record, mc_entry); return err; } static void mlxsw_sp_nve_mc_record_entry_del(struct mlxsw_sp_nve_mc_record *mc_record, struct mlxsw_sp_nve_mc_entry *mc_entry) { struct mlxsw_sp_nve_mc_list *mc_list = mc_record->mc_list; mc_entry->valid = false; mc_record->num_entries--; /* When the record continues to exist we only need to invalidate * the requested entry */ if (mc_record->num_entries != 0) { mlxsw_sp_nve_mc_record_refresh(mc_record); mc_record->ops->entry_del(mc_record, mc_entry); return; } /* If the record needs to be deleted, but it is not the first, * then we need to make sure that the previous record no longer * points to it. Remove deleted record from the list to reflect * that and then re-add it at the end, so that it could be * properly removed by the record destruction code */ if (!mlxsw_sp_nve_mc_record_is_first(mc_record)) { struct mlxsw_sp_nve_mc_record *prev_record; prev_record = list_prev_entry(mc_record, list); list_del(&mc_record->list); mlxsw_sp_nve_mc_record_refresh(prev_record); list_add_tail(&mc_record->list, &mc_list->records_list); mc_record->ops->entry_del(mc_record, mc_entry); return; } /* If the first record needs to be deleted, but the list is not * singular, then the second record needs to be written in the * first record's address, as this address is stored as a property * of the FID */ if (mlxsw_sp_nve_mc_record_is_first(mc_record) && !list_is_singular(&mc_list->records_list)) { struct mlxsw_sp_nve_mc_record *next_record; next_record = list_next_entry(mc_record, list); swap(mc_record->kvdl_index, next_record->kvdl_index); mlxsw_sp_nve_mc_record_refresh(next_record); mc_record->ops->entry_del(mc_record, mc_entry); return; } /* This is the last case where the last remaining record needs to * be deleted. Simply delete the entry */ mc_record->ops->entry_del(mc_record, mc_entry); } static struct mlxsw_sp_nve_mc_record * mlxsw_sp_nve_mc_record_find(struct mlxsw_sp_nve_mc_list *mc_list, enum mlxsw_sp_l3proto proto, union mlxsw_sp_l3addr *addr, struct mlxsw_sp_nve_mc_entry **mc_entry) { struct mlxsw_sp_nve_mc_record *mc_record; list_for_each_entry(mc_record, &mc_list->records_list, list) { if (mc_record->proto != proto) continue; *mc_entry = mlxsw_sp_nve_mc_entry_find(mc_record, addr); if (*mc_entry) return mc_record; } return NULL; } static int mlxsw_sp_nve_mc_list_ip_add(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_nve_mc_list *mc_list, enum mlxsw_sp_l3proto proto, union mlxsw_sp_l3addr *addr) { struct mlxsw_sp_nve_mc_record *mc_record; int err; mc_record = mlxsw_sp_nve_mc_record_get(mlxsw_sp, mc_list, proto); if (IS_ERR(mc_record)) return PTR_ERR(mc_record); err = mlxsw_sp_nve_mc_record_ip_add(mc_record, addr); if (err) goto err_ip_add;