Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1080164ybv; Fri, 7 Feb 2020 14:06:59 -0800 (PST) X-Google-Smtp-Source: APXvYqxoVvyeXUZXPg/LBDAn0248fNCGDri4/5aYhUuEqTj0WyD7R2GF2nhTY9TvlEfcsVOW1v5/ X-Received: by 2002:a9d:6212:: with SMTP id g18mr1231144otj.187.1581113219499; Fri, 07 Feb 2020 14:06:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581113219; cv=none; d=google.com; s=arc-20160816; b=VBoD/X0oo9e5siaGngy73Sd9xBm/b4W9BNJfcwMDk7peAceDr/JQddD1EPKX1wAL9g wIvqO20Nk4cNnZ3Htc2TZt/bTaU6QHH6rwOhze57pYFgcBiqQDxvhJRG1EBWg8qBKAOP mOePtmpJlGQVtnZYmXv0YBja4GyxbTefLLXvpSCIBh8njqWbrFq2/AgGXXwidZHzCbAE HrTpYvCWXgowSjC/FlTkKfcaKd7/5q/U33E9MVsPof8tndytD1n84cjOgzCgmFkuFape Tbf5Qt3sWCXLOwVQTER7IanYFPeCpbcRg/q58B8QvDncf0orGflBv7VDOYkYw7ghzRAU 2nGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zPDmhswiBJE1QLstk4ChpHjPj5mjGrF+m5q4SUTfNEg=; b=xgJtioTaupLKRAIXAPTpRGPR9niWvYpjQswIcXDPEDLbBzeKRWNb6mjQU7brXMB341 FmpLrocK6EmL08CcWClG880wCuWi+9981J5mR7e79kpjH/k/Wo89GmRAzHyll3ow6RwK sFApOGo9vLa5xciZw0O8Exr676Dlk57gZ/8Cmjb0tKqIX9UkZPDbVYdB5h9WpAqdBiFW fCtng9H5t0DHOiTgx5LQhdX9ilZqLXgLWYA6qBSMdDocr4iEVZ7iC++inddocKPsgnkE DkwaJJSmuKWvDudrZpVx+Cr3V3Wx6ysdEhcaXDu5Qqc4S6mTRBlMmQeCe9A+oS04SbxO F4YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=U3MjPxbM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si330613otc.160.2020.02.07.14.06.47; Fri, 07 Feb 2020 14:06:59 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=U3MjPxbM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727305AbgBGWEn (ORCPT + 99 others); Fri, 7 Feb 2020 17:04:43 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:36013 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbgBGWEm (ORCPT ); Fri, 7 Feb 2020 17:04:42 -0500 Received: by mail-pl1-f195.google.com with SMTP id a6so299321plm.3; Fri, 07 Feb 2020 14:04:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zPDmhswiBJE1QLstk4ChpHjPj5mjGrF+m5q4SUTfNEg=; b=U3MjPxbM1K7k+8ZkbpekkqbvP1T3T9jED5khnh21/XhANQP7Wbgi80pEsmDkZwPHbl 37lP5zlxvJpTjbYI1q6Oek5OnQnKNiru74FBLjRlHlUVKvW27Ktv5dvu36vGWvWTZ3jU 4WY7XUcG9dCOy6Qca+R7E01Q/AfcWBP6uXOWrNhjpn8l7+cycHqBGDeHouyKWCkNfxgK c7gWN7a9HnL4uMLFC6JbjujSVUqxJnvUlNpB5bFQBjxRKncNHxmRkAVGKyxqm5WhJIkz CGMvrwf0/LCCTL/P5Y/ilk+OAXpbYIkLEpu2m8dcT46JTayEeTGAgWfPATDr2Jve2E86 DAMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zPDmhswiBJE1QLstk4ChpHjPj5mjGrF+m5q4SUTfNEg=; b=Nwb1Uj48HN6cMhZibTR7Oo5JDREqjOcBcmowKfpzScbfYSfPB9Fp5nKpEjCA9YZKR2 pfpAnp7rWoWi5cEjT9ASEe+lf3OGKxxw7Kcn3sMMIyw8qleIZdK4trqZGjCGmJOp4S5w v2FOpQIKcXvNl9x4/7x3a6JF7oGSRmE4OLCIH4u0gi3bS88ROXUVel3emXV30mqBp5gc LAb1vlZMi132hE+cf25TIizkLPdFQpmePXzms0SyH+0lK3GEmfKWTAHsuuW5iouXHwgt M1XPthipazyRcsC+dqv163CrhbsezuScK64/1mxl5hyAO4ES6/oCRbOe4M2iacub5mZw o0NQ== X-Gm-Message-State: APjAAAX8BGg+Nd/+6Kzgim7k9SbFriHV2gZFPWywASSyMfo7EQE0SjxG Z7/Lf3pSdBgdByai20JzN1e5FUxfbNOemUM/4zA= X-Received: by 2002:a17:90a:2004:: with SMTP id n4mr6351388pjc.20.1581113080425; Fri, 07 Feb 2020 14:04:40 -0800 (PST) MIME-Version: 1.0 References: <1580328504-436-1-git-send-email-eajames@linux.ibm.com> <29f6cc86-69ca-bc88-b6ae-2b1a24c0dae3@linux.vnet.ibm.com> <744f0019-8656-eec1-cb9a-7e70cd042587@linux.ibm.com> <90973143-bd0a-33cf-9eb8-a83be1a9b415@linux.vnet.ibm.com> In-Reply-To: From: Andy Shevchenko Date: Sat, 8 Feb 2020 00:04:29 +0200 Message-ID: Subject: Re: [PATCH] spi: Add FSI-attached SPI controller driver To: Eddie James Cc: Eddie James , linux-spi , Linux Kernel Mailing List , Mark Brown , Joel Stanley , Andrew Jeffery Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 7, 2020 at 11:04 PM Eddie James wrote: > On 2/7/20 2:34 PM, Andy Shevchenko wrote: > > On Fri, Feb 7, 2020 at 10:04 PM Eddie James wrote: > >> On 2/7/20 1:39 PM, Andy Shevchenko wrote: > >>> On Fri, Feb 7, 2020 at 9:28 PM Eddie James wrote: > >>>> On 2/5/20 9:51 AM, Andy Shevchenko wrote: > >>>>> On Tue, Feb 4, 2020 at 6:06 PM Eddie James wrote: > >>>>>> On 2/4/20 5:02 AM, Andy Shevchenko wrote: > >>>>>>> On Mon, Feb 3, 2020 at 10:33 PM Eddie James wrote: > >>>>>>>> On 1/30/20 10:37 AM, Andy Shevchenko wrote: > > > >>>>>>>>>> + for (i = 0; i < num_bytes; ++i) > >>>>>>>>>> + rx[i] = (u8)((in >> (8 * ((num_bytes - 1) - i))) & 0xffULL); > >>>>>>>>> Redundant & 0xffULL part. > >>>>> For me it looks like > >>>>> > >>>>> u8 tmp[8]; > >>>>> > >>>>> put_unaligned_be64(in, tmp); > >>>>> memcpy(rx, tmp, num_bytes); > >>>>> > >>>>> put_unaligned*() is just a method to unroll the value to the u8 buffer. > >>>>> See, for example, linux/unaligned/be_byteshift.h implementation. > >>>> Unforunately it is not the same. put_unaligned_be64 will take the > >>>> highest 8 bits (0xff00000000000000) and move it into tmp[0]. Then > >>>> 0x00ff000000000000 into tmp[1], etc. This is only correct for this > >>>> driver IF my transfer is 8 bytes. If, for example, I transfer 5 bytes, > >>>> then I need 0x000000ff00000000 into tmp[0], 0x00000000ff000000 into > >>>> tmp[1], etc. So I think my current implementation is correct. > >>> Yes, I missed correction of the start address in memcpy(). Otherwise > >>> it's still the same what I was talking about. > >> > >> I see now, yes, thanks. > >> > >> Do you think this is worth a v3? Perhaps put_unaligned is slightly more > >> optimized than the loop but there is more memory copy with that way too. > > I already forgot the entire context when this has been called. Can you > > summarize what the sequence(s) of num_bytes are expected usually. > > > > IIUC if packets small, less than 8 bytes, than num_bytes will be that value. > > Otherwise it will be something like 8 + 8 + 8 ... + tail. Is it > > correct assumption? > > > Yes, it will typically be 8 + 8 +... remainder. Basically, on any RX, > the driver polls for the rx register full. Once full, it will read > however much data is left to be transferred. Since we use min(len, 8) > then we read 8 usually, until we get to the end. I asked that because we might have a better optimization, i.e, call directly put_unaligned_be64() when we know that length is 8 bytes. For the rest your approach might be simpler. Similar for the TX case. > >>>>>>>>>> + return num_bytes; > >>>>>>>>>> +} -- With Best Regards, Andy Shevchenko