Changeset b724494 in mainline for uspace/drv/bus/usb/xhci/endpoint.c
- Timestamp:
- 2017-10-23T21:26:22Z (6 years ago)
- Branches:
- lfn, master, serial
- Children:
- ec700c7
- Parents:
- 327f147
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/endpoint.c
r327f147 rb724494 242 242 }; 243 243 244 static int create_valid_input_ctx(xhci_input_ctx_t **out_ictx)245 {246 xhci_input_ctx_t *ictx = malloc32(sizeof(xhci_input_ctx_t));247 if (!ictx) {248 return ENOMEM;249 }250 251 memset(ictx, 0, sizeof(xhci_input_ctx_t));252 253 // Quoting sec. 4.6.6: A1, D0, D1 are down, A0 is up.254 XHCI_INPUT_CTRL_CTX_ADD_CLEAR(ictx->ctrl_ctx, 1);255 XHCI_INPUT_CTRL_CTX_DROP_CLEAR(ictx->ctrl_ctx, 0);256 XHCI_INPUT_CTRL_CTX_DROP_CLEAR(ictx->ctrl_ctx, 1);257 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 0);258 259 if (out_ictx) {260 *out_ictx = ictx;261 }262 263 return EOK;264 }265 266 244 int xhci_device_add_endpoint(xhci_device_t *dev, xhci_endpoint_t *ep) 267 245 { … … 300 278 } 301 279 302 /* Issue configure endpoint command (sec 4.3.5). */ 303 xhci_input_ctx_t *ictx; 304 if ((err = create_valid_input_ctx(&ictx))) { 280 /* Add endpoint. */ 281 xhci_ep_ctx_t ep_ctx; 282 memset(&ep_ctx, 0, sizeof(xhci_ep_ctx_t)); 283 setup_ep_ctx_helpers[ep->base.transfer_type](ep, &ep_ctx); 284 285 if ((err = hc_add_endpoint(dev->hc, dev->slot_id, xhci_endpoint_index(ep), &ep_ctx))) { 305 286 goto err_ds; 306 287 } 307 288 308 const unsigned ep_idx = xhci_endpoint_index(ep); 309 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */ 310 setup_ep_ctx_helpers[ep->base.transfer_type](ep, &ictx->endpoint_ctx[ep_idx]); 311 312 xhci_cmd_t cmd; 313 xhci_cmd_init(&cmd); 314 315 cmd.slot_id = dev->slot_id; 316 317 if ((err = xhci_send_configure_endpoint_command(dev->hc, &cmd, ictx))) { 318 goto err_ictx; 319 } 320 321 if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) { 322 goto err_ictx; 323 } 324 325 xhci_cmd_fini(&cmd); 326 327 free32(ictx); 328 return EOK; 329 330 err_ictx: 331 free32(ictx); 289 return EOK; 290 332 291 err_ds: 333 292 xhci_endpoint_free_transfer_ds(ep); … … 356 315 } 357 316 358 /* Issue configure endpoint command to drop this endpoint. */ 359 xhci_input_ctx_t *ictx; 360 if ((err = create_valid_input_ctx(&ictx))) { 317 /* Drop the endpoint. */ 318 if ((err = hc_drop_endpoint(dev->hc, dev->slot_id, xhci_endpoint_index(ep)))) { 361 319 goto err; 362 320 } 363 364 const unsigned ep_idx = xhci_endpoint_index(ep);365 XHCI_INPUT_CTRL_CTX_DROP_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */366 367 xhci_cmd_t cmd;368 xhci_cmd_init(&cmd);369 370 cmd.slot_id = dev->slot_id;371 372 if ((err = xhci_send_configure_endpoint_command(dev->hc, &cmd, ictx))) {373 goto err_ictx;374 }375 376 if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {377 goto err_ictx;378 }379 380 xhci_cmd_fini(&cmd);381 321 382 322 /* Tear down TRB ring / PSA. */ … … 387 327 */ 388 328 389 free32(ictx); 390 return EOK; 391 392 err_ictx: 393 free32(ictx); 329 return EOK; 330 394 331 err: 395 332 dev->endpoints[ep_num] = ep; … … 403 340 } 404 341 405 int xhci_device_configure(xhci_device_t *dev, xhci_hc_t *hc)406 {407 int err;408 409 /* Issue configure endpoint command (sec 4.3.5). */410 xhci_input_ctx_t *ictx;411 if ((err = create_valid_input_ctx(&ictx))) {412 goto err;413 }414 415 // TODO: Set slot context and other flags. (probably forgot a lot of 'em)416 417 xhci_cmd_t cmd;418 xhci_cmd_init(&cmd);419 420 cmd.slot_id = dev->slot_id;421 422 if ((err = xhci_send_configure_endpoint_command(hc, &cmd, ictx))) {423 goto err_cmd;424 }425 426 if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {427 goto err_cmd;428 }429 430 xhci_cmd_fini(&cmd);431 432 free32(ictx);433 return EOK;434 435 err_cmd:436 free32(ictx);437 err:438 return err;439 }440 441 342 /** 442 343 * @}
Note: See TracChangeset
for help on using the changeset viewer.