Home | History | Annotate | Download | only in pci

Lines Matching defs:ccb

322 	struct twe_ccb *ccb;
408 ccb = malloc(sizeof(*ccb) * TWE_MAX_QUEUECNT, M_DEVBUF, M_WAITOK);
409 sc->sc_ccbs = ccb;
411 for (i = 0; i < TWE_MAX_QUEUECNT; i++, tc++, ccb++) {
412 ccb->ccb_cmd = tc;
413 ccb->ccb_cmdid = i;
414 ccb->ccb_flags = 0;
418 &ccb->ccb_dmamap_xfer);
425 /* Save the first CCB for AEN retrieval. */
427 SLIST_INSERT_HEAD(&sc->sc_ccb_freelist, ccb,
833 * reserve a CCB for it to avoid resource shortage.
844 struct twe_ccb *ccb;
867 ccb = twe_ccb_alloc(sc,
869 KASSERT(ccb != NULL);
871 ccb->ccb_data = tp;
872 ccb->ccb_datasize = TWE_SECTOR_SIZE;
873 ccb->ccb_tx.tx_handler = (aenp == NULL) ? twe_aen_handler : NULL;
874 ccb->ccb_tx.tx_context = tp;
875 ccb->ccb_tx.tx_dv = sc->sc_dev;
877 tc = ccb->ccb_cmd;
889 if ((rv = twe_ccb_map(sc, ccb)) != 0) {
890 twe_ccb_free(sc, ccb);
896 rv = twe_ccb_poll(sc, ccb, 5);
897 twe_ccb_unmap(sc, ccb);
898 twe_ccb_free(sc, ccb);
904 twe_ccb_enqueue(sc, ccb);
917 twe_aen_handler(struct twe_ccb *ccb, int error)
924 sc = device_private(ccb->ccb_tx.tx_dv);
925 tp = ccb->ccb_tx.tx_context;
926 twe_ccb_unmap(sc, ccb);
936 twe_ccb_free(sc, ccb);
1116 * NOTE: We assume we can sleep here to wait for a CCB to become available.
1122 struct twe_ccb *ccb;
1131 ccb = twe_ccb_alloc_wait(sc, TWE_CCB_DATA_IN | TWE_CCB_DATA_OUT);
1132 KASSERT(ccb != NULL);
1134 ccb->ccb_data = tp;
1135 ccb->ccb_datasize = TWE_SECTOR_SIZE;
1136 ccb->ccb_tx.tx_handler = func;
1137 ccb->ccb_tx.tx_context = tp;
1138 ccb->ccb_tx.tx_dv = sc->sc_dev;
1140 tc = ccb->ccb_cmd;
1152 if ((rv = twe_ccb_map(sc, ccb)) != 0) {
1153 twe_ccb_free(sc, ccb);
1160 rv = twe_ccb_poll(sc, ccb, 5);
1161 twe_ccb_unmap(sc, ccb);
1162 twe_ccb_free(sc, ccb);
1169 twe_ccb_enqueue(sc, ccb);
1184 * NOTE: We assume we can sleep here to wait for a CCB to become available.
1190 struct twe_ccb *ccb;
1196 ccb = twe_ccb_alloc_wait(sc, TWE_CCB_DATA_IN | TWE_CCB_DATA_OUT);
1197 ccb->ccb_data = tp;
1198 ccb->ccb_datasize = TWE_SECTOR_SIZE;
1199 ccb->ccb_tx.tx_handler = 0;
1200 ccb->ccb_tx.tx_context = tp;
1201 ccb->ccb_tx.tx_dv = sc->sc_dev;
1203 tc = ccb->ccb_cmd;
1216 if ((rv = twe_ccb_map(sc, ccb)) != 0) {
1217 twe_ccb_free(sc, ccb);
1223 rv = twe_ccb_poll(sc, ccb, 5);
1224 twe_ccb_unmap(sc, ccb);
1225 twe_ccb_free(sc, ccb);
1239 struct twe_ccb *ccb;
1243 if ((ccb = twe_ccb_alloc(sc, 0)) == NULL)
1247 tc = ccb->ccb_cmd;
1255 rv = twe_ccb_poll(sc, ccb, 5);
1256 twe_ccb_free(sc, ccb);
1267 struct twe_ccb *ccb;
1288 ccb = sc->sc_ccbs + cmdid;
1289 if ((ccb->ccb_flags & TWE_CCB_ACTIVE) == 0) {
1290 printf("%s: CCB for cmdid %d not active\n",
1294 ccb->ccb_flags ^= TWE_CCB_COMPLETE | TWE_CCB_ACTIVE;
1297 (char *)ccb->ccb_cmd - (char *)sc->sc_cmds,
1302 if (ccb->ccb_tx.tx_handler != NULL)
1303 (*ccb->ccb_tx.tx_handler)(ccb,
1304 ccb->ccb_cmd->tc_status != 0 ? EIO : 0);
1388 * Allocate and initialise a CCB.
1391 twe_ccb_init(struct twe_softc *sc, struct twe_ccb *ccb, int flags)
1395 ccb->ccb_tx.tx_handler = NULL;
1396 ccb->ccb_flags = flags;
1397 tc = ccb->ccb_cmd;
1400 tc->tc_cmdid = ccb->ccb_cmdid;
1406 struct twe_ccb *ccb;
1411 /* Use the reserved CCB. */
1412 ccb = sc->sc_ccbs;
1414 /* Allocate a CCB and command block. */
1415 if (__predict_false((ccb =
1423 if ((long)(ccb - sc->sc_ccbs) == 0 && (flags & TWE_CCB_AEN) == 0)
1424 panic("twe_ccb_alloc: got reserved CCB for non-AEN");
1425 if ((ccb->ccb_flags & TWE_CCB_ALLOCED) != 0)
1426 panic("twe_ccb_alloc: CCB %ld already allocated",
1427 (long)(ccb - sc->sc_ccbs));
1432 twe_ccb_init(sc, ccb, flags);
1433 return (ccb);
1439 struct twe_ccb *ccb;
1445 while (__predict_false((ccb =
1452 if ((ccb->ccb_flags & TWE_CCB_ALLOCED) != 0)
1453 panic("twe_ccb_alloc_wait: CCB %ld already allocated",
1454 (long)(ccb - sc->sc_ccbs));
1459 twe_ccb_init(sc, ccb, flags);
1460 return (ccb);
1464 * Free a CCB.
1467 twe_ccb_free(struct twe_softc *sc, struct twe_ccb *ccb)
1472 if ((ccb->ccb_flags & TWE_CCB_AEN) == 0) {
1473 SLIST_INSERT_HEAD(&sc->sc_ccb_freelist, ccb, ccb_chain.slist);
1479 ccb->ccb_flags = 0;
1484 * Map the specified CCB's command block and data buffer (if any) into
1488 twe_ccb_map(struct twe_softc *sc, struct twe_ccb *ccb)
1497 if (((u_long)ccb->ccb_data & (TWE_ALIGNMENT - 1)) != 0) {
1501 ccb->ccb_datasize, (VM_NOSLEEP | VM_INSTANTFIT),
1502 (vmem_addr_t *)&ccb->ccb_abuf);
1504 data = (void *)ccb->ccb_abuf;
1505 if ((ccb->ccb_flags & TWE_CCB_DATA_OUT) != 0)
1506 memcpy(data, ccb->ccb_data, ccb->ccb_datasize);
1508 ccb->ccb_abuf = (vaddr_t)0;
1509 data = ccb->ccb_data;
1515 rv = bus_dmamap_load(sc->sc_dmat, ccb->ccb_dmamap_xfer, data,
1516 ccb->ccb_datasize, NULL, BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
1517 ((ccb->ccb_flags & TWE_CCB_DATA_IN) ?
1520 if (ccb->ccb_abuf != (vaddr_t)0) {
1523 uvm_km_kmem_free(kmem_va_arena, ccb->ccb_abuf,
1524 ccb->ccb_datasize);
1530 nsegs = ccb->ccb_dmamap_xfer->dm_nsegs;
1531 tc = ccb->ccb_cmd;
1539 htole32(ccb->ccb_dmamap_xfer->dm_segs[i].ds_addr);
1541 htole32(ccb->ccb_dmamap_xfer->dm_segs[i].ds_len);
1552 htole32(ccb->ccb_dmamap_xfer->dm_segs[i].ds_addr);
1554 htole32(ccb->ccb_dmamap_xfer->dm_segs[i].ds_len);
1571 if ((ccb->ccb_flags & TWE_CCB_DATA_IN) != 0)
1575 if ((ccb->ccb_flags & TWE_CCB_DATA_OUT) != 0)
1578 bus_dmamap_sync(sc->sc_dmat, ccb->ccb_dmamap_xfer, 0,
1579 ccb->ccb_datasize, flags);
1584 * Unmap the specified CCB's command block and data buffer (if any) and
1588 twe_ccb_unmap(struct twe_softc *sc, struct twe_ccb *ccb)
1592 if ((ccb->ccb_flags & TWE_CCB_DATA_IN) != 0)
1596 if ((ccb->ccb_flags & TWE_CCB_DATA_OUT) != 0)
1599 bus_dmamap_sync(sc->sc_dmat, ccb->ccb_dmamap_xfer, 0,
1600 ccb->ccb_datasize, flags);
1601 bus_dmamap_unload(sc->sc_dmat, ccb->ccb_dmamap_xfer);
1603 if (ccb->ccb_abuf != (vaddr_t)0) {
1604 if ((ccb->ccb_flags & TWE_CCB_DATA_IN) != 0)
1605 memcpy(ccb->ccb_data, (void *)ccb->ccb_abuf,
1606 ccb->ccb_datasize);
1609 uvm_km_kmem_free(kmem_va_arena, ccb->ccb_abuf,
1610 ccb->ccb_datasize);
1621 twe_ccb_poll(struct twe_softc *sc, struct twe_ccb *ccb, int timo)
1625 if ((rv = twe_ccb_submit(sc, ccb)) != 0)
1630 if ((ccb->ccb_flags & TWE_CCB_COMPLETE) != 0)
1639 * If a CCB is specified, enqueue it. Pull CCBs off the software queue in
1644 twe_ccb_enqueue(struct twe_softc *sc, struct twe_ccb *ccb)
1650 if (ccb != NULL)
1651 SIMPLEQ_INSERT_TAIL(&sc->sc_ccb_queue, ccb, ccb_chain.simpleq);
1653 while ((ccb = SIMPLEQ_FIRST(&sc->sc_ccb_queue)) != NULL) {
1654 if (twe_ccb_submit(sc, ccb))
1663 * Submit the command block associated with the specified CCB to the
1667 twe_ccb_submit(struct twe_softc *sc, struct twe_ccb *ccb)
1679 (char *)ccb->ccb_cmd - (char *)sc->sc_cmds,
1683 if ((ccb->ccb_flags & TWE_CCB_ALLOCED) == 0)
1684 panic("%s: CCB %ld not ALLOCED\n",
1685 device_xname(sc->sc_dev), (long)(ccb - sc->sc_ccbs));
1687 ccb->ccb_flags |= TWE_CCB_ACTIVE;
1689 ccb->ccb_cmdid * sizeof(struct twe_cmd);
1731 twe_ccb_wait_handler(struct twe_ccb *ccb, int error)
1735 wakeup(ccb);
1745 struct twe_ccb *ccb;
1784 ccb = twe_ccb_alloc_wait(twe,
1786 KASSERT(ccb != NULL);
1787 ccb->ccb_data = pdata;
1788 ccb->ccb_datasize = TWE_SECTOR_SIZE;
1790 ccb = twe_ccb_alloc_wait(twe, 0);
1791 KASSERT(ccb != NULL);
1794 ccb->ccb_tx.tx_handler = twe_ccb_wait_handler;
1795 ccb->ccb_tx.tx_context = NULL;
1796 ccb->ccb_tx.tx_dv = twe->sc_dev;
1798 cmdid = ccb->ccb_cmdid;
1799 memcpy(ccb->ccb_cmd, &tu->tu_cmd, sizeof(struct twe_cmd));
1800 ccb->ccb_cmd->tc_cmdid = cmdid;
1803 if ((error = twe_ccb_map(twe, ccb)) != 0) {
1804 twe_ccb_free(twe, ccb);
1810 twe_ccb_enqueue(twe, ccb);
1812 while ((ccb->ccb_flags & TWE_CCB_COMPLETE) == 0)
1813 if ((error = tsleep(ccb, PRIBIO, "tweioctl",
1819 memcpy(&tu->tu_cmd, ccb->ccb_cmd, sizeof(struct twe_cmd));
1827 twe_ccb_free(twe, ccb);