Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2617410pxb; Sun, 17 Oct 2021 20:39:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypcCDZTx+hKGqvDLZWZCw/EqW0pJ0Svuhv6hF6SoTzquJt8uZwRZOZdEVfkotpWzAJe7RF X-Received: by 2002:a62:1d46:0:b0:44d:1a4d:5d03 with SMTP id d67-20020a621d46000000b0044d1a4d5d03mr26307420pfd.55.1634528341917; Sun, 17 Oct 2021 20:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528341; cv=none; d=google.com; s=arc-20160816; b=iyl0aMo70FFPTreOyTGES+7K5ThtcvUp5katwEvdUCf8Daywc2lTi5UtFY3ZTgR20M eMMa7VQCCSG3cKilZ/DQb0M12Gq2sU7z7PRxF83k1KyLuK/PC+isEiv8gDrhZhHuQNHh o9bJvBHNDsWcdTvyUps19PQhJoIv3k45pEcnw4GKJeHkuhHirLuBZ/kTYlm6n7ljdpDX nL00uQCyd9uMr52sBaZ8SCbP3mINrEZe1NmScggRApQ+f1ec6+haqzOLf6B5uF7d57fL RkE9r+Ud20CUOfl9J2QiONDNADYIvJrDSfmPQvosBhPIFYlVuVyDX22IGLIKsGPFm8AS IP8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:dkim-signature:dkim-signature; bh=p+3fJpf6HsLcqnYgYGZWWNKUWfCVk/9sOVpR4wT6xDE=; b=AepO2kKjrPG8WJJmlMoJjFx+FyGjYpAOy6uoLU6AF53YroDgW+Mcj/Dnknf+RRaoKS 9i4lL887fuBj/DqMh5xSkGtozDYHgcAJT+tEK1rp8du8JuZ5PZS++HVDViwGit/xV7Ii rtfEHKCvQOfgnOl50N3++8peK8x6dEjxsV4eQ8hOn8kGGcxk6aLUkggetY4p+eA/sYA1 L2j1gdBb7UTlqEfbvSi8Qbxy4tINVEHIKs+sVuFm2Jcz818HT2MyP7zzUTQ27BgaJtzb rNjesWoxeoo76qxs6tffOhpcp8Cuk50bM+3C9E9CS9vDbw+y17DCeCkWB1MWSke5nu1r /0FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm2 header.b=iyM6Cgwi; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=maLpXOgC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v185si3721470pgd.18.2021.10.17.20.38.47; Sun, 17 Oct 2021 20:39:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm2 header.b=iyM6Cgwi; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=maLpXOgC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240888AbhJPTUQ (ORCPT + 98 others); Sat, 16 Oct 2021 15:20:16 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:39833 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232336AbhJPTUP (ORCPT ); Sat, 16 Oct 2021 15:20:15 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id EC7FE5C00B9; Sat, 16 Oct 2021 15:18:02 -0400 (EDT) Received: from imap47 ([10.202.2.97]) by compute1.internal (MEProxy); Sat, 16 Oct 2021 15:18:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=mime-version:message-id:in-reply-to:references:date:from:to :cc:subject:content-type; s=fm2; bh=p+3fJpf6HsLcqnYgYGZWWNKUWfCV k/9sOVpR4wT6xDE=; b=iyM6CgwiL8L4K3qxv8twtQsIHtWyStR0Pkaug/vgOMfX y/9TPdhVHmNLQkLVVU2L+huLud9vyzygfLAE+a+iZFEiPlHAy1+RJwgSFFQ/6e9p //my73qVLbjzG02ciupQ/C4TCuKxIbwHOF5EnyCcHaaYbJt3rJ0eZGr2EbdSyhFP //rw8s0InEaiptLEXgp4xLLcQX8gyab9f7eL+DOx1cCHBHuk38QDyaIExROhqI5t 03ZMiQj3qddFWMH8pNRJ/J+gnKHGL6yZVdZ37zwiDXhKk4eSBRd+O3MJDUh/Kkyk QDnC3IDR9NlUZEkwiMuTIoXZUZQlyxVYVNavQ+slEw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=p+3fJp f6HsLcqnYgYGZWWNKUWfCVk/9sOVpR4wT6xDE=; b=maLpXOgCpJEVD49lPeN4l0 2ijgKcNsDvU0qQUVRRiMhzGgPS5YfeK1IGBTEoxGjqTsZ32GPcvrIV6HXmQAkrl3 2E3Tft+VcuY7LEncgbP2zfrL/kOdpTgu/2cncBCbmLB0Nta/SLiR2O9AZ/Tj3MzM iLqVgrqASaWpozepL8WqIdtrteL7iBZ/5xMcLMxe+P03oDw4mwITmRbBHU+7TeSb Lic3A0Eknm1PbwdVkd5iah8AcUW0CrCUhp2DsF012j0CfVmrUpKlhK875gimmaih bO+tARmYC+5vvQFY/ItFQOlzRPvpRWTZgOlU/vyZQ3oFtPPzZ1JVYb1hc4sDFh1w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvdduiedguddvlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfufhv vghnucfrvghtvghrfdcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrf grthhtvghrnhepvedvgeevuddvvedvgfelfeegiedvgeehieeutdelvedvieevveeljeef vedtleehnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehsvhgvnhesshhvvghnphgvthgvrhdr uggvvh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 681BB2740061; Sat, 16 Oct 2021 15:18:02 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-1345-g8441cd7852-fm-20211006.001-g8441cd78 Mime-Version: 1.0 Message-Id: <33b20615-14bb-49e7-ac2a-4bfdfabeaaa4@www.fastmail.com> In-Reply-To: References: <20210916154911.3168-1-sven@svenpeter.dev> <20210916154911.3168-3-sven@svenpeter.dev> Date: Sat, 16 Oct 2021 21:17:41 +0200 From: "Sven Peter" To: "Jassi Brar" Cc: "Rob Herring" , "Mark Kettenis" , "Hector Martin" , "Alyssa Rosenzweig" , "Mohamed Mediouni" , "Stan Skowronek" , "Devicetree List" , linux-arm-kernel , "Linux Kernel Mailing List" Subject: Re: [PATCH v2 2/2] mailbox: apple: Add driver for Apple mailboxes Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jassi, Thanks a lot for the review! On Sat, Oct 16, 2021, at 21:04, Jassi Brar wrote: > On Thu, Sep 16, 2021 at 10:49 AM Sven Peter wrote: > > .... >> +static const struct apple_mbox_hw apple_mbox_asc_hw = { >> + .control_full = APPLE_ASC_MBOX_CONTROL_FULL, >> + .control_empty = APPLE_ASC_MBOX_CONTROL_EMPTY, >> + >> + .a2i_control = APPLE_ASC_MBOX_A2I_CONTROL, >> + .a2i_send0 = APPLE_ASC_MBOX_A2I_SEND0, >> + .a2i_send1 = APPLE_ASC_MBOX_A2I_SEND1, >> + >> + .i2a_control = APPLE_ASC_MBOX_I2A_CONTROL, >> + .i2a_recv0 = APPLE_ASC_MBOX_I2A_RECV0, >> + .i2a_recv1 = APPLE_ASC_MBOX_I2A_RECV1, >> + >> + .has_irq_controls = false, >> +}; >> + >> +static const struct apple_mbox_hw apple_mbox_m3_hw = { >> + .control_full = APPLE_M3_MBOX_CONTROL_FULL, >> + .control_empty = APPLE_M3_MBOX_CONTROL_EMPTY, >> + >> + .a2i_control = APPLE_M3_MBOX_A2I_CONTROL, >> + .a2i_send0 = APPLE_M3_MBOX_A2I_SEND0, >> + .a2i_send1 = APPLE_M3_MBOX_A2I_SEND1, >> + >> + .i2a_control = APPLE_M3_MBOX_I2A_CONTROL, >> + .i2a_recv0 = APPLE_M3_MBOX_I2A_RECV0, >> + .i2a_recv1 = APPLE_M3_MBOX_I2A_RECV1, >> + >> + .has_irq_controls = true, >> + .irq_enable = APPLE_M3_MBOX_IRQ_ENABLE, >> + .irq_ack = APPLE_M3_MBOX_IRQ_ACK, >> + .irq_bit_recv_not_empty = APPLE_M3_MBOX_IRQ_I2A_NOT_EMPTY, >> + .irq_bit_send_empty = APPLE_M3_MBOX_IRQ_A2I_EMPTY, >> +}; >> + >> +static const struct of_device_id apple_mbox_of_match[] = { >> + { .compatible = "apple,t8103-asc-mailbox", .data = &apple_mbox_asc_hw }, >> + { .compatible = "apple,t8103-m3-mailbox", .data = &apple_mbox_m3_hw }, >> + {} >> +}; >> +MODULE_DEVICE_TABLE(of, apple_mbox_of_match); >> + > Traditionally, these go at the end of file. Ack. > > .... >> + >> +static int apple_mbox_hw_send(struct apple_mbox *apple_mbox, >> + struct apple_mbox_msg *msg) >> +{ >> + if (!apple_mbox_hw_can_send(apple_mbox)) >> + return -EBUSY; >> + >> + dev_dbg(apple_mbox->dev, "> TX %016llx %08x\n", msg->msg0, msg->msg1); >> + >> + /* >> + * This message may be related to a shared memory buffer and we must >> + * ensure all previous writes to normal memory are visible before >> + * submitting it. >> + */ >> + dma_wmb(); >> + > This may cause unnecessary overhead. > mbox_client.tx_prepare() is where the SHMEM data is copied, which > should also call dma_wmb() just before return. > ...... > Ok, I'll just drop it here then. >> + >> +static int apple_mbox_hw_recv(struct apple_mbox *apple_mbox, >> + struct apple_mbox_msg *msg) >> +{ >> + if (!apple_mbox_hw_can_recv(apple_mbox)) >> + return -ENOMSG; >> + >> + msg->msg0 = readq_relaxed(apple_mbox->regs + apple_mbox->hw->i2a_recv0); >> + msg->msg1 = FIELD_GET( >> + APPLE_MBOX_MSG1_MSG, >> + readq_relaxed(apple_mbox->regs + apple_mbox->hw->i2a_recv1)); >> + >> + dev_dbg(apple_mbox->dev, "< RX %016llx %08x\n", msg->msg0, msg->msg1); >> + >> + /* >> + * This message may be related to a shared memory buffer and we must >> + * ensure any following reads from normal memory only happen after >> + * having read this message. >> + */ >> + dma_rmb(); >> + > .... similarly should be done by the client as the first thing in recv callback. Ok. > > >> +static struct mbox_chan *apple_mbox_of_xlate(struct mbox_controller *mbox, >> + const struct of_phandle_args *spec) >> +{ >> + struct apple_mbox *apple_mbox = dev_get_drvdata(mbox->dev); >> + >> + if (spec->args_count != 0) >> + return ERR_PTR(-EINVAL); >> + if (apple_mbox->chan.con_priv) >> + return ERR_PTR(-EBUSY); >> + >> + apple_mbox->chan.con_priv = apple_mbox; >> + return &apple_mbox->chan; >> +} >> + > we could do without of_xlate callback, by assigning chan.con_priv > already in the .probe() Sure, will do that. > > >> diff --git a/include/linux/apple-mailbox.h b/include/linux/apple-mailbox.h >> + >> +struct apple_mbox_msg { >> + u64 msg0; >> + u32 msg1; >> +}; >> + > Aren't msg0/1 the Tx and Rx channels? If so you may want to separate > them out as such. But of course, I don't know the h/w details so I may > be wrong. This hardware essentially only has a single channel. Depending on the firmware running on the other side sometimes msg1 is used as an endpoint index and sometimes 8bits of msg0 are. This is similar to the discussion about the raspberry pi mailbox hardware [1]. Thanks, Sven [1] https://lore.kernel.org/all/550C7534.8070100@wwwdotorg.org/