af9015 usb bus repeater.
PATCH 5/7 af9015 usb bus repeater.
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.
--- drivers/media/dvb/dvb-usb/af9015.c | 61 ++++++++++++++++++++++-------------- 1 files changed, 37 insertions(+), 24 deletions(-)
drivers/media/dvb/dvb-usb/af9015.c +37 -24
@@ -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; }
Signature · 1 line
1.7.5.4
Quoted 10 lines · Malcolm Priestley
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
-ETIMEDOUTor-EBUSYare repeated. If the device fails it usually return0x55in 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.
Repeating does not help for those I2C errors. I have already tested it. IIRC 01 and 02 was the error codes returned in case of I2C read / write.
Which command gives 0x55 for failing?
And generally only very first command will fail. There is already repeat for that. Generally I think it is good idea to add some repeating, since it is needed. But it does not make much sense to repeat for those common I2C errors since it does not matter - you can repeat forever it still fails. So first need to fix main error source.
And it is indeed good idea to generalize it, but I think it is possible only for error situations when error is returned by platform call.
1. general repeat for platform calls
2. repeat for firmware command fail (is there need?)
regards
Antti
Signature · 1 line
http://palosaari.fi/