Ticket #9311: 0001-usb_midi-fixed-handling-of-multiport-devices.patch

File 0001-usb_midi-fixed-handling-of-multiport-devices.patch, 6.4 KB (added by Pete, 11 years ago)

Up[dated (and git-formatted) patch for usb_midi driver

  • src/add-ons/kernel/drivers/midi/usb_midi/usb_midi.cpp

    From 36148198df04bfd8873b6e6ebe5dad2f4d18f296 Mon Sep 17 00:00:00 2001
    From: Pete Goodeve <pete.goodeve@computer.org>
    Date: Wed, 1 May 2013 15:11:04 -0700
    Subject: [PATCH] usb_midi: fixed handling of multiport devices
    
    ---
     .../kernel/drivers/midi/usb_midi/usb_midi.cpp      |   45 ++++++++++++--------
     .../kernel/drivers/midi/usb_midi/usb_midi.h        |    7 ++-
     2 files changed, 33 insertions(+), 19 deletions(-)
    
    diff --git a/src/add-ons/kernel/drivers/midi/usb_midi/usb_midi.cpp b/src/add-ons/kernel/drivers/midi/usb_midi/usb_midi.cpp
    index 40f58eb..7650aee 100644
    a b  
    22 * midi usb driver
    33 * usb_midi.c
    44 *
    5  * Copyright 2006-2011 Haiku Inc.  All rights reserved.
     5 * Copyright 2006-2012 Haiku Inc.  All rights reserved.
    66 * Distributed under the terms of the MIT Licence.
    77 *
    88 * Authors:
     
    1717 */
    1818
    1919
    20 /* #define DEBUG 1 */   /* Define this to enable DPRINTF_DEBUG statements */
     20/* #define DEBUG 1 */   /* Define this to enable DPRINTF_DEBUG statements */ 
    2121/* (Other categories of printout set in usb_midi.h) */
    2222
    2323#include "usb_midi.h"
    create_device(const usb_device* dev, uint16 ifno)  
    134134    midiDevice->active = true;
    135135    midiDevice->flags = 0;
    136136    memset(midiDevice->ports, 0, sizeof(midiDevice->ports));
    137     midiDevice->buffer_size = B_PAGE_SIZE / 2;
     137    midiDevice->inMaxPkt = midiDevice->outMaxPkt = B_PAGE_SIZE / 2;
     138        /* Initially -- will get reduced */
    138139    DPRINTF_INFO((MY_ID "Created device %p\n", midiDevice));
    139140
    140141    return midiDevice;
    midi_usb_read_callback(void* cookie, status_t status,  
    234235    usbmidi_device_info* midiDevice = (usbmidi_device_info*)cookie;
    235236
    236237    assert(cookie != NULL);
    237     DPRINTF_DEBUG((MY_ID "midi_usb_read_callback() -- packet length %ld\n",
    238         actual_len));
     238    if (actual_len > 0) {
     239        DPRINTF_DEBUG((MY_ID "midi_usb_read_callback() -- packet length %ld\n",
     240            actual_len));
     241    }
    239242
    240243    acquire_sem(midiDevice->sem_lock);
    241244    midiDevice->actual_length = actual_len;
    midi_usb_read_callback(void* cookie, status_t status,  
    271274
    272275    /* issue next request */
    273276    st = usb->queue_bulk(midiDevice->ept_in->handle,
    274         midiDevice->buffer, midiDevice->buffer_size,
     277        midiDevice->buffer, midiDevice->inMaxPkt,
    275278        (usb_callback_func)midi_usb_read_callback, midiDevice);
    276279    if (st != B_OK) {
    277280        /* probably endpoint stall */
    got_one:  
    383386
    384387    for (uint16 i = 0; i < intf->endpoint_count && i < 2; i++) {
    385388        /* we are actually assuming max one IN, one OUT endpoint... */
    386         DPRINTF_INFO((MY_ID "endpoint %d = %p  %s\n",
     389        DPRINTF_INFO((MY_ID "endpoint %d = %p  %s maxPkt=%d\n",
    387390            i, &intf->endpoint[i],
    388391            (intf->endpoint[i].descr->endpoint_address & 0x80) != 0
    389              ? "IN" : "OUT"));
     392             ? "IN" : "OUT", intf->endpoint[i].descr->max_packet_size));
    390393        if ((intf->endpoint[i].descr->endpoint_address & 0x80) != 0) {
    391394            if (midiDevice->ept_in == NULL) {
    392395                midiDevice->ept_in = &intf->endpoint[i];
    393396                in_cables = cable_count[i];
     397                if (intf->endpoint[i].descr->max_packet_size
     398                    < midiDevice->inMaxPkt)
     399                    midiDevice->inMaxPkt = intf->endpoint[i].descr->max_packet_size;
     400            }
     401        } else {
     402            if (midiDevice->ept_out == NULL) {
     403                midiDevice->ept_out = &intf->endpoint[i];
     404                out_cables = cable_count[i];
     405                if (intf->endpoint[i].descr->max_packet_size
     406                    < midiDevice->outMaxPkt)
     407                    midiDevice->outMaxPkt = intf->endpoint[i].descr->max_packet_size;
    394408            }
    395         } else if (midiDevice->ept_out == NULL) {
    396             midiDevice->ept_out = &intf->endpoint[i];
    397             out_cables = cable_count[i];
    398409        }
    399410    }
    400411
    got_one:  
    416427    /* issue bulk transfer */
    417428    DPRINTF_DEBUG((MY_ID "queueing bulk xfer IN endpoint\n"));
    418429    status = usb->queue_bulk(midiDevice->ept_in->handle, midiDevice->buffer,
    419         midiDevice->buffer_size,
     430        midiDevice->inMaxPkt,
    420431        (usb_callback_func)midi_usb_read_callback, midiDevice);
    421432    if (status != B_OK) {
    422433        DPRINTF_ERR((MY_ID "queue_bulk() error 0x%lx\n", status));
    usb_midi_open(const char* name, uint32 flags,  
    498509    if ((port = search_port_info(name)) == NULL)
    499510        return B_ENTRY_NOT_FOUND;
    500511
    501     if (!port->has_in && mode != O_RDONLY)
     512    if (!port->has_in && mode != O_WRONLY)
    502513        return B_PERMISSION_DENIED;  /* == EACCES */
    503     else if (!port->has_out && mode != O_WRONLY)
     514    else if (!port->has_out && mode != O_RDONLY)
    504515        return B_PERMISSION_DENIED;
    505516
    506517    if ((cookie = (driver_cookie*)malloc(sizeof(driver_cookie))) == NULL)
    usb_midi_read(driver_cookie* cookie, off_t position,  
    550561    DPRINTF_DEBUG((MY_ID "usb_midi_read: (%ld byte buffer at %lld cookie %p)"
    551562        "\n", *num_bytes, position, cookie));
    552563    while (midiDevice && midiDevice->active) {
    553         DPRINTF_DEBUG((MY_ID "waiting on acquire_sem_etc\n"));
     564        ZDPRINTF_DEBUG((MY_ID "waiting on acquire_sem_etc\n"));
    554565        err = acquire_sem_etc(cookie->sem_cb, 1,
    555566             B_RELATIVE_TIMEOUT, 1000000);
    556567        if (err == B_TIMED_OUT) {
    557             DPRINTF_DEBUG((MY_ID "acquire_sem_etc timed out\n"));
     568            ZDPRINTF_DEBUG((MY_ID "acquire_sem_etc timed out\n"));
    558569            continue;   /* see if we're still active */
    559570        }
    560571        if (err != B_OK) {
    usb_midi_write(driver_cookie* cookie, off_t position,  
    616627    if (!midiDevice || !midiDevice->active)
    617628        return B_ERROR;     /* already unplugged */
    618629
    619     buff_lim = midiDevice->buffer_size * 3 / 4;
     630    buff_lim = midiDevice->outMaxPkt * 3 / 4;
    620631        /* max MIDI bytes buffer space */
    621632
    622633    DPRINTF_DEBUG((MY_ID "MIDI write (%ld bytes at %lld)\n",
  • src/add-ons/kernel/drivers/midi/usb_midi/usb_midi.h

    diff --git a/src/add-ons/kernel/drivers/midi/usb_midi/usb_midi.h b/src/add-ons/kernel/drivers/midi/usb_midi/usb_midi.h
    index f3e91e3..929eb62 100644
    a b  
    22 * midi usb driver
    33 * usb_midi.h
    44 *
    5  * Copyright 2006-2011 Haiku Inc.  All rights reserved.
     5 * Copyright 2006-2012 Haiku Inc.  All rights reserved.
    66 * Distributed under the terms of the MIT Licence.
    77 *
    88 * Authors:
     
    5151    #define DPRINTF_DEBUG(x)
    5252#endif
    5353
     54/* a convenient way of suppressing some printouts: */
     55#define ZDPRINTF_DEBUG(x)
     56
    5457
    5558/* driver specific definitions */
    5659
    typedef struct usbmidi_device_info  
    8285    area_id buffer_area;
    8386    usb_midi_event_packet* buffer;  /* input buffer & base of area */
    8487    usb_midi_event_packet* out_buffer;  /* above input buffer */
    85     size_t buffer_size;     /* for each of in and out buffers */
     88    size_t inMaxPkt, outMaxPkt;     /* for each of in and out buffers */
    8689
    8790    const usb_device* dev;
    8891    uint16 ifno;