From nobody Sun Sep 14 10:17:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F745C77B7A for ; Mon, 29 May 2023 11:35:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbjE2Lfc (ORCPT ); Mon, 29 May 2023 07:35:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231478AbjE2LfW (ORCPT ); Mon, 29 May 2023 07:35:22 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13A3DE0 for ; Mon, 29 May 2023 04:34:55 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 8C4DF320093D; Mon, 29 May 2023 07:34:37 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 29 May 2023 07:34:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685360077; x= 1685446477; bh=CwMQ3mRgLz5XKiLhS8Bwc8Qm3NwjUti4uZQkCUexV3s=; b=V LGXMcp4ht63Clh35SxVozb6VFsiRHdaUNdo/RlE5pwuoyuK5Z6Tt+29HiJD+02TV kJ7TwOw3ZErysVCDPK1NlBfWygR82xnO6BV5BpQDlUkpix5qvKYiTgfen+jqL/4U UfN6qd0+6MCyRzWMHoJRl6q8Lkhc+88ioxOpVju37vEIlgBgVM3/dbq65fnWSZSJ bwE05tV545c/noUtZVdbN/Dh8n8sK/QiU3qyFRRxw26qVEW7RCPz2mKOG3jc2Z4z 6rq3e5A+7wQkEL7H92nrJAY5PsEKzNgmNH/ijEXfIy4UZxF4dleT+Vhrn79zcrA2 7G0tZTMguGXxv5JAfhGiQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1685360077; x=1685446477; bh=C wMQ3mRgLz5XKiLhS8Bwc8Qm3NwjUti4uZQkCUexV3s=; b=WmWPabBhTVuCAushw 3v5jJwLROWfCyXLe3wqDCLrgheYHcLC+06904VXoc0+ufYc8nJnvBCLts29SiQkN XQSOL3BI/LpE2F9maHT4Ukk9gk8/74vSTie2bWLi9KfWVQFmqFIyY/cpzmXjAy+a AUxRdTXOnl9cdNL4xK+m253WGeinqk6JSCZmZSNBoLsrv7hPpPNj4RkV6hiFEsz6 PipHBRo8LCm8wP0hPUZ0V0tcO84nKIaISzAi24sDiWzNmq9UyCEpy79pem1TK4Gv xhxmQ3Dvp7jQqDob4BM8Q/9gL6D1F+143feO/EOkL4dTe6Te+iV/eFWlksEwc+k0 CFNOA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:36 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3 12/12] firewire: cdev: implement new event relevant to phy packet with time stamp Date: Mon, 29 May 2023 20:34:06 +0900 Message-Id: <20230529113406.986289-13-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In 1394 OHCI, the OUTPUT_LAST descriptor of Asynchronous Transmit (AT) context has timeStamp field, in which 1394 OHCI controller record the isochronous cycle when the packet was sent for the request subaction. Additionally, the trailing quadlet of Asynchronous Receive (AR) context has timeStamp field as well in which 1394 OHCI controller record the isochronous cycle when the packet arrived. The time stamps are also available for the cases to send and receive phy packet. This commit implements new events with time stamp field for user space. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 90 +++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 2220de3c945e..6274b86eb943 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -206,6 +206,7 @@ struct outbound_phy_packet_event { struct fw_packet p; union { struct fw_cdev_event_phy_packet without_tstamp; + struct fw_cdev_event_phy_packet2 with_tstamp; } phy_packet; }; =20 @@ -213,6 +214,7 @@ struct inbound_phy_packet_event { struct event event; union { struct fw_cdev_event_phy_packet without_tstamp; + struct fw_cdev_event_phy_packet2 with_tstamp; } phy_packet; }; =20 @@ -1555,7 +1557,6 @@ static void outbound_phy_packet_callback(struct fw_pa= cket *packet, container_of(packet, struct outbound_phy_packet_event, p); struct client *e_client =3D e->client; u32 rcode; - struct fw_cdev_event_phy_packet *pp; =20 switch (status) { // expected: @@ -1583,10 +1584,31 @@ static void outbound_phy_packet_callback(struct fw_= packet *packet, break; } =20 - pp =3D &e->phy_packet.without_tstamp; - pp->rcode =3D rcode; - pp->data[0] =3D packet->timestamp; - queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->lengt= h, NULL, 0); + switch (e->phy_packet.without_tstamp.type) { + case FW_CDEV_EVENT_PHY_PACKET_SENT: + { + struct fw_cdev_event_phy_packet *pp =3D &e->phy_packet.without_tstamp; + + pp->rcode =3D rcode; + pp->data[0] =3D packet->timestamp; + queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->leng= th, + NULL, 0); + break; + } + case FW_CDEV_EVENT_PHY_PACKET_SENT2: + { + struct fw_cdev_event_phy_packet2 *pp =3D &e->phy_packet.with_tstamp; + + pp->rcode =3D rcode; + pp->tstamp =3D packet->timestamp; + queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->leng= th, + NULL, 0); + break; + } + default: + WARN_ON(1); + break; + } =20 client_put(e_client); } @@ -1596,13 +1618,12 @@ static int ioctl_send_phy_packet(struct client *cli= ent, union ioctl_arg *arg) struct fw_cdev_send_phy_packet *a =3D &arg->send_phy_packet; struct fw_card *card =3D client->device->card; struct outbound_phy_packet_event *e; - struct fw_cdev_event_phy_packet *pp; =20 /* Access policy: Allow this ioctl only on local nodes' device files. */ if (!client->device->is_local) return -ENOSYS; =20 - e =3D kzalloc(sizeof(*e) + 4, GFP_KERNEL); + e =3D kzalloc(sizeof(*e) + sizeof(a->data), GFP_KERNEL); if (e =3D=3D NULL) return -ENOMEM; =20 @@ -1616,11 +1637,23 @@ static int ioctl_send_phy_packet(struct client *cli= ent, union ioctl_arg *arg) e->p.header_length =3D 12; e->p.callback =3D outbound_phy_packet_callback; =20 - pp =3D &e->phy_packet.without_tstamp; - pp->closure =3D a->closure; - pp->type =3D FW_CDEV_EVENT_PHY_PACKET_SENT; - if (is_ping_packet(a->data)) - pp->length =3D 4; + if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { + struct fw_cdev_event_phy_packet *pp =3D &e->phy_packet.without_tstamp; + + pp->closure =3D a->closure; + pp->type =3D FW_CDEV_EVENT_PHY_PACKET_SENT; + if (is_ping_packet(a->data)) + pp->length =3D 4; + } else { + struct fw_cdev_event_phy_packet2 *pp =3D &e->phy_packet.with_tstamp; + + pp->closure =3D a->closure; + pp->type =3D FW_CDEV_EVENT_PHY_PACKET_SENT2; + // Keep the data field so that application can match the response event = to the + // request. + pp->length =3D sizeof(a->data); + memcpy(pp->data, a->data, sizeof(a->data)); + } =20 card->driver->send_request(card, &e->p); =20 @@ -1655,20 +1688,33 @@ void fw_cdev_handle_phy_packet(struct fw_card *card= , struct fw_packet *p) spin_lock_irqsave(&card->lock, flags); =20 list_for_each_entry(client, &card->phy_receiver_list, phy_receiver_link) { - struct fw_cdev_event_phy_packet *pp; - e =3D kmalloc(sizeof(*e) + 8, GFP_ATOMIC); if (e =3D=3D NULL) break; =20 - pp =3D &e->phy_packet.without_tstamp; - pp->closure =3D client->phy_receiver_closure; - pp->type =3D FW_CDEV_EVENT_PHY_PACKET_RECEIVED; - pp->rcode =3D RCODE_COMPLETE; - pp->length =3D 8; - pp->data[0] =3D p->header[1]; - pp->data[1] =3D p->header[2]; - queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0); + if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { + struct fw_cdev_event_phy_packet *pp =3D &e->phy_packet.without_tstamp; + + pp->closure =3D client->phy_receiver_closure; + pp->type =3D FW_CDEV_EVENT_PHY_PACKET_RECEIVED; + pp->rcode =3D RCODE_COMPLETE; + pp->length =3D 8; + pp->data[0] =3D p->header[1]; + pp->data[1] =3D p->header[2]; + queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0= ); + } else { + struct fw_cdev_event_phy_packet2 *pp =3D &e->phy_packet.with_tstamp; + + pp =3D &e->phy_packet.with_tstamp; + pp->closure =3D client->phy_receiver_closure; + pp->type =3D FW_CDEV_EVENT_PHY_PACKET_RECEIVED2; + pp->rcode =3D RCODE_COMPLETE; + pp->length =3D 8; + pp->tstamp =3D p->timestamp; + pp->data[0] =3D p->header[1]; + pp->data[1] =3D p->header[2]; + queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0= ); + } } =20 spin_unlock_irqrestore(&card->lock, flags); --=20 2.39.2