Skip to content

Commit e8cd3e4

Browse files
committed
firewire: core: replace local macros with common inline functions for asynchronous packet header
This commit uses common inline functions to serialize and deserialize header of asynchronous packet. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Sakamoto <[email protected]>
1 parent 75527d8 commit e8cd3e4

File tree

1 file changed

+56
-82
lines changed

1 file changed

+56
-82
lines changed

drivers/firewire/core-transaction.c

Lines changed: 56 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,13 @@
2929
#include <asm/byteorder.h>
3030

3131
#include "core.h"
32+
#include "packet-header-definitions.h"
3233

33-
#define HEADER_PRI(pri) ((pri) << 0)
3434
#define HEADER_TCODE(tcode) ((tcode) << 4)
35-
#define HEADER_RETRY(retry) ((retry) << 8)
36-
#define HEADER_TLABEL(tlabel) ((tlabel) << 10)
37-
#define HEADER_DESTINATION(destination) ((destination) << 16)
38-
#define HEADER_SOURCE(source) ((source) << 16)
39-
#define HEADER_RCODE(rcode) ((rcode) << 12)
40-
#define HEADER_OFFSET_HIGH(offset_high) ((offset_high) << 0)
4135
#define HEADER_DATA_LENGTH(length) ((length) << 16)
42-
#define HEADER_EXTENDED_TCODE(tcode) ((tcode) << 0)
4336

44-
#define HEADER_GET_TCODE(q) (((q) >> 4) & 0x0f)
45-
#define HEADER_GET_TLABEL(q) (((q) >> 10) & 0x3f)
46-
#define HEADER_GET_RCODE(q) (((q) >> 12) & 0x0f)
47-
#define HEADER_GET_DESTINATION(q) (((q) >> 16) & 0xffff)
48-
#define HEADER_GET_SOURCE(q) (((q) >> 16) & 0xffff)
49-
#define HEADER_GET_OFFSET_HIGH(q) (((q) >> 0) & 0xffff)
50-
#define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff)
51-
#define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff)
52-
53-
#define HEADER_DESTINATION_IS_BROADCAST(q) \
54-
(((q) & HEADER_DESTINATION(0x3f)) == HEADER_DESTINATION(0x3f))
37+
#define HEADER_DESTINATION_IS_BROADCAST(header) \
38+
((async_header_get_destination(header) & 0x3f) == 0x3f)
5539

5640
#define PHY_PACKET_CONFIG 0x0
5741
#define PHY_PACKET_LINK_ON 0x1
@@ -248,28 +232,24 @@ static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
248232
} else
249233
ext_tcode = 0;
250234

251-
packet->header[0] =
252-
HEADER_RETRY(RETRY_X) |
253-
HEADER_TLABEL(tlabel) |
254-
HEADER_TCODE(tcode) |
255-
HEADER_DESTINATION(destination_id);
256-
packet->header[1] =
257-
HEADER_OFFSET_HIGH(offset >> 32) | HEADER_SOURCE(source_id);
258-
packet->header[2] =
259-
offset;
235+
async_header_set_retry(packet->header, RETRY_X);
236+
async_header_set_tlabel(packet->header, tlabel);
237+
async_header_set_tcode(packet->header, tcode);
238+
async_header_set_destination(packet->header, destination_id);
239+
async_header_set_source(packet->header, source_id);
240+
async_header_set_offset(packet->header, offset);
260241

261242
switch (tcode) {
262243
case TCODE_WRITE_QUADLET_REQUEST:
263-
packet->header[3] = *(u32 *)payload;
244+
async_header_set_quadlet_data(packet->header, *(u32 *)payload);
264245
packet->header_length = 16;
265246
packet->payload_length = 0;
266247
break;
267248

268249
case TCODE_LOCK_REQUEST:
269250
case TCODE_WRITE_BLOCK_REQUEST:
270-
packet->header[3] =
271-
HEADER_DATA_LENGTH(length) |
272-
HEADER_EXTENDED_TCODE(ext_tcode);
251+
async_header_set_data_length(packet->header, length);
252+
async_header_set_extended_tcode(packet->header, ext_tcode);
273253
packet->header_length = 16;
274254
packet->payload = payload;
275255
packet->payload_length = length;
@@ -281,9 +261,8 @@ static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
281261
break;
282262

283263
case TCODE_READ_BLOCK_REQUEST:
284-
packet->header[3] =
285-
HEADER_DATA_LENGTH(length) |
286-
HEADER_EXTENDED_TCODE(ext_tcode);
264+
async_header_set_data_length(packet->header, length);
265+
async_header_set_extended_tcode(packet->header, ext_tcode);
287266
packet->header_length = 16;
288267
packet->payload_length = 0;
289268
break;
@@ -655,7 +634,7 @@ EXPORT_SYMBOL(fw_core_remove_address_handler);
655634
struct fw_request {
656635
struct kref kref;
657636
struct fw_packet response;
658-
u32 request_header[4];
637+
u32 request_header[ASYNC_HEADER_QUADLET_COUNT];
659638
int ack;
660639
u32 timestamp;
661640
u32 length;
@@ -695,7 +674,7 @@ int fw_get_response_length(struct fw_request *r)
695674
{
696675
int tcode, ext_tcode, data_length;
697676

698-
tcode = HEADER_GET_TCODE(r->request_header[0]);
677+
tcode = async_header_get_tcode(r->request_header);
699678

700679
switch (tcode) {
701680
case TCODE_WRITE_QUADLET_REQUEST:
@@ -706,12 +685,12 @@ int fw_get_response_length(struct fw_request *r)
706685
return 4;
707686

708687
case TCODE_READ_BLOCK_REQUEST:
709-
data_length = HEADER_GET_DATA_LENGTH(r->request_header[3]);
688+
data_length = async_header_get_data_length(r->request_header);
710689
return data_length;
711690

712691
case TCODE_LOCK_REQUEST:
713-
ext_tcode = HEADER_GET_EXTENDED_TCODE(r->request_header[3]);
714-
data_length = HEADER_GET_DATA_LENGTH(r->request_header[3]);
692+
ext_tcode = async_header_get_extended_tcode(r->request_header);
693+
data_length = async_header_get_data_length(r->request_header);
715694
switch (ext_tcode) {
716695
case EXTCODE_FETCH_ADD:
717696
case EXTCODE_LITTLE_ADD:
@@ -731,46 +710,42 @@ void fw_fill_response(struct fw_packet *response, u32 *request_header,
731710
{
732711
int tcode, tlabel, extended_tcode, source, destination;
733712

734-
tcode = HEADER_GET_TCODE(request_header[0]);
735-
tlabel = HEADER_GET_TLABEL(request_header[0]);
736-
source = HEADER_GET_DESTINATION(request_header[0]);
737-
destination = HEADER_GET_SOURCE(request_header[1]);
738-
extended_tcode = HEADER_GET_EXTENDED_TCODE(request_header[3]);
739-
740-
response->header[0] =
741-
HEADER_RETRY(RETRY_1) |
742-
HEADER_TLABEL(tlabel) |
743-
HEADER_DESTINATION(destination);
744-
response->header[1] =
745-
HEADER_SOURCE(source) |
746-
HEADER_RCODE(rcode);
747-
response->header[2] = 0;
713+
tcode = async_header_get_tcode(request_header);
714+
tlabel = async_header_get_tlabel(request_header);
715+
source = async_header_get_destination(request_header); // Exchange.
716+
destination = async_header_get_source(request_header); // Exchange.
717+
extended_tcode = async_header_get_extended_tcode(request_header);
718+
719+
async_header_set_retry(response->header, RETRY_1);
720+
async_header_set_tlabel(response->header, tlabel);
721+
async_header_set_destination(response->header, destination);
722+
async_header_set_source(response->header, source);
723+
async_header_set_rcode(response->header, rcode);
724+
response->header[2] = 0; // The field is reserved.
748725

749726
switch (tcode) {
750727
case TCODE_WRITE_QUADLET_REQUEST:
751728
case TCODE_WRITE_BLOCK_REQUEST:
752-
response->header[0] |= HEADER_TCODE(TCODE_WRITE_RESPONSE);
729+
async_header_set_tcode(response->header, TCODE_WRITE_RESPONSE);
753730
response->header_length = 12;
754731
response->payload_length = 0;
755732
break;
756733

757734
case TCODE_READ_QUADLET_REQUEST:
758-
response->header[0] |=
759-
HEADER_TCODE(TCODE_READ_QUADLET_RESPONSE);
735+
async_header_set_tcode(response->header, TCODE_READ_QUADLET_RESPONSE);
760736
if (payload != NULL)
761-
response->header[3] = *(u32 *)payload;
737+
async_header_set_quadlet_data(response->header, *(u32 *)payload);
762738
else
763-
response->header[3] = 0;
739+
async_header_set_quadlet_data(response->header, 0);
764740
response->header_length = 16;
765741
response->payload_length = 0;
766742
break;
767743

768744
case TCODE_READ_BLOCK_REQUEST:
769745
case TCODE_LOCK_REQUEST:
770-
response->header[0] |= HEADER_TCODE(tcode + 2);
771-
response->header[3] =
772-
HEADER_DATA_LENGTH(length) |
773-
HEADER_EXTENDED_TCODE(extended_tcode);
746+
async_header_set_tcode(response->header, tcode + 2);
747+
async_header_set_data_length(response->header, length);
748+
async_header_set_extended_tcode(response->header, extended_tcode);
774749
response->header_length = 16;
775750
response->payload = payload;
776751
response->payload_length = length;
@@ -807,7 +782,7 @@ static struct fw_request *allocate_request(struct fw_card *card,
807782
u32 *data, length;
808783
int request_tcode;
809784

810-
request_tcode = HEADER_GET_TCODE(p->header[0]);
785+
request_tcode = async_header_get_tcode(p->header);
811786
switch (request_tcode) {
812787
case TCODE_WRITE_QUADLET_REQUEST:
813788
data = &p->header[3];
@@ -817,7 +792,7 @@ static struct fw_request *allocate_request(struct fw_card *card,
817792
case TCODE_WRITE_BLOCK_REQUEST:
818793
case TCODE_LOCK_REQUEST:
819794
data = p->payload;
820-
length = HEADER_GET_DATA_LENGTH(p->header[3]);
795+
length = async_header_get_data_length(p->header);
821796
break;
822797

823798
case TCODE_READ_QUADLET_REQUEST:
@@ -827,7 +802,7 @@ static struct fw_request *allocate_request(struct fw_card *card,
827802

828803
case TCODE_READ_BLOCK_REQUEST:
829804
data = NULL;
830-
length = HEADER_GET_DATA_LENGTH(p->header[3]);
805+
length = async_header_get_data_length(p->header);
831806
break;
832807

833808
default:
@@ -872,7 +847,7 @@ void fw_send_response(struct fw_card *card,
872847
{
873848
/* unified transaction or broadcast transaction: don't respond */
874849
if (request->ack != ACK_PENDING ||
875-
HEADER_DESTINATION_IS_BROADCAST(request->request_header[0])) {
850+
HEADER_DESTINATION_IS_BROADCAST(request->request_header)) {
876851
fw_request_put(request);
877852
return;
878853
}
@@ -926,11 +901,11 @@ static void handle_exclusive_region_request(struct fw_card *card,
926901
struct fw_address_handler *handler;
927902
int tcode, destination, source;
928903

929-
destination = HEADER_GET_DESTINATION(p->header[0]);
930-
source = HEADER_GET_SOURCE(p->header[1]);
931-
tcode = HEADER_GET_TCODE(p->header[0]);
904+
destination = async_header_get_destination(p->header);
905+
source = async_header_get_source(p->header);
906+
tcode = async_header_get_tcode(p->header);
932907
if (tcode == TCODE_LOCK_REQUEST)
933-
tcode = 0x10 + HEADER_GET_EXTENDED_TCODE(p->header[3]);
908+
tcode = 0x10 + async_header_get_extended_tcode(p->header);
934909

935910
rcu_read_lock();
936911
handler = lookup_enclosing_address_handler(&address_handler_list,
@@ -963,9 +938,9 @@ static void handle_fcp_region_request(struct fw_card *card,
963938
return;
964939
}
965940

966-
tcode = HEADER_GET_TCODE(p->header[0]);
967-
destination = HEADER_GET_DESTINATION(p->header[0]);
968-
source = HEADER_GET_SOURCE(p->header[1]);
941+
tcode = async_header_get_tcode(p->header);
942+
destination = async_header_get_destination(p->header);
943+
source = async_header_get_source(p->header);
969944

970945
if (tcode != TCODE_WRITE_QUADLET_REQUEST &&
971946
tcode != TCODE_WRITE_BLOCK_REQUEST) {
@@ -997,7 +972,7 @@ void fw_core_handle_request(struct fw_card *card, struct fw_packet *p)
997972
if (p->ack != ACK_PENDING && p->ack != ACK_COMPLETE)
998973
return;
999974

1000-
if (TCODE_IS_LINK_INTERNAL(HEADER_GET_TCODE(p->header[0]))) {
975+
if (TCODE_IS_LINK_INTERNAL(async_header_get_tcode(p->header))) {
1001976
fw_cdev_handle_phy_packet(card, p);
1002977
return;
1003978
}
@@ -1008,8 +983,7 @@ void fw_core_handle_request(struct fw_card *card, struct fw_packet *p)
1008983
return;
1009984
}
1010985

1011-
offset = ((u64)HEADER_GET_OFFSET_HIGH(p->header[1]) << 32) |
1012-
p->header[2];
986+
offset = async_header_get_offset(p->header);
1013987

1014988
if (!is_in_fcp_region(offset, request->length))
1015989
handle_exclusive_region_request(card, p, request, offset);
@@ -1027,10 +1001,10 @@ void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
10271001
size_t data_length;
10281002
int tcode, tlabel, source, rcode;
10291003

1030-
tcode = HEADER_GET_TCODE(p->header[0]);
1031-
tlabel = HEADER_GET_TLABEL(p->header[0]);
1032-
source = HEADER_GET_SOURCE(p->header[1]);
1033-
rcode = HEADER_GET_RCODE(p->header[1]);
1004+
tcode = async_header_get_tcode(p->header);
1005+
tlabel = async_header_get_tlabel(p->header);
1006+
source = async_header_get_source(p->header);
1007+
rcode = async_header_get_rcode(p->header);
10341008

10351009
spin_lock_irqsave(&card->lock, flags);
10361010
list_for_each_entry(iter, &card->transaction_list, link) {
@@ -1073,7 +1047,7 @@ void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
10731047
case TCODE_READ_BLOCK_RESPONSE:
10741048
case TCODE_LOCK_RESPONSE:
10751049
data = p->payload;
1076-
data_length = HEADER_GET_DATA_LENGTH(p->header[3]);
1050+
data_length = async_header_get_data_length(p->header);
10771051
break;
10781052

10791053
default:

0 commit comments

Comments
 (0)