Changeset 20a3465 in mainline for uspace/drv/bus/usb/usbmast/main.c


Ignore:
Timestamp:
2011-10-30T19:50:54Z (14 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3ce78580, 48902fa
Parents:
4c3ad56 (diff), 45bf63c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmast/main.c

    r4c3ad56 r20a3465  
    5555#define GET_BULK_OUT(dev) ((dev)->pipes[BULK_OUT_EP].pipe)
    5656
    57 static usb_endpoint_description_t bulk_in_ep = {
     57static const usb_endpoint_description_t bulk_in_ep = {
    5858        .transfer_type = USB_TRANSFER_BULK,
    5959        .direction = USB_DIRECTION_IN,
     
    6363        .flags = 0
    6464};
    65 static usb_endpoint_description_t bulk_out_ep = {
     65static const usb_endpoint_description_t bulk_out_ep = {
    6666        .transfer_type = USB_TRANSFER_BULK,
    6767        .direction = USB_DIRECTION_OUT,
     
    7272};
    7373
    74 usb_endpoint_description_t *mast_endpoints[] = {
     74static const usb_endpoint_description_t *mast_endpoints[] = {
    7575        &bulk_in_ep,
    7676        &bulk_out_ep,
     
    8282    void *arg);
    8383
     84/** Callback when a device is removed from the system.
     85 *
     86 * @param dev Representation of USB device.
     87 * @return Error code.
     88 */
     89static int usbmast_device_gone(usb_device_t *dev)
     90{
     91        usbmast_dev_t *mdev = dev->driver_data;
     92        assert(mdev);
     93
     94        for (size_t i = 0; i < mdev->lun_count; ++i) {
     95                const int rc = ddf_fun_unbind(mdev->luns[i]);
     96                if (rc != EOK) {
     97                        usb_log_error("Failed to unbind LUN function %zu: "
     98                            "%s\n", i, str_error(rc));
     99                        return rc;
     100                }
     101                ddf_fun_destroy(mdev->luns[i]);
     102                mdev->luns[i] = NULL;
     103        }
     104        free(mdev->luns);
     105        return EOK;
     106}
     107
     108/** Callback when a device is about to be removed.
     109 *
     110 * @param dev Representation of USB device.
     111 * @return Error code.
     112 */
     113static int usbmast_device_remove(usb_device_t *dev)
     114{
     115        //TODO: flush buffers, or whatever.
     116        return ENOTSUP;
     117}
     118
    84119/** Callback when new device is attached and recognized as a mass storage.
    85120 *
    86  * @param dev Representation of a the USB device.
     121 * @param dev Representation of USB device.
    87122 * @return Error code.
    88123 */
     
    94129
    95130        /* Allocate softstate */
    96         dev->driver_data = mdev = malloc(sizeof(usbmast_dev_t));
     131        mdev = usb_device_data_alloc(dev, sizeof(usbmast_dev_t));
    97132        if (mdev == NULL) {
    98133                usb_log_error("Failed allocating softstate.\n");
     
    112147
    113148        usb_log_debug("Get LUN count...\n");
    114         mdev->luns = usb_masstor_get_lun_count(mdev);
    115 
    116         for (i = 0; i < mdev->luns; i++) {
     149        mdev->lun_count = usb_masstor_get_lun_count(mdev);
     150        mdev->luns = calloc(mdev->lun_count, sizeof(ddf_fun_t*));
     151        if (mdev->luns == NULL) {
     152                rc = ENOMEM;
     153                usb_log_error("Failed allocating luns table.\n");
     154                goto error;
     155        }
     156
     157        for (i = 0; i < mdev->lun_count; i++) {
    117158                rc = usbmast_fun_create(mdev, i);
    118159                if (rc != EOK)
     
    122163        return EOK;
    123164error:
    124         /* XXX Destroy functions */
     165        /* Destroy functions */
     166        for (size_t i = 0; i < mdev->lun_count; ++i) {
     167                if (mdev->luns[i] == NULL)
     168                        continue;
     169                const int rc = ddf_fun_unbind(mdev->luns[i]);
     170                if (rc != EOK) {
     171                        usb_log_warning("Failed to unbind LUN function %zu: "
     172                            "%s.\n", i, str_error(rc));
     173                }
     174                ddf_fun_destroy(mdev->luns[i]);
     175        }
     176        free(mdev->luns);
    125177        return rc;
    126178}
     
    162214        }
    163215
     216        mfun->ddf_fun = fun;
    164217        mfun->mdev = mdev;
    165218        mfun->lun = lun;
     
    212265
    213266        free(fun_name);
     267        mdev->luns[lun] = fun;
    214268
    215269        return EOK;
     
    293347
    294348/** USB mass storage driver ops. */
    295 static usb_driver_ops_t usbmast_driver_ops = {
     349static const usb_driver_ops_t usbmast_driver_ops = {
    296350        .device_add = usbmast_device_add,
     351        .device_rem = usbmast_device_remove,
     352        .device_gone = usbmast_device_gone,
    297353};
    298354
    299355/** USB mass storage driver. */
    300 static usb_driver_t usbmast_driver = {
     356static const usb_driver_t usbmast_driver = {
    301357        .name = NAME,
    302358        .ops = &usbmast_driver_ops,
Note: See TracChangeset for help on using the changeset viewer.