Lines Matching +full:queue +full:- +full:pkt +full:- +full:tx
1 // SPDX-License-Identifier: GPL-2.0+
7 * Jerry Huang <Chang-Ming.Huang@freescale.com>
33 #define TD_CNF 0x0200 /* CNF - Must be always 1 */
34 #define TD_LSP 0x0100 /* Low-speed transaction */
84 if (!ep->already_pushed_dummy_bd) { in fhci_push_dummy_bd()
85 u16 td_status = in_be16(&ep->empty_td->status); in fhci_push_dummy_bd()
87 out_be32(&ep->empty_td->buf_ptr, DUMMY_BD_BUFFER); in fhci_push_dummy_bd()
89 ep->empty_td = next_bd(ep->td_base, ep->empty_td, td_status); in fhci_push_dummy_bd()
90 ep->already_pushed_dummy_bd = true; in fhci_push_dummy_bd()
100 ep = usb->ep0; in fhci_ep0_free()
102 if (ep->td_base) in fhci_ep0_free()
103 cpm_muram_free(cpm_muram_offset(ep->td_base)); in fhci_ep0_free()
105 if (kfifo_initialized(&ep->conf_frame_Q)) { in fhci_ep0_free()
106 size = cq_howmany(&ep->conf_frame_Q); in fhci_ep0_free()
107 for (; size; size--) { in fhci_ep0_free()
108 struct packet *pkt = cq_get(&ep->conf_frame_Q); in fhci_ep0_free() local
110 kfree(pkt); in fhci_ep0_free()
112 cq_delete(&ep->conf_frame_Q); in fhci_ep0_free()
115 if (kfifo_initialized(&ep->empty_frame_Q)) { in fhci_ep0_free()
116 size = cq_howmany(&ep->empty_frame_Q); in fhci_ep0_free()
117 for (; size; size--) { in fhci_ep0_free()
118 struct packet *pkt = cq_get(&ep->empty_frame_Q); in fhci_ep0_free() local
120 kfree(pkt); in fhci_ep0_free()
122 cq_delete(&ep->empty_frame_Q); in fhci_ep0_free()
125 if (kfifo_initialized(&ep->dummy_packets_Q)) { in fhci_ep0_free()
126 size = cq_howmany(&ep->dummy_packets_Q); in fhci_ep0_free()
127 for (; size; size--) { in fhci_ep0_free()
128 u8 *buff = cq_get(&ep->dummy_packets_Q); in fhci_ep0_free()
132 cq_delete(&ep->dummy_packets_Q); in fhci_ep0_free()
136 usb->ep0 = NULL; in fhci_ep0_free()
160 fhci_err(usb->fhci, "illegal TD ring length parameters\n"); in fhci_create_ep()
161 return -EINVAL; in fhci_create_ep()
166 return -ENOMEM; in fhci_create_ep()
172 ep->td_base = cpm_muram_addr(ep_offset); in fhci_create_ep()
174 /* zero all queue pointers */ in fhci_create_ep()
175 if (cq_new(&ep->conf_frame_Q, ring_len + 2) || in fhci_create_ep()
176 cq_new(&ep->empty_frame_Q, ring_len + 2) || in fhci_create_ep()
177 cq_new(&ep->dummy_packets_Q, ring_len + 2)) { in fhci_create_ep()
183 struct packet *pkt; in fhci_create_ep() local
186 pkt = kmalloc(sizeof(*pkt), GFP_KERNEL); in fhci_create_ep()
187 if (!pkt) { in fhci_create_ep()
194 kfree(pkt); in fhci_create_ep()
198 cq_put(&ep->empty_frame_Q, pkt); in fhci_create_ep()
199 cq_put(&ep->dummy_packets_Q, buff); in fhci_create_ep()
203 ep->ep_pram_ptr = (void __iomem *)ep->td_base + sizeof(*td) * ring_len; in fhci_create_ep()
205 ep->conf_td = ep->td_base; in fhci_create_ep()
206 ep->empty_td = ep->td_base; in fhci_create_ep()
208 ep->already_pushed_dummy_bd = false; in fhci_create_ep()
211 td = ep->td_base; in fhci_create_ep()
213 out_be32(&td->buf_ptr, 0); in fhci_create_ep()
214 out_be16(&td->status, 0); in fhci_create_ep()
215 out_be16(&td->length, 0); in fhci_create_ep()
216 out_be16(&td->extra, 0); in fhci_create_ep()
219 td--; in fhci_create_ep()
220 out_be16(&td->status, TD_W); /* for last TD set Wrap bit */ in fhci_create_ep()
221 out_be16(&td->length, 0); in fhci_create_ep()
224 usb->ep0 = ep; in fhci_create_ep()
230 fhci_err(usb->fhci, "no memory for the %s\n", err_for); in fhci_create_ep()
231 return -ENOMEM; in fhci_create_ep()
248 out_be16(&usb->fhci->regs->usb_usep[0], in fhci_init_ep_registers()
250 out_be16(&usb->fhci->pram->ep_ptr[0], in fhci_init_ep_registers()
251 cpm_muram_offset(ep->ep_pram_ptr)); in fhci_init_ep_registers()
258 out_8(&ep->ep_pram_ptr->rx_func_code, rt); in fhci_init_ep_registers()
259 out_8(&ep->ep_pram_ptr->tx_func_code, rt); in fhci_init_ep_registers()
260 out_be16(&ep->ep_pram_ptr->rx_buff_len, 1028); in fhci_init_ep_registers()
261 out_be16(&ep->ep_pram_ptr->rx_base, 0); in fhci_init_ep_registers()
262 out_be16(&ep->ep_pram_ptr->tx_base, cpm_muram_offset(ep->td_base)); in fhci_init_ep_registers()
263 out_be16(&ep->ep_pram_ptr->rx_bd_ptr, 0); in fhci_init_ep_registers()
264 out_be16(&ep->ep_pram_ptr->tx_bd_ptr, cpm_muram_offset(ep->td_base)); in fhci_init_ep_registers()
265 out_be32(&ep->ep_pram_ptr->tx_state, 0); in fhci_init_ep_registers()
270 * It is also preparing the TDs for new frames. If the Tx interrupts
273 * called from the interrupt service routine during the Tx interrupt.
279 struct endpoint *ep = usb->ep0; in fhci_td_transaction_confirm()
280 struct packet *pkt; in fhci_td_transaction_confirm() local
293 td = ep->conf_td; in fhci_td_transaction_confirm()
294 td_status = in_be16(&td->status); in fhci_td_transaction_confirm()
295 td_length = in_be16(&td->length); in fhci_td_transaction_confirm()
296 buf = in_be32(&td->buf_ptr); in fhci_td_transaction_confirm()
297 extra_data = in_be16(&td->extra); in fhci_td_transaction_confirm()
307 clrbits16(&td->status, ~TD_W); in fhci_td_transaction_confirm()
308 out_be16(&td->length, 0); in fhci_td_transaction_confirm()
309 out_be32(&td->buf_ptr, 0); in fhci_td_transaction_confirm()
310 out_be16(&td->extra, 0); in fhci_td_transaction_confirm()
312 ep->conf_td = next_bd(ep->td_base, ep->conf_td, td_status); in fhci_td_transaction_confirm()
318 pkt = cq_get(&ep->conf_frame_Q); in fhci_td_transaction_confirm()
319 if (!pkt) in fhci_td_transaction_confirm()
320 fhci_err(usb->fhci, "no frame to confirm\n"); in fhci_td_transaction_confirm()
325 pkt->status = USB_TD_RX_ER_CRC; in fhci_td_transaction_confirm()
327 pkt->status = USB_TD_RX_ER_BITSTUFF; in fhci_td_transaction_confirm()
329 pkt->status = USB_TD_RX_ER_OVERUN; in fhci_td_transaction_confirm()
331 pkt->status = USB_TD_RX_DATA_OVERUN; in fhci_td_transaction_confirm()
333 pkt->status = USB_TD_RX_ER_NONOCT; in fhci_td_transaction_confirm()
335 fhci_err(usb->fhci, "illegal error " in fhci_td_transaction_confirm()
338 pkt->status = USB_TD_TX_ER_NAK; in fhci_td_transaction_confirm()
340 pkt->status = USB_TD_TX_ER_TIMEOUT; in fhci_td_transaction_confirm()
342 pkt->status = USB_TD_TX_ER_UNDERUN; in fhci_td_transaction_confirm()
344 pkt->status = USB_TD_TX_ER_STALL; in fhci_td_transaction_confirm()
346 fhci_err(usb->fhci, "illegal error occurred\n"); in fhci_td_transaction_confirm()
348 pkt->len > td_length - CRC_SIZE) { in fhci_td_transaction_confirm()
349 pkt->status = USB_TD_RX_DATA_UNDERUN; in fhci_td_transaction_confirm()
353 pkt->len = td_length - CRC_SIZE; in fhci_td_transaction_confirm()
354 else if (pkt->info & PKT_ZLP) in fhci_td_transaction_confirm()
355 pkt->len = 0; in fhci_td_transaction_confirm()
357 pkt->len = td_length; in fhci_td_transaction_confirm()
359 fhci_transaction_confirm(usb, pkt); in fhci_td_transaction_confirm()
365 * The frame is put in the driver's transmit queue for this endpoint
369 * pkt A pointer to the user frame structure
370 * trans_type Transaction tyep - IN,OUT or SETUP
371 * dest_addr Device address - 0~127
372 * dest_ep Endpoint number of the device - 0~16
373 * trans_mode Pipe type - ISO,Interrupt,bulk or control
374 * dest_speed USB speed - Low speed or FULL speed
375 * data_toggle Data sequence toggle - 0 or 1
378 struct packet *pkt, in fhci_host_transaction() argument
385 struct endpoint *ep = usb->ep0; in fhci_host_transaction()
392 td = ep->empty_td; in fhci_host_transaction()
393 td_status = in_be16(&td->status); in fhci_host_transaction()
395 if (td_status & TD_R && in_be16(&td->length)) { in fhci_host_transaction()
398 return -1; in fhci_host_transaction()
402 ep->empty_td = next_bd(ep->td_base, ep->empty_td, td_status); in fhci_host_transaction()
404 pkt->priv_data = td; in fhci_host_transaction()
405 out_be32(&td->buf_ptr, virt_to_phys(pkt->data)); in fhci_host_transaction()
406 /* sets up transaction parameters - addr,endp,dir,and type */ in fhci_host_transaction()
421 out_be16(&td->extra, extra_data); in fhci_host_transaction()
425 if (!(pkt->info & PKT_NO_CRC)) in fhci_host_transaction()
431 pkt->info |= PKT_PID_DATA1; in fhci_host_transaction()
433 pkt->info |= PKT_PID_DATA0; in fhci_host_transaction()
438 pkt->info |= PKT_PID_DATA1; in fhci_host_transaction()
441 pkt->info |= PKT_PID_DATA0; in fhci_host_transaction()
447 (usb->port_status == FHCI_PORT_FULL)) in fhci_host_transaction()
450 out_be16(&td->status, td_status); in fhci_host_transaction()
454 out_be16(&td->length, pkt->len + CRC_SIZE); in fhci_host_transaction()
456 out_be16(&td->length, pkt->len); in fhci_host_transaction()
458 /* put the frame to the confirmation queue */ in fhci_host_transaction()
459 cq_put(&ep->conf_frame_Q, pkt); in fhci_host_transaction()
461 if (cq_howmany(&ep->conf_frame_Q) == 1) in fhci_host_transaction()
462 out_8(&usb->fhci->regs->usb_uscom, USB_CMD_STR_FIFO); in fhci_host_transaction()
467 /* Reset the Tx BD ring */
472 struct endpoint *ep = usb->ep0; in fhci_flush_bds()
474 td = ep->td_base; in fhci_flush_bds()
476 td_status = in_be16(&td->status); in fhci_flush_bds()
477 in_be32(&td->buf_ptr); in fhci_flush_bds()
478 in_be16(&td->extra); in fhci_flush_bds()
480 /* if the TD is not empty - we'll confirm it as Timeout */ in fhci_flush_bds()
482 out_be16(&td->status, (td_status & ~TD_R) | TD_TO); in fhci_flush_bds()
483 /* if this TD is dummy - let's skip this TD */ in fhci_flush_bds()
484 else if (in_be32(&td->buf_ptr) == DUMMY_BD_BUFFER) in fhci_flush_bds()
485 out_be32(&td->buf_ptr, DUMMY2_BD_BUFFER); in fhci_flush_bds()
486 /* if this is the last TD - break */ in fhci_flush_bds()
495 td = ep->td_base; in fhci_flush_bds()
497 out_be16(&td->status, 0); in fhci_flush_bds()
498 out_be16(&td->length, 0); in fhci_flush_bds()
499 out_be32(&td->buf_ptr, 0); in fhci_flush_bds()
500 out_be16(&td->extra, 0); in fhci_flush_bds()
502 } while (!(in_be16(&td->status) & TD_W)); in fhci_flush_bds()
503 out_be16(&td->status, TD_W); /* for last TD set Wrap bit */ in fhci_flush_bds()
504 out_be16(&td->length, 0); in fhci_flush_bds()
505 out_be32(&td->buf_ptr, 0); in fhci_flush_bds()
506 out_be16(&td->extra, 0); in fhci_flush_bds()
508 out_be16(&ep->ep_pram_ptr->tx_bd_ptr, in fhci_flush_bds()
509 in_be16(&ep->ep_pram_ptr->tx_base)); in fhci_flush_bds()
510 out_be32(&ep->ep_pram_ptr->tx_state, 0); in fhci_flush_bds()
511 out_be16(&ep->ep_pram_ptr->tx_cnt, 0); in fhci_flush_bds()
512 ep->empty_td = ep->td_base; in fhci_flush_bds()
513 ep->conf_td = ep->td_base; in fhci_flush_bds()
528 struct endpoint *ep = usb->ep0; in fhci_flush_actual_frame()
531 mode = in_8(&usb->fhci->regs->usb_usmod); in fhci_flush_actual_frame()
532 out_8(&usb->fhci->regs->usb_usmod, mode & ~USB_MODE_EN); in fhci_flush_actual_frame()
534 tb_ptr = in_be16(&ep->ep_pram_ptr->tx_bd_ptr); in fhci_flush_actual_frame()
536 td_status = in_be16(&td->status); in fhci_flush_actual_frame()
537 buf_ptr = in_be32(&td->buf_ptr); in fhci_flush_actual_frame()
538 in_be16(&td->extra); in fhci_flush_actual_frame()
541 out_be16(&td->status, (td_status & ~TD_R) | TD_TO); in fhci_flush_actual_frame()
543 out_be32(&td->buf_ptr, 0); in fhci_flush_actual_frame()
544 ep->already_pushed_dummy_bd = false; in fhci_flush_actual_frame()
549 td = next_bd(ep->td_base, td, td_status); in fhci_flush_actual_frame()
550 td_status = in_be16(&td->status); in fhci_flush_actual_frame()
551 buf_ptr = in_be32(&td->buf_ptr); in fhci_flush_actual_frame()
552 in_be16(&td->extra); in fhci_flush_actual_frame()
557 out_be16(&ep->ep_pram_ptr->tx_bd_ptr, in fhci_flush_actual_frame()
558 in_be16(&ep->ep_pram_ptr->tx_base)); in fhci_flush_actual_frame()
559 out_be32(&ep->ep_pram_ptr->tx_state, 0); in fhci_flush_actual_frame()
560 out_be16(&ep->ep_pram_ptr->tx_cnt, 0); in fhci_flush_actual_frame()
561 ep->empty_td = ep->td_base; in fhci_flush_actual_frame()
562 ep->conf_td = ep->td_base; in fhci_flush_actual_frame()
564 usb->actual_frame->frame_status = FRAME_TIMER_END_TRANSMISSION; in fhci_flush_actual_frame()
567 out_be16(&usb->fhci->regs->usb_usber, 0xffff); in fhci_flush_actual_frame()
569 out_8(&usb->fhci->regs->usb_usmod, mode | USB_MODE_EN); in fhci_flush_actual_frame()
572 /* handles Tx confirm and Tx error interrupt */
581 if (((fhci_get_sof_timer_count(usb) < usb->max_frame_usage) || in fhci_tx_conf_interrupt()
582 (usb->actual_frame->frame_status & FRAME_END_TRANSMISSION)) && in fhci_tx_conf_interrupt()
583 (list_empty(&usb->actual_frame->tds_list))) in fhci_tx_conf_interrupt()
592 struct endpoint *ep = usb->ep0; in fhci_host_transmit_actual_frame()
594 tb_ptr = in_be16(&ep->ep_pram_ptr->tx_bd_ptr); in fhci_host_transmit_actual_frame()
597 if (in_be32(&td->buf_ptr) == DUMMY_BD_BUFFER) { in fhci_host_transmit_actual_frame()
600 ep->already_pushed_dummy_bd = false; in fhci_host_transmit_actual_frame()
601 td_status = in_be16(&td->status); in fhci_host_transmit_actual_frame()
603 td = next_bd(ep->td_base, td, td_status); in fhci_host_transmit_actual_frame()
605 out_be16(&ep->ep_pram_ptr->tx_bd_ptr, tb_ptr); in fhci_host_transmit_actual_frame()
608 if (in_be16(&td->status) & TD_R) in fhci_host_transmit_actual_frame()
609 out_8(&usb->fhci->regs->usb_uscom, USB_CMD_STR_FIFO); in fhci_host_transmit_actual_frame()
611 if (in_be32(&ep->conf_td->buf_ptr) == DUMMY_BD_BUFFER) { in fhci_host_transmit_actual_frame()
612 out_be32(&old_td->buf_ptr, 0); in fhci_host_transmit_actual_frame()
613 ep->conf_td = next_bd(ep->td_base, ep->conf_td, in fhci_host_transmit_actual_frame()
616 out_be32(&old_td->buf_ptr, DUMMY2_BD_BUFFER); in fhci_host_transmit_actual_frame()