fhci-tds.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Freescale QUICC Engine USB Host Controller Driver
  4. *
  5. * Copyright (c) Freescale Semicondutor, Inc. 2006.
  6. * Shlomi Gridish <gridish@freescale.com>
  7. * Jerry Huang <Chang-Ming.Huang@freescale.com>
  8. * Copyright (c) Logic Product Development, Inc. 2007
  9. * Peter Barada <peterb@logicpd.com>
  10. * Copyright (c) MontaVista Software, Inc. 2008.
  11. * Anton Vorontsov <avorontsov@ru.mvista.com>
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/errno.h>
  16. #include <linux/slab.h>
  17. #include <linux/list.h>
  18. #include <linux/io.h>
  19. #include <linux/usb.h>
  20. #include <linux/usb/hcd.h>
  21. #include "fhci.h"
  22. #define DUMMY_BD_BUFFER 0xdeadbeef
  23. #define DUMMY2_BD_BUFFER 0xbaadf00d
  24. /* Transaction Descriptors bits */
  25. #define TD_R 0x8000 /* ready bit */
  26. #define TD_W 0x2000 /* wrap bit */
  27. #define TD_I 0x1000 /* interrupt on completion */
  28. #define TD_L 0x0800 /* last */
  29. #define TD_TC 0x0400 /* transmit CRC */
  30. #define TD_CNF 0x0200 /* CNF - Must be always 1 */
  31. #define TD_LSP 0x0100 /* Low-speed transaction */
  32. #define TD_PID 0x00c0 /* packet id */
  33. #define TD_RXER 0x0020 /* Rx error or not */
  34. #define TD_NAK 0x0010 /* No ack. */
  35. #define TD_STAL 0x0008 /* Stall received */
  36. #define TD_TO 0x0004 /* time out */
  37. #define TD_UN 0x0002 /* underrun */
  38. #define TD_NO 0x0010 /* Rx Non Octet Aligned Packet */
  39. #define TD_AB 0x0008 /* Frame Aborted */
  40. #define TD_CR 0x0004 /* CRC Error */
  41. #define TD_OV 0x0002 /* Overrun */
  42. #define TD_BOV 0x0001 /* Buffer Overrun */
  43. #define TD_ERRORS (TD_NAK | TD_STAL | TD_TO | TD_UN | \
  44. TD_NO | TD_AB | TD_CR | TD_OV | TD_BOV)
  45. #define TD_PID_DATA0 0x0080 /* Data 0 toggle */
  46. #define TD_PID_DATA1 0x00c0 /* Data 1 toggle */
  47. #define TD_PID_TOGGLE 0x00c0 /* Data 0/1 toggle mask */
  48. #define TD_TOK_SETUP 0x0000
  49. #define TD_TOK_OUT 0x4000
  50. #define TD_TOK_IN 0x8000
  51. #define TD_ISO 0x1000
  52. #define TD_ENDP 0x0780
  53. #define TD_ADDR 0x007f
  54. #define TD_ENDP_SHIFT 7
  55. struct usb_td {
  56. __be16 status;
  57. __be16 length;
  58. __be32 buf_ptr;
  59. __be16 extra;
  60. __be16 reserved;
  61. };
  62. static struct usb_td __iomem *next_bd(struct usb_td __iomem *base,
  63. struct usb_td __iomem *td,
  64. u16 status)
  65. {
  66. if (status & TD_W)
  67. return base;
  68. else
  69. return ++td;
  70. }
  71. void fhci_push_dummy_bd(struct endpoint *ep)
  72. {
  73. if (!ep->already_pushed_dummy_bd) {
  74. u16 td_status = in_be16(&ep->empty_td->status);
  75. out_be32(&ep->empty_td->buf_ptr, DUMMY_BD_BUFFER);
  76. /* get the next TD in the ring */
  77. ep->empty_td = next_bd(ep->td_base, ep->empty_td, td_status);
  78. ep->already_pushed_dummy_bd = true;
  79. }
  80. }
  81. /* destroy an USB endpoint */
  82. void fhci_ep0_free(struct fhci_usb *usb)
  83. {
  84. struct endpoint *ep;
  85. int size;
  86. ep = usb->ep0;
  87. if (ep) {
  88. if (ep->td_base)
  89. cpm_muram_free(cpm_muram_offset(ep->td_base));
  90. if (kfifo_initialized(&ep->conf_frame_Q)) {
  91. size = cq_howmany(&ep->conf_frame_Q);
  92. for (; size; size--) {
  93. struct packet *pkt = cq_get(&ep->conf_frame_Q);
  94. kfree(pkt);
  95. }
  96. cq_delete(&ep->conf_frame_Q);
  97. }
  98. if (kfifo_initialized(&ep->empty_frame_Q)) {
  99. size = cq_howmany(&ep->empty_frame_Q);
  100. for (; size; size--) {
  101. struct packet *pkt = cq_get(&ep->empty_frame_Q);
  102. kfree(pkt);
  103. }
  104. cq_delete(&ep->empty_frame_Q);
  105. }
  106. if (kfifo_initialized(&ep->dummy_packets_Q)) {
  107. size = cq_howmany(&ep->dummy_packets_Q);
  108. for (; size; size--) {
  109. u8 *buff = cq_get(&ep->dummy_packets_Q);
  110. kfree(buff);
  111. }
  112. cq_delete(&ep->dummy_packets_Q);
  113. }
  114. kfree(ep);
  115. usb->ep0 = NULL;
  116. }
  117. }
  118. /*
  119. * create the endpoint structure
  120. *
  121. * arguments:
  122. * usb A pointer to the data structure of the USB
  123. * data_mem The data memory partition(BUS)
  124. * ring_len TD ring length
  125. */
  126. u32 fhci_create_ep(struct fhci_usb *usb, enum fhci_mem_alloc data_mem,
  127. u32 ring_len)
  128. {
  129. struct endpoint *ep;
  130. struct usb_td __iomem *td;
  131. unsigned long ep_offset;
  132. char *err_for = "endpoint PRAM";
  133. int ep_mem_size;
  134. u32 i;
  135. /* we need at least 3 TDs in the ring */
  136. if (!(ring_len > 2)) {
  137. fhci_err(usb->fhci, "illegal TD ring length parameters\n");
  138. return -EINVAL;
  139. }
  140. ep = kzalloc(sizeof(*ep), GFP_KERNEL);
  141. if (!ep)
  142. return -ENOMEM;
  143. ep_mem_size = ring_len * sizeof(*td) + sizeof(struct fhci_ep_pram);
  144. ep_offset = cpm_muram_alloc(ep_mem_size, 32);
  145. if (IS_ERR_VALUE(ep_offset))
  146. goto err;
  147. ep->td_base = cpm_muram_addr(ep_offset);
  148. /* zero all queue pointers */
  149. if (cq_new(&ep->conf_frame_Q, ring_len + 2) ||
  150. cq_new(&ep->empty_frame_Q, ring_len + 2) ||
  151. cq_new(&ep->dummy_packets_Q, ring_len + 2)) {
  152. err_for = "frame_queues";
  153. goto err;
  154. }
  155. for (i = 0; i < (ring_len + 1); i++) {
  156. struct packet *pkt;
  157. u8 *buff;
  158. pkt = kmalloc(sizeof(*pkt), GFP_KERNEL);
  159. if (!pkt) {
  160. err_for = "frame";
  161. goto err;
  162. }
  163. buff = kmalloc_array(1028, sizeof(*buff), GFP_KERNEL);
  164. if (!buff) {
  165. kfree(pkt);
  166. err_for = "buffer";
  167. goto err;
  168. }
  169. cq_put(&ep->empty_frame_Q, pkt);
  170. cq_put(&ep->dummy_packets_Q, buff);
  171. }
  172. /* we put the endpoint parameter RAM right behind the TD ring */
  173. ep->ep_pram_ptr = (void __iomem *)ep->td_base + sizeof(*td) * ring_len;
  174. ep->conf_td = ep->td_base;
  175. ep->empty_td = ep->td_base;
  176. ep->already_pushed_dummy_bd = false;
  177. /* initialize tds */
  178. td = ep->td_base;
  179. for (i = 0; i < ring_len; i++) {
  180. out_be32(&td->buf_ptr, 0);
  181. out_be16(&td->status, 0);
  182. out_be16(&td->length, 0);
  183. out_be16(&td->extra, 0);
  184. td++;
  185. }
  186. td--;
  187. out_be16(&td->status, TD_W); /* for last TD set Wrap bit */
  188. out_be16(&td->length, 0);
  189. /* endpoint structure has been created */
  190. usb->ep0 = ep;
  191. return 0;
  192. err:
  193. fhci_ep0_free(usb);
  194. kfree(ep);
  195. fhci_err(usb->fhci, "no memory for the %s\n", err_for);
  196. return -ENOMEM;
  197. }
  198. /*
  199. * initialize the endpoint register according to the given parameters
  200. *
  201. * artuments:
  202. * usb A pointer to the data strucutre of the USB
  203. * ep A pointer to the endpoint structre
  204. * data_mem The data memory partition(BUS)
  205. */
  206. void fhci_init_ep_registers(struct fhci_usb *usb, struct endpoint *ep,
  207. enum fhci_mem_alloc data_mem)
  208. {
  209. u8 rt;
  210. /* set the endpoint registers according to the endpoint */
  211. out_be16(&usb->fhci->regs->usb_usep[0],
  212. USB_TRANS_CTR | USB_EP_MF | USB_EP_RTE);
  213. out_be16(&usb->fhci->pram->ep_ptr[0],
  214. cpm_muram_offset(ep->ep_pram_ptr));
  215. rt = (BUS_MODE_BO_BE | BUS_MODE_GBL);
  216. #ifdef MULTI_DATA_BUS
  217. if (data_mem == MEM_SECONDARY)
  218. rt |= BUS_MODE_DTB;
  219. #endif
  220. out_8(&ep->ep_pram_ptr->rx_func_code, rt);
  221. out_8(&ep->ep_pram_ptr->tx_func_code, rt);
  222. out_be16(&ep->ep_pram_ptr->rx_buff_len, 1028);
  223. out_be16(&ep->ep_pram_ptr->rx_base, 0);
  224. out_be16(&ep->ep_pram_ptr->tx_base, cpm_muram_offset(ep->td_base));
  225. out_be16(&ep->ep_pram_ptr->rx_bd_ptr, 0);
  226. out_be16(&ep->ep_pram_ptr->tx_bd_ptr, cpm_muram_offset(ep->td_base));
  227. out_be32(&ep->ep_pram_ptr->tx_state, 0);
  228. }
  229. /*
  230. * Collect the submitted frames and inform the application about them
  231. * It is also preparing the TDs for new frames. If the Tx interrupts
  232. * are disabled, the application should call that routine to get
  233. * confirmation about the submitted frames. Otherwise, the routine is
  234. * called from the interrupt service routine during the Tx interrupt.
  235. * In that case the application is informed by calling the application
  236. * specific 'fhci_transaction_confirm' routine
  237. */
  238. static void fhci_td_transaction_confirm(struct fhci_usb *usb)
  239. {
  240. struct endpoint *ep = usb->ep0;
  241. struct packet *pkt;
  242. struct usb_td __iomem *td;
  243. u16 extra_data;
  244. u16 td_status;
  245. u16 td_length;
  246. u32 buf;
  247. /*
  248. * collect transmitted BDs from the chip. The routine clears all BDs
  249. * with R bit = 0 and the pointer to data buffer is not NULL, that is
  250. * BDs which point to the transmitted data buffer
  251. */
  252. while (1) {
  253. td = ep->conf_td;
  254. td_status = in_be16(&td->status);
  255. td_length = in_be16(&td->length);
  256. buf = in_be32(&td->buf_ptr);
  257. extra_data = in_be16(&td->extra);
  258. /* check if the TD is empty */
  259. if (!(!(td_status & TD_R) && ((td_status & ~TD_W) || buf)))
  260. break;
  261. /* check if it is a dummy buffer */
  262. else if ((buf == DUMMY_BD_BUFFER) && !(td_status & ~TD_W))
  263. break;
  264. /* mark TD as empty */
  265. clrbits16(&td->status, ~TD_W);
  266. out_be16(&td->length, 0);
  267. out_be32(&td->buf_ptr, 0);
  268. out_be16(&td->extra, 0);
  269. /* advance the TD pointer */
  270. ep->conf_td = next_bd(ep->td_base, ep->conf_td, td_status);
  271. /* check if it is a dummy buffer(type2) */
  272. if ((buf == DUMMY2_BD_BUFFER) && !(td_status & ~TD_W))
  273. continue;
  274. pkt = cq_get(&ep->conf_frame_Q);
  275. if (!pkt)
  276. fhci_err(usb->fhci, "no frame to confirm\n");
  277. if (td_status & TD_ERRORS) {
  278. if (td_status & TD_RXER) {
  279. if (td_status & TD_CR)
  280. pkt->status = USB_TD_RX_ER_CRC;
  281. else if (td_status & TD_AB)
  282. pkt->status = USB_TD_RX_ER_BITSTUFF;
  283. else if (td_status & TD_OV)
  284. pkt->status = USB_TD_RX_ER_OVERUN;
  285. else if (td_status & TD_BOV)
  286. pkt->status = USB_TD_RX_DATA_OVERUN;
  287. else if (td_status & TD_NO)
  288. pkt->status = USB_TD_RX_ER_NONOCT;
  289. else
  290. fhci_err(usb->fhci, "illegal error "
  291. "occurred\n");
  292. } else if (td_status & TD_NAK)
  293. pkt->status = USB_TD_TX_ER_NAK;
  294. else if (td_status & TD_TO)
  295. pkt->status = USB_TD_TX_ER_TIMEOUT;
  296. else if (td_status & TD_UN)
  297. pkt->status = USB_TD_TX_ER_UNDERUN;
  298. else if (td_status & TD_STAL)
  299. pkt->status = USB_TD_TX_ER_STALL;
  300. else
  301. fhci_err(usb->fhci, "illegal error occurred\n");
  302. } else if ((extra_data & TD_TOK_IN) &&
  303. pkt->len > td_length - CRC_SIZE) {
  304. pkt->status = USB_TD_RX_DATA_UNDERUN;
  305. }
  306. if (extra_data & TD_TOK_IN)
  307. pkt->len = td_length - CRC_SIZE;
  308. else if (pkt->info & PKT_ZLP)
  309. pkt->len = 0;
  310. else
  311. pkt->len = td_length;
  312. fhci_transaction_confirm(usb, pkt);
  313. }
  314. }
  315. /*
  316. * Submitting a data frame to a specified endpoint of a USB device
  317. * The frame is put in the driver's transmit queue for this endpoint
  318. *
  319. * Arguments:
  320. * usb A pointer to the USB structure
  321. * pkt A pointer to the user frame structure
  322. * trans_type Transaction tyep - IN,OUT or SETUP
  323. * dest_addr Device address - 0~127
  324. * dest_ep Endpoint number of the device - 0~16
  325. * trans_mode Pipe type - ISO,Interrupt,bulk or control
  326. * dest_speed USB speed - Low speed or FULL speed
  327. * data_toggle Data sequence toggle - 0 or 1
  328. */
  329. u32 fhci_host_transaction(struct fhci_usb *usb,
  330. struct packet *pkt,
  331. enum fhci_ta_type trans_type,
  332. u8 dest_addr,
  333. u8 dest_ep,
  334. enum fhci_tf_mode trans_mode,
  335. enum fhci_speed dest_speed, u8 data_toggle)
  336. {
  337. struct endpoint *ep = usb->ep0;
  338. struct usb_td __iomem *td;
  339. u16 extra_data;
  340. u16 td_status;
  341. fhci_usb_disable_interrupt(usb);
  342. /* start from the next BD that should be filled */
  343. td = ep->empty_td;
  344. td_status = in_be16(&td->status);
  345. if (td_status & TD_R && in_be16(&td->length)) {
  346. /* if the TD is not free */
  347. fhci_usb_enable_interrupt(usb);
  348. return -1;
  349. }
  350. /* get the next TD in the ring */
  351. ep->empty_td = next_bd(ep->td_base, ep->empty_td, td_status);
  352. fhci_usb_enable_interrupt(usb);
  353. pkt->priv_data = td;
  354. out_be32(&td->buf_ptr, virt_to_phys(pkt->data));
  355. /* sets up transaction parameters - addr,endp,dir,and type */
  356. extra_data = (dest_ep << TD_ENDP_SHIFT) | dest_addr;
  357. switch (trans_type) {
  358. case FHCI_TA_IN:
  359. extra_data |= TD_TOK_IN;
  360. break;
  361. case FHCI_TA_OUT:
  362. extra_data |= TD_TOK_OUT;
  363. break;
  364. case FHCI_TA_SETUP:
  365. extra_data |= TD_TOK_SETUP;
  366. break;
  367. }
  368. if (trans_mode == FHCI_TF_ISO)
  369. extra_data |= TD_ISO;
  370. out_be16(&td->extra, extra_data);
  371. /* sets up the buffer descriptor */
  372. td_status = ((td_status & TD_W) | TD_R | TD_L | TD_I | TD_CNF);
  373. if (!(pkt->info & PKT_NO_CRC))
  374. td_status |= TD_TC;
  375. switch (trans_type) {
  376. case FHCI_TA_IN:
  377. if (data_toggle)
  378. pkt->info |= PKT_PID_DATA1;
  379. else
  380. pkt->info |= PKT_PID_DATA0;
  381. break;
  382. default:
  383. if (data_toggle) {
  384. td_status |= TD_PID_DATA1;
  385. pkt->info |= PKT_PID_DATA1;
  386. } else {
  387. td_status |= TD_PID_DATA0;
  388. pkt->info |= PKT_PID_DATA0;
  389. }
  390. break;
  391. }
  392. if ((dest_speed == FHCI_LOW_SPEED) &&
  393. (usb->port_status == FHCI_PORT_FULL))
  394. td_status |= TD_LSP;
  395. out_be16(&td->status, td_status);
  396. /* set up buffer length */
  397. if (trans_type == FHCI_TA_IN)
  398. out_be16(&td->length, pkt->len + CRC_SIZE);
  399. else
  400. out_be16(&td->length, pkt->len);
  401. /* put the frame to the confirmation queue */
  402. cq_put(&ep->conf_frame_Q, pkt);
  403. if (cq_howmany(&ep->conf_frame_Q) == 1)
  404. out_8(&usb->fhci->regs->usb_uscom, USB_CMD_STR_FIFO);
  405. return 0;
  406. }
  407. /* Reset the Tx BD ring */
  408. void fhci_flush_bds(struct fhci_usb *usb)
  409. {
  410. u16 extra_data;
  411. u16 td_status;
  412. u32 buf;
  413. struct usb_td __iomem *td;
  414. struct endpoint *ep = usb->ep0;
  415. td = ep->td_base;
  416. while (1) {
  417. td_status = in_be16(&td->status);
  418. buf = in_be32(&td->buf_ptr);
  419. extra_data = in_be16(&td->extra);
  420. /* if the TD is not empty - we'll confirm it as Timeout */
  421. if (td_status & TD_R)
  422. out_be16(&td->status, (td_status & ~TD_R) | TD_TO);
  423. /* if this TD is dummy - let's skip this TD */
  424. else if (in_be32(&td->buf_ptr) == DUMMY_BD_BUFFER)
  425. out_be32(&td->buf_ptr, DUMMY2_BD_BUFFER);
  426. /* if this is the last TD - break */
  427. if (td_status & TD_W)
  428. break;
  429. td++;
  430. }
  431. fhci_td_transaction_confirm(usb);
  432. td = ep->td_base;
  433. do {
  434. out_be16(&td->status, 0);
  435. out_be16(&td->length, 0);
  436. out_be32(&td->buf_ptr, 0);
  437. out_be16(&td->extra, 0);
  438. td++;
  439. } while (!(in_be16(&td->status) & TD_W));
  440. out_be16(&td->status, TD_W); /* for last TD set Wrap bit */
  441. out_be16(&td->length, 0);
  442. out_be32(&td->buf_ptr, 0);
  443. out_be16(&td->extra, 0);
  444. out_be16(&ep->ep_pram_ptr->tx_bd_ptr,
  445. in_be16(&ep->ep_pram_ptr->tx_base));
  446. out_be32(&ep->ep_pram_ptr->tx_state, 0);
  447. out_be16(&ep->ep_pram_ptr->tx_cnt, 0);
  448. ep->empty_td = ep->td_base;
  449. ep->conf_td = ep->td_base;
  450. }
  451. /*
  452. * Flush all transmitted packets from TDs in the actual frame.
  453. * This routine is called when something wrong with the controller and
  454. * we want to get rid of the actual frame and start again next frame
  455. */
  456. void fhci_flush_actual_frame(struct fhci_usb *usb)
  457. {
  458. u8 mode;
  459. u16 tb_ptr;
  460. u16 extra_data;
  461. u16 td_status;
  462. u32 buf_ptr;
  463. struct usb_td __iomem *td;
  464. struct endpoint *ep = usb->ep0;
  465. /* disable the USB controller */
  466. mode = in_8(&usb->fhci->regs->usb_usmod);
  467. out_8(&usb->fhci->regs->usb_usmod, mode & ~USB_MODE_EN);
  468. tb_ptr = in_be16(&ep->ep_pram_ptr->tx_bd_ptr);
  469. td = cpm_muram_addr(tb_ptr);
  470. td_status = in_be16(&td->status);
  471. buf_ptr = in_be32(&td->buf_ptr);
  472. extra_data = in_be16(&td->extra);
  473. do {
  474. if (td_status & TD_R) {
  475. out_be16(&td->status, (td_status & ~TD_R) | TD_TO);
  476. } else {
  477. out_be32(&td->buf_ptr, 0);
  478. ep->already_pushed_dummy_bd = false;
  479. break;
  480. }
  481. /* advance the TD pointer */
  482. td = next_bd(ep->td_base, td, td_status);
  483. td_status = in_be16(&td->status);
  484. buf_ptr = in_be32(&td->buf_ptr);
  485. extra_data = in_be16(&td->extra);
  486. } while ((td_status & TD_R) || buf_ptr);
  487. fhci_td_transaction_confirm(usb);
  488. out_be16(&ep->ep_pram_ptr->tx_bd_ptr,
  489. in_be16(&ep->ep_pram_ptr->tx_base));
  490. out_be32(&ep->ep_pram_ptr->tx_state, 0);
  491. out_be16(&ep->ep_pram_ptr->tx_cnt, 0);
  492. ep->empty_td = ep->td_base;
  493. ep->conf_td = ep->td_base;
  494. usb->actual_frame->frame_status = FRAME_TIMER_END_TRANSMISSION;
  495. /* reset the event register */
  496. out_be16(&usb->fhci->regs->usb_usber, 0xffff);
  497. /* enable the USB controller */
  498. out_8(&usb->fhci->regs->usb_usmod, mode | USB_MODE_EN);
  499. }
  500. /* handles Tx confirm and Tx error interrupt */
  501. void fhci_tx_conf_interrupt(struct fhci_usb *usb)
  502. {
  503. fhci_td_transaction_confirm(usb);
  504. /*
  505. * Schedule another transaction to this frame only if we have
  506. * already confirmed all transaction in the frame.
  507. */
  508. if (((fhci_get_sof_timer_count(usb) < usb->max_frame_usage) ||
  509. (usb->actual_frame->frame_status & FRAME_END_TRANSMISSION)) &&
  510. (list_empty(&usb->actual_frame->tds_list)))
  511. fhci_schedule_transactions(usb);
  512. }
  513. void fhci_host_transmit_actual_frame(struct fhci_usb *usb)
  514. {
  515. u16 tb_ptr;
  516. u16 td_status;
  517. struct usb_td __iomem *td;
  518. struct endpoint *ep = usb->ep0;
  519. tb_ptr = in_be16(&ep->ep_pram_ptr->tx_bd_ptr);
  520. td = cpm_muram_addr(tb_ptr);
  521. if (in_be32(&td->buf_ptr) == DUMMY_BD_BUFFER) {
  522. struct usb_td __iomem *old_td = td;
  523. ep->already_pushed_dummy_bd = false;
  524. td_status = in_be16(&td->status);
  525. /* gets the next TD in the ring */
  526. td = next_bd(ep->td_base, td, td_status);
  527. tb_ptr = cpm_muram_offset(td);
  528. out_be16(&ep->ep_pram_ptr->tx_bd_ptr, tb_ptr);
  529. /* start transmit only if we have something in the TDs */
  530. if (in_be16(&td->status) & TD_R)
  531. out_8(&usb->fhci->regs->usb_uscom, USB_CMD_STR_FIFO);
  532. if (in_be32(&ep->conf_td->buf_ptr) == DUMMY_BD_BUFFER) {
  533. out_be32(&old_td->buf_ptr, 0);
  534. ep->conf_td = next_bd(ep->td_base, ep->conf_td,
  535. td_status);
  536. } else {
  537. out_be32(&old_td->buf_ptr, DUMMY2_BD_BUFFER);
  538. }
  539. }
  540. }