Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
269fe102
Commit
269fe102
authored
Jul 22, 2010
by
Stefan Richter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools/firewire: nosy-dump: break up a deeply nested function
Signed-off-by:
Stefan Richter
<
stefanr@s5r6.in-berlin.de
>
parent
468066f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
132 additions
and
113 deletions
+132
-113
tools/firewire/nosy-dump.c
tools/firewire/nosy-dump.c
+132
-113
No files found.
tools/firewire/nosy-dump.c
View file @
269fe102
...
...
@@ -487,138 +487,157 @@ static const struct packet_info packet_info[] = {
};
static
int
handle_packet
(
uint32_t
*
data
,
size_t
length
)
handle_
request_
packet
(
uint32_t
*
data
,
size_t
length
)
{
if
(
length
==
0
)
{
printf
(
"bus reset
\r\n
"
);
clear_pending_transaction_list
();
}
else
if
(
length
>
sizeof
(
struct
phy_packet
))
{
struct
link_packet
*
p
=
(
struct
link_packet
*
)
data
;
struct
subaction
*
sa
,
*
prev
;
struct
link_transaction
*
t
;
struct
link_packet
*
p
=
(
struct
link_packet
*
)
data
;
struct
subaction
*
sa
,
*
prev
;
struct
link_transaction
*
t
;
switch
(
packet_info
[
p
->
common
.
tcode
].
type
)
{
case
PACKET_REQUEST
:
t
=
link_transaction_lookup
(
p
->
common
.
source
,
p
->
common
.
destination
,
p
->
common
.
tlabel
);
sa
=
subaction_create
(
data
,
length
);
t
->
request
=
sa
;
if
(
!
list_empty
(
&
t
->
request_list
))
{
prev
=
list_tail
(
&
t
->
request_list
,
struct
subaction
,
link
);
if
(
!
ACK_BUSY
(
prev
->
ack
))
{
/*
* error, we should only see ack_busy_* before the
* ack_pending/ack_complete -- this is an ack_pending
* instead (ack_complete would have finished the
* transaction).
*/
}
t
=
link_transaction_lookup
(
p
->
common
.
source
,
p
->
common
.
destination
,
p
->
common
.
tlabel
);
sa
=
subaction_create
(
data
,
length
);
t
->
request
=
sa
;
if
(
!
list_empty
(
&
t
->
request_list
))
{
prev
=
list_tail
(
&
t
->
request_list
,
struct
subaction
,
link
);
if
(
!
ACK_BUSY
(
prev
->
ack
))
{
/*
* error, we should only see ack_busy_* before the
* ack_pending/ack_complete -- this is an ack_pending
* instead (ack_complete would have finished the
* transaction).
*/
}
if
(
prev
->
packet
.
common
.
tcode
!=
sa
->
packet
.
common
.
tcode
||
prev
->
packet
.
common
.
tlabel
!=
sa
->
packet
.
common
.
tlabel
)
{
/* memcmp() ? */
/* error, these should match for retries. */
}
}
if
(
prev
->
packet
.
common
.
tcode
!=
sa
->
packet
.
common
.
tcode
||
prev
->
packet
.
common
.
tlabel
!=
sa
->
packet
.
common
.
tlabel
)
{
/* memcmp() ? */
/* error, these should match for retries. */
}
}
list_append
(
&
t
->
request_list
,
&
sa
->
link
);
list_append
(
&
t
->
request_list
,
&
sa
->
link
);
switch
(
sa
->
ack
)
{
case
ACK_COMPLETE
:
if
(
p
->
common
.
tcode
!=
TCODE_WRITE_QUADLET
&&
p
->
common
.
tcode
!=
TCODE_WRITE_BLOCK
)
/* error, unified transactions only allowed for write */
;
list_remove
(
&
t
->
link
);
handle_transaction
(
t
);
break
;
switch
(
sa
->
ack
)
{
case
ACK_COMPLETE
:
if
(
p
->
common
.
tcode
!=
TCODE_WRITE_QUADLET
&&
p
->
common
.
tcode
!=
TCODE_WRITE_BLOCK
)
/* error, unified transactions only allowed for write */
;
list_remove
(
&
t
->
link
);
handle_transaction
(
t
);
break
;
case
ACK_NO_ACK
:
case
ACK_DATA_ERROR
:
case
ACK_TYPE_ERROR
:
list_remove
(
&
t
->
link
);
handle_transaction
(
t
);
break
;
case
ACK_NO_ACK
:
case
ACK_DATA_ERROR
:
case
ACK_TYPE_ERROR
:
list_remove
(
&
t
->
link
);
handle_transaction
(
t
);
break
;
case
ACK_PENDING
:
/* request subaction phase over, wait for response. */
break
;
case
ACK_BUSY_X
:
case
ACK_BUSY_A
:
case
ACK_BUSY_B
:
/* ok, wait for retry. */
/* check that retry protocol is respected. */
break
;
}
case
ACK_PENDING
:
/* request subaction phase over, wait for response. */
break
;
return
1
;
}
case
ACK_BUSY_X
:
case
ACK_BUSY_A
:
case
ACK_BUSY_B
:
/* ok, wait for retry. */
/* check that retry protocol is respected. */
break
;
}
break
;
static
int
handle_response_packet
(
uint32_t
*
data
,
size_t
length
)
{
struct
link_packet
*
p
=
(
struct
link_packet
*
)
data
;
struct
subaction
*
sa
,
*
prev
;
struct
link_transaction
*
t
;
case
PACKET_RESPONSE
:
t
=
link_transaction_lookup
(
p
->
common
.
destination
,
p
->
common
.
source
,
p
->
common
.
tlabel
);
if
(
list_empty
(
&
t
->
request_list
))
{
/* unsolicited response */
}
t
=
link_transaction_lookup
(
p
->
common
.
destination
,
p
->
common
.
source
,
p
->
common
.
tlabel
);
if
(
list_empty
(
&
t
->
request_list
))
{
/* unsolicited response */
}
sa
=
subaction_create
(
data
,
length
);
t
->
response
=
sa
;
sa
=
subaction_create
(
data
,
length
);
t
->
response
=
sa
;
if
(
!
list_empty
(
&
t
->
response_list
))
{
prev
=
list_tail
(
&
t
->
response_list
,
struct
subaction
,
link
);
if
(
!
list_empty
(
&
t
->
response_list
))
{
prev
=
list_tail
(
&
t
->
response_list
,
struct
subaction
,
link
);
if
(
!
ACK_BUSY
(
prev
->
ack
))
{
/*
* error, we should only see ack_busy_* before the
* ack_pending/ack_complete
*/
}
if
(
!
ACK_BUSY
(
prev
->
ack
))
{
/*
* error, we should only see ack_busy_* before the
* ack_pending/ack_complete
*/
}
if
(
prev
->
packet
.
common
.
tcode
!=
sa
->
packet
.
common
.
tcode
||
prev
->
packet
.
common
.
tlabel
!=
sa
->
packet
.
common
.
tlabel
)
{
/* use memcmp() instead? */
/* error, these should match for retries. */
}
}
else
{
prev
=
list_tail
(
&
t
->
request_list
,
struct
subaction
,
link
);
if
(
prev
->
ack
!=
ACK_PENDING
)
{
/*
* error, should not get response unless last request got
* ack_pending.
*/
}
if
(
prev
->
packet
.
common
.
tcode
!=
sa
->
packet
.
common
.
tcode
||
prev
->
packet
.
common
.
tlabel
!=
sa
->
packet
.
common
.
tlabel
)
{
/* use memcmp() instead? */
/* error, these should match for retries. */
}
}
else
{
prev
=
list_tail
(
&
t
->
request_list
,
struct
subaction
,
link
);
if
(
prev
->
ack
!=
ACK_PENDING
)
{
/*
* error, should not get response unless last request got
* ack_pending.
*/
}
if
(
packet_info
[
prev
->
packet
.
common
.
tcode
].
response_tcode
!=
sa
->
packet
.
common
.
tcode
)
{
/* error, tcode mismatch */
}
}
if
(
packet_info
[
prev
->
packet
.
common
.
tcode
].
response_tcode
!=
sa
->
packet
.
common
.
tcode
)
{
/* error, tcode mismatch */
}
}
list_append
(
&
t
->
response_list
,
&
sa
->
link
);
list_append
(
&
t
->
response_list
,
&
sa
->
link
);
switch
(
sa
->
ack
)
{
case
ACK_COMPLETE
:
case
ACK_NO_ACK
:
case
ACK_DATA_ERROR
:
case
ACK_TYPE_ERROR
:
list_remove
(
&
t
->
link
);
handle_transaction
(
t
);
/* transaction complete, remove t from pending list. */
break
;
switch
(
sa
->
ack
)
{
case
ACK_COMPLETE
:
case
ACK_NO_ACK
:
case
ACK_DATA_ERROR
:
case
ACK_TYPE_ERROR
:
list_remove
(
&
t
->
link
);
handle_transaction
(
t
);
/* transaction complete, remove t from pending list. */
break
;
case
ACK_PENDING
:
/* error for responses. */
break
;
case
ACK_BUSY_X
:
case
ACK_BUSY_A
:
case
ACK_BUSY_B
:
/* no problem, wait for next retry */
break
;
}
case
ACK_PENDING
:
/* error for responses. */
break
;
return
1
;
}
case
ACK_BUSY_X
:
case
ACK_BUSY_A
:
case
ACK_BUSY_B
:
/* no problem, wait for next retry */
break
;
}
static
int
handle_packet
(
uint32_t
*
data
,
size_t
length
)
{
if
(
length
==
0
)
{
printf
(
"bus reset
\r\n
"
);
clear_pending_transaction_list
();
}
else
if
(
length
>
sizeof
(
struct
phy_packet
))
{
struct
link_packet
*
p
=
(
struct
link_packet
*
)
data
;
break
;
switch
(
packet_info
[
p
->
common
.
tcode
].
type
)
{
case
PACKET_REQUEST
:
return
handle_request_packet
(
data
,
length
);
case
PACKET_RESPONSE
:
return
handle_response_packet
(
data
,
length
);
case
PACKET_OTHER
:
case
PACKET_RESERVED
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment