blob: b67ebc88434d911418da95800b7a08d36076c6aa [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Stefan Richter83ef7c72010-07-22 11:58:05 +02002#include <linux/firewire-constants.h>
Stefan Richter9f6d3c42010-07-22 11:58:05 +02003#include <stdio.h>
Stefan Richter83ef7c72010-07-22 11:58:05 +02004#include <stdlib.h>
5
Stefan Richter9f6d3c42010-07-22 11:58:05 +02006#include "list.h"
7#include "nosy-dump.h"
8
9#define CSR_FCP_COMMAND 0xfffff0000b00ull
10#define CSR_FCP_RESPONSE 0xfffff0000d00ull
11
Stefan Richter92c16f72010-07-22 11:58:05 +020012static const char * const ctype_names[] = {
13 [0x0] = "control", [0x8] = "not implemented",
14 [0x1] = "status", [0x9] = "accepted",
15 [0x2] = "specific inquiry", [0xa] = "rejected",
16 [0x3] = "notify", [0xb] = "in transition",
17 [0x4] = "general inquiry", [0xc] = "stable",
18 [0x5] = "(reserved 0x05)", [0xd] = "changed",
19 [0x6] = "(reserved 0x06)", [0xe] = "(reserved 0x0e)",
20 [0x7] = "(reserved 0x07)", [0xf] = "interim",
Stefan Richter9f6d3c42010-07-22 11:58:05 +020021};
22
Stefan Richter92c16f72010-07-22 11:58:05 +020023static const char * const subunit_type_names[] = {
24 [0x00] = "monitor", [0x10] = "(reserved 0x10)",
25 [0x01] = "audio", [0x11] = "(reserved 0x11)",
26 [0x02] = "printer", [0x12] = "(reserved 0x12)",
27 [0x03] = "disc", [0x13] = "(reserved 0x13)",
28 [0x04] = "tape recorder/player",[0x14] = "(reserved 0x14)",
29 [0x05] = "tuner", [0x15] = "(reserved 0x15)",
30 [0x06] = "ca", [0x16] = "(reserved 0x16)",
31 [0x07] = "camera", [0x17] = "(reserved 0x17)",
32 [0x08] = "(reserved 0x08)", [0x18] = "(reserved 0x18)",
33 [0x09] = "panel", [0x19] = "(reserved 0x19)",
34 [0x0a] = "bulletin board", [0x1a] = "(reserved 0x1a)",
35 [0x0b] = "camera storage", [0x1b] = "(reserved 0x1b)",
36 [0x0c] = "(reserved 0x0c)", [0x1c] = "vendor unique",
37 [0x0d] = "(reserved 0x0d)", [0x1d] = "all subunit types",
38 [0x0e] = "(reserved 0x0e)", [0x1e] = "subunit_type extended to next byte",
39 [0x0f] = "(reserved 0x0f)", [0x1f] = "unit",
Stefan Richter9f6d3c42010-07-22 11:58:05 +020040};
41
42struct avc_enum {
Stefan Richter92c16f72010-07-22 11:58:05 +020043 int value;
44 const char *name;
Stefan Richter9f6d3c42010-07-22 11:58:05 +020045};
46
47struct avc_field {
Stefan Richter92c16f72010-07-22 11:58:05 +020048 const char *name; /* Short name for field. */
49 int offset; /* Location of field, specified in bits; */
50 /* negative means from end of packet. */
51 int width; /* Width of field, 0 means use data_length. */
52 struct avc_enum *names;
Stefan Richter9f6d3c42010-07-22 11:58:05 +020053};
54
55struct avc_opcode_info {
Stefan Richter92c16f72010-07-22 11:58:05 +020056 const char *name;
57 struct avc_field fields[8];
Stefan Richter9f6d3c42010-07-22 11:58:05 +020058};
59
60struct avc_enum power_field_names[] = {
Stefan Richter92c16f72010-07-22 11:58:05 +020061 { 0x70, "on" },
62 { 0x60, "off" },
63 { }
Stefan Richter9f6d3c42010-07-22 11:58:05 +020064};
65
66static const struct avc_opcode_info opcode_info[256] = {
67
Stefan Richter92c16f72010-07-22 11:58:05 +020068 /* TA Document 1999026 */
69 /* AV/C Digital Interface Command Set General Specification 4.0 */
70 [0xb2] = { "power", {
71 { "state", 0, 8, power_field_names }
72 }
73 },
74 [0x30] = { "unit info", {
75 { "foo", 0, 8 },
76 { "unit_type", 8, 5 },
77 { "unit", 13, 3 },
78 { "company id", 16, 24 },
79 }
80 },
81 [0x31] = { "subunit info" },
82 [0x01] = { "reserve" },
83 [0xb0] = { "version" },
84 [0x00] = { "vendor dependent" },
85 [0x02] = { "plug info" },
86 [0x12] = { "channel usage" },
87 [0x24] = { "connect" },
88 [0x20] = { "connect av" },
89 [0x22] = { "connections" },
90 [0x11] = { "digital input" },
91 [0x10] = { "digital output" },
92 [0x25] = { "disconnect" },
93 [0x21] = { "disconnect av" },
94 [0x19] = { "input plug signal format" },
95 [0x18] = { "output plug signal format" },
96 [0x1f] = { "general bus setup" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +020097
Stefan Richter92c16f72010-07-22 11:58:05 +020098 /* TA Document 1999025 */
99 /* AV/C Descriptor Mechanism Specification Version 1.0 */
100 [0x0c] = { "create descriptor" },
101 [0x08] = { "open descriptor" },
102 [0x09] = { "read descriptor" },
103 [0x0a] = { "write descriptor" },
104 [0x05] = { "open info block" },
105 [0x06] = { "read info block" },
106 [0x07] = { "write info block" },
107 [0x0b] = { "search descriptor" },
108 [0x0d] = { "object number select" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200109
Stefan Richter92c16f72010-07-22 11:58:05 +0200110 /* TA Document 1999015 */
111 /* AV/C Command Set for Rate Control of Isochronous Data Flow 1.0 */
112 [0xb3] = { "rate", {
113 { "subfunction", 0, 8 },
114 { "result", 8, 8 },
115 { "plug_type", 16, 8 },
116 { "plug_id", 16, 8 },
117 }
118 },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200119
Stefan Richter92c16f72010-07-22 11:58:05 +0200120 /* TA Document 1999008 */
121 /* AV/C Audio Subunit Specification 1.0 */
122 [0xb8] = { "function block" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200123
Stefan Richter92c16f72010-07-22 11:58:05 +0200124 /* TA Document 2001001 */
125 /* AV/C Panel Subunit Specification 1.1 */
126 [0x7d] = { "gui update" },
127 [0x7e] = { "push gui data" },
128 [0x7f] = { "user action" },
129 [0x7c] = { "pass through" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200130
Stefan Richter92c16f72010-07-22 11:58:05 +0200131 /* */
132 [0x26] = { "asynchronous connection" },
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200133};
134
135struct avc_frame {
Stefan Richter92c16f72010-07-22 11:58:05 +0200136 uint32_t operand0:8;
137 uint32_t opcode:8;
138 uint32_t subunit_id:3;
139 uint32_t subunit_type:5;
140 uint32_t ctype:4;
141 uint32_t cts:4;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200142};
143
144static void
145decode_avc(struct link_transaction *t)
146{
Stefan Richter92c16f72010-07-22 11:58:05 +0200147 struct avc_frame *frame =
148 (struct avc_frame *) t->request->packet.write_block.data;
149 const struct avc_opcode_info *info;
150 const char *name;
151 char buffer[32];
152 int i;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200153
Stefan Richter92c16f72010-07-22 11:58:05 +0200154 info = &opcode_info[frame->opcode];
155 if (info->name == NULL) {
156 snprintf(buffer, sizeof(buffer),
157 "(unknown opcode 0x%02x)", frame->opcode);
158 name = buffer;
159 } else {
160 name = info->name;
161 }
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200162
Stefan Richter92c16f72010-07-22 11:58:05 +0200163 printf("av/c %s, subunit_type=%s, subunit_id=%d, opcode=%s",
164 ctype_names[frame->ctype], subunit_type_names[frame->subunit_type],
165 frame->subunit_id, name);
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200166
Stefan Richter92c16f72010-07-22 11:58:05 +0200167 for (i = 0; info->fields[i].name != NULL; i++)
168 printf(", %s", info->fields[i].name);
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200169
Stefan Richter92c16f72010-07-22 11:58:05 +0200170 printf("\n");
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200171}
172
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200173int
174decode_fcp(struct link_transaction *t)
175{
Stefan Richter92c16f72010-07-22 11:58:05 +0200176 struct avc_frame *frame =
177 (struct avc_frame *) t->request->packet.write_block.data;
178 unsigned long long offset =
179 ((unsigned long long) t->request->packet.common.offset_high << 32) |
180 t->request->packet.common.offset_low;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200181
Stefan Richter83ef7c72010-07-22 11:58:05 +0200182 if (t->request->packet.common.tcode != TCODE_WRITE_BLOCK_REQUEST)
Stefan Richter92c16f72010-07-22 11:58:05 +0200183 return 0;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200184
Stefan Richter92c16f72010-07-22 11:58:05 +0200185 if (offset == CSR_FCP_COMMAND || offset == CSR_FCP_RESPONSE) {
186 switch (frame->cts) {
187 case 0x00:
188 decode_avc(t);
189 break;
190 case 0x01:
191 printf("cal fcp frame (cts=0x01)\n");
192 break;
193 case 0x02:
194 printf("ehs fcp frame (cts=0x02)\n");
195 break;
196 case 0x03:
197 printf("havi fcp frame (cts=0x03)\n");
198 break;
199 case 0x0e:
200 printf("vendor specific fcp frame (cts=0x0e)\n");
201 break;
202 case 0x0f:
203 printf("extended cts\n");
204 break;
205 default:
206 printf("reserved fcp frame (ctx=0x%02x)\n", frame->cts);
207 break;
208 }
209 return 1;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200210 }
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200211
Stefan Richter92c16f72010-07-22 11:58:05 +0200212 return 0;
Stefan Richter9f6d3c42010-07-22 11:58:05 +0200213}
214