Changes in uspace/drv/bus/usb/usbmast/main.c [fbcdeb8:5f6e25e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmast/main.c
rfbcdeb8 r5f6e25e 55 55 #define GET_BULK_OUT(dev) ((dev)->pipes[BULK_OUT_EP].pipe) 56 56 57 static constusb_endpoint_description_t bulk_in_ep = {57 static usb_endpoint_description_t bulk_in_ep = { 58 58 .transfer_type = USB_TRANSFER_BULK, 59 59 .direction = USB_DIRECTION_IN, … … 63 63 .flags = 0 64 64 }; 65 static constusb_endpoint_description_t bulk_out_ep = {65 static usb_endpoint_description_t bulk_out_ep = { 66 66 .transfer_type = USB_TRANSFER_BULK, 67 67 .direction = USB_DIRECTION_OUT, … … 72 72 }; 73 73 74 static constusb_endpoint_description_t *mast_endpoints[] = {74 usb_endpoint_description_t *mast_endpoints[] = { 75 75 &bulk_in_ep, 76 76 &bulk_out_ep, … … 82 82 void *arg); 83 83 84 /** Callback when a device is removed from the system.85 * 86 * @param dev Representation of USB device.84 /** Callback when new device is attached and recognized as a mass storage. 85 * 86 * @param dev Representation of a the USB device. 87 87 * @return Error code. 88 88 */ 89 static 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 */ 113 static int usbmast_device_remove(usb_device_t *dev) 114 { 115 //TODO: flush buffers, or whatever. 116 //TODO: remove device 117 return ENOTSUP; 118 } 119 120 /** Callback when new device is attached and recognized as a mass storage. 121 * 122 * @param dev Representation of USB device. 123 * @return Error code. 124 */ 125 static int usbmast_device_add(usb_device_t *dev) 89 static int usbmast_add_device(usb_device_t *dev) 126 90 { 127 91 int rc; … … 130 94 131 95 /* Allocate softstate */ 132 mdev = usb_device_data_alloc(dev, sizeof(usbmast_dev_t));96 mdev = calloc(1, sizeof(usbmast_dev_t)); 133 97 if (mdev == NULL) { 134 98 usb_log_error("Failed allocating softstate.\n"); 135 return ENOMEM; 99 rc = ENOMEM; 100 goto error; 136 101 } 137 102 … … 139 104 mdev->usb_dev = dev; 140 105 141 usb_log_info("Initializing mass storage `%s'.\n", dev->ddf_dev->name); 142 usb_log_debug("Bulk in endpoint: %d [%zuB].\n", 143 dev->pipes[BULK_IN_EP].pipe.endpoint_no, 144 dev->pipes[BULK_IN_EP].pipe.max_packet_size); 106 usb_log_info("Initializing mass storage `%s'.\n", 107 dev->ddf_dev->name); 108 usb_log_debug(" Bulk in endpoint: %d [%zuB].\n", 109 dev->pipes[BULK_IN_EP].pipe->endpoint_no, 110 (size_t) dev->pipes[BULK_IN_EP].descriptor->max_packet_size); 145 111 usb_log_debug("Bulk out endpoint: %d [%zuB].\n", 146 dev->pipes[BULK_OUT_EP].pipe .endpoint_no,147 dev->pipes[BULK_OUT_EP].pipe.max_packet_size);112 dev->pipes[BULK_OUT_EP].pipe->endpoint_no, 113 (size_t) dev->pipes[BULK_OUT_EP].descriptor->max_packet_size); 148 114 149 115 usb_log_debug("Get LUN count...\n"); 150 mdev->lun_count = usb_masstor_get_lun_count(mdev); 151 mdev->luns = calloc(mdev->lun_count, sizeof(ddf_fun_t*)); 152 if (mdev->luns == NULL) { 153 rc = ENOMEM; 154 usb_log_error("Failed allocating luns table.\n"); 155 goto error; 156 } 157 158 for (i = 0; i < mdev->lun_count; i++) { 116 mdev->luns = usb_masstor_get_lun_count(mdev); 117 118 for (i = 0; i < mdev->luns; i++) { 159 119 rc = usbmast_fun_create(mdev, i); 160 120 if (rc != EOK) … … 164 124 return EOK; 165 125 error: 166 /* Destroy functions */ 167 for (size_t i = 0; i < mdev->lun_count; ++i) { 168 if (mdev->luns[i] == NULL) 169 continue; 170 const int rc = ddf_fun_unbind(mdev->luns[i]); 171 if (rc != EOK) { 172 usb_log_warning("Failed to unbind LUN function %zu: " 173 "%s.\n", i, str_error(rc)); 174 } 175 ddf_fun_destroy(mdev->luns[i]); 176 } 177 free(mdev->luns); 126 /* XXX Destroy functions */ 127 if (mdev != NULL) 128 free(mdev); 178 129 return rc; 179 130 } … … 207 158 } 208 159 160 free(fun_name); 161 209 162 /* Allocate soft state */ 210 mfun = ddf_ fun_data_alloc(fun, sizeof(usbmast_fun_t));163 mfun = ddf_dev_data_alloc(mdev->ddf_dev, sizeof(usbmast_fun_t)); 211 164 if (mfun == NULL) { 212 165 usb_log_error("Failed allocating softstate.\n"); … … 215 168 } 216 169 217 mfun->ddf_fun = fun;218 170 mfun->mdev = mdev; 219 171 mfun->lun = lun; 220 172 173 fun_name = NULL; 174 221 175 /* Set up a connection handler. */ 222 176 fun->conn_handler = usbmast_bd_connection; 177 fun->driver_data = mfun; 223 178 224 179 usb_log_debug("Inquire...\n"); … … 264 219 goto error; 265 220 } 266 267 free(fun_name);268 mdev->luns[lun] = fun;269 221 270 222 return EOK; … … 300 252 return; 301 253 } 302 303 (void) async_share_out_finalize(callid, &comm_buf);304 if (comm_buf == (void *) -1) {254 255 comm_buf = as_get_mappable_page(comm_size); 256 if (comm_buf == NULL) { 305 257 async_answer_0(callid, EHANGUP); 306 258 return; 307 259 } 308 260 261 (void) async_share_out_finalize(callid, comm_buf); 262 309 263 mfun = (usbmast_fun_t *) ((ddf_fun_t *)arg)->driver_data; 310 264 … … 346 300 347 301 /** USB mass storage driver ops. */ 348 static const usb_driver_ops_t usbmast_driver_ops = { 349 .device_add = usbmast_device_add, 350 .device_rem = usbmast_device_remove, 351 .device_gone = usbmast_device_gone, 302 static usb_driver_ops_t usbmast_driver_ops = { 303 .add_device = usbmast_add_device, 352 304 }; 353 305 354 306 /** USB mass storage driver. */ 355 static constusb_driver_t usbmast_driver = {307 static usb_driver_t usbmast_driver = { 356 308 .name = NAME, 357 309 .ops = &usbmast_driver_ops,
Note:
See TracChangeset
for help on using the changeset viewer.