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