Lines Matching refs:fc

146 fw_noderesolve_nodeid(struct firewire_comm *fc, int dst)
150 FW_GLOCK(fc);
151 STAILQ_FOREACH(fwdev, &fc->devices, link)
154 FW_GUNLOCK(fc);
163 fw_noderesolve_eui64(struct firewire_comm *fc, struct fw_eui64 *eui)
167 FW_GLOCK(fc);
168 STAILQ_FOREACH(fwdev, &fc->devices, link)
171 FW_GUNLOCK(fc);
184 fw_asyreq(struct firewire_comm *fc, int sub, struct fw_xfer *xfer)
202 info = &fc->tcode[tcode];
209 if ((fc->status < FWBUSEXPLORE) &&
219 xferq = fc->atq;
221 xferq = fc->ats;
223 if (xfer->send.pay_len > MAXREC(fc->maxrec)) {
244 device_printf(fc->bdev, "Discard a packet (queued=%d)\n",
251 if (fw_get_tlabel(fc, xfer) < 0)
256 xfer->fc = fc;
269 struct mtx *lock = &xfer->fc->wait_lock;
282 struct mtx *lock = &xfer->fc->wait_lock;
299 struct firewire_comm *fc = xfer->fc;
302 FW_GLOCK(fc);
308 FW_GUNLOCK(fc);
311 xfer->q->start(fc);
332 struct firewire_comm *fc = (struct firewire_comm *)arg;
346 mtx_lock(&fc->tlabel_lock);
347 for (i = 0; i < nitems(fc->tlabels); i++) {
348 while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
355 device_printf(fc->bdev,
361 STAILQ_REMOVE_HEAD(&fc->tlabels[i], tlabel);
365 mtx_unlock(&fc->tlabel_lock);
366 fc->timeout(fc);
376 struct firewire_comm *fc;
379 fc = arg;
387 taskqueue_enqueue(fc->taskqueue, &fc->task_timeout);
391 callout_reset(&fc->timeout_callout, hz / WATCHDOG_HZ,
392 firewire_watchdog, fc);
404 struct firewire_comm *fc;
406 fc = device_get_softc(pa);
407 sc->fc = fc;
408 fc->status = FWBUSNOTREADY;
411 if (fc->nisodma > FWMAXNDMA)
412 fc->nisodma = FWMAXNDMA;
416 fc->crom_src_buf = malloc(sizeof(struct crom_src_buf),
418 if (fc->crom_src_buf == NULL) {
419 device_printf(fc->dev,
423 fc->topology_map = malloc(sizeof(struct fw_topology_map),
425 if (fc->topology_map == NULL) {
426 device_printf(fc->dev, "%s: unable to allocate topology map\n",
428 free(fc->crom_src_buf, M_FW);
431 fc->speed_map = malloc(sizeof(struct fw_speed_map),
433 if (fc->speed_map == NULL) {
434 device_printf(fc->dev, "%s: unable to allocate speed map\n",
436 free(fc->crom_src_buf, M_FW);
437 free(fc->topology_map, M_FW);
441 mtx_init(&fc->wait_lock, "fwwait", NULL, MTX_DEF);
442 mtx_init(&fc->tlabel_lock, "fwtlabel", NULL, MTX_DEF);
443 CALLOUT_INIT(&fc->timeout_callout);
444 CALLOUT_INIT(&fc->bmr_callout);
445 CALLOUT_INIT(&fc->busprobe_callout);
446 TASK_INIT(&fc->task_timeout, 0, firewire_xfer_timeout, fc);
448 callout_reset(&sc->fc->timeout_callout, hz,
449 firewire_watchdog, sc->fc);
452 kproc_create(fw_bus_probe_thread, fc, &fc->probe_thread,
462 FW_GLOCK(fc);
463 fw_busreset(fc, FWBUSNOTREADY);
464 FW_GUNLOCK(fc);
465 fc->ibr(fc);
482 device_set_ivars(child, sc->fc);
495 sc->fc->status = FWBUSNOTREADY;
509 struct firewire_comm *fc;
514 fc = sc->fc;
515 mtx_lock(&fc->wait_lock);
516 fc->status = FWBUSDETACH;
517 wakeup(fc);
518 if (msleep(fc->probe_thread, &fc->wait_lock, PWAIT, "fwthr", hz * 60))
520 mtx_unlock(&fc->wait_lock);
522 if (fc->arq != 0 && fc->arq->maxq > 0)
523 fw_drain_txq(fc);
531 callout_stop(&fc->timeout_callout);
532 callout_stop(&fc->bmr_callout);
533 callout_stop(&fc->busprobe_callout);
536 for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL;
541 free(fc->topology_map, M_FW);
542 free(fc->speed_map, M_FW);
543 free(fc->crom_src_buf, M_FW);
545 mtx_destroy(&fc->tlabel_lock);
546 mtx_destroy(&fc->wait_lock);
567 fw_drain_txq(struct firewire_comm *fc)
575 FW_GLOCK(fc);
576 fw_xferq_drain(fc->atq);
577 fw_xferq_drain(fc->ats);
578 for (i = 0; i < fc->nisodma; i++)
579 fw_xferq_drain(fc->it[i]);
580 FW_GUNLOCK(fc);
582 mtx_lock(&fc->tlabel_lock);
584 while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
589 STAILQ_REMOVE_HEAD(&fc->tlabels[i], tlabel);
592 mtx_unlock(&fc->tlabel_lock);
599 fw_reset_csr(struct firewire_comm *fc)
603 CSRARC(fc, STATE_CLEAR)
605 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
606 CSRARC(fc, NODE_IDS) = 0x3f;
608 CSRARC(fc, TOPO_MAP + 8) = 0;
609 fc->irm = -1;
611 fc->max_node = -1;
614 CSRARC(fc, SPED_MAP + i * 4) = 0;
616 CSRARC(fc, STATE_CLEAR) = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14;
617 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
618 CSRARC(fc, RESET_START) = 0;
619 CSRARC(fc, SPLIT_TIMEOUT_HI) = 0;
620 CSRARC(fc, SPLIT_TIMEOUT_LO) = 800 << 19;
621 CSRARC(fc, CYCLE_TIME) = 0x0;
622 CSRARC(fc, BUS_TIME) = 0x0;
623 CSRARC(fc, BUS_MGR_ID) = 0x3f;
624 CSRARC(fc, BANDWIDTH_AV) = 4915;
625 CSRARC(fc, CHANNELS_AV_HI) = 0xffffffff;
626 CSRARC(fc, CHANNELS_AV_LO) = 0xffffffff;
627 CSRARC(fc, IP_CHANNELS) = (1U << 31);
629 CSRARC(fc, CONF_ROM) = 0x04 << 24;
630 CSRARC(fc, CONF_ROM + 4) = 0x31333934; /* means strings 1394 */
631 CSRARC(fc, CONF_ROM + 8) = 1 << 31 | 1 << 30 | 1 << 29 |
633 CSRARC(fc, CONF_ROM + 0xc) = 0;
636 CSRARC(fc, oPCR) &= ~DV_BROADCAST_ON;
637 CSRARC(fc, iPCR) &= ~DV_BROADCAST_ON;
639 CSRARC(fc, STATE_CLEAR) &= ~(1 << 23 | 1 << 15 | 1 << 14);
640 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
644 fw_init_crom(struct firewire_comm *fc)
648 src = &fc->crom_src_buf->src;
662 src->businfo.max_rec = fc->maxrec;
666 src->businfo.link_spd = fc->speed;
668 src->businfo.eui64.hi = fc->eui.hi;
669 src->businfo.eui64.lo = fc->eui.lo;
673 fc->crom_src = src;
674 fc->crom_root = &fc->crom_src_buf->root;
678 fw_reset_crom(struct firewire_comm *fc)
684 buf = fc->crom_src_buf;
685 src = fc->crom_src;
686 root = fc->crom_root;
706 fw_busreset(struct firewire_comm *fc, uint32_t new_status)
714 FW_GLOCK_ASSERT(fc);
715 if (fc->status == FWBUSMGRELECT)
716 callout_stop(&fc->bmr_callout);
718 fc->status = new_status;
719 fw_reset_csr(fc);
721 if (fc->status == FWBUSNOTREADY)
722 fw_init_crom(fc);
724 fw_reset_crom(fc);
726 if (device_get_children(fc->bdev, &devlistp, &devcnt) == 0) {
736 src = &fc->crom_src_buf->src;
753 src = &fc->crom_src_buf->src;
755 if (bcmp(newrom, fc->config_rom, CROMSIZE) != 0) {
765 bcopy(newrom, fc->config_rom, CROMSIZE);
771 void fw_init(struct firewire_comm *fc)
779 fc->arq->queued = 0;
780 fc->ars->queued = 0;
781 fc->atq->queued = 0;
782 fc->ats->queued = 0;
784 fc->arq->buf = NULL;
785 fc->ars->buf = NULL;
786 fc->atq->buf = NULL;
787 fc->ats->buf = NULL;
789 fc->arq->flag = 0;
790 fc->ars->flag = 0;
791 fc->atq->flag = 0;
792 fc->ats->flag = 0;
794 STAILQ_INIT(&fc->atq->q);
795 STAILQ_INIT(&fc->ats->q);
797 for (i = 0; i < fc->nisodma; i++) {
798 fc->it[i]->queued = 0;
799 fc->ir[i]->queued = 0;
801 fc->it[i]->start = NULL;
802 fc->ir[i]->start = NULL;
804 fc->it[i]->buf = NULL;
805 fc->ir[i]->buf = NULL;
807 fc->it[i]->flag = FWXFERQ_STREAM;
808 fc->ir[i]->flag = FWXFERQ_STREAM;
810 STAILQ_INIT(&fc->it[i]->q);
811 STAILQ_INIT(&fc->ir[i]->q);
814 fc->arq->maxq = FWMAXQUEUE;
815 fc->ars->maxq = FWMAXQUEUE;
816 fc->atq->maxq = FWMAXQUEUE;
817 fc->ats->maxq = FWMAXQUEUE;
819 for (i = 0; i < fc->nisodma; i++) {
820 fc->ir[i]->maxq = FWMAXQUEUE;
821 fc->it[i]->maxq = FWMAXQUEUE;
824 CSRARC(fc, TOPO_MAP) = 0x3f1 << 16;
825 CSRARC(fc, TOPO_MAP + 4) = 1;
826 CSRARC(fc, SPED_MAP) = 0x3f1 << 16;
827 CSRARC(fc, SPED_MAP + 4) = 1;
829 STAILQ_INIT(&fc->devices);
832 STAILQ_INIT(&fc->binds);
834 STAILQ_INIT(&fc->tlabels[i]);
839 CSRARC(fc, oMPR) = 0x3fff0001; /* # output channel = 1 */
840 CSRARC(fc, oPCR) = 0x8000007a;
842 CSRARC(fc, i + oPCR) = 0x8000007a;
845 CSRARC(fc, iMPR) = 0x00ff0001; /* # input channel = 1 */
846 CSRARC(fc, iPCR) = 0x803f0000;
848 CSRARC(fc, i + iPCR) = 0x0;
852 fc->crom_src_buf = NULL;
865 xfer->fc = fc;
872 fw_bindadd(fc, fwb);
883 fw_bindlookup(struct firewire_comm *fc, uint16_t dest_hi, uint32_t dest_lo)
889 FW_GLOCK(fc);
890 STAILQ_FOREACH(tfw, &fc->binds, fclist)
895 FW_GUNLOCK(fc);
903 fw_bindadd(struct firewire_comm *fc, struct fw_bind *fwb)
913 FW_GLOCK(fc);
914 STAILQ_FOREACH(tfw, &fc->binds, fclist) {
920 STAILQ_INSERT_HEAD(&fc->binds, fwb, fclist);
922 STAILQ_INSERT_AFTER(&fc->binds, prev, fwb, fclist);
927 FW_GUNLOCK(fc);
935 fw_bindremove(struct firewire_comm *fc, struct fw_bind *fwb)
944 FW_GLOCK(fc);
945 STAILQ_FOREACH(tfw, &fc->binds, fclist)
947 STAILQ_REMOVE(&fc->binds, fwb, fw_bind, fclist);
952 FW_GUNLOCK(fc);
964 FW_GUNLOCK(fc);
973 struct firewire_comm *fc, void *sc, void (*hand)(struct fw_xfer *))
982 xfer->fc = fc;
1021 fw_tl_free(struct firewire_comm *fc, struct fw_xfer *xfer)
1025 mtx_lock(&fc->tlabel_lock);
1027 mtx_unlock(&fc->tlabel_lock);
1031 STAILQ_FOREACH(txfer, &fc->tlabels[xfer->tl], tlabel)
1041 mtx_unlock(&fc->tlabel_lock);
1045 STAILQ_REMOVE(&fc->tlabels[xfer->tl], xfer, fw_xfer, tlabel);
1047 mtx_unlock(&fc->tlabel_lock);
1055 fw_tl2xfer(struct firewire_comm *fc, int node, int tlabel, int tcode)
1061 mtx_lock(&fc->tlabel_lock);
1062 STAILQ_FOREACH(xfer, &fc->tlabels[tlabel], tlabel)
1064 mtx_unlock(&fc->tlabel_lock);
1070 if (xfer->fc->tcode[req].valid_res != tcode) {
1081 mtx_unlock(&fc->tlabel_lock);
1146 if (xfer->fc == NULL)
1147 panic("fw_xfer_done: why xfer->fc is NULL?");
1149 fw_tl_free(xfer->fc, xfer);
1160 if (xfer->fc != NULL) {
1161 FW_GLOCK(xfer->fc);
1169 FW_GUNLOCK(xfer->fc);
1175 fw_tl_free(xfer->fc, xfer);
1233 fw_phy_config(struct firewire_comm *fc, int root_node, int gap_count)
1238 fc->status = FWBUSPHYCONF;
1243 xfer->fc = fc;
1257 device_printf(fc->bdev, "%s: root_node=%d gap_count=%d\n",
1259 fw_asyreq(fc, -1, xfer);
1298 void fw_sidrcv(struct firewire_comm *fc, uint32_t *sid, u_int len)
1304 fc->sid_cnt = len / (sizeof(uint32_t) * 2);
1305 fc->max_node = fc->nodeid & 0x3f;
1306 CSRARC(fc, NODE_IDS) = ((uint32_t)fc->nodeid) << 16;
1307 fc->status = FWBUSCYMELECT;
1308 fc->topology_map->crc_len = 2;
1309 fc->topology_map->generation++;
1310 fc->topology_map->self_id_count = 0;
1311 fc->topology_map->node_count= 0;
1312 fc->speed_map->generation++;
1313 fc->speed_map->crc_len = 1 + (64 * 64 + 3) / 4;
1314 self_id = &fc->topology_map->self_id[0];
1315 for (i = 0; i < fc->sid_cnt; i++) {
1317 device_printf(fc->bdev,
1323 fc->topology_map->crc_len++;
1325 fc->topology_map->node_count++;
1330 if (fc->max_node < node)
1331 fc->max_node = self_id->p0.phy_id;
1333 fc->speed_map->speed[node][node] =
1336 fc->speed_map->speed[j][node] =
1337 fc->speed_map->speed[node][j] =
1338 min(fc->speed_map->speed[j][j],
1341 if ((fc->irm == -1 || self_id->p0.phy_id > fc->irm) &&
1343 fc->irm = self_id->p0.phy_id;
1355 fc->topology_map->self_id_count++;
1358 fc->topology_map->crc = fw_crc16(
1359 (uint32_t *)&fc->topology_map->generation,
1360 fc->topology_map->crc_len * 4);
1361 fc->speed_map->crc = fw_crc16(
1362 (uint32_t *)&fc->speed_map->generation,
1363 fc->speed_map->crc_len * 4);
1365 p = (uint32_t *)fc->topology_map;
1366 for (i = 0; i <= fc->topology_map->crc_len; i++)
1367 CSRARC(fc, TOPO_MAP + i * 4) = htonl(*p++);
1368 p = (uint32_t *)fc->speed_map;
1369 CSRARC(fc, SPED_MAP) = htonl(*p++);
1370 CSRARC(fc, SPED_MAP + 4) = htonl(*p++);
1372 bcopy(p, &CSRARC(fc, SPED_MAP + 8), (fc->speed_map->crc_len - 1) * 4);
1374 fc->max_hop = fc->max_node - i_branch;
1375 device_printf(fc->bdev, "%d nodes, maxhop <= %d %s irm(%d) %s\n",
1376 fc->max_node + 1, fc->max_hop,
1377 (fc->irm == -1) ? "Not IRM capable" : "cable IRM",
1378 fc->irm, (fc->irm == fc->nodeid) ? " (me) " : "");
1380 if (try_bmr && (fc->irm != -1) && (CSRARC(fc, BUS_MGR_ID) == 0x3f)) {
1381 if (fc->irm == fc->nodeid) {
1382 fc->status = FWBUSMGRDONE;
1383 CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, fc->irm);
1384 fw_bmr(fc);
1386 fc->status = FWBUSMGRELECT;
1387 callout_reset(&fc->bmr_callout, hz / 8,
1388 fw_try_bmr, fc);
1391 fc->status = FWBUSMGRDONE;
1393 callout_reset(&fc->busprobe_callout, hz / 4, fw_bus_probe, fc);
1402 struct firewire_comm *fc;
1407 fc = arg;
1408 fc->status = FWBUSEXPLORE;
1412 device_printf(fc->bdev, "%s:"
1415 STAILQ_FOREACH(fwdev, &fc->devices, link)
1420 device_printf(fc->bdev, "%s:"
1425 device_printf(fc->bdev, "%s:"
1431 wakeup(fc);
1513 struct firewire_comm *fc;
1521 fc = dfwdev->fc;
1534 device_printf(fc->bdev,
1554 device_printf(fc->bdev, "%s: node(%d) BUS INFO BLOCK:\n"
1564 STAILQ_FOREACH(fwdev, &fc->devices, link)
1572 device_printf(fc->bdev, "%s: node%d: no memory\n",
1576 fwdev->fc = fc;
1591 device_printf(fc->bdev, "%s: "
1593 fwdev->speed = fc->speed_map->speed[fc->nodeid][node];
1604 device_printf(fc->bdev,
1615 * fc->devices TAILQ, then we will add it.
1618 STAILQ_FOREACH(tfwdev, &fc->devices, link) {
1626 STAILQ_INSERT_HEAD(&fc->devices, fwdev, link);
1628 STAILQ_INSERT_AFTER(&fc->devices, pfwdev, fwdev, link);
1635 device_printf(fc->dev,
1651 device_printf(fc->dev, "%s: explore csrblock failed err(%d)\n",
1664 fw_find_self_id(struct firewire_comm *fc, int node)
1669 for (i = 0; i < fc->topology_map->self_id_count; i++) {
1670 s = &fc->topology_map->self_id[i];
1680 fw_explore(struct firewire_comm *fc)
1689 dfwdev.fc = fc;
1694 for (node = 0; node <= fc->max_node; node++) {
1696 if (node == fc->nodeid) {
1698 device_printf(fc->bdev, "%s:"
1699 "found myself node(%d) fc->nodeid(%d) fc->max_node(%d)\n",
1700 __func__, node, fc->nodeid, fc->max_node);
1703 device_printf(fc->bdev, "%s:"
1704 "node(%d) fc->max_node(%d) found\n",
1705 __func__, node, fc->max_node);
1707 fwsid = fw_find_self_id(fc, node);
1710 device_printf(fc->bdev,
1727 device_printf(fc->bdev,
1739 struct firewire_comm *fc;
1741 fc = arg;
1743 mtx_lock(&fc->wait_lock);
1744 while (fc->status != FWBUSDETACH) {
1745 if (fc->status == FWBUSEXPLORE) {
1746 mtx_unlock(&fc->wait_lock);
1747 fw_explore(fc);
1748 fc->status = FWBUSEXPDONE;
1751 fw_attach_dev(fc);
1752 mtx_lock(&fc->wait_lock);
1754 msleep((void *)fc, &fc->wait_lock, PWAIT|PCATCH, "-", 0);
1756 mtx_unlock(&fc->wait_lock);
1764 fw_attach_dev(struct firewire_comm *fc)
1772 for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL; fwdev = next) {
1779 device_printf(fc->bdev, "%s:"
1787 STAILQ_REMOVE(&fc->devices, fwdev, fw_device,
1794 err = device_get_children(fc->bdev, &devlistp, &devcnt);
1813 fw_get_tlabel(struct firewire_comm *fc, struct fw_xfer *xfer)
1821 mtx_lock(&fc->tlabel_lock);
1822 new_tlabel = (fc->last_tlabel[dst] + 1) & 0x3f;
1823 STAILQ_FOREACH(txfer, &fc->tlabels[new_tlabel], tlabel)
1827 fc->last_tlabel[dst] = new_tlabel;
1828 STAILQ_INSERT_TAIL(&fc->tlabels[new_tlabel], xfer, tlabel);
1829 mtx_unlock(&fc->tlabel_lock);
1837 mtx_unlock(&fc->tlabel_lock);
1856 tinfo = &rb->fc->tcode[pkt->mode.hdr.tcode];
1884 device_printf(rb->fc->bdev, "%s:"
1929 rb->xfer = fw_tl2xfer(rb->fc, fp->mode.hdr.src,
1932 device_printf(rb->fc->bdev, "%s: unknown response "
1942 rb->xfer = fw_tl2xfer(rb->fc, fp->mode.hdr.src,
1971 device_printf(rb->fc->bdev, "%s: "
1981 bind = fw_bindlookup(rb->fc, fp->mode.rreqq.dest_hi,
1984 device_printf(rb->fc->bdev, "%s: "
1994 if (rb->fc->status == FWBUSINIT) {
1995 device_printf(rb->fc->bdev,
2032 if (fw_asyreq(rb->fc, -1, rb->xfer))
2041 device_printf(rb->fc->bdev, "%s: "
2054 xferq = rb->fc->ir[sub];
2074 sc = device_get_softc(rb->fc->bdev);
2089 device_printf(rb->fc->bdev,"%s: unknown tcode %d\n",
2101 struct firewire_comm *fc;
2106 fc = xfer->fc;
2116 bmr = fc->nodeid;
2118 CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, bmr & 0x3f);
2120 fw_bmr(fc);
2124 device_printf(fc->bdev, "bus manager election failed\n");
2136 struct firewire_comm *fc = arg;
2144 fc->status = FWBUSMGRELECT;
2154 fp->mode.lreq.dst = FWLOCALBUS | fc->irm;
2157 xfer->send.payload[1] = htonl(fc->nodeid);
2160 err = fw_asyreq(fc, -1, xfer);
2246 fw_asyreq(xfer->fc, -1, xfer);
2278 fw_bmr(struct firewire_comm *fc)
2286 self_id = fw_find_self_id(fc, fc->max_node);
2287 if (fc->max_node > 0) {
2290 cmstr = fc->max_node;
2292 device_printf(fc->bdev,
2295 cmstr = fc->nodeid;
2301 device_printf(fc->bdev, "bus manager %d %s\n",
2302 CSRARC(fc, BUS_MGR_ID),
2303 (CSRARC(fc, BUS_MGR_ID) != fc->nodeid) ? "(me)" : "");
2304 if (CSRARC(fc, BUS_MGR_ID) != fc->nodeid) {
2310 if (fc->max_hop <= MAX_GAPHOP)
2311 fw_phy_config(fc, cmstr, gap_cnt[fc->max_hop]);
2313 if (cmstr == fc->nodeid || cmstr == -1)
2317 fwdev.fc = fc;
2331 fw_open_isodma(struct firewire_comm *fc, int tx)
2338 xferqa = &fc->it[0];
2340 xferqa = &fc->ir[0];
2342 FW_GLOCK(fc);
2343 for (i = 0; i < fc->nisodma; i++) {
2350 if (i == fc->nisodma) {
2354 FW_GUNLOCK(fc);