From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752682AbcETSGy (ORCPT ); Fri, 20 May 2016 14:06:54 -0400 Received: from mail-bl2on0124.outbound.protection.outlook.com ([65.55.169.124]:38912 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752603AbcETSGw convert rfc822-to-8bit (ORCPT ); Fri, 20 May 2016 14:06:52 -0400 From: Hartley Sweeten To: Ian Abbott , "devel@driverdev.osuosl.org" CC: Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH 04/20] staging: comedi: drivers: re-do macros for PLX PCI 9080 LASxRR values Thread-Topic: [PATCH 04/20] staging: comedi: drivers: re-do macros for PLX PCI 9080 LASxRR values Thread-Index: AQHRsp52i+Ex6wGEvk2AFSoHtHMG8Z/CAlBQgAAPhwCAAAA+AA== Date: Fri, 20 May 2016 17:52:25 +0000 Message-ID: References: <1463752162-15181-1-git-send-email-abbotti@mev.co.uk> <1463752162-15181-5-git-send-email-abbotti@mev.co.uk> <573F46C0.4050808@mev.co.uk> In-Reply-To: <573F46C0.4050808@mev.co.uk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: mev.co.uk; dkim=none (message not signed) header.d=none;mev.co.uk; dmarc=none action=none header.from=visionengravers.com; x-originating-ip: [184.183.19.121] x-ms-office365-filtering-correlation-id: d2ef49e4-f631-4bd2-7cab-08d380d78186 x-microsoft-exchange-diagnostics: 1;CO2PR01MB2085;5:BDRBfG9SKud7vtpHByIjpyq/sGeWayfWVC8LKM/HOMYzLscAhjM6lcDOqLioLFJJ2E241UrSji6wmIZ0SpKVbgHEizdl5kre0riOwBnE7zz8wXilTsJaj8ah57pxt+ANSCvaPd68UENRc+n/bamZMA==;24:vTpzoiWRjQIAisVMiH1mQFH33EZgFcESXKL6JAsiAdW5m8Zy+HQNqwTJG9H8P3EgIawe94zPOAGu5LND8K+4nW5lJ73q448HK2Vnle4MwNw=;7:4ZHJ+MFnCBKTfxPQ8IDeAB138MPZtCrHA0gSF9PeabOphjTe1iq8i7GlKX9QbEFv9CQ8QF1FP8ho8E+7v+Of1xPZ8Ipv0OV+XCO2aHBf8BlWhAO8gyNNLGG0ZD3d7bTQUkpCZexpGXgSVwL4zcMt7tA2eNfyg6x7nVnVckW1yKWuz6cqS0Iz3OP+pWYowICp x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CO2PR01MB2085; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040130)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041072)(6043046);SRVR:CO2PR01MB2085;BCL:0;PCL:0;RULEID:;SRVR:CO2PR01MB2085; x-forefront-prvs: 09480768F8 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(24454002)(377454003)(122556002)(54356999)(50986999)(2906002)(86362001)(11100500001)(76176999)(92566002)(66066001)(575784001)(5004730100002)(33656002)(6116002)(4326007)(3846002)(586003)(5001770100001)(87936001)(189998001)(106116001)(1220700001)(80792005)(102836003)(5008740100001)(2501003)(5002640100001)(74316001)(10400500002)(93886004)(8676002)(81166006)(3280700002)(77096005)(3660700001)(2950100001)(2900100001)(9686002)(5003600100002)(8936002)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:CO2PR01MB2085;H:CO2PR01MB2088.prod.exchangelabs.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: visionengravers.com X-MS-Exchange-CrossTenant-originalarrivaltime: 20 May 2016 17:52:25.9852 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d698601f-af92-4269-8099-fd6f11636477 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR01MB2085 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Friday, May 20, 2016 10:18 AM, Ian Abbott wrote: > On 20/05/16 17:37, Hartley Sweeten wrote: >> On Friday, May 20, 2016 6:49 AM, Ian Abbott wrote: >>> Rename the macros for the PLX PCI 9080 LAS0RR and LAS1RR registers in >>> "plx9080.h", using the prefix `PLX_LASRR_`. Make use of the `BIT(x)` >>> and `GENMASK(h,l)` macros to define the values. >>> >>> Define a macro `PLX_LASRR_PREFETCH` for the "prefetchable memory" bit in >>> this register, and define a macro `PLX_LASRR_MLOC_MASK` to mask the PCI >>> memory location control bits. [snip] >>> +#define PLX_LASRR_IO BIT(0) /* Map to: 1=I/O, 0=Mem */ >>> +#define PLX_LASRR_ANY32 (BIT(1) * 0) /* Locate anywhere in 32 bit */ >>> +#define PLX_LASRR_LT1MB (BIT(1) * 1) /* Locate in 1st meg */ >>> +#define PLX_LASRR_ANY64 (BIT(1) * 2) /* Locate anywhere in 64 bit */ >> >> The (BIT(n) * x) looks ugly. > > You won't like the remaining patches then! You are correct... ;-) > FWIW, all the constants end up with the same type (unsigned long) this way. That's probably good but it sure makes the defines look ugly, and a bit hard to understand imoh. You also don't know what the 'max' value for the bit-field is without further digging. I applied your whole series to see what the final header looks like. To me it actually looks worse than the original. The original had a number of whitespace issues that made it hard to follow and the defines were lacking namespace. Personally I also don't can for all the enums since the symbols are not actually used as enums just as raw values. But the 'bit' usage of the registers was fairly clear. With your series applied the whtespace and namespace issues are addressed. You also converted all the enums to defines which is great. But the 'bit' usage now is a bit muddled. I really don't care for the (BIT(n) * (x)) stuff. There are also the various, unused and unnecessary, _SHIFT defines. Those just add additional cruft. I'm also not sure if all the bits require a comment. They seem to clutter the header. Datasheets for the PLX-9080 are easy to find. Maybe just have a comment for each register and remove all the bit comments. > I have been looking for a solution to the problem where random people > change something like this: > > #define MY_COOLREG_VAL_FOO (0 << 5) > #define MY_COOLREG_VAL_BAR (1 << 5) > #define MY_COOLREG_VAL_BAZ (2 << 5) > > to: > > #define MY_COOLREG_VAL_FOO (0 << 5) > #define MY_COOLREG_VAL_BAR BIT(5) > #define MY_COOLREG_VAL_BAZ (2 << 5) > > and this seemed like one way to do it. Like I stated previously, I prefer something like this for the multi-bit fields of a register. >> #define PLX_LASSR_MLOC(x) (((x) & 0x3) << 1) >> #define PLX_LASSR_MLOC_ANY32 PLX_LASSR_MLOC(0) >> #define PLX_LASSR_MLOC_LT1MB PLX_LASSR_MLOC(1) >> #define PLX_LASSR_MLOC_ANY64 PLX_LASSR_MLOC(2) >> #define PLX_LASSR_MLOC_MASK PLX_LASSR_MLOC(3) > > It is handy when matching it up with the data sheet though. I have a > field that occupies bits 2 and 1. It also doesn't expose a fairly > useless PLX_LASRR_MLOC() macro to the user of the header file. The (BIT(n) * (x)) just looks odd. The GENMASK() for a multi-bit field also makes it more difficult to figure out what the maximum value for the field is when there are more than just a few bits and the lower bit is not 0. Anyway.. Technically it looks like your series doesn't break anything I just don't feel that it adds much clarity. I'm still looking it over... Maybe I'll change my mind... ;-) Regards, Hartley