mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: marc.ferland@gmail.com
To: krzysztof.kozlowski@linaro.org
Cc: gregkh@linuxfoundation.org, marc.ferland@sonatest.com,
	jeff.dagenais@gmail.com, rdunlap@infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 7/7] w1: ds2490: support buffer sizes bigger than 128
Date: Fri, 17 Nov 2023 14:29:09 -0500	[thread overview]
Message-ID: <20231117192909.98944-7-marc.ferland@sonatest.com> (raw)
In-Reply-To: <20231117192909.98944-1-marc.ferland@sonatest.com>

From: Marc Ferland <marc.ferland@sonatest.com>

The ds_read_block and ds_write_block functions only support buffer
sizes up to 128 bytes, which is the depth of the fifo on the ds2490.

Sending bigger buffers will fail with a: -110 (ETIMEDOUT) from
usb_control_msg():

    usb 5-1: Failed to write 1-wire data to ep0x2: err=-110.

Also, from the datasheet (2995.pdf, page 22, BLOCK I/O command):

     For a block write sequence the EP2 FIFO must be pre-filled with
     data before command execution. Additionally, for block sizes
     greater then the FIFO size, the FIFO content status must be
     monitored by host SW so that additional data can be sent to the
     FIFO when necessary. A similar EP3 FIFO content monitoring
     requirement exists for block read sequences. During a block read
     the number of bytes loaded into the EP3 FIFO must be monitored so
     that the data can be read before the FIFO overflows.

Breaking the buffer in 128 bytes blocks and simply calling the
original code sequence has solved the issue for me.

Tested with a DS1490F usb<->one-wire adapter and a DS28EC20 eeprom
memory.

Signed-off-by: Marc Ferland <marc.ferland@sonatest.com>
---
 drivers/w1/masters/ds2490.c | 45 ++++++++++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/drivers/w1/masters/ds2490.c b/drivers/w1/masters/ds2490.c
index 5f5b97e24700..d0a1a0b8b7ff 100644
--- a/drivers/w1/masters/ds2490.c
+++ b/drivers/w1/masters/ds2490.c
@@ -98,6 +98,8 @@
 #define ST_EPOF				0x80
 /* Status transfer size, 16 bytes status, 16 byte result flags */
 #define ST_SIZE				0x20
+/* 1-wire data i/o fifo size, 128 bytes */
+#define FIFO_SIZE                       0x80
 
 /* Result Register flags */
 #define RR_DETECT			0xA5 /* New device detected */
@@ -614,14 +616,11 @@ static int ds_read_byte(struct ds_device *dev, u8 *byte)
 	return 0;
 }
 
-static int ds_read_block(struct ds_device *dev, u8 *buf, int len)
+static int __read_block(struct ds_device *dev, u8 *buf, int len)
 {
 	struct ds_status st;
 	int err;
 
-	if (len > 64*1024)
-		return -E2BIG;
-
 	memset(buf, 0xFF, len);
 
 	err = ds_send_data(dev, buf, len);
@@ -640,7 +639,25 @@ static int ds_read_block(struct ds_device *dev, u8 *buf, int len)
 	return err;
 }
 
-static int ds_write_block(struct ds_device *dev, u8 *buf, int len)
+static int ds_read_block(struct ds_device *dev, u8 *buf, int len)
+{
+	int err, to_read, rem = len;
+
+	if (len > 64*1024)
+		return -E2BIG;
+
+	do {
+		to_read = rem <= FIFO_SIZE ? rem : FIFO_SIZE;
+		err = __read_block(dev, &buf[len - rem], to_read);
+		if (err < 0)
+			return err;
+		rem -= to_read;
+	} while (rem);
+
+	return err;
+}
+
+static int __write_block(struct ds_device *dev, u8 *buf, int len)
 {
 	int err;
 	struct ds_status st;
@@ -665,6 +682,24 @@ static int ds_write_block(struct ds_device *dev, u8 *buf, int len)
 	return !(err == len);
 }
 
+static int ds_write_block(struct ds_device *dev, u8 *buf, int len)
+{
+	int err, to_write, rem = len;
+
+	if (len > 64*1024)
+		return -E2BIG;
+
+	do {
+		to_write = rem <= FIFO_SIZE ? rem : FIFO_SIZE;
+		err = __write_block(dev, &buf[len - rem], to_write);
+		if (err < 0)
+			return err;
+		rem -= to_write;
+	} while (rem);
+
+	return err;
+}
+
 static void ds9490r_search(void *data, struct w1_master *master,
 	u8 search_type, w1_slave_found_callback callback)
 {
-- 
2.34.1


  parent reply	other threads:[~2023-11-17 19:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 19:29 [PATCH 1/7] w1: ds2433: remove unused definition marc.ferland
2023-11-17 19:29 ` [PATCH 2/7] w1: ds2433: add support for registering multiple families marc.ferland
2023-11-20  9:22   ` Krzysztof Kozlowski
2023-11-17 19:29 ` [PATCH 3/7] w1: ds2433: rename W1_EEPROM_DS2433 marc.ferland
2023-11-20  9:24   ` Krzysztof Kozlowski
2023-11-17 19:29 ` [PATCH 4/7] w1: ds2433: introduce a configuration structure marc.ferland
2023-11-18  6:33   ` kernel test robot
2023-11-17 19:29 ` [PATCH 5/7] w1: ds2433: rename w1_f23_data to w1_data marc.ferland
2023-11-20  9:24   ` Krzysztof Kozlowski
2023-11-17 19:29 ` [PATCH 6/7] w1: ds2433: add support for ds28ec20 eeprom marc.ferland
2023-11-20  9:26   ` Krzysztof Kozlowski
2023-11-21 16:37     ` Marc Ferland
2023-11-17 19:29 ` marc.ferland [this message]
2023-11-27 20:18 ` [PATCH v2 0/5] Add support for the ds28ec20 one-wire eeprom marc.ferland
2023-11-27 20:18   ` [PATCH v2 1/5] w1: ds2490: support block sizes larger than 128 bytes in ds_read_block marc.ferland
2023-11-27 20:18   ` [PATCH v2 2/5] w1: ds2433: remove unused definition marc.ferland
2023-11-27 20:18   ` [PATCH v2 3/5] w1: ds2433: introduce a configuration structure marc.ferland
2023-11-27 20:18   ` [PATCH v2 4/5] w1: ds2433: use the kernel bitmap implementation marc.ferland
2023-11-27 20:18   ` [PATCH v2 5/5] w1: ds2433: add support for ds28ec20 eeprom marc.ferland
2023-11-28  9:08   ` [PATCH v2 0/5] Add support for the ds28ec20 one-wire eeprom Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231117192909.98944-7-marc.ferland@sonatest.com \
    --to=marc.ferland@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jeff.dagenais@gmail.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.ferland@sonatest.com \
    --cc=rdunlap@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®