^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/firewire-constants.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "list.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "nosy-dump.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define CSR_FCP_COMMAND 0xfffff0000b00ull
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define CSR_FCP_RESPONSE 0xfffff0000d00ull
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static const char * const ctype_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) [0x0] = "control", [0x8] = "not implemented",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) [0x1] = "status", [0x9] = "accepted",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) [0x2] = "specific inquiry", [0xa] = "rejected",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) [0x3] = "notify", [0xb] = "in transition",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) [0x4] = "general inquiry", [0xc] = "stable",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) [0x5] = "(reserved 0x05)", [0xd] = "changed",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) [0x6] = "(reserved 0x06)", [0xe] = "(reserved 0x0e)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) [0x7] = "(reserved 0x07)", [0xf] = "interim",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static const char * const subunit_type_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) [0x00] = "monitor", [0x10] = "(reserved 0x10)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) [0x01] = "audio", [0x11] = "(reserved 0x11)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) [0x02] = "printer", [0x12] = "(reserved 0x12)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) [0x03] = "disc", [0x13] = "(reserved 0x13)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) [0x04] = "tape recorder/player",[0x14] = "(reserved 0x14)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) [0x05] = "tuner", [0x15] = "(reserved 0x15)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) [0x06] = "ca", [0x16] = "(reserved 0x16)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) [0x07] = "camera", [0x17] = "(reserved 0x17)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) [0x08] = "(reserved 0x08)", [0x18] = "(reserved 0x18)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) [0x09] = "panel", [0x19] = "(reserved 0x19)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) [0x0a] = "bulletin board", [0x1a] = "(reserved 0x1a)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) [0x0b] = "camera storage", [0x1b] = "(reserved 0x1b)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) [0x0c] = "(reserved 0x0c)", [0x1c] = "vendor unique",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) [0x0d] = "(reserved 0x0d)", [0x1d] = "all subunit types",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) [0x0e] = "(reserved 0x0e)", [0x1e] = "subunit_type extended to next byte",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) [0x0f] = "(reserved 0x0f)", [0x1f] = "unit",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct avc_enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct avc_field {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) const char *name; /* Short name for field. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int offset; /* Location of field, specified in bits; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* negative means from end of packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int width; /* Width of field, 0 means use data_length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct avc_enum *names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct avc_opcode_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct avc_field fields[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct avc_enum power_field_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) { 0x70, "on" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) { 0x60, "off" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static const struct avc_opcode_info opcode_info[256] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* TA Document 1999026 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* AV/C Digital Interface Command Set General Specification 4.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) [0xb2] = { "power", {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) { "state", 0, 8, power_field_names }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) [0x30] = { "unit info", {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) { "foo", 0, 8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) { "unit_type", 8, 5 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) { "unit", 13, 3 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) { "company id", 16, 24 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) [0x31] = { "subunit info" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) [0x01] = { "reserve" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) [0xb0] = { "version" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) [0x00] = { "vendor dependent" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) [0x02] = { "plug info" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) [0x12] = { "channel usage" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) [0x24] = { "connect" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) [0x20] = { "connect av" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) [0x22] = { "connections" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) [0x11] = { "digital input" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) [0x10] = { "digital output" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) [0x25] = { "disconnect" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) [0x21] = { "disconnect av" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) [0x19] = { "input plug signal format" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) [0x18] = { "output plug signal format" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) [0x1f] = { "general bus setup" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* TA Document 1999025 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* AV/C Descriptor Mechanism Specification Version 1.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) [0x0c] = { "create descriptor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) [0x08] = { "open descriptor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) [0x09] = { "read descriptor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) [0x0a] = { "write descriptor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) [0x05] = { "open info block" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) [0x06] = { "read info block" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) [0x07] = { "write info block" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) [0x0b] = { "search descriptor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) [0x0d] = { "object number select" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* TA Document 1999015 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* AV/C Command Set for Rate Control of Isochronous Data Flow 1.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) [0xb3] = { "rate", {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) { "subfunction", 0, 8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) { "result", 8, 8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) { "plug_type", 16, 8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) { "plug_id", 16, 8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* TA Document 1999008 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* AV/C Audio Subunit Specification 1.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) [0xb8] = { "function block" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* TA Document 2001001 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* AV/C Panel Subunit Specification 1.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) [0x7d] = { "gui update" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) [0x7e] = { "push gui data" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) [0x7f] = { "user action" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) [0x7c] = { "pass through" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) [0x26] = { "asynchronous connection" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct avc_frame {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) uint32_t operand0:8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) uint32_t opcode:8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) uint32_t subunit_id:3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) uint32_t subunit_type:5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) uint32_t ctype:4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) uint32_t cts:4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) decode_avc(struct link_transaction *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct avc_frame *frame =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) (struct avc_frame *) t->request->packet.write_block.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) const struct avc_opcode_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) char buffer[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) info = &opcode_info[frame->opcode];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (info->name == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) snprintf(buffer, sizeof(buffer),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) "(unknown opcode 0x%02x)", frame->opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) name = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) name = info->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) printf("av/c %s, subunit_type=%s, subunit_id=%d, opcode=%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ctype_names[frame->ctype], subunit_type_names[frame->subunit_type],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) frame->subunit_id, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) for (i = 0; info->fields[i].name != NULL; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) printf(", %s", info->fields[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) printf("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) decode_fcp(struct link_transaction *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct avc_frame *frame =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) (struct avc_frame *) t->request->packet.write_block.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) unsigned long long offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ((unsigned long long) t->request->packet.common.offset_high << 32) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) t->request->packet.common.offset_low;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (t->request->packet.common.tcode != TCODE_WRITE_BLOCK_REQUEST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (offset == CSR_FCP_COMMAND || offset == CSR_FCP_RESPONSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) switch (frame->cts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) case 0x00:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) decode_avc(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) case 0x01:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) printf("cal fcp frame (cts=0x01)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) case 0x02:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) printf("ehs fcp frame (cts=0x02)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) case 0x03:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) printf("havi fcp frame (cts=0x03)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) case 0x0e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) printf("vendor specific fcp frame (cts=0x0e)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) case 0x0f:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) printf("extended cts\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) printf("reserved fcp frame (ctx=0x%02x)\n", frame->cts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)