Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755838AbcKJSh2 (ORCPT ); Thu, 10 Nov 2016 13:37:28 -0500 Received: from mail-db5eur01on0071.outbound.protection.outlook.com ([104.47.2.71]:50804 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755447AbcKJSh0 (ORCPT ); Thu, 10 Nov 2016 13:37:26 -0500 From: Ruxandra Ioana Radulescu To: Stuart Yoder , "gregkh@linuxfoundation.org" CC: German Rivera , "devel@driverdev.osuosl.org" , "linux-kernel@vger.kernel.org" , "agraf@suse.de" , "arnd@arndb.de" , Leo Li , Roy Pledge , Haiying Wang , Stuart Yoder Subject: RE: [PATCH 6/9] bus: fsl-mc: dpio: add QBMan portal APIs for DPAA2 Thread-Topic: [PATCH 6/9] bus: fsl-mc: dpio: add QBMan portal APIs for DPAA2 Thread-Index: AQHSK6SU/JJyAb48sEOHR53H+I1ID6DHaGwwgAsET1A= Date: Thu, 10 Nov 2016 15:03:35 +0000 Message-ID: References: <1477058509-12547-1-git-send-email-stuart.yoder@nxp.com> <1477058509-12547-7-git-send-email-stuart.yoder@nxp.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=ruxandra.radulescu@nxp.com; x-originating-ip: [192.88.146.1] x-microsoft-exchange-diagnostics: 1;DB5PR0401MB1751;7:cAm/ZAValIagzOgO9Drks4sk6zRygILvNRR/+GOy6Rx0cxKP9Nk1u6lii1fPT3EIw+s0sMUPasQ2xL1n57cXOZaNvtR5cHXe06ffwuHt34AZMOAcr1YAp1vWxQJFrjKzLqIs6XizYC74bn+ziizofJalDoGWS8acAjL8nD66wKUOLtrHDeWgVjVJ7+M3YgPhcxNlSXRVqXx3MaxgOtBem8gq1IZrCkYWeb0uV0PlueZ6ppeAe5M+lm8qj9JV3QSrEkokFB4t16mEK+RLOjVflxmU5lDJjczcnDYdKXf2A7l4iune9PDV5gsiWlecpmSE7V3rl1z6SqtDDwDRl2r2X6CDZXDtmbvu7VJYypNaMGU= x-ms-office365-filtering-correlation-id: 213dd5c9-b046-40f9-e9a2-08d4097abf03 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DB5PR0401MB1751; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(185117386973197)(275809806118684); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040176)(6045074)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6046074)(6072074);SRVR:DB5PR0401MB1751;BCL:0;PCL:0;RULEID:;SRVR:DB5PR0401MB1751; x-forefront-prvs: 01221E3973 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(189002)(13464003)(199003)(377454003)(9686002)(102836003)(122556002)(68736007)(6116002)(8676002)(66066001)(76176999)(3846002)(5001770100001)(8936002)(97736004)(76576001)(3660700001)(2906002)(229853002)(87936001)(77096005)(33656002)(3280700002)(2900100001)(7696004)(5660300001)(81156014)(189998001)(2950100002)(92566002)(86362001)(81166006)(50986999)(4326007)(2501003)(54356999)(106356001)(105586002)(106116001)(7736002)(305945005)(101416001)(586003)(74316002)(7846002);DIR:OUT;SFP:1101;SCL:1;SRVR:DB5PR0401MB1751;H:VI1PR0402MB2847.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Nov 2016 15:03:35.9795 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR0401MB1751 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uAAIcPRu025861 Content-Length: 4943 Lines: 161 > -----Original Message----- > From: Stuart Yoder [mailto:stuart.yoder@nxp.com] > Sent: Friday, October 21, 2016 9:02 AM > To: gregkh@linuxfoundation.org > Cc: German Rivera ; devel@driverdev.osuosl.org; > linux-kernel@vger.kernel.org; agraf@suse.de; arnd@arndb.de; Leo Li > ; Roy Pledge ; Roy Pledge > ; Haiying Wang ; Stuart > Yoder > Subject: [PATCH 6/9] bus: fsl-mc: dpio: add QBMan portal APIs for DPAA2 > > From: Roy Pledge > > Add QBman APIs for frame queue and buffer pool operations. > > Signed-off-by: Roy Pledge > Signed-off-by: Haiying Wang > Signed-off-by: Stuart Yoder > --- > drivers/bus/fsl-mc/dpio/Makefile | 2 +- > drivers/bus/fsl-mc/dpio/qbman-portal.c | 1009 > ++++++++++++++++++++++++++++++++ > drivers/bus/fsl-mc/dpio/qbman-portal.h | 464 +++++++++++++++ > 3 files changed, 1474 insertions(+), 1 deletion(-) > create mode 100644 drivers/bus/fsl-mc/dpio/qbman-portal.c > create mode 100644 drivers/bus/fsl-mc/dpio/qbman-portal.h > > diff --git a/drivers/bus/fsl-mc/dpio/Makefile b/drivers/bus/fsl- > mc/dpio/Makefile > index 128befc..6588498 100644 > --- a/drivers/bus/fsl-mc/dpio/Makefile > +++ b/drivers/bus/fsl-mc/dpio/Makefile > @@ -6,4 +6,4 @@ subdir-ccflags-y := -Werror > > obj-$(CONFIG_FSL_MC_DPIO) += fsl-mc-dpio.o > > -fsl-mc-dpio-objs := dpio.o > +fsl-mc-dpio-objs := dpio.o qbman-portal.o > diff --git a/drivers/bus/fsl-mc/dpio/qbman-portal.c b/drivers/bus/fsl- > mc/dpio/qbman-portal.c > new file mode 100644 > index 0000000..1eb3dd9 > --- /dev/null > +++ b/drivers/bus/fsl-mc/dpio/qbman-portal.c > @@ -0,0 +1,1009 @@ [...] > +/** > + * qbman_swp_release() - Issue a buffer release command > + * @s: the software portal object > + * @d: the release descriptor > + * @buffers: a pointer pointing to the buffer address to be released > + * @num_buffers: number of buffers to be released, must be less than 8 > + * > + * Return 0 for success, -EBUSY if the release command ring is not ready. > + */ > +int qbman_swp_release(struct qbman_swp *s, const struct > qbman_release_desc *d, > + const u64 *buffers, unsigned int num_buffers) > +{ > + int i; > + struct qbman_release_desc *p; > + u32 rar; > + > + if (!num_buffers || (num_buffers > 7)) > + return -EINVAL; > + > + rar = qbman_read_register(s, QBMAN_CINH_SWP_RAR); > + if (!RAR_SUCCESS(rar)) > + return -EBUSY; > + > + /* Start the release command */ > + p = qbman_get_cmd(s, QBMAN_CENA_SWP_RCR(RAR_IDX(rar))); > + /* Copy the caller's buffer pointers to the command */ > + for (i = 0; i < num_buffers; i++) > + p->buf[i] = cpu_to_le64(buffers[i]); > + Hi Stuart, We also need to set BPID field in the buffer release command, something like: + p->bpid = d->bpid; Without this all buffers will be released to buffer pool id 0, which is incorrect. > + /* > + * Set the verb byte, have to substitute in the valid-bit and the > number > + * of buffers. > + */ > + dma_wmb(); > + p->verb = d->verb | RAR_VB(rar) | num_buffers; > + > + return 0; > +} > + > +struct qbman_acquire_desc { > + u8 verb; > + u8 reserved; > + u16 bpid; > + u8 num; > + u8 reserved2[59]; > +}; > + > +struct qbman_acquire_rslt { > + u8 verb; > + u8 rslt; > + u16 reserved; > + u8 num; > + u8 reserved2[3]; > + u64 buf[7]; > +}; > + > +/** > + * qbman_swp_acquire() - Issue a buffer acquire command > + * @s: the software portal object > + * @bpid: the buffer pool index > + * @buffers: a pointer pointing to the acquired buffer addresses > + * @num_buffers: number of buffers to be acquired, must be less than 8 > + * > + * Return 0 for success, or negative error code if the acquire command > + * fails. > + */ > +int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers, > + unsigned int num_buffers) > +{ > + struct qbman_acquire_desc *p; > + struct qbman_acquire_rslt *r; > + int i; > + > + if (!num_buffers || (num_buffers > 7)) > + return -EINVAL; > + > + /* Start the management command */ > + p = qbman_swp_mc_start(s); qbman_swp_mc_start() returns a pointer to where the QBMan management command must be written, but doesn't clear any previous values found there. We should memset the area to zero before using it. Same comment applies to other places where this function is used. > + > + if (!p) > + return -EBUSY; > + > + /* Encode the caller-provided attributes */ > + p->bpid = cpu_to_le16(bpid); > + p->num = num_buffers; > + > + /* Complete the management command */ > + r = qbman_swp_mc_complete(s, p, p->verb | > QBMAN_MC_ACQUIRE); qbman_swp_mc_complete() may return NULL, if for instance the hardware is unresponsive. We need to check this before dereferencing r. Same for other instances of usage throughout the code. Thanks, Ioana