Lines Matching +full:data +full:- +full:width

1 // SPDX-License-Identifier: GPL-2.0+
53 itr->offset = offset; in vcap_iter_set()
54 itr->sw_width = sw_width; in vcap_iter_set()
55 itr->regs_per_sw = DIV_ROUND_UP(sw_width, 32); in vcap_iter_set()
56 itr->tg = tg; in vcap_iter_set()
62 * A typegroup table ends with an all-zero terminator. in vcap_iter_skip_tg()
64 while (itr->tg->width && itr->offset >= itr->tg->offset) { in vcap_iter_skip_tg()
65 itr->offset += itr->tg->width; in vcap_iter_skip_tg()
66 itr->tg++; /* next typegroup */ in vcap_iter_skip_tg()
75 sw_idx = itr->offset / itr->sw_width; in vcap_iter_update()
76 sw_bitpos = itr->offset % itr->sw_width; in vcap_iter_update()
78 itr->reg_idx = (sw_idx * itr->regs_per_sw) + (sw_bitpos / 32); in vcap_iter_update()
79 itr->reg_bitpos = sw_bitpos % 32; in vcap_iter_update()
92 itr->offset++; in vcap_iter_next()
99 u32 mask = BIT(itr->reg_bitpos); in vcap_set_bit()
100 u32 *p = &stream[itr->reg_idx]; in vcap_set_bit()
113 while (itr->tg->width && in vcap_encode_bit()
114 itr->offset >= itr->tg->offset && in vcap_encode_bit()
115 itr->offset < itr->tg->offset + itr->tg->width) { in vcap_encode_bit()
116 int tg_bitpos = itr->tg->offset - itr->offset; in vcap_encode_bit()
118 vcap_set_bit(stream, itr, (itr->tg->value >> tg_bitpos) & 0x1); in vcap_encode_bit()
119 itr->offset++; in vcap_encode_bit()
126 int width, const u8 *value) in vcap_encode_field() argument
133 for (idx = 0; idx < width; idx++) { in vcap_encode_field()
151 * match-1 or match-0, or both in vcap_encode_typegroups()
154 while (iter.tg->width) { in vcap_encode_typegroups()
156 iter.offset = iter.tg->offset; in vcap_encode_typegroups()
158 for (idx = 0; idx < iter.tg->width; idx++) { in vcap_encode_typegroups()
166 (iter.tg->value >> idx) & 0x1); in vcap_encode_typegroups()
174 static bool vcap_bitarray_zero(int width, u8 *value) in vcap_bitarray_zero() argument
176 int bytes = DIV_ROUND_UP(width, BITS_PER_BYTE); in vcap_bitarray_zero()
178 int rwidth = width; in vcap_bitarray_zero()
181 for (idx = 0; idx < bytes; ++idx, rwidth -= BITS_PER_BYTE) { in vcap_bitarray_zero()
183 bmask = (1 << rwidth) - 1; in vcap_bitarray_zero()
191 u32 mask = BIT(itr->reg_bitpos); in vcap_get_bit()
192 u32 *p = &stream[itr->reg_idx]; in vcap_get_bit()
198 int width, u8 *value) in vcap_decode_field() argument
205 for (idx = 0; idx < width; idx++) { in vcap_decode_field()
224 const struct vcap_info *vcap = &vctrl->vcaps[vt]; in vcap_verify_keystream_keyset()
241 /* a type_id of value -1 means that there is no type field */ in vcap_verify_keystream_keyset()
242 if (info->type_id == (u8)-1) in vcap_verify_keystream_keyset()
255 vcap_iter_init(&iter, vcap->sw_width, tgt, typefld->offset); in vcap_verify_keystream_keyset()
256 vcap_decode_field(mskstream, &iter, typefld->width, (u8 *)&mask); in vcap_verify_keystream_keyset()
258 if (vcap_bitarray_zero(typefld->width, (u8 *)&mask)) in vcap_verify_keystream_keyset()
264 vcap_iter_init(&iter, vcap->sw_width, tgt, typefld->offset); in vcap_verify_keystream_keyset()
265 vcap_decode_field(keystream, &iter, typefld->width, (u8 *)&value); in vcap_verify_keystream_keyset()
267 return (value & mask) == (info->type_id & mask); in vcap_verify_keystream_keyset()
280 while (iter.tg->width) { in vcap_verify_typegroups()
282 u32 tg_value = iter.tg->value; in vcap_verify_typegroups()
285 tg_value = (1 << iter.tg->width) - 1; in vcap_verify_typegroups()
287 iter.offset = iter.tg->offset; in vcap_verify_typegroups()
289 for (idx = 0; idx < iter.tg->width; idx++) { in vcap_verify_typegroups()
297 return -EINVAL; in vcap_verify_typegroups()
307 /* Find the subword width of the key typegroup that matches the stream data */
315 tgt = vctrl->vcaps[vt].keyfield_set_typegroups; in vcap_find_keystream_typegroup_sw()
317 for (sw_idx = vctrl->vcaps[vt].sw_count; sw_idx >= 0; sw_idx--) { in vcap_find_keystream_typegroup_sw()
321 res = vcap_verify_typegroups(stream, vctrl->vcaps[vt].sw_width, in vcap_find_keystream_typegroup_sw()
326 return -EINVAL; in vcap_find_keystream_typegroup_sw()
348 keyfield_set = vctrl->vcaps[vt].keyfield_set; in vcap_find_keystream_keysets()
349 for (idx = 0; idx < vctrl->vcaps[vt].keyfield_set_size; ++idx) { in vcap_find_keystream_keysets()
357 if (kslist->cnt > 0) in vcap_find_keystream_keysets()
359 return -EINVAL; in vcap_find_keystream_keysets()
363 /* Read key data from a VCAP address and discover if there are any rule keysets
372 enum vcap_type vt = admin->vtype; in vcap_addr_keysets()
377 keyset_sw_regs = DIV_ROUND_UP(vctrl->vcaps[vt].sw_width, 32); in vcap_addr_keysets()
378 vctrl->ops->update(ndev, admin, VCAP_CMD_READ, VCAP_SEL_ALL, addr); in vcap_addr_keysets()
379 vctrl->ops->cache_read(ndev, admin, VCAP_SEL_ENTRY, 0, in vcap_addr_keysets()
383 key |= ~admin->cache.keystream[idx]; in vcap_addr_keysets()
384 mask |= admin->cache.maskstream[idx]; in vcap_addr_keysets()
387 return -EINVAL; in vcap_addr_keysets()
389 return vcap_find_keystream_keysets(vctrl, vt, admin->cache.keystream, in vcap_addr_keysets()
390 admin->cache.maskstream, false, 0, in vcap_addr_keysets()
401 if (keyset >= vctrl->vcaps[vt].keyfield_set_size) in vcap_keyfields()
403 return vctrl->vcaps[vt].keyfield_set_map[keyset]; in vcap_keyfields()
414 if (keyset >= vctrl->vcaps[vt].keyfield_set_size) in vcap_keyfieldset()
416 kset = &vctrl->vcaps[vt].keyfield_set[keyset]; in vcap_keyfieldset()
417 if (kset->sw_per_item == 0 || kset->sw_per_item > vctrl->vcaps[vt].sw_count) in vcap_keyfieldset()
433 return vctrl->vcaps[vt].keyfield_set_typegroups[kset->sw_per_item]; in vcap_keyfield_typegroup()
441 if (keyset >= vctrl->vcaps[vt].keyfield_set_size) in vcap_keyfield_count()
443 return vctrl->vcaps[vt].keyfield_set_map_size[keyset]; in vcap_keyfield_count()
451 int sw_width = ri->vctrl->vcaps[ri->admin->vtype].sw_width; in vcap_encode_keyfield()
452 struct vcap_cache_data *cache = &ri->admin->cache; in vcap_encode_keyfield()
457 * streams, respecting the subword width. in vcap_encode_keyfield()
459 switch (kf->ctrl.type) { in vcap_encode_keyfield()
461 value = &kf->data.u1.value; in vcap_encode_keyfield()
462 mask = &kf->data.u1.mask; in vcap_encode_keyfield()
465 value = (const u8 *)&kf->data.u32.value; in vcap_encode_keyfield()
466 mask = (const u8 *)&kf->data.u32.mask; in vcap_encode_keyfield()
469 value = kf->data.u48.value; in vcap_encode_keyfield()
470 mask = kf->data.u48.mask; in vcap_encode_keyfield()
473 value = kf->data.u56.value; in vcap_encode_keyfield()
474 mask = kf->data.u56.mask; in vcap_encode_keyfield()
477 value = kf->data.u64.value; in vcap_encode_keyfield()
478 mask = kf->data.u64.mask; in vcap_encode_keyfield()
481 value = kf->data.u72.value; in vcap_encode_keyfield()
482 mask = kf->data.u72.mask; in vcap_encode_keyfield()
485 value = kf->data.u112.value; in vcap_encode_keyfield()
486 mask = kf->data.u112.mask; in vcap_encode_keyfield()
489 value = kf->data.u128.value; in vcap_encode_keyfield()
490 mask = kf->data.u128.mask; in vcap_encode_keyfield()
493 vcap_iter_init(&iter, sw_width, tgt, rf->offset); in vcap_encode_keyfield()
494 vcap_encode_field(cache->keystream, &iter, rf->width, value); in vcap_encode_keyfield()
495 vcap_iter_init(&iter, sw_width, tgt, rf->offset); in vcap_encode_keyfield()
496 vcap_encode_field(cache->maskstream, &iter, rf->width, mask); in vcap_encode_keyfield()
503 int sw_width = vctrl->vcaps[ri->admin->vtype].sw_width; in vcap_encode_keyfield_typegroups()
504 struct vcap_cache_data *cache = &ri->admin->cache; in vcap_encode_keyfield_typegroups()
507 * respecting the subword width. in vcap_encode_keyfield_typegroups()
509 vcap_encode_typegroups(cache->keystream, sw_width, tgt, false); in vcap_encode_keyfield_typegroups()
510 vcap_encode_typegroups(cache->maskstream, sw_width, tgt, true); in vcap_encode_keyfield_typegroups()
513 /* Copy data from src to dst but reverse the data in chunks of 32bits.
523 first_byte_index = size - (((idx >> 2) + 1) << 2); in vcap_copy_to_w32be()
526 nidx = idx + first_byte_index - (idx & ~0x3); in vcap_copy_to_w32be()
541 dst->ctrl.type = src->ctrl.type; in vcap_copy_from_client_keyfield()
542 dst->ctrl.key = src->ctrl.key; in vcap_copy_from_client_keyfield()
543 INIT_LIST_HEAD(&dst->ctrl.list); in vcap_copy_from_client_keyfield()
544 sdata = &src->data; in vcap_copy_from_client_keyfield()
545 ddata = &dst->data; in vcap_copy_from_client_keyfield()
547 if (!ri->admin->w32be) { in vcap_copy_from_client_keyfield()
548 memcpy(ddata, sdata, sizeof(dst->data)); in vcap_copy_from_client_keyfield()
552 size = keyfield_size_table[dst->ctrl.type] / 2; in vcap_copy_from_client_keyfield()
554 switch (dst->ctrl.type) { in vcap_copy_from_client_keyfield()
557 memcpy(ddata, sdata, sizeof(dst->data)); in vcap_copy_from_client_keyfield()
560 vcap_copy_to_w32be(ddata->u48.value, src->data.u48.value, size); in vcap_copy_from_client_keyfield()
561 vcap_copy_to_w32be(ddata->u48.mask, src->data.u48.mask, size); in vcap_copy_from_client_keyfield()
564 vcap_copy_to_w32be(ddata->u56.value, sdata->u56.value, size); in vcap_copy_from_client_keyfield()
565 vcap_copy_to_w32be(ddata->u56.mask, sdata->u56.mask, size); in vcap_copy_from_client_keyfield()
568 vcap_copy_to_w32be(ddata->u64.value, sdata->u64.value, size); in vcap_copy_from_client_keyfield()
569 vcap_copy_to_w32be(ddata->u64.mask, sdata->u64.mask, size); in vcap_copy_from_client_keyfield()
572 vcap_copy_to_w32be(ddata->u72.value, sdata->u72.value, size); in vcap_copy_from_client_keyfield()
573 vcap_copy_to_w32be(ddata->u72.mask, sdata->u72.mask, size); in vcap_copy_from_client_keyfield()
576 vcap_copy_to_w32be(ddata->u112.value, sdata->u112.value, size); in vcap_copy_from_client_keyfield()
577 vcap_copy_to_w32be(ddata->u112.mask, sdata->u112.mask, size); in vcap_copy_from_client_keyfield()
580 vcap_copy_to_w32be(ddata->u128.value, sdata->u128.value, size); in vcap_copy_from_client_keyfield()
581 vcap_copy_to_w32be(ddata->u128.mask, sdata->u128.mask, size); in vcap_copy_from_client_keyfield()
596 dst->ctrl.type = src->ctrl.type; in vcap_copy_from_client_actionfield()
597 dst->ctrl.action = src->ctrl.action; in vcap_copy_from_client_actionfield()
598 INIT_LIST_HEAD(&dst->ctrl.list); in vcap_copy_from_client_actionfield()
599 sdata = &src->data; in vcap_copy_from_client_actionfield()
600 ddata = &dst->data; in vcap_copy_from_client_actionfield()
602 if (!ri->admin->w32be) { in vcap_copy_from_client_actionfield()
603 memcpy(ddata, sdata, sizeof(dst->data)); in vcap_copy_from_client_actionfield()
607 size = actionfield_size_table[dst->ctrl.type]; in vcap_copy_from_client_actionfield()
609 switch (dst->ctrl.type) { in vcap_copy_from_client_actionfield()
612 memcpy(ddata, sdata, sizeof(dst->data)); in vcap_copy_from_client_actionfield()
615 vcap_copy_to_w32be(ddata->u48.value, sdata->u48.value, size); in vcap_copy_from_client_actionfield()
618 vcap_copy_to_w32be(ddata->u56.value, sdata->u56.value, size); in vcap_copy_from_client_actionfield()
621 vcap_copy_to_w32be(ddata->u64.value, sdata->u64.value, size); in vcap_copy_from_client_actionfield()
624 vcap_copy_to_w32be(ddata->u72.value, sdata->u72.value, size); in vcap_copy_from_client_actionfield()
627 vcap_copy_to_w32be(ddata->u112.value, sdata->u112.value, size); in vcap_copy_from_client_actionfield()
630 vcap_copy_to_w32be(ddata->u128.value, sdata->u128.value, size); in vcap_copy_from_client_actionfield()
644 kf_table = vcap_keyfields(ri->vctrl, ri->admin->vtype, ri->data.keyset); in vcap_encode_rule_keyset()
647 __func__, __LINE__, ri->data.keyset); in vcap_encode_rule_keyset()
648 return -EINVAL; in vcap_encode_rule_keyset()
651 tg_table = vcap_keyfield_typegroup(ri->vctrl, ri->admin->vtype, in vcap_encode_rule_keyset()
652 ri->data.keyset); in vcap_encode_rule_keyset()
655 __func__, __LINE__, ri->data.keyset); in vcap_encode_rule_keyset()
656 return -EINVAL; in vcap_encode_rule_keyset()
659 keyset_size = vcap_keyfield_count(ri->vctrl, ri->admin->vtype, in vcap_encode_rule_keyset()
660 ri->data.keyset); in vcap_encode_rule_keyset()
663 __func__, __LINE__, ri->data.keyset); in vcap_encode_rule_keyset()
664 return -EINVAL; in vcap_encode_rule_keyset()
669 if (list_empty(&ri->data.keyfields)) { in vcap_encode_rule_keyset()
671 return -EINVAL; in vcap_encode_rule_keyset()
673 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) { in vcap_encode_rule_keyset()
675 if (ckf->ctrl.key >= keyset_size) { in vcap_encode_rule_keyset()
677 __func__, __LINE__, ckf->ctrl.key); in vcap_encode_rule_keyset()
678 return -EINVAL; in vcap_encode_rule_keyset()
680 vcap_copy_from_client_keyfield(&ri->data, &tempkf, ckf); in vcap_encode_rule_keyset()
681 vcap_encode_keyfield(ri, &tempkf, &kf_table[ckf->ctrl.key], in vcap_encode_rule_keyset()
685 vcap_encode_keyfield_typegroups(ri->vctrl, ri, tg_table); in vcap_encode_rule_keyset()
695 if (actionset >= vctrl->vcaps[vt].actionfield_set_size) in vcap_actionfields()
697 return vctrl->vcaps[vt].actionfield_set_map[actionset]; in vcap_actionfields()
707 if (actionset >= vctrl->vcaps[vt].actionfield_set_size) in vcap_actionfieldset()
709 aset = &vctrl->vcaps[vt].actionfield_set[actionset]; in vcap_actionfieldset()
710 if (aset->sw_per_item == 0 || aset->sw_per_item > vctrl->vcaps[vt].sw_count) in vcap_actionfieldset()
725 return vctrl->vcaps[vt].actionfield_set_typegroups[aset->sw_per_item]; in vcap_actionfield_typegroup()
734 if (actionset >= vctrl->vcaps[vt].actionfield_set_size) in vcap_actionfield_count()
736 return vctrl->vcaps[vt].actionfield_set_map_size[actionset]; in vcap_actionfield_count()
744 int act_width = ri->vctrl->vcaps[ri->admin->vtype].act_width; in vcap_encode_actionfield()
746 struct vcap_cache_data *cache = &ri->admin->cache; in vcap_encode_actionfield()
750 /* Encode the action field in the stream, respecting the subword width */ in vcap_encode_actionfield()
751 switch (af->ctrl.type) { in vcap_encode_actionfield()
753 value = &af->data.u1.value; in vcap_encode_actionfield()
756 value = (const u8 *)&af->data.u32.value; in vcap_encode_actionfield()
759 value = af->data.u48.value; in vcap_encode_actionfield()
762 value = af->data.u56.value; in vcap_encode_actionfield()
765 value = af->data.u64.value; in vcap_encode_actionfield()
768 value = af->data.u72.value; in vcap_encode_actionfield()
771 value = af->data.u112.value; in vcap_encode_actionfield()
774 value = af->data.u128.value; in vcap_encode_actionfield()
777 vcap_iter_init(&iter, act_width, tgt, rf->offset); in vcap_encode_actionfield()
778 vcap_encode_field(cache->actionstream, &iter, rf->width, value); in vcap_encode_actionfield()
784 int sw_width = ri->vctrl->vcaps[ri->admin->vtype].act_width; in vcap_encode_actionfield_typegroups()
785 struct vcap_cache_data *cache = &ri->admin->cache; in vcap_encode_actionfield_typegroups()
788 * width. in vcap_encode_actionfield_typegroups()
790 vcap_encode_typegroups(cache->actionstream, sw_width, tgt, false); in vcap_encode_actionfield_typegroups()
802 af_table = vcap_actionfields(ri->vctrl, ri->admin->vtype, in vcap_encode_rule_actionset()
803 ri->data.actionset); in vcap_encode_rule_actionset()
806 __func__, __LINE__, ri->data.actionset); in vcap_encode_rule_actionset()
807 return -EINVAL; in vcap_encode_rule_actionset()
810 tg_table = vcap_actionfield_typegroup(ri->vctrl, ri->admin->vtype, in vcap_encode_rule_actionset()
811 ri->data.actionset); in vcap_encode_rule_actionset()
814 __func__, __LINE__, ri->data.actionset); in vcap_encode_rule_actionset()
815 return -EINVAL; in vcap_encode_rule_actionset()
818 actionset_size = vcap_actionfield_count(ri->vctrl, ri->admin->vtype, in vcap_encode_rule_actionset()
819 ri->data.actionset); in vcap_encode_rule_actionset()
822 __func__, __LINE__, ri->data.actionset); in vcap_encode_rule_actionset()
823 return -EINVAL; in vcap_encode_rule_actionset()
828 if (list_empty(&ri->data.actionfields)) in vcap_encode_rule_actionset()
831 list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) { in vcap_encode_rule_actionset()
833 if (caf->ctrl.action >= actionset_size) { in vcap_encode_rule_actionset()
835 __func__, __LINE__, caf->ctrl.action); in vcap_encode_rule_actionset()
836 return -EINVAL; in vcap_encode_rule_actionset()
838 vcap_copy_from_client_actionfield(&ri->data, &tempaf, caf); in vcap_encode_rule_actionset()
840 &af_table[caf->ctrl.action], tg_table); in vcap_encode_rule_actionset()
864 return -EINVAL; in vcap_api_check()
866 if (!ctrl->ops || !ctrl->ops->validate_keyset || in vcap_api_check()
867 !ctrl->ops->add_default_fields || !ctrl->ops->cache_erase || in vcap_api_check()
868 !ctrl->ops->cache_write || !ctrl->ops->cache_read || in vcap_api_check()
869 !ctrl->ops->init || !ctrl->ops->update || !ctrl->ops->move || in vcap_api_check()
870 !ctrl->ops->port_info) { in vcap_api_check()
873 return -ENOENT; in vcap_api_check()
880 ri->vctrl->ops->cache_erase(ri->admin); in vcap_erase_cache()
891 kset = vcap_keyfieldset(ri->vctrl, ri->admin->vtype, keyset); in vcap_set_rule_set_keyset()
894 return -EINVAL; in vcap_set_rule_set_keyset()
895 ri->keyset_sw = kset->sw_per_item; in vcap_set_rule_set_keyset()
896 sw_width = ri->vctrl->vcaps[ri->admin->vtype].sw_width; in vcap_set_rule_set_keyset()
897 ri->keyset_sw_regs = DIV_ROUND_UP(sw_width, 32); in vcap_set_rule_set_keyset()
898 ri->data.keyset = keyset; in vcap_set_rule_set_keyset()
911 aset = vcap_actionfieldset(ri->vctrl, ri->admin->vtype, actionset); in vcap_set_rule_set_actionset()
914 return -EINVAL; in vcap_set_rule_set_actionset()
915 ri->actionset_sw = aset->sw_per_item; in vcap_set_rule_set_actionset()
916 act_width = ri->vctrl->vcaps[ri->admin->vtype].act_width; in vcap_set_rule_set_actionset()
917 ri->actionset_sw_regs = DIV_ROUND_UP(act_width, 32); in vcap_set_rule_set_actionset()
918 ri->data.actionset = actionset; in vcap_set_rule_set_actionset()
930 list_for_each_entry(admin, &vctrl->list, list) in vcap_rule_exists()
931 list_for_each_entry(ri, &admin->rules, list) in vcap_rule_exists()
932 if (ri->data.id == id) in vcap_rule_exists()
945 list_for_each_entry(admin, &vctrl->list, list) { in vcap_get_locked_rule()
946 mutex_lock(&admin->lock); in vcap_get_locked_rule()
947 list_for_each_entry(ri, &admin->rules, list) in vcap_get_locked_rule()
948 if (ri->data.id == id) in vcap_get_locked_rule()
950 mutex_unlock(&admin->lock); in vcap_get_locked_rule()
963 list_for_each_entry(admin, &vctrl->list, list) { in vcap_lookup_rule_by_cookie()
964 mutex_lock(&admin->lock); in vcap_lookup_rule_by_cookie()
965 list_for_each_entry(ri, &admin->rules, list) { in vcap_lookup_rule_by_cookie()
966 if (ri->data.cookie == cookie) { in vcap_lookup_rule_by_cookie()
967 id = ri->data.id; in vcap_lookup_rule_by_cookie()
971 mutex_unlock(&admin->lock); in vcap_lookup_rule_by_cookie()
975 return -ENOENT; in vcap_lookup_rule_by_cookie()
987 list_for_each_entry(elem, &admin->rules, list) { in vcap_admin_rule_count()
988 mutex_lock(&admin->lock); in vcap_admin_rule_count()
989 if (elem->data.vcap_chain_id >= min_cid && in vcap_admin_rule_count()
990 elem->data.vcap_chain_id < max_cid) in vcap_admin_rule_count()
992 mutex_unlock(&admin->lock); in vcap_admin_rule_count()
1009 return ERR_PTR(-ENOMEM); in vcap_dup_rule()
1012 INIT_LIST_HEAD(&duprule->list); in vcap_dup_rule()
1014 INIT_LIST_HEAD(&duprule->data.keyfields); in vcap_dup_rule()
1015 INIT_LIST_HEAD(&duprule->data.actionfields); in vcap_dup_rule()
1021 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) { in vcap_dup_rule()
1025 list_add_tail(&newckf->ctrl.list, &duprule->data.keyfields); in vcap_dup_rule()
1028 list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) { in vcap_dup_rule()
1032 list_add_tail(&newcaf->ctrl.list, &duprule->data.actionfields); in vcap_dup_rule()
1038 list_for_each_entry_safe(ckf, newckf, &duprule->data.keyfields, ctrl.list) { in vcap_dup_rule()
1039 list_del(&ckf->ctrl.list); in vcap_dup_rule()
1043 list_for_each_entry_safe(caf, newcaf, &duprule->data.actionfields, ctrl.list) { in vcap_dup_rule()
1044 list_del(&caf->ctrl.list); in vcap_dup_rule()
1049 return ERR_PTR(-ENOMEM); in vcap_dup_rule()
1052 static void vcap_apply_width(u8 *dst, int width, int bytes) in vcap_apply_width() argument
1058 if (width > 0) in vcap_apply_width()
1059 if (width < 8) in vcap_apply_width()
1060 bmask = (1 << width) - 1; in vcap_apply_width()
1066 width -= 8; in vcap_apply_width()
1070 static void vcap_copy_from_w32be(u8 *dst, u8 *src, int size, int width) in vcap_copy_from_w32be() argument
1073 int tail_bytes = (((size + 4) >> 2) << 2) - size; in vcap_copy_from_w32be()
1075 for (idx = 0, ridx = size - 1; idx < size; ++idx, --ridx) { in vcap_copy_from_w32be()
1077 nidx = wstart + 3 - (idx & 0x3); in vcap_copy_from_w32be()
1079 nidx -= tail_bytes; in vcap_copy_from_w32be()
1083 vcap_apply_width(dst, width, size); in vcap_copy_from_w32be()
1088 field->value = (*value) & 0x1; in vcap_copy_action_bit_field()
1092 int width, int bytes) in vcap_copy_limited_actionfield() argument
1095 vcap_apply_width(dstvalue, width, bytes); in vcap_copy_limited_actionfield()
1100 u8 *value, u16 width) in vcap_copy_to_client_actionfield() argument
1102 int field_size = actionfield_size_table[field->ctrl.type]; in vcap_copy_to_client_actionfield()
1104 if (ri->admin->w32be) { in vcap_copy_to_client_actionfield()
1105 switch (field->ctrl.type) { in vcap_copy_to_client_actionfield()
1107 vcap_copy_action_bit_field(&field->data.u1, value); in vcap_copy_to_client_actionfield()
1110 vcap_copy_limited_actionfield((u8 *)&field->data.u32.value, in vcap_copy_to_client_actionfield()
1112 width, field_size); in vcap_copy_to_client_actionfield()
1115 vcap_copy_from_w32be(field->data.u48.value, value, in vcap_copy_to_client_actionfield()
1116 field_size, width); in vcap_copy_to_client_actionfield()
1119 vcap_copy_from_w32be(field->data.u56.value, value, in vcap_copy_to_client_actionfield()
1120 field_size, width); in vcap_copy_to_client_actionfield()
1123 vcap_copy_from_w32be(field->data.u64.value, value, in vcap_copy_to_client_actionfield()
1124 field_size, width); in vcap_copy_to_client_actionfield()
1127 vcap_copy_from_w32be(field->data.u72.value, value, in vcap_copy_to_client_actionfield()
1128 field_size, width); in vcap_copy_to_client_actionfield()
1131 vcap_copy_from_w32be(field->data.u112.value, value, in vcap_copy_to_client_actionfield()
1132 field_size, width); in vcap_copy_to_client_actionfield()
1135 vcap_copy_from_w32be(field->data.u128.value, value, in vcap_copy_to_client_actionfield()
1136 field_size, width); in vcap_copy_to_client_actionfield()
1140 switch (field->ctrl.type) { in vcap_copy_to_client_actionfield()
1142 vcap_copy_action_bit_field(&field->data.u1, value); in vcap_copy_to_client_actionfield()
1145 vcap_copy_limited_actionfield((u8 *)&field->data.u32.value, in vcap_copy_to_client_actionfield()
1147 width, field_size); in vcap_copy_to_client_actionfield()
1150 vcap_copy_limited_actionfield(field->data.u48.value, in vcap_copy_to_client_actionfield()
1152 width, field_size); in vcap_copy_to_client_actionfield()
1155 vcap_copy_limited_actionfield(field->data.u56.value, in vcap_copy_to_client_actionfield()
1157 width, field_size); in vcap_copy_to_client_actionfield()
1160 vcap_copy_limited_actionfield(field->data.u64.value, in vcap_copy_to_client_actionfield()
1162 width, field_size); in vcap_copy_to_client_actionfield()
1165 vcap_copy_limited_actionfield(field->data.u72.value, in vcap_copy_to_client_actionfield()
1167 width, field_size); in vcap_copy_to_client_actionfield()
1170 vcap_copy_limited_actionfield(field->data.u112.value, in vcap_copy_to_client_actionfield()
1172 width, field_size); in vcap_copy_to_client_actionfield()
1175 vcap_copy_limited_actionfield(field->data.u128.value, in vcap_copy_to_client_actionfield()
1177 width, field_size); in vcap_copy_to_client_actionfield()
1186 field->value = (*value) & 0x1; in vcap_copy_key_bit_field()
1187 field->mask = (*mask) & 0x1; in vcap_copy_key_bit_field()
1192 int width, int bytes) in vcap_copy_limited_keyfield() argument
1195 vcap_apply_width(dstvalue, width, bytes); in vcap_copy_limited_keyfield()
1197 vcap_apply_width(dstmask, width, bytes); in vcap_copy_limited_keyfield()
1202 u8 *value, u8 *mask, u16 width) in vcap_copy_to_client_keyfield() argument
1204 int field_size = keyfield_size_table[field->ctrl.type] / 2; in vcap_copy_to_client_keyfield()
1206 if (ri->admin->w32be) { in vcap_copy_to_client_keyfield()
1207 switch (field->ctrl.type) { in vcap_copy_to_client_keyfield()
1209 vcap_copy_key_bit_field(&field->data.u1, value, mask); in vcap_copy_to_client_keyfield()
1212 vcap_copy_limited_keyfield((u8 *)&field->data.u32.value, in vcap_copy_to_client_keyfield()
1213 (u8 *)&field->data.u32.mask, in vcap_copy_to_client_keyfield()
1215 width, field_size); in vcap_copy_to_client_keyfield()
1218 vcap_copy_from_w32be(field->data.u48.value, value, in vcap_copy_to_client_keyfield()
1219 field_size, width); in vcap_copy_to_client_keyfield()
1220 vcap_copy_from_w32be(field->data.u48.mask, mask, in vcap_copy_to_client_keyfield()
1221 field_size, width); in vcap_copy_to_client_keyfield()
1224 vcap_copy_from_w32be(field->data.u56.value, value, in vcap_copy_to_client_keyfield()
1225 field_size, width); in vcap_copy_to_client_keyfield()
1226 vcap_copy_from_w32be(field->data.u56.mask, mask, in vcap_copy_to_client_keyfield()
1227 field_size, width); in vcap_copy_to_client_keyfield()
1230 vcap_copy_from_w32be(field->data.u64.value, value, in vcap_copy_to_client_keyfield()
1231 field_size, width); in vcap_copy_to_client_keyfield()
1232 vcap_copy_from_w32be(field->data.u64.mask, mask, in vcap_copy_to_client_keyfield()
1233 field_size, width); in vcap_copy_to_client_keyfield()
1236 vcap_copy_from_w32be(field->data.u72.value, value, in vcap_copy_to_client_keyfield()
1237 field_size, width); in vcap_copy_to_client_keyfield()
1238 vcap_copy_from_w32be(field->data.u72.mask, mask, in vcap_copy_to_client_keyfield()
1239 field_size, width); in vcap_copy_to_client_keyfield()
1242 vcap_copy_from_w32be(field->data.u112.value, value, in vcap_copy_to_client_keyfield()
1243 field_size, width); in vcap_copy_to_client_keyfield()
1244 vcap_copy_from_w32be(field->data.u112.mask, mask, in vcap_copy_to_client_keyfield()
1245 field_size, width); in vcap_copy_to_client_keyfield()
1248 vcap_copy_from_w32be(field->data.u128.value, value, in vcap_copy_to_client_keyfield()
1249 field_size, width); in vcap_copy_to_client_keyfield()
1250 vcap_copy_from_w32be(field->data.u128.mask, mask, in vcap_copy_to_client_keyfield()
1251 field_size, width); in vcap_copy_to_client_keyfield()
1255 switch (field->ctrl.type) { in vcap_copy_to_client_keyfield()
1257 vcap_copy_key_bit_field(&field->data.u1, value, mask); in vcap_copy_to_client_keyfield()
1260 vcap_copy_limited_keyfield((u8 *)&field->data.u32.value, in vcap_copy_to_client_keyfield()
1261 (u8 *)&field->data.u32.mask, in vcap_copy_to_client_keyfield()
1263 width, field_size); in vcap_copy_to_client_keyfield()
1266 vcap_copy_limited_keyfield(field->data.u48.value, in vcap_copy_to_client_keyfield()
1267 field->data.u48.mask, in vcap_copy_to_client_keyfield()
1269 width, field_size); in vcap_copy_to_client_keyfield()
1272 vcap_copy_limited_keyfield(field->data.u56.value, in vcap_copy_to_client_keyfield()
1273 field->data.u56.mask, in vcap_copy_to_client_keyfield()
1275 width, field_size); in vcap_copy_to_client_keyfield()
1278 vcap_copy_limited_keyfield(field->data.u64.value, in vcap_copy_to_client_keyfield()
1279 field->data.u64.mask, in vcap_copy_to_client_keyfield()
1281 width, field_size); in vcap_copy_to_client_keyfield()
1284 vcap_copy_limited_keyfield(field->data.u72.value, in vcap_copy_to_client_keyfield()
1285 field->data.u72.mask, in vcap_copy_to_client_keyfield()
1287 width, field_size); in vcap_copy_to_client_keyfield()
1290 vcap_copy_limited_keyfield(field->data.u112.value, in vcap_copy_to_client_keyfield()
1291 field->data.u112.mask, in vcap_copy_to_client_keyfield()
1293 width, field_size); in vcap_copy_to_client_keyfield()
1296 vcap_copy_limited_keyfield(field->data.u128.value, in vcap_copy_to_client_keyfield()
1297 field->data.u128.mask, in vcap_copy_to_client_keyfield()
1299 width, field_size); in vcap_copy_to_client_keyfield()
1315 INIT_LIST_HEAD(&field->ctrl.list); in vcap_rule_alloc_keyfield()
1316 field->ctrl.key = key; in vcap_rule_alloc_keyfield()
1317 field->ctrl.type = keyfield->type; in vcap_rule_alloc_keyfield()
1318 vcap_copy_to_client_keyfield(ri, field, value, mask, keyfield->width); in vcap_rule_alloc_keyfield()
1319 list_add_tail(&field->ctrl.list, &ri->data.keyfields); in vcap_rule_alloc_keyfield()
1322 /* Read key data from a VCAP address and discover if there is a rule keyset
1343 /* a type_id of value -1 means that there is no type field */ in vcap_verify_actionstream_actionset()
1344 if (info->type_id == (u8)-1) in vcap_verify_actionstream_actionset()
1360 /* Find the subword width of the action typegroup that matches the stream data
1369 tgt = vctrl->vcaps[vt].actionfield_set_typegroups; in vcap_find_actionstream_typegroup_sw()
1371 for (sw_idx = vctrl->vcaps[vt].sw_count; sw_idx >= 0; sw_idx--) { in vcap_find_actionstream_typegroup_sw()
1374 res = vcap_verify_typegroups(stream, vctrl->vcaps[vt].act_width, in vcap_find_actionstream_typegroup_sw()
1379 return -EINVAL; in vcap_find_actionstream_typegroup_sw()
1400 actionfield_set = vctrl->vcaps[vt].actionfield_set; in vcap_find_actionstream_actionset()
1401 for (idx = 0; idx < vctrl->vcaps[vt].actionfield_set_size; ++idx) { in vcap_find_actionstream_actionset()
1410 return -EINVAL; in vcap_find_actionstream_actionset()
1424 INIT_LIST_HEAD(&field->ctrl.list); in vcap_rule_alloc_actionfield()
1425 field->ctrl.action = action; in vcap_rule_alloc_actionfield()
1426 field->ctrl.type = actionfield->type; in vcap_rule_alloc_actionfield()
1427 vcap_copy_to_client_actionfield(ri, field, value, actionfield->width); in vcap_rule_alloc_actionfield()
1428 list_add_tail(&field->ctrl.list, &ri->data.actionfields); in vcap_rule_alloc_actionfield()
1433 struct vcap_control *vctrl = ri->vctrl; in vcap_decode_actionset()
1434 struct vcap_admin *admin = ri->admin; in vcap_decode_actionset()
1437 enum vcap_type vt = admin->vtype; in vcap_decode_actionset()
1444 actstream = admin->cache.actionstream; in vcap_decode_actionset()
1449 return -EINVAL; in vcap_decode_actionset()
1457 if (actionfield[idx].width <= 0) in vcap_decode_actionset()
1460 memset(value, 0, DIV_ROUND_UP(actionfield[idx].width, 8)); in vcap_decode_actionset()
1461 vcap_iter_init(&iter, vctrl->vcaps[vt].act_width, tgt, in vcap_decode_actionset()
1463 vcap_decode_field(actstream, &iter, actionfield[idx].width, in vcap_decode_actionset()
1466 if (vcap_bitarray_zero(actionfield[idx].width, value)) in vcap_decode_actionset()
1476 struct vcap_control *vctrl = ri->vctrl; in vcap_decode_keyset()
1478 struct vcap_admin *admin = ri->admin; in vcap_decode_keyset()
1481 enum vcap_type vt = admin->vtype; in vcap_decode_keyset()
1491 keystream = admin->cache.keystream; in vcap_decode_keyset()
1492 maskstream = admin->cache.maskstream; in vcap_decode_keyset()
1501 return -EINVAL; in vcap_decode_keyset()
1509 if (keyfield[idx].width <= 0) in vcap_decode_keyset()
1512 memset(mask, 0, DIV_ROUND_UP(keyfield[idx].width, 8)); in vcap_decode_keyset()
1513 vcap_iter_init(&miter, vctrl->vcaps[vt].sw_width, tgt, in vcap_decode_keyset()
1515 vcap_decode_field(maskstream, &miter, keyfield[idx].width, in vcap_decode_keyset()
1518 if (vcap_bitarray_zero(keyfield[idx].width, mask)) in vcap_decode_keyset()
1521 memset(value, 0, DIV_ROUND_UP(keyfield[idx].width, 8)); in vcap_decode_keyset()
1522 vcap_iter_init(&kiter, vctrl->vcaps[vt].sw_width, tgt, in vcap_decode_keyset()
1524 vcap_decode_field(keystream, &kiter, keyfield[idx].width, in vcap_decode_keyset()
1534 struct vcap_admin *admin = ri->admin; in vcap_read_rule()
1536 u32 addr = ri->addr; in vcap_read_rule()
1538 if (!ri->size || !ri->keyset_sw_regs || !ri->actionset_sw_regs) { in vcap_read_rule()
1540 return -EINVAL; in vcap_read_rule()
1544 for (sw_idx = 0; sw_idx < ri->size; sw_idx++, addr++) { in vcap_read_rule()
1545 ri->vctrl->ops->update(ri->ndev, admin, VCAP_CMD_READ, in vcap_read_rule()
1547 ri->vctrl->ops->cache_read(ri->ndev, admin, in vcap_read_rule()
1549 ri->keyset_sw_regs); in vcap_read_rule()
1550 ri->vctrl->ops->cache_read(ri->ndev, admin, in vcap_read_rule()
1552 ri->actionset_sw_regs); in vcap_read_rule()
1554 ri->vctrl->ops->cache_read(ri->ndev, admin, in vcap_read_rule()
1556 ri->counter_id, 0); in vcap_read_rule()
1557 ent_idx += ri->keyset_sw_regs; in vcap_read_rule()
1558 act_idx += ri->actionset_sw_regs; in vcap_read_rule()
1566 struct vcap_admin *admin = ri->admin; in vcap_write_rule()
1568 u32 addr = ri->addr; in vcap_write_rule()
1570 if (!ri->size || !ri->keyset_sw_regs || !ri->actionset_sw_regs) { in vcap_write_rule()
1572 return -EINVAL; in vcap_write_rule()
1575 for (sw_idx = 0; sw_idx < ri->size; sw_idx++, addr++) { in vcap_write_rule()
1576 ri->vctrl->ops->cache_write(ri->ndev, admin, in vcap_write_rule()
1578 ri->keyset_sw_regs); in vcap_write_rule()
1579 ri->vctrl->ops->cache_write(ri->ndev, admin, in vcap_write_rule()
1581 ri->actionset_sw_regs); in vcap_write_rule()
1582 ri->vctrl->ops->update(ri->ndev, admin, VCAP_CMD_WRITE, in vcap_write_rule()
1584 ent_idx += ri->keyset_sw_regs; in vcap_write_rule()
1585 act_idx += ri->actionset_sw_regs; in vcap_write_rule()
1593 struct vcap_admin *admin = ri->admin; in vcap_write_counter()
1595 admin->cache.counter = ctr->value; in vcap_write_counter()
1596 admin->cache.sticky = ctr->sticky; in vcap_write_counter()
1597 ri->vctrl->ops->cache_write(ri->ndev, admin, VCAP_SEL_COUNTER, in vcap_write_counter()
1598 ri->counter_id, 0); in vcap_write_counter()
1599 ri->vctrl->ops->update(ri->ndev, admin, VCAP_CMD_WRITE, in vcap_write_counter()
1600 VCAP_SEL_COUNTER, ri->addr); in vcap_write_counter()
1607 int lookup_first = admin->vinst * admin->lookups_per_instance; in vcap_chain_id_to_lookup()
1608 int lookup_last = lookup_first + admin->lookups_per_instance; in vcap_chain_id_to_lookup()
1609 int cid_next = admin->first_cid + VCAP_CID_LOOKUP_SIZE; in vcap_chain_id_to_lookup()
1610 int cid = admin->first_cid; in vcap_chain_id_to_lookup()
1629 list_for_each_entry(admin, &vctrl->list, list) { in vcap_find_admin()
1630 if (cid >= admin->first_cid && cid <= admin->last_cid) in vcap_find_admin()
1645 list_for_each_entry(iter, &vctrl->list, list) { in vcap_admin_is_last()
1646 if (iter->first_cid > max_cid && in vcap_admin_is_last()
1647 iter->ingress == ingress) { in vcap_admin_is_last()
1649 max_cid = iter->first_cid; in vcap_admin_is_last()
1661 int diff = to_cid - from_cid; in vcap_chain_offset()
1702 if (admin->last_used_addr - size < admin->first_valid_addr) { in vcap_rule_space()
1704 __func__, __LINE__, size, admin->first_valid_addr); in vcap_rule_space()
1705 return -ENOSPC; in vcap_rule_space()
1714 enum vcap_keyfield_set keyset = rule->keyset; in vcap_add_type_keyfield()
1715 enum vcap_type vt = ri->admin->vtype; in vcap_add_type_keyfield()
1718 int ret = -EINVAL; in vcap_add_type_keyfield()
1720 kset = vcap_keyfieldset(ri->vctrl, vt, keyset); in vcap_add_type_keyfield()
1723 if (kset->type_id == (u8)-1) /* No type field is needed */ in vcap_add_type_keyfield()
1726 fields = vcap_keyfields(ri->vctrl, vt, keyset); in vcap_add_type_keyfield()
1728 return -EINVAL; in vcap_add_type_keyfield()
1729 if (fields[VCAP_KF_TYPE].width > 1) { in vcap_add_type_keyfield()
1731 kset->type_id, 0xff); in vcap_add_type_keyfield()
1733 if (kset->type_id) in vcap_add_type_keyfield()
1746 enum vcap_actionfield_set actionset = rule->actionset; in vcap_add_type_actionfield()
1748 enum vcap_type vt = ri->admin->vtype; in vcap_add_type_actionfield()
1751 int ret = -EINVAL; in vcap_add_type_actionfield()
1753 aset = vcap_actionfieldset(ri->vctrl, vt, actionset); in vcap_add_type_actionfield()
1756 if (aset->type_id == (u8)-1) /* No type field is needed */ in vcap_add_type_actionfield()
1759 fields = vcap_actionfields(ri->vctrl, vt, actionset); in vcap_add_type_actionfield()
1761 return -EINVAL; in vcap_add_type_actionfield()
1762 if (fields[VCAP_AF_TYPE].width > 1) { in vcap_add_type_actionfield()
1764 aset->type_id); in vcap_add_type_actionfield()
1766 if (aset->type_id) in vcap_add_type_actionfield()
1782 if (keysetlist->cnt < keysetlist->max) { in vcap_keyset_list_add()
1784 for (idx = 0; idx < keysetlist->cnt; ++idx) in vcap_keyset_list_add()
1785 if (keysetlist->keysets[idx] == keyset) in vcap_keyset_list_add()
1786 return keysetlist->cnt < keysetlist->max; in vcap_keyset_list_add()
1787 keysetlist->keysets[keysetlist->cnt++] = keyset; in vcap_keyset_list_add()
1789 return keysetlist->cnt < keysetlist->max; in vcap_keyset_list_add()
1799 if (actionsetlist->cnt < actionsetlist->max) { in vcap_actionset_list_add()
1801 for (idx = 0; idx < actionsetlist->cnt; ++idx) in vcap_actionset_list_add()
1802 if (actionsetlist->actionsets[idx] == actionset) in vcap_actionset_list_add()
1803 return actionsetlist->cnt < actionsetlist->max; in vcap_actionset_list_add()
1804 actionsetlist->actionsets[actionsetlist->cnt++] = actionset; in vcap_actionset_list_add()
1806 return actionsetlist->cnt < actionsetlist->max; in vcap_actionset_list_add()
1813 return vctrl->stats->keyfield_set_names[keyset]; in vcap_keyset_name()
1821 return vctrl->stats->keyfield_names[key]; in vcap_keyfield_name()
1829 return vctrl->stats->actionfield_set_names[actionset]; in vcap_actionset_name()
1836 return vctrl->stats->actionfield_names[action]; in vcap_actionfield_name()
1856 if (fields[idx].width == 0) in vcap_find_keyset_keyfield()
1875 vtype = ri->admin->vtype; in _vcap_rule_find_keysets()
1876 map = ri->vctrl->vcaps[vtype].keyfield_set_map; in _vcap_rule_find_keysets()
1877 map_size = ri->vctrl->vcaps[vtype].keyfield_set_size; in _vcap_rule_find_keysets()
1881 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) in _vcap_rule_find_keysets()
1884 matches->cnt = 0; in _vcap_rule_find_keysets()
1892 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) in _vcap_rule_find_keysets()
1893 if (vcap_find_keyset_keyfield(ri->vctrl, vtype, in _vcap_rule_find_keysets()
1894 keyset, ckf->ctrl.key)) in _vcap_rule_find_keysets()
1904 return matches->cnt > 0; in _vcap_rule_find_keysets()
1934 if (fields[idx].width == 0) in vcap_find_actionset_actionfield()
1953 vtype = ri->admin->vtype; in vcap_rule_find_actionsets()
1954 map = ri->vctrl->vcaps[vtype].actionfield_set_map; in vcap_rule_find_actionsets()
1955 map_size = ri->vctrl->vcaps[vtype].actionfield_set_size; in vcap_rule_find_actionsets()
1959 list_for_each_entry(ckf, &ri->data.actionfields, ctrl.list) in vcap_rule_find_actionsets()
1962 matches->cnt = 0; in vcap_rule_find_actionsets()
1970 list_for_each_entry(ckf, &ri->data.actionfields, ctrl.list) in vcap_rule_find_actionsets()
1971 if (vcap_find_actionset_actionfield(ri->vctrl, vtype, in vcap_rule_find_actionsets()
1973 ckf->ctrl.action)) in vcap_rule_find_actionsets()
1983 return matches->cnt > 0; in vcap_rule_find_actionsets()
1994 ret = vcap_api_check(ri->vctrl); in vcap_val_rule()
1997 if (!ri->admin) { in vcap_val_rule()
1998 ri->data.exterr = VCAP_ERR_NO_ADMIN; in vcap_val_rule()
1999 return -EINVAL; in vcap_val_rule()
2001 if (!ri->ndev) { in vcap_val_rule()
2002 ri->data.exterr = VCAP_ERR_NO_NETDEV; in vcap_val_rule()
2003 return -EINVAL; in vcap_val_rule()
2008 if (ri->data.keyset == VCAP_KFS_NO_VALUE) { in vcap_val_rule()
2011 ri->data.exterr = VCAP_ERR_NO_KEYSET_MATCH; in vcap_val_rule()
2012 return -EINVAL; in vcap_val_rule()
2016 keysets[0] = ri->data.keyset; in vcap_val_rule()
2021 ret = ri->vctrl->ops->validate_keyset(ri->ndev, ri->admin, rule, in vcap_val_rule()
2026 ri->data.exterr = VCAP_ERR_NO_PORT_KEYSET_MATCH; in vcap_val_rule()
2036 if (ri->data.actionset == VCAP_AFS_NO_VALUE) { in vcap_val_rule()
2045 ri->data.exterr = VCAP_ERR_NO_ACTIONSET_MATCH; in vcap_val_rule()
2046 return -EINVAL; in vcap_val_rule()
2058 ri->vctrl->ops->add_default_fields(ri->ndev, ri->admin, rule); in vcap_val_rule()
2061 ri->size = max(ri->keyset_sw, ri->actionset_sw); in vcap_val_rule()
2064 return vcap_rule_space(ri->admin, ri->size); in vcap_val_rule()
2071 * (max_size - size).
2075 return ((max_size - size) << 24) | (user << 16) | prio; in vcap_sort_key()
2081 return ((addr - ri->size) / ri->size) * ri->size; in vcap_next_rule_addr()
2087 if (ri->data.id != 0) in vcap_set_rule_id()
2088 return ri->data.id; in vcap_set_rule_id()
2091 if (!vcap_rule_exists(ri->vctrl, next_id)) { in vcap_set_rule_id()
2092 ri->data.id = next_id; in vcap_set_rule_id()
2096 return ri->data.id; in vcap_set_rule_id()
2102 int sw_count = ri->vctrl->vcaps[ri->admin->vtype].sw_count; in vcap_insert_rule()
2104 struct vcap_admin *admin = ri->admin; in vcap_insert_rule()
2107 ri->sort_key = vcap_sort_key(sw_count, ri->size, ri->data.user, in vcap_insert_rule()
2108 ri->data.priority); in vcap_insert_rule()
2115 list_for_each_entry(iter, &admin->rules, list) { in vcap_insert_rule()
2116 if (ri->sort_key < iter->sort_key) { in vcap_insert_rule()
2123 ri->addr = vcap_next_rule_addr(admin->last_used_addr, ri); in vcap_insert_rule()
2124 admin->last_used_addr = ri->addr; in vcap_insert_rule()
2127 duprule = vcap_dup_rule(ri, ri->state == VCAP_RS_DISABLED); in vcap_insert_rule()
2131 list_add_tail(&duprule->list, &admin->rules); in vcap_insert_rule()
2136 addr = elem->addr + elem->size; in vcap_insert_rule()
2137 ri->addr = vcap_next_rule_addr(addr, ri); in vcap_insert_rule()
2138 addr = ri->addr; in vcap_insert_rule()
2141 duprule = vcap_dup_rule(ri, ri->state == VCAP_RS_DISABLED); in vcap_insert_rule()
2146 list_add_tail(&duprule->list, &elem->list); in vcap_insert_rule()
2149 elem->addr = vcap_next_rule_addr(addr, elem); in vcap_insert_rule()
2150 addr = elem->addr; in vcap_insert_rule()
2153 list_for_each_entry_continue(elem, &admin->rules, list) { in vcap_insert_rule()
2154 elem->addr = vcap_next_rule_addr(addr, elem); in vcap_insert_rule()
2155 addr = elem->addr; in vcap_insert_rule()
2159 move->addr = admin->last_used_addr; in vcap_insert_rule()
2160 move->count = ri->addr - addr; in vcap_insert_rule()
2161 move->offset = admin->last_used_addr - addr; in vcap_insert_rule()
2162 admin->last_used_addr = addr; in vcap_insert_rule()
2169 ri->vctrl->ops->move(ri->ndev, ri->admin, move->addr, in vcap_move_rules()
2170 move->offset, move->count); in vcap_move_rules()
2180 list_for_each_entry(admin, &vctrl->list, list) in vcap_is_chain_used()
2181 list_for_each_entry(eport, &admin->enabled, list) in vcap_is_chain_used()
2182 if (eport->src_cid == src_cid && eport->ndev == ndev) in vcap_is_chain_used()
2196 list_for_each_entry(admin, &vctrl->list, list) { in vcap_get_next_chain()
2197 list_for_each_entry(eport, &admin->enabled, list) { in vcap_get_next_chain()
2198 if (eport->ndev != ndev) in vcap_get_next_chain()
2200 if (eport->src_cid == dst_cid) in vcap_get_next_chain()
2201 return eport->dst_cid; in vcap_get_next_chain()
2221 list_for_each_entry(admin, &vctrl->list, list) { in vcap_path_exist()
2222 list_for_each_entry(elem, &admin->enabled, list) { in vcap_path_exist()
2223 if (elem->src_cid == 0 && elem->ndev == ndev) { in vcap_path_exist()
2235 tmp = eport->dst_cid; in vcap_path_exist()
2249 if (ri->data.user <= VCAP_USER_QOS) in vcap_rule_set_state()
2250 ri->state = VCAP_RS_PERMANENT; in vcap_rule_set_state()
2251 else if (vcap_path_exist(ri->vctrl, ri->ndev, ri->data.vcap_chain_id)) in vcap_rule_set_state()
2252 ri->state = VCAP_RS_ENABLED; in vcap_rule_set_state()
2254 ri->state = VCAP_RS_DISABLED; in vcap_rule_set_state()
2265 ret = vcap_api_check(ri->vctrl); in vcap_add_rule()
2269 mutex_lock(&ri->admin->lock); in vcap_add_rule()
2286 if (ri->state == VCAP_RS_DISABLED) { in vcap_add_rule()
2288 ri->vctrl->ops->init(ri->ndev, ri->admin, ri->addr, ri->size); in vcap_add_rule()
2305 mutex_unlock(&ri->admin->lock); in vcap_add_rule()
2324 return ERR_PTR(-ENODEV); in vcap_alloc_rule()
2328 return ERR_PTR(-ENOENT); in vcap_alloc_rule()
2330 if (vctrl->vcaps[admin->vtype].rows == 0) in vcap_alloc_rule()
2331 return ERR_PTR(-EINVAL); in vcap_alloc_rule()
2333 mutex_lock(&admin->lock); in vcap_alloc_rule()
2336 err = -EINVAL; in vcap_alloc_rule()
2341 maxsize = vctrl->vcaps[admin->vtype].sw_count; /* worst case rule size */ in vcap_alloc_rule()
2343 err = -ENOSPC; in vcap_alloc_rule()
2350 err = -ENOMEM; in vcap_alloc_rule()
2354 ri->data.vcap_chain_id = vcap_chain_id; in vcap_alloc_rule()
2355 ri->data.user = user; in vcap_alloc_rule()
2356 ri->data.priority = priority; in vcap_alloc_rule()
2357 ri->data.id = id; in vcap_alloc_rule()
2358 ri->data.keyset = VCAP_KFS_NO_VALUE; in vcap_alloc_rule()
2359 ri->data.actionset = VCAP_AFS_NO_VALUE; in vcap_alloc_rule()
2360 INIT_LIST_HEAD(&ri->list); in vcap_alloc_rule()
2361 INIT_LIST_HEAD(&ri->data.keyfields); in vcap_alloc_rule()
2362 INIT_LIST_HEAD(&ri->data.actionfields); in vcap_alloc_rule()
2363 ri->ndev = ndev; in vcap_alloc_rule()
2364 ri->admin = admin; /* refer to the vcap instance */ in vcap_alloc_rule()
2365 ri->vctrl = vctrl; /* refer to the client */ in vcap_alloc_rule()
2368 err = -EINVAL; in vcap_alloc_rule()
2372 mutex_unlock(&admin->lock); in vcap_alloc_rule()
2378 mutex_unlock(&admin->lock); in vcap_alloc_rule()
2392 list_for_each_entry_safe(ckf, next_ckf, &ri->data.keyfields, ctrl.list) { in vcap_free_rule()
2393 list_del(&ckf->ctrl.list); in vcap_free_rule()
2396 list_for_each_entry_safe(caf, next_caf, &ri->data.actionfields, ctrl.list) { in vcap_free_rule()
2397 list_del(&caf->ctrl.list); in vcap_free_rule()
2411 ri = vcap_dup_rule(elem, elem->state == VCAP_RS_DISABLED); in vcap_decode_rule()
2415 if (ri->state == VCAP_RS_DISABLED) in vcap_decode_rule()
2431 return &ri->data; in vcap_decode_rule()
2446 return ERR_PTR(-ENOENT); in vcap_get_rule()
2449 mutex_unlock(&elem->admin->lock); in vcap_get_rule()
2461 err = vcap_api_check(ri->vctrl); in vcap_mod_rule()
2465 if (!vcap_get_locked_rule(ri->vctrl, ri->data.id)) in vcap_mod_rule()
2466 return -ENOENT; in vcap_mod_rule()
2469 if (ri->state == VCAP_RS_DISABLED) in vcap_mod_rule()
2486 mutex_unlock(&ri->admin->lock); in vcap_mod_rule()
2494 return (el->addr + offset) % el->size; in vcap_valid_rule_move()
2500 el->addr += offset; in vcap_adjust_rule_addr()
2506 struct vcap_admin *admin = ri->admin; in vcap_fill_rule_gap()
2512 if (list_is_first(&ri->list, &admin->rules)) in vcap_fill_rule_gap()
2513 offset = admin->last_valid_addr + 1 - ri->addr - ri->size; in vcap_fill_rule_gap()
2517 list_for_each_entry_continue(elem, &admin->rules, list) in vcap_fill_rule_gap()
2518 gap += vcap_valid_rule_move(elem, ri->size); in vcap_fill_rule_gap()
2522 list_for_each_entry_continue(elem, &admin->rules, list) in vcap_fill_rule_gap()
2523 vcap_adjust_rule_addr(elem, ri->size + gap + offset); in vcap_fill_rule_gap()
2526 move.addr = admin->last_used_addr; in vcap_fill_rule_gap()
2527 move.count = ri->addr - admin->last_used_addr - gap; in vcap_fill_rule_gap()
2528 move.offset = -(ri->size + gap + offset); in vcap_fill_rule_gap()
2545 return -ENODEV; in vcap_del_rule()
2552 return -ENOENT; in vcap_del_rule()
2554 admin = ri->admin; in vcap_del_rule()
2556 if (ri->addr > admin->last_used_addr) in vcap_del_rule()
2560 list_del(&ri->list); in vcap_del_rule()
2561 vctrl->ops->init(ndev, admin, admin->last_used_addr, ri->size + gap); in vcap_del_rule()
2562 vcap_free_rule(&ri->data); in vcap_del_rule()
2565 if (list_empty(&admin->rules)) { in vcap_del_rule()
2566 admin->last_used_addr = admin->last_valid_addr + 1; in vcap_del_rule()
2568 elem = list_last_entry(&admin->rules, struct vcap_rule_internal, in vcap_del_rule()
2570 admin->last_used_addr = elem->addr; in vcap_del_rule()
2573 mutex_unlock(&admin->lock); in vcap_del_rule()
2588 mutex_lock(&admin->lock); in vcap_del_rules()
2589 list_for_each_entry_safe(ri, next_ri, &admin->rules, list) { in vcap_del_rules()
2590 vctrl->ops->init(ri->ndev, admin, ri->addr, ri->size); in vcap_del_rules()
2591 list_del(&ri->list); in vcap_del_rules()
2592 vcap_free_rule(&ri->data); in vcap_del_rules()
2594 admin->last_used_addr = admin->last_valid_addr; in vcap_del_rules()
2597 list_for_each_entry_safe(eport, next_eport, &admin->enabled, list) { in vcap_del_rules()
2598 list_del(&eport->list); in vcap_del_rules()
2601 mutex_unlock(&admin->lock); in vcap_del_rules()
2614 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) in vcap_find_keyfield()
2615 if (ckf->ctrl.key == key) in vcap_find_keyfield()
2625 enum vcap_keyfield_set keyset = rule->keyset; in vcap_lookup_keyfield()
2626 enum vcap_type vt = ri->admin->vtype; in vcap_lookup_keyfield()
2631 fields = vcap_keyfields(ri->vctrl, vt, keyset); in vcap_lookup_keyfield()
2645 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) in vcap_keyfield_unique()
2646 if (ckf->ctrl.key == key) in vcap_keyfield_unique()
2656 enum vcap_keyfield_set keyset = rule->keyset; in vcap_keyfield_match_keyset()
2657 enum vcap_type vt = ri->admin->vtype; in vcap_keyfield_match_keyset()
2663 fields = vcap_keyfields(ri->vctrl, vt, keyset); in vcap_keyfield_match_keyset()
2666 /* if there is a width there is a way */ in vcap_keyfield_match_keyset()
2667 return fields[key].width > 0; in vcap_keyfield_match_keyset()
2673 struct vcap_client_keyfield_data *data) in vcap_rule_add_key() argument
2681 vcap_keyfield_name(ri->vctrl, key)); in vcap_rule_add_key()
2682 return -EINVAL; in vcap_rule_add_key()
2688 vcap_keyfield_name(ri->vctrl, key)); in vcap_rule_add_key()
2689 return -EINVAL; in vcap_rule_add_key()
2694 return -ENOMEM; in vcap_rule_add_key()
2695 memcpy(&field->data, data, sizeof(field->data)); in vcap_rule_add_key()
2696 field->ctrl.key = key; in vcap_rule_add_key()
2697 field->ctrl.type = ftype; in vcap_rule_add_key()
2698 list_add_tail(&field->ctrl.list, &rule->keyfields); in vcap_rule_add_key()
2706 u1->value = 0; in vcap_rule_set_key_bitsize()
2707 u1->mask = 1; in vcap_rule_set_key_bitsize()
2710 u1->value = 1; in vcap_rule_set_key_bitsize()
2711 u1->mask = 1; in vcap_rule_set_key_bitsize()
2714 u1->value = 0; in vcap_rule_set_key_bitsize()
2715 u1->mask = 0; in vcap_rule_set_key_bitsize()
2724 struct vcap_client_keyfield_data data; in vcap_rule_add_key_bit() local
2726 vcap_rule_set_key_bitsize(&data.u1, val); in vcap_rule_add_key_bit()
2727 return vcap_rule_add_key(rule, key, VCAP_FIELD_BIT, &data); in vcap_rule_add_key_bit()
2735 struct vcap_client_keyfield_data data; in vcap_rule_add_key_u32() local
2737 data.u32.value = value; in vcap_rule_add_key_u32()
2738 data.u32.mask = mask; in vcap_rule_add_key_u32()
2739 return vcap_rule_add_key(rule, key, VCAP_FIELD_U32, &data); in vcap_rule_add_key_u32()
2747 struct vcap_client_keyfield_data data; in vcap_rule_add_key_u48() local
2749 memcpy(&data.u48, fieldval, sizeof(data.u48)); in vcap_rule_add_key_u48()
2750 return vcap_rule_add_key(rule, key, VCAP_FIELD_U48, &data); in vcap_rule_add_key_u48()
2758 struct vcap_client_keyfield_data data; in vcap_rule_add_key_u72() local
2760 memcpy(&data.u72, fieldval, sizeof(data.u72)); in vcap_rule_add_key_u72()
2761 return vcap_rule_add_key(rule, key, VCAP_FIELD_U72, &data); in vcap_rule_add_key_u72()
2769 struct vcap_client_keyfield_data data; in vcap_rule_add_key_u128() local
2771 memcpy(&data.u128, fieldval, sizeof(data.u128)); in vcap_rule_add_key_u128()
2772 return vcap_rule_add_key(rule, key, VCAP_FIELD_U128, &data); in vcap_rule_add_key_u128()
2783 return -ENOENT; in vcap_rule_get_key_u32()
2785 *value = ckf->data.u32.value; in vcap_rule_get_key_u32()
2786 *mask = ckf->data.u32.mask; in vcap_rule_get_key_u32()
2799 list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) in vcap_find_actionfield()
2800 if (caf->ctrl.action == act) in vcap_find_actionfield()
2813 list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) in vcap_actionfield_unique()
2814 if (caf->ctrl.action == act) in vcap_actionfield_unique()
2823 enum vcap_actionfield_set actionset = rule->actionset; in vcap_actionfield_match_actionset()
2825 enum vcap_type vt = ri->admin->vtype; in vcap_actionfield_match_actionset()
2831 fields = vcap_actionfields(ri->vctrl, vt, actionset); in vcap_actionfield_match_actionset()
2834 /* if there is a width there is a way */ in vcap_actionfield_match_actionset()
2835 return fields[action].width > 0; in vcap_actionfield_match_actionset()
2841 struct vcap_client_actionfield_data *data) in vcap_rule_add_action() argument
2849 vcap_actionfield_name(ri->vctrl, action)); in vcap_rule_add_action()
2850 return -EINVAL; in vcap_rule_add_action()
2856 vcap_actionfield_name(ri->vctrl, action)); in vcap_rule_add_action()
2857 return -EINVAL; in vcap_rule_add_action()
2862 return -ENOMEM; in vcap_rule_add_action()
2863 memcpy(&field->data, data, sizeof(field->data)); in vcap_rule_add_action()
2864 field->ctrl.action = action; in vcap_rule_add_action()
2865 field->ctrl.type = ftype; in vcap_rule_add_action()
2866 list_add_tail(&field->ctrl.list, &rule->actionfields); in vcap_rule_add_action()
2875 u1->value = 0; in vcap_rule_set_action_bitsize()
2878 u1->value = 1; in vcap_rule_set_action_bitsize()
2881 u1->value = 0; in vcap_rule_set_action_bitsize()
2891 struct vcap_client_actionfield_data data; in vcap_rule_add_action_bit() local
2893 vcap_rule_set_action_bitsize(&data.u1, val); in vcap_rule_add_action_bit()
2894 return vcap_rule_add_action(rule, action, VCAP_FIELD_BIT, &data); in vcap_rule_add_action_bit()
2903 struct vcap_client_actionfield_data data; in vcap_rule_add_action_u32() local
2905 data.u32.value = value; in vcap_rule_add_action_u32()
2906 return vcap_rule_add_action(rule, action, VCAP_FIELD_U32, &data); in vcap_rule_add_action_u32()
2915 struct vcap_client_actionfield_data data; in vcap_rule_add_action_u72() local
2917 memcpy(&data.u72, fieldval, sizeof(data.u72)); in vcap_rule_add_action_u72()
2918 return vcap_rule_add_action(rule, action, VCAP_FIELD_U72, &data); in vcap_rule_add_action_u72()
2925 struct vcap_admin *admin = ri->admin; in vcap_read_counter()
2927 ri->vctrl->ops->update(ri->ndev, admin, VCAP_CMD_READ, VCAP_SEL_COUNTER, in vcap_read_counter()
2928 ri->addr); in vcap_read_counter()
2929 ri->vctrl->ops->cache_read(ri->ndev, admin, VCAP_SEL_COUNTER, in vcap_read_counter()
2930 ri->counter_id, 0); in vcap_read_counter()
2931 ctr->value = admin->cache.counter; in vcap_read_counter()
2932 ctr->sticky = admin->cache.sticky; in vcap_read_counter()
2942 *dst = src[count - idx - 1]; in vcap_netbytes_copy()
2949 switch (vrule->exterr) { in vcap_set_tc_exterr()
2953 NL_SET_ERR_MSG_MOD(fco->common.extack, in vcap_set_tc_exterr()
2957 NL_SET_ERR_MSG_MOD(fco->common.extack, in vcap_set_tc_exterr()
2961 NL_SET_ERR_MSG_MOD(fco->common.extack, in vcap_set_tc_exterr()
2965 NL_SET_ERR_MSG_MOD(fco->common.extack, in vcap_set_tc_exterr()
2969 NL_SET_ERR_MSG_MOD(fco->common.extack, in vcap_set_tc_exterr()
2992 list_for_each_entry_safe(kf, nkf, &ri->data.keyfields, ctrl.list) { in vcap_enable_rule()
2993 list_del(&kf->ctrl.list); in vcap_enable_rule()
2996 list_for_each_entry_safe(af, naf, &ri->data.actionfields, ctrl.list) { in vcap_enable_rule()
2997 list_del(&af->ctrl.list); in vcap_enable_rule()
3000 ri->state = VCAP_RS_ENABLED; in vcap_enable_rule()
3014 list_for_each_entry(admin, &vctrl->list, list) { in vcap_enable_rules()
3015 if (!(chain >= admin->first_cid && chain <= admin->last_cid)) in vcap_enable_rules()
3019 mutex_lock(&admin->lock); in vcap_enable_rules()
3020 list_for_each_entry(ri, &admin->rules, list) { in vcap_enable_rules()
3022 if (!(ri->data.vcap_chain_id >= chain && in vcap_enable_rules()
3023 ri->data.vcap_chain_id < next_chain)) { in vcap_enable_rules()
3027 if (ri->ndev != ndev) in vcap_enable_rules()
3030 if (ri->state != VCAP_RS_DISABLED) in vcap_enable_rules()
3037 mutex_unlock(&admin->lock); in vcap_enable_rules()
3059 ri->state = VCAP_RS_DISABLED; in vcap_disable_rule()
3060 ri->vctrl->ops->init(ri->ndev, ri->admin, ri->addr, ri->size); in vcap_disable_rule()
3072 list_for_each_entry(admin, &vctrl->list, list) { in vcap_disable_rules()
3073 if (!(chain >= admin->first_cid && chain <= admin->last_cid)) in vcap_disable_rules()
3077 mutex_lock(&admin->lock); in vcap_disable_rules()
3078 list_for_each_entry(ri, &admin->rules, list) { in vcap_disable_rules()
3079 if (ri->data.vcap_chain_id != chain) in vcap_disable_rules()
3082 if (ri->ndev != ndev) in vcap_disable_rules()
3085 if (ri->state != VCAP_RS_ENABLED) in vcap_disable_rules()
3092 mutex_unlock(&admin->lock); in vcap_disable_rules()
3106 list_for_each_entry(admin, &vctrl->list, list) in vcap_is_enabled()
3107 list_for_each_entry(eport, &admin->enabled, list) in vcap_is_enabled()
3108 if (eport->dst_cid == dst_cid && eport->ndev == ndev) in vcap_is_enabled()
3122 return -EFAULT; in vcap_enable()
3126 return -ENOENT; in vcap_enable()
3130 return -ENOMEM; in vcap_enable()
3132 eport->ndev = ndev; in vcap_enable()
3133 eport->cookie = cookie; in vcap_enable()
3134 eport->src_cid = src_cid; in vcap_enable()
3135 eport->dst_cid = dst_cid; in vcap_enable()
3136 mutex_lock(&admin->lock); in vcap_enable()
3137 list_add_tail(&eport->list, &admin->enabled); in vcap_enable()
3138 mutex_unlock(&admin->lock); in vcap_enable()
3145 return -ENOENT; in vcap_enable()
3162 list_for_each_entry(admin, &vctrl->list, list) { in vcap_disable()
3163 list_for_each_entry(elem, &admin->enabled, list) { in vcap_disable()
3164 if (elem->cookie == cookie && elem->ndev == ndev) { in vcap_disable()
3175 return -ENOENT; in vcap_disable()
3178 dst_cid = eport->dst_cid; in vcap_disable()
3182 return -ENOENT; in vcap_disable()
3188 mutex_lock(&found->lock); in vcap_disable()
3189 list_del(&eport->list); in vcap_disable()
3190 mutex_unlock(&found->lock); in vcap_disable()
3207 return -ENODEV; in vcap_enable_lookups()
3211 return -EFAULT; in vcap_enable_lookups()
3213 return -EFAULT; in vcap_enable_lookups()
3217 return -EADDRINUSE; in vcap_enable_lookups()
3219 return -EADDRNOTAVAIL; in vcap_enable_lookups()
3247 return lookup == admin->lookups - 1; in vcap_is_last_chain()
3256 ri->counter_id = counter_id; in vcap_rule_set_counter_id()
3265 err = vcap_api_check(ri->vctrl); in vcap_rule_set_counter()
3270 return -EINVAL; in vcap_rule_set_counter()
3273 mutex_lock(&ri->admin->lock); in vcap_rule_set_counter()
3275 mutex_unlock(&ri->admin->lock); in vcap_rule_set_counter()
3286 err = vcap_api_check(ri->vctrl); in vcap_rule_get_counter()
3291 return -EINVAL; in vcap_rule_get_counter()
3294 mutex_lock(&ri->admin->lock); in vcap_rule_get_counter()
3296 mutex_unlock(&ri->admin->lock); in vcap_rule_get_counter()
3311 return -EINVAL; in vcap_rule_get_key()
3313 INIT_LIST_HEAD(&ckf->ctrl.list); in vcap_rule_get_key()
3323 struct vcap_control *vctrl = ri->vctrl; in vcap_rule_get_untyped_keyset()
3324 enum vcap_type vt = ri->admin->vtype; in vcap_rule_get_untyped_keyset()
3328 keyfield_set = vctrl->vcaps[vt].keyfield_set; in vcap_rule_get_untyped_keyset()
3329 for (idx = 0; idx < vctrl->vcaps[vt].keyfield_set_size; ++idx) { in vcap_rule_get_untyped_keyset()
3330 if (keyfield_set[idx].sw_per_item == ri->keyset_sw && in vcap_rule_get_untyped_keyset()
3331 keyfield_set[idx].type_id == (u8)-1) { in vcap_rule_get_untyped_keyset()
3336 return -EINVAL; in vcap_rule_get_untyped_keyset()
3343 struct vcap_control *vctrl = ri->vctrl; in vcap_rule_get_keysets()
3344 enum vcap_type vt = ri->admin->vtype; in vcap_rule_get_keysets()
3350 err = vcap_rule_get_key(&ri->data, VCAP_KF_TYPE, &kf); in vcap_rule_get_keysets()
3355 value = kf.data.u1.value; in vcap_rule_get_keysets()
3356 mask = kf.data.u1.mask; in vcap_rule_get_keysets()
3358 value = kf.data.u32.value; in vcap_rule_get_keysets()
3359 mask = kf.data.u32.mask; in vcap_rule_get_keysets()
3361 return -EINVAL; in vcap_rule_get_keysets()
3364 keyfield_set = vctrl->vcaps[vt].keyfield_set; in vcap_rule_get_keysets()
3365 for (idx = 0; idx < vctrl->vcaps[vt].keyfield_set_size; ++idx) { in vcap_rule_get_keysets()
3366 if (keyfield_set[idx].sw_per_item != ri->keyset_sw) in vcap_rule_get_keysets()
3369 if (keyfield_set[idx].type_id == (u8)-1) { in vcap_rule_get_keysets()
3377 if (matches->cnt > 0) in vcap_rule_get_keysets()
3380 return -EINVAL; in vcap_rule_get_keysets()
3397 list_for_each_entry(admin, &vctrl->list, list) { in vcap_get_rule_count_by_cookie()
3398 mutex_lock(&admin->lock); in vcap_get_rule_count_by_cookie()
3399 list_for_each_entry(ri, &admin->rules, list) { in vcap_get_rule_count_by_cookie()
3400 if (ri->data.cookie != cookie) in vcap_get_rule_count_by_cookie()
3406 ctr->value += temp.value; in vcap_get_rule_count_by_cookie()
3415 mutex_unlock(&admin->lock); in vcap_get_rule_count_by_cookie()
3420 mutex_unlock(&admin->lock); in vcap_get_rule_count_by_cookie()
3428 struct vcap_client_keyfield_data *data) in vcap_rule_mod_key() argument
3434 return vcap_rule_add_key(rule, key, ftype, data); in vcap_rule_mod_key()
3435 memcpy(&field->data, data, sizeof(field->data)); in vcap_rule_mod_key()
3443 struct vcap_client_keyfield_data data; in vcap_rule_mod_key_u32() local
3445 data.u32.value = value; in vcap_rule_mod_key_u32()
3446 data.u32.mask = mask; in vcap_rule_mod_key_u32()
3447 return vcap_rule_mod_key(rule, key, VCAP_FIELD_U32, &data); in vcap_rule_mod_key_u32()
3460 __func__, __LINE__, vcap_keyfield_name(ri->vctrl, key)); in vcap_rule_rem_key()
3461 return -EINVAL; in vcap_rule_rem_key()
3464 list_del(&field->ctrl.list); in vcap_rule_rem_key()
3473 struct vcap_client_actionfield_data *data) in vcap_rule_mod_action() argument
3479 return vcap_rule_add_action(rule, action, ftype, data); in vcap_rule_mod_action()
3480 memcpy(&field->data, data, sizeof(field->data)); in vcap_rule_mod_action()
3489 struct vcap_client_actionfield_data data; in vcap_rule_mod_action_u32() local
3491 data.u32.value = value; in vcap_rule_mod_action_u32()
3492 return vcap_rule_mod_action(rule, action, VCAP_FIELD_U32, &data); in vcap_rule_mod_action_u32()
3509 err = -EEXIST; in vcap_filter_rule_keys()
3511 &ri->data.keyfields, ctrl.list) { in vcap_filter_rule_keys()
3512 key = ckf->ctrl.key; in vcap_filter_rule_keys()
3515 list_del(&ckf->ctrl.list); in vcap_filter_rule_keys()
3523 err = -EEXIST; in vcap_filter_rule_keys()
3524 fields = vcap_keyfields(ri->vctrl, ri->admin->vtype, in vcap_filter_rule_keys()
3525 rule->keyset); in vcap_filter_rule_keys()
3529 &ri->data.keyfields, ctrl.list) { in vcap_filter_rule_keys()
3530 key = ckf->ctrl.key; in vcap_filter_rule_keys()
3531 if (fields[key].width == 0) { in vcap_filter_rule_keys()
3532 list_del(&ckf->ctrl.list); in vcap_filter_rule_keys()
3552 for (idx = 0; idx < kslist->cnt; ++idx) { in vcap_select_min_rule_keyset()
3553 kset = vcap_keyfieldset(vctrl, vtype, kslist->keysets[idx]); in vcap_select_min_rule_keyset()
3556 if (kset->sw_per_item >= max) in vcap_select_min_rule_keyset()
3558 max = kset->sw_per_item; in vcap_select_min_rule_keyset()
3559 ret = kslist->keysets[idx]; in vcap_select_min_rule_keyset()
3574 err = vcap_api_check(ri->vctrl); in vcap_copy_rule()
3578 rule = vcap_alloc_rule(ri->vctrl, ri->ndev, ri->data.vcap_chain_id, in vcap_copy_rule()
3579 ri->data.user, ri->data.priority, 0); in vcap_copy_rule()
3583 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) { in vcap_copy_rule()
3586 ckf->ctrl.key, in vcap_copy_rule()
3587 ckf->ctrl.type, in vcap_copy_rule()
3588 &ckf->data); in vcap_copy_rule()
3593 list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) { in vcap_copy_rule()
3596 caf->ctrl.action, in vcap_copy_rule()
3597 caf->ctrl.type, in vcap_copy_rule()
3598 &caf->data); in vcap_copy_rule()