Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752511AbcKRI4Y (ORCPT ); Fri, 18 Nov 2016 03:56:24 -0500 Received: from mail-db5eur01on0044.outbound.protection.outlook.com ([104.47.2.44]:10400 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751613AbcKRI4W (ORCPT ); Fri, 18 Nov 2016 03:56:22 -0500 From: Vadim Pasternak To: Wolfram Sang CC: "wsa@the-dreams.de" , "linux-i2c@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "jiri@resnulli.us" , Michael Shych Subject: RE: [v7,1/1] i2c: add master driver for mellanox systems Thread-Topic: [v7,1/1] i2c: add master driver for mellanox systems Thread-Index: AQHSQSAZNeTKGGHCeUKrDWybIkZf2aDeBnGg Date: Fri, 18 Nov 2016 02:50:32 +0000 Message-ID: References: <1479388708-37054-1-git-send-email-vadimp@mellanox.com> <20161117221522.GA10875@katana> In-Reply-To: <20161117221522.GA10875@katana> 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=vadimp@mellanox.com; x-originating-ip: [46.120.54.214] x-microsoft-exchange-diagnostics: 1;HE1PR05MB1273;7:dnTFCNQbPbA4Fvy5nlLtKdfS/FJ28HA2N6WnYp2q5C4OAmp2tPJ5ik6EeHer51iob3wg5DFk5haoLTorryhOYMbXjGYyGlKVjMpjehR7dlyHBFZGWNGk0xfs/BrFXv9+xqEyJ+5U+Uq3qgspgLmFbyWpbOAEBRm7+NedSw3NwKuZOQcm6ZWV4GhK3TtseNToe6EiuONetIcEGWNnESw/kXsDU4YXqJpK0Kc5dhCQsUCyZATF5kAIteIcAe5ebqcq39cIhomV7zLB9zez0atX84O1ZchF833OPIMtPTNRqOOt1gK5t3d45nL7AjaMpcmNlqrFNRqLk42T5wYHqceze1u8h19/boSksyexfpSwMhA= x-forefront-antispam-report: SFV:SKI;SCL:-1SFV:NSPM;SFS:(10009020)(6009001)(7916002)(377454003)(199003)(189002)(13464003)(51914003)(8936002)(97736004)(4001430100002)(345774005)(101416001)(122556002)(8676002)(33656002)(3280700002)(551934003)(50986999)(54356999)(76176999)(81166006)(81156014)(66066001)(3660700001)(2950100002)(77096005)(9686002)(6916009)(110136003)(74316002)(229853002)(2900100001)(3846002)(76576001)(2906002)(106116001)(68736007)(6506003)(106356001)(105586002)(86362001)(7736002)(5660300001)(305945005)(92566002)(7846002)(87936001)(7696004)(6116002)(102836003)(189998001)(4326007)(107886002);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR05MB1273;H:AM5PR0501MB2097.eurprd05.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; x-ms-office365-filtering-correlation-id: ea75eeb2-7a75-4f13-2ece-08d40f5daa52 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:HE1PR05MB1273; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(171992500451332); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6060326)(6040281)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6061324)(6041223);SRVR:HE1PR05MB1273;BCL:0;PCL:0;RULEID:;SRVR:HE1PR05MB1273; x-forefront-prvs: 01304918F3 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Nov 2016 02:50:32.8018 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR05MB1273 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 uAI8uTEs016733 Content-Length: 5269 Lines: 175 Hi Wolfram, Thank you for review. > -----Original Message----- > From: Wolfram Sang [mailto:wsa-dev@sang-engineering.com] > Sent: Friday, November 18, 2016 12:15 AM > To: Vadim Pasternak > Cc: wsa@the-dreams.de; linux-i2c@vger.kernel.org; linux- > kernel@vger.kernel.org; jiri@resnulli.us; Michael Shych > > Subject: Re: [v7,1/1] i2c: add master driver for mellanox systems > > Hi, > > thanks for the patch and the prompt reworks. Also thank you to Vladimir for > initial reviews! > > > Device supports: > > - Master mode > > - One physical bus > > - Polling mode > > Out of interest: is there any interrupt at all? Yes, it's possible to configure interrupt mode in HW, but we've never used it. > > > diff --git a/MAINTAINERS b/MAINTAINERS index 411e3b8..26d05f8 100644 > > --- a/MAINTAINERS > > +++ b/MAINTAINERS > > @@ -7881,6 +7881,14 @@ W: http://www.mellanox.com > > Q: http://patchwork.ozlabs.org/project/netdev/list/ > > F: drivers/net/ethernet/mellanox/mlxsw/ > > > > +MELLANOX MLXCPLD I2C DRIVER > > +M: Vadim Pasternak > > +M: Michael Shych > > +L: linux-i2c@vger.kernel.org > > +S: Supported > > +F: drivers/i2c/busses/i2c-mlxcpld.c > > +F: Documentation/i2c/busses/i2c-mlxcpld > > + > > No need to change right now, but I think you could simplify all your drivers in > one entry with > > F: *mlxcpld* > > or something similar to keep MAINTAINERS compact. > > > +/** > > + * struct mlxcpld_i2c_curr_xfer - current transaction parameters: > > + * @cmd: command; > > + * @addr_width: address width; > > + * @data_len: data length; > > + * @cmd: command register; > > + * @msg_num: message number; > > + * @msg: pointer to message buffer; > > + */ > > While I value effort to describe struct members, this is so self-explaining that I > think it could be left out. > > > +/** > > + * struct mlxcpld_i2c_priv - private controller data: > > + * @adap: i2c adapter; > > + * @base_addr: base IO address; > > + * @lock: bus access lock; > > + * @xfer: current i2c transfer block; > > + * @dev: device handle; > > + */ > > ditto > > > +/* > > + * Check validity of current i2c message and all transfer. > > + * Calculate also common length of all i2c messages in transfer. > > + */ > > +static int mlxcpld_i2c_invalid_len(struct mlxcpld_i2c_priv *priv, > > + const struct i2c_msg *msg, u8 *comm_len) { > > + u8 max_len = msg->flags == I2C_M_RD ? MLXCPLD_I2C_DATA_REG_SZ - > > + MLXCPLD_I2C_MAX_ADDR_LEN : > MLXCPLD_I2C_DATA_REG_SZ; > > + > > + if (msg->len > max_len) > > + return -EINVAL; > > If you populate a 'struct i2c_adapter_quirks' the core will do this check for you. > > > + *comm_len += msg->len; > > + if (*comm_len > MLXCPLD_I2C_DATA_REG_SZ) > > + return -EINVAL; > > + > > + return 0; > > +} > > + > > +/* > > + * Check validity of received i2c messages parameters. > > + * Returns 0 if OK, other - in case of invalid parameters > > + * or common length of data that should be passed to CPLD */ static > > +int mlxcpld_i2c_check_msg_params(struct mlxcpld_i2c_priv *priv, > > + struct i2c_msg *msgs, int num, > > + u8 *comm_len) > > +{ > > + int i; > > + > > + if (!num) { > > + dev_err(priv->dev, "Incorrect 0 num of messages\n"); > > + return -EINVAL; > > + } > > + > > + if (unlikely(msgs[0].addr > 0x7f)) { > > + dev_err(priv->dev, "Invalid address 0x%03x\n", > > + msgs[0].addr); > > + return -EINVAL; > > + } > > + > > + for (i = 0; i < num; ++i) { > > + if (unlikely(!msgs[i].buf)) { > > + dev_err(priv->dev, "Invalid buf in msg[%d]\n", > > + i); > > + return -EINVAL; > > + } > > I was about to write "the core will check this for you", but wow, we are not > good at this... I will try to come up with some patches soon. No need for you to > changes this right now. > > ... > > > + case MLXCPLD_LPCI2C_ACK_IND: > > + if (priv->xfer.cmd != I2C_M_RD) > > + return (priv->xfer.addr_width + priv->xfer.data_len); > > + > > + if (priv->xfer.msg_num == 1) > > + i = 0; > > + else > > + i = 1; > > + > > + if (!priv->xfer.msg[i].buf) > > + return -EINVAL; > > + > > + /* > > + * Actual read data len will be always the same as > > + * requested len. 0xff (line pull-up) will be returned > > + * if slave has no data to return. Thus don't read > > + * MLXCPLD_LPCI2C_NUM_DAT_REG reg from CPLD. > > + */ > > + datalen = priv->xfer.data_len; > > + > > + mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_DATA_REG, > > + priv->xfer.msg[i].buf, datalen); > > + > > + return datalen; > > + > > + case MLXCPLD_LPCI2C_NACK_IND: > > + return -EAGAIN; > > -EAGAIN is for arbitration lost. -ENXIO is for NACK. See > Documentation/i2c/fault-codes. > > What kind of testing have you done with the driver? > Actually we are using these driver on a wide range of different Mellanox systems (about 10 systems, TORs and modular systems), which we have on the filed about two years. After updating it with the upstream review comments, I performed some basic set of the functional testing on a couple of our systems - access to all the devices (1, 2, 4 byte width), access to broken device (transaction TO), some kind of stress test. > Thanks, > > Wolfram Thanks, Vadim.