From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32DFF421A11 for ; Wed, 29 Apr 2026 19:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777489575; cv=none; b=LdnE/3pd0BqEt57Ejo/6ZLdpwiExaZCYYoVrMyEFZD9aGZIZpd+wmqQGz8dZ6ejmEGB0CkDjV+JT7kEixBxa3PVXbP12opt8SXmU7xjJ9WHqssBdYAkN6vpHrBuXjYlIH8fbQK3+3ppmB4SbnunNkMvZwOfrCtBaVpHb+O5gDRU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777489575; c=relaxed/simple; bh=v6/9V/mp+0VaUqiO4OggX9M3nsJ9rsEkbG6fS3iZ24o=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=CV52kh4kvhXOIH69sa856/XPMxkPjrtWVZ/LujUoZr83orqcPsr1SFJXGyS43r5GyUgKRoy/5Iw3Z+dYwVMPDTvonM5JD+DATcN2Xh+bEfIxCfgqutEmzdB83Kg14ACQ1eOlYXI80eoDpeq6hZLunuoPL42jA5gBzxwTIZF2Zrk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ieee.org; spf=pass smtp.mailfrom=ieee.org; dkim=pass (1024-bit key) header.d=ieee.org header.i=@ieee.org header.b=fdSguQNj; arc=none smtp.client-ip=209.85.210.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ieee.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ieee.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ieee.org header.i=@ieee.org header.b="fdSguQNj" Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-7dbe437b072so87722a34.2 for ; Wed, 29 Apr 2026 12:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ieee.org; s=google; t=1777489573; x=1778094373; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=tLp77h37TVQdWoQsotndHzDBo5bpvvkPFhWBJBsBzYc=; b=fdSguQNjqLtGBdBpn8vqsF50gEHLhFAzDZI11aRQ+hRC7SnFaxrmtvazmMiVwQr6Qk 9VIx4qH7N6COIPqkP/bKOnM6ykzb6ABaivLxN50LadNB4ld45pwV5I/QTKhVGXX4UwlK bd2zvgMbvED6DMRS//um3wq58CFSG1yqjAaH0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777489573; x=1778094373; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tLp77h37TVQdWoQsotndHzDBo5bpvvkPFhWBJBsBzYc=; b=LO38kHMYr3JfhtNb52ptGcKzsEJWSWYqia0fttnc6WqvfSsjUr++8FmJejOHjgi/Dc p8Ihi4SCHUpumD7rtiqowD2hb2SKFQclEvDTZLVGJwerWjxO96wGsVOFDR8yGeTj/VBH 14fr5JQ78+WWn/zjkasxvM6b/OHl5I76CuBB4oSs5Glz7mjAOcxxumNdO5/Vqv35e3PN nRFd/MZxUhgdeBl+Q7uKdMITv3U44XBSkTkUN9y9YWeCq7fGcyUiHokCZkZJVHWJiwGO QdskpVfmr6aw/O9BR1srrqFDecksO48G5NkoW0vOLQ9kql/Yw7HMPwLsHHAn3ey7nXub YdWA== X-Forwarded-Encrypted: i=1; AFNElJ85ZzCg60vh1jUUiSxNivzr7FF82HwlCnilC6Uu51G2EDCOpETwAmuEXj7WawHwYd0KawN7zjjL8dMUFSo=@vger.kernel.org X-Gm-Message-State: AOJu0YzmJ+a3MOwM/H8btyEgwPT83MwkUOls9pnO2eyNFVFZFKNA7Myx jiASdE6wMvmQBfFCm1TJ1RBUaAwTsH1OBmvJhYIf0xrnmMRr9zRNgc++eVoLAJ4kyw== X-Gm-Gg: AeBDieu3Uj0IAO1DmfWVUQjsA9JcV1tb4446LvOK4P+io/EZB5uE4EIxAExxJIvHZkU +gmzPDNTPnmJvEO02RvjFVd3vMmS2b1j45GJ3eXjoYePgcOCJS+iSmH25/rd1FVGS+s967CLEqi tKvrIp7RDY4TULeGRC8SnpdScM1A2mcNwNe8A9EeW61UehDvl+GD+s7ciZiatWSzUSVizOjdauJ EsQBWc+hUwtscnqNnpEsfcgfI7Ln/+IxPEEuAberzqUY8rEYJEa/K6OtDI/sK8j4jT5GGr+NTk4 PpCBhs+xEsr6zDBfp6k0QSYG+jz01WjZpSP/XOygR/Hke1y8krNaXjKVkFfdHSAaB5jiaasxW+e MzNVOAmpY5eup5JNgELm+kx39aEmjBomYNySHSF6wYwvSYpxUHwrFfdwYxo6DSngjXHeQS3Syf4 b4DoRTlQJfxdxnXBpbLMdckuVfAIWb5AJu/Vma/eravPOcnWaY1fcWU26xB4T7kyU38OF7Yjexi ZwFJTU= X-Received: by 2002:a05:6830:6008:b0:7de:44a5:51ea with SMTP id 46e09a7af769-7deba07072emr31818a34.6.1777489573064; Wed, 29 Apr 2026 12:06:13 -0700 (PDT) Received: from [172.22.22.28] (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.googlemail.com with ESMTPSA id 46e09a7af769-7deab9d5b9asm1822657a34.21.2026.04.29.12.06.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Apr 2026 12:06:12 -0700 (PDT) Message-ID: <856f4e8d-ff7c-4744-9624-e838c758f009@ieee.org> Date: Wed, 29 Apr 2026 14:06:11 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 2/3] spi: spacemit: introduce SpacemiT K1 SPI controller driver To: Mark Brown , Guodong Xu Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Yixun Lan , Alex Elder , Philipp Zabel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, spacemit@lists.linux.dev, linux-kernel@vger.kernel.org, Alex Elder References: <20260427-spi-spacemit-k1-v9-0-ff753b551302@riscstar.com> <20260427-spi-spacemit-k1-v9-2-ff753b551302@riscstar.com> Content-Language: en-US From: Alex Elder In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/27/26 7:17 PM, Mark Brown wrote: > On Mon, Apr 27, 2026 at 10:01:28PM -0400, Guodong Xu wrote: > >> +static int k1_spi_transfer_one(struct spi_controller *host, >> + struct spi_device *spi, >> + struct spi_transfer *transfer) >> +{ > >> + /* Record how many words the len bytes represent */ >> + count = transfer->len / drv_data->bytes; >> + drv_data->rx_resid = count; >> + drv_data->tx_resid = count; > > This is setting up _resid with a number of words. Guodong, see below, but I think the above should be: drv_data->rx_resid = transfer->len; drv_data->tx_resid = transfer->len; >> +static void k1_spi_write_word(struct k1_spi_driver_data *drv_data) >> +{ >> + struct spi_transfer *transfer = drv_data->transfer; >> + u32 bytes = drv_data->bytes; >> + u32 val; >> + >> + if (transfer->tx_buf) { >> + const void *buf; >> + >> + buf = transfer->tx_buf + (transfer->len - drv_data->tx_resid); > > This is using _resid as a byte count. It'll be fine for 8 bits per word > (which is by far the most common thing). You're right, this is a really great observation. The best thing is probably to just have the *_resid symbols represent bytes. (Their definitions in the structure say that as well.) k1_spi_write_word() decrements tx_resid by the number of bytes transferred, so that's OK. But the FIFO handles words, and k1_spi_write() limits the number of *words* transferred, so the "count" calculation there needs to take the word size into account. Something like: /**/ unsigned int resid_words; unsigned int count; /* Get the number of open slots in the FIFO; zero means all */ count = FIELD_GET(SSP_STATUS_TFL, val) ? : K1_SPI_FIFO_SIZE; /* * Limit how much we try to send at a time, to reduce the * chance the other side can overrun our RX FIFO. */ /**/ resid_words = drv_data->tx_resid / drv_data->bytes; /**/ count = min3(count, K1_SPI_THRESH, resid_words); do k1_spi_write_word(drv_data); while (--count); return !drv_data->tx_resid; And we have the same problem in k1_spi_read(). There you can probably change this: count = min(count, drv_data->rx_resid); to this count = min(count, drv_data->rx_resid / drv_data->bytes); You'll want to review and test yourself, but scanning through the code this is what I see. -Alex