From 07b5795208c79274aa29253a73109bad00561bea Mon Sep 17 00:00:00 2001 From: Yi Sun Date: Mon, 28 Oct 2024 17:34:34 +0800 Subject: [PATCH] Add decode subcommand info 'Content-type:text/plain' Decode op_cap to a readable operation name, providing users with easier access to information about hardware support." Example ------------- [root@testmachine]accel-config info -v dsa0 [active] 00000000,00000000,00000000,00000000,00000000,00000000,0000007b,00bf07fd Batch[-] Drain[+] Memory Move[+] Fill[+] Compare[+] Compare Pattern[+] Create Delta Record[+] Apply Delta Record[+] Memory Copy with Dualcast[+] Translation Fetch[+] CRC Generation[+] Copy with CRC Generation[+] DIF Check[+] DIF Insert[+] DIF Strip[+] DIF Update[+] DIX Generate[+] Cache Flush[+] Update Window[+] Inter-Domain Momery Copy[+] Inter-Domain Fill[+] Inter-Domain Compare[+] Inter-Domain Compare Pattern[+] Inter-Domain Cache Flush[-] iax1 00000000,00000000,00000000,00000000,00000000,004d001c,00000000,00000405 Drain[+] Translation Fetch[+] Decrypt[-] Encrypt[-] Decompress[+] Compress[+] CRC64[+] Zdecompress32[-] Zdecompress16[-] Zdecompress8 [-] Zcompress32[-] Zcompress16[-] Zcompress8[-] Scan[+] Set Membership[-] Extract[+] Select[+] BLE Burst[-] Find Unique[-] Expand[+] - Change from v1 to v2: - Merge two related patch into a single commit. - Reword. Signed-off-by: Yi Sun --- accfg/accel-config.c | 1 + accfg/list.c | 148 +++++++++++++++++++++++++++++++++++++++++++ builtin.h | 1 + 3 files changed, 150 insertions(+) diff --git a/accfg/accel-config.c b/accfg/accel-config.c index 616f2e5af5dd..e8a1f718cebc 100644 --- a/accfg/accel-config.c +++ b/accfg/accel-config.c @@ -23,6 +23,7 @@ const char accfg_usage_string[] = static struct cmd_struct commands[] = { {"list", cmd_list}, + {"info", cmd_info}, {"load-config", cmd_config}, {"save-config", cmd_save}, {"disable-device", cmd_disable_device}, diff --git a/accfg/list.c b/accfg/list.c index 145c5231f5c5..916451069d2c 100644 --- a/accfg/list.c +++ b/accfg/list.c @@ -14,6 +14,7 @@ #include #include #include +#include static struct util_filter_params util_param; static struct { @@ -25,6 +26,96 @@ static struct { bool save_conf; } list; +struct map_op_name { + int op_code; + const char *op_name; +}; + +#define BITMAP_SIZE 8 +#define IAX_OP_CODE_NAME \ + {0x02, "Drain"}, \ + {0x0A, "Translation Fetch"}, \ + {0x40, "Decrypt"}, \ + {0x41, "Encrypt"}, \ + {0x42, "Decompress"}, \ + {0x43, "Compress"}, \ + {0x44, "CRC64"}, \ + {0x48, "Zdecompress32"}, \ + {0x49, "Zdecompress16"}, \ + {0x4A, "Zdecompress8"}, \ + {0x4C, "Zcompress32"}, \ + {0x4D, "Zcompress16"}, \ + {0x4E, "Zcompress8"}, \ + {0x50, "Scan"}, \ + {0x51, "Set Membership"}, \ + {0x52, "Extract"}, \ + {0x53, "Select"}, \ + {0x54, "BLE Burst"}, \ + {0x55, "Find Unique"}, \ + {0x56, "Expand"} + +struct map_op_name iax_op_code_name[] = { + IAX_OP_CODE_NAME, + {-1, NULL} +}; + +#define DSA_OP_CODE_NAME \ + {0x01, "Batch"}, \ + {0x02, "Drain"}, \ + {0x03, "Memory Move"}, \ + {0x04, "Fill"}, \ + {0x05, "Compare"}, \ + {0x06, "Compare Pattern"}, \ + {0x07, "Create Delta Record"}, \ + {0x08, "Apply Delta Record"}, \ + {0x09, "Memory Copy with Dualcast"}, \ + {0x0A, "Translation Fetch"}, \ + {0x10, "CRC Generation"}, \ + {0x11, "Copy with CRC Generation"}, \ + {0x12, "DIF Check"}, \ + {0x13, "DIF Insert"}, \ + {0x14, "DIF Strip"}, \ + {0x15, "DIF Update"}, \ + {0x17, "DIX Generate"}, \ + {0x20, "Cache Flush"}, \ + {0x21, "Update Window"}, \ + {0x23, "Inter-Domain Momery Copy"}, \ + {0x24, "Inter-Domain Fill"}, \ + {0x25, "Inter-Domain Compare"}, \ + {0x26, "Inter-Domain Compare Pattern"}, \ + {0x27, "Inter-Domain Cache Flush"} + +struct map_op_name dsa_op_code_name[] = { + DSA_OP_CODE_NAME, + {-1, NULL} +}; + + +static const char* get_op_name(struct map_op_name *code_name, int op_code) +{ + int i = 0; + while (code_name[i].op_code != -1) { + if (code_name[i].op_code == op_code) { + return code_name[i].op_name; + } + i++; + } + return NULL; +} + +static int get_bit(struct accfg_op_cap op_cap, int bit_index) +{ + int array_index = (BITMAP_SIZE - 1) - (bit_index / 32); + int bit_offset = bit_index % 32; + + if (bit_index < 0 || bit_index >= 256) { + printf("Error: bit_index out of range (0-255)\n"); + return -1; + } + + return (op_cap.bits[array_index] & (1 << bit_offset)) != 0; +} + static uint64_t listopts_to_flags(void) { uint64_t flags = 0; @@ -692,6 +783,63 @@ int cmd_list(int argc, const char **argv, void *ctx) return 0; } +int cmd_info(int argc, const char **argv, void *ctx) +{ + struct map_op_name *cur_op_name = NULL; + struct accfg_device *device; + struct accfg_op_cap op_cap; + bool verbose = false; + const char *dev_name; + const char *op_name; + int rc, j, has_op; + + const struct option options[] = { + OPT_BOOLEAN('v', "verbose", &verbose, "show more info"), + OPT_END(), + }; + const char *const u[] = { + "accel-config info []", + NULL + }; + + argc = parse_options(argc, argv, options, u, 0); + for (j = 0; j < argc; j++) + error("unknown parameter \"%s\"\n", argv[j]); + + accfg_device_foreach(ctx, device) { + dev_name = accfg_device_get_devname(device); + fprintf(stdout, "%s %s\n", dev_name, + accfg_device_is_active(device)? "[active]" : ""); + + rc = accfg_device_get_op_cap(device, &op_cap); + if (rc) { + printf("Error getting op cap\n"); + return rc; + } + + for (j = 0; j < BITMAP_SIZE; j++) + printf("%08x,", op_cap.bits[j]); + printf("\b \n"); + + if (!verbose) + continue; + + if (strstr(dev_name, "dsa") != NULL) { + cur_op_name = dsa_op_code_name; + } else if (strstr(dev_name, "iax") != NULL) { + cur_op_name = iax_op_code_name; + } + for (int k = 0; k < 256; k++) { + has_op = get_bit(op_cap, k); + op_name = get_op_name(cur_op_name, k); + if (op_name) + printf("%s[%c] ", op_name, has_op? '+' : '-'); + } + printf("\n"); + } + + return 0; +} int cmd_save(int argc, const char **argv, void *ctx) { const struct option options[] = { diff --git a/builtin.h b/builtin.h index 9554ee541eed..ff6cb5f62990 100644 --- a/builtin.h +++ b/builtin.h @@ -19,6 +19,7 @@ struct cmd_struct { int (*fn) (int, const char **, void *ctx); }; int cmd_list(int argc, const char **argv, void *ctx); +int cmd_info(int argc, const char **argv, void *ctx); int cmd_config(int argc, const char **argv, void *ctx); int cmd_save(int argc, const char **argv, void *ctx); int cmd_disable_device(int argc, const char **argv, void *ctx); -- 2.48.0