Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset f974519 in mainline


Ignore:
Timestamp:
2011-08-25T16:14:58Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
0815000
Parents:
09ace19
Message:

ohci: Fix double enqueue issue, refactoring

Location:
uspace/drv/bus/usb/ohci
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/batch.c

    r09ace19 rf974519  
    6161                batch_control_write(batch);
    6262}
    63 
     63/*----------------------------------------------------------------------------*/
    6464void (*batch_setup[4][3])(usb_transfer_batch_t*) =
    6565{
     
    9898        if (!instance)
    9999                return;
    100         free32(instance->device_buffer);
    101100        unsigned i = 0;
    102101        if (instance->tds) {
     
    107106                free(instance->tds);
    108107        }
     108        free32(instance->device_buffer);
    109109        free(instance);
    110110}
     
    122122        } else (void)0
    123123
    124         const ohci_endpoint_t *ohci_ep = ohci_endpoint_get(batch->ep);
    125         assert(ohci_ep);
    126 
    127124        ohci_transfer_batch_t *data = calloc(sizeof(ohci_transfer_batch_t), 1);
    128125        CHECK_NULL_DISPOSE_RETURN(data, "Failed to allocate batch data.\n");
     
    135132        }
    136133
    137         /* We need an extra place for TD that is assigned to ohci_ep */
     134        /* We need an extra place for TD that was left at ED */
    138135        data->tds = calloc(sizeof(td_t*), data->td_count + 1);
    139136        CHECK_NULL_DISPOSE_RETURN(data->tds,
     
    141138
    142139        /* Add TD left over by the previous transfer */
    143         data->tds[0] = ohci_ep->td;
     140        data->ed = ohci_endpoint_get(batch->ep)->ed;
     141        data->tds[0] = ohci_endpoint_get(batch->ep)->td;
    144142        data->leave_td = 0;
    145143        unsigned i = 1;
     
    150148        }
    151149
    152         data->ed = ohci_ep->ed;
    153         batch->private_data = data;
    154         batch->private_data_dtor = ohci_batch_dispose;
    155150
    156151        /* NOTE: OHCI is capable of handling buffer that crosses page boundaries
     
    163158                CHECK_NULL_DISPOSE_RETURN(data->device_buffer,
    164159                    "Failed to allocate device accessible buffer.\n");
     160                /* Copy setup data */
    165161                memcpy(data->device_buffer, batch->setup_buffer,
    166162                    batch->setup_size);
    167163                batch->data_buffer = data->device_buffer + batch->setup_size;
    168164        }
     165
     166        batch->private_data = data;
     167        batch->private_data_dtor = ohci_batch_dispose;
    169168
    170169        assert(batch_setup[batch->ep->transfer_type][batch->ep->direction]);
     
    221220        ohci_endpoint_t *ohci_ep = ohci_endpoint_get(instance->ep);
    222221        assert(ohci_ep);
    223         ohci_ep->td = data->tds[i];
     222        ohci_ep->td = data->tds[data->leave_td];
    224223        assert(i > 0);
    225224        for (--i;i < data->td_count; ++i)
     
    363362                instance->setup_size, toggle);
    364363        td_set_next(data->tds[0], data->tds[1]);
    365         usb_log_debug("Created SETUP TD: %x:%x:%x:%x.\n", data->tds[0]->status,
    366             data->tds[0]->cbp, data->tds[0]->next, data->tds[0]->be);
     364        usb_log_debug("Created CONTROL SETUP TD: %x:%x:%x:%x.\n",
     365            data->tds[0]->status, data->tds[0]->cbp, data->tds[0]->next,
     366            data->tds[0]->be);
    367367
    368368        /* data stage */
     
    378378                    transfer_size, toggle);
    379379                td_set_next(data->tds[td_current], data->tds[td_current + 1]);
    380                 usb_log_debug("Created DATA TD: %x:%x:%x:%x.\n",
     380                usb_log_debug("Created CONTROL DATA TD: %x:%x:%x:%x.\n",
    381381                    data->tds[td_current]->status, data->tds[td_current]->cbp,
    382382                    data->tds[td_current]->next, data->tds[td_current]->be);
     
    392392        td_init(data->tds[td_current], status_dir, NULL, 0, 1);
    393393        td_set_next(data->tds[td_current], data->tds[td_current + 1]);
    394         usb_log_debug("Created STATUS TD: %x:%x:%x:%x.\n",
     394        usb_log_debug("Created CONTROL STATUS TD: %x:%x:%x:%x.\n",
    395395            data->tds[td_current]->status, data->tds[td_current]->cbp,
    396396            data->tds[td_current]->next, data->tds[td_current]->be);
  • uspace/drv/bus/usb/ohci/hc.c

    r09ace19 rf974519  
    139139            &instance->generic.dev_manager, hub_address, hub_fun->handle);
    140140
    141 #define CHECK_RET_RELEASE(ret, message...) \
     141#define CHECK_RET_DESTROY(ret, message...) \
    142142if (ret != EOK) { \
    143143        usb_log_error(message); \
     144        endpoint_destroy(ep); \
     145        usb_endpoint_manager_unregister_ep(&instance->generic.ep_manager, \
     146            hub_address, 0, USB_DIRECTION_BOTH); \
    144147        return ret; \
    145148} else (void)0
     
    151154
    152155        int ret = ohci_endpoint_init(&instance->generic, ep);
    153         if (ret != EOK) {
    154                 endpoint_destroy(ep);
    155                 return ret;
    156         }
    157 
    158         ret = usb_endpoint_manager_register_ep(&instance->generic.ep_manager, ep, 0);
    159         if (ret != EOK) {
    160                 endpoint_destroy(ep);
    161                 return ret;
    162         }
    163         hc_enqueue_endpoint(instance, ep);
    164 
    165 
    166 //      int ret = hc_add_endpoint(instance, hub_address, 0, USB_SPEED_FULL,
    167 //          USB_TRANSFER_CONTROL, USB_DIRECTION_BOTH, 64, 0, 0);
    168 //      CHECK_RET_RELEASE(ret,
    169 //          "Failed to add OHCI root hub endpoint 0: %s.\n", str_error(ret));
     156        CHECK_RET_DESTROY(ret, "Failed to initialize rh OHCI ep structures.\n");
     157
     158        ret = usb_endpoint_manager_register_ep(
     159            &instance->generic.ep_manager, ep, 0);
     160        CHECK_RET_DESTROY(ret, "Failed to initialize rh control ep.\n");
     161        ep = NULL;
    170162
    171163        ret = ddf_fun_add_match_id(hub_fun, "usb&class=hub", 100);
    172         CHECK_RET_RELEASE(ret,
     164        CHECK_RET_DESTROY(ret,
    173165            "Failed to add root hub match-id: %s.\n", str_error(ret));
    174166
    175167        ret = ddf_fun_bind(hub_fun);
    176         CHECK_RET_RELEASE(ret,
     168        CHECK_RET_DESTROY(ret,
    177169            "Failed to bind root hub function: %s.\n", str_error(ret));
    178170
     
    248240        case USB_TRANSFER_BULK:
    249241                instance->registers->control &= ~C_BLE;
    250                 endpoint_list_add_ep(
    251                     &instance->lists[ep->transfer_type], ohci_endpoint_get(ep));
     242                endpoint_list_add_ep(list, ohci_ep);
    252243                instance->registers->control |= C_BLE;
    253244                break;
     
    255246        case USB_TRANSFER_INTERRUPT:
    256247                instance->registers->control &= (~C_PLE & ~C_IE);
    257                 endpoint_list_add_ep(
    258                     &instance->lists[ep->transfer_type], ohci_endpoint_get(ep));
     248                endpoint_list_add_ep(list, ohci_ep);
    259249                instance->registers->control |= C_PLE | C_IE;
    260250                break;
     
    368358
    369359        if (status & I_UE) {
     360                usb_log_fatal("Error like no other!\n");
    370361                hc_start(instance);
    371362        }
Note: See TracChangeset for help on using the changeset viewer.