[haiku-commits] haiku: hrev49000 - in src: add-ons/kernel/drivers/input/usb_hid system/kernel/cache

  • From: ithamar@xxxxxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 5 Apr 2015 22:18:36 +0200 (CEST)

hrev49000 adds 3 changesets to branch 'master'
old head: 7f0d2c98b60a9910e0260be1531eb3f3f910c049
new head: efdcada6f30bd510641bfda1b15ab374bc22c04a
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=efdcada6f30b+%5E7f0d2c98b60a

----------------------------------------------------------------------------

7f440923c899: usb_hid: make sure removed devices do not get published

On many SMP systems, publish_devices() would get called before the
free() hook was triggered, resulting in removed devices still being
published.

Fix sponsered by http://www.izcorp.com

f1a02a8e1e57: usb_hid: fix STALL handling

It is not allowed to do synchronous calls to the usb bus manager
while in a usb callback routine. This causes the usb stack to get
very confused.

This code now uses the async interface to clear the STALL, and will
try to continue normal operations after that request has been handled.

Fix sponsered by http://www.izcorp.com

efdcada6f30b: BlockWriter: Do not panic on failing read/writes

These were here for debugging purposes, as often it is a sign of
inconsistencies. However, for USB disks this is a normal occurence
when someone janks out of the device without unmounting first.

Make sure we log these cases though, as it still helps debugging.

Fix sponsered by http://www.izcorp.com

[ Ithamar R. Adema <ithamar@xxxxxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

4 files changed, 34 insertions(+), 21 deletions(-)
.../kernel/drivers/input/usb_hid/Driver.cpp | 23 ++++++--------------
.../kernel/drivers/input/usb_hid/HIDDevice.cpp | 22 ++++++++++++++++---
.../kernel/drivers/input/usb_hid/HIDDevice.h | 4 ++++
src/system/kernel/cache/block_cache.cpp | 6 +++--

############################################################################

Commit: 7f440923c899626f39cb56c6a923ecf4b61566dd
URL: http://cgit.haiku-os.org/haiku/commit/?id=7f440923c899
Author: Ithamar R. Adema <ithamar@xxxxxxxxxxxxxxxxxxx>
Date: Sun Mar 15 15:48:16 2015 UTC

usb_hid: make sure removed devices do not get published

On many SMP systems, publish_devices() would get called before the
free() hook was triggered, resulting in removed devices still being
published.

Fix sponsered by http://www.izcorp.com

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp
b/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp
index 51ca81f..f194056 100644
--- a/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp
+++ b/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp
@@ -170,13 +170,6 @@ usb_hid_device_removed(void *cookie)
if (device->ParentCookie() != parentCookie)
continue;

- // this handler's device belongs to the one removed
- if (device->IsOpen()) {
- // the device and it's handlers will be deleted in the
free hook
- device->Removed();
- break;
- }
-
// remove all the handlers
for (uint32 i = 0;; i++) {
handler = device->ProtocolHandlerAt(i);
@@ -186,7 +179,13 @@ usb_hid_device_removed(void *cookie)
gDeviceList->RemoveDevice(NULL, handler);
}

- delete device;
+ // this handler's device belongs to the one removed
+ if (device->IsOpen()) {
+ // the device and it's handlers will be deleted in the
free hook
+ device->Removed();
+ } else
+ delete device;
+
break;
}

@@ -287,14 +286,6 @@ usb_hid_free(void *_cookie)
} else if (device->IsRemoved()) {
// the parent device is removed already and none of its
handlers are
// open anymore so we can free it here
- for (uint32 i = 0;; i++) {
- ProtocolHandler *handler = device->ProtocolHandlerAt(i);
- if (handler == NULL)
- break;
-
- gDeviceList->RemoveDevice(NULL, handler);
- }
-
delete device;
}


############################################################################

Commit: f1a02a8e1e570ec209443c5ce1dff417d7c7d80b
URL: http://cgit.haiku-os.org/haiku/commit/?id=f1a02a8e1e57
Author: Ithamar R. Adema <ithamar@xxxxxxxxxxxxxxxxxxx>
Date: Sun Mar 15 17:34:47 2015 UTC

usb_hid: fix STALL handling

It is not allowed to do synchronous calls to the usb bus manager
while in a usb callback routine. This causes the usb stack to get
very confused.

This code now uses the async interface to clear the STALL, and will
try to continue normal operations after that request has been handled.

Fix sponsered by http://www.izcorp.com

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp
b/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp
index 9348370..7ed6017 100644
--- a/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp
+++ b/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.cpp
@@ -170,6 +170,7 @@ HIDDevice::HIDDevice(usb_device device, const
usb_configuration_info *config,
if ((descriptor->endpoint_address & USB_ENDPOINT_ADDR_DIR_IN)
&& (descriptor->attributes & USB_ENDPOINT_ATTR_MASK)
== USB_ENDPOINT_ATTR_INTERRUPT) {
+ fEndpointAddress = descriptor->endpoint_address;
fInterruptPipe = interface->endpoint[i].handle;
break;
}
@@ -310,16 +311,31 @@ HIDDevice::ProtocolHandlerAt(uint32 index) const


void
+HIDDevice::_UnstallCallback(void *cookie, status_t status, void *data,
+ size_t actualLength)
+{
+ HIDDevice *device = (HIDDevice *)cookie;
+ if (status != B_OK) {
+ TRACE_ALWAYS("Unable to unstall device: %s\n",
strerror(status));
+ }
+
+ // Now report the original failure, since we're ready to retry
+ _TransferCallback(cookie, B_ERROR, device->fTransferBuffer, 0);
+}
+
+
+void
HIDDevice::_TransferCallback(void *cookie, status_t status, void *data,
size_t actualLength)
{
HIDDevice *device = (HIDDevice *)cookie;
if (status == B_DEV_STALLED && !device->fRemoved) {
// try clearing stalls right away, the report listeners will
resubmit
- gUSBModule->clear_feature(device->fInterruptPipe,
- USB_FEATURE_ENDPOINT_HALT);
+ gUSBModule->queue_request(device->fDevice,
+ USB_REQTYPE_STANDARD | USB_REQTYPE_ENDPOINT_OUT,
USB_REQUEST_CLEAR_FEATURE,
+ USB_FEATURE_ENDPOINT_HALT, device->fEndpointAddress, 0,
NULL, _UnstallCallback, device);
+ return;
}
-
atomic_set(&device->fTransferScheduled, 0);
device->fParser.SetReport(status, device->fTransferBuffer,
actualLength);
}
diff --git a/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.h
b/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.h
index 744b9ba..8cd8b95 100644
--- a/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.h
+++ b/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.h
@@ -48,12 +48,16 @@ private:
static void _TransferCallback(void *cookie,

status_t status, void *data,
size_t
actualLength);
+ static void _UnstallCallback(void *cookie,
+
status_t status, void *data,
+ size_t
actualLength);

private:
status_t fStatus;
usb_device fDevice;
usb_pipe fInterruptPipe;
size_t fInterfaceIndex;
+ uint8 fEndpointAddress;

int32 fTransferScheduled;
size_t fTransferBufferSize;

############################################################################

Revision: hrev49000
Commit: efdcada6f30bd510641bfda1b15ab374bc22c04a
URL: http://cgit.haiku-os.org/haiku/commit/?id=efdcada6f30b
Author: Ithamar R. Adema <ithamar@xxxxxxxxxxxxxxxxxxx>
Date: Mon Mar 30 17:23:07 2015 UTC

BlockWriter: Do not panic on failing read/writes

These were here for debugging purposes, as often it is a sign of
inconsistencies. However, for USB disks this is a normal occurence
when someone janks out of the device without unmounting first.

Make sure we log these cases though, as it still helps debugging.

Fix sponsered by http://www.izcorp.com

----------------------------------------------------------------------------

diff --git a/src/system/kernel/cache/block_cache.cpp
b/src/system/kernel/cache/block_cache.cpp
index 36af948..ce08c5d 100644
--- a/src/system/kernel/cache/block_cache.cpp
+++ b/src/system/kernel/cache/block_cache.cpp
@@ -40,6 +40,8 @@
# define TRACE(x) ;
#endif

+#define TRACE_ALWAYS(x) dprintf x
+
// This macro is used for fatal situations that are acceptable in a running
// system, like out of memory situations - should only panic for debugging.
#define FATAL(x) panic x
@@ -1239,7 +1241,7 @@ BlockWriter::_WriteBlock(cached_block* block)

if (written != (ssize_t)blockSize) {
TB(Error(fCache, block->block_number, "write failed", written));
- FATAL(("could not write back block %" B_PRIdOFF " (%s)\n",
block->block_number,
+ TRACE_ALWAYS(("could not write back block %" B_PRIdOFF "
(%s)\n", block->block_number,
strerror(errno)));
if (written < 0)
return errno;
@@ -1902,7 +1904,7 @@ retry:
cache->RemoveBlock(block);
TB(Error(cache, blockNumber, "read failed", bytesRead));

- FATAL(("could not read block %" B_PRIdOFF ": bytesRead:
%zd, error: %s\n",
+ TRACE_ALWAYS(("could not read block %" B_PRIdOFF ":
bytesRead: %zd, error: %s\n",
blockNumber, bytesRead, strerror(errno)));
return NULL;
}


Other related posts:

  • » [haiku-commits] haiku: hrev49000 - in src: add-ons/kernel/drivers/input/usb_hid system/kernel/cache - ithamar