diff --git a/lib/libcrypto/bio/b_dump.c b/lib/libcrypto/bio/b_dump.c index ef965b61d..09b011268 100644 --- a/lib/libcrypto/bio/b_dump.c +++ b/lib/libcrypto/bio/b_dump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b_dump.c,v 1.27 2024/02/01 17:04:09 tb Exp $ */ +/* $OpenBSD: b_dump.c,v 1.28 2024/02/02 10:53:48 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -56,90 +56,141 @@ * [including the GNU Public Licence.] */ -/* - * Stolen from tjh's ssl/ssl_trc.c stuff. - */ - +#include #include #include #include #include -#define TRUNCATE -#define DUMP_WIDTH 16 -#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4)) +#include "bytestring.h" + +#define MAX_BYTES_PER_LINE 16 + +/* + * The byte string s is dumped as lines of the following form: + * indent | byte count (4 digits) | " - " | hex dump | " " | ASCII dump + * Each byte uses 4 characters (two hex digits followed by a space and one + * ASCII character). + */ int BIO_dump_indent(BIO *bio, const char *s, int len, int indent) { - char buf[288 + 1], tmp[20], str[128 + 1]; - int i, j, rows, trc, written; - unsigned char ch; - int dump_width; - int ret = 0; + CBB cbb; + CBS cbs; + int bytes_per_line, dumped, printed, trailing, written; + int ret = -1; - trc = 0; + memset(&cbb, 0, sizeof(cbb)); -#ifdef TRUNCATE - for (; (len > 0) && ((s[len - 1] == ' ') || (s[len - 1] == '\0')); len--) - trc++; -#endif + if (len < 0) + goto err; + CBS_init(&cbs, s, len); if (indent < 0) indent = 0; if (indent > 64) indent = 64; - memset(str, ' ', indent); - str[indent] = '\0'; - if ((dump_width = DUMP_WIDTH_LESS_INDENT(indent)) <= 0) - return -1; - rows = (len / dump_width); - if ((rows * dump_width) < len) - rows++; - for (i = 0; i < rows; i++) { - strlcpy(buf, str, sizeof buf); - snprintf(tmp, sizeof tmp, "%04x - ", i*dump_width); - strlcat(buf, tmp, sizeof buf); - for (j = 0; j < dump_width; j++) { - if (((i*dump_width) + j) >= len) { - strlcat(buf, " ", sizeof buf); - } else { - ch = ((unsigned char)*(s + i*dump_width + j)) & 0xff; - snprintf(tmp, sizeof tmp, "%02x%c", ch, - j == 7 ? '-' : ' '); - strlcat(buf, tmp, sizeof buf); - } - } - strlcat(buf, " ", sizeof buf); - for (j = 0; j < dump_width; j++) { - if (((i*dump_width) + j) >= len) - break; - ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff; - snprintf(tmp, sizeof tmp, "%c", - ((ch >= ' ') && (ch <= '~')) ? ch : '.'); - strlcat(buf, tmp, sizeof buf); - } - strlcat(buf, "\n", sizeof buf); - /* if this is the last call then update the ddt_dump thing so - * that we will move the selection point in the debug window + /* + * Less obfuscated version of the original calculation attempting to + * ensure that the dump doesn't overshoot 80 characters per line. For + * a very long string the byte count will still make it go past that. + */ + bytes_per_line = MAX_BYTES_PER_LINE; + if (indent > 6) + bytes_per_line -= (indent - 3) / 4; + if (bytes_per_line <= 0) + goto err; + + /* Strip and count trailing spaces and NULs. */ + trailing = 0; + while (CBS_len(&cbs) > 0) { + uint8_t u8; + + if (!CBS_peek_last_u8(&cbs, &u8)) + goto err; + if (u8 != '\0' && u8 != ' ') + break; + if (!CBS_get_last_u8(&cbs, &u8)) + goto err; + trailing++; + } + + printed = 0; + dumped = 0; + while (CBS_len(&cbs) > 0) { + CBS row; + uint8_t ascii_dump[MAX_BYTES_PER_LINE]; + int missing, row_bytes; + + if ((row_bytes = CBS_len(&cbs)) > bytes_per_line) + row_bytes = bytes_per_line; + if (!CBS_get_bytes(&cbs, &row, row_bytes)) + goto err; + + /* Write out indent, byte count and initial " - ". */ + if ((written = BIO_printf(bio, "%*s%04x - ", indent, "", + dumped)) < 0) + goto err; + printed += written; + + /* + * Write out hex dump, prepare ASCII dump. */ - if ((written = BIO_write(bio, buf, strlen(buf))) < 0) - return -1; - ret += written; + if (!CBB_init_fixed(&cbb, ascii_dump, sizeof(ascii_dump))) + goto err; + while (CBS_len(&row) > 0) { + uint8_t u8; + char sep = ' '; + + if (!CBS_get_u8(&row, &u8)) + goto err; + + /* Historic behavior: print a '-' after eighth byte. */ + if (row_bytes - CBS_len(&row) == 8) + sep = '-'; + if ((written = BIO_printf(bio, "%02x%c", u8, sep)) < 0) + goto err; + printed += written; + + /* Locale-independent version of !isprint(u8). */ + if (u8 < ' ' || u8 > '~') + u8 = '.'; + if (!CBB_add_u8(&cbb, u8)) + goto err; + } + if (!CBB_finish(&cbb, NULL, NULL)) + goto err; + + /* Calculate number of bytes missing in dump of last line. */ + if ((missing = bytes_per_line - row_bytes) < 0) + goto err; + + /* Pad missing bytes, add 2 spaces and print the ASCII dump. */ + if ((written = BIO_printf(bio, "%*s%.*s\n", 3 * missing + 2, "", + row_bytes, ascii_dump)) < 0) + goto err; + printed += written; + + dumped += row_bytes; } -#ifdef TRUNCATE - if (trc > 0) { - snprintf(buf, sizeof buf, "%s%04x - \n", - str, len + trc); - if ((written = BIO_write(bio, buf, strlen(buf))) < 0) - return -1; - ret += written; + + if (trailing > 0) { + if ((written = BIO_printf(bio, "%*s%04x - \n", + indent, "", dumped + trailing)) < 0) + goto err; + printed += written; } -#endif - return (ret); + + ret = printed; + + err: + CBB_cleanup(&cbb); + + return ret; } LCRYPTO_ALIAS(BIO_dump_indent); diff --git a/lib/libcrypto/cms/cms_kari.c b/lib/libcrypto/cms/cms_kari.c index 8ed54e757..242a49693 100644 --- a/lib/libcrypto/cms/cms_kari.c +++ b/lib/libcrypto/cms/cms_kari.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cms_kari.c,v 1.15 2023/07/08 08:26:26 beck Exp $ */ +/* $OpenBSD: cms_kari.c,v 1.16 2024/02/02 14:11:45 tb Exp $ */ /* * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. @@ -279,7 +279,7 @@ cms_kek_cipher(unsigned char **pout, size_t *poutlen, const unsigned char *in, explicit_bzero(kek, keklen); if (!rv) free(out); - EVP_CIPHER_CTX_reset(kari->ctx); + (void)EVP_CIPHER_CTX_reset(kari->ctx); /* FIXME: WHY IS kari->pctx freed here? /RL */ EVP_PKEY_CTX_free(kari->pctx); kari->pctx = NULL; diff --git a/lib/libcrypto/cms/cms_sd.c b/lib/libcrypto/cms/cms_sd.c index 5f472311d..b644717bb 100644 --- a/lib/libcrypto/cms/cms_sd.c +++ b/lib/libcrypto/cms/cms_sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cms_sd.c,v 1.29 2023/10/18 07:30:49 tb Exp $ */ +/* $OpenBSD: cms_sd.c,v 1.30 2024/02/02 14:13:11 tb Exp $ */ /* * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. @@ -744,7 +744,7 @@ CMS_SignerInfo_sign(CMS_SignerInfo *si) } if (si->pctx == NULL) { - EVP_MD_CTX_reset(si->mctx); + (void)EVP_MD_CTX_reset(si->mctx); if (!EVP_DigestSignInit(si->mctx, &si->pctx, md, NULL, si->pkey)) goto err; } @@ -779,8 +779,7 @@ CMS_SignerInfo_sign(CMS_SignerInfo *si) ret = 1; err: - if (si->mctx != NULL) - EVP_MD_CTX_reset(si->mctx); + (void)EVP_MD_CTX_reset(si->mctx); freezero(buf, buf_len); freezero(sig, sig_len); @@ -831,8 +830,7 @@ CMS_SignerInfo_verify(CMS_SignerInfo *si) } err: - if (si->mctx != NULL) - EVP_MD_CTX_reset(si->mctx); + (void)EVP_MD_CTX_reset(si->mctx); freezero(buf, buf_len); return ret; diff --git a/regress/lib/libcrypto/bio/Makefile b/regress/lib/libcrypto/bio/Makefile index 0402e3939..336dc2ff6 100644 --- a/regress/lib/libcrypto/bio/Makefile +++ b/regress/lib/libcrypto/bio/Makefile @@ -1,7 +1,8 @@ -# $OpenBSD: Makefile,v 1.7 2023/04/25 19:48:24 tb Exp $ +# $OpenBSD: Makefile,v 1.8 2024/02/02 06:22:01 tb Exp $ PROGS += bio_asn1 PROGS += bio_chain +PROGS += bio_dump PROGS += bio_host PROGS += bio_mem diff --git a/regress/lib/libcrypto/bio/bio_dump.c b/regress/lib/libcrypto/bio/bio_dump.c new file mode 100644 index 000000000..069f677fe --- /dev/null +++ b/regress/lib/libcrypto/bio/bio_dump.c @@ -0,0 +1,777 @@ +/* $OpenBSD: bio_dump.c,v 1.3 2024/02/02 06:47:21 tb Exp $ */ +/* + * Copyright (c) 2024 Theo Buehler + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +#include + +const uint8_t dump[] = { + 0x74, 0x45, 0xc6, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x36, 0xd8, 0x61, 0x48, 0x68, 0x3c, 0xc0, 0x68, + 0xaa, 0x15, 0x57, 0x77, 0xe3, 0xec, 0xb4, 0x98, + 0xc6, 0x08, 0xfc, 0x59, 0xb3, 0x4f, 0x45, 0xcf, + 0x4b, 0xc2, 0xae, 0x98, 0xb5, 0xeb, 0xe0, 0xb5, + 0xc1, 0x68, 0xba, 0xcf, 0x7c, 0xf7, 0x7b, 0x38, + 0x43, 0x2f, 0xb9, 0x0e, 0x23, 0x02, 0xb9, 0x4f, + 0x8c, 0x26, 0xeb, 0xef, 0x70, 0x98, 0x82, 0xa7, + 0xb9, 0x78, 0xc5, 0x08, 0x96, 0x99, 0xb3, 0x84, + 0xa3, 0x4f, 0xfb, 0xd7, 0x38, 0xa9, 0xd9, 0xd4, + 0x53, 0x0f, 0x4f, 0x64, 0x97, 0xdf, 0xcf, 0xf3, + 0x4f, 0xc8, 0xd2, 0x56, 0x3f, 0x0d, 0x72, 0xd4, + 0x55, 0x98, 0x89, 0xb0, 0x45, 0x26, 0x3f, 0x7a, + 0xbd, 0x9d, 0x96, 0x15, 0xa2, 0x10, 0x14, 0x85, + 0xaa, 0xa1, 0x7c, 0x84, 0xfb, 0xc4, 0xa5, 0x7b, + 0xc6, 0xe3, 0xad, 0x85, 0x57, 0x96, 0xbb, 0x81, + 0x18, 0x0c, 0xed, 0x2f, 0xf7, 0x6a, 0x4c, 0x4d, + 0x59, 0xe1, 0xcc, 0xc5, 0x3a, 0x9f, 0x48, 0xfc, + 0x1d, 0x7c, 0x0d, 0xa4, 0x79, 0x96, 0xe7, 0x2b, + 0x39, 0x15, 0xf9, 0x3a, 0x6a, 0x5e, 0x7c, 0x4e, + 0xc9, 0x3b, 0xaf, 0xeb, 0x3b, 0xcf, 0x8d, 0x6a, + 0x57, 0xe6, 0xc5, 0xba, 0xbd, 0xa6, 0xa0, 0x6b, + 0x03, 0xd5, 0xa3, 0x9f, 0x99, 0x2a, 0xea, 0x88, + 0x72, 0x1b, 0x66, 0x6c, 0x5e, 0x1d, 0x49, 0xd5, + 0x1e, 0x1e, 0xcc, 0x1a, 0xb1, 0xd8, 0xf7, 0x91, + 0x1e, 0x1e, 0xcc, 0x1a, 0x20, 0x00, 0x20, 0x00, + 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, + 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, + 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, + 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, +}; +#define DUMP_LEN (sizeof(dump) / sizeof(dump[0])) + +static const struct bio_dump_testcase { + int indent; + const char *input; + int inlen; + const char *output; +} bio_dump_testcases[] = { + { + .indent = 0, + .input = "", + .inlen = 0, + .output = "", + }, + { + .indent = 0, + .input = "", + .inlen = 1, + .output = "0001 - \n", + }, + { + .indent = 6, + .input = " ", + .inlen = 1, + .output = " 0001 - \n", + }, + { + .indent = -1, + .input = "!", + .inlen = 1, + .output = +"0000 - 21 !\n", + }, + { + .indent = -1, + .input = "~", + .inlen = 1, + .output = +"0000 - 7e ~\n", + }, + { + .indent = 4, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 45 c6 20 00 00 00 00-00 00 00 00 00 00 00 00 tE. ............\n" +" 0010 - 36 d8 61 48 68 3c c0 68-aa 15 57 77 e3 ec b4 98 6.aHh<.h..Ww....\n" +" 0020 - c6 08 fc 59 b3 4f 45 cf-4b c2 ae 98 b5 eb e0 b5 ...Y.OE.K.......\n" +" 0030 - c1 68 ba cf 7c f7 7b 38-43 2f b9 0e 23 02 b9 4f .h..|.{8C/..#..O\n" +" 0040 - 8c 26 eb ef 70 98 82 a7-b9 78 c5 08 96 99 b3 84 .&..p....x......\n" +" 0050 - a3 4f fb d7 38 a9 d9 d4-53 0f 4f 64 97 df cf f3 .O..8...S.Od....\n" +" 0060 - 4f c8 d2 56 3f 0d 72 d4-55 98 89 b0 45 26 3f 7a O..V?.r.U...E&?z\n" +" 0070 - bd 9d 96 15 a2 10 14 85-aa a1 7c 84 fb c4 a5 7b ..........|....{\n" +" 0080 - c6 e3 ad 85 57 96 bb 81-18 0c ed 2f f7 6a 4c 4d ....W....../.jLM\n" +" 0090 - 59 e1 cc c5 3a 9f 48 fc-1d 7c 0d a4 79 96 e7 2b Y...:.H..|..y..+\n" +" 00a0 - 39 15 f9 3a 6a 5e 7c 4e-c9 3b af eb 3b cf 8d 6a 9..:j^|N.;..;..j\n" +" 00b0 - 57 e6 c5 ba bd a6 a0 6b-03 d5 a3 9f 99 2a ea 88 W......k.....*..\n" +" 00c0 - 72 1b 66 6c 5e 1d 49 d5-1e 1e cc 1a b1 d8 f7 91 r.fl^.I.........\n" +" 00d0 - 1e 1e cc 1a ....\n" +" 00f6 - \n", + }, + { + .indent = 11, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 45 c6 20 00 00 00 00-00 00 00 00 00 00 tE. ..........\n" +" 000e - 00 00 36 d8 61 48 68 3c-c0 68 aa 15 57 77 ..6.aHh<.h..Ww\n" +" 001c - e3 ec b4 98 c6 08 fc 59-b3 4f 45 cf 4b c2 .......Y.OE.K.\n" +" 002a - ae 98 b5 eb e0 b5 c1 68-ba cf 7c f7 7b 38 .......h..|.{8\n" +" 0038 - 43 2f b9 0e 23 02 b9 4f-8c 26 eb ef 70 98 C/..#..O.&..p.\n" +" 0046 - 82 a7 b9 78 c5 08 96 99-b3 84 a3 4f fb d7 ...x.......O..\n" +" 0054 - 38 a9 d9 d4 53 0f 4f 64-97 df cf f3 4f c8 8...S.Od....O.\n" +" 0062 - d2 56 3f 0d 72 d4 55 98-89 b0 45 26 3f 7a .V?.r.U...E&?z\n" +" 0070 - bd 9d 96 15 a2 10 14 85-aa a1 7c 84 fb c4 ..........|...\n" +" 007e - a5 7b c6 e3 ad 85 57 96-bb 81 18 0c ed 2f .{....W....../\n" +" 008c - f7 6a 4c 4d 59 e1 cc c5-3a 9f 48 fc 1d 7c .jLMY...:.H..|\n" +" 009a - 0d a4 79 96 e7 2b 39 15-f9 3a 6a 5e 7c 4e ..y..+9..:j^|N\n" +" 00a8 - c9 3b af eb 3b cf 8d 6a-57 e6 c5 ba bd a6 .;..;..jW.....\n" +" 00b6 - a0 6b 03 d5 a3 9f 99 2a-ea 88 72 1b 66 6c .k.....*..r.fl\n" +" 00c4 - 5e 1d 49 d5 1e 1e cc 1a-b1 d8 f7 91 1e 1e ^.I...........\n" +" 00d2 - cc 1a ..\n" +" 00f6 - \n", + }, + { + .indent = 18, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 45 c6 20 00 00 00 00-00 00 00 00 00 tE. .........\n" +" 000d - 00 00 00 36 d8 61 48 68-3c c0 68 aa 15 ...6.aHh<.h..\n" +" 001a - 57 77 e3 ec b4 98 c6 08-fc 59 b3 4f 45 Ww.......Y.OE\n" +" 0027 - cf 4b c2 ae 98 b5 eb e0-b5 c1 68 ba cf .K........h..\n" +" 0034 - 7c f7 7b 38 43 2f b9 0e-23 02 b9 4f 8c |.{8C/..#..O.\n" +" 0041 - 26 eb ef 70 98 82 a7 b9-78 c5 08 96 99 &..p....x....\n" +" 004e - b3 84 a3 4f fb d7 38 a9-d9 d4 53 0f 4f ...O..8...S.O\n" +" 005b - 64 97 df cf f3 4f c8 d2-56 3f 0d 72 d4 d....O..V?.r.\n" +" 0068 - 55 98 89 b0 45 26 3f 7a-bd 9d 96 15 a2 U...E&?z.....\n" +" 0075 - 10 14 85 aa a1 7c 84 fb-c4 a5 7b c6 e3 .....|....{..\n" +" 0082 - ad 85 57 96 bb 81 18 0c-ed 2f f7 6a 4c ..W....../.jL\n" +" 008f - 4d 59 e1 cc c5 3a 9f 48-fc 1d 7c 0d a4 MY...:.H..|..\n" +" 009c - 79 96 e7 2b 39 15 f9 3a-6a 5e 7c 4e c9 y..+9..:j^|N.\n" +" 00a9 - 3b af eb 3b cf 8d 6a 57-e6 c5 ba bd a6 ;..;..jW.....\n" +" 00b6 - a0 6b 03 d5 a3 9f 99 2a-ea 88 72 1b 66 .k.....*..r.f\n" +" 00c3 - 6c 5e 1d 49 d5 1e 1e cc-1a b1 d8 f7 91 l^.I.........\n" +" 00d0 - 1e 1e cc 1a ....\n" +" 00f6 - \n", + }, + { + .indent = 25, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 45 c6 20 00 00 00 00-00 00 00 tE. .......\n" +" 000b - 00 00 00 00 00 36 d8 61-48 68 3c .....6.aHh<\n" +" 0016 - c0 68 aa 15 57 77 e3 ec-b4 98 c6 .h..Ww.....\n" +" 0021 - 08 fc 59 b3 4f 45 cf 4b-c2 ae 98 ..Y.OE.K...\n" +" 002c - b5 eb e0 b5 c1 68 ba cf-7c f7 7b .....h..|.{\n" +" 0037 - 38 43 2f b9 0e 23 02 b9-4f 8c 26 8C/..#..O.&\n" +" 0042 - eb ef 70 98 82 a7 b9 78-c5 08 96 ..p....x...\n" +" 004d - 99 b3 84 a3 4f fb d7 38-a9 d9 d4 ....O..8...\n" +" 0058 - 53 0f 4f 64 97 df cf f3-4f c8 d2 S.Od....O..\n" +" 0063 - 56 3f 0d 72 d4 55 98 89-b0 45 26 V?.r.U...E&\n" +" 006e - 3f 7a bd 9d 96 15 a2 10-14 85 aa ?z.........\n" +" 0079 - a1 7c 84 fb c4 a5 7b c6-e3 ad 85 .|....{....\n" +" 0084 - 57 96 bb 81 18 0c ed 2f-f7 6a 4c W....../.jL\n" +" 008f - 4d 59 e1 cc c5 3a 9f 48-fc 1d 7c MY...:.H..|\n" +" 009a - 0d a4 79 96 e7 2b 39 15-f9 3a 6a ..y..+9..:j\n" +" 00a5 - 5e 7c 4e c9 3b af eb 3b-cf 8d 6a ^|N.;..;..j\n" +" 00b0 - 57 e6 c5 ba bd a6 a0 6b-03 d5 a3 W......k...\n" +" 00bb - 9f 99 2a ea 88 72 1b 66-6c 5e 1d ..*..r.fl^.\n" +" 00c6 - 49 d5 1e 1e cc 1a b1 d8-f7 91 1e I..........\n" +" 00d1 - 1e cc 1a ...\n" +" 00f6 - \n", + }, + { + .indent = 32, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 45 c6 20 00 00 00 00-00 tE. .....\n" +" 0009 - 00 00 00 00 00 00 00 36-d8 .......6.\n" +" 0012 - 61 48 68 3c c0 68 aa 15-57 aHh<.h..W\n" +" 001b - 77 e3 ec b4 98 c6 08 fc-59 w.......Y\n" +" 0024 - b3 4f 45 cf 4b c2 ae 98-b5 .OE.K....\n" +" 002d - eb e0 b5 c1 68 ba cf 7c-f7 ....h..|.\n" +" 0036 - 7b 38 43 2f b9 0e 23 02-b9 {8C/..#..\n" +" 003f - 4f 8c 26 eb ef 70 98 82-a7 O.&..p...\n" +" 0048 - b9 78 c5 08 96 99 b3 84-a3 .x.......\n" +" 0051 - 4f fb d7 38 a9 d9 d4 53-0f O..8...S.\n" +" 005a - 4f 64 97 df cf f3 4f c8-d2 Od....O..\n" +" 0063 - 56 3f 0d 72 d4 55 98 89-b0 V?.r.U...\n" +" 006c - 45 26 3f 7a bd 9d 96 15-a2 E&?z.....\n" +" 0075 - 10 14 85 aa a1 7c 84 fb-c4 .....|...\n" +" 007e - a5 7b c6 e3 ad 85 57 96-bb .{....W..\n" +" 0087 - 81 18 0c ed 2f f7 6a 4c-4d ..../.jLM\n" +" 0090 - 59 e1 cc c5 3a 9f 48 fc-1d Y...:.H..\n" +" 0099 - 7c 0d a4 79 96 e7 2b 39-15 |..y..+9.\n" +" 00a2 - f9 3a 6a 5e 7c 4e c9 3b-af .:j^|N.;.\n" +" 00ab - eb 3b cf 8d 6a 57 e6 c5-ba .;..jW...\n" +" 00b4 - bd a6 a0 6b 03 d5 a3 9f-99 ...k.....\n" +" 00bd - 2a ea 88 72 1b 66 6c 5e-1d *..r.fl^.\n" +" 00c6 - 49 d5 1e 1e cc 1a b1 d8-f7 I........\n" +" 00cf - 91 1e 1e cc 1a .....\n" +" 00f6 - \n", + }, + { + .indent = 35, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 45 c6 20 00 00 00 00- tE. ....\n" +" 0008 - 00 00 00 00 00 00 00 00- ........\n" +" 0010 - 36 d8 61 48 68 3c c0 68- 6.aHh<.h\n" +" 0018 - aa 15 57 77 e3 ec b4 98- ..Ww....\n" +" 0020 - c6 08 fc 59 b3 4f 45 cf- ...Y.OE.\n" +" 0028 - 4b c2 ae 98 b5 eb e0 b5- K.......\n" +" 0030 - c1 68 ba cf 7c f7 7b 38- .h..|.{8\n" +" 0038 - 43 2f b9 0e 23 02 b9 4f- C/..#..O\n" +" 0040 - 8c 26 eb ef 70 98 82 a7- .&..p...\n" +" 0048 - b9 78 c5 08 96 99 b3 84- .x......\n" +" 0050 - a3 4f fb d7 38 a9 d9 d4- .O..8...\n" +" 0058 - 53 0f 4f 64 97 df cf f3- S.Od....\n" +" 0060 - 4f c8 d2 56 3f 0d 72 d4- O..V?.r.\n" +" 0068 - 55 98 89 b0 45 26 3f 7a- U...E&?z\n" +" 0070 - bd 9d 96 15 a2 10 14 85- ........\n" +" 0078 - aa a1 7c 84 fb c4 a5 7b- ..|....{\n" +" 0080 - c6 e3 ad 85 57 96 bb 81- ....W...\n" +" 0088 - 18 0c ed 2f f7 6a 4c 4d- .../.jLM\n" +" 0090 - 59 e1 cc c5 3a 9f 48 fc- Y...:.H.\n" +" 0098 - 1d 7c 0d a4 79 96 e7 2b- .|..y..+\n" +" 00a0 - 39 15 f9 3a 6a 5e 7c 4e- 9..:j^|N\n" +" 00a8 - c9 3b af eb 3b cf 8d 6a- .;..;..j\n" +" 00b0 - 57 e6 c5 ba bd a6 a0 6b- W......k\n" +" 00b8 - 03 d5 a3 9f 99 2a ea 88- .....*..\n" +" 00c0 - 72 1b 66 6c 5e 1d 49 d5- r.fl^.I.\n" +" 00c8 - 1e 1e cc 1a b1 d8 f7 91- ........\n" +" 00d0 - 1e 1e cc 1a ....\n" +" 00f6 - \n", + }, + { + .indent = 39, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 45 c6 20 00 00 00 tE. ...\n" +" 0007 - 00 00 00 00 00 00 00 .......\n" +" 000e - 00 00 36 d8 61 48 68 ..6.aHh\n" +" 0015 - 3c c0 68 aa 15 57 77 <.h..Ww\n" +" 001c - e3 ec b4 98 c6 08 fc .......\n" +" 0023 - 59 b3 4f 45 cf 4b c2 Y.OE.K.\n" +" 002a - ae 98 b5 eb e0 b5 c1 .......\n" +" 0031 - 68 ba cf 7c f7 7b 38 h..|.{8\n" +" 0038 - 43 2f b9 0e 23 02 b9 C/..#..\n" +" 003f - 4f 8c 26 eb ef 70 98 O.&..p.\n" +" 0046 - 82 a7 b9 78 c5 08 96 ...x...\n" +" 004d - 99 b3 84 a3 4f fb d7 ....O..\n" +" 0054 - 38 a9 d9 d4 53 0f 4f 8...S.O\n" +" 005b - 64 97 df cf f3 4f c8 d....O.\n" +" 0062 - d2 56 3f 0d 72 d4 55 .V?.r.U\n" +" 0069 - 98 89 b0 45 26 3f 7a ...E&?z\n" +" 0070 - bd 9d 96 15 a2 10 14 .......\n" +" 0077 - 85 aa a1 7c 84 fb c4 ...|...\n" +" 007e - a5 7b c6 e3 ad 85 57 .{....W\n" +" 0085 - 96 bb 81 18 0c ed 2f ....../\n" +" 008c - f7 6a 4c 4d 59 e1 cc .jLMY..\n" +" 0093 - c5 3a 9f 48 fc 1d 7c .:.H..|\n" +" 009a - 0d a4 79 96 e7 2b 39 ..y..+9\n" +" 00a1 - 15 f9 3a 6a 5e 7c 4e ..:j^|N\n" +" 00a8 - c9 3b af eb 3b cf 8d .;..;..\n" +" 00af - 6a 57 e6 c5 ba bd a6 jW.....\n" +" 00b6 - a0 6b 03 d5 a3 9f 99 .k.....\n" +" 00bd - 2a ea 88 72 1b 66 6c *..r.fl\n" +" 00c4 - 5e 1d 49 d5 1e 1e cc ^.I....\n" +" 00cb - 1a b1 d8 f7 91 1e 1e .......\n" +" 00d2 - cc 1a ..\n" +" 00f6 - \n", + }, + { + .indent = 46, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 45 c6 20 00 00 tE. ..\n" +" 0006 - 00 00 00 00 00 00 ......\n" +" 000c - 00 00 00 00 36 d8 ....6.\n" +" 0012 - 61 48 68 3c c0 68 aHh<.h\n" +" 0018 - aa 15 57 77 e3 ec ..Ww..\n" +" 001e - b4 98 c6 08 fc 59 .....Y\n" +" 0024 - b3 4f 45 cf 4b c2 .OE.K.\n" +" 002a - ae 98 b5 eb e0 b5 ......\n" +" 0030 - c1 68 ba cf 7c f7 .h..|.\n" +" 0036 - 7b 38 43 2f b9 0e {8C/..\n" +" 003c - 23 02 b9 4f 8c 26 #..O.&\n" +" 0042 - eb ef 70 98 82 a7 ..p...\n" +" 0048 - b9 78 c5 08 96 99 .x....\n" +" 004e - b3 84 a3 4f fb d7 ...O..\n" +" 0054 - 38 a9 d9 d4 53 0f 8...S.\n" +" 005a - 4f 64 97 df cf f3 Od....\n" +" 0060 - 4f c8 d2 56 3f 0d O..V?.\n" +" 0066 - 72 d4 55 98 89 b0 r.U...\n" +" 006c - 45 26 3f 7a bd 9d E&?z..\n" +" 0072 - 96 15 a2 10 14 85 ......\n" +" 0078 - aa a1 7c 84 fb c4 ..|...\n" +" 007e - a5 7b c6 e3 ad 85 .{....\n" +" 0084 - 57 96 bb 81 18 0c W.....\n" +" 008a - ed 2f f7 6a 4c 4d ./.jLM\n" +" 0090 - 59 e1 cc c5 3a 9f Y...:.\n" +" 0096 - 48 fc 1d 7c 0d a4 H..|..\n" +" 009c - 79 96 e7 2b 39 15 y..+9.\n" +" 00a2 - f9 3a 6a 5e 7c 4e .:j^|N\n" +" 00a8 - c9 3b af eb 3b cf .;..;.\n" +" 00ae - 8d 6a 57 e6 c5 ba .jW...\n" +" 00b4 - bd a6 a0 6b 03 d5 ...k..\n" +" 00ba - a3 9f 99 2a ea 88 ...*..\n" +" 00c0 - 72 1b 66 6c 5e 1d r.fl^.\n" +" 00c6 - 49 d5 1e 1e cc 1a I.....\n" +" 00cc - b1 d8 f7 91 1e 1e ......\n" +" 00d2 - cc 1a ..\n" +" 00f6 - \n", + }, + { + .indent = 53, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 45 c6 20 tE. \n" +" 0004 - 00 00 00 00 ....\n" +" 0008 - 00 00 00 00 ....\n" +" 000c - 00 00 00 00 ....\n" +" 0010 - 36 d8 61 48 6.aH\n" +" 0014 - 68 3c c0 68 h<.h\n" +" 0018 - aa 15 57 77 ..Ww\n" +" 001c - e3 ec b4 98 ....\n" +" 0020 - c6 08 fc 59 ...Y\n" +" 0024 - b3 4f 45 cf .OE.\n" +" 0028 - 4b c2 ae 98 K...\n" +" 002c - b5 eb e0 b5 ....\n" +" 0030 - c1 68 ba cf .h..\n" +" 0034 - 7c f7 7b 38 |.{8\n" +" 0038 - 43 2f b9 0e C/..\n" +" 003c - 23 02 b9 4f #..O\n" +" 0040 - 8c 26 eb ef .&..\n" +" 0044 - 70 98 82 a7 p...\n" +" 0048 - b9 78 c5 08 .x..\n" +" 004c - 96 99 b3 84 ....\n" +" 0050 - a3 4f fb d7 .O..\n" +" 0054 - 38 a9 d9 d4 8...\n" +" 0058 - 53 0f 4f 64 S.Od\n" +" 005c - 97 df cf f3 ....\n" +" 0060 - 4f c8 d2 56 O..V\n" +" 0064 - 3f 0d 72 d4 ?.r.\n" +" 0068 - 55 98 89 b0 U...\n" +" 006c - 45 26 3f 7a E&?z\n" +" 0070 - bd 9d 96 15 ....\n" +" 0074 - a2 10 14 85 ....\n" +" 0078 - aa a1 7c 84 ..|.\n" +" 007c - fb c4 a5 7b ...{\n" +" 0080 - c6 e3 ad 85 ....\n" +" 0084 - 57 96 bb 81 W...\n" +" 0088 - 18 0c ed 2f .../\n" +" 008c - f7 6a 4c 4d .jLM\n" +" 0090 - 59 e1 cc c5 Y...\n" +" 0094 - 3a 9f 48 fc :.H.\n" +" 0098 - 1d 7c 0d a4 .|..\n" +" 009c - 79 96 e7 2b y..+\n" +" 00a0 - 39 15 f9 3a 9..:\n" +" 00a4 - 6a 5e 7c 4e j^|N\n" +" 00a8 - c9 3b af eb .;..\n" +" 00ac - 3b cf 8d 6a ;..j\n" +" 00b0 - 57 e6 c5 ba W...\n" +" 00b4 - bd a6 a0 6b ...k\n" +" 00b8 - 03 d5 a3 9f ....\n" +" 00bc - 99 2a ea 88 .*..\n" +" 00c0 - 72 1b 66 6c r.fl\n" +" 00c4 - 5e 1d 49 d5 ^.I.\n" +" 00c8 - 1e 1e cc 1a ....\n" +" 00cc - b1 d8 f7 91 ....\n" +" 00d0 - 1e 1e cc 1a ....\n" +" 00f6 - \n", + }, + { + .indent = 60, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 45 tE\n" +" 0002 - c6 20 . \n" +" 0004 - 00 00 ..\n" +" 0006 - 00 00 ..\n" +" 0008 - 00 00 ..\n" +" 000a - 00 00 ..\n" +" 000c - 00 00 ..\n" +" 000e - 00 00 ..\n" +" 0010 - 36 d8 6.\n" +" 0012 - 61 48 aH\n" +" 0014 - 68 3c h<\n" +" 0016 - c0 68 .h\n" +" 0018 - aa 15 ..\n" +" 001a - 57 77 Ww\n" +" 001c - e3 ec ..\n" +" 001e - b4 98 ..\n" +" 0020 - c6 08 ..\n" +" 0022 - fc 59 .Y\n" +" 0024 - b3 4f .O\n" +" 0026 - 45 cf E.\n" +" 0028 - 4b c2 K.\n" +" 002a - ae 98 ..\n" +" 002c - b5 eb ..\n" +" 002e - e0 b5 ..\n" +" 0030 - c1 68 .h\n" +" 0032 - ba cf ..\n" +" 0034 - 7c f7 |.\n" +" 0036 - 7b 38 {8\n" +" 0038 - 43 2f C/\n" +" 003a - b9 0e ..\n" +" 003c - 23 02 #.\n" +" 003e - b9 4f .O\n" +" 0040 - 8c 26 .&\n" +" 0042 - eb ef ..\n" +" 0044 - 70 98 p.\n" +" 0046 - 82 a7 ..\n" +" 0048 - b9 78 .x\n" +" 004a - c5 08 ..\n" +" 004c - 96 99 ..\n" +" 004e - b3 84 ..\n" +" 0050 - a3 4f .O\n" +" 0052 - fb d7 ..\n" +" 0054 - 38 a9 8.\n" +" 0056 - d9 d4 ..\n" +" 0058 - 53 0f S.\n" +" 005a - 4f 64 Od\n" +" 005c - 97 df ..\n" +" 005e - cf f3 ..\n" +" 0060 - 4f c8 O.\n" +" 0062 - d2 56 .V\n" +" 0064 - 3f 0d ?.\n" +" 0066 - 72 d4 r.\n" +" 0068 - 55 98 U.\n" +" 006a - 89 b0 ..\n" +" 006c - 45 26 E&\n" +" 006e - 3f 7a ?z\n" +" 0070 - bd 9d ..\n" +" 0072 - 96 15 ..\n" +" 0074 - a2 10 ..\n" +" 0076 - 14 85 ..\n" +" 0078 - aa a1 ..\n" +" 007a - 7c 84 |.\n" +" 007c - fb c4 ..\n" +" 007e - a5 7b .{\n" +" 0080 - c6 e3 ..\n" +" 0082 - ad 85 ..\n" +" 0084 - 57 96 W.\n" +" 0086 - bb 81 ..\n" +" 0088 - 18 0c ..\n" +" 008a - ed 2f ./\n" +" 008c - f7 6a .j\n" +" 008e - 4c 4d LM\n" +" 0090 - 59 e1 Y.\n" +" 0092 - cc c5 ..\n" +" 0094 - 3a 9f :.\n" +" 0096 - 48 fc H.\n" +" 0098 - 1d 7c .|\n" +" 009a - 0d a4 ..\n" +" 009c - 79 96 y.\n" +" 009e - e7 2b .+\n" +" 00a0 - 39 15 9.\n" +" 00a2 - f9 3a .:\n" +" 00a4 - 6a 5e j^\n" +" 00a6 - 7c 4e |N\n" +" 00a8 - c9 3b .;\n" +" 00aa - af eb ..\n" +" 00ac - 3b cf ;.\n" +" 00ae - 8d 6a .j\n" +" 00b0 - 57 e6 W.\n" +" 00b2 - c5 ba ..\n" +" 00b4 - bd a6 ..\n" +" 00b6 - a0 6b .k\n" +" 00b8 - 03 d5 ..\n" +" 00ba - a3 9f ..\n" +" 00bc - 99 2a .*\n" +" 00be - ea 88 ..\n" +" 00c0 - 72 1b r.\n" +" 00c2 - 66 6c fl\n" +" 00c4 - 5e 1d ^.\n" +" 00c6 - 49 d5 I.\n" +" 00c8 - 1e 1e ..\n" +" 00ca - cc 1a ..\n" +" 00cc - b1 d8 ..\n" +" 00ce - f7 91 ..\n" +" 00d0 - 1e 1e ..\n" +" 00d2 - cc 1a ..\n" +" 00f6 - \n", + }, + { + .indent = 67, + .input = dump, + .inlen = DUMP_LEN, + .output = +" 0000 - 74 t\n" +" 0001 - 45 E\n" +" 0002 - c6 .\n" +" 0003 - 20 \n" +" 0004 - 00 .\n" +" 0005 - 00 .\n" +" 0006 - 00 .\n" +" 0007 - 00 .\n" +" 0008 - 00 .\n" +" 0009 - 00 .\n" +" 000a - 00 .\n" +" 000b - 00 .\n" +" 000c - 00 .\n" +" 000d - 00 .\n" +" 000e - 00 .\n" +" 000f - 00 .\n" +" 0010 - 36 6\n" +" 0011 - d8 .\n" +" 0012 - 61 a\n" +" 0013 - 48 H\n" +" 0014 - 68 h\n" +" 0015 - 3c <\n" +" 0016 - c0 .\n" +" 0017 - 68 h\n" +" 0018 - aa .\n" +" 0019 - 15 .\n" +" 001a - 57 W\n" +" 001b - 77 w\n" +" 001c - e3 .\n" +" 001d - ec .\n" +" 001e - b4 .\n" +" 001f - 98 .\n" +" 0020 - c6 .\n" +" 0021 - 08 .\n" +" 0022 - fc .\n" +" 0023 - 59 Y\n" +" 0024 - b3 .\n" +" 0025 - 4f O\n" +" 0026 - 45 E\n" +" 0027 - cf .\n" +" 0028 - 4b K\n" +" 0029 - c2 .\n" +" 002a - ae .\n" +" 002b - 98 .\n" +" 002c - b5 .\n" +" 002d - eb .\n" +" 002e - e0 .\n" +" 002f - b5 .\n" +" 0030 - c1 .\n" +" 0031 - 68 h\n" +" 0032 - ba .\n" +" 0033 - cf .\n" +" 0034 - 7c |\n" +" 0035 - f7 .\n" +" 0036 - 7b {\n" +" 0037 - 38 8\n" +" 0038 - 43 C\n" +" 0039 - 2f /\n" +" 003a - b9 .\n" +" 003b - 0e .\n" +" 003c - 23 #\n" +" 003d - 02 .\n" +" 003e - b9 .\n" +" 003f - 4f O\n" +" 0040 - 8c .\n" +" 0041 - 26 &\n" +" 0042 - eb .\n" +" 0043 - ef .\n" +" 0044 - 70 p\n" +" 0045 - 98 .\n" +" 0046 - 82 .\n" +" 0047 - a7 .\n" +" 0048 - b9 .\n" +" 0049 - 78 x\n" +" 004a - c5 .\n" +" 004b - 08 .\n" +" 004c - 96 .\n" +" 004d - 99 .\n" +" 004e - b3 .\n" +" 004f - 84 .\n" +" 0050 - a3 .\n" +" 0051 - 4f O\n" +" 0052 - fb .\n" +" 0053 - d7 .\n" +" 0054 - 38 8\n" +" 0055 - a9 .\n" +" 0056 - d9 .\n" +" 0057 - d4 .\n" +" 0058 - 53 S\n" +" 0059 - 0f .\n" +" 005a - 4f O\n" +" 005b - 64 d\n" +" 005c - 97 .\n" +" 005d - df .\n" +" 005e - cf .\n" +" 005f - f3 .\n" +" 0060 - 4f O\n" +" 0061 - c8 .\n" +" 0062 - d2 .\n" +" 0063 - 56 V\n" +" 0064 - 3f ?\n" +" 0065 - 0d .\n" +" 0066 - 72 r\n" +" 0067 - d4 .\n" +" 0068 - 55 U\n" +" 0069 - 98 .\n" +" 006a - 89 .\n" +" 006b - b0 .\n" +" 006c - 45 E\n" +" 006d - 26 &\n" +" 006e - 3f ?\n" +" 006f - 7a z\n" +" 0070 - bd .\n" +" 0071 - 9d .\n" +" 0072 - 96 .\n" +" 0073 - 15 .\n" +" 0074 - a2 .\n" +" 0075 - 10 .\n" +" 0076 - 14 .\n" +" 0077 - 85 .\n" +" 0078 - aa .\n" +" 0079 - a1 .\n" +" 007a - 7c |\n" +" 007b - 84 .\n" +" 007c - fb .\n" +" 007d - c4 .\n" +" 007e - a5 .\n" +" 007f - 7b {\n" +" 0080 - c6 .\n" +" 0081 - e3 .\n" +" 0082 - ad .\n" +" 0083 - 85 .\n" +" 0084 - 57 W\n" +" 0085 - 96 .\n" +" 0086 - bb .\n" +" 0087 - 81 .\n" +" 0088 - 18 .\n" +" 0089 - 0c .\n" +" 008a - ed .\n" +" 008b - 2f /\n" +" 008c - f7 .\n" +" 008d - 6a j\n" +" 008e - 4c L\n" +" 008f - 4d M\n" +" 0090 - 59 Y\n" +" 0091 - e1 .\n" +" 0092 - cc .\n" +" 0093 - c5 .\n" +" 0094 - 3a :\n" +" 0095 - 9f .\n" +" 0096 - 48 H\n" +" 0097 - fc .\n" +" 0098 - 1d .\n" +" 0099 - 7c |\n" +" 009a - 0d .\n" +" 009b - a4 .\n" +" 009c - 79 y\n" +" 009d - 96 .\n" +" 009e - e7 .\n" +" 009f - 2b +\n" +" 00a0 - 39 9\n" +" 00a1 - 15 .\n" +" 00a2 - f9 .\n" +" 00a3 - 3a :\n" +" 00a4 - 6a j\n" +" 00a5 - 5e ^\n" +" 00a6 - 7c |\n" +" 00a7 - 4e N\n" +" 00a8 - c9 .\n" +" 00a9 - 3b ;\n" +" 00aa - af .\n" +" 00ab - eb .\n" +" 00ac - 3b ;\n" +" 00ad - cf .\n" +" 00ae - 8d .\n" +" 00af - 6a j\n" +" 00b0 - 57 W\n" +" 00b1 - e6 .\n" +" 00b2 - c5 .\n" +" 00b3 - ba .\n" +" 00b4 - bd .\n" +" 00b5 - a6 .\n" +" 00b6 - a0 .\n" +" 00b7 - 6b k\n" +" 00b8 - 03 .\n" +" 00b9 - d5 .\n" +" 00ba - a3 .\n" +" 00bb - 9f .\n" +" 00bc - 99 .\n" +" 00bd - 2a *\n" +" 00be - ea .\n" +" 00bf - 88 .\n" +" 00c0 - 72 r\n" +" 00c1 - 1b .\n" +" 00c2 - 66 f\n" +" 00c3 - 6c l\n" +" 00c4 - 5e ^\n" +" 00c5 - 1d .\n" +" 00c6 - 49 I\n" +" 00c7 - d5 .\n" +" 00c8 - 1e .\n" +" 00c9 - 1e .\n" +" 00ca - cc .\n" +" 00cb - 1a .\n" +" 00cc - b1 .\n" +" 00cd - d8 .\n" +" 00ce - f7 .\n" +" 00cf - 91 .\n" +" 00d0 - 1e .\n" +" 00d1 - 1e .\n" +" 00d2 - cc .\n" +" 00d3 - 1a .\n" +" 00f6 - \n", + }, +}; + +#define N_TESTS (sizeof(bio_dump_testcases) / sizeof(bio_dump_testcases[0])) + +static int +bio_dump_test(const struct bio_dump_testcase *tc) +{ + BIO *bio; + char *got; + long got_len; + int ret; + int failed = 1; + + if ((bio = BIO_new(BIO_s_mem())) == NULL) + errx(1, "BIO_new"); + + if ((ret = BIO_dump_indent(bio, tc->input, tc->inlen, tc->indent)) == -1) + errx(1, "BIO_dump_indent"); + if ((got_len = BIO_get_mem_data(bio, &got)) < 0) + errx(1, "BIO_get_mem_data"); + if (ret != got_len || strlen(tc->output) != (size_t)ret) { + fprintf(stderr, "indent %d: ret %d, got_len %ld, strlen %zu\n", + tc->indent, ret, got_len, strlen(tc->output)); + goto err; + } + if (strncmp(tc->output, got, got_len) != 0) { + fprintf(stderr, "%d: mismatch\n", tc->indent); + goto err; + } + + failed = 0; + + err: + BIO_free(bio); + + return failed; +} + +int +main(void) +{ + size_t i; + int failed = 0; + + for (i = 0; i < N_TESTS; i++) + failed |= bio_dump_test(&bio_dump_testcases[i]); + + return failed; +} diff --git a/sbin/iked/util.c b/sbin/iked/util.c index c3c0c3e29..2cd34d12b 100644 --- a/sbin/iked/util.c +++ b/sbin/iked/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.43 2023/07/28 11:23:03 claudio Exp $ */ +/* $OpenBSD: util.c,v 1.44 2024/02/03 00:38:08 jsg Exp $ */ /* * Copyright (c) 2010-2013 Reyk Floeter @@ -701,8 +701,7 @@ print_proto(uint8_t proto) if ((p = getprotobynumber(proto)) != NULL) strlcpy(buf[idx], p->p_name, sizeof(buf[idx])); else - snprintf(buf[idx], sizeof(buf), "%u", proto); - + snprintf(buf[idx], sizeof(buf[idx]), "%u", proto); return (buf[idx++]); } diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c index ece39d210..27cc175c8 100644 --- a/sbin/pfctl/pfctl.c +++ b/sbin/pfctl/pfctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl.c,v 1.393 2024/01/15 07:23:32 sashan Exp $ */ +/* $OpenBSD: pfctl.c,v 1.394 2024/02/02 08:23:29 sashan Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -514,7 +514,7 @@ pfctl_kill_src_nodes(int dev, int opts) dests++; - copy_satopfaddr(&psnk.psnk_src.addr.v.a.addr, + copy_satopfaddr(&psnk.psnk_dst.addr.v.a.addr, resp[1]->ai_addr); if (ioctl(dev, DIOCKILLSRCNODES, &psnk) == -1) @@ -595,7 +595,7 @@ pfctl_net_kill_states(int dev, const char *iface, int opts, int rdomain) dests++; - copy_satopfaddr(&psk.psk_src.addr.v.a.addr, + copy_satopfaddr(&psk.psk_dst.addr.v.a.addr, resp[1]->ai_addr); if (ioctl(dev, DIOCKILLSTATES, &psk) == -1) diff --git a/sys/arch/amd64/pci/pci_machdep.c b/sys/arch/amd64/pci/pci_machdep.c index 41c65293c..16d2362f4 100644 --- a/sys/arch/amd64/pci/pci_machdep.c +++ b/sys/arch/amd64/pci/pci_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci_machdep.c,v 1.78 2024/01/19 18:38:16 kettenis Exp $ */ +/* $OpenBSD: pci_machdep.c,v 1.79 2024/02/02 21:13:35 kettenis Exp $ */ /* $NetBSD: pci_machdep.c,v 1.3 2003/05/07 21:33:58 fvdl Exp $ */ /*- @@ -499,8 +499,8 @@ pci_intr_map_msivec(struct pci_attach_args *pa, int vec, return 1; mme = ((reg & PCI_MSI_MC_MME_MASK) >> PCI_MSI_MC_MME_SHIFT); - if (vec > (1 << mme)) - return 0; + if (vec >= (1 << mme)) + return 1; ihp->tag = PCI_MSI_PIN(tag, vec); ihp->line = APIC_INT_VIA_MSG; diff --git a/sys/dev/fdt/sxiccmu.c b/sys/dev/fdt/sxiccmu.c index 568f8276c..f482a7320 100644 --- a/sys/dev/fdt/sxiccmu.c +++ b/sys/dev/fdt/sxiccmu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sxiccmu.c,v 1.33 2024/01/26 17:50:00 kettenis Exp $ */ +/* $OpenBSD: sxiccmu.c,v 1.34 2024/02/02 12:01:49 kettenis Exp $ */ /* * Copyright (c) 2007,2009 Dale Rahn * Copyright (c) 2013 Artturi Alm @@ -1168,14 +1168,50 @@ sxiccmu_a80_get_frequency(struct sxiccmu_softc *sc, uint32_t idx) } /* Allwinner D1 */ +#define D1_PLL_CPU_CTRL_REG 0x0000 +#define D1_PLL_CPU_FACTOR_M(x) (((x) >> 0) & 0x3) +#define D1_PLL_CPU_FACTOR_N(x) (((x) >> 8) & 0xff) +#define D1_RISCV_CLK_REG 0x0d00 +#define D1_RISCV_CLK_SEL (7 << 24) +#define D1_RISCV_CLK_SEL_HOSC (0 << 24) +#define D1_RISCV_CLK_SEL_PLL_CPU (5 << 24) +#define D1_RISCV_DIV_CFG_FACTOR_M(x) (((x) >> 0) & 0x1f) uint32_t sxiccmu_d1_get_frequency(struct sxiccmu_softc *sc, uint32_t idx) { + uint32_t parent; + uint32_t reg; + uint32_t m, n; + switch (idx) { + case D1_CLK_HOSC: + return clock_get_frequency(sc->sc_node, "hosc"); + case D1_CLK_PLL_CPU: + reg = SXIREAD4(sc, D1_PLL_CPU_CTRL_REG); + m = D1_PLL_CPU_FACTOR_M(reg) + 1; + n = D1_PLL_CPU_FACTOR_N(reg) + 1; + return (24000000 * n) / m; + case D1_CLK_PLL_PERIPH0: + /* Not hardcoded, but recommended. */ + return 600000000; case D1_CLK_APB1: /* XXX Controlled by a MUX. */ return 24000000; + case D1_CLK_RISCV: + reg = SXIREAD4(sc, D1_RISCV_CLK_REG); + switch (reg & D1_RISCV_CLK_SEL) { + case D1_RISCV_CLK_SEL_HOSC: + parent = D1_CLK_HOSC; + break; + case D1_RISCV_CLK_SEL_PLL_CPU: + parent = D1_CLK_PLL_CPU; + break; + default: + return 0; + } + m = D1_RISCV_DIV_CFG_FACTOR_M(reg) + 1; + return sxiccmu_ccu_get_frequency(sc, &parent) / m; } printf("%s: 0x%08x\n", __func__, idx); @@ -1671,9 +1707,72 @@ sxiccmu_a80_set_frequency(struct sxiccmu_softc *sc, uint32_t idx, uint32_t freq) return -1; } +#define D1_SMHC0_CLK_REG 0x0830 +#define D1_SMHC1_CLK_REG 0x0834 +#define D1_SMHC2_CLK_REG 0x0838 +#define D1_SMHC_CLK_SRC_SEL (0x3 << 24) +#define D1_SMHC_CLK_SRC_SEL_HOSC (0x0 << 24) +#define D1_SMHC_CLK_SRC_SEL_PLL_PERIPH0 (0x1 << 24) +#define D1_SMHC_FACTOR_N_MASK (0x3 << 8) +#define D1_SMHC_FACTOR_N_SHIFT 8 +#define D1_SMHC_FACTOR_M_MASK (0xf << 0) +#define D1_SMHC_FACTOR_M_SHIFT 0 + +int +sxiccmu_d1_mmc_set_frequency(struct sxiccmu_softc *sc, bus_size_t offset, + uint32_t freq) +{ + uint32_t parent_freq; + uint32_t reg, m, n; + uint32_t clk_src; + + switch (freq) { + case 400000: + n = 2, m = 15; + clk_src = D1_SMHC_CLK_SRC_SEL_HOSC; + break; + case 20000000: + case 25000000: + case 26000000: + case 50000000: + case 52000000: + n = 0, m = 0; + clk_src = D1_SMHC_CLK_SRC_SEL_PLL_PERIPH0; + parent_freq = + sxiccmu_d1_get_frequency(sc, D1_CLK_PLL_PERIPH0); + while ((parent_freq / (1 << n) / 16) > freq) + n++; + while ((parent_freq / (1 << n) / (m + 1)) > freq) + m++; + break; + default: + return -1; + } + + reg = SXIREAD4(sc, offset); + reg &= ~D1_SMHC_CLK_SRC_SEL; + reg |= clk_src; + reg &= ~D1_SMHC_FACTOR_N_MASK; + reg |= n << D1_SMHC_FACTOR_N_SHIFT; + reg &= ~D1_SMHC_FACTOR_M_MASK; + reg |= m << D1_SMHC_FACTOR_M_SHIFT; + SXIWRITE4(sc, offset, reg); + + return 0; +} + int sxiccmu_d1_set_frequency(struct sxiccmu_softc *sc, uint32_t idx, uint32_t freq) { + switch (idx) { + case D1_CLK_MMC0: + return sxiccmu_d1_mmc_set_frequency(sc, D1_SMHC0_CLK_REG, freq); + case D1_CLK_MMC1: + return sxiccmu_d1_mmc_set_frequency(sc, D1_SMHC1_CLK_REG, freq); + case D1_CLK_MMC2: + return sxiccmu_d1_mmc_set_frequency(sc, D1_SMHC2_CLK_REG, freq); + } + printf("%s: 0x%08x\n", __func__, idx); return -1; } diff --git a/sys/dev/fdt/sxiccmu_clocks.h b/sys/dev/fdt/sxiccmu_clocks.h index 7dc5a90f1..f8b4a85fd 100644 --- a/sys/dev/fdt/sxiccmu_clocks.h +++ b/sys/dev/fdt/sxiccmu_clocks.h @@ -304,7 +304,15 @@ const struct sxiccmu_ccu_bit sun9i_a80_mmc_gates[] = { /* D1 */ +#define D1_CLK_PLL_CPU 0 +#define D1_CLK_PLL_PERIPH0 5 #define D1_CLK_APB1 25 +#define D1_CLK_MMC0 56 +#define D1_CLK_MMC1 57 +#define D1_CLK_MMC2 58 +#define D1_CLK_BUS_MMC0 59 +#define D1_CLK_BUS_MMC1 60 +#define D1_CLK_BUS_MMC2 61 #define D1_CLK_BUS_UART0 62 #define D1_CLK_BUS_UART1 63 #define D1_CLK_BUS_UART2 64 @@ -317,8 +325,17 @@ const struct sxiccmu_ccu_bit sun9i_a80_mmc_gates[] = { #define D1_CLK_BUS_OHCI1 100 #define D1_CLK_BUS_EHCI0 101 #define D1_CLK_BUS_EHCI1 102 +#define D1_CLK_RISCV 132 + +#define D1_CLK_HOSC 255 const struct sxiccmu_ccu_bit sun20i_d1_gates[] = { + [D1_CLK_MMC0] = { 0x0830, 31 }, + [D1_CLK_MMC1] = { 0x0834, 31 }, + [D1_CLK_MMC2] = { 0x0838, 31 }, + [D1_CLK_BUS_MMC0] = { 0x084c, 0 }, + [D1_CLK_BUS_MMC1] = { 0x084c, 1 }, + [D1_CLK_BUS_MMC2] = { 0x084c, 2 }, [D1_CLK_BUS_UART0] = { 0x090c, 0, D1_CLK_APB1 }, [D1_CLK_BUS_UART1] = { 0x090c, 1, D1_CLK_APB1 }, [D1_CLK_BUS_UART2] = { 0x090c, 2, D1_CLK_APB1 }, @@ -801,6 +818,9 @@ const struct sxiccmu_ccu_bit sun9i_a80_mmc_resets[] = { /* D1 */ +#define D1_RST_BUS_MMC0 15 +#define D1_RST_BUS_MMC1 16 +#define D1_RST_BUS_MMC2 17 #define D1_RST_BUS_UART0 18 #define D1_RST_BUS_UART1 19 #define D1_RST_BUS_UART2 20 @@ -815,6 +835,9 @@ const struct sxiccmu_ccu_bit sun9i_a80_mmc_resets[] = { #define D1_RST_BUS_EHCI1 45 const struct sxiccmu_ccu_bit sun20i_d1_resets[] = { + [D1_RST_BUS_MMC0] = { 0x084c, 16 }, + [D1_RST_BUS_MMC1] = { 0x084c, 17 }, + [D1_RST_BUS_MMC2] = { 0x084c, 18 }, [D1_RST_BUS_UART0] = { 0x090c, 16 }, [D1_RST_BUS_UART1] = { 0x090c, 17 }, [D1_RST_BUS_UART2] = { 0x090c, 18 }, diff --git a/sys/dev/fdt/sximmc.c b/sys/dev/fdt/sximmc.c index 43f179277..d90c36c60 100644 --- a/sys/dev/fdt/sximmc.c +++ b/sys/dev/fdt/sximmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sximmc.c,v 1.12 2021/10/24 17:52:27 mpi Exp $ */ +/* $OpenBSD: sximmc.c,v 1.13 2024/02/02 12:02:26 kettenis Exp $ */ /* $NetBSD: awin_mmc.c,v 1.23 2015/11/14 10:32:40 bouyer Exp $ */ /*- @@ -261,6 +261,7 @@ struct sximmc_softc { bus_dmamap_t sc_idma_map; int sc_idma_ndesc; char *sc_idma_desc; + int sc_idma_shift; uint32_t sc_intr_rint; uint32_t sc_intr_mint; @@ -297,6 +298,8 @@ sximmc_match(struct device *parent, void *match, void *aux) OF_is_compatible(faa->fa_node, "allwinner,sun5i-a13-mmc") || OF_is_compatible(faa->fa_node, "allwinner,sun7i-a20-mmc") || OF_is_compatible(faa->fa_node, "allwinner,sun9i-a80-mmc") || + OF_is_compatible(faa->fa_node, "allwinner,sun20i-d1-mmc") || + OF_is_compatible(faa->fa_node, "allwinner,sun20i-d1-emmc") || OF_is_compatible(faa->fa_node, "allwinner,sun50i-a64-mmc") || OF_is_compatible(faa->fa_node, "allwinner,sun50i-a64-emmc")); } @@ -394,6 +397,10 @@ sximmc_attach(struct device *parent, struct device *self, void *aux) else sc->sc_dma_ftrglevel = SXIMMC_DMA_FTRGLEVEL_A20; + if (OF_is_compatible(faa->fa_node, "allwinner,sun20i-d1-mmc") || + OF_is_compatible(faa->fa_node, "allwinner,sun20i-d1-emmc")) + sc->sc_idma_shift = 2; + if (sc->sc_use_dma) { if (sximmc_idma_setup(sc) != 0) { printf("%s: failed to setup DMA\n", self->dv_xname); @@ -443,6 +450,8 @@ sximmc_attach(struct device *parent, struct device *self, void *aux) } if (OF_is_compatible(sc->sc_node, "allwinner,sun4i-a10-mmc") || + OF_is_compatible(sc->sc_node, "allwinner,sun20i-d1-mmc") || + OF_is_compatible(sc->sc_node, "allwinner,sun20i-d1-emmc") || OF_is_compatible(sc->sc_node, "allwinner,sun50i-a64-emmc")) { saa.max_seg = 0x2000; } else { @@ -853,8 +862,10 @@ sximmc_dma_prepare(struct sximmc_softc *sc, struct sdmmc_command *cmd) for (seg = 0; seg < cmd->c_dmamap->dm_nsegs; seg++) { bus_addr_t paddr = cmd->c_dmamap->dm_segs[seg].ds_addr; bus_size_t len = cmd->c_dmamap->dm_segs[seg].ds_len; + + desc_paddr += sizeof(struct sximmc_idma_descriptor); dma[seg].dma_buf_size = htole32(len); - dma[seg].dma_buf_addr = htole32(paddr); + dma[seg].dma_buf_addr = htole32(paddr >> sc->sc_idma_shift); dma[seg].dma_config = htole32(SXIMMC_IDMA_CONFIG_CH | SXIMMC_IDMA_CONFIG_OWN); if (seg == 0) { @@ -870,9 +881,8 @@ sximmc_dma_prepare(struct sximmc_softc *sc, struct sdmmc_command *cmd) } else { dma[seg].dma_config |= htole32(SXIMMC_IDMA_CONFIG_DIC); - dma[seg].dma_next = htole32( - desc_paddr + ((seg + 1) * - sizeof(struct sximmc_idma_descriptor))); + dma[seg].dma_next = + htole32(desc_paddr >> sc->sc_idma_shift); } } @@ -897,7 +907,8 @@ sximmc_dma_prepare(struct sximmc_softc *sc, struct sdmmc_command *cmd) else val |= SXIMMC_IDST_TRANSMIT_INT; MMC_WRITE(sc, SXIMMC_IDIE, val); - MMC_WRITE(sc, SXIMMC_DLBA, desc_paddr); + MMC_WRITE(sc, SXIMMC_DLBA, + sc->sc_idma_map->dm_segs[0].ds_addr >> sc->sc_idma_shift); MMC_WRITE(sc, SXIMMC_FTRGLEVEL, sc->sc_dma_ftrglevel); return 0; diff --git a/sys/dev/ic/qwx.c b/sys/dev/ic/qwx.c index 6e9596973..cc13b0978 100644 --- a/sys/dev/ic/qwx.c +++ b/sys/dev/ic/qwx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: qwx.c,v 1.13 2024/01/30 15:33:32 stsp Exp $ */ +/* $OpenBSD: qwx.c,v 1.14 2024/02/02 15:44:19 stsp Exp $ */ /* * Copyright 2023 Stefan Sperling @@ -358,7 +358,7 @@ qwx_tx(struct qwx_softc *sc, struct mbuf *m, struct ieee80211_node *ni) if (frame_type == IEEE80211_FC0_TYPE_MGT) return qwx_mac_mgmt_tx_wmi(sc, arvif, pdev_id, m); - printf("%s: not implemented\n", sc->sc_dev.dv_xname); + printf("%s: not implemented\n", __func__); m_freem(m); return ENOTSUP; } @@ -837,6 +837,7 @@ qwx_hw_ipq5018_reo_setup(struct qwx_softc *sc) sc->ops.write32(sc, reo_base + HAL_REO1_DEST_RING_CTRL_IX_3, ring_hash_map); } + int qwx_hw_mac_id_to_pdev_id_ipq8074(struct ath11k_hw_params *hw, int mac_id) { @@ -860,6 +861,600 @@ qwx_hw_mac_id_to_srng_id_qca6390(struct ath11k_hw_params *hw, int mac_id) return mac_id; } +uint8_t +qwx_hw_ipq8074_rx_desc_get_l3_pad_bytes(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_END_INFO2_L3_HDR_PADDING, + le32toh(desc->u.ipq8074.msdu_end.info2)); +} + +uint8_t * +qwx_hw_ipq8074_rx_desc_get_hdr_status(struct hal_rx_desc *desc) +{ + return desc->u.ipq8074.hdr_status; +} + +int +qwx_hw_ipq8074_rx_desc_encrypt_valid(struct hal_rx_desc *desc) +{ + return le32toh(desc->u.ipq8074.mpdu_start.info1) & + RX_MPDU_START_INFO1_ENCRYPT_INFO_VALID; +} + +uint32_t +qwx_hw_ipq8074_rx_desc_get_encrypt_type(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MPDU_START_INFO2_ENC_TYPE, + le32toh(desc->u.ipq8074.mpdu_start.info2)); +} + +uint8_t +qwx_hw_ipq8074_rx_desc_get_decap_type(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO2_DECAP_FORMAT, + le32toh(desc->u.ipq8074.msdu_start.info2)); +} + +uint8_t +qwx_hw_ipq8074_rx_desc_get_mesh_ctl(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO2_MESH_CTRL_PRESENT, + le32toh(desc->u.ipq8074.msdu_start.info2)); +} + +int +qwx_hw_ipq8074_rx_desc_get_ldpc_support(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO2_LDPC, + le32toh(desc->u.ipq8074.msdu_start.info2)); +} + +int +qwx_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MPDU_START_INFO1_MPDU_SEQ_CTRL_VALID, + le32toh(desc->u.ipq8074.mpdu_start.info1)); +} + +int +qwx_hw_ipq8074_rx_desc_get_mpdu_fc_valid(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MPDU_START_INFO1_MPDU_FCTRL_VALID, + le32toh(desc->u.ipq8074.mpdu_start.info1)); +} + +uint16_t +qwx_hw_ipq8074_rx_desc_get_mpdu_start_seq_no(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MPDU_START_INFO1_MPDU_SEQ_NUM, + le32toh(desc->u.ipq8074.mpdu_start.info1)); +} + +uint16_t +qwx_hw_ipq8074_rx_desc_get_msdu_len(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO1_MSDU_LENGTH, + le32toh(desc->u.ipq8074.msdu_start.info1)); +} + +uint8_t +qwx_hw_ipq8074_rx_desc_get_msdu_sgi(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_SGI, + le32toh(desc->u.ipq8074.msdu_start.info3)); +} + +uint8_t +qwx_hw_ipq8074_rx_desc_get_msdu_rate_mcs(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_RATE_MCS, + le32toh(desc->u.ipq8074.msdu_start.info3)); +} + +uint8_t +qwx_hw_ipq8074_rx_desc_get_msdu_rx_bw(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_RECV_BW, + le32toh(desc->u.ipq8074.msdu_start.info3)); +} + +uint32_t +qwx_hw_ipq8074_rx_desc_get_msdu_freq(struct hal_rx_desc *desc) +{ + return le32toh(desc->u.ipq8074.msdu_start.phy_meta_data); +} + +uint8_t +qwx_hw_ipq8074_rx_desc_get_msdu_pkt_type(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_PKT_TYPE, + le32toh(desc->u.ipq8074.msdu_start.info3)); +} + +uint8_t +qwx_hw_ipq8074_rx_desc_get_msdu_nss(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_MIMO_SS_BITMAP, + le32toh(desc->u.ipq8074.msdu_start.info3)); +} + +uint8_t +qwx_hw_ipq8074_rx_desc_get_mpdu_tid(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MPDU_START_INFO2_TID, + le32toh(desc->u.ipq8074.mpdu_start.info2)); +} + +uint16_t +qwx_hw_ipq8074_rx_desc_get_mpdu_peer_id(struct hal_rx_desc *desc) +{ + return le16toh(desc->u.ipq8074.mpdu_start.sw_peer_id); +} + +void +qwx_hw_ipq8074_rx_desc_copy_attn_end(struct hal_rx_desc *fdesc, + struct hal_rx_desc *ldesc) +{ + memcpy((uint8_t *)&fdesc->u.ipq8074.msdu_end, (uint8_t *)&ldesc->u.ipq8074.msdu_end, + sizeof(struct rx_msdu_end_ipq8074)); + memcpy((uint8_t *)&fdesc->u.ipq8074.attention, (uint8_t *)&ldesc->u.ipq8074.attention, + sizeof(struct rx_attention)); + memcpy((uint8_t *)&fdesc->u.ipq8074.mpdu_end, (uint8_t *)&ldesc->u.ipq8074.mpdu_end, + sizeof(struct rx_mpdu_end)); +} + +uint32_t +qwx_hw_ipq8074_rx_desc_get_mpdu_start_tag(struct hal_rx_desc *desc) +{ + return FIELD_GET(HAL_TLV_HDR_TAG, + le32toh(desc->u.ipq8074.mpdu_start_tag)); +} + +uint32_t +qwx_hw_ipq8074_rx_desc_get_mpdu_ppdu_id(struct hal_rx_desc *desc) +{ + return le16toh(desc->u.ipq8074.mpdu_start.phy_ppdu_id); +} + +void +qwx_hw_ipq8074_rx_desc_set_msdu_len(struct hal_rx_desc *desc, uint16_t len) +{ + uint32_t info = le32toh(desc->u.ipq8074.msdu_start.info1); + + info &= ~RX_MSDU_START_INFO1_MSDU_LENGTH; + info |= FIELD_PREP(RX_MSDU_START_INFO1_MSDU_LENGTH, len); + + desc->u.ipq8074.msdu_start.info1 = htole32(info); +} + +int +qwx_hw_ipq8074_rx_desc_mac_addr2_valid(struct hal_rx_desc *desc) +{ + return le32toh(desc->u.ipq8074.mpdu_start.info1) & + RX_MPDU_START_INFO1_MAC_ADDR2_VALID; +} + +uint8_t * +qwx_hw_ipq8074_rx_desc_mpdu_start_addr2(struct hal_rx_desc *desc) +{ + return desc->u.ipq8074.mpdu_start.addr2; +} + +struct rx_attention * +qwx_hw_ipq8074_rx_desc_get_attention(struct hal_rx_desc *desc) +{ + return &desc->u.ipq8074.attention; +} + +uint8_t * +qwx_hw_ipq8074_rx_desc_get_msdu_payload(struct hal_rx_desc *desc) +{ + return &desc->u.ipq8074.msdu_payload[0]; +} + +int +qwx_hw_qcn9074_rx_desc_get_first_msdu(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MSDU_END_INFO4_FIRST_MSDU, + le16toh(desc->u.qcn9074.msdu_end.info4)); +} + +int +qwx_hw_qcn9074_rx_desc_get_last_msdu(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MSDU_END_INFO4_LAST_MSDU, + le16toh(desc->u.qcn9074.msdu_end.info4)); +} + +uint8_t +qwx_hw_qcn9074_rx_desc_get_l3_pad_bytes(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_END_INFO4_L3_HDR_PADDING, + le16toh(desc->u.qcn9074.msdu_end.info4)); +} + +uint8_t * +qwx_hw_qcn9074_rx_desc_get_hdr_status(struct hal_rx_desc *desc) +{ + return desc->u.qcn9074.hdr_status; +} + +int +qwx_hw_qcn9074_rx_desc_encrypt_valid(struct hal_rx_desc *desc) +{ + return le32toh(desc->u.qcn9074.mpdu_start.info11) & + RX_MPDU_START_INFO11_ENCRYPT_INFO_VALID; +} + +uint32_t +qwx_hw_qcn9074_rx_desc_get_encrypt_type(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MPDU_START_INFO9_ENC_TYPE, + le32toh(desc->u.qcn9074.mpdu_start.info9)); +} + +uint8_t +qwx_hw_qcn9074_rx_desc_get_decap_type(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO2_DECAP_FORMAT, + le32toh(desc->u.qcn9074.msdu_start.info2)); +} + +uint8_t +qwx_hw_qcn9074_rx_desc_get_mesh_ctl(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO2_MESH_CTRL_PRESENT, + le32toh(desc->u.qcn9074.msdu_start.info2)); +} + +int +qwx_hw_qcn9074_rx_desc_get_ldpc_support(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO2_LDPC, + le32toh(desc->u.qcn9074.msdu_start.info2)); +} + +int +qwx_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MPDU_START_INFO11_MPDU_SEQ_CTRL_VALID, + le32toh(desc->u.qcn9074.mpdu_start.info11)); +} + +int +qwx_hw_qcn9074_rx_desc_get_mpdu_fc_valid(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MPDU_START_INFO11_MPDU_FCTRL_VALID, + le32toh(desc->u.qcn9074.mpdu_start.info11)); +} + +uint16_t +qwx_hw_qcn9074_rx_desc_get_mpdu_start_seq_no(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MPDU_START_INFO11_MPDU_SEQ_NUM, + le32toh(desc->u.qcn9074.mpdu_start.info11)); +} + +uint16_t +qwx_hw_qcn9074_rx_desc_get_msdu_len(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO1_MSDU_LENGTH, + le32toh(desc->u.qcn9074.msdu_start.info1)); +} + +uint8_t +qwx_hw_qcn9074_rx_desc_get_msdu_sgi(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_SGI, + le32toh(desc->u.qcn9074.msdu_start.info3)); +} + +uint8_t +qwx_hw_qcn9074_rx_desc_get_msdu_rate_mcs(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_RATE_MCS, + le32toh(desc->u.qcn9074.msdu_start.info3)); +} + +uint8_t +qwx_hw_qcn9074_rx_desc_get_msdu_rx_bw(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_RECV_BW, + le32toh(desc->u.qcn9074.msdu_start.info3)); +} + +uint32_t +qwx_hw_qcn9074_rx_desc_get_msdu_freq(struct hal_rx_desc *desc) +{ + return le32toh(desc->u.qcn9074.msdu_start.phy_meta_data); +} + +uint8_t +qwx_hw_qcn9074_rx_desc_get_msdu_pkt_type(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_PKT_TYPE, + le32toh(desc->u.qcn9074.msdu_start.info3)); +} + +uint8_t +qwx_hw_qcn9074_rx_desc_get_msdu_nss(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_MIMO_SS_BITMAP, + le32toh(desc->u.qcn9074.msdu_start.info3)); +} + +uint8_t +qwx_hw_qcn9074_rx_desc_get_mpdu_tid(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MPDU_START_INFO9_TID, + le32toh(desc->u.qcn9074.mpdu_start.info9)); +} + +uint16_t +qwx_hw_qcn9074_rx_desc_get_mpdu_peer_id(struct hal_rx_desc *desc) +{ + return le16toh(desc->u.qcn9074.mpdu_start.sw_peer_id); +} + +void +qwx_hw_qcn9074_rx_desc_copy_attn_end(struct hal_rx_desc *fdesc, + struct hal_rx_desc *ldesc) +{ + memcpy((uint8_t *)&fdesc->u.qcn9074.msdu_end, (uint8_t *)&ldesc->u.qcn9074.msdu_end, + sizeof(struct rx_msdu_end_qcn9074)); + memcpy((uint8_t *)&fdesc->u.qcn9074.attention, (uint8_t *)&ldesc->u.qcn9074.attention, + sizeof(struct rx_attention)); + memcpy((uint8_t *)&fdesc->u.qcn9074.mpdu_end, (uint8_t *)&ldesc->u.qcn9074.mpdu_end, + sizeof(struct rx_mpdu_end)); +} + +uint32_t +qwx_hw_qcn9074_rx_desc_get_mpdu_start_tag(struct hal_rx_desc *desc) +{ + return FIELD_GET(HAL_TLV_HDR_TAG, + le32toh(desc->u.qcn9074.mpdu_start_tag)); +} + +uint32_t +qwx_hw_qcn9074_rx_desc_get_mpdu_ppdu_id(struct hal_rx_desc *desc) +{ + return le16toh(desc->u.qcn9074.mpdu_start.phy_ppdu_id); +} + +void +qwx_hw_qcn9074_rx_desc_set_msdu_len(struct hal_rx_desc *desc, uint16_t len) +{ + uint32_t info = le32toh(desc->u.qcn9074.msdu_start.info1); + + info &= ~RX_MSDU_START_INFO1_MSDU_LENGTH; + info |= FIELD_PREP(RX_MSDU_START_INFO1_MSDU_LENGTH, len); + + desc->u.qcn9074.msdu_start.info1 = htole32(info); +} + +struct rx_attention * +qwx_hw_qcn9074_rx_desc_get_attention(struct hal_rx_desc *desc) +{ + return &desc->u.qcn9074.attention; +} + +uint8_t * +qwx_hw_qcn9074_rx_desc_get_msdu_payload(struct hal_rx_desc *desc) +{ + return &desc->u.qcn9074.msdu_payload[0]; +} + +int +qwx_hw_ipq9074_rx_desc_mac_addr2_valid(struct hal_rx_desc *desc) +{ + return le32toh(desc->u.qcn9074.mpdu_start.info11) & + RX_MPDU_START_INFO11_MAC_ADDR2_VALID; +} + +uint8_t * +qwx_hw_ipq9074_rx_desc_mpdu_start_addr2(struct hal_rx_desc *desc) +{ + return desc->u.qcn9074.mpdu_start.addr2; +} + +int +qwx_hw_wcn6855_rx_desc_get_first_msdu(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MSDU_END_INFO2_FIRST_MSDU_WCN6855, + le32toh(desc->u.wcn6855.msdu_end.info2)); +} + +int +qwx_hw_wcn6855_rx_desc_get_last_msdu(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MSDU_END_INFO2_LAST_MSDU_WCN6855, + le32toh(desc->u.wcn6855.msdu_end.info2)); +} + +uint8_t +qwx_hw_wcn6855_rx_desc_get_l3_pad_bytes(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_END_INFO2_L3_HDR_PADDING, + le32toh(desc->u.wcn6855.msdu_end.info2)); +} + +uint8_t * +qwx_hw_wcn6855_rx_desc_get_hdr_status(struct hal_rx_desc *desc) +{ + return desc->u.wcn6855.hdr_status; +} + +int +qwx_hw_wcn6855_rx_desc_encrypt_valid(struct hal_rx_desc *desc) +{ + return le32toh(desc->u.wcn6855.mpdu_start.info1) & + RX_MPDU_START_INFO1_ENCRYPT_INFO_VALID; +} + +uint32_t +qwx_hw_wcn6855_rx_desc_get_encrypt_type(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MPDU_START_INFO2_ENC_TYPE, + le32toh(desc->u.wcn6855.mpdu_start.info2)); +} + +uint8_t +qwx_hw_wcn6855_rx_desc_get_decap_type(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO2_DECAP_FORMAT, + le32toh(desc->u.wcn6855.msdu_start.info2)); +} + +uint8_t +qwx_hw_wcn6855_rx_desc_get_mesh_ctl(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO2_MESH_CTRL_PRESENT, + le32toh(desc->u.wcn6855.msdu_start.info2)); +} + +int +qwx_hw_wcn6855_rx_desc_get_mpdu_seq_ctl_vld(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MPDU_START_INFO1_MPDU_SEQ_CTRL_VALID, + le32toh(desc->u.wcn6855.mpdu_start.info1)); +} + +int +qwx_hw_wcn6855_rx_desc_get_mpdu_fc_valid(struct hal_rx_desc *desc) +{ + return !!FIELD_GET(RX_MPDU_START_INFO1_MPDU_FCTRL_VALID, + le32toh(desc->u.wcn6855.mpdu_start.info1)); +} + +uint16_t +qwx_hw_wcn6855_rx_desc_get_mpdu_start_seq_no(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MPDU_START_INFO1_MPDU_SEQ_NUM, + le32toh(desc->u.wcn6855.mpdu_start.info1)); +} + +uint16_t +qwx_hw_wcn6855_rx_desc_get_msdu_len(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO1_MSDU_LENGTH, + le32toh(desc->u.wcn6855.msdu_start.info1)); +} + +uint8_t +qwx_hw_wcn6855_rx_desc_get_msdu_sgi(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_SGI, + le32toh(desc->u.wcn6855.msdu_start.info3)); +} + +uint8_t +qwx_hw_wcn6855_rx_desc_get_msdu_rate_mcs(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_RATE_MCS, + le32toh(desc->u.wcn6855.msdu_start.info3)); +} + +uint8_t +qwx_hw_wcn6855_rx_desc_get_msdu_rx_bw(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_RECV_BW, + le32toh(desc->u.wcn6855.msdu_start.info3)); +} + +uint32_t +qwx_hw_wcn6855_rx_desc_get_msdu_freq(struct hal_rx_desc *desc) +{ + return le32toh(desc->u.wcn6855.msdu_start.phy_meta_data); +} + +uint8_t +qwx_hw_wcn6855_rx_desc_get_msdu_pkt_type(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_PKT_TYPE, + le32toh(desc->u.wcn6855.msdu_start.info3)); +} + +uint8_t +qwx_hw_wcn6855_rx_desc_get_msdu_nss(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MSDU_START_INFO3_MIMO_SS_BITMAP, + le32toh(desc->u.wcn6855.msdu_start.info3)); +} + +uint8_t +qwx_hw_wcn6855_rx_desc_get_mpdu_tid(struct hal_rx_desc *desc) +{ + return FIELD_GET(RX_MPDU_START_INFO2_TID_WCN6855, + le32toh(desc->u.wcn6855.mpdu_start.info2)); +} + +uint16_t +qwx_hw_wcn6855_rx_desc_get_mpdu_peer_id(struct hal_rx_desc *desc) +{ + return le16toh(desc->u.wcn6855.mpdu_start.sw_peer_id); +} + +void +qwx_hw_wcn6855_rx_desc_copy_attn_end(struct hal_rx_desc *fdesc, + struct hal_rx_desc *ldesc) +{ + memcpy((uint8_t *)&fdesc->u.wcn6855.msdu_end, (uint8_t *)&ldesc->u.wcn6855.msdu_end, + sizeof(struct rx_msdu_end_wcn6855)); + memcpy((uint8_t *)&fdesc->u.wcn6855.attention, (uint8_t *)&ldesc->u.wcn6855.attention, + sizeof(struct rx_attention)); + memcpy((uint8_t *)&fdesc->u.wcn6855.mpdu_end, (uint8_t *)&ldesc->u.wcn6855.mpdu_end, + sizeof(struct rx_mpdu_end)); +} + +uint32_t +qwx_hw_wcn6855_rx_desc_get_mpdu_start_tag(struct hal_rx_desc *desc) +{ + return FIELD_GET(HAL_TLV_HDR_TAG, + le32toh(desc->u.wcn6855.mpdu_start_tag)); +} + +uint32_t +qwx_hw_wcn6855_rx_desc_get_mpdu_ppdu_id(struct hal_rx_desc *desc) +{ + return le16toh(desc->u.wcn6855.mpdu_start.phy_ppdu_id); +} + +void +qwx_hw_wcn6855_rx_desc_set_msdu_len(struct hal_rx_desc *desc, uint16_t len) +{ + uint32_t info = le32toh(desc->u.wcn6855.msdu_start.info1); + + info &= ~RX_MSDU_START_INFO1_MSDU_LENGTH; + info |= FIELD_PREP(RX_MSDU_START_INFO1_MSDU_LENGTH, len); + + desc->u.wcn6855.msdu_start.info1 = htole32(info); +} + +struct rx_attention * +qwx_hw_wcn6855_rx_desc_get_attention(struct hal_rx_desc *desc) +{ + return &desc->u.wcn6855.attention; +} + +uint8_t * +qwx_hw_wcn6855_rx_desc_get_msdu_payload(struct hal_rx_desc *desc) +{ + return &desc->u.wcn6855.msdu_payload[0]; +} + +int +qwx_hw_wcn6855_rx_desc_mac_addr2_valid(struct hal_rx_desc *desc) +{ + return le32toh(desc->u.wcn6855.mpdu_start.info1) & + RX_MPDU_START_INFO1_MAC_ADDR2_VALID; +} + +uint8_t * +qwx_hw_wcn6855_rx_desc_mpdu_start_addr2(struct hal_rx_desc *desc) +{ + return desc->u.wcn6855.mpdu_start.addr2; +} + const struct ath11k_hw_ops ipq8074_ops = { #if notyet .get_hw_mac_from_pdev_id = ath11k_hw_ipq8074_mac_from_pdev_id, @@ -871,21 +1466,27 @@ const struct ath11k_hw_ops ipq8074_ops = { .tx_mesh_enable = ath11k_hw_ipq8074_tx_mesh_enable, .rx_desc_get_first_msdu = ath11k_hw_ipq8074_rx_desc_get_first_msdu, .rx_desc_get_last_msdu = ath11k_hw_ipq8074_rx_desc_get_last_msdu, - .rx_desc_get_l3_pad_bytes = ath11k_hw_ipq8074_rx_desc_get_l3_pad_bytes, - .rx_desc_get_hdr_status = ath11k_hw_ipq8074_rx_desc_get_hdr_status, - .rx_desc_encrypt_valid = ath11k_hw_ipq8074_rx_desc_encrypt_valid, - .rx_desc_get_encrypt_type = ath11k_hw_ipq8074_rx_desc_get_encrypt_type, - .rx_desc_get_decap_type = ath11k_hw_ipq8074_rx_desc_get_decap_type, +#endif + .rx_desc_get_l3_pad_bytes = qwx_hw_ipq8074_rx_desc_get_l3_pad_bytes, + .rx_desc_get_hdr_status = qwx_hw_ipq8074_rx_desc_get_hdr_status, + .rx_desc_encrypt_valid = qwx_hw_ipq8074_rx_desc_encrypt_valid, + .rx_desc_get_encrypt_type = qwx_hw_ipq8074_rx_desc_get_encrypt_type, + .rx_desc_get_decap_type = qwx_hw_ipq8074_rx_desc_get_decap_type, +#ifdef notyet .rx_desc_get_mesh_ctl = ath11k_hw_ipq8074_rx_desc_get_mesh_ctl, .rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_ipq8074_rx_desc_get_mpdu_start_seq_no, - .rx_desc_get_msdu_len = ath11k_hw_ipq8074_rx_desc_get_msdu_len, +#endif + .rx_desc_get_msdu_len = qwx_hw_ipq8074_rx_desc_get_msdu_len, +#ifdef notyet .rx_desc_get_msdu_sgi = ath11k_hw_ipq8074_rx_desc_get_msdu_sgi, .rx_desc_get_msdu_rate_mcs = ath11k_hw_ipq8074_rx_desc_get_msdu_rate_mcs, .rx_desc_get_msdu_rx_bw = ath11k_hw_ipq8074_rx_desc_get_msdu_rx_bw, - .rx_desc_get_msdu_freq = ath11k_hw_ipq8074_rx_desc_get_msdu_freq, +#endif + .rx_desc_get_msdu_freq = qwx_hw_ipq8074_rx_desc_get_msdu_freq, +#ifdef notyet .rx_desc_get_msdu_pkt_type = ath11k_hw_ipq8074_rx_desc_get_msdu_pkt_type, .rx_desc_get_msdu_nss = ath11k_hw_ipq8074_rx_desc_get_msdu_nss, .rx_desc_get_mpdu_tid = ath11k_hw_ipq8074_rx_desc_get_mpdu_tid, @@ -894,7 +1495,9 @@ const struct ath11k_hw_ops ipq8074_ops = { .rx_desc_get_mpdu_start_tag = ath11k_hw_ipq8074_rx_desc_get_mpdu_start_tag, .rx_desc_get_mpdu_ppdu_id = ath11k_hw_ipq8074_rx_desc_get_mpdu_ppdu_id, .rx_desc_set_msdu_len = ath11k_hw_ipq8074_rx_desc_set_msdu_len, - .rx_desc_get_attention = ath11k_hw_ipq8074_rx_desc_get_attention, +#endif + .rx_desc_get_attention = qwx_hw_ipq8074_rx_desc_get_attention, +#ifdef notyet .rx_desc_get_msdu_payload = ath11k_hw_ipq8074_rx_desc_get_msdu_payload, #endif .reo_setup = qwx_hw_ipq8074_reo_setup, @@ -917,21 +1520,27 @@ const struct ath11k_hw_ops ipq6018_ops = { .tx_mesh_enable = ath11k_hw_ipq8074_tx_mesh_enable, .rx_desc_get_first_msdu = ath11k_hw_ipq8074_rx_desc_get_first_msdu, .rx_desc_get_last_msdu = ath11k_hw_ipq8074_rx_desc_get_last_msdu, - .rx_desc_get_l3_pad_bytes = ath11k_hw_ipq8074_rx_desc_get_l3_pad_bytes, - .rx_desc_get_hdr_status = ath11k_hw_ipq8074_rx_desc_get_hdr_status, - .rx_desc_encrypt_valid = ath11k_hw_ipq8074_rx_desc_encrypt_valid, - .rx_desc_get_encrypt_type = ath11k_hw_ipq8074_rx_desc_get_encrypt_type, - .rx_desc_get_decap_type = ath11k_hw_ipq8074_rx_desc_get_decap_type, +#endif + .rx_desc_get_l3_pad_bytes = qwx_hw_ipq8074_rx_desc_get_l3_pad_bytes, + .rx_desc_get_hdr_status = qwx_hw_ipq8074_rx_desc_get_hdr_status, + .rx_desc_encrypt_valid = qwx_hw_ipq8074_rx_desc_encrypt_valid, + .rx_desc_get_encrypt_type = qwx_hw_ipq8074_rx_desc_get_encrypt_type, + .rx_desc_get_decap_type = qwx_hw_ipq8074_rx_desc_get_decap_type, +#ifdef notyet .rx_desc_get_mesh_ctl = ath11k_hw_ipq8074_rx_desc_get_mesh_ctl, .rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_ipq8074_rx_desc_get_mpdu_start_seq_no, - .rx_desc_get_msdu_len = ath11k_hw_ipq8074_rx_desc_get_msdu_len, +#endif + .rx_desc_get_msdu_len = qwx_hw_ipq8074_rx_desc_get_msdu_len, +#ifdef notyet .rx_desc_get_msdu_sgi = ath11k_hw_ipq8074_rx_desc_get_msdu_sgi, .rx_desc_get_msdu_rate_mcs = ath11k_hw_ipq8074_rx_desc_get_msdu_rate_mcs, .rx_desc_get_msdu_rx_bw = ath11k_hw_ipq8074_rx_desc_get_msdu_rx_bw, - .rx_desc_get_msdu_freq = ath11k_hw_ipq8074_rx_desc_get_msdu_freq, +#endif + .rx_desc_get_msdu_freq = qwx_hw_ipq8074_rx_desc_get_msdu_freq, +#ifdef notyet .rx_desc_get_msdu_pkt_type = ath11k_hw_ipq8074_rx_desc_get_msdu_pkt_type, .rx_desc_get_msdu_nss = ath11k_hw_ipq8074_rx_desc_get_msdu_nss, .rx_desc_get_mpdu_tid = ath11k_hw_ipq8074_rx_desc_get_mpdu_tid, @@ -940,7 +1549,9 @@ const struct ath11k_hw_ops ipq6018_ops = { .rx_desc_get_mpdu_start_tag = ath11k_hw_ipq8074_rx_desc_get_mpdu_start_tag, .rx_desc_get_mpdu_ppdu_id = ath11k_hw_ipq8074_rx_desc_get_mpdu_ppdu_id, .rx_desc_set_msdu_len = ath11k_hw_ipq8074_rx_desc_set_msdu_len, - .rx_desc_get_attention = ath11k_hw_ipq8074_rx_desc_get_attention, +#endif + .rx_desc_get_attention = qwx_hw_ipq8074_rx_desc_get_attention, +#ifdef notyet .rx_desc_get_msdu_payload = ath11k_hw_ipq8074_rx_desc_get_msdu_payload, #endif .reo_setup = qwx_hw_ipq8074_reo_setup, @@ -963,21 +1574,27 @@ const struct ath11k_hw_ops qca6390_ops = { .tx_mesh_enable = ath11k_hw_ipq8074_tx_mesh_enable, .rx_desc_get_first_msdu = ath11k_hw_ipq8074_rx_desc_get_first_msdu, .rx_desc_get_last_msdu = ath11k_hw_ipq8074_rx_desc_get_last_msdu, - .rx_desc_get_l3_pad_bytes = ath11k_hw_ipq8074_rx_desc_get_l3_pad_bytes, - .rx_desc_get_hdr_status = ath11k_hw_ipq8074_rx_desc_get_hdr_status, - .rx_desc_encrypt_valid = ath11k_hw_ipq8074_rx_desc_encrypt_valid, - .rx_desc_get_encrypt_type = ath11k_hw_ipq8074_rx_desc_get_encrypt_type, - .rx_desc_get_decap_type = ath11k_hw_ipq8074_rx_desc_get_decap_type, +#endif + .rx_desc_get_l3_pad_bytes = qwx_hw_ipq8074_rx_desc_get_l3_pad_bytes, + .rx_desc_get_hdr_status = qwx_hw_ipq8074_rx_desc_get_hdr_status, + .rx_desc_encrypt_valid = qwx_hw_ipq8074_rx_desc_encrypt_valid, + .rx_desc_get_encrypt_type = qwx_hw_ipq8074_rx_desc_get_encrypt_type, + .rx_desc_get_decap_type = qwx_hw_ipq8074_rx_desc_get_decap_type, +#ifdef notyet .rx_desc_get_mesh_ctl = ath11k_hw_ipq8074_rx_desc_get_mesh_ctl, .rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_ipq8074_rx_desc_get_mpdu_start_seq_no, - .rx_desc_get_msdu_len = ath11k_hw_ipq8074_rx_desc_get_msdu_len, +#endif + .rx_desc_get_msdu_len = qwx_hw_ipq8074_rx_desc_get_msdu_len, +#ifdef notyet .rx_desc_get_msdu_sgi = ath11k_hw_ipq8074_rx_desc_get_msdu_sgi, .rx_desc_get_msdu_rate_mcs = ath11k_hw_ipq8074_rx_desc_get_msdu_rate_mcs, .rx_desc_get_msdu_rx_bw = ath11k_hw_ipq8074_rx_desc_get_msdu_rx_bw, - .rx_desc_get_msdu_freq = ath11k_hw_ipq8074_rx_desc_get_msdu_freq, +#endif + .rx_desc_get_msdu_freq = qwx_hw_ipq8074_rx_desc_get_msdu_freq, +#ifdef notyet .rx_desc_get_msdu_pkt_type = ath11k_hw_ipq8074_rx_desc_get_msdu_pkt_type, .rx_desc_get_msdu_nss = ath11k_hw_ipq8074_rx_desc_get_msdu_nss, .rx_desc_get_mpdu_tid = ath11k_hw_ipq8074_rx_desc_get_mpdu_tid, @@ -986,7 +1603,9 @@ const struct ath11k_hw_ops qca6390_ops = { .rx_desc_get_mpdu_start_tag = ath11k_hw_ipq8074_rx_desc_get_mpdu_start_tag, .rx_desc_get_mpdu_ppdu_id = ath11k_hw_ipq8074_rx_desc_get_mpdu_ppdu_id, .rx_desc_set_msdu_len = ath11k_hw_ipq8074_rx_desc_set_msdu_len, - .rx_desc_get_attention = ath11k_hw_ipq8074_rx_desc_get_attention, +#endif + .rx_desc_get_attention = qwx_hw_ipq8074_rx_desc_get_attention, +#ifdef notyet .rx_desc_get_msdu_payload = ath11k_hw_ipq8074_rx_desc_get_msdu_payload, #endif .reo_setup = qwx_hw_ipq8074_reo_setup, @@ -1009,21 +1628,27 @@ const struct ath11k_hw_ops qcn9074_ops = { .tx_mesh_enable = ath11k_hw_qcn9074_tx_mesh_enable, .rx_desc_get_first_msdu = ath11k_hw_qcn9074_rx_desc_get_first_msdu, .rx_desc_get_last_msdu = ath11k_hw_qcn9074_rx_desc_get_last_msdu, - .rx_desc_get_l3_pad_bytes = ath11k_hw_qcn9074_rx_desc_get_l3_pad_bytes, - .rx_desc_get_hdr_status = ath11k_hw_qcn9074_rx_desc_get_hdr_status, - .rx_desc_encrypt_valid = ath11k_hw_qcn9074_rx_desc_encrypt_valid, - .rx_desc_get_encrypt_type = ath11k_hw_qcn9074_rx_desc_get_encrypt_type, - .rx_desc_get_decap_type = ath11k_hw_qcn9074_rx_desc_get_decap_type, +#endif + .rx_desc_get_l3_pad_bytes = qwx_hw_qcn9074_rx_desc_get_l3_pad_bytes, + .rx_desc_get_hdr_status = qwx_hw_qcn9074_rx_desc_get_hdr_status, + .rx_desc_encrypt_valid = qwx_hw_qcn9074_rx_desc_encrypt_valid, + .rx_desc_get_encrypt_type = qwx_hw_qcn9074_rx_desc_get_encrypt_type, + .rx_desc_get_decap_type = qwx_hw_qcn9074_rx_desc_get_decap_type, +#ifdef notyet .rx_desc_get_mesh_ctl = ath11k_hw_qcn9074_rx_desc_get_mesh_ctl, .rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_qcn9074_rx_desc_get_mpdu_start_seq_no, - .rx_desc_get_msdu_len = ath11k_hw_qcn9074_rx_desc_get_msdu_len, +#endif + .rx_desc_get_msdu_len = qwx_hw_qcn9074_rx_desc_get_msdu_len, +#ifdef notyet .rx_desc_get_msdu_sgi = ath11k_hw_qcn9074_rx_desc_get_msdu_sgi, .rx_desc_get_msdu_rate_mcs = ath11k_hw_qcn9074_rx_desc_get_msdu_rate_mcs, .rx_desc_get_msdu_rx_bw = ath11k_hw_qcn9074_rx_desc_get_msdu_rx_bw, - .rx_desc_get_msdu_freq = ath11k_hw_qcn9074_rx_desc_get_msdu_freq, +#endif + .rx_desc_get_msdu_freq = qwx_hw_qcn9074_rx_desc_get_msdu_freq, +#ifdef notyet .rx_desc_get_msdu_pkt_type = ath11k_hw_qcn9074_rx_desc_get_msdu_pkt_type, .rx_desc_get_msdu_nss = ath11k_hw_qcn9074_rx_desc_get_msdu_nss, .rx_desc_get_mpdu_tid = ath11k_hw_qcn9074_rx_desc_get_mpdu_tid, @@ -1032,7 +1657,9 @@ const struct ath11k_hw_ops qcn9074_ops = { .rx_desc_get_mpdu_start_tag = ath11k_hw_qcn9074_rx_desc_get_mpdu_start_tag, .rx_desc_get_mpdu_ppdu_id = ath11k_hw_qcn9074_rx_desc_get_mpdu_ppdu_id, .rx_desc_set_msdu_len = ath11k_hw_qcn9074_rx_desc_set_msdu_len, - .rx_desc_get_attention = ath11k_hw_qcn9074_rx_desc_get_attention, +#endif + .rx_desc_get_attention = qwx_hw_qcn9074_rx_desc_get_attention, +#ifdef notyet .rx_desc_get_msdu_payload = ath11k_hw_qcn9074_rx_desc_get_msdu_payload, #endif .reo_setup = qwx_hw_ipq8074_reo_setup, @@ -1055,21 +1682,27 @@ const struct ath11k_hw_ops wcn6855_ops = { .tx_mesh_enable = ath11k_hw_wcn6855_tx_mesh_enable, .rx_desc_get_first_msdu = ath11k_hw_wcn6855_rx_desc_get_first_msdu, .rx_desc_get_last_msdu = ath11k_hw_wcn6855_rx_desc_get_last_msdu, - .rx_desc_get_l3_pad_bytes = ath11k_hw_wcn6855_rx_desc_get_l3_pad_bytes, - .rx_desc_get_hdr_status = ath11k_hw_wcn6855_rx_desc_get_hdr_status, - .rx_desc_encrypt_valid = ath11k_hw_wcn6855_rx_desc_encrypt_valid, - .rx_desc_get_encrypt_type = ath11k_hw_wcn6855_rx_desc_get_encrypt_type, - .rx_desc_get_decap_type = ath11k_hw_wcn6855_rx_desc_get_decap_type, +#endif + .rx_desc_get_l3_pad_bytes = qwx_hw_wcn6855_rx_desc_get_l3_pad_bytes, + .rx_desc_get_hdr_status = qwx_hw_wcn6855_rx_desc_get_hdr_status, + .rx_desc_encrypt_valid = qwx_hw_wcn6855_rx_desc_encrypt_valid, + .rx_desc_get_encrypt_type = qwx_hw_wcn6855_rx_desc_get_encrypt_type, + .rx_desc_get_decap_type = qwx_hw_wcn6855_rx_desc_get_decap_type, +#ifdef notyet .rx_desc_get_mesh_ctl = ath11k_hw_wcn6855_rx_desc_get_mesh_ctl, .rx_desc_get_ldpc_support = ath11k_hw_wcn6855_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_wcn6855_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_wcn6855_rx_desc_get_mpdu_fc_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_wcn6855_rx_desc_get_mpdu_start_seq_no, - .rx_desc_get_msdu_len = ath11k_hw_wcn6855_rx_desc_get_msdu_len, +#endif + .rx_desc_get_msdu_len = qwx_hw_wcn6855_rx_desc_get_msdu_len, +#ifdef notyet .rx_desc_get_msdu_sgi = ath11k_hw_wcn6855_rx_desc_get_msdu_sgi, .rx_desc_get_msdu_rate_mcs = ath11k_hw_wcn6855_rx_desc_get_msdu_rate_mcs, .rx_desc_get_msdu_rx_bw = ath11k_hw_wcn6855_rx_desc_get_msdu_rx_bw, - .rx_desc_get_msdu_freq = ath11k_hw_wcn6855_rx_desc_get_msdu_freq, +#endif + .rx_desc_get_msdu_freq = qwx_hw_wcn6855_rx_desc_get_msdu_freq, +#ifdef notyet .rx_desc_get_msdu_pkt_type = ath11k_hw_wcn6855_rx_desc_get_msdu_pkt_type, .rx_desc_get_msdu_nss = ath11k_hw_wcn6855_rx_desc_get_msdu_nss, .rx_desc_get_mpdu_tid = ath11k_hw_wcn6855_rx_desc_get_mpdu_tid, @@ -1078,7 +1711,9 @@ const struct ath11k_hw_ops wcn6855_ops = { .rx_desc_get_mpdu_start_tag = ath11k_hw_wcn6855_rx_desc_get_mpdu_start_tag, .rx_desc_get_mpdu_ppdu_id = ath11k_hw_wcn6855_rx_desc_get_mpdu_ppdu_id, .rx_desc_set_msdu_len = ath11k_hw_wcn6855_rx_desc_set_msdu_len, - .rx_desc_get_attention = ath11k_hw_wcn6855_rx_desc_get_attention, +#endif + .rx_desc_get_attention = qwx_hw_wcn6855_rx_desc_get_attention, +#ifdef notyet .rx_desc_get_msdu_payload = ath11k_hw_wcn6855_rx_desc_get_msdu_payload, #endif .reo_setup = qwx_hw_wcn6855_reo_setup, @@ -1101,21 +1736,27 @@ const struct ath11k_hw_ops wcn6750_ops = { .tx_mesh_enable = ath11k_hw_qcn9074_tx_mesh_enable, .rx_desc_get_first_msdu = ath11k_hw_qcn9074_rx_desc_get_first_msdu, .rx_desc_get_last_msdu = ath11k_hw_qcn9074_rx_desc_get_last_msdu, - .rx_desc_get_l3_pad_bytes = ath11k_hw_qcn9074_rx_desc_get_l3_pad_bytes, - .rx_desc_get_hdr_status = ath11k_hw_qcn9074_rx_desc_get_hdr_status, - .rx_desc_encrypt_valid = ath11k_hw_qcn9074_rx_desc_encrypt_valid, - .rx_desc_get_encrypt_type = ath11k_hw_qcn9074_rx_desc_get_encrypt_type, - .rx_desc_get_decap_type = ath11k_hw_qcn9074_rx_desc_get_decap_type, +#endif + .rx_desc_get_l3_pad_bytes = qwx_hw_qcn9074_rx_desc_get_l3_pad_bytes, + .rx_desc_get_hdr_status = qwx_hw_qcn9074_rx_desc_get_hdr_status, + .rx_desc_encrypt_valid = qwx_hw_qcn9074_rx_desc_encrypt_valid, + .rx_desc_get_encrypt_type = qwx_hw_qcn9074_rx_desc_get_encrypt_type, + .rx_desc_get_decap_type = qwx_hw_qcn9074_rx_desc_get_decap_type, +#ifdef notyet .rx_desc_get_mesh_ctl = ath11k_hw_qcn9074_rx_desc_get_mesh_ctl, .rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid, .rx_desc_get_mpdu_start_seq_no = ath11k_hw_qcn9074_rx_desc_get_mpdu_start_seq_no, - .rx_desc_get_msdu_len = ath11k_hw_qcn9074_rx_desc_get_msdu_len, +#endif + .rx_desc_get_msdu_len = qwx_hw_qcn9074_rx_desc_get_msdu_len, +#ifdef notyet .rx_desc_get_msdu_sgi = ath11k_hw_qcn9074_rx_desc_get_msdu_sgi, .rx_desc_get_msdu_rate_mcs = ath11k_hw_qcn9074_rx_desc_get_msdu_rate_mcs, .rx_desc_get_msdu_rx_bw = ath11k_hw_qcn9074_rx_desc_get_msdu_rx_bw, - .rx_desc_get_msdu_freq = ath11k_hw_qcn9074_rx_desc_get_msdu_freq, +#endif + .rx_desc_get_msdu_freq = qwx_hw_qcn9074_rx_desc_get_msdu_freq, +#ifdef notyet .rx_desc_get_msdu_pkt_type = ath11k_hw_qcn9074_rx_desc_get_msdu_pkt_type, .rx_desc_get_msdu_nss = ath11k_hw_qcn9074_rx_desc_get_msdu_nss, .rx_desc_get_mpdu_tid = ath11k_hw_qcn9074_rx_desc_get_mpdu_tid, @@ -1124,7 +1765,9 @@ const struct ath11k_hw_ops wcn6750_ops = { .rx_desc_get_mpdu_start_tag = ath11k_hw_qcn9074_rx_desc_get_mpdu_start_tag, .rx_desc_get_mpdu_ppdu_id = ath11k_hw_qcn9074_rx_desc_get_mpdu_ppdu_id, .rx_desc_set_msdu_len = ath11k_hw_qcn9074_rx_desc_set_msdu_len, - .rx_desc_get_attention = ath11k_hw_qcn9074_rx_desc_get_attention, +#endif + .rx_desc_get_attention = qwx_hw_qcn9074_rx_desc_get_attention, +#ifdef notyet .rx_desc_get_msdu_payload = ath11k_hw_qcn9074_rx_desc_get_msdu_payload, #endif .reo_setup = qwx_hw_wcn6855_reo_setup, @@ -7732,7 +8375,7 @@ qwx_qmi_load_bdf_qmi(struct qwx_softc *sc, int regdb) goto out; } success: - fw_size = min_t(u32, ab->hw_params.fw.board_size, fw_entry->size); + fw_size = MIN(ab->hw_params.fw.board_size, fw_entry->size); tmp = fw_entry->data; } @@ -13919,12 +14562,451 @@ qwx_dp_rx_process_wbm_err(struct qwx_softc *sc) return 0; } +struct qwx_rx_msdu * +qwx_dp_rx_get_msdu_last_buf(struct qwx_rx_msdu_list *msdu_list, + struct qwx_rx_msdu *first) +{ + struct qwx_rx_msdu *msdu; + + if (!first->is_continuation) + return first; + + TAILQ_FOREACH(msdu, msdu_list, entry) { + if (!msdu->is_continuation) + return msdu; + } + + return NULL; +} + +static inline void * +qwx_dp_rx_get_attention(struct qwx_softc *sc, struct hal_rx_desc *desc) +{ + return sc->hw_params.hw_ops->rx_desc_get_attention(desc); +} + +static inline uint8_t +qwx_dp_rx_h_msdu_end_l3pad(struct qwx_softc *sc, struct hal_rx_desc *desc) +{ + return sc->hw_params.hw_ops->rx_desc_get_l3_pad_bytes(desc); +} + +static inline uint16_t +qwx_dp_rx_h_msdu_start_msdu_len(struct qwx_softc *sc, struct hal_rx_desc *desc) +{ + return sc->hw_params.hw_ops->rx_desc_get_msdu_len(desc); +} + +static inline int +qwx_dp_rx_h_attn_msdu_done(struct rx_attention *attn) +{ + return !!FIELD_GET(RX_ATTENTION_INFO2_MSDU_DONE, le32toh(attn->info2)); +} + +static inline uint32_t +qwx_dp_rx_h_msdu_start_freq(struct qwx_softc *sc, struct hal_rx_desc *desc) +{ + return sc->hw_params.hw_ops->rx_desc_get_msdu_freq(desc); +} + +uint32_t +qwx_dp_rx_h_attn_mpdu_err(struct rx_attention *attn) +{ + uint32_t info = le32toh(attn->info1); + uint32_t errmap = 0; + + if (info & RX_ATTENTION_INFO1_FCS_ERR) + errmap |= DP_RX_MPDU_ERR_FCS; + + if (info & RX_ATTENTION_INFO1_DECRYPT_ERR) + errmap |= DP_RX_MPDU_ERR_DECRYPT; + + if (info & RX_ATTENTION_INFO1_TKIP_MIC_ERR) + errmap |= DP_RX_MPDU_ERR_TKIP_MIC; + + if (info & RX_ATTENTION_INFO1_A_MSDU_ERROR) + errmap |= DP_RX_MPDU_ERR_AMSDU_ERR; + + if (info & RX_ATTENTION_INFO1_OVERFLOW_ERR) + errmap |= DP_RX_MPDU_ERR_OVERFLOW; + + if (info & RX_ATTENTION_INFO1_MSDU_LEN_ERR) + errmap |= DP_RX_MPDU_ERR_MSDU_LEN; + + if (info & RX_ATTENTION_INFO1_MPDU_LEN_ERR) + errmap |= DP_RX_MPDU_ERR_MPDU_LEN; + + return errmap; +} + +int +qwx_dp_rx_h_attn_msdu_len_err(struct qwx_softc *sc, struct hal_rx_desc *desc) +{ + struct rx_attention *rx_attention; + uint32_t errmap; + + rx_attention = qwx_dp_rx_get_attention(sc, desc); + errmap = qwx_dp_rx_h_attn_mpdu_err(rx_attention); + + return errmap & DP_RX_MPDU_ERR_MSDU_LEN; +} + +int +qwx_dp_rx_msdu_coalesce(struct qwx_softc *sc, struct qwx_rx_msdu_list *msdu_list, + struct qwx_rx_msdu *first, struct qwx_rx_msdu *last, uint8_t l3pad_bytes, + int msdu_len) +{ + printf("%s: not implemented\n", __func__); + return ENOTSUP; +} + +void +qwx_dp_rx_h_rate(struct qwx_softc *sc, struct hal_rx_desc *rx_desc, + struct ieee80211_rxinfo *rxi) +{ + /* TODO */ +} + +void +qwx_dp_rx_h_ppdu(struct qwx_softc *sc, struct hal_rx_desc *rx_desc, + struct ieee80211_rxinfo *rxi) +{ + uint8_t channel_num; + uint32_t meta_data; + + meta_data = qwx_dp_rx_h_msdu_start_freq(sc, rx_desc); + channel_num = meta_data & 0xff; + + rxi->rxi_chan = channel_num; + + qwx_dp_rx_h_rate(sc, rx_desc, rxi); +} + +void +qwx_dp_rx_h_undecap_nwifi(struct qwx_softc *sc, struct qwx_rx_msdu *msdu, + uint8_t *first_hdr, enum hal_encrypt_type enctype) +{ + printf("%s: not implemented\n", __func__); +} + +void +qwx_dp_rx_h_undecap_raw(struct qwx_softc *sc, struct qwx_rx_msdu *msdu, + enum hal_encrypt_type enctype, int decrypted) +{ +#if 0 + struct ieee80211_hdr *hdr; + size_t hdr_len; + size_t crypto_len; +#endif + + if (!msdu->is_first_msdu || + !(msdu->is_first_msdu && msdu->is_last_msdu)) + return; + + m_adj(msdu->m, -IEEE80211_CRC_LEN); +#if 0 + if (!decrypted) + return; + + hdr = (void *)msdu->data; + + /* Tail */ + if (status->flag & RX_FLAG_IV_STRIPPED) { + skb_trim(msdu, msdu->len - + ath11k_dp_rx_crypto_mic_len(ar, enctype)); + + skb_trim(msdu, msdu->len - + ath11k_dp_rx_crypto_icv_len(ar, enctype)); + } else { + /* MIC */ + if (status->flag & RX_FLAG_MIC_STRIPPED) + skb_trim(msdu, msdu->len - + ath11k_dp_rx_crypto_mic_len(ar, enctype)); + + /* ICV */ + if (status->flag & RX_FLAG_ICV_STRIPPED) + skb_trim(msdu, msdu->len - + ath11k_dp_rx_crypto_icv_len(ar, enctype)); + } + + /* MMIC */ + if ((status->flag & RX_FLAG_MMIC_STRIPPED) && + !ieee80211_has_morefrags(hdr->frame_control) && + enctype == HAL_ENCRYPT_TYPE_TKIP_MIC) + skb_trim(msdu, msdu->len - IEEE80211_CCMP_MIC_LEN); + + /* Head */ + if (status->flag & RX_FLAG_IV_STRIPPED) { + hdr_len = ieee80211_hdrlen(hdr->frame_control); + crypto_len = ath11k_dp_rx_crypto_param_len(ar, enctype); + + memmove((void *)msdu->data + crypto_len, + (void *)msdu->data, hdr_len); + skb_pull(msdu, crypto_len); + } +#endif +} + +static inline uint8_t * +qwx_dp_rx_h_80211_hdr(struct qwx_softc *sc, struct hal_rx_desc *desc) +{ + return sc->hw_params.hw_ops->rx_desc_get_hdr_status(desc); +} + +static inline enum hal_encrypt_type +qwx_dp_rx_h_mpdu_start_enctype(struct qwx_softc *sc, struct hal_rx_desc *desc) +{ + if (!sc->hw_params.hw_ops->rx_desc_encrypt_valid(desc)) + return HAL_ENCRYPT_TYPE_OPEN; + + return sc->hw_params.hw_ops->rx_desc_get_encrypt_type(desc); +} + +static inline uint8_t +qwx_dp_rx_h_msdu_start_decap_type(struct qwx_softc *sc, struct hal_rx_desc *desc) +{ + return sc->hw_params.hw_ops->rx_desc_get_decap_type(desc); +} + +void +qwx_dp_rx_h_undecap(struct qwx_softc *sc, struct qwx_rx_msdu *msdu, + struct hal_rx_desc *rx_desc, enum hal_encrypt_type enctype, + int decrypted) +{ + uint8_t *first_hdr; + uint8_t decap; + + first_hdr = qwx_dp_rx_h_80211_hdr(sc, rx_desc); + decap = qwx_dp_rx_h_msdu_start_decap_type(sc, rx_desc); + + switch (decap) { + case DP_RX_DECAP_TYPE_NATIVE_WIFI: + qwx_dp_rx_h_undecap_nwifi(sc, msdu, first_hdr, enctype); + break; + case DP_RX_DECAP_TYPE_RAW: + qwx_dp_rx_h_undecap_raw(sc, msdu, enctype, decrypted); + break; +#if 0 + case DP_RX_DECAP_TYPE_ETHERNET2_DIX: + ehdr = (struct ethhdr *)msdu->data; + + /* mac80211 allows fast path only for authorized STA */ + if (ehdr->h_proto == cpu_to_be16(ETH_P_PAE)) { + ATH11K_SKB_RXCB(msdu)->is_eapol = true; + ath11k_dp_rx_h_undecap_eth(ar, msdu, first_hdr, + enctype, status); + break; + } + + /* PN for mcast packets will be validated in mac80211; + * remove eth header and add 802.11 header. + */ + if (ATH11K_SKB_RXCB(msdu)->is_mcbc && decrypted) + ath11k_dp_rx_h_undecap_eth(ar, msdu, first_hdr, + enctype, status); + break; + case DP_RX_DECAP_TYPE_8023: + /* TODO: Handle undecap for these formats */ + break; +#endif + } +} + + +void +qwx_dp_rx_h_mpdu(struct qwx_softc *sc, struct qwx_rx_msdu *msdu, + struct hal_rx_desc *rx_desc) +{ +#if 0 + bool fill_crypto_hdr; +#endif + enum hal_encrypt_type enctype; + int is_decrypted = 0; +#if 0 + struct ath11k_skb_rxcb *rxcb; + struct ieee80211_hdr *hdr; + struct ath11k_peer *peer; + struct rx_attention *rx_attention; + u32 err_bitmap; + + /* PN for multicast packets will be checked in mac80211 */ + rxcb = ATH11K_SKB_RXCB(msdu); + fill_crypto_hdr = ath11k_dp_rx_h_attn_is_mcbc(ar->ab, rx_desc); + rxcb->is_mcbc = fill_crypto_hdr; + + if (rxcb->is_mcbc) { + rxcb->peer_id = ath11k_dp_rx_h_mpdu_start_peer_id(ar->ab, rx_desc); + rxcb->seq_no = ath11k_dp_rx_h_mpdu_start_seq_no(ar->ab, rx_desc); + } + + spin_lock_bh(&ar->ab->base_lock); + peer = ath11k_dp_rx_h_find_peer(ar->ab, msdu); + if (peer) { + if (rxcb->is_mcbc) + enctype = peer->sec_type_grp; + else + enctype = peer->sec_type; + } else { +#endif + enctype = qwx_dp_rx_h_mpdu_start_enctype(sc, rx_desc); +#if 0 + } + spin_unlock_bh(&ar->ab->base_lock); + + rx_attention = ath11k_dp_rx_get_attention(ar->ab, rx_desc); + err_bitmap = ath11k_dp_rx_h_attn_mpdu_err(rx_attention); + if (enctype != HAL_ENCRYPT_TYPE_OPEN && !err_bitmap) + is_decrypted = ath11k_dp_rx_h_attn_is_decrypted(rx_attention); + + /* Clear per-MPDU flags while leaving per-PPDU flags intact */ + rx_status->flag &= ~(RX_FLAG_FAILED_FCS_CRC | + RX_FLAG_MMIC_ERROR | + RX_FLAG_DECRYPTED | + RX_FLAG_IV_STRIPPED | + RX_FLAG_MMIC_STRIPPED); + + if (err_bitmap & DP_RX_MPDU_ERR_FCS) + rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; + if (err_bitmap & DP_RX_MPDU_ERR_TKIP_MIC) + rx_status->flag |= RX_FLAG_MMIC_ERROR; + + if (is_decrypted) { + rx_status->flag |= RX_FLAG_DECRYPTED | RX_FLAG_MMIC_STRIPPED; + + if (fill_crypto_hdr) + rx_status->flag |= RX_FLAG_MIC_STRIPPED | + RX_FLAG_ICV_STRIPPED; + else + rx_status->flag |= RX_FLAG_IV_STRIPPED | + RX_FLAG_PN_VALIDATED; + } + + ath11k_dp_rx_h_csum_offload(ar, msdu); +#endif + qwx_dp_rx_h_undecap(sc, msdu, rx_desc, enctype, is_decrypted); +#if 0 + if (!is_decrypted || fill_crypto_hdr) + return; + + if (ath11k_dp_rx_h_msdu_start_decap_type(ar->ab, rx_desc) != + DP_RX_DECAP_TYPE_ETHERNET2_DIX) { + hdr = (void *)msdu->data; + hdr->frame_control &= ~__cpu_to_le16(IEEE80211_FCTL_PROTECTED); + } +#endif +} + +int +qwx_dp_rx_process_msdu(struct qwx_softc *sc, struct qwx_rx_msdu *msdu, + struct qwx_rx_msdu_list *msdu_list) +{ + struct hal_rx_desc *rx_desc, *lrx_desc; + struct rx_attention *rx_attention; + struct qwx_rx_msdu *last_buf; + uint8_t l3_pad_bytes; + uint16_t msdu_len; + int ret; + uint32_t hal_rx_desc_sz = sc->hw_params.hal_desc_sz; + + last_buf = qwx_dp_rx_get_msdu_last_buf(msdu_list, msdu); + if (!last_buf) { + DPRINTF("%s: No valid Rx buffer to access " + "Atten/MSDU_END/MPDU_END tlvs\n", __func__); + return EIO; + } + + rx_desc = mtod(msdu->m, struct hal_rx_desc *); + if (qwx_dp_rx_h_attn_msdu_len_err(sc, rx_desc)) { + DPRINTF("%s: msdu len not valid\n", __func__); + return EIO; + } + + lrx_desc = mtod(last_buf->m, struct hal_rx_desc *); + rx_attention = qwx_dp_rx_get_attention(sc, lrx_desc); + if (!qwx_dp_rx_h_attn_msdu_done(rx_attention)) { + DPRINTF("%s: msdu_done bit in attention is not set\n", + __func__); + return EIO; + } + + msdu->rx_desc = rx_desc; + msdu_len = qwx_dp_rx_h_msdu_start_msdu_len(sc, rx_desc); + l3_pad_bytes = qwx_dp_rx_h_msdu_end_l3pad(sc, lrx_desc); + + if (msdu->is_frag) { + m_adj(msdu->m, hal_rx_desc_sz); + } else if (!msdu->is_continuation) { + if ((msdu_len + hal_rx_desc_sz) > DP_RX_BUFFER_SIZE) { +#if 0 + uint8_t *hdr_status; + + hdr_status = ath11k_dp_rx_h_80211_hdr(ab, rx_desc); +#endif + DPRINTF("%s: invalid msdu len %u\n", + __func__, msdu_len); +#if 0 + ath11k_dbg_dump(ab, ATH11K_DBG_DATA, NULL, "", hdr_status, + sizeof(struct ieee80211_hdr)); + ath11k_dbg_dump(ab, ATH11K_DBG_DATA, NULL, "", rx_desc, + sizeof(struct hal_rx_desc)); +#endif + return EINVAL; + } + m_adj(msdu->m, hal_rx_desc_sz + l3_pad_bytes); + } else { + ret = qwx_dp_rx_msdu_coalesce(sc, msdu_list, msdu, last_buf, + l3_pad_bytes, msdu_len); + if (ret) { + DPRINTF("%s: failed to coalesce msdu rx buffer%d\n", + __func__, ret); + return ret; + } + } + + memset(&msdu->rxi, 0, sizeof(msdu->rxi)); + qwx_dp_rx_h_ppdu(sc, rx_desc, &msdu->rxi); + qwx_dp_rx_h_mpdu(sc, msdu, rx_desc); + + return 0; +} + +void +qwx_dp_rx_deliver_msdu(struct qwx_softc *sc, struct qwx_rx_msdu *msdu) +{ + struct ieee80211com *ic = &sc->sc_ic; + struct ifnet *ifp = &ic->ic_if; + struct ieee80211_frame *wh; + struct ieee80211_node *ni; + + wh = mtod(msdu->m, struct ieee80211_frame *); + ni = ieee80211_find_rxnode(ic, wh); + + /* TODO: bpf */ + + ieee80211_input(ifp, msdu->m, ni, &msdu->rxi); + ieee80211_release_node(ic, ni); +} + void qwx_dp_rx_process_received_packets(struct qwx_softc *sc, - struct mbuf_list *msdu_list, int mac_id) + struct qwx_rx_msdu_list *msdu_list, int mac_id) { - printf("%s: not implemented", __func__); - ml_purge(msdu_list); + struct qwx_rx_msdu *msdu; + int ret; + + while ((msdu = TAILQ_FIRST(msdu_list))) { + TAILQ_REMOVE(msdu_list, msdu, entry); + ret = qwx_dp_rx_process_msdu(sc, msdu, msdu_list); + if (ret) { + DNPRINTF(QWX_D_MAC, "Unable to process msdu: %d", ret); + m_freem(msdu->m); + msdu->m = NULL; + continue; + } + + qwx_dp_rx_deliver_msdu(sc, msdu); + msdu->m = NULL; + } } int @@ -13934,20 +15016,22 @@ qwx_dp_process_rx(struct qwx_softc *sc, int ring_id) struct qwx_pdev_dp *pdev_dp = &sc->pdev_dp; struct dp_rxdma_ring *rx_ring; int num_buffs_reaped[MAX_RADIOS] = {0}; - struct mbuf_list msdu_list[MAX_RADIOS]; + struct qwx_rx_msdu_list msdu_list[MAX_RADIOS]; + struct qwx_rx_msdu *msdu; struct mbuf *m; struct qwx_rx_data *rx_data; int total_msdu_reaped = 0; struct hal_srng *srng; int done = 0; - int idx, mac_id; + int idx; + unsigned int mac_id; struct hal_reo_dest_ring *desc; enum hal_reo_dest_ring_push_reason push_reason; uint32_t cookie; int i; for (i = 0; i < MAX_RADIOS; i++) - ml_init(&msdu_list[i]); + TAILQ_INIT(&msdu_list[i]); srng = &sc->hal.srng_list[dp->reo_dst_ring[ring_id].ring_id]; #ifdef notyet @@ -13963,6 +15047,9 @@ try_again: idx = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, cookie); mac_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_PDEV_ID, cookie); + if (mac_id >= MAX_RADIOS) + continue; + rx_ring = &pdev_dp->rx_refill_buf_ring; if (idx >= rx_ring->bufs_max) continue; @@ -13989,23 +15076,25 @@ try_again: continue; } - rx_data->is_first_msdu = !!(desc->rx_msdu_info.info0 & + msdu = &rx_data->rx_msdu; + msdu->m = m; + msdu->is_first_msdu = !!(desc->rx_msdu_info.info0 & RX_MSDU_DESC_INFO0_FIRST_MSDU_IN_MPDU); - rx_data->is_last_msdu = !!(desc->rx_msdu_info.info0 & + msdu->is_last_msdu = !!(desc->rx_msdu_info.info0 & RX_MSDU_DESC_INFO0_LAST_MSDU_IN_MPDU); - rx_data->is_continuation = !!(desc->rx_msdu_info.info0 & + msdu->is_continuation = !!(desc->rx_msdu_info.info0 & RX_MSDU_DESC_INFO0_MSDU_CONTINUATION); - rx_data->peer_id = FIELD_GET(RX_MPDU_DESC_META_DATA_PEER_ID, + msdu->peer_id = FIELD_GET(RX_MPDU_DESC_META_DATA_PEER_ID, desc->rx_mpdu_info.meta_data); - rx_data->seq_no = FIELD_GET(RX_MPDU_DESC_INFO0_SEQ_NUM, + msdu->seq_no = FIELD_GET(RX_MPDU_DESC_INFO0_SEQ_NUM, desc->rx_mpdu_info.info0); - rx_data->tid = FIELD_GET(HAL_REO_DEST_RING_INFO0_RX_QUEUE_NUM, + msdu->tid = FIELD_GET(HAL_REO_DEST_RING_INFO0_RX_QUEUE_NUM, desc->info0); - rx_data->mac_id = mac_id; - ml_enqueue(&msdu_list[mac_id], m); + msdu->mac_id = mac_id; + TAILQ_INSERT_TAIL(&msdu_list[mac_id], msdu, entry); - if (rx_data->is_continuation) { + if (msdu->is_continuation) { done = 0; } else { total_msdu_reaped++; diff --git a/sys/dev/ic/qwxreg.h b/sys/dev/ic/qwxreg.h index 604e67aaf..d5a4aab50 100644 --- a/sys/dev/ic/qwxreg.h +++ b/sys/dev/ic/qwxreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: qwxreg.h,v 1.4 2024/01/30 15:32:04 stsp Exp $ */ +/* $OpenBSD: qwxreg.h,v 1.5 2024/02/02 15:44:19 stsp Exp $ */ /* * Copyright (c) 2021-2022, Qualcomm Innovation Center, Inc. @@ -10416,6 +10416,24 @@ enum rx_desc_sw_frame_grp_id { RX_DESC_SW_FRAME_GRP_ID_PHY_ERR, }; +#define DP_MAX_NWIFI_HDR_LEN 30 + +#define DP_RX_MPDU_ERR_FCS BIT(0) +#define DP_RX_MPDU_ERR_DECRYPT BIT(1) +#define DP_RX_MPDU_ERR_TKIP_MIC BIT(2) +#define DP_RX_MPDU_ERR_AMSDU_ERR BIT(3) +#define DP_RX_MPDU_ERR_OVERFLOW BIT(4) +#define DP_RX_MPDU_ERR_MSDU_LEN BIT(5) +#define DP_RX_MPDU_ERR_MPDU_LEN BIT(6) +#define DP_RX_MPDU_ERR_UNENCRYPTED_FRAME BIT(7) + +enum dp_rx_decap_type { + DP_RX_DECAP_TYPE_RAW, + DP_RX_DECAP_TYPE_NATIVE_WIFI, + DP_RX_DECAP_TYPE_ETHERNET2_DIX, + DP_RX_DECAP_TYPE_8023, +}; + enum rx_desc_decap_type { RX_DESC_DECAP_TYPE_RAW, RX_DESC_DECAP_TYPE_NATIVE_WIFI, diff --git a/sys/dev/ic/qwxvar.h b/sys/dev/ic/qwxvar.h index 4cd17295f..ac915ac88 100644 --- a/sys/dev/ic/qwxvar.h +++ b/sys/dev/ic/qwxvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: qwxvar.h,v 1.8 2024/01/30 15:32:04 stsp Exp $ */ +/* $OpenBSD: qwxvar.h,v 1.9 2024/02/02 15:44:19 stsp Exp $ */ /* * Copyright (c) 2018-2019 The Linux Foundation. @@ -221,21 +221,27 @@ struct ath11k_hw_ops { struct hal_tcl_data_cmd *tcl_cmd); bool (*rx_desc_get_first_msdu)(struct hal_rx_desc *desc); bool (*rx_desc_get_last_msdu)(struct hal_rx_desc *desc); +#endif uint8_t (*rx_desc_get_l3_pad_bytes)(struct hal_rx_desc *desc); uint8_t *(*rx_desc_get_hdr_status)(struct hal_rx_desc *desc); - bool (*rx_desc_encrypt_valid)(struct hal_rx_desc *desc); + int (*rx_desc_encrypt_valid)(struct hal_rx_desc *desc); uint32_t (*rx_desc_get_encrypt_type)(struct hal_rx_desc *desc); uint8_t (*rx_desc_get_decap_type)(struct hal_rx_desc *desc); +#ifdef notyet uint8_t (*rx_desc_get_mesh_ctl)(struct hal_rx_desc *desc); bool (*rx_desc_get_ldpc_support)(struct hal_rx_desc *desc); bool (*rx_desc_get_mpdu_seq_ctl_vld)(struct hal_rx_desc *desc); bool (*rx_desc_get_mpdu_fc_valid)(struct hal_rx_desc *desc); uint16_t (*rx_desc_get_mpdu_start_seq_no)(struct hal_rx_desc *desc); +#endif uint16_t (*rx_desc_get_msdu_len)(struct hal_rx_desc *desc); +#ifdef notyet uint8_t (*rx_desc_get_msdu_sgi)(struct hal_rx_desc *desc); uint8_t (*rx_desc_get_msdu_rate_mcs)(struct hal_rx_desc *desc); uint8_t (*rx_desc_get_msdu_rx_bw)(struct hal_rx_desc *desc); +#endif uint32_t (*rx_desc_get_msdu_freq)(struct hal_rx_desc *desc); +#ifdef notyet uint8_t (*rx_desc_get_msdu_pkt_type)(struct hal_rx_desc *desc); uint8_t (*rx_desc_get_msdu_nss)(struct hal_rx_desc *desc); uint8_t (*rx_desc_get_mpdu_tid)(struct hal_rx_desc *desc); @@ -245,7 +251,9 @@ struct ath11k_hw_ops { uint32_t (*rx_desc_get_mpdu_start_tag)(struct hal_rx_desc *desc); uint32_t (*rx_desc_get_mpdu_ppdu_id)(struct hal_rx_desc *desc); void (*rx_desc_set_msdu_len)(struct hal_rx_desc *desc, uint16_t len); +#endif struct rx_attention *(*rx_desc_get_attention)(struct hal_rx_desc *desc); +#ifdef notyet uint8_t *(*rx_desc_get_msdu_payload)(struct hal_rx_desc *desc); #endif void (*reo_setup)(struct qwx_softc *); @@ -695,9 +703,10 @@ struct ce_attr { #define CE_DESC_RING_ALIGN 8 -struct qwx_rx_data { - struct mbuf *m; - bus_dmamap_t map; +struct qwx_rx_msdu { + TAILQ_ENTRY(qwx_rx_msdu) entry; + struct mbuf *m; + struct ieee80211_rxinfo rxi; int is_first_msdu; int is_last_msdu; int is_continuation; @@ -714,6 +723,14 @@ struct qwx_rx_data { uint16_t seq_no; }; +TAILQ_HEAD(qwx_rx_msdu_list, qwx_rx_msdu); + +struct qwx_rx_data { + struct mbuf *m; + bus_dmamap_t map; + struct qwx_rx_msdu rx_msdu; +}; + struct qwx_tx_data { struct mbuf *m; bus_dmamap_t map; diff --git a/sys/dev/pci/drm/amd/amdgpu/gfx_v10_0.c b/sys/dev/pci/drm/amd/amdgpu/gfx_v10_0.c index dc29e6c52..8e9e70319 100644 --- a/sys/dev/pci/drm/amd/amdgpu/gfx_v10_0.c +++ b/sys/dev/pci/drm/amd/amdgpu/gfx_v10_0.c @@ -3989,16 +3989,13 @@ static int gfx_v10_0_init_microcode(struct amdgpu_device *adev) if (!amdgpu_sriov_vf(adev)) { snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_rlc.bin", ucode_prefix); - err = amdgpu_ucode_request(adev, &adev->gfx.rlc_fw, fw_name); - /* don't check this. There are apparently firmwares in the wild with - * incorrect size in the header - */ - if (err == -ENODEV) - goto out; + err = request_firmware(&adev->gfx.rlc_fw, fw_name, adev->dev); if (err) - dev_dbg(adev->dev, - "gfx10: amdgpu_ucode_request() failed \"%s\"\n", - fw_name); + goto out; + + /* don't validate this firmware. There are apparently firmwares + * in the wild with incorrect size in the header + */ rlc_hdr = (const struct rlc_firmware_header_v2_0 *)adev->gfx.rlc_fw->data; version_major = le16_to_cpu(rlc_hdr->header.header_version_major); version_minor = le16_to_cpu(rlc_hdr->header.header_version_minor); @@ -6575,7 +6572,7 @@ static int gfx_v10_0_compute_mqd_init(struct amdgpu_device *adev, void *m, #ifdef __BIG_ENDIAN tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, ENDIAN_SWAP, 1); #endif - tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 0); + tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 1); tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, TUNNEL_DISPATCH, 0); tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1); tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1); diff --git a/sys/dev/pci/drm/amd/amdgpu/gfx_v11_0.c b/sys/dev/pci/drm/amd/amdgpu/gfx_v11_0.c index be073ee68..1ba804843 100644 --- a/sys/dev/pci/drm/amd/amdgpu/gfx_v11_0.c +++ b/sys/dev/pci/drm/amd/amdgpu/gfx_v11_0.c @@ -3807,7 +3807,7 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m, (order_base_2(prop->queue_size / 4) - 1)); tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, RPTR_BLOCK_SIZE, (order_base_2(AMDGPU_GPU_PAGE_SIZE / 4) - 1)); - tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 0); + tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 1); tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, TUNNEL_DISPATCH, 0); tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1); tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1); @@ -6353,6 +6353,9 @@ static int gfx_v11_0_get_cu_info(struct amdgpu_device *adev, mutex_lock(&adev->grbm_idx_mutex); for (i = 0; i < adev->gfx.config.max_shader_engines; i++) { for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) { + bitmap = i * adev->gfx.config.max_sh_per_se + j; + if (!((gfx_v11_0_get_sa_active_bitmap(adev) >> bitmap) & 1)) + continue; mask = 1; counter = 0; gfx_v11_0_select_se_sh(adev, i, j, 0xffffffff, 0); diff --git a/sys/dev/pci/drm/amd/amdkfd/kfd_mqd_manager_v10.c b/sys/dev/pci/drm/amd/amdkfd/kfd_mqd_manager_v10.c index 8b7fed913..22cbfa1bd 100644 --- a/sys/dev/pci/drm/amd/amdkfd/kfd_mqd_manager_v10.c +++ b/sys/dev/pci/drm/amd/amdkfd/kfd_mqd_manager_v10.c @@ -170,6 +170,7 @@ static void update_mqd(struct mqd_manager *mm, void *mqd, m->cp_hqd_pq_control = 5 << CP_HQD_PQ_CONTROL__RPTR_BLOCK_SIZE__SHIFT; m->cp_hqd_pq_control |= ffs(q->queue_size / sizeof(unsigned int)) - 1 - 1; + m->cp_hqd_pq_control |= CP_HQD_PQ_CONTROL__UNORD_DISPATCH_MASK; pr_debug("cp_hqd_pq_control 0x%x\n", m->cp_hqd_pq_control); m->cp_hqd_pq_base_lo = lower_32_bits((uint64_t)q->queue_address >> 8); diff --git a/sys/dev/pci/drm/amd/amdkfd/kfd_mqd_manager_v11.c b/sys/dev/pci/drm/amd/amdkfd/kfd_mqd_manager_v11.c index 15277f1d5..d722cbd31 100644 --- a/sys/dev/pci/drm/amd/amdkfd/kfd_mqd_manager_v11.c +++ b/sys/dev/pci/drm/amd/amdkfd/kfd_mqd_manager_v11.c @@ -224,6 +224,7 @@ static void update_mqd(struct mqd_manager *mm, void *mqd, m->cp_hqd_pq_control = 5 << CP_HQD_PQ_CONTROL__RPTR_BLOCK_SIZE__SHIFT; m->cp_hqd_pq_control |= ffs(q->queue_size / sizeof(unsigned int)) - 1 - 1; + m->cp_hqd_pq_control |= CP_HQD_PQ_CONTROL__UNORD_DISPATCH_MASK; pr_debug("cp_hqd_pq_control 0x%x\n", m->cp_hqd_pq_control); m->cp_hqd_pq_base_lo = lower_32_bits((uint64_t)q->queue_address >> 8); diff --git a/sys/dev/pci/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c b/sys/dev/pci/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c index cb0142f3a..f50a0d689 100644 --- a/sys/dev/pci/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +++ b/sys/dev/pci/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c @@ -956,6 +956,11 @@ int dm_helper_dmub_aux_transfer_sync( struct aux_payload *payload, enum aux_return_code_type *operation_result) { + if (!link->hpd_status) { + *operation_result = AUX_RET_ERROR_HPD_DISCON; + return -1; + } + return amdgpu_dm_process_dmub_aux_transfer_sync(ctx, link->link_index, payload, operation_result); } diff --git a/sys/dev/pci/drm/amd/display/dc/clk_mgr/dcn314/dcn314_clk_mgr.c b/sys/dev/pci/drm/amd/display/dc/clk_mgr/dcn314/dcn314_clk_mgr.c index 7326b7565..2618504e2 100644 --- a/sys/dev/pci/drm/amd/display/dc/clk_mgr/dcn314/dcn314_clk_mgr.c +++ b/sys/dev/pci/drm/amd/display/dc/clk_mgr/dcn314/dcn314_clk_mgr.c @@ -131,30 +131,27 @@ static int dcn314_get_active_display_cnt_wa( return display_count; } -static void dcn314_disable_otg_wa(struct clk_mgr *clk_mgr_base, struct dc_state *context, bool disable) +static void dcn314_disable_otg_wa(struct clk_mgr *clk_mgr_base, struct dc_state *context, + bool safe_to_lower, bool disable) { struct dc *dc = clk_mgr_base->ctx->dc; int i; for (i = 0; i < dc->res_pool->pipe_count; ++i) { - struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i]; + struct pipe_ctx *pipe = safe_to_lower + ? &context->res_ctx.pipe_ctx[i] + : &dc->current_state->res_ctx.pipe_ctx[i]; if (pipe->top_pipe || pipe->prev_odm_pipe) continue; if (pipe->stream && (pipe->stream->dpms_off || dc_is_virtual_signal(pipe->stream->signal))) { - struct stream_encoder *stream_enc = pipe->stream_res.stream_enc; - if (disable) { - if (stream_enc && stream_enc->funcs->disable_fifo) - pipe->stream_res.stream_enc->funcs->disable_fifo(stream_enc); + if (pipe->stream_res.tg && pipe->stream_res.tg->funcs->immediate_disable_crtc) + pipe->stream_res.tg->funcs->immediate_disable_crtc(pipe->stream_res.tg); - pipe->stream_res.tg->funcs->immediate_disable_crtc(pipe->stream_res.tg); reset_sync_context_for_pipe(dc, context, i); } else { pipe->stream_res.tg->funcs->enable_crtc(pipe->stream_res.tg); - - if (stream_enc && stream_enc->funcs->enable_fifo) - pipe->stream_res.stream_enc->funcs->enable_fifo(stream_enc); } } } @@ -252,11 +249,11 @@ void dcn314_update_clocks(struct clk_mgr *clk_mgr_base, } if (should_set_clock(safe_to_lower, new_clocks->dispclk_khz, clk_mgr_base->clks.dispclk_khz)) { - dcn314_disable_otg_wa(clk_mgr_base, context, true); + dcn314_disable_otg_wa(clk_mgr_base, context, safe_to_lower, true); clk_mgr_base->clks.dispclk_khz = new_clocks->dispclk_khz; dcn314_smu_set_dispclk(clk_mgr, clk_mgr_base->clks.dispclk_khz); - dcn314_disable_otg_wa(clk_mgr_base, context, false); + dcn314_disable_otg_wa(clk_mgr_base, context, safe_to_lower, false); update_dispclk = true; } diff --git a/sys/dev/pci/drm/amd/display/dc/link/link_dpms.c b/sys/dev/pci/drm/amd/display/dc/link/link_dpms.c index f2f3ba15b..87a2f12ae 100644 --- a/sys/dev/pci/drm/amd/display/dc/link/link_dpms.c +++ b/sys/dev/pci/drm/amd/display/dc/link/link_dpms.c @@ -873,11 +873,15 @@ bool link_set_dsc_pps_packet(struct pipe_ctx *pipe_ctx, bool enable, bool immedi { struct display_stream_compressor *dsc = pipe_ctx->stream_res.dsc; struct dc_stream_state *stream = pipe_ctx->stream; - DC_LOGGER_INIT(dsc->ctx->logger); - if (!pipe_ctx->stream->timing.flags.DSC || !dsc) + if (!pipe_ctx->stream->timing.flags.DSC) return false; + if (!dsc) + return false; + + DC_LOGGER_INIT(dsc->ctx->logger); + if (enable) { struct dsc_config dsc_cfg; uint8_t dsc_packed_pps[128]; diff --git a/sys/dev/pci/drm/amd/display/dc/link/protocols/link_dpcd.c b/sys/dev/pci/drm/amd/display/dc/link/protocols/link_dpcd.c index 5c9a30211..fc50931c2 100644 --- a/sys/dev/pci/drm/amd/display/dc/link/protocols/link_dpcd.c +++ b/sys/dev/pci/drm/amd/display/dc/link/protocols/link_dpcd.c @@ -205,7 +205,7 @@ enum dc_status core_link_read_dpcd( uint32_t extended_size; /* size of the remaining partitioned address space */ uint32_t size_left_to_read; - enum dc_status status; + enum dc_status status = DC_ERROR_UNEXPECTED; /* size of the next partition to be read from */ uint32_t partition_size; uint32_t data_index = 0; @@ -234,7 +234,7 @@ enum dc_status core_link_write_dpcd( { uint32_t partition_size; uint32_t data_index = 0; - enum dc_status status; + enum dc_status status = DC_ERROR_UNEXPECTED; while (size) { partition_size = dpcd_get_next_partition_size(address, size); diff --git a/sys/dev/pci/drm/amd/display/dc/link/protocols/link_edp_panel_control.c b/sys/dev/pci/drm/amd/display/dc/link/protocols/link_edp_panel_control.c index 13c3d7ff6..6f64aab18 100644 --- a/sys/dev/pci/drm/amd/display/dc/link/protocols/link_edp_panel_control.c +++ b/sys/dev/pci/drm/amd/display/dc/link/protocols/link_edp_panel_control.c @@ -920,8 +920,8 @@ bool edp_get_replay_state(const struct dc_link *link, uint64_t *state) bool edp_setup_replay(struct dc_link *link, const struct dc_stream_state *stream) { /* To-do: Setup Replay */ - struct dc *dc = link->ctx->dc; - struct dmub_replay *replay = dc->res_pool->replay; + struct dc *dc; + struct dmub_replay *replay; int i; unsigned int panel_inst; struct replay_context replay_context = { 0 }; @@ -937,6 +937,10 @@ bool edp_setup_replay(struct dc_link *link, const struct dc_stream_state *stream if (!link) return false; + dc = link->ctx->dc; + + replay = dc->res_pool->replay; + if (!replay) return false; @@ -965,8 +969,7 @@ bool edp_setup_replay(struct dc_link *link, const struct dc_stream_state *stream replay_context.line_time_in_ns = lineTimeInNs; - if (replay) - link->replay_settings.replay_feature_enabled = + link->replay_settings.replay_feature_enabled = replay->funcs->replay_copy_settings(replay, link, &replay_context, panel_inst); if (link->replay_settings.replay_feature_enabled) { diff --git a/sys/dev/pci/drm/amd/pm/swsmu/amdgpu_smu.c b/sys/dev/pci/drm/amd/pm/swsmu/amdgpu_smu.c index 69ce82244..7c4a436de 100644 --- a/sys/dev/pci/drm/amd/pm/swsmu/amdgpu_smu.c +++ b/sys/dev/pci/drm/amd/pm/swsmu/amdgpu_smu.c @@ -24,6 +24,7 @@ #include #include +#include #include #include "amdgpu.h" @@ -741,16 +742,8 @@ static int smu_late_init(void *handle) * handle the switch automatically. Driver involvement * is unnecessary. */ - if (!smu->dc_controlled_by_gpio) { - ret = smu_set_power_source(smu, - adev->pm.ac_power ? SMU_POWER_SOURCE_AC : - SMU_POWER_SOURCE_DC); - if (ret) { - dev_err(adev->dev, "Failed to switch to %s mode!\n", - adev->pm.ac_power ? "AC" : "DC"); - return ret; - } - } + adev->pm.ac_power = power_supply_is_system_supplied() > 0; + smu_set_ac_dc(smu); if ((adev->ip_versions[MP1_HWIP][0] == IP_VERSION(13, 0, 1)) || (adev->ip_versions[MP1_HWIP][0] == IP_VERSION(13, 0, 3))) diff --git a/sys/dev/pci/drm/amd/pm/swsmu/smu11/smu_v11_0.c b/sys/dev/pci/drm/amd/pm/swsmu/smu11/smu_v11_0.c index a447351a4..0a46bff17 100644 --- a/sys/dev/pci/drm/amd/pm/swsmu/smu11/smu_v11_0.c +++ b/sys/dev/pci/drm/amd/pm/swsmu/smu11/smu_v11_0.c @@ -1441,10 +1441,12 @@ static int smu_v11_0_irq_process(struct amdgpu_device *adev, case 0x3: dev_dbg(adev->dev, "Switched to AC mode!\n"); schedule_work(&smu->interrupt_work); + adev->pm.ac_power = true; break; case 0x4: dev_dbg(adev->dev, "Switched to DC mode!\n"); schedule_work(&smu->interrupt_work); + adev->pm.ac_power = false; break; case 0x7: /* diff --git a/sys/dev/pci/drm/amd/pm/swsmu/smu13/smu_v13_0.c b/sys/dev/pci/drm/amd/pm/swsmu/smu13/smu_v13_0.c index ecc687ac8..8f9e44143 100644 --- a/sys/dev/pci/drm/amd/pm/swsmu/smu13/smu_v13_0.c +++ b/sys/dev/pci/drm/amd/pm/swsmu/smu13/smu_v13_0.c @@ -1377,10 +1377,12 @@ static int smu_v13_0_irq_process(struct amdgpu_device *adev, case 0x3: dev_dbg(adev->dev, "Switched to AC mode!\n"); smu_v13_0_ack_ac_dc_interrupt(smu); + adev->pm.ac_power = true; break; case 0x4: dev_dbg(adev->dev, "Switched to DC mode!\n"); smu_v13_0_ack_ac_dc_interrupt(smu); + adev->pm.ac_power = false; break; case 0x7: /* diff --git a/sys/dev/pci/drm/drm_damage_helper.c b/sys/dev/pci/drm/drm_damage_helper.c index d8b2955e8..afb02aae7 100644 --- a/sys/dev/pci/drm/drm_damage_helper.c +++ b/sys/dev/pci/drm/drm_damage_helper.c @@ -241,7 +241,8 @@ drm_atomic_helper_damage_iter_init(struct drm_atomic_helper_damage_iter *iter, iter->plane_src.x2 = (src.x2 >> 16) + !!(src.x2 & 0xFFFF); iter->plane_src.y2 = (src.y2 >> 16) + !!(src.y2 & 0xFFFF); - if (!iter->clips || !drm_rect_equals(&state->src, &old_state->src)) { + if (!iter->clips || state->ignore_damage_clips || + !drm_rect_equals(&state->src, &old_state->src)) { iter->clips = NULL; iter->num_clips = 0; iter->full_update = true; diff --git a/sys/dev/pci/drm/drm_plane.c b/sys/dev/pci/drm/drm_plane.c index 24e7998d1..311e17990 100644 --- a/sys/dev/pci/drm/drm_plane.c +++ b/sys/dev/pci/drm/drm_plane.c @@ -678,6 +678,19 @@ int drm_mode_getplane_res(struct drm_device *dev, void *data, !file_priv->universal_planes) continue; + /* + * If we're running on a virtualized driver then, + * unless userspace advertizes support for the + * virtualized cursor plane, disable cursor planes + * because they'll be broken due to missing cursor + * hotspot info. + */ + if (plane->type == DRM_PLANE_TYPE_CURSOR && + drm_core_check_feature(dev, DRIVER_CURSOR_HOTSPOT) && + file_priv->atomic && + !file_priv->supports_virtualized_cursor_plane) + continue; + if (drm_lease_held(file_priv, plane->base.id)) { if (count < plane_resp->count_planes && put_user(plane->base.id, plane_ptr + count)) @@ -1387,6 +1400,7 @@ retry: out: if (fb) drm_framebuffer_put(fb); + fb = NULL; if (plane->old_fb) drm_framebuffer_put(plane->old_fb); plane->old_fb = NULL; diff --git a/sys/dev/pci/drm/i915/display/icl_dsi.c b/sys/dev/pci/drm/i915/display/icl_dsi.c index 336bc2210..89b7c604a 100644 --- a/sys/dev/pci/drm/i915/display/icl_dsi.c +++ b/sys/dev/pci/drm/i915/display/icl_dsi.c @@ -1155,6 +1155,7 @@ static void gen11_dsi_powerup_panel(struct intel_encoder *encoder) } intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP); + intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON); /* ensure all panel commands dispatched before enabling transcoder */ wait_for_cmds_dispatched_to_panel(encoder); @@ -1255,8 +1256,6 @@ static void gen11_dsi_enable(struct intel_atomic_state *state, /* step6d: enable dsi transcoder */ gen11_dsi_enable_transcoder(encoder); - intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON); - /* step7: enable backlight */ intel_backlight_enable(crtc_state, conn_state); intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON); diff --git a/sys/dev/pci/drm/i915/display/intel_psr.c b/sys/dev/pci/drm/i915/display/intel_psr.c index 471b3880e..702c6a80c 100644 --- a/sys/dev/pci/drm/i915/display/intel_psr.c +++ b/sys/dev/pci/drm/i915/display/intel_psr.c @@ -674,7 +674,9 @@ static void hsw_activate_psr1(struct intel_dp *intel_dp) val |= EDP_PSR_IDLE_FRAMES(psr_compute_idle_frames(intel_dp)); - val |= EDP_PSR_MAX_SLEEP_TIME(max_sleep_time); + if (DISPLAY_VER(dev_priv) < 20) + val |= EDP_PSR_MAX_SLEEP_TIME(max_sleep_time); + if (IS_HASWELL(dev_priv)) val |= EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES; @@ -1398,9 +1400,21 @@ static void intel_psr_enable_source(struct intel_dp *intel_dp, * can rely on frontbuffer tracking. */ mask = EDP_PSR_DEBUG_MASK_MEMUP | - EDP_PSR_DEBUG_MASK_HPD | - EDP_PSR_DEBUG_MASK_LPSP | - EDP_PSR_DEBUG_MASK_MAX_SLEEP; + EDP_PSR_DEBUG_MASK_HPD; + + /* + * For some unknown reason on HSW non-ULT (or at least on + * Dell Latitude E6540) external displays start to flicker + * when PSR is enabled on the eDP. SR/PC6 residency is much + * higher than should be possible with an external display. + * As a workaround leave LPSP unmasked to prevent PSR entry + * when external displays are active. + */ + if (DISPLAY_VER(dev_priv) >= 8 || IS_HASWELL_ULT(dev_priv)) + mask |= EDP_PSR_DEBUG_MASK_LPSP; + + if (DISPLAY_VER(dev_priv) < 20) + mask |= EDP_PSR_DEBUG_MASK_MAX_SLEEP; /* * No separate pipe reg write mask on hsw/bdw, so have to unmask all diff --git a/sys/dev/pci/drm/include/drm/drm_drv.h b/sys/dev/pci/drm/include/drm/drm_drv.h index 89d7dcb54..5c855a1bc 100644 --- a/sys/dev/pci/drm/include/drm/drm_drv.h +++ b/sys/dev/pci/drm/include/drm/drm_drv.h @@ -112,6 +112,15 @@ enum drm_driver_feature { * Driver supports user defined GPU VA bindings for GEM objects. */ DRIVER_GEM_GPUVA = BIT(8), + /** + * @DRIVER_CURSOR_HOTSPOT: + * + * Driver supports and requires cursor hotspot information in the + * cursor plane (e.g. cursor plane has to actually track the mouse + * cursor and the clients are required to set hotspot in order for + * the cursor planes to work correctly). + */ + DRIVER_CURSOR_HOTSPOT = BIT(9), /* IMPORTANT: Below are all the legacy flags, add new ones above. */ diff --git a/sys/dev/pci/drm/include/drm/drm_file.h b/sys/dev/pci/drm/include/drm/drm_file.h index 7d5259aef..6e966a8e8 100644 --- a/sys/dev/pci/drm/include/drm/drm_file.h +++ b/sys/dev/pci/drm/include/drm/drm_file.h @@ -231,6 +231,18 @@ struct drm_file { */ bool is_master; + /** + * @supports_virtualized_cursor_plane: + * + * This client is capable of handling the cursor plane with the + * restrictions imposed on it by the virtualized drivers. + * + * This implies that the cursor plane has to behave like a cursor + * i.e. track cursor movement. It also requires setting of the + * hotspot properties by the client on the cursor plane. + */ + bool supports_virtualized_cursor_plane; + /** * @master: * diff --git a/sys/dev/pci/drm/include/drm/drm_plane.h b/sys/dev/pci/drm/include/drm/drm_plane.h index 79d62856d..fef775200 100644 --- a/sys/dev/pci/drm/include/drm/drm_plane.h +++ b/sys/dev/pci/drm/include/drm/drm_plane.h @@ -190,6 +190,16 @@ struct drm_plane_state { */ struct drm_property_blob *fb_damage_clips; + /** + * @ignore_damage_clips: + * + * Set by drivers to indicate the drm_atomic_helper_damage_iter_init() + * helper that the @fb_damage_clips blob property should be ignored. + * + * See :ref:`damage_tracking_properties` for more information. + */ + bool ignore_damage_clips; + /** * @src: * diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 36ff7553a..fd6417eea 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.288 2024/01/31 12:27:57 bluhm Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.289 2024/02/02 15:39:23 bluhm Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -911,7 +911,7 @@ in_pcbrtentry(struct inpcb *inp) #ifdef INET6 if (ISSET(inp->inp_flags, INP_IPV6)) - in6_pcbrtentry(inp); + return in6_pcbrtentry(inp); #endif ro = &inp->inp_route; diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 17d357c59..d36bcb39f 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.620 2024/01/30 13:50:09 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.622 2024/02/03 00:11:34 jsg Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -2484,7 +2484,7 @@ rde_update_err(struct rde_peer *peer, uint8_t error, uint8_t suberr, fatal("%s %d imsg_add error", __func__, __LINE__); if (opt != NULL) if (ibuf_add_ibuf(wbuf, opt) == -1) - fatal("%s %d imsg_add error", __func__, __LINE__); + fatal("%s %d ibuf_add_ibuf error", __func__, __LINE__); imsg_close(ibuf_se, wbuf); peer->state = PEER_ERR; } @@ -4244,8 +4244,7 @@ rde_peer_send_eor(struct rde_peer *peer, uint8_t aid) if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id, 0, -1, &buf, 10) == -1) - fatal("%s %d imsg_compose error in peer_send_eor", - __func__, __LINE__); + fatal("%s %d imsg_compose error", __func__, __LINE__); } log_peer_info(&peer->conf, "sending %s EOR marker", @@ -4274,6 +4273,7 @@ rde_peer_send_rrefresh(struct rde_peer *peer, uint8_t aid, uint8_t subtype) if (imsg_compose(ibuf_se, IMSG_REFRESH, peer->conf.id, 0, -1, &rr, sizeof(rr)) == -1) + fatal("%s %d imsg_compose error", __func__, __LINE__); log_peer_info(&peer->conf, "sending %s %s marker", aid2str(aid), subtype == ROUTE_REFRESH_END_RR ? "EoRR" : "BoRR"); diff --git a/usr.sbin/bgpd/util.c b/usr.sbin/bgpd/util.c index f3b08f945..eb9b61080 100644 --- a/usr.sbin/bgpd/util.c +++ b/usr.sbin/bgpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.80 2024/01/30 13:50:09 claudio Exp $ */ +/* $OpenBSD: util.c,v 1.81 2024/02/02 16:14:51 claudio Exp $ */ /* * Copyright (c) 2006 Claudio Jeker @@ -547,8 +547,12 @@ aspath_inflate(struct ibuf *in) uint16_t short_as; uint8_t seg_type, seg_len; - /* allocate enough space for the worst case */ - if ((out = ibuf_open(ibuf_size(in) * 2)) == NULL) + /* + * Allocate enough space for the worst case. + * XXX add 1 byte for the empty ASPATH case since we can't + * allocate an ibuf of 0 length. + */ + if ((out = ibuf_open(ibuf_size(in) * 2 + 1)) == NULL) return (NULL); /* then copy the aspath */ diff --git a/usr.sbin/rpki-client/mft.c b/usr.sbin/rpki-client/mft.c index a98e6ac33..57323f0a5 100644 --- a/usr.sbin/rpki-client/mft.c +++ b/usr.sbin/rpki-client/mft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mft.c,v 1.102 2024/01/31 06:57:21 tb Exp $ */ +/* $OpenBSD: mft.c,v 1.103 2024/02/02 19:26:49 job Exp $ */ /* * Copyright (c) 2022 Theo Buehler * Copyright (c) 2019 Kristaps Dzonsons @@ -301,16 +301,6 @@ mft_parse_econtent(const unsigned char *d, size_t dsz, struct parse *p) if (p->res->seqnum == NULL) goto out; - /* - * Timestamps: this and next update time. - * Validate that the current date falls into this interval. - * This is required by section 4.4, (3). - * If we're after the given date, then the MFT is stale. - * This is made super complicated because it uses OpenSSL's - * ASN1_GENERALIZEDTIME instead of ASN1_TIME, which we could - * compare against the current time trivially. - */ - if (!mft_parse_time(mft->thisUpdate, mft->nextUpdate, p)) goto out; diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c index 0ee6b97a2..529c3a90b 100644 --- a/usr.sbin/rpki-client/parser.c +++ b/usr.sbin/rpki-client/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.114 2024/02/01 09:50:15 tb Exp $ */ +/* $OpenBSD: parser.c,v 1.126 2024/02/02 22:09:56 tb Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -169,6 +169,9 @@ proc_parser_mft_check(const char *fn, struct mft *p) int rc = 1; char *path; + if (p == NULL) + return 0; + for (i = 0; i < p->filesz; i++) { struct mftfile *m = &p->files[i]; int try, fd = -1, noent = 0, valid = 0; @@ -251,44 +254,43 @@ parse_load_crl_from_mft(struct entity *entp, struct mft *mft, enum location loc, } /* - * Parse and validate a manifest file. Skip checking the fileandhash - * this is done in the post check. After this step we know the mft is - * valid and can be compared. - * Return the mft on success or NULL on failure. + * Parse and validate a manifest file. + * Don't check the fileandhash, this is done later on. + * Return the mft on success, or NULL on failure. */ static struct mft * -proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, - struct crl **crl, char **crlfile, struct mft *cached_mft, - const char **errstr) +proc_parser_mft_pre(struct entity *entp, char *file, struct crl **crl, + char **crlfile, struct mft *cached_mft, const char **errstr) { struct mft *mft; X509 *x509; struct auth *a; unsigned char *der; size_t len; + time_t now; int issued_cmp, seqnum_cmp; *crl = NULL; *crlfile = NULL; *errstr = NULL; - /* XXX - pull this into proc_parser_mft. */ - *file = parse_filepath(entp->repoid, entp->path, entp->file, loc); - if (*file == NULL) + if (file == NULL) return NULL; - if (noop && loc == DIR_TEMP) - return NULL; - - der = load_file(*file, &len); + der = load_file(file, &len); if (der == NULL && errno != ENOENT) - warn("parse file %s", *file); + warn("parse file %s", file); - if ((mft = mft_parse(&x509, *file, entp->talid, der, len)) == NULL) { + if ((mft = mft_parse(&x509, file, entp->talid, der, len)) == NULL) { free(der); return NULL; } + if (entp->path != NULL) { + if ((mft->path = strdup(entp->path)) == NULL) + err(1, NULL); + } + if (!EVP_Digest(der, len, mft->mfthash, NULL, EVP_sha256(), NULL)) errx(1, "EVP_Digest failed"); @@ -298,8 +300,8 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, if (*crl == NULL) *crl = parse_load_crl_from_mft(entp, mft, DIR_VALID, crlfile); - a = valid_ski_aki(*file, &auths, mft->ski, mft->aki, NULL); - if (!valid_x509(*file, ctx, x509, a, *crl, errstr)) + a = valid_ski_aki(file, &auths, mft->ski, mft->aki, NULL); + if (!valid_x509(file, ctx, x509, a, *crl, errstr)) goto err; X509_free(x509); x509 = NULL; @@ -307,6 +309,21 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, mft->repoid = entp->repoid; mft->talid = a->cert->talid; + now = get_current_time(); + /* check that now is not before from */ + if (now < mft->thisupdate) { + warnx("%s: manifest not yet valid %s", file, + time2str(mft->thisupdate)); + mft->stale = 1; + } + /* check that now is not after until */ + if (now > mft->nextupdate) { + warnx("%s: manifest expired on %s", file, + time2str(mft->nextupdate)); + mft->stale = 1; + } + + /* if there is nothing to compare to, return now */ if (cached_mft == NULL) return mft; @@ -316,33 +333,33 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, */ if ((issued_cmp = mft_compare_issued(mft, cached_mft)) < 0) { - warnx("%s: unexpected manifest issuance time (want >= %lld, " - "got %lld)", *file, (long long)cached_mft->thisupdate, + warnx("%s: unexpected manifest issuance date (want >= %lld, " + "got %lld)", file, (long long)cached_mft->thisupdate, (long long)mft->thisupdate); goto err; } if ((seqnum_cmp = mft_compare_seqnum(mft, cached_mft)) < 0) { warnx("%s: unexpected manifest number (want >= #%s, got #%s)", - *file, cached_mft->seqnum, mft->seqnum); + file, cached_mft->seqnum, mft->seqnum); goto err; } if (issued_cmp > 0 && seqnum_cmp == 0) { - warnx("%s#%s: manifest issued at %lld and %lld with same " - "sequence number", *file, cached_mft->seqnum, - (long long)mft->thisupdate, - (long long)cached_mft->thisupdate); + warnx("%s: manifest issued at %lld and %lld with same " + "manifest number #%s", file, (long long)mft->thisupdate, + (long long)cached_mft->thisupdate, cached_mft->seqnum); goto err; } if (issued_cmp == 0 && seqnum_cmp > 0) { - warnx("%s#%s: reissued manifest same issuance time %lld as #%s", - *file, mft->seqnum, (long long)mft->thisupdate, - cached_mft->seqnum); + warnx("%s: #%s and #%s were issued at same issuance date %lld", + file, mft->seqnum, cached_mft->seqnum, + (long long)mft->thisupdate); goto err; } if (issued_cmp == 0 && seqnum_cmp == 0 && memcmp(mft->mfthash, cached_mft->mfthash, SHA256_DIGEST_LENGTH) != 0) { - warnx("%s: manifest misissuance, #%s was recycled", - *file, mft->seqnum); + warnx("%s: misissuance, issuance date %lld and manifest number " + "#%s were recycled", file, (long long)mft->thisupdate, + mft->seqnum); goto err; } @@ -358,52 +375,6 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, return NULL; } -/* - * Do the end of manifest validation. - * Return the mft on success or NULL on failure. - */ -static struct mft * -proc_parser_mft_post(char *file, struct mft *mft, const char *path, - const char *errstr, int *warned) -{ - /* check that now is not before from */ - time_t now = get_current_time(); - - if (mft == NULL) { - if (errstr == NULL) - errstr = "no valid mft available"; - if ((*warned)++ > 0) - return NULL; - warnx("%s: %s", file, errstr); - return NULL; - } - - /* check that now is not before from */ - if (now < mft->thisupdate) { - warnx("%s: mft not yet valid %s", file, - time2str(mft->thisupdate)); - mft->stale = 1; - } - /* check that now is not after until */ - if (now > mft->nextupdate) { - warnx("%s: mft expired on %s", file, - time2str(mft->nextupdate)); - mft->stale = 1; - } - - if (path != NULL) - if ((mft->path = strdup(path)) == NULL) - err(1, NULL); - - if (!mft->stale) - if (!proc_parser_mft_check(file, mft)) { - mft_free(mft); - return NULL; - } - - return mft; -} - /* * Load the most recent MFT by opening both options and comparing the two. */ @@ -412,49 +383,51 @@ proc_parser_mft(struct entity *entp, struct mft **mp, char **crlfile, time_t *crlmtime) { struct mft *mft1 = NULL, *mft2 = NULL; - struct crl *crl, *crl1, *crl2; - char *file, *file1, *file2, *crl1file, *crl2file; - const char *err1, *err2; - int warned = 0; + struct crl *crl, *crl1 = NULL, *crl2 = NULL; + char *file, *file1 = NULL, *file2 = NULL; + char *crl1file = NULL, *crl2file = NULL; + const char *err1 = NULL, *err2 = NULL; *mp = NULL; *crlmtime = 0; - mft2 = proc_parser_mft_pre(entp, DIR_VALID, &file2, &crl2, &crl2file, - NULL, &err2); - mft1 = proc_parser_mft_pre(entp, DIR_TEMP, &file1, &crl1, &crl1file, - mft2, &err1); + file2 = parse_filepath(entp->repoid, entp->path, entp->file, DIR_VALID); + mft2 = proc_parser_mft_pre(entp, file2, &crl2, &crl2file, NULL, &err2); - /* overload error from temp file if it is set */ - if (mft1 == NULL && mft2 == NULL) - if (err1 != NULL) - err2 = err1; - - if (!noop && mft1 != NULL) { - *mp = proc_parser_mft_post(file1, mft1, entp->path, err1, - &warned); - if (*mp == NULL) { - mft1 = NULL; - if (mft2 != NULL) - warnx("%s: failed fetch, continuing with #%s" - " from cache", file2, mft2->seqnum); - } + if (!noop) { + file1 = parse_filepath(entp->repoid, entp->path, entp->file, + DIR_TEMP); + mft1 = proc_parser_mft_pre(entp, file1, &crl1, &crl1file, mft2, + &err1); } - if (*mp != NULL) { + if (proc_parser_mft_check(file1, mft1)) { mft_free(mft2); crl_free(crl2); free(crl2file); free(file2); + *mp = mft1; crl = crl1; file = file1; *crlfile = crl1file; } else { - if (err2 == NULL) - err2 = err1; - *mp = proc_parser_mft_post(file2, mft2, entp->path, err2, - &warned); + if (mft1 != NULL && mft2 != NULL) + warnx("%s: failed fetch, continuing with #%s " + "from cache", file2, mft2->seqnum); + + if (proc_parser_mft_check(file2, mft2)) { + *mp = mft2; + } else { + mft_free(mft2); + mft2 = NULL; + + if (err2 == NULL) + err2 = err1; + if (err2 == NULL) + err2 = "no valid manifest available"; + warnx("%s: %s", file2, err2); + } mft_free(mft1); crl_free(crl1); diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c index 60429999a..cf11dfe3f 100644 --- a/usr.sbin/smtpd/lka_session.c +++ b/usr.sbin/smtpd/lka_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_session.c,v 1.98 2023/11/03 13:40:07 op Exp $ */ +/* $OpenBSD: lka_session.c,v 1.100 2024/02/02 23:33:42 gilles Exp $ */ /* * Copyright (c) 2011 Gilles Chehade @@ -397,6 +397,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) break; } xn->realuser = 1; + xn->realuser_uid = lk.userinfo.uid; if (xn->sameuser && xn->parent->forwarded) { log_trace(TRACE_EXPAND, "expand: lka_expand: same " @@ -405,6 +406,20 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) break; } + + /* when alternate delivery user is provided, + * skip other users forward files. + */ + if (dsp->u.local.user) { + if (strcmp(dsp->u.local.user, xn->u.user) != 0) { + log_trace(TRACE_EXPAND, "expand: lka_expand: " + "alternate delivery user mismatch recipient " + "user, skip .forward, submitting"); + lka_submit(lks, rule, xn); + break; + } + } + /* no aliases found, query forward file */ lks->rule = rule; lks->node = xn; @@ -423,6 +438,12 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) break; case EXPAND_FILENAME: + if (xn->parent->realuser && xn->parent->realuser_uid == 0) { + log_trace(TRACE_EXPAND, "expand: filename not allowed in root's forward"); + lks->error = LKA_TEMPFAIL; + break; + } + dsp = dict_xget(env->sc_dispatchers, rule->dispatcher); if (dsp->u.local.forward_only) { log_trace(TRACE_EXPAND, "expand: filename matched on forward-only rule"); @@ -451,6 +472,12 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) break; case EXPAND_FILTER: + if (xn->parent->realuser && xn->parent->realuser_uid == 0) { + log_trace(TRACE_EXPAND, "expand: filter not allowed in root's forward"); + lks->error = LKA_TEMPFAIL; + break; + } + dsp = dict_xget(env->sc_dispatchers, rule->dispatcher); if (dsp->u.local.forward_only) { log_trace(TRACE_EXPAND, "expand: filter matched on forward-only rule"); diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index b4705f942..f6d44673d 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.296 2023/12/03 11:52:16 op Exp $ */ +/* $OpenBSD: parse.y,v 1.297 2024/02/02 20:54:27 millert Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -697,12 +697,10 @@ MBOX { | LMTP STRING { asprintf(&dsp->u.local.command, "/usr/libexec/mail.lmtp -d %s -u", $2); - dsp->u.local.user = SMTPD_USER; } dispatcher_local_options | LMTP STRING RCPT_TO { asprintf(&dsp->u.local.command, "/usr/libexec/mail.lmtp -d %s -r", $2); - dsp->u.local.user = SMTPD_USER; } dispatcher_local_options | MDA STRING { asprintf(&dsp->u.local.command, diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index cc9ad7a17..f7965b534 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.347 2024/01/20 09:01:03 claudio Exp $ */ +/* $OpenBSD: smtpd.c,v 1.348 2024/02/02 22:02:12 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -1425,16 +1425,9 @@ forkmda(struct mproc *p, uint64_t id, struct deliver *deliver) pw_dir = deliver->userinfo.directory; } - if (pw_uid == 0 && deliver->mda_exec[0]) { - pw_name = deliver->userinfo.username; - pw_uid = deliver->userinfo.uid; - pw_gid = deliver->userinfo.gid; - pw_dir = deliver->userinfo.directory; - } - - if (pw_uid == 0 && !dsp->u.local.is_mbox) { - (void)snprintf(ebuf, sizeof ebuf, "not allowed to deliver to: %s", - deliver->userinfo.username); + if (pw_uid == 0 && (!dsp->u.local.is_mbox || deliver->mda_exec[0])) { + (void)snprintf(ebuf, sizeof ebuf, "MDA not allowed to deliver to: %s", + deliver->userinfo.username); m_create(p_dispatcher, IMSG_MDA_DONE, 0, 0, -1); m_add_id(p_dispatcher, id); m_add_int(p_dispatcher, MDA_PERMFAIL); diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 5e1b16b6a..a0e8add90 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.680 2024/01/03 08:11:15 op Exp $ */ +/* $OpenBSD: smtpd.h,v 1.681 2024/02/02 22:02:12 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -428,6 +428,7 @@ struct expandnode { enum expand_type type; int sameuser; int realuser; + uid_t realuser_uid; int forwarded; struct rule *rule; struct expandnode *parent; diff --git a/usr.sbin/tcpdump/print-snmp.c b/usr.sbin/tcpdump/print-snmp.c index fe62607ca..c3e74537c 100644 --- a/usr.sbin/tcpdump/print-snmp.c +++ b/usr.sbin/tcpdump/print-snmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-snmp.c,v 1.28 2021/10/23 10:47:50 martijn Exp $ */ +/* $OpenBSD: print-snmp.c,v 1.29 2024/02/03 00:20:21 jsg Exp $ */ /* * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 @@ -746,7 +746,7 @@ asn1_print(struct be *elem) Class[CONTEXT].Id[elem->id], elem->asnlen); break; case BE_VB: - if (elem->id > sizeof(ContextVarbind)/sizeof(ContextVarbind[0])) + if (elem->id >= sizeof(ContextVarbind)/sizeof(ContextVarbind[0])) break; printf("%s", ContextVarbind[elem->id]); break; diff --git a/usr.sbin/vmd/vioblk.c b/usr.sbin/vmd/vioblk.c index 4dbd7f129..427fdea43 100644 --- a/usr.sbin/vmd/vioblk.c +++ b/usr.sbin/vmd/vioblk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vioblk.c,v 1.9 2023/09/26 01:53:54 dv Exp $ */ +/* $OpenBSD: vioblk.c,v 1.10 2024/02/03 00:28:07 jsg Exp $ */ /* * Copyright (c) 2023 Dave Voutila @@ -67,7 +67,7 @@ __dead void vioblk_main(int fd, int fd_vmm) { struct virtio_dev dev; - struct vioblk_dev *vioblk; + struct vioblk_dev *vioblk = NULL; struct viodev_msg msg; struct vmd_vm vm; struct vm_create_params *vcp; @@ -210,7 +210,7 @@ vioblk_main(int fd, int fd_vmm) /* Clean shutdown. */ close_fd(dev.sync_fd); close_fd(dev.async_fd); - for (i = 0; i < (int)sizeof(vioblk->disk_fd); i++) + for (i = 0; i < vioblk->ndisk_fd; i++) close_fd(vioblk->disk_fd[i]); _exit(0); /* NOTREACHED */ @@ -227,8 +227,10 @@ fail: close_fd(dev.sync_fd); close_fd(dev.async_fd); - for (i = 0; i < (int)sizeof(vioblk->disk_fd); i++) - close_fd(vioblk->disk_fd[i]); + if (vioblk != NULL) { + for (i = 0; i < vioblk->ndisk_fd; i++) + close_fd(vioblk->disk_fd[i]); + } _exit(ret); /* NOTREACHED */ } diff --git a/usr.sbin/vmd/vm_agentx.c b/usr.sbin/vmd/vm_agentx.c index a79f09a4c..af80964d6 100644 --- a/usr.sbin/vmd/vm_agentx.c +++ b/usr.sbin/vmd/vm_agentx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vm_agentx.c,v 1.1 2022/09/13 10:28:19 martijn Exp $ */ +/* $OpenBSD: vm_agentx.c,v 1.2 2024/02/02 14:58:02 dv Exp $ */ /* * Copyright (c) 2022 Martijn van Duren @@ -106,7 +106,7 @@ vm_agentx(struct privsep *ps, struct privsep_proc *p) * group permissions. */ if ((grp = getgrnam(AGENTX_GROUP)) == NULL) - fatal("getgrnam"); + fatal("failed to get group: %s", AGENTX_GROUP); ps->ps_pw->pw_gid = grp->gr_gid; proc_run(ps, p, procs, nitems(procs), vm_agentx_run, NULL);