Lines Matching refs:pdev

21 static void cdnsp_free_stream_info(struct cdnsp_device *pdev,
29 static struct cdnsp_segment *cdnsp_segment_alloc(struct cdnsp_device *pdev, in cdnsp_segment_alloc() argument
42 seg->trbs = dma_pool_zalloc(pdev->segment_pool, flags, &dma); in cdnsp_segment_alloc()
65 dma_pool_free(pdev->segment_pool, seg->trbs, dma); in cdnsp_segment_alloc()
71 static void cdnsp_segment_free(struct cdnsp_device *pdev, in cdnsp_segment_free() argument
75 dma_pool_free(pdev->segment_pool, seg->trbs, seg->dma); in cdnsp_segment_free()
81 static void cdnsp_free_segments_for_ring(struct cdnsp_device *pdev, in cdnsp_free_segments_for_ring() argument
91 cdnsp_segment_free(pdev, seg); in cdnsp_free_segments_for_ring()
95 cdnsp_segment_free(pdev, first); in cdnsp_free_segments_for_ring()
105 static void cdnsp_link_segments(struct cdnsp_device *pdev, in cdnsp_link_segments() argument
136 static void cdnsp_link_rings(struct cdnsp_device *pdev, in cdnsp_link_rings() argument
148 cdnsp_link_segments(pdev, ring->enq_seg, first, ring->type); in cdnsp_link_rings()
149 cdnsp_link_segments(pdev, last, next, ring->type); in cdnsp_link_rings()
280 static void cdnsp_ring_free(struct cdnsp_device *pdev, struct cdnsp_ring *ring) in cdnsp_ring_free() argument
291 cdnsp_free_segments_for_ring(pdev, ring->first_seg); in cdnsp_ring_free()
322 static int cdnsp_alloc_segments_for_ring(struct cdnsp_device *pdev, in cdnsp_alloc_segments_for_ring() argument
334 prev = cdnsp_segment_alloc(pdev, cycle_state, max_packet, flags); in cdnsp_alloc_segments_for_ring()
345 next = cdnsp_segment_alloc(pdev, cycle_state, in cdnsp_alloc_segments_for_ring()
348 cdnsp_free_segments_for_ring(pdev, *first); in cdnsp_alloc_segments_for_ring()
352 cdnsp_link_segments(pdev, prev, next, type); in cdnsp_alloc_segments_for_ring()
358 cdnsp_link_segments(pdev, prev, *first, type); in cdnsp_alloc_segments_for_ring()
370 static struct cdnsp_ring *cdnsp_ring_alloc(struct cdnsp_device *pdev, in cdnsp_ring_alloc() argument
391 ret = cdnsp_alloc_segments_for_ring(pdev, &ring->first_seg, in cdnsp_ring_alloc()
410 void cdnsp_free_endpoint_rings(struct cdnsp_device *pdev, struct cdnsp_ep *pep) in cdnsp_free_endpoint_rings() argument
412 cdnsp_ring_free(pdev, pep->ring); in cdnsp_free_endpoint_rings()
414 cdnsp_free_stream_info(pdev, pep); in cdnsp_free_endpoint_rings()
421 int cdnsp_ring_expansion(struct cdnsp_device *pdev, in cdnsp_ring_expansion() argument
438 ret = cdnsp_alloc_segments_for_ring(pdev, &first, &last, num_segs, in cdnsp_ring_expansion()
450 cdnsp_free_segments_for_ring(pdev, first); in cdnsp_ring_expansion()
455 cdnsp_link_rings(pdev, ring, first, last, num_segs); in cdnsp_ring_expansion()
461 static int cdnsp_init_device_ctx(struct cdnsp_device *pdev) in cdnsp_init_device_ctx() argument
463 int size = HCC_64BYTE_CONTEXT(pdev->hcc_params) ? 2048 : 1024; in cdnsp_init_device_ctx()
465 pdev->out_ctx.type = CDNSP_CTX_TYPE_DEVICE; in cdnsp_init_device_ctx()
466 pdev->out_ctx.size = size; in cdnsp_init_device_ctx()
467 pdev->out_ctx.ctx_size = CTX_SIZE(pdev->hcc_params); in cdnsp_init_device_ctx()
468 pdev->out_ctx.bytes = dma_pool_zalloc(pdev->device_pool, GFP_ATOMIC, in cdnsp_init_device_ctx()
469 &pdev->out_ctx.dma); in cdnsp_init_device_ctx()
471 if (!pdev->out_ctx.bytes) in cdnsp_init_device_ctx()
474 pdev->in_ctx.type = CDNSP_CTX_TYPE_INPUT; in cdnsp_init_device_ctx()
475 pdev->in_ctx.ctx_size = pdev->out_ctx.ctx_size; in cdnsp_init_device_ctx()
476 pdev->in_ctx.size = size + pdev->out_ctx.ctx_size; in cdnsp_init_device_ctx()
477 pdev->in_ctx.bytes = dma_pool_zalloc(pdev->device_pool, GFP_ATOMIC, in cdnsp_init_device_ctx()
478 &pdev->in_ctx.dma); in cdnsp_init_device_ctx()
480 if (!pdev->in_ctx.bytes) { in cdnsp_init_device_ctx()
481 dma_pool_free(pdev->device_pool, pdev->out_ctx.bytes, in cdnsp_init_device_ctx()
482 pdev->out_ctx.dma); in cdnsp_init_device_ctx()
517 static void cdnsp_free_stream_ctx(struct cdnsp_device *pdev, in cdnsp_free_stream_ctx() argument
520 dma_pool_free(pdev->device_pool, pep->stream_info.stream_ctx_array, in cdnsp_free_stream_ctx()
526 *cdnsp_alloc_stream_ctx(struct cdnsp_device *pdev, struct cdnsp_ep *pep) in cdnsp_alloc_stream_ctx() argument
539 return dma_pool_zalloc(pdev->device_pool, GFP_DMA32 | GFP_ATOMIC, in cdnsp_alloc_stream_ctx()
561 int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, in cdnsp_alloc_stream_info() argument
585 stream_info->stream_ctx_array = cdnsp_alloc_stream_ctx(pdev, pep); in cdnsp_alloc_stream_info()
600 cur_ring = cdnsp_ring_alloc(pdev, 2, TYPE_STREAM, mps, in cdnsp_alloc_stream_info()
630 cdnsp_ring_free(pdev, cur_ring); in cdnsp_alloc_stream_info()
642 static void cdnsp_free_stream_info(struct cdnsp_device *pdev, in cdnsp_free_stream_info() argument
656 cdnsp_ring_free(pdev, cur_ring); in cdnsp_free_stream_info()
662 cdnsp_free_stream_ctx(pdev, pep); in cdnsp_free_stream_info()
669 static void cdnsp_free_priv_device(struct cdnsp_device *pdev) in cdnsp_free_priv_device() argument
671 pdev->dcbaa->dev_context_ptrs[1] = 0; in cdnsp_free_priv_device()
673 cdnsp_free_endpoint_rings(pdev, &pdev->eps[0]); in cdnsp_free_priv_device()
675 if (pdev->in_ctx.bytes) in cdnsp_free_priv_device()
676 dma_pool_free(pdev->device_pool, pdev->in_ctx.bytes, in cdnsp_free_priv_device()
677 pdev->in_ctx.dma); in cdnsp_free_priv_device()
679 if (pdev->out_ctx.bytes) in cdnsp_free_priv_device()
680 dma_pool_free(pdev->device_pool, pdev->out_ctx.bytes, in cdnsp_free_priv_device()
681 pdev->out_ctx.dma); in cdnsp_free_priv_device()
683 pdev->in_ctx.bytes = NULL; in cdnsp_free_priv_device()
684 pdev->out_ctx.bytes = NULL; in cdnsp_free_priv_device()
687 static int cdnsp_alloc_priv_device(struct cdnsp_device *pdev) in cdnsp_alloc_priv_device() argument
691 ret = cdnsp_init_device_ctx(pdev); in cdnsp_alloc_priv_device()
696 pdev->eps[0].ring = cdnsp_ring_alloc(pdev, 2, TYPE_CTRL, 0, GFP_ATOMIC); in cdnsp_alloc_priv_device()
697 if (!pdev->eps[0].ring) in cdnsp_alloc_priv_device()
701 pdev->dcbaa->dev_context_ptrs[1] = cpu_to_le64(pdev->out_ctx.dma); in cdnsp_alloc_priv_device()
702 pdev->cmd.in_ctx = &pdev->in_ctx; in cdnsp_alloc_priv_device()
704 trace_cdnsp_alloc_priv_device(pdev); in cdnsp_alloc_priv_device()
707 dma_pool_free(pdev->device_pool, pdev->out_ctx.bytes, in cdnsp_alloc_priv_device()
708 pdev->out_ctx.dma); in cdnsp_alloc_priv_device()
709 dma_pool_free(pdev->device_pool, pdev->in_ctx.bytes, in cdnsp_alloc_priv_device()
710 pdev->in_ctx.dma); in cdnsp_alloc_priv_device()
715 void cdnsp_copy_ep0_dequeue_into_input_ctx(struct cdnsp_device *pdev) in cdnsp_copy_ep0_dequeue_into_input_ctx() argument
717 struct cdnsp_ep_ctx *ep0_ctx = pdev->eps[0].in_ctx; in cdnsp_copy_ep0_dequeue_into_input_ctx()
718 struct cdnsp_ring *ep_ring = pdev->eps[0].ring; in cdnsp_copy_ep0_dequeue_into_input_ctx()
726 int cdnsp_setup_addressable_priv_dev(struct cdnsp_device *pdev) in cdnsp_setup_addressable_priv_dev() argument
732 ep0_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, 0); in cdnsp_setup_addressable_priv_dev()
733 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_setup_addressable_priv_dev()
738 switch (pdev->gadget.speed) { in cdnsp_setup_addressable_priv_dev()
760 port = DEV_PORT(pdev->active_port->port_num); in cdnsp_setup_addressable_priv_dev()
762 slot_ctx->dev_state = cpu_to_le32((pdev->device_address & in cdnsp_setup_addressable_priv_dev()
769 ep0_ctx->deq = cpu_to_le64(pdev->eps[0].ring->first_seg->dma | in cdnsp_setup_addressable_priv_dev()
770 pdev->eps[0].ring->cycle_state); in cdnsp_setup_addressable_priv_dev()
772 trace_cdnsp_setup_addressable_priv_device(pdev); in cdnsp_setup_addressable_priv_dev()
941 int cdnsp_endpoint_init(struct cdnsp_device *pdev, in cdnsp_endpoint_init() argument
971 max_esit_payload = cdnsp_get_max_esit_payload(&pdev->gadget, pep); in cdnsp_endpoint_init()
972 interval = cdnsp_get_endpoint_interval(&pdev->gadget, pep); in cdnsp_endpoint_init()
973 mult = cdnsp_get_endpoint_mult(&pdev->gadget, pep); in cdnsp_endpoint_init()
975 max_burst = cdnsp_get_endpoint_max_burst(&pdev->gadget, pep); in cdnsp_endpoint_init()
982 pdev->gadget.speed == USB_SPEED_HIGH) in cdnsp_endpoint_init()
989 pep->ring = cdnsp_ring_alloc(pdev, 2, ring_type, max_packet, mem_flags); in cdnsp_endpoint_init()
1008 pdev->gadget.speed > USB_SPEED_HIGH) { in cdnsp_endpoint_init()
1009 ret = cdnsp_alloc_streams(pdev, pep); in cdnsp_endpoint_init()
1017 void cdnsp_endpoint_zero(struct cdnsp_device *pdev, struct cdnsp_ep *pep) in cdnsp_endpoint_zero() argument
1025 static int cdnsp_alloc_erst(struct cdnsp_device *pdev, in cdnsp_alloc_erst() argument
1035 erst->entries = dma_alloc_coherent(pdev->dev, size, in cdnsp_alloc_erst()
1054 static void cdnsp_free_erst(struct cdnsp_device *pdev, struct cdnsp_erst *erst) in cdnsp_free_erst() argument
1057 struct device *dev = pdev->dev; in cdnsp_free_erst()
1066 void cdnsp_mem_cleanup(struct cdnsp_device *pdev) in cdnsp_mem_cleanup() argument
1068 struct device *dev = pdev->dev; in cdnsp_mem_cleanup()
1070 cdnsp_free_priv_device(pdev); in cdnsp_mem_cleanup()
1071 cdnsp_free_erst(pdev, &pdev->erst); in cdnsp_mem_cleanup()
1073 if (pdev->event_ring) in cdnsp_mem_cleanup()
1074 cdnsp_ring_free(pdev, pdev->event_ring); in cdnsp_mem_cleanup()
1076 pdev->event_ring = NULL; in cdnsp_mem_cleanup()
1078 if (pdev->cmd_ring) in cdnsp_mem_cleanup()
1079 cdnsp_ring_free(pdev, pdev->cmd_ring); in cdnsp_mem_cleanup()
1081 pdev->cmd_ring = NULL; in cdnsp_mem_cleanup()
1083 dma_pool_destroy(pdev->segment_pool); in cdnsp_mem_cleanup()
1084 pdev->segment_pool = NULL; in cdnsp_mem_cleanup()
1085 dma_pool_destroy(pdev->device_pool); in cdnsp_mem_cleanup()
1086 pdev->device_pool = NULL; in cdnsp_mem_cleanup()
1088 dma_free_coherent(dev, sizeof(*pdev->dcbaa), in cdnsp_mem_cleanup()
1089 pdev->dcbaa, pdev->dcbaa->dma); in cdnsp_mem_cleanup()
1091 pdev->dcbaa = NULL; in cdnsp_mem_cleanup()
1093 pdev->usb2_port.exist = 0; in cdnsp_mem_cleanup()
1094 pdev->usb3_port.exist = 0; in cdnsp_mem_cleanup()
1095 pdev->usb2_port.port_num = 0; in cdnsp_mem_cleanup()
1096 pdev->usb3_port.port_num = 0; in cdnsp_mem_cleanup()
1097 pdev->active_port = NULL; in cdnsp_mem_cleanup()
1100 static void cdnsp_set_event_deq(struct cdnsp_device *pdev) in cdnsp_set_event_deq() argument
1105 deq = cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg, in cdnsp_set_event_deq()
1106 pdev->event_ring->dequeue); in cdnsp_set_event_deq()
1109 temp = cdnsp_read_64(&pdev->ir_set->erst_dequeue); in cdnsp_set_event_deq()
1119 &pdev->ir_set->erst_dequeue); in cdnsp_set_event_deq()
1122 static void cdnsp_add_in_port(struct cdnsp_device *pdev, in cdnsp_add_in_port() argument
1147 static int cdnsp_setup_port_arrays(struct cdnsp_device *pdev) in cdnsp_setup_port_arrays() argument
1153 base = &pdev->cap_regs->hc_capbase; in cdnsp_setup_port_arrays()
1156 pdev->port20_regs = base + offset; in cdnsp_setup_port_arrays()
1159 pdev->port3x_regs = base + offset; in cdnsp_setup_port_arrays()
1162 base = &pdev->cap_regs->hc_capbase; in cdnsp_setup_port_arrays()
1173 !pdev->usb3_port.port_num) in cdnsp_setup_port_arrays()
1174 cdnsp_add_in_port(pdev, &pdev->usb3_port, in cdnsp_setup_port_arrays()
1178 !pdev->usb2_port.port_num) in cdnsp_setup_port_arrays()
1179 cdnsp_add_in_port(pdev, &pdev->usb2_port, in cdnsp_setup_port_arrays()
1183 if (!pdev->usb2_port.exist || !pdev->usb3_port.exist) { in cdnsp_setup_port_arrays()
1184 dev_err(pdev->dev, "Error: Only one port detected\n"); in cdnsp_setup_port_arrays()
1190 pdev->usb2_port.regs = (struct cdnsp_port_regs __iomem *) in cdnsp_setup_port_arrays()
1191 (&pdev->op_regs->port_reg_base + NUM_PORT_REGS * in cdnsp_setup_port_arrays()
1192 (pdev->usb2_port.port_num - 1)); in cdnsp_setup_port_arrays()
1194 pdev->usb3_port.regs = (struct cdnsp_port_regs __iomem *) in cdnsp_setup_port_arrays()
1195 (&pdev->op_regs->port_reg_base + NUM_PORT_REGS * in cdnsp_setup_port_arrays()
1196 (pdev->usb3_port.port_num - 1)); in cdnsp_setup_port_arrays()
1208 int cdnsp_mem_init(struct cdnsp_device *pdev) in cdnsp_mem_init() argument
1210 struct device *dev = pdev->dev; in cdnsp_mem_init()
1223 val = readl(&pdev->op_regs->config_reg); in cdnsp_mem_init()
1225 writel(val, &pdev->op_regs->config_reg); in cdnsp_mem_init()
1231 pdev->dcbaa = dma_alloc_coherent(dev, sizeof(*pdev->dcbaa), in cdnsp_mem_init()
1233 if (!pdev->dcbaa) in cdnsp_mem_init()
1236 pdev->dcbaa->dma = dma; in cdnsp_mem_init()
1238 cdnsp_write_64(dma, &pdev->op_regs->dcbaa_ptr); in cdnsp_mem_init()
1248 pdev->segment_pool = dma_pool_create("CDNSP ring segments", dev, in cdnsp_mem_init()
1251 if (!pdev->segment_pool) in cdnsp_mem_init()
1254 pdev->device_pool = dma_pool_create("CDNSP input/output contexts", dev, in cdnsp_mem_init()
1256 if (!pdev->device_pool) in cdnsp_mem_init()
1261 pdev->cmd_ring = cdnsp_ring_alloc(pdev, 1, TYPE_COMMAND, 0, GFP_KERNEL); in cdnsp_mem_init()
1262 if (!pdev->cmd_ring) in cdnsp_mem_init()
1266 val_64 = cdnsp_read_64(&pdev->op_regs->cmd_ring); in cdnsp_mem_init()
1268 (pdev->cmd_ring->first_seg->dma & (u64)~CMD_RING_RSVD_BITS) | in cdnsp_mem_init()
1269 pdev->cmd_ring->cycle_state; in cdnsp_mem_init()
1270 cdnsp_write_64(val_64, &pdev->op_regs->cmd_ring); in cdnsp_mem_init()
1272 val = readl(&pdev->cap_regs->db_off); in cdnsp_mem_init()
1274 pdev->dba = (void __iomem *)pdev->cap_regs + val; in cdnsp_mem_init()
1277 pdev->ir_set = &pdev->run_regs->ir_set[0]; in cdnsp_mem_init()
1283 pdev->event_ring = cdnsp_ring_alloc(pdev, ERST_NUM_SEGS, TYPE_EVENT, in cdnsp_mem_init()
1285 if (!pdev->event_ring) in cdnsp_mem_init()
1288 ret = cdnsp_alloc_erst(pdev, pdev->event_ring, &pdev->erst); in cdnsp_mem_init()
1293 val = readl(&pdev->ir_set->erst_size); in cdnsp_mem_init()
1296 writel(val, &pdev->ir_set->erst_size); in cdnsp_mem_init()
1299 val_64 = cdnsp_read_64(&pdev->ir_set->erst_base); in cdnsp_mem_init()
1301 val_64 |= (pdev->erst.erst_dma_addr & (u64)~ERST_PTR_MASK); in cdnsp_mem_init()
1302 cdnsp_write_64(val_64, &pdev->ir_set->erst_base); in cdnsp_mem_init()
1305 cdnsp_set_event_deq(pdev); in cdnsp_mem_init()
1307 ret = cdnsp_setup_port_arrays(pdev); in cdnsp_mem_init()
1311 ret = cdnsp_alloc_priv_device(pdev); in cdnsp_mem_init()
1313 dev_err(pdev->dev, in cdnsp_mem_init()
1321 cdnsp_free_erst(pdev, &pdev->erst); in cdnsp_mem_init()
1323 cdnsp_ring_free(pdev, pdev->event_ring); in cdnsp_mem_init()
1325 cdnsp_ring_free(pdev, pdev->cmd_ring); in cdnsp_mem_init()
1327 dma_pool_destroy(pdev->device_pool); in cdnsp_mem_init()
1329 dma_pool_destroy(pdev->segment_pool); in cdnsp_mem_init()
1331 dma_free_coherent(dev, sizeof(*pdev->dcbaa), pdev->dcbaa, in cdnsp_mem_init()
1332 pdev->dcbaa->dma); in cdnsp_mem_init()
1334 cdnsp_reset(pdev); in cdnsp_mem_init()