Commit 36bfe49d authored by Kristian Høgsberg's avatar Kristian Høgsberg Committed by Stefan Richter

firewire: Clean up response handling.

Signed-off-by: default avatarKristian Høgsberg <krh@redhat.com>
Signed-off-by: default avatarStefan Richter <stefanr@s5r6.in-berlin.de>
parent e636fe25
...@@ -107,9 +107,9 @@ transmit_complete_callback(struct fw_packet *packet, ...@@ -107,9 +107,9 @@ transmit_complete_callback(struct fw_packet *packet,
} }
static void static void
fw_fill_packet(struct fw_packet *packet, int tcode, int tlabel, fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
int node_id, int generation, int speed, int node_id, int generation, int speed,
unsigned long long offset, void *payload, size_t length) unsigned long long offset, void *payload, size_t length)
{ {
int ext_tcode; int ext_tcode;
...@@ -240,8 +240,8 @@ fw_send_request(struct fw_card *card, struct fw_transaction *t, ...@@ -240,8 +240,8 @@ fw_send_request(struct fw_card *card, struct fw_transaction *t,
t->callback = callback; t->callback = callback;
t->callback_data = callback_data; t->callback_data = callback_data;
fw_fill_packet(&t->packet, tcode, t->tlabel, fw_fill_request(&t->packet, tcode, t->tlabel,
node_id, generation, speed, offset, payload, length); node_id, generation, speed, offset, payload, length);
t->packet.callback = transmit_complete_callback; t->packet.callback = transmit_complete_callback;
card->driver->send_request(card, &t->packet); card->driver->send_request(card, &t->packet);
...@@ -409,6 +409,7 @@ EXPORT_SYMBOL(fw_core_remove_address_handler); ...@@ -409,6 +409,7 @@ EXPORT_SYMBOL(fw_core_remove_address_handler);
struct fw_request { struct fw_request {
struct fw_packet response; struct fw_packet response;
u32 request_header[4];
int ack; int ack;
u32 length; u32 length;
u32 data[0]; u32 data[0];
...@@ -425,22 +426,24 @@ free_response_callback(struct fw_packet *packet, ...@@ -425,22 +426,24 @@ free_response_callback(struct fw_packet *packet,
} }
static void static void
fw_fill_response(struct fw_packet *response, fw_fill_response(struct fw_packet *response, u32 *request_header,
struct fw_packet *request, void *data) int rcode, void *payload, size_t length)
{ {
int tcode, tlabel, extended_tcode, source, destination; int tcode, tlabel, extended_tcode, source, destination;
tcode = header_get_tcode(request->header[0]); tcode = header_get_tcode(request_header[0]);
tlabel = header_get_tlabel(request->header[0]); tlabel = header_get_tlabel(request_header[0]);
source = header_get_destination(request->header[0]); source = header_get_destination(request_header[0]);
destination = header_get_source(request->header[1]); destination = header_get_source(request_header[1]);
extended_tcode = header_get_extended_tcode(request->header[3]); extended_tcode = header_get_extended_tcode(request_header[3]);
response->header[0] = response->header[0] =
header_retry(RETRY_1) | header_retry(RETRY_1) |
header_tlabel(tlabel) | header_tlabel(tlabel) |
header_destination(destination); header_destination(destination);
response->header[1] = header_source(source); response->header[1] =
header_source(source) |
header_rcode(rcode);
response->header[2] = 0; response->header[2] = 0;
switch (tcode) { switch (tcode) {
...@@ -454,7 +457,7 @@ fw_fill_response(struct fw_packet *response, ...@@ -454,7 +457,7 @@ fw_fill_response(struct fw_packet *response,
case TCODE_READ_QUADLET_REQUEST: case TCODE_READ_QUADLET_REQUEST:
response->header[0] |= response->header[0] |=
header_tcode(TCODE_READ_QUADLET_RESPONSE); header_tcode(TCODE_READ_QUADLET_RESPONSE);
response->header[3] = 0; response->header[3] = *(u32 *)payload;
response->header_length = 16; response->header_length = 16;
response->payload_length = 0; response->payload_length = 0;
break; break;
...@@ -463,11 +466,11 @@ fw_fill_response(struct fw_packet *response, ...@@ -463,11 +466,11 @@ fw_fill_response(struct fw_packet *response,
case TCODE_LOCK_REQUEST: case TCODE_LOCK_REQUEST:
response->header[0] |= header_tcode(tcode + 2); response->header[0] |= header_tcode(tcode + 2);
response->header[3] = response->header[3] =
header_data_length(request->payload_length) | header_data_length(length) |
header_extended_tcode(extended_tcode); header_extended_tcode(extended_tcode);
response->header_length = 16; response->header_length = 16;
response->payload = data; response->payload = payload;
response->payload_length = request->payload_length; response->payload_length = length;
break; break;
default: default:
...@@ -530,7 +533,7 @@ allocate_request(struct fw_packet *p) ...@@ -530,7 +533,7 @@ allocate_request(struct fw_packet *p)
if (data) if (data)
memcpy(request->data, p->payload, p->payload_length); memcpy(request->data, p->payload, p->payload_length);
fw_fill_response(&request->response, p, request->data); memcpy(request->request_header, p->header, sizeof p->header);
return request; return request;
} }
...@@ -538,21 +541,18 @@ allocate_request(struct fw_packet *p) ...@@ -538,21 +541,18 @@ allocate_request(struct fw_packet *p)
void void
fw_send_response(struct fw_card *card, struct fw_request *request, int rcode) fw_send_response(struct fw_card *card, struct fw_request *request, int rcode)
{ {
int response_tcode;
/* Broadcast packets are reported as ACK_COMPLETE, so this /* Broadcast packets are reported as ACK_COMPLETE, so this
* check is sufficient to ensure we don't send response to * check is sufficient to ensure we don't send response to
* broadcast packets or posted writes. */ * broadcast packets or posted writes. */
if (request->ack != ACK_PENDING) if (request->ack != ACK_PENDING)
return; return;
request->response.header[1] |= header_rcode(rcode); if (rcode == RCODE_COMPLETE)
response_tcode = header_get_tcode(request->response.header[0]); fw_fill_response(&request->response, request->request_header,
if (rcode != RCODE_COMPLETE) rcode, request->data, request->length);
/* Clear the data_length field. */ else
request->response.header[3] &= 0xffff; fw_fill_response(&request->response, request->request_header,
else if (response_tcode == TCODE_READ_QUADLET_RESPONSE) rcode, NULL, 0);
request->response.header[3] = request->data[0];
card->driver->send_response(card, &request->response); card->driver->send_response(card, &request->response);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment