From: Malcolm Priestley <tvboxspy@gmail.com>
To: linux-media@vger.kernel.org
Subject: [PATCH 5/7] af9015 usb bus repeater.
Date: Sat, 12 Nov 2011 15:56:20 +0000 [thread overview]
Message-ID: <4ebe9728.4dc6e30a.47c5.ffff8fc3@mx.google.com> (raw)
This a bus repeater for af9015 devices. Commands usually fail because of other
activity on the usb bus.
Afatech drivers can repeat up to ten times on the usb bus.
bulk failures that report -ETIMEDOUT or -EBUSY are repeated. If the device fails
it usually return 0x55 in the first byte.
I am working on a patch to move parts of this to the dvb-usb common area to
be used by other drivers.
Signed-off-by: Malcolm Priestley<tvboxspy@gmail.com>
---
drivers/media/dvb/dvb-usb/af9015.c | 61 ++++++++++++++++++++++--------------
1 files changed, 37 insertions(+), 24 deletions(-)
diff --git a/drivers/media/dvb/dvb-usb/af9015.c b/drivers/media/dvb/dvb-usb/af9015.c
index 9077ac4..ac134b6 100644
--- a/drivers/media/dvb/dvb-usb/af9015.c
+++ b/drivers/media/dvb/dvb-usb/af9015.c
@@ -68,7 +68,7 @@ static struct af9013_config af9015_af9013_config[] = {
}
};
-static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
+static int af9015_io_udev(struct usb_device *udev, struct req_t *req)
{
#define BUF_LEN 63
#define REQ_HDR_LEN 8 /* send header size */
@@ -79,9 +79,6 @@ static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
u8 msg_len = REQ_HDR_LEN;
static u8 seq; /* packet sequence number */
- if (mutex_lock_interruptible(&af9015_usb_mutex) < 0)
- return -EAGAIN;
-
buf[0] = req->cmd;
buf[1] = seq++;
buf[2] = req->i2c_addr;
@@ -114,16 +111,14 @@ static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
break;
default:
err("unknown command:%d", req->cmd);
- ret = -1;
- goto error_unlock;
+ return -EINVAL;
}
/* buffer overflow check */
if ((write && (req->data_len > BUF_LEN - REQ_HDR_LEN)) ||
(!write && (req->data_len > BUF_LEN - ACK_HDR_LEN))) {
err("too much data; cmd:%d len:%d", req->cmd, req->data_len);
- ret = -EINVAL;
- goto error_unlock;
+ return -EINVAL;
}
/* write requested */
@@ -142,13 +137,13 @@ static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
err("bulk message failed:%d (%d/%d)", ret, msg_len, act_len);
else
if (act_len != msg_len)
- ret = -1; /* all data is not send */
+ return -EAGAIN; /* all data is not send */
if (ret)
- goto error_unlock;
+ goto error;
/* no ack for those packets */
if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB)
- goto exit_unlock;
+ return 0;
/* write receives seq + status = 2 bytes
read receives seq + status + data = 2 + N bytes */
@@ -158,30 +153,48 @@ static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len,
&act_len, AF9015_USB_TIMEOUT);
- if (ret) {
- err("recv bulk message failed:%d", ret);
- ret = -1;
- goto error_unlock;
- }
+ if (ret)
+ goto error;
deb_xfer("<<< ");
debug_dump(buf, act_len, deb_xfer);
/* check status */
- if (buf[1]) {
- err("command failed:%d", buf[1]);
- ret = -1;
- goto error_unlock;
- }
+ if (buf[1])
+ return -EAGAIN;
/* read request, copy returned data to return buf */
if (!write)
memcpy(req->data, &buf[ACK_HDR_LEN], req->data_len);
-error_unlock:
-exit_unlock:
- mutex_unlock(&af9015_usb_mutex);
+error:
+ if (ret == -ETIMEDOUT || ret == -EBUSY)
+ return -EAGAIN;
+
+ return ret;
+}
+
+#define AF9015_RETRY 5
+static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
+{
+ int ret = 0, i;
+
+ if (mutex_lock_interruptible(&af9015_usb_mutex) < 0)
+ return -EAGAIN;
+
+ for (i = 0; i < AF9015_RETRY; i++) {
+ if (req == NULL)
+ break;
+ ret = af9015_io_udev(udev, req);
+ if (ret != -EAGAIN)
+ break;
+ udelay(250);
+ }
+ if (ret && req)
+ err("Command failed:%x i2c addr:%x error:%d",
+ req->cmd, req->i2c_addr, ret);
+ mutex_unlock(&af9015_usb_mutex);
return ret;
}
--
1.7.5.4
next reply other threads:[~2011-11-12 15:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-12 15:56 Malcolm Priestley [this message]
2011-11-12 16:54 ` [PATCH 5/7] af9015 usb bus repeater Antti Palosaari
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=4ebe9728.4dc6e30a.47c5.ffff8fc3@mx.google.com \
--to=tvboxspy@gmail.com \
--cc=linux-media@vger.kernel.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