Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754457AbcCBUHp (ORCPT ); Wed, 2 Mar 2016 15:07:45 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:53607 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752990AbcCBUHn (ORCPT ); Wed, 2 Mar 2016 15:07:43 -0500 From: Arnd Bergmann To: Lada Trimasova Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Brodkin , Noam Camus , Tal Zilcer Subject: Re: [PATCH v2] net: ezchip: adapt driver to little endian architecture Date: Wed, 02 Mar 2016 21:07:37 +0100 Message-ID: <3132255.zs1gQSacSZ@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <1456943884-29149-1-git-send-email-ltrimas@synopsys.com> References: <1456943884-29149-1-git-send-email-ltrimas@synopsys.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:/6i/4TQAnee4lAkY4gBDM1xfJo176Qn9Ivl/Ha1UZJboNa9tz3w J0xJK7YNdYLrhyyYx0BWwjPweuZgBjuWN16oLxM48M7+7XCDmaV2h1BPaHVBGIjq4yGTzWD yMSH7Zdz50JEzQxU5u8Y0xk7xDB150ir2M8S+XlCwpMQGJ7FHiwyYYOSKq25wK1w9qIgZGa C4dePVXFEsAah091BXDpA== X-UI-Out-Filterresults: notjunk:1;V01:K0:P0gqI2WYqhM=:zBSy6sVakejLiIEtCIc5NJ ZM1jjHC1x96smQSUiAwS7AGhkur6psNFzTJ8RXkpd2Sjq3WSBquTCIAJp4uc2XHnCqYhsdkpx K6N0OGrGGzEjIme7pabQuzUdgw/frro/HQL3l01PRoe/48Zqmf7o2OTriBsUT53PQaHdQeBKp M+DwlHEeayDGf7SyKXqKpo1fFUvrIXqcHrnqe2P1bMg7tEJiORBx+KX+RuhkB7h+7gQPyMeS6 E9SDX3BF9EJW/IjFFzKFVTGRBShbji4T6I56NNlfzWg20NP3YcVKscXEpz146SGeOX+dw90L/ cHL+VXv76bwY9WI0DkVlvE94zuXdyzNb1hlS3KT1HjU/LoWIyg2DDxfwqiK2xYkZDO6iwxwhs 1o+z8u0ZvIoLl4WrDmVN+EYDnGJI+3ZQ/DRXHJjsT9WM+pw9utmrln1T9VKHmaQuDElP2jpfO zFR+TQuAetx6j7+NP4H9uj0BUNjNpaGg9o8vzagwzRF43NBNU/X3kKAg2BxHQQezgXLJVOWW7 kwy+FtIEXnvB8/6Dk9acRtfuqTOcfG91Lt+42+fDmqN9rJt6c6OlZdGsKquQHLxErDmhT9otu ETtdUTYtRy07bF8cydA3q5eXuX/ixk4BNQa4Gs6J2AzNWRCwJmTifCSzEl0XtNPYOJhpw6fV7 3nasiOYtPkzS/xi8a/kr4FXWuwHgrENkIB2evLvgs6MCO//QSRUtWqW/E6lYi6nG7eB3Dv2sj fbJxcnQC5NLgr9gI Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2307 Lines: 59 On Wednesday 02 March 2016 21:38:04 Lada Trimasova wrote: > Since ezchip network driver is written with big endian EZChip platform it > is necessary to add support for little endian architecture. > > The first issue is that the order of the bits in a bit field is > implementation specific. So all the bit fields are removed. > Named constants are used to access necessary fields. > > And the second one is that network byte order is big endian. > For example, data on ethernet is transmitted with most-significant > octet (byte) first. So in case of little endian architecture > it is important to swap data byte order when we read it from > register. In case of unaligned access we can use "get_unaligned_be32" > and in other case we should use function "be32_to_cpu" as we read from > peripheral to CPU. > > And then when we are going to write data to register we need to restore > byte order using the function "put_unaligned_be32" in case of > unaligned access and in other case "cpu_to_be32" as > we write from CPU to peripheral. > > The last little fix is a space between type and pointer to observe > coding style. > > Signed-off-by: Lada Trimasova > Cc: Alexey Brodkin > Cc: Noam Camus > Cc: Tal Zilcer > Cc: Arnd Bergmann Looks much better already. > index b102668..9a5a3bf 100644 > --- a/drivers/net/ethernet/ezchip/nps_enet.c > +++ b/drivers/net/ethernet/ezchip/nps_enet.c > @@ -44,19 +44,22 @@ static void nps_enet_read_rx_fifo(struct net_device *ndev, > > /* In case dst is not aligned we need an intermediate buffer */ > if (dst_is_aligned) > - for (i = 0; i < len; i++, reg++) > + for (i = 0; i < len; i++, reg++) { > + /* In case of LE we need to swap bytes */ > *reg = nps_enet_reg_get(priv, NPS_ENET_REG_RX_BUF); > + *reg = be32_to_cpu(*reg); > + } This is still not right: please build this with make C=2 CF="-D__CHECK_ENDIAN__" drivers/net/ethernet/ezchip/nps_enet.o What is going on here is that NPS_ENET_REG_RX_BUF seems to be some kind of FIFO register rather than an MMIO register, so the swap in ioread32be() is wrong. What you should do instead is to replace the loop with a call to ioread32_rep(), which will be more efficient and endian-safe. Arnd