tools/firewire: nosy-dump: change to kernel coding style

This changes only
  - whitespace
  - C99 initializers
  - comment style
  - order of #includes
  - if { } else { } bracing

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
This commit is contained in:
Stefan Richter 2010-07-22 11:58:05 +02:00
parent a8461c0f3b
commit 92c16f7e9c
4 changed files with 1064 additions and 1117 deletions

View File

@ -6,58 +6,34 @@
#define CSR_FCP_COMMAND 0xfffff0000b00ull #define CSR_FCP_COMMAND 0xfffff0000b00ull
#define CSR_FCP_RESPONSE 0xfffff0000d00ull #define CSR_FCP_RESPONSE 0xfffff0000d00ull
static const char * const ctype_names[16] = { static const char * const ctype_names[] = {
"control", [0x0] = "control", [0x8] = "not implemented",
"status", [0x1] = "status", [0x9] = "accepted",
"specific inquiry", [0x2] = "specific inquiry", [0xa] = "rejected",
"notify", [0x3] = "notify", [0xb] = "in transition",
"general inquiry", [0x4] = "general inquiry", [0xc] = "stable",
"(reserved 0x05)", [0x5] = "(reserved 0x05)", [0xd] = "changed",
"(reserved 0x06)", [0x6] = "(reserved 0x06)", [0xe] = "(reserved 0x0e)",
"(reserved 0x07)", [0x7] = "(reserved 0x07)", [0xf] = "interim",
"not implemented",
"accepted",
"rejected",
"in transition",
"stable",
"changed",
"(reserved 0x0e)",
"interim"
}; };
static const char * const subunit_type_names[32] = { static const char * const subunit_type_names[] = {
"monitor", [0x00] = "monitor", [0x10] = "(reserved 0x10)",
"audio", [0x01] = "audio", [0x11] = "(reserved 0x11)",
"printer", [0x02] = "printer", [0x12] = "(reserved 0x12)",
"disc", [0x03] = "disc", [0x13] = "(reserved 0x13)",
"tape recorder/player", [0x04] = "tape recorder/player",[0x14] = "(reserved 0x14)",
"tuner", [0x05] = "tuner", [0x15] = "(reserved 0x15)",
"ca", [0x06] = "ca", [0x16] = "(reserved 0x16)",
"camera", [0x07] = "camera", [0x17] = "(reserved 0x17)",
"(reserved 0x08)", [0x08] = "(reserved 0x08)", [0x18] = "(reserved 0x18)",
"panel", [0x09] = "panel", [0x19] = "(reserved 0x19)",
"bulletin board", [0x0a] = "bulletin board", [0x1a] = "(reserved 0x1a)",
"camera storage", [0x0b] = "camera storage", [0x1b] = "(reserved 0x1b)",
"(reserved 0x0c)", [0x0c] = "(reserved 0x0c)", [0x1c] = "vendor unique",
"(reserved 0x0d)", [0x0d] = "(reserved 0x0d)", [0x1d] = "all subunit types",
"(reserved 0x0e)", [0x0e] = "(reserved 0x0e)", [0x1e] = "subunit_type extended to next byte",
"(reserved 0x0f)", [0x0f] = "(reserved 0x0f)", [0x1f] = "unit",
"(reserved 0x10)",
"(reserved 0x11)",
"(reserved 0x12)",
"(reserved 0x13)",
"(reserved 0x14)",
"(reserved 0x15)",
"(reserved 0x16)",
"(reserved 0x17)",
"(reserved 0x18)",
"(reserved 0x19)",
"(reserved 0x1a)",
"(reserved 0x1b)",
"vendor unique",
"all subunit types",
"subunit_type extended to next byte",
"unit"
}; };
struct avc_enum { struct avc_enum {
@ -67,8 +43,8 @@ struct avc_enum {
struct avc_field { struct avc_field {
const char *name; /* Short name for field. */ const char *name; /* Short name for field. */
int offset; /* Location of field, specified in bits. int offset; /* Location of field, specified in bits; */
* Negative means from end of packet */ /* negative means from end of packet. */
int width; /* Width of field, 0 means use data_length. */ int width; /* Width of field, 0 means use data_length. */
struct avc_enum *names; struct avc_enum *names;
}; };
@ -86,16 +62,13 @@ struct avc_enum power_field_names[] = {
static const struct avc_opcode_info opcode_info[256] = { static const struct avc_opcode_info opcode_info[256] = {
/* TA Document 1999026 /* TA Document 1999026 */
* AV/C Digital Interface Command Set General Specification /* AV/C Digital Interface Command Set General Specification 4.0 */
* Version 4.0 */ [0xb2] = { "power", {
[0xb2] =
{ "power", {
{ "state", 0, 8, power_field_names } { "state", 0, 8, power_field_names }
} }
}, },
[0x30] = [0x30] = { "unit info", {
{ "unit info", {
{ "foo", 0, 8 }, { "foo", 0, 8 },
{ "unit_type", 8, 5 }, { "unit_type", 8, 5 },
{ "unit", 13, 3 }, { "unit", 13, 3 },
@ -106,7 +79,6 @@ static const struct avc_opcode_info opcode_info[256] = {
[0x01] = { "reserve" }, [0x01] = { "reserve" },
[0xb0] = { "version" }, [0xb0] = { "version" },
[0x00] = { "vendor dependent" }, [0x00] = { "vendor dependent" },
[0x02] = { "plug info" }, [0x02] = { "plug info" },
[0x12] = { "channel usage" }, [0x12] = { "channel usage" },
[0x24] = { "connect" }, [0x24] = { "connect" },
@ -120,8 +92,8 @@ static const struct avc_opcode_info opcode_info[256] = {
[0x18] = { "output plug signal format" }, [0x18] = { "output plug signal format" },
[0x1f] = { "general bus setup" }, [0x1f] = { "general bus setup" },
/* TA Document 1999025 /* TA Document 1999025 */
* AV/C Descriptor Mechanism Specification Version 1.0 */ /* AV/C Descriptor Mechanism Specification Version 1.0 */
[0x0c] = { "create descriptor" }, [0x0c] = { "create descriptor" },
[0x08] = { "open descriptor" }, [0x08] = { "open descriptor" },
[0x09] = { "read descriptor" }, [0x09] = { "read descriptor" },
@ -132,8 +104,8 @@ static const struct avc_opcode_info opcode_info[256] = {
[0x0b] = { "search descriptor" }, [0x0b] = { "search descriptor" },
[0x0d] = { "object number select" }, [0x0d] = { "object number select" },
/* TA Document 1999015 /* TA Document 1999015 */
* AV/C Command Set for Rate Control of Isochronous Data Flow 1.0 */ /* AV/C Command Set for Rate Control of Isochronous Data Flow 1.0 */
[0xb3] = { "rate", { [0xb3] = { "rate", {
{ "subfunction", 0, 8 }, { "subfunction", 0, 8 },
{ "result", 8, 8 }, { "result", 8, 8 },
@ -142,12 +114,12 @@ static const struct avc_opcode_info opcode_info[256] = {
} }
}, },
/* TA Document 1999008 /* TA Document 1999008 */
* AV/C Audio Subunit Specification 1.0 */ /* AV/C Audio Subunit Specification 1.0 */
[0xb8] = { "function block" }, [0xb8] = { "function block" },
/* TA Document 2001001 /* TA Document 2001001 */
* AV/C Panel Subunit Specification 1.1 */ /* AV/C Panel Subunit Specification 1.1 */
[0x7d] = { "gui update" }, [0x7d] = { "gui update" },
[0x7e] = { "push gui data" }, [0x7e] = { "push gui data" },
[0x7f] = { "user action" }, [0x7f] = { "user action" },
@ -169,7 +141,8 @@ struct avc_frame {
static void static void
decode_avc(struct link_transaction *t) decode_avc(struct link_transaction *t)
{ {
struct avc_frame *frame = (struct avc_frame *) t->request->packet.write_block.data; struct avc_frame *frame =
(struct avc_frame *) t->request->packet.write_block.data;
const struct avc_opcode_info *info; const struct avc_opcode_info *info;
const char *name; const char *name;
char buffer[32]; char buffer[32];
@ -177,7 +150,8 @@ decode_avc(struct link_transaction *t)
info = &opcode_info[frame->opcode]; info = &opcode_info[frame->opcode];
if (info->name == NULL) { if (info->name == NULL) {
snprintf(buffer, sizeof buffer, "(unknown opcode 0x%02x)", frame->opcode); snprintf(buffer, sizeof(buffer),
"(unknown opcode 0x%02x)", frame->opcode);
name = buffer; name = buffer;
} else { } else {
name = info->name; name = info->name;
@ -187,21 +161,19 @@ decode_avc(struct link_transaction *t)
ctype_names[frame->ctype], subunit_type_names[frame->subunit_type], ctype_names[frame->ctype], subunit_type_names[frame->subunit_type],
frame->subunit_id, name); frame->subunit_id, name);
for (i = 0; info->fields[i].name != NULL; i++) { for (i = 0; info->fields[i].name != NULL; i++)
printf(", %s", info->fields[i].name); printf(", %s", info->fields[i].name);
}
printf("\n"); printf("\n");
} }
int int
decode_fcp(struct link_transaction *t) decode_fcp(struct link_transaction *t)
{ {
struct avc_frame *frame = (struct avc_frame *) t->request->packet.write_block.data; struct avc_frame *frame =
unsigned long long offset; (struct avc_frame *) t->request->packet.write_block.data;
unsigned long long offset =
offset = ((unsigned long long) t->request->packet.common.offset_high << 32) | ((unsigned long long) t->request->packet.common.offset_high << 32) |
t->request->packet.common.offset_low; t->request->packet.common.offset_low;
if (t->request->packet.common.tcode != TCODE_WRITE_BLOCK) if (t->request->packet.common.tcode != TCODE_WRITE_BLOCK)

View File

@ -1,5 +1,3 @@
/* -*- mode: c; c-basic-offset: 2 -*- */
/* /*
* nosy-dump - Interface to snoop mode driver for TI PCILynx 1394 controllers * nosy-dump - Interface to snoop mode driver for TI PCILynx 1394 controllers
* Copyright (C) 2002-2006 Kristian Høgsberg * Copyright (C) 2002-2006 Kristian Høgsberg
@ -19,45 +17,41 @@
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include <stdlib.h> #include <byteswap.h>
#include <stdio.h> #include <endian.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <poll.h>
#include <popt.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/time.h> #include <sys/time.h>
#include <endian.h>
#include <popt.h>
#include <poll.h>
#include <byteswap.h>
#include <termios.h> #include <termios.h>
#include <unistd.h>
#include <signal.h>
#include "list.h" #include "list.h"
#include "nosy-user.h"
#include "nosy-dump.h" #include "nosy-dump.h"
#include "nosy-user.h"
enum { enum {
PACKET_FIELD_DETAIL = 0x01, PACKET_FIELD_DETAIL = 0x01,
PACKET_FIELD_DATA_LENGTH = 0x02, PACKET_FIELD_DATA_LENGTH = 0x02,
/* Marks the fields we print in transaction view. */ /* Marks the fields we print in transaction view. */
PACKET_FIELD_TRANSACTION = 0x04 PACKET_FIELD_TRANSACTION = 0x04,
}; };
static void static void print_packet(uint32_t *data, size_t length);
print_packet(uint32_t *data, size_t length); static void decode_link_packet(struct link_packet *packet, size_t length,
static void
decode_link_packet(struct link_packet *packet, size_t length,
int include_flags, int exclude_flags); int include_flags, int exclude_flags);
static int run = 1; static int run = 1;
sig_t sys_sigint_handler; sig_t sys_sigint_handler;
static char *option_nosy_device = "/dev/nosy"; static char *option_nosy_device = "/dev/nosy";
static char *option_view = "packet"; static char *option_view = "packet";
static char *option_output = NULL; static char *option_output;
static char *option_input = NULL; static char *option_input;
static int option_hex; static int option_hex;
static int option_iso; static int option_iso;
static int option_cycle_start; static int option_cycle_start;
@ -67,85 +61,83 @@ static int option_verbose;
enum { enum {
VIEW_TRANSACTION, VIEW_TRANSACTION,
VIEW_PACKET, VIEW_PACKET,
VIEW_STATS VIEW_STATS,
}; };
static const struct poptOption options[] = { static const struct poptOption options[] = {
{ {
longName: "device", .longName = "device",
shortName: 'd', .shortName = 'd',
argInfo: POPT_ARG_STRING, .argInfo = POPT_ARG_STRING,
arg: &option_nosy_device, .arg = &option_nosy_device,
descrip: "Path to nosy device.", .descrip = "Path to nosy device.",
argDescrip: "DEVICE" .argDescrip = "DEVICE"
}, },
{ {
longName: "view", .longName = "view",
argInfo: POPT_ARG_STRING, .argInfo = POPT_ARG_STRING,
arg: &option_view, .arg = &option_view,
descrip: "Specify view of bus traffic: packet, transaction or stats.", .descrip = "Specify view of bus traffic: packet, transaction or stats.",
argDescrip: "VIEW" .argDescrip = "VIEW"
}, },
{ {
longName: "hex", .longName = "hex",
shortName: 'x', .shortName = 'x',
argInfo: POPT_ARG_NONE, .argInfo = POPT_ARG_NONE,
arg: &option_hex, .arg = &option_hex,
descrip: "Print each packet in hex.", .descrip = "Print each packet in hex.",
}, },
{ {
longName: "iso", .longName = "iso",
argInfo: POPT_ARG_NONE, .argInfo = POPT_ARG_NONE,
arg: &option_iso, .arg = &option_iso,
descrip: "Print iso packets.", .descrip = "Print iso packets.",
}, },
{ {
longName: "cycle-start", .longName = "cycle-start",
argInfo: POPT_ARG_NONE, .argInfo = POPT_ARG_NONE,
arg: &option_cycle_start, .arg = &option_cycle_start,
descrip: "Print cycle start packets.", .descrip = "Print cycle start packets.",
}, },
{ {
longName: "verbose", .longName = "verbose",
shortName: 'v', .shortName = 'v',
argInfo: POPT_ARG_NONE, .argInfo = POPT_ARG_NONE,
arg: &option_verbose, .arg = &option_verbose,
descrip: "Verbose packet view.", .descrip = "Verbose packet view.",
}, },
{ {
longName: "output", .longName = "output",
shortName: 'o', .shortName = 'o',
argInfo: POPT_ARG_STRING, .argInfo = POPT_ARG_STRING,
arg: &option_output, .arg = &option_output,
descrip: "Log to output file.", .descrip = "Log to output file.",
argDescrip: "FILENAME" .argDescrip = "FILENAME"
}, },
{ {
longName: "input", .longName = "input",
shortName: 'i', .shortName = 'i',
argInfo: POPT_ARG_STRING, .argInfo = POPT_ARG_STRING,
arg: &option_input, .arg = &option_input,
descrip: "Decode log from file.", .descrip = "Decode log from file.",
argDescrip: "FILENAME" .argDescrip = "FILENAME"
}, },
{ {
longName: "version", .longName = "version",
argInfo: POPT_ARG_NONE, .argInfo = POPT_ARG_NONE,
arg: &option_version, .arg = &option_version,
descrip: "Specify print version info.", .descrip = "Specify print version info.",
}, },
POPT_AUTOHELP POPT_AUTOHELP
POPT_TABLEEND POPT_TABLEEND
}; };
/* Allow all ^C except the first to interrupt the program in the usual way. */
void void
sigint_handler(int signal_num) sigint_handler(int signal_num)
{ {
if (run == 1) { if (run == 1) {
run = 0; run = 0;
/* Allow all Ctrl-C's except the first to interrupt the program in
* the usual way.
*/
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
} }
} }
@ -170,8 +162,9 @@ subaction_destroy(struct subaction *sa)
free(sa); free(sa);
} }
struct list pending_transaction_list = struct list pending_transaction_list = {
{ &pending_transaction_list, &pending_transaction_list }; &pending_transaction_list, &pending_transaction_list
};
struct link_transaction * struct link_transaction *
link_transaction_lookup(int request_node, int response_node, int tlabel) link_transaction_lookup(int request_node, int response_node, int tlabel)
@ -200,18 +193,18 @@ link_transaction_lookup(int request_node, int response_node, int tlabel)
void void
link_transaction_destroy(struct link_transaction *t) link_transaction_destroy(struct link_transaction *t)
{ {
struct subaction *sa;
while (!list_empty(&t->request_list)) { while (!list_empty(&t->request_list)) {
struct subaction *sa = list_head(&t->request_list, struct subaction, link); sa = list_head(&t->request_list, struct subaction, link);
list_remove(&sa->link); list_remove(&sa->link);
subaction_destroy(sa); subaction_destroy(sa);
} }
while (!list_empty(&t->response_list)) { while (!list_empty(&t->response_list)) {
struct subaction *sa = list_head(&t->response_list, struct subaction, link); sa = list_head(&t->response_list, struct subaction, link);
list_remove(&sa->link); list_remove(&sa->link);
subaction_destroy(sa); subaction_destroy(sa);
} }
free(t); free(t);
} }
@ -267,7 +260,8 @@ clear_pending_transaction_list(void)
struct link_transaction *t; struct link_transaction *t;
while (!list_empty(&pending_transaction_list)) { while (!list_empty(&pending_transaction_list)) {
t = list_head(&pending_transaction_list, struct link_transaction, link); t = list_head(&pending_transaction_list,
struct link_transaction, link);
list_remove(&t->link); list_remove(&t->link);
link_transaction_destroy(t); link_transaction_destroy(t);
/* print unfinished transactions */ /* print unfinished transactions */
@ -275,55 +269,37 @@ clear_pending_transaction_list(void)
} }
static const char * const tcode_names[] = { static const char * const tcode_names[] = {
"write_quadlet_request", [0x0] = "write_quadlet_request", [0x6] = "read_quadlet_response",
"write_block_request", [0x1] = "write_block_request", [0x7] = "read_block_response",
"write_response", [0x2] = "write_response", [0x8] = "cycle_start",
"reserved", [0x3] = "reserved", [0x9] = "lock_request",
"read_quadlet_request", [0x4] = "read_quadlet_request", [0xa] = "iso_data",
"read_block_request", [0x5] = "read_block_request", [0xb] = "lock_response",
"read_quadlet_response",
"read_block_response",
"cycle_start",
"lock_request",
"iso_data",
"lock_response"
}; };
static const char * const ack_names[] = { static const char * const ack_names[] = {
"no ack", [0x0] = "no ack", [0x8] = "reserved (0x08)",
"ack_complete", [0x1] = "ack_complete", [0x9] = "reserved (0x09)",
"ack_pending", [0x2] = "ack_pending", [0xa] = "reserved (0x0a)",
"reserved (0x03)", [0x3] = "reserved (0x03)", [0xb] = "reserved (0x0b)",
"ack_busy_x", [0x4] = "ack_busy_x", [0xc] = "reserved (0x0c)",
"ack_busy_a", [0x5] = "ack_busy_a", [0xd] = "ack_data_error",
"ack_busy_b", [0x6] = "ack_busy_b", [0xe] = "ack_type_error",
"reserved (0x07)", [0x7] = "reserved (0x07)", [0xf] = "reserved (0x0f)",
"reserved (0x08)",
"reserved (0x09)",
"reserved (0x0a)",
"reserved (0x0b)",
"reserved (0x0c)",
"ack_data_error",
"ack_type_error",
"reserved (0x0f)",
}; };
static const char * const rcode_names[] = { static const char * const rcode_names[] = {
"complete", [0x0] = "complete", [0x4] = "conflict_error",
"reserved (0x01)", [0x1] = "reserved (0x01)", [0x5] = "data_error",
"reserved (0x02)", [0x2] = "reserved (0x02)", [0x6] = "type_error",
"reserved (0x03)", [0x3] = "reserved (0x03)", [0x7] = "address_error",
"conflict_error",
"data_error",
"type_error",
"address_error",
}; };
static const char * const retry_names[] = { static const char * const retry_names[] = {
"retry_1", [0x0] = "retry_1",
"retry_x", [0x1] = "retry_x",
"retry_a", [0x2] = "retry_a",
"retry_b", [0x3] = "retry_b",
}; };
enum { enum {
@ -343,8 +319,8 @@ struct packet_info {
struct packet_field { struct packet_field {
const char *name; /* Short name for field. */ const char *name; /* Short name for field. */
int offset; /* Location of field, specified in bits. int offset; /* Location of field, specified in bits; */
* Negative means from end of packet */ /* negative means from end of packet. */
int width; /* Width of field, 0 means use data_length. */ int width; /* Width of field, 0 means use data_length. */
int flags; /* Show options. */ int flags; /* Show options. */
const char * const *value_names; const char * const *value_names;
@ -371,14 +347,14 @@ struct packet_field {
struct packet_field read_quadlet_request_fields[] = { struct packet_field read_quadlet_request_fields[] = {
COMMON_REQUEST_FIELDS, COMMON_REQUEST_FIELDS,
{ "crc", 96, 32, PACKET_FIELD_DETAIL }, { "crc", 96, 32, PACKET_FIELD_DETAIL },
{ "ack", 156, 4, 0, ack_names } { "ack", 156, 4, 0, ack_names },
}; };
struct packet_field read_quadlet_response_fields[] = { struct packet_field read_quadlet_response_fields[] = {
COMMON_RESPONSE_FIELDS, COMMON_RESPONSE_FIELDS,
{ "data", 96, 32, PACKET_FIELD_TRANSACTION }, { "data", 96, 32, PACKET_FIELD_TRANSACTION },
{ "crc", 128, 32, PACKET_FIELD_DETAIL }, { "crc", 128, 32, PACKET_FIELD_DETAIL },
{ "ack", 188, 4, 0, ack_names } { "ack", 188, 4, 0, ack_names },
}; };
struct packet_field read_block_request_fields[] = { struct packet_field read_block_request_fields[] = {
@ -396,13 +372,13 @@ struct packet_field block_response_fields[] = {
{ "crc", 128, 32, PACKET_FIELD_DETAIL }, { "crc", 128, 32, PACKET_FIELD_DETAIL },
{ "data", 160, 0, PACKET_FIELD_TRANSACTION }, { "data", 160, 0, PACKET_FIELD_TRANSACTION },
{ "crc", -64, 32, PACKET_FIELD_DETAIL }, { "crc", -64, 32, PACKET_FIELD_DETAIL },
{ "ack", -4, 4, 0, ack_names } { "ack", -4, 4, 0, ack_names },
}; };
struct packet_field write_quadlet_request_fields[] = { struct packet_field write_quadlet_request_fields[] = {
COMMON_REQUEST_FIELDS, COMMON_REQUEST_FIELDS,
{ "data", 96, 32, PACKET_FIELD_TRANSACTION }, { "data", 96, 32, PACKET_FIELD_TRANSACTION },
{ "ack", -4, 4, 0, ack_names } { "ack", -4, 4, 0, ack_names },
}; };
struct packet_field block_request_fields[] = { struct packet_field block_request_fields[] = {
@ -412,13 +388,13 @@ struct packet_field block_request_fields[] = {
{ "crc", 128, 32, PACKET_FIELD_DETAIL }, { "crc", 128, 32, PACKET_FIELD_DETAIL },
{ "data", 160, 0, PACKET_FIELD_TRANSACTION }, { "data", 160, 0, PACKET_FIELD_TRANSACTION },
{ "crc", -64, 32, PACKET_FIELD_DETAIL }, { "crc", -64, 32, PACKET_FIELD_DETAIL },
{ "ack", -4, 4, 0, ack_names } { "ack", -4, 4, 0, ack_names },
}; };
struct packet_field write_response_fields[] = { struct packet_field write_response_fields[] = {
COMMON_RESPONSE_FIELDS, COMMON_RESPONSE_FIELDS,
{ "reserved", 64, 32, PACKET_FIELD_DETAIL }, { "reserved", 64, 32, PACKET_FIELD_DETAIL },
{ "ack", -4, 4, 0, ack_names } { "ack", -4, 4, 0, ack_names },
}; };
struct packet_field iso_data_fields[] = { struct packet_field iso_data_fields[] = {
@ -430,7 +406,7 @@ struct packet_field iso_data_fields[] = {
{ "crc", 32, 32, PACKET_FIELD_DETAIL }, { "crc", 32, 32, PACKET_FIELD_DETAIL },
{ "data", 64, 0 }, { "data", 64, 0 },
{ "crc", -64, 32, PACKET_FIELD_DETAIL }, { "crc", -64, 32, PACKET_FIELD_DETAIL },
{ "ack", -4, 4, 0, ack_names } { "ack", -4, 4, 0, ack_names },
}; };
static struct packet_info packet_info[] = { static struct packet_info packet_info[] = {
@ -507,7 +483,7 @@ static struct packet_info packet_info[] = {
.type = PACKET_RESPONSE, .type = PACKET_RESPONSE,
.fields = block_response_fields, .fields = block_response_fields,
.field_count = array_length(block_response_fields) .field_count = array_length(block_response_fields)
} },
}; };
int int
@ -516,8 +492,7 @@ handle_packet(uint32_t *data, size_t length)
if (length == 0) { if (length == 0) {
printf("bus reset\r\n"); printf("bus reset\r\n");
clear_pending_transaction_list(); clear_pending_transaction_list();
} } else if (length > sizeof(struct phy_packet)) {
else if (length > sizeof(struct phy_packet)) {
struct link_packet *p = (struct link_packet *) data; struct link_packet *p = (struct link_packet *) data;
struct subaction *sa, *prev; struct subaction *sa, *prev;
struct link_transaction *t; struct link_transaction *t;
@ -530,19 +505,23 @@ handle_packet(uint32_t *data, size_t length)
t->request = sa; t->request = sa;
if (!list_empty(&t->request_list)) { if (!list_empty(&t->request_list)) {
prev = list_tail(&t->request_list, struct subaction, link); prev = list_tail(&t->request_list,
struct subaction, link);
if (!ACK_BUSY(prev->ack)) { if (!ACK_BUSY(prev->ack)) {
/* error, we should only see ack_busy_* before the /*
* error, we should only see ack_busy_* before the
* ack_pending/ack_complete -- this is an ack_pending * ack_pending/ack_complete -- this is an ack_pending
* instead (ack_complete would have finished the * instead (ack_complete would have finished the
* transaction). */ * transaction).
*/
} }
if (prev->packet.common.tcode != sa->packet.common.tcode || if (prev->packet.common.tcode != sa->packet.common.tcode ||
prev->packet.common.tlabel != sa->packet.common.tlabel) prev->packet.common.tlabel != sa->packet.common.tlabel) {
/* memcmp() ? */ /* memcmp() ? */
/* error, these should match for retries. */; /* error, these should match for retries. */
}
} }
list_append(&t->request_list, &sa->link); list_append(&t->request_list, &sa->link);
@ -589,20 +568,25 @@ handle_packet(uint32_t *data, size_t length)
if (!list_empty(&t->response_list)) { if (!list_empty(&t->response_list)) {
prev = list_tail(&t->response_list, struct subaction, link); prev = list_tail(&t->response_list, struct subaction, link);
if (!ACK_BUSY(prev->ack)) if (!ACK_BUSY(prev->ack)) {
/* error, we should only see ack_busy_* before the /*
* ack_pending/ack_complete */; * error, we should only see ack_busy_* before the
* ack_pending/ack_complete
*/
}
if (prev->packet.common.tcode != sa->packet.common.tcode || if (prev->packet.common.tcode != sa->packet.common.tcode ||
prev->packet.common.tlabel != sa->packet.common.tlabel) prev->packet.common.tlabel != sa->packet.common.tlabel) {
/* use memcmp() instead? */ /* use memcmp() instead? */
/* error, these should match for retries. */; /* error, these should match for retries. */
} }
else { } else {
prev = list_tail(&t->request_list, struct subaction, link); prev = list_tail(&t->request_list, struct subaction, link);
if (prev->ack != ACK_PENDING) { if (prev->ack != ACK_PENDING) {
/* error, should not get response unless last request got /*
* ack_pending. */ * error, should not get response unless last request got
* ack_pending.
*/
} }
if (packet_info[prev->packet.common.tcode].response_tcode != if (packet_info[prev->packet.common.tcode].response_tcode !=
@ -712,13 +696,11 @@ decode_link_packet(struct link_packet *packet, size_t length,
bits = get_bits(packet, offset, f->width); bits = get_bits(packet, offset, f->width);
printf("%s", f->value_names[bits]); printf("%s", f->value_names[bits]);
} } else if (f->width == 0) {
else if (f->width == 0) {
printf("%s=[", f->name); printf("%s=[", f->name);
dump_data((unsigned char *) packet + (offset / 8 + 4), data_length); dump_data((unsigned char *) packet + (offset / 8 + 4), data_length);
printf("]"); printf("]");
} } else {
else {
unsigned long long bits; unsigned long long bits;
int high_width, low_width; int high_width, low_width;
@ -730,9 +712,9 @@ decode_link_packet(struct link_packet *packet, size_t length,
bits = get_bits(packet, offset, high_width); bits = get_bits(packet, offset, high_width);
bits = (bits << low_width) | bits = (bits << low_width) |
get_bits(packet, offset + high_width, low_width); get_bits(packet, offset + high_width, low_width);
} } else {
else
bits = get_bits(packet, offset, f->width); bits = get_bits(packet, offset, f->width);
}
printf("%s=0x%0*llx", f->name, (f->width + 3) / 4, bits); printf("%s=0x%0*llx", f->name, (f->width + 3) / 4, bits);
@ -752,16 +734,15 @@ print_packet(uint32_t *data, size_t length)
printf("%6u ", data[0]); printf("%6u ", data[0]);
if (length == 4) if (length == 4) {
printf("bus reset"); printf("bus reset");
else if (length < sizeof(struct phy_packet)) { } else if (length < sizeof(struct phy_packet)) {
printf("short packet: "); printf("short packet: ");
for (i = 1; i < length / 4; i++) for (i = 1; i < length / 4; i++)
printf("%s%08x", i == 0 ? "[" : " ", data[i]); printf("%s%08x", i == 0 ? "[" : " ", data[i]);
printf("]"); printf("]");
} } else if (length == sizeof(struct phy_packet) && data[1] == ~data[2]) {
else if (length == sizeof(struct phy_packet) && data[1] == ~data[2]) {
struct phy_packet *pp = (struct phy_packet *) data; struct phy_packet *pp = (struct phy_packet *) data;
/* phy packet are 3 quadlets: the 1 quadlet payload, /* phy packet are 3 quadlets: the 1 quadlet payload,
@ -772,8 +753,7 @@ print_packet(uint32_t *data, size_t length)
case PHY_PACKET_CONFIGURATION: case PHY_PACKET_CONFIGURATION:
if (!pp->phy_config.set_root && !pp->phy_config.set_gap_count) { if (!pp->phy_config.set_root && !pp->phy_config.set_gap_count) {
printf("ext phy config: phy_id=%02x", pp->phy_config.root_id); printf("ext phy config: phy_id=%02x", pp->phy_config.root_id);
} } else {
else {
printf("phy config:"); printf("phy config:");
if (pp->phy_config.set_root) if (pp->phy_config.set_root)
printf(" set_root_id=%02x", pp->phy_config.root_id); printf(" set_root_id=%02x", pp->phy_config.root_id);
@ -790,8 +770,7 @@ print_packet(uint32_t *data, size_t length)
if (pp->self_id.extended) { if (pp->self_id.extended) {
printf("extended self id: phy_id=%02x, seq=%d", printf("extended self id: phy_id=%02x, seq=%d",
pp->ext_self_id.phy_id, pp->ext_self_id.sequence); pp->ext_self_id.phy_id, pp->ext_self_id.sequence);
} } else {
else {
static const char * const speed_names[] = { static const char * const speed_names[] = {
"S100", "S200", "S400", "BETA" "S100", "S200", "S400", "BETA"
}; };
@ -802,7 +781,6 @@ print_packet(uint32_t *data, size_t length)
speed_names[pp->self_id.phy_speed], speed_names[pp->self_id.phy_speed],
(pp->self_id.contender ? ", irm contender" : ""), (pp->self_id.contender ? ", irm contender" : ""),
(pp->self_id.initiated_reset ? ", initiator" : "")); (pp->self_id.initiated_reset ? ", initiator" : ""));
} }
break; break;
default: default:
@ -812,8 +790,7 @@ print_packet(uint32_t *data, size_t length)
printf("]"); printf("]");
break; break;
} }
} } else {
else {
struct link_packet *packet = (struct link_packet *) data; struct link_packet *packet = (struct link_packet *) data;
decode_link_packet(packet, length, 0, decode_link_packet(packet, length, 0,
@ -936,8 +913,7 @@ int main(int argc, const char *argv[])
fprintf(stderr, "Could not open %s, %m\n", option_input); fprintf(stderr, "Could not open %s, %m\n", option_input);
return -1; return -1;
} }
} } else {
else {
fd = open(option_nosy_device, O_RDWR); fd = open(option_nosy_device, O_RDWR);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "Could not open %s, %m\n", option_nosy_device); fprintf(stderr, "Could not open %s, %m\n", option_nosy_device);
@ -990,8 +966,7 @@ int main(int argc, const char *argv[])
if (fread(&length, sizeof length, 1, input) != 1) if (fread(&length, sizeof length, 1, input) != 1)
return 0; return 0;
fread(buf, 1, length, input); fread(buf, 1, length, input);
} } else {
else {
poll(pollfds, 2, -1); poll(pollfds, 2, -1);
if (pollfds[1].revents) { if (pollfds[1].revents) {
read(STDIN_FILENO, &c, sizeof c); read(STDIN_FILENO, &c, sizeof c);
@ -1026,9 +1001,9 @@ int main(int argc, const char *argv[])
break; break;
} }
} }
} } else {
else
poptPrintUsage(con, stdout, 0); poptPrintUsage(con, stdout, 0);
}
if (output != NULL) if (output != NULL)
fclose(output); fclose(output);