Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp962828ybv; Fri, 7 Feb 2020 11:41:35 -0800 (PST) X-Google-Smtp-Source: APXvYqyMm3kyfuGJqlokb4oHD94NYoU4Q1eOn+m3YhAuG3qKyq61ylEjSbk7RcjzpKtXya8Z84Iu X-Received: by 2002:a9d:831:: with SMTP id 46mr748970oty.295.1581104495104; Fri, 07 Feb 2020 11:41:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581104495; cv=none; d=google.com; s=arc-20160816; b=aWkzz0afWIi5qxVjDRMZnZPu6t7OegfeKJyZFwG89n+bfem/gPHiMnVlqLjhSjDd9N wI8PHHaGiYq1ps+/RgIG+1krqWF5kDRFeHB5zAxNGKIOREGL52jy2Jeczzo6fx/hlwKD eJqeQfc/1maiazvU86OTkXjIq5nsHs0J5+O6LK3gBo2KbFs+CyEc1E3cz24ObGj0YLFj CeGlvN65XvvLn2sKdRSbuECU+PcZO3p8xJaryZxGvoKnDzXd8XxM+BFPS1r7Y5cfDlSi xJvDfyhGSSO9LpKiAm731XmbTejcdZqqt6WGGgKbSSUxjLplxU39q5qaf9xJRss/7BJx mdHQ== 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=kMV9mrvxXKtF7veXVaTaKRwaBbMNRnkTmlI+NnwqDp0=; b=T5FAID1+jlktz1GriANL5phY5QMZxkFhtHE9yRDxfz6DShO2UlEKpdnNcQHkzbVzCc k3Ap6F6P2h72t7ZiP78Jk5xNByMaQcEnQCOsat/W2SZPGw3CX+55ZFfgIo56YyHTQXdy lRr0JB7i1rY8M4Q949xjlQmx3XyQXPFRNjo1MEaUVt3LIxC3LEilZmTcqcJTjUi7SrYm 80j4o9NCn4t0eL+EF17Xl+jBMJf+OrXa/oUN5rsDS1rkr3yRV5tiF8W1tTKWM+c1Zw2Z t3ffNPPKDRS/qcyjyNUw3SaZjoATfqsPZVVRtU2A/yOrkOcI2sx41DtVvKbgNMoV5iur G4Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UVW1Jr3r; 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 v26si177801otj.0.2020.02.07.11.41.23; Fri, 07 Feb 2020 11:41:35 -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=UVW1Jr3r; 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 S1727144AbgBGTj0 (ORCPT + 99 others); Fri, 7 Feb 2020 14:39:26 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43715 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727113AbgBGTj0 (ORCPT ); Fri, 7 Feb 2020 14:39:26 -0500 Received: by mail-pf1-f194.google.com with SMTP id s1so277773pfh.10; Fri, 07 Feb 2020 11:39:26 -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=kMV9mrvxXKtF7veXVaTaKRwaBbMNRnkTmlI+NnwqDp0=; b=UVW1Jr3rxr43QMhieO9muTBS+hJj0+c93HmCQYuhH0kio1os13hyQ701MxvUvCE76v KFpgpEbaHsKkidsrjbiUQ4wODCM9UWOXmd+c56elI9tcMrKhXyJWQlgK47igUdYr6FLY gLlqN/z2b1rKywI+q/+V30XqwuH5x5X4ItHIdjrce/ehs1hisN/HFq/n0Y+jMOc3CvQ2 1pGW9ZGUdxB59DHcHOBvOaFfRv8Tr2ddqrU9LzxkKFPp425UO3j6m0AJlKd9kx23EHSp ZUdv8KvcAiDMpL0c3onlAIrjRgWotEUBZqUrPUjh5pgNE0qOhSpeXkMF7iRgwtvkb8ZX ajFg== 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=kMV9mrvxXKtF7veXVaTaKRwaBbMNRnkTmlI+NnwqDp0=; b=qE3sGm4l0ETkwL2FR9Xw7GMU43I0oT0lHRND2RJpwVzN4MLpnnxNzjuUx8Kjmj5wWD KmIg8tSct+FdJvgsBxpPvU0CmVBmMDWuftZeUbQCM9NJ1JtgSfuKGXUGLUopfcoOAWuX FhKzeY2HFm5ul/PVayowdtk3UQoLl0xvf4rxxkZsfzSS76EjSE89qdDAVfiEP1BMzXh/ b1b6TRMQQSqUexLhrLDk8V3hL8eIjhlg7064WGnCoeuS50J9gtKWrQCydRgjg3yts1l1 t71X84YunP6rHltqqjxEmMh4HFx7Lde+ilBsrKwXniO/kHp7w6s1IFf4K5bF4tLGCEdx WGqA== X-Gm-Message-State: APjAAAXfhcaw1D3ZGZplQJkYwtNp10gtFOhWWX5xC8QqVqOkIi1wLbVE 1/ItZQUAiySlEjb7G5T46SVZsMarA97rYC0fbNo= X-Received: by 2002:a65:5242:: with SMTP id q2mr810978pgp.74.1581104365541; Fri, 07 Feb 2020 11:39:25 -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: <90973143-bd0a-33cf-9eb8-a83be1a9b415@linux.vnet.ibm.com> From: Andy Shevchenko Date: Fri, 7 Feb 2020 21:39:17 +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 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. > >>>>> > >>>>> Isn't it NIH of get_unalinged_be64 / le64 or something similar? > >>>> No, these are shift in/out operations. The read register will also have > >>>> previous operations data in them and must be extracted with only the > >>>> correct number of bytes. > >>> Why not to call put_unaligned() how the tail in this case (it's 0 or > >>> can be easily made to be 0) will affect the result? > >> > >> The shift-in is not the same as any byte-swap or unaligned operation. > >> For however many bytes we've read, we start at that many bytes > >> left-shifted in the register and copy out to our buffer, moving right > >> for each next byte... I don't think there is an existing function for > >> this operation. > > 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. > >>>>>> + return num_bytes; > >>>>>> +} > >>>>>> +static int fsi_spi_data_out(u64 *out, const u8 *tx, int len) > >>>>>> +{ > >>>>> Ditto as for above function. (put_unaligned ...) > >>> Ditto. > >> > >> I don't understand how this could work for transfers of less than 8 > >> bytes, any put_unaligned would access memory that it doesn't own. > > Ditto. > > > >>>>>> +} -- With Best Regards, Andy Shevchenko