Received: by 10.223.185.116 with SMTP id b49csp2663534wrg; Mon, 5 Mar 2018 06:50:19 -0800 (PST) X-Google-Smtp-Source: AG47ELugiDLkC/sL7Gy2psEocRnH/dku1cEPCIDLwXK2Uz0VNHRLfP+E1WD1COaktCy5I/CYj0Jj X-Received: by 10.98.89.156 with SMTP id k28mr15384597pfj.130.1520261418970; Mon, 05 Mar 2018 06:50:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520261418; cv=none; d=google.com; s=arc-20160816; b=dhX8Mb7C2a70kGX3y7tEDVCTODYR2LkmSGakCV8JSCXidhguAzvW23tEiRER/J9y3O brLJ2YaYMWTcHzFFyRNvUfoy73YsaALJMZSyri92rCrdLUu6sETJ5tfDkt0+aD7CPbFk srS2kKzkPPuMTmEmlz6MLix1hVWqmN5pGH0cgZKADid67wdE9hwhhaSy14LFAIlxium9 0+E9lq7aayf+YmvniiP2YMPK3ePgSwKxeiXG5K+ZfHbKBz/OIGfcGkelVHb+1NHIuN5a zEIUy4dAYHQg3WHyKrnVUPSa72G4fT5ScmxL4sNKhgBtUNlyL+TRg5QGrHzrEHbvyKcr 5mrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=OOt0FO5OwQqJ1vs116RDWEfoYMYc7aFs0LfHYtGJJiM=; b=KNJAhdv8tG+ewcToFQFcHU1ghvgU+7Jt7wBRrOK1E2yOHpsqzYxQy7GFbdrSz/URww nJqPulgslliZKnVAIEW3bvbeKCaBEMK7MutSDpX3M4IsT1JaFGtSqrVnAXi5lh2wvzyp Ved/kXQQJiDpLPRmkD/GBR9l1vPPu6ylYXT3tPEsMSnfdQ8UYgPd7rXup8RULYWtLAfb 0TrSdYjt+0gMQ5VZL5+LsqTnOW+N/G8TiGn2XOLN6gFxYcGpjqmrr2sIscZn7T8y0I2P 6+prQAFIxplpXhnejBzV0QrcvDCUOR9Hhf+UMSPy8tiHqExku6Qfu40CO/bkNNaKp4Uk Z+Cg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u64si8413952pgc.295.2018.03.05.06.50.03; Mon, 05 Mar 2018 06:50:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751906AbeCEOsI (ORCPT + 99 others); Mon, 5 Mar 2018 09:48:08 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:35271 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751386AbeCEOsF (ORCPT ); Mon, 5 Mar 2018 09:48:05 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 9BF5D9552A2D3; Mon, 5 Mar 2018 22:47:51 +0800 (CST) Received: from localhost (10.202.226.43) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 5 Mar 2018 22:47:51 +0800 Date: Mon, 5 Mar 2018 14:47:42 +0000 From: Jonathan Cameron To: Sudeep Holla CC: ALKML , LKML , DTML , "Alexey Klimov" , Greg Kroah-Hartman , Arnd Bergmann Subject: Re: [PATCH v6 03/20] firmware: arm_scmi: add basic driver infrastructure for SCMI Message-ID: <20180305154742.000029c0@huawei.com> In-Reply-To: <9d6e431e-fa07-63b6-81fc-6b00c7e8267e@arm.com> References: <1519403030-21189-1-git-send-email-sudeep.holla@arm.com> <1519403030-21189-4-git-send-email-sudeep.holla@arm.com> <20180305145253.00004247@huawei.com> <9d6e431e-fa07-63b6-81fc-6b00c7e8267e@arm.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.43] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > >> +/** > >> + * scmi_one_xfer_get() - Allocate one message > >> + * > >> + * @handle: SCMI entity handle > >> + * > >> + * Helper function which is used by various command functions that are > >> + * exposed to clients of this driver for allocating a message traffic event. > >> + * > >> + * This function can sleep depending on pending requests already in the system > >> + * for the SCMI entity. Further, this also holds a spinlock to maintain > >> + * integrity of internal data structures. > >> + * > >> + * Return: 0 if all went fine, else corresponding error. > >> + */ > >> +static struct scmi_xfer *scmi_one_xfer_get(const struct scmi_handle *handle) > > Maybe it's just me, but I think this would be more clearly named as > > scmi_xfer_alloc. > > > > Agreed to some extent. The reason I didn't have it as alloc as they are > preallocated and this just returns a reference to free slot in that > preallocated array. > > > I'd assume we were dealing with one anyway as it's not called scmi_xfers_get > > and the get to my mind implies a reference counter rather than allocating > > an xfer for use... > > > > Ah OK, I get your concerne with _get/_put but _alloc/_free is equally > bad then in the contect of preallocated buffers. Sure, this is always a fun question. Lots of other options _assign _deassign works but never feels nice. > ... > > >> + .max_msg = 20, /* Limited by MBOX_TX_QUEUE_LEN */ > >> + .max_msg_size = 128, > >> +}; > >> + > >> +/* Each compatible listed below must have descriptor associated with it */ > >> +static const struct of_device_id scmi_of_match[] = { > >> + { .compatible = "arm,scmi", .data = &scmi_generic_desc }, > >> + { /* Sentinel */ }, > >> +}; > >> + > >> +MODULE_DEVICE_TABLE(of, scmi_of_match); > >> + > >> +static int scmi_xfer_info_init(struct scmi_info *sinfo) > >> +{ > >> + int i; > >> + struct scmi_xfer *xfer; > >> + struct device *dev = sinfo->dev; > >> + const struct scmi_desc *desc = sinfo->desc; > >> + struct scmi_xfers_info *info = &sinfo->minfo; > >> + > >> + /* Pre-allocated messages, no more than what hdr.seq can support */ > >> + if (WARN_ON(desc->max_msg >= (MSG_TOKEN_ID_MASK + 1))) { > >> + dev_err(dev, "Maximum message of %d exceeds supported %d\n", > >> + desc->max_msg, MSG_TOKEN_ID_MASK + 1); > >> + return -EINVAL; > >> + } > >> + > >> + info->xfer_block = devm_kcalloc(dev, desc->max_msg, > >> + sizeof(*info->xfer_block), GFP_KERNEL); > >> + if (!info->xfer_block) > >> + return -ENOMEM; > >> + > >> + info->xfer_alloc_table = devm_kcalloc(dev, BITS_TO_LONGS(desc->max_msg), > >> + sizeof(long), GFP_KERNEL); > >> + if (!info->xfer_alloc_table) > >> + return -ENOMEM; > > Hmm. I wonder if it is worth adding a devm_bitmap_alloc? > > > > OK > > >> + > >> + bitmap_zero(info->xfer_alloc_table, desc->max_msg); > > kcalloc zeros the memory. > > > >> + > >> + /* Pre-initialize the buffer pointer to pre-allocated buffers */ > >> + for (i = 0, xfer = info->xfer_block; i < desc->max_msg; i++, xfer++) { > >> + xfer->rx.buf = devm_kcalloc(dev, sizeof(u8), desc->max_msg_size, > >> + GFP_KERNEL); > >> + if (!xfer->rx.buf) > >> + return -ENOMEM; > >> + > >> + xfer->tx.buf = xfer->rx.buf; > >> + init_completion(&xfer->done); > >> + } > >> + > >> + spin_lock_init(&info->xfer_lock); > >> + > >> + return 0; > >> +} > >> + > >> +static int scmi_mailbox_check(struct device_node *np) > >> +{ > >> + struct of_phandle_args arg; > >> + > >> + return of_parse_phandle_with_args(np, "mboxes", "#mbox-cells", 0, &arg); > >> +} > >> + > >> +static int scmi_mbox_free_channel(struct scmi_info *info) > > Some of the naming in here could do with being adjusted to be obviously > > 'balanced'. The moment I see a free I expect a matched alloc but in this > > case the alloc is done in scmi_mbox_chan_setup which at very least > > should be scmi_mbox_setup_channel and should really imply that it is > > doing allocation as well. > > > > That's inline with mailbox APIs. oh goody. Fair enough if ugly > ... > OK