Commit d8527cab authored by Takashi Sakamoto's avatar Takashi Sakamoto

firewire: cdev: implement new event to notify response subaction with time stamp

The callback function now receives an argument for time stamps relevant
to asynchronous transaction. This commit implements a new event to
notify response subaction with the time stamps for user space.

Link: https://lore.kernel.org/r/20230529113406.986289-10-o-takashi@sakamocchi.jpSigned-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
parent fc2b52cf
...@@ -172,6 +172,7 @@ struct outbound_transaction_event { ...@@ -172,6 +172,7 @@ struct outbound_transaction_event {
struct outbound_transaction_resource r; struct outbound_transaction_resource r;
union { union {
struct fw_cdev_event_response without_tstamp; struct fw_cdev_event_response without_tstamp;
struct fw_cdev_event_response2 with_tstamp;
} rsp; } rsp;
}; };
...@@ -538,41 +539,64 @@ static void release_transaction(struct client *client, ...@@ -538,41 +539,64 @@ static void release_transaction(struct client *client,
{ {
} }
static void complete_transaction(struct fw_card *card, int rcode, static void complete_transaction(struct fw_card *card, int rcode, u32 request_tstamp,
void *payload, size_t length, void *data) u32 response_tstamp, void *payload, size_t length, void *data)
{ {
struct outbound_transaction_event *e = data; struct outbound_transaction_event *e = data;
struct fw_cdev_event_response *rsp = &e->rsp.without_tstamp;
struct client *client = e->client; struct client *client = e->client;
unsigned long flags; unsigned long flags;
if (length < rsp->length)
rsp->length = length;
if (rcode == RCODE_COMPLETE)
memcpy(rsp->data, payload, rsp->length);
spin_lock_irqsave(&client->lock, flags); spin_lock_irqsave(&client->lock, flags);
idr_remove(&client->resource_idr, e->r.resource.handle); idr_remove(&client->resource_idr, e->r.resource.handle);
if (client->in_shutdown) if (client->in_shutdown)
wake_up(&client->tx_flush_wait); wake_up(&client->tx_flush_wait);
spin_unlock_irqrestore(&client->lock, flags); spin_unlock_irqrestore(&client->lock, flags);
rsp->type = FW_CDEV_EVENT_RESPONSE; switch (e->rsp.without_tstamp.type) {
rsp->rcode = rcode; case FW_CDEV_EVENT_RESPONSE:
{
struct fw_cdev_event_response *rsp = &e->rsp.without_tstamp;
if (length < rsp->length)
rsp->length = length;
if (rcode == RCODE_COMPLETE)
memcpy(rsp->data, payload, rsp->length);
rsp->rcode = rcode;
// In the case that sizeof(*rsp) doesn't align with the position of the
// data, and the read is short, preserve an extra copy of the data
// to stay compatible with a pre-2.6.27 bug. Since the bug is harmless
// for short reads and some apps depended on it, this is both safe
// and prudent for compatibility.
if (rsp->length <= sizeof(*rsp) - offsetof(typeof(*rsp), data))
queue_event(client, &e->event, rsp, sizeof(*rsp), rsp->data, rsp->length);
else
queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, NULL, 0);
/* break;
* In the case that sizeof(*rsp) doesn't align with the position of the }
* data, and the read is short, preserve an extra copy of the data case FW_CDEV_EVENT_RESPONSE2:
* to stay compatible with a pre-2.6.27 bug. Since the bug is harmless {
* for short reads and some apps depended on it, this is both safe struct fw_cdev_event_response2 *rsp = &e->rsp.with_tstamp;
* and prudent for compatibility.
*/ if (length < rsp->length)
if (rsp->length <= sizeof(*rsp) - offsetof(typeof(*rsp), data)) rsp->length = length;
queue_event(client, &e->event, rsp, sizeof(*rsp), if (rcode == RCODE_COMPLETE)
rsp->data, rsp->length); memcpy(rsp->data, payload, rsp->length);
else
queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, rsp->rcode = rcode;
NULL, 0); rsp->request_tstamp = request_tstamp;
rsp->response_tstamp = response_tstamp;
queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, NULL, 0);
break;
default:
WARN_ON(1);
break;
}
}
/* Drop the idr's reference */ /* Drop the idr's reference */
client_put(client); client_put(client);
...@@ -583,7 +607,6 @@ static int init_request(struct client *client, ...@@ -583,7 +607,6 @@ static int init_request(struct client *client,
int destination_id, int speed) int destination_id, int speed)
{ {
struct outbound_transaction_event *e; struct outbound_transaction_event *e;
struct fw_cdev_event_response *rsp;
void *payload; void *payload;
int ret; int ret;
...@@ -600,10 +623,21 @@ static int init_request(struct client *client, ...@@ -600,10 +623,21 @@ static int init_request(struct client *client,
return -ENOMEM; return -ENOMEM;
e->client = client; e->client = client;
rsp = &e->rsp.without_tstamp; if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) {
rsp->length = request->length; struct fw_cdev_event_response *rsp = &e->rsp.without_tstamp;
rsp->closure = request->closure;
payload = rsp->data; rsp->type = FW_CDEV_EVENT_RESPONSE;
rsp->length = request->length;
rsp->closure = request->closure;
payload = rsp->data;
} else {
struct fw_cdev_event_response2 *rsp = &e->rsp.with_tstamp;
rsp->type = FW_CDEV_EVENT_RESPONSE2;
rsp->length = request->length;
rsp->closure = request->closure;
payload = rsp->data;
}
if (request->data && copy_from_user(payload, u64_to_uptr(request->data), request->length)) { if (request->data && copy_from_user(payload, u64_to_uptr(request->data), request->length)) {
ret = -EFAULT; ret = -EFAULT;
...@@ -615,9 +649,9 @@ static int init_request(struct client *client, ...@@ -615,9 +649,9 @@ static int init_request(struct client *client,
if (ret < 0) if (ret < 0)
goto failed; goto failed;
fw_send_request(client->device->card, &e->r.transaction, request->tcode, destination_id, fw_send_request_with_tstamp(client->device->card, &e->r.transaction, request->tcode,
request->generation, speed, request->offset, payload, request->length, destination_id, request->generation, speed, request->offset,
complete_transaction, e); payload, request->length, complete_transaction, e);
return 0; return 0;
failed: failed:
......
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