usb: align buffers at cacheline
PATCH v9 1/1 usb: align buffers at cacheline
This avoids cache-alignment warnings shown in console when a usb command is entered.
Whenever X bytes of unaligned buffer is invalidated, arm core invalidates X + Y bytes as per the cache line size and throws these warnings.
---
This patch is tested on "denx-uboot-arm/master". Stop address alignment warnings still seen which should not be suppressed. See further discussion on this @
http://lists.denx.de/pipermail/u-boot/2012-March/120031.html
Changes for V7:
- Trivial change, missed removing memcpy. Removed now.
Changes for V8:
- Corrected "setup_packet" allocation using "ALLOC_CACHE_ALIGN_BUFFER".
common/cmd_usb.c | 3 +- common/usb.c | 22 +++++++++--------- common/usb_hub.c | 27 +++++++++++----------- common/usb_storage.c | 59 +++++++++++++++++++++++-------------------------- disk/part_dos.c | 2 +- include/scsi.h | 4 ++- include/usb.h | 4 ++- 7 files changed, 62 insertions(+), 59 deletions(-)
common/cmd_usb.c +2 -1
@@ -150,7 +150,8 @@ void usb_display_class_sub(unsigned char dclass, unsigned char subclass,void usb_display_string (struct usb_device *dev,int index) { -char buffer[256 ]; +ALLOC_CACHE_ALIGN_BUFFER (char, buffer,256 ); +if (index !=0 ) {if (usb_string (dev, index, &buffer[0 ],256 ) >0 )printf ("String: \"%s\"" , buffer);
common/usb.c +11 -11
@@ -169,7 +169,7 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, unsigned short value, unsigned short index, void *data, unsigned short size, int timeout) { - struct devrequest setup_packet; + ALLOC_CACHE_ALIGN_BUFFER(struct devrequest, setup_packet, 1);if ((timeout ==0 ) && (!asynch_allowed)) {/* request for a asynch control pipe is not allowed */
@@ -177,17 +177,17 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, }/* set setup command */ - setup_packet.requesttype = requesttype; - setup_packet.request = request; - setup_packet.value =cpu_to_le16 (value); - setup_packet.index =cpu_to_le16 (index); - setup_packet.length =cpu_to_le16 (size); + setup_packet->requesttype = requesttype; + setup_packet->request = request; + setup_packet->value =cpu_to_le16 (value); + setup_packet->index =cpu_to_le16 (index); + setup_packet->length =cpu_to_le16 (size);USB_PRINTF ("usb_control_msg: request: 0x%X, requesttype: 0x%X, " \"value 0x%X index 0x%X length 0x%X\n" , request, requesttype, value, index, size); dev->status =USB_ST_NOT_PROC ;/*not yet processed */ -submit_control_msg (dev, pipe, data, size, &setup_packet); +submit_control_msg (dev, pipe, data, size, setup_packet);if (timeout ==0 )return (int )size;
@@ -681,7 +681,7 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid,*/ int usb_string (struct usb_device *dev,int index,char *buf,size_t size) { -unsigned char mybuf[USB_BUFSIZ ]; + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, mybuf, USB_BUFSIZ);unsigned char *tbuf;int err;unsigned int u, idx;
@@ -781,7 +781,7 @@ int usb_new_device(struct usb_device *dev) {int addr, err;int tmp; -unsigned char tmpbuf[USB_BUFSIZ ]; + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, tmpbuf, USB_BUFSIZ);/* We still haven't set the Address yet */ addr = dev->devnum;
@@ -908,8 +908,8 @@ int usb_new_device(struct usb_device *dev)le16_to_cpus (&dev->descriptor.idProduct);le16_to_cpus (&dev->descriptor.bcdDevice);/* only support for one config for now */ -usb_get_configuration_no (dev, &tmpbuf[0 ],0 ); -usb_parse_config (dev, &tmpbuf[0 ],0 ); +usb_get_configuration_no (dev, tmpbuf,0 ); +usb_parse_config (dev, tmpbuf,0 );usb_set_maxpacket (dev);/* we set the default configuration here */ if (usb_set_configuration (dev, dev->config.desc.bConfigurationValue)) {
common/usb_hub.c +14 -13
@@ -153,7 +153,7 @@ int hub_port_reset(struct usb_device *dev, int port, unsigned short *portstat) {int tries; -struct usb_port_status portsts; + ALLOC_CACHE_ALIGN_BUFFER(struct usb_port_status, portsts, 1);unsigned short portstatus, portchange;USB_HUB_PRINTF ("hub_port_reset: resetting port %d...\n" , port);
@@ -162,13 +162,13 @@ int hub_port_reset(struct usb_device *dev, int port,usb_set_port_feature (dev, port +1 ,USB_PORT_FEAT_RESET );mdelay (200 ); -if (usb_get_port_status (dev, port +1 , &portsts) <0 ) { +if (usb_get_port_status (dev, port +1 , portsts) <0 ) {USB_HUB_PRINTF ("get_port_status failed status %lX\n" , dev->status);return -1 ; } - portstatus =le16_to_cpu (portsts.wPortStatus); - portchange =le16_to_cpu (portsts.wPortChange); + portstatus =le16_to_cpu (portsts->wPortStatus); + portchange =le16_to_cpu (portsts->wPortChange); USB_HUB_PRINTF("portstatus %x, change %x, %s\n", portstatus, portchange,
@@ -206,19 +206,19 @@ int hub_port_reset(struct usb_device *dev, int port,void usb_hub_port_connect_change (struct usb_device *dev,int port) {struct usb_device *usb; -struct usb_port_status portsts; + ALLOC_CACHE_ALIGN_BUFFER(struct usb_port_status, portsts, 1);unsigned short portstatus;/* Check status */ -if (usb_get_port_status (dev, port +1 , &portsts) <0 ) { +if (usb_get_port_status (dev, port +1 , portsts) <0 ) {USB_HUB_PRINTF ("get_port_status failed\n" );return ; } - portstatus =le16_to_cpu (portsts.wPortStatus); + portstatus =le16_to_cpu (portsts->wPortStatus);USB_HUB_PRINTF ("portstatus %x, change %x, %s\n" , portstatus, -le16_to_cpu (portsts.wPortChange), +le16_to_cpu (portsts->wPortChange),portspeed (portstatus));/* Clear the connection change status */
@@ -267,7 +267,8 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)static int usb_hub_configure (struct usb_device *dev) {int i; -unsigned char buffer[USB_BUFSIZ ], *bitmap; + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, USB_BUFSIZ); +unsigned char *bitmap;struct usb_hub_descriptor *descriptor;struct usb_hub_device *hub;#ifdef USB_HUB_DEBUG
@@ -389,16 +390,16 @@ static int usb_hub_configure(struct usb_device *dev)usb_hub_power_on (hub);for (i =0 ; i < dev->maxchild; i++) { -struct usb_port_status portsts; + ALLOC_CACHE_ALIGN_BUFFER(struct usb_port_status, portsts, 1);unsigned short portstatus, portchange; -if (usb_get_port_status (dev, i +1 , &portsts) <0 ) { +if (usb_get_port_status (dev, i +1 , portsts) <0 ) {USB_HUB_PRINTF ("get_port_status failed\n" );continue ; } - portstatus =le16_to_cpu (portsts.wPortStatus); - portchange =le16_to_cpu (portsts.wPortChange); + portstatus =le16_to_cpu (portsts->wPortStatus); + portchange =le16_to_cpu (portsts->wPortChange);USB_HUB_PRINTF ("Port %d Status %X Change %X\n" , i +1 , portstatus, portchange);
common/usb_storage.c +28 -31
150 lines not on this page · raw message
disk/part_dos.c +1 -1
@@ -87,7 +87,7 @@ static int test_block_type(unsigned char *buffer)int test_part_dos (block_dev_desc_t *dev_desc) { -unsigned char buffer[dev_desc->blksz]; + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *) buffer) != 1) || (buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) ||
include/scsi.h +3 -1
@@ -26,7 +26,9 @@ typedef struct SCSI_cmd_block{ unsigned char cmd[16]; /* command */ - unsigned char sense_buf[64]; /* for request sense */ + /* for request sense */ + unsigned char sense_buf[64] + __attribute__((aligned(ARCH_DMA_MINALIGN))); unsigned char status; /* SCSI Status */ unsigned char target; /* Target ID */ unsigned char lun; /* Target LUN */
include/usb.h +3 -1
@@ -109,7 +109,9 @@ struct usb_device {int epmaxpacketout[16 ];/* OUTput endpoint specific maximums */ int configno;/* selected config number */ -struct usb_device_descriptor descriptor;/* Device Descriptor */ +/* Device Descriptor */ + struct usb_device_descriptor descriptor + __attribute__((aligned(ARCH_DMA_MINALIGN)));struct usb_config config;/* config descriptor */ int have_langid;/* whether string_langid is valid yet */
Signature · 1 line
1.7.1
PATCH v9 1/1 usb: align buffers at cacheline
Dear Puneet Saxena,
Quoted 9 lines
This avoids cache-alignment warnings shown in console when a usb command is entered.
Whenever X bytes of unaligned buffer is invalidated, arm core invalidates X + Y bytes as per the cache line size and throws these warnings.
Signed-off-by Puneet Saxena <[email protected]>---
I think we're almost there, hurray! :-)
Though on m28evk this still has issues:
=> usb reset
(Re)start USB...
USB: Register 10011 NbrPorts 1
USB EHCI 1.00
scanning bus for devices... EHCI timed out on TD - token=0x80008c80 EHCI timed out on TD - token=0x80008d80
EHCI timed out on TD - token=0x80008c80
EHCI timed out on TD - token=0x80008c80
EHCI timed out on TD - token=0x80008c80
ERROR: NOT USB_CONFIG_DESC 1
EHCI timed out on TD - token=0x80008d80
2 USB Device(s) found
scanning bus for storage devices... 0 Storage Device(s) found
I have a single USB pendrive connected to the board.
Also note, that if I disable the caches, it all works even with your patch applied. So I suspect there's something even more to this (maybe broken ehci_invalidate_dcache() ? ). Where did you test these patches?
Thanks!
Best regards,
Marek Vasut
PATCH v9 1/1 usb: align buffers at cacheline
Hi Marek,
I tested on tegra2, Seaboard and didn't see these messages though see lots of messages
"ERROR: v7_dcache_inval_range - stop address is not aligned - 0x3fb7c608" which are expected.
PFA the logs if you can make out anything useful.
Try to increase the delay in handshake();
Thanks,
Puneet
Quoted 31 lines · Marek Vasut
Dear Puneet Saxena,
Quoted 9 lines
This avoids cache-alignment warnings shown in console when a usb command is entered.
Whenever X bytes of unaligned buffer is invalidated, arm core invalidates X + Y bytes as per the cache line size and throws these warnings.
Signed-off-by Puneet Saxena<[email protected]>---
I think we're almost there, hurray! :-)
Though on m28evk this still has issues:
=> usb reset
(Re)start USB...
USB: Register 10011 NbrPorts 1
USB EHCI 1.00
scanning bus for devices... EHCI timed out on TD - token=0x80008c80 EHCI timed out on TD - token=0x80008d80
EHCI timed out on TD - token=0x80008c80
EHCI timed out on TD - token=0x80008c80
EHCI timed out on TD - token=0x80008c80
ERROR: NOTUSB_CONFIG_DESC1
EHCI timed out on TD - token=0x80008d80
2 USB Device(s) found
scanning bus for storage devices... 0 Storage Device(s) foundI have a single USB pendrive connected to the board.
Quoted 8 lines
Also note, that if I disable the caches, it all works even with your patch applied. So I suspect there's something even more to this (maybe broken
ehci_invalidate_dcache()? ). Where did you test these patches?Thanks!
Best regards,
Marek Vasut
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pendrive_prints.txt
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120406/e74c5949/attachment.txt>