Lines Matching refs:ri

446 static void vcap_encode_keyfield(struct vcap_rule_internal *ri,  in vcap_encode_keyfield()  argument
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()
500 struct vcap_rule_internal *ri, in vcap_encode_keyfield_typegroups() argument
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()
536 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_copy_from_client_keyfield() local
547 if (!ri->admin->w32be) { in vcap_copy_from_client_keyfield()
591 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_copy_from_client_actionfield() local
602 if (!ri->admin->w32be) { in vcap_copy_from_client_actionfield()
635 static int vcap_encode_rule_keyset(struct vcap_rule_internal *ri) in vcap_encode_rule_keyset() argument
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()
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()
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()
669 if (list_empty(&ri->data.keyfields)) { in vcap_encode_rule_keyset()
673 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) { 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()
739 static void vcap_encode_actionfield(struct vcap_rule_internal *ri, in vcap_encode_actionfield() argument
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()
781 static void vcap_encode_actionfield_typegroups(struct vcap_rule_internal *ri, in vcap_encode_actionfield_typegroups() argument
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()
793 static int vcap_encode_rule_actionset(struct vcap_rule_internal *ri) in vcap_encode_rule_actionset() argument
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()
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()
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()
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()
838 vcap_copy_from_client_actionfield(&ri->data, &tempaf, caf); in vcap_encode_rule_actionset()
839 vcap_encode_actionfield(ri, &tempaf, in vcap_encode_rule_actionset()
843 vcap_encode_actionfield_typegroups(ri, tg_table); in vcap_encode_rule_actionset()
847 static int vcap_encode_rule(struct vcap_rule_internal *ri) in vcap_encode_rule() argument
851 err = vcap_encode_rule_keyset(ri); in vcap_encode_rule()
854 err = vcap_encode_rule_actionset(ri); in vcap_encode_rule()
878 void vcap_erase_cache(struct vcap_rule_internal *ri) in vcap_erase_cache() argument
880 ri->vctrl->ops->cache_erase(ri->admin); in vcap_erase_cache()
887 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_set_rule_set_keyset() local
891 kset = vcap_keyfieldset(ri->vctrl, ri->admin->vtype, keyset); 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()
907 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_set_rule_set_actionset() local
911 aset = vcap_actionfieldset(ri->vctrl, ri->admin->vtype, actionset); 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()
926 struct vcap_rule_internal *ri; in vcap_rule_exists() local
931 list_for_each_entry(ri, &admin->rules, list) in vcap_rule_exists()
932 if (ri->data.id == id) in vcap_rule_exists()
941 struct vcap_rule_internal *ri; in vcap_get_locked_rule() local
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()
949 return ri; in vcap_get_locked_rule()
958 struct vcap_rule_internal *ri; in vcap_lookup_rule_by_cookie() local
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()
999 static struct vcap_rule_internal *vcap_dup_rule(struct vcap_rule_internal *ri, in vcap_dup_rule() argument
1010 *duprule = *ri; in vcap_dup_rule()
1021 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) { in vcap_dup_rule()
1028 list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) { in vcap_dup_rule()
1098 static void vcap_copy_to_client_actionfield(struct vcap_rule_internal *ri, in vcap_copy_to_client_actionfield() argument
1104 if (ri->admin->w32be) { in vcap_copy_to_client_actionfield()
1200 static void vcap_copy_to_client_keyfield(struct vcap_rule_internal *ri, in vcap_copy_to_client_keyfield() argument
1206 if (ri->admin->w32be) { in vcap_copy_to_client_keyfield()
1305 static void vcap_rule_alloc_keyfield(struct vcap_rule_internal *ri, in vcap_rule_alloc_keyfield() argument
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()
1414 static void vcap_rule_alloc_actionfield(struct vcap_rule_internal *ri, in vcap_rule_alloc_actionfield() argument
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()
1431 static int vcap_decode_actionset(struct vcap_rule_internal *ri) in vcap_decode_actionset() argument
1433 struct vcap_control *vctrl = ri->vctrl; in vcap_decode_actionset()
1434 struct vcap_admin *admin = ri->admin; in vcap_decode_actionset()
1468 vcap_rule_alloc_actionfield(ri, &actionfield[idx], idx, value); in vcap_decode_actionset()
1471 return vcap_set_rule_set_actionset((struct vcap_rule *)ri, actionset); in vcap_decode_actionset()
1474 static int vcap_decode_keyset(struct vcap_rule_internal *ri) in vcap_decode_keyset() argument
1476 struct vcap_control *vctrl = ri->vctrl; in vcap_decode_keyset()
1478 struct vcap_admin *admin = ri->admin; in vcap_decode_keyset()
1526 vcap_rule_alloc_keyfield(ri, &keyfield[idx], idx, value, mask); in vcap_decode_keyset()
1528 return vcap_set_rule_set_keyset((struct vcap_rule *)ri, keyset); in vcap_decode_keyset()
1532 static int vcap_read_rule(struct vcap_rule_internal *ri) in vcap_read_rule() argument
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()
1542 vcap_erase_cache(ri); 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()
1564 static int vcap_write_rule(struct vcap_rule_internal *ri) in vcap_write_rule() argument
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()
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()
1590 static int vcap_write_counter(struct vcap_rule_internal *ri, in vcap_write_counter() argument
1593 struct vcap_admin *admin = ri->admin; 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()
1713 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_add_type_keyfield() local
1715 enum vcap_type vt = ri->admin->vtype; in vcap_add_type_keyfield()
1720 kset = vcap_keyfieldset(ri->vctrl, vt, keyset); in vcap_add_type_keyfield()
1726 fields = vcap_keyfields(ri->vctrl, vt, keyset); in vcap_add_type_keyfield()
1747 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_add_type_actionfield() local
1748 enum vcap_type vt = ri->admin->vtype; in vcap_add_type_actionfield()
1753 aset = vcap_actionfieldset(ri->vctrl, vt, actionset); in vcap_add_type_actionfield()
1759 fields = vcap_actionfields(ri->vctrl, vt, actionset); in vcap_add_type_actionfield()
1867 static bool _vcap_rule_find_keysets(struct vcap_rule_internal *ri, in _vcap_rule_find_keysets() argument
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()
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()
1911 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_rule_find_keysets() local
1913 return _vcap_rule_find_keysets(ri, matches); in vcap_rule_find_keysets()
1945 static bool vcap_rule_find_actionsets(struct vcap_rule_internal *ri, in vcap_rule_find_actionsets() argument
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()
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()
1989 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_val_rule() local
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()
2001 if (!ri->ndev) { in vcap_val_rule()
2002 ri->data.exterr = VCAP_ERR_NO_NETDEV; in vcap_val_rule()
2008 if (ri->data.keyset == VCAP_KFS_NO_VALUE) { in vcap_val_rule()
2010 if (!_vcap_rule_find_keysets(ri, &matches)) { in vcap_val_rule()
2011 ri->data.exterr = VCAP_ERR_NO_KEYSET_MATCH; 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()
2044 if (!vcap_rule_find_actionsets(ri, &matches)) { in vcap_val_rule()
2045 ri->data.exterr = VCAP_ERR_NO_ACTIONSET_MATCH; 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()
2079 static u32 vcap_next_rule_addr(u32 addr, struct vcap_rule_internal *ri) in vcap_next_rule_addr() argument
2081 return ((addr - ri->size) / ri->size) * ri->size; in vcap_next_rule_addr()
2085 static u32 vcap_set_rule_id(struct vcap_rule_internal *ri) in vcap_set_rule_id() argument
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()
2099 static int vcap_insert_rule(struct vcap_rule_internal *ri, in vcap_insert_rule() argument
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()
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()
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()
2160 move->count = ri->addr - addr; in vcap_insert_rule()
2166 static void vcap_move_rules(struct vcap_rule_internal *ri, in vcap_move_rules() argument
2169 ri->vctrl->ops->move(ri->ndev, ri->admin, move->addr, in vcap_move_rules()
2247 static void vcap_rule_set_state(struct vcap_rule_internal *ri) in vcap_rule_set_state() argument
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()
2260 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_add_rule() local
2265 ret = vcap_api_check(ri->vctrl); in vcap_add_rule()
2269 mutex_lock(&ri->admin->lock); in vcap_add_rule()
2271 vcap_rule_set_state(ri); in vcap_add_rule()
2272 ret = vcap_insert_rule(ri, &move); in vcap_add_rule()
2279 vcap_move_rules(ri, &move); in vcap_add_rule()
2282 ret = vcap_write_counter(ri, &ctr); 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()
2292 vcap_erase_cache(ri); in vcap_add_rule()
2293 ret = vcap_encode_rule(ri); in vcap_add_rule()
2299 ret = vcap_write_rule(ri); in vcap_add_rule()
2305 mutex_unlock(&ri->admin->lock); in vcap_add_rule()
2316 struct vcap_rule_internal *ri; in vcap_alloc_rule() local
2348 ri = kzalloc(sizeof(*ri), GFP_KERNEL); in vcap_alloc_rule()
2349 if (!ri) { 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()
2367 if (vcap_set_rule_id(ri) == 0) { in vcap_alloc_rule()
2373 return (struct vcap_rule *)ri; in vcap_alloc_rule()
2376 kfree(ri); in vcap_alloc_rule()
2387 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_free_rule() local
2392 list_for_each_entry_safe(ckf, next_ckf, &ri->data.keyfields, ctrl.list) { in vcap_free_rule()
2396 list_for_each_entry_safe(caf, next_caf, &ri->data.actionfields, ctrl.list) { in vcap_free_rule()
2408 struct vcap_rule_internal *ri; in vcap_decode_rule() local
2411 ri = vcap_dup_rule(elem, elem->state == VCAP_RS_DISABLED); in vcap_decode_rule()
2412 if (IS_ERR(ri)) in vcap_decode_rule()
2413 return ERR_CAST(ri); in vcap_decode_rule()
2415 if (ri->state == VCAP_RS_DISABLED) in vcap_decode_rule()
2418 err = vcap_read_rule(ri); in vcap_decode_rule()
2422 err = vcap_decode_keyset(ri); in vcap_decode_rule()
2426 err = vcap_decode_actionset(ri); in vcap_decode_rule()
2431 return &ri->data; in vcap_decode_rule()
2457 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_mod_rule() local
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()
2468 vcap_rule_set_state(ri); in vcap_mod_rule()
2469 if (ri->state == VCAP_RS_DISABLED) in vcap_mod_rule()
2473 vcap_erase_cache(ri); in vcap_mod_rule()
2474 err = vcap_encode_rule(ri); in vcap_mod_rule()
2478 err = vcap_write_rule(ri); in vcap_mod_rule()
2483 err = vcap_write_counter(ri, &ctr); in vcap_mod_rule()
2486 mutex_unlock(&ri->admin->lock); in vcap_mod_rule()
2504 static int vcap_fill_rule_gap(struct vcap_rule_internal *ri) in vcap_fill_rule_gap() argument
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()
2516 elem = ri; in vcap_fill_rule_gap()
2518 gap += vcap_valid_rule_move(elem, ri->size); in vcap_fill_rule_gap()
2521 elem = ri; in vcap_fill_rule_gap()
2523 vcap_adjust_rule_addr(elem, ri->size + gap + offset); 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()
2531 vcap_move_rules(ri, &move); in vcap_fill_rule_gap()
2539 struct vcap_rule_internal *ri, *elem; in vcap_del_rule() local
2550 ri = vcap_get_locked_rule(vctrl, id); in vcap_del_rule()
2551 if (!ri) in vcap_del_rule()
2554 admin = ri->admin; in vcap_del_rule()
2556 if (ri->addr > admin->last_used_addr) in vcap_del_rule()
2557 gap = vcap_fill_rule_gap(ri); 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()
2582 struct vcap_rule_internal *ri, *next_ri; in vcap_del_rules() local
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()
2611 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_find_keyfield() local
2614 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) in vcap_find_keyfield()
2624 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_lookup_keyfield() local
2626 enum vcap_type vt = ri->admin->vtype; in vcap_lookup_keyfield()
2631 fields = vcap_keyfields(ri->vctrl, vt, keyset); in vcap_lookup_keyfield()
2642 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_keyfield_unique() local
2645 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) in vcap_keyfield_unique()
2655 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_keyfield_match_keyset() local
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()
2675 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_rule_add_key() local
2681 vcap_keyfield_name(ri->vctrl, key)); in vcap_rule_add_key()
2688 vcap_keyfield_name(ri->vctrl, key)); in vcap_rule_add_key()
2796 struct vcap_rule_internal *ri = (struct vcap_rule_internal *)rule; in vcap_find_actionfield() local
2799 list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) in vcap_find_actionfield()
2810 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_actionfield_unique() local
2813 list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) in vcap_actionfield_unique()
2824 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_actionfield_match_actionset() local
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()
2843 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_rule_add_action() local
2849 vcap_actionfield_name(ri->vctrl, action)); in vcap_rule_add_action()
2856 vcap_actionfield_name(ri->vctrl, action)); in vcap_rule_add_action()
2910 static int vcap_read_counter(struct vcap_rule_internal *ri, in vcap_read_counter() argument
2913 struct vcap_admin *admin = ri->admin; in vcap_read_counter()
2915 ri->vctrl->ops->update(ri->ndev, admin, VCAP_CMD_READ, VCAP_SEL_COUNTER, in vcap_read_counter()
2916 ri->addr); in vcap_read_counter()
2917 ri->vctrl->ops->cache_read(ri->ndev, admin, VCAP_SEL_COUNTER, in vcap_read_counter()
2918 ri->counter_id, 0); in vcap_read_counter()
2965 static int vcap_enable_rule(struct vcap_rule_internal *ri) in vcap_enable_rule() argument
2971 vcap_erase_cache(ri); in vcap_enable_rule()
2972 err = vcap_encode_rule(ri); in vcap_enable_rule()
2975 err = vcap_write_rule(ri); in vcap_enable_rule()
2980 list_for_each_entry_safe(kf, nkf, &ri->data.keyfields, ctrl.list) { in vcap_enable_rule()
2984 list_for_each_entry_safe(af, naf, &ri->data.actionfields, ctrl.list) { in vcap_enable_rule()
2988 ri->state = VCAP_RS_ENABLED; in vcap_enable_rule()
2998 struct vcap_rule_internal *ri; in vcap_enable_rules() local
3008 list_for_each_entry(ri, &admin->rules, list) { in vcap_enable_rules()
3010 if (!(ri->data.vcap_chain_id >= chain && in vcap_enable_rules()
3011 ri->data.vcap_chain_id < next_chain)) { in vcap_enable_rules()
3015 if (ri->ndev != ndev) in vcap_enable_rules()
3018 if (ri->state != VCAP_RS_DISABLED) in vcap_enable_rules()
3021 err = vcap_enable_rule(ri); in vcap_enable_rules()
3033 static int vcap_disable_rule(struct vcap_rule_internal *ri) in vcap_disable_rule() argument
3037 err = vcap_read_rule(ri); in vcap_disable_rule()
3040 err = vcap_decode_keyset(ri); in vcap_disable_rule()
3043 err = vcap_decode_actionset(ri); in vcap_disable_rule()
3047 ri->state = VCAP_RS_DISABLED; in vcap_disable_rule()
3048 ri->vctrl->ops->init(ri->ndev, ri->admin, ri->addr, ri->size); in vcap_disable_rule()
3056 struct vcap_rule_internal *ri; in vcap_disable_rules() local
3066 list_for_each_entry(ri, &admin->rules, list) { in vcap_disable_rules()
3067 if (ri->data.vcap_chain_id != chain) in vcap_disable_rules()
3070 if (ri->ndev != ndev) in vcap_disable_rules()
3073 if (ri->state != VCAP_RS_ENABLED) in vcap_disable_rules()
3076 err = vcap_disable_rule(ri); in vcap_disable_rules()
3242 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_rule_set_counter_id() local
3244 ri->counter_id = counter_id; in vcap_rule_set_counter_id()
3250 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_rule_set_counter() local
3253 err = vcap_api_check(ri->vctrl); in vcap_rule_set_counter()
3261 mutex_lock(&ri->admin->lock); in vcap_rule_set_counter()
3262 err = vcap_write_counter(ri, ctr); in vcap_rule_set_counter()
3263 mutex_unlock(&ri->admin->lock); in vcap_rule_set_counter()
3271 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_rule_get_counter() local
3274 err = vcap_api_check(ri->vctrl); in vcap_rule_get_counter()
3282 mutex_lock(&ri->admin->lock); in vcap_rule_get_counter()
3283 err = vcap_read_counter(ri, ctr); in vcap_rule_get_counter()
3284 mutex_unlock(&ri->admin->lock); in vcap_rule_get_counter()
3308 static int vcap_rule_get_untyped_keyset(struct vcap_rule_internal *ri, in vcap_rule_get_untyped_keyset() argument
3311 struct vcap_control *vctrl = ri->vctrl; in vcap_rule_get_untyped_keyset()
3312 enum vcap_type vt = ri->admin->vtype; in vcap_rule_get_untyped_keyset()
3318 if (keyfield_set[idx].sw_per_item == ri->keyset_sw && in vcap_rule_get_untyped_keyset()
3328 int vcap_rule_get_keysets(struct vcap_rule_internal *ri, in vcap_rule_get_keysets() argument
3331 struct vcap_control *vctrl = ri->vctrl; in vcap_rule_get_keysets()
3332 enum vcap_type vt = ri->admin->vtype; in vcap_rule_get_keysets()
3338 err = vcap_rule_get_key(&ri->data, VCAP_KF_TYPE, &kf); in vcap_rule_get_keysets()
3340 return vcap_rule_get_untyped_keyset(ri, matches); in vcap_rule_get_keysets()
3354 if (keyfield_set[idx].sw_per_item != ri->keyset_sw) in vcap_rule_get_keysets()
3375 struct vcap_rule_internal *ri; in vcap_get_rule_count_by_cookie() local
3387 list_for_each_entry(ri, &admin->rules, list) { in vcap_get_rule_count_by_cookie()
3388 if (ri->data.cookie != cookie) in vcap_get_rule_count_by_cookie()
3391 err = vcap_read_counter(ri, &temp); in vcap_get_rule_count_by_cookie()
3399 err = vcap_write_counter(ri, &temp); in vcap_get_rule_count_by_cookie()
3442 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_rule_rem_key() local
3448 __func__, __LINE__, vcap_keyfield_name(ri->vctrl, key)); in vcap_rule_rem_key()
3489 struct vcap_rule_internal *ri = to_intrule(rule); in vcap_filter_rule_keys() local
3499 &ri->data.keyfields, ctrl.list) { in vcap_filter_rule_keys()
3512 fields = vcap_keyfields(ri->vctrl, ri->admin->vtype, in vcap_filter_rule_keys()
3517 &ri->data.keyfields, ctrl.list) { in vcap_filter_rule_keys()
3556 struct vcap_rule_internal *ri = to_intrule(erule); in vcap_copy_rule() local
3562 err = vcap_api_check(ri->vctrl); in vcap_copy_rule()
3566 rule = vcap_alloc_rule(ri->vctrl, ri->ndev, ri->data.vcap_chain_id, in vcap_copy_rule()
3567 ri->data.user, ri->data.priority, 0); in vcap_copy_rule()
3571 list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) { in vcap_copy_rule()
3581 list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) { in vcap_copy_rule()