Lines Matching defs:fc

145 fw_noderesolve_nodeid(struct firewire_comm *fc, int dst)
149 FW_GLOCK(fc);
150 STAILQ_FOREACH(fwdev, &fc->devices, link)
153 FW_GUNLOCK(fc);
162 fw_noderesolve_eui64(struct firewire_comm *fc, struct fw_eui64 *eui)
166 FW_GLOCK(fc);
167 STAILQ_FOREACH(fwdev, &fc->devices, link)
170 FW_GUNLOCK(fc);
183 fw_asyreq(struct firewire_comm *fc, int sub, struct fw_xfer *xfer)
201 info = &fc->tcode[tcode];
208 if ((fc->status < FWBUSEXPLORE) &&
218 xferq = fc->atq;
220 xferq = fc->ats;
222 if (xfer->send.pay_len > MAXREC(fc->maxrec)) {
243 device_printf(fc->bdev, "Discard a packet (queued=%d)\n",
250 if (fw_get_tlabel(fc, xfer) < 0)
255 xfer->fc = fc;
268 struct mtx *lock = &xfer->fc->wait_lock;
281 struct mtx *lock = &xfer->fc->wait_lock;
298 struct firewire_comm *fc = xfer->fc;
301 FW_GLOCK(fc);
307 FW_GUNLOCK(fc);
310 xfer->q->start(fc);
331 struct firewire_comm *fc = (struct firewire_comm *)arg;
345 mtx_lock(&fc->tlabel_lock);
346 for (i = 0; i < nitems(fc->tlabels); i++) {
347 while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
354 device_printf(fc->bdev,
360 STAILQ_REMOVE_HEAD(&fc->tlabels[i], tlabel);
364 mtx_unlock(&fc->tlabel_lock);
365 fc->timeout(fc);
375 struct firewire_comm *fc;
378 fc = arg;
386 taskqueue_enqueue(fc->taskqueue, &fc->task_timeout);
390 callout_reset(&fc->timeout_callout, hz / WATCHDOG_HZ,
391 firewire_watchdog, fc);
403 struct firewire_comm *fc;
405 fc = device_get_softc(pa);
406 sc->fc = fc;
407 fc->status = FWBUSNOTREADY;
410 if (fc->nisodma > FWMAXNDMA)
411 fc->nisodma = FWMAXNDMA;
415 fc->crom_src_buf = malloc(sizeof(struct crom_src_buf),
417 if (fc->crom_src_buf == NULL) {
418 device_printf(fc->dev,
422 fc->topology_map = malloc(sizeof(struct fw_topology_map),
424 if (fc->topology_map == NULL) {
425 device_printf(fc->dev, "%s: unable to allocate topology map\n",
427 free(fc->crom_src_buf, M_FW);
430 fc->speed_map = malloc(sizeof(struct fw_speed_map),
432 if (fc->speed_map == NULL) {
433 device_printf(fc->dev, "%s: unable to allocate speed map\n",
435 free(fc->crom_src_buf, M_FW);
436 free(fc->topology_map, M_FW);
440 mtx_init(&fc->wait_lock, "fwwait", NULL, MTX_DEF);
441 mtx_init(&fc->tlabel_lock, "fwtlabel", NULL, MTX_DEF);
442 CALLOUT_INIT(&fc->timeout_callout);
443 CALLOUT_INIT(&fc->bmr_callout);
444 CALLOUT_INIT(&fc->busprobe_callout);
445 TASK_INIT(&fc->task_timeout, 0, firewire_xfer_timeout, fc);
447 callout_reset(&sc->fc->timeout_callout, hz,
448 firewire_watchdog, sc->fc);
451 kproc_create(fw_bus_probe_thread, fc, &fc->probe_thread,
461 FW_GLOCK(fc);
462 fw_busreset(fc, FWBUSNOTREADY);
463 FW_GUNLOCK(fc);
464 fc->ibr(fc);
481 device_set_ivars(child, sc->fc);
494 sc->fc->status = FWBUSNOTREADY;
508 struct firewire_comm *fc;
513 fc = sc->fc;
514 mtx_lock(&fc->wait_lock);
515 fc->status = FWBUSDETACH;
516 wakeup(fc);
517 if (msleep(fc->probe_thread, &fc->wait_lock, PWAIT, "fwthr", hz * 60))
519 mtx_unlock(&fc->wait_lock);
521 if (fc->arq != 0 && fc->arq->maxq > 0)
522 fw_drain_txq(fc);
530 callout_stop(&fc->timeout_callout);
531 callout_stop(&fc->bmr_callout);
532 callout_stop(&fc->busprobe_callout);
535 for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL;
540 free(fc->topology_map, M_FW);
541 free(fc->speed_map, M_FW);
542 free(fc->crom_src_buf, M_FW);
544 mtx_destroy(&fc->tlabel_lock);
545 mtx_destroy(&fc->wait_lock);
566 fw_drain_txq(struct firewire_comm *fc)
574 FW_GLOCK(fc);
575 fw_xferq_drain(fc->atq);
576 fw_xferq_drain(fc->ats);
577 for (i = 0; i < fc->nisodma; i++)
578 fw_xferq_drain(fc->it[i]);
579 FW_GUNLOCK(fc);
581 mtx_lock(&fc->tlabel_lock);
583 while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
588 STAILQ_REMOVE_HEAD(&fc->tlabels[i], tlabel);
591 mtx_unlock(&fc->tlabel_lock);
598 fw_reset_csr(struct firewire_comm *fc)
602 CSRARC(fc, STATE_CLEAR)
604 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
605 CSRARC(fc, NODE_IDS) = 0x3f;
607 CSRARC(fc, TOPO_MAP + 8) = 0;
608 fc->irm = -1;
610 fc->max_node = -1;
613 CSRARC(fc, SPED_MAP + i * 4) = 0;
615 CSRARC(fc, STATE_CLEAR) = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14;
616 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
617 CSRARC(fc, RESET_START) = 0;
618 CSRARC(fc, SPLIT_TIMEOUT_HI) = 0;
619 CSRARC(fc, SPLIT_TIMEOUT_LO) = 800 << 19;
620 CSRARC(fc, CYCLE_TIME) = 0x0;
621 CSRARC(fc, BUS_TIME) = 0x0;
622 CSRARC(fc, BUS_MGR_ID) = 0x3f;
623 CSRARC(fc, BANDWIDTH_AV) = 4915;
624 CSRARC(fc, CHANNELS_AV_HI) = 0xffffffff;
625 CSRARC(fc, CHANNELS_AV_LO) = 0xffffffff;
626 CSRARC(fc, IP_CHANNELS) = (1U << 31);
628 CSRARC(fc, CONF_ROM) = 0x04 << 24;
629 CSRARC(fc, CONF_ROM + 4) = 0x31333934; /* means strings 1394 */
630 CSRARC(fc, CONF_ROM + 8) = 1 << 31 | 1 << 30 | 1 << 29 |
632 CSRARC(fc, CONF_ROM + 0xc) = 0;
635 CSRARC(fc, oPCR) &= ~DV_BROADCAST_ON;
636 CSRARC(fc, iPCR) &= ~DV_BROADCAST_ON;
638 CSRARC(fc, STATE_CLEAR) &= ~(1 << 23 | 1 << 15 | 1 << 14);
639 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
643 fw_init_crom(struct firewire_comm *fc)
647 src = &fc->crom_src_buf->src;
661 src->businfo.max_rec = fc->maxrec;
665 src->businfo.link_spd = fc->speed;
667 src->businfo.eui64.hi = fc->eui.hi;
668 src->businfo.eui64.lo = fc->eui.lo;
672 fc->crom_src = src;
673 fc->crom_root = &fc->crom_src_buf->root;
677 fw_reset_crom(struct firewire_comm *fc)
683 buf = fc->crom_src_buf;
684 src = fc->crom_src;
685 root = fc->crom_root;
705 fw_busreset(struct firewire_comm *fc, uint32_t new_status)
713 FW_GLOCK_ASSERT(fc);
714 if (fc->status == FWBUSMGRELECT)
715 callout_stop(&fc->bmr_callout);
717 fc->status = new_status;
718 fw_reset_csr(fc);
720 if (fc->status == FWBUSNOTREADY)
721 fw_init_crom(fc);
723 fw_reset_crom(fc);
725 if (device_get_children(fc->bdev, &devlistp, &devcnt) == 0) {
735 src = &fc->crom_src_buf->src;
752 src = &fc->crom_src_buf->src;
754 if (bcmp(newrom, fc->config_rom, CROMSIZE) != 0) {
764 bcopy(newrom, fc->config_rom, CROMSIZE);
770 void fw_init(struct firewire_comm *fc)
778 fc->arq->queued = 0;
779 fc->ars->queued = 0;
780 fc->atq->queued = 0;
781 fc->ats->queued = 0;
783 fc->arq->buf = NULL;
784 fc->ars->buf = NULL;
785 fc->atq->buf = NULL;
786 fc->ats->buf = NULL;
788 fc->arq->flag = 0;
789 fc->ars->flag = 0;
790 fc->atq->flag = 0;
791 fc->ats->flag = 0;
793 STAILQ_INIT(&fc->atq->q);
794 STAILQ_INIT(&fc->ats->q);
796 for (i = 0; i < fc->nisodma; i++) {
797 fc->it[i]->queued = 0;
798 fc->ir[i]->queued = 0;
800 fc->it[i]->start = NULL;
801 fc->ir[i]->start = NULL;
803 fc->it[i]->buf = NULL;
804 fc->ir[i]->buf = NULL;
806 fc->it[i]->flag = FWXFERQ_STREAM;
807 fc->ir[i]->flag = FWXFERQ_STREAM;
809 STAILQ_INIT(&fc->it[i]->q);
810 STAILQ_INIT(&fc->ir[i]->q);
813 fc->arq->maxq = FWMAXQUEUE;
814 fc->ars->maxq = FWMAXQUEUE;
815 fc->atq->maxq = FWMAXQUEUE;
816 fc->ats->maxq = FWMAXQUEUE;
818 for (i = 0; i < fc->nisodma; i++) {
819 fc->ir[i]->maxq = FWMAXQUEUE;
820 fc->it[i]->maxq = FWMAXQUEUE;
823 CSRARC(fc, TOPO_MAP) = 0x3f1 << 16;
824 CSRARC(fc, TOPO_MAP + 4) = 1;
825 CSRARC(fc, SPED_MAP) = 0x3f1 << 16;
826 CSRARC(fc, SPED_MAP + 4) = 1;
828 STAILQ_INIT(&fc->devices);
831 STAILQ_INIT(&fc->binds);
833 STAILQ_INIT(&fc->tlabels[i]);
838 CSRARC(fc, oMPR) = 0x3fff0001; /* # output channel = 1 */
839 CSRARC(fc, oPCR) = 0x8000007a;
841 CSRARC(fc, i + oPCR) = 0x8000007a;
844 CSRARC(fc, iMPR) = 0x00ff0001; /* # input channel = 1 */
845 CSRARC(fc, iPCR) = 0x803f0000;
847 CSRARC(fc, i + iPCR) = 0x0;
851 fc->crom_src_buf = NULL;
864 xfer->fc = fc;
871 fw_bindadd(fc, fwb);
882 fw_bindlookup(struct firewire_comm *fc, uint16_t dest_hi, uint32_t dest_lo)
888 FW_GLOCK(fc);
889 STAILQ_FOREACH(tfw, &fc->binds, fclist)
894 FW_GUNLOCK(fc);
902 fw_bindadd(struct firewire_comm *fc, struct fw_bind *fwb)
912 FW_GLOCK(fc);
913 STAILQ_FOREACH(tfw, &fc->binds, fclist) {
919 STAILQ_INSERT_HEAD(&fc->binds, fwb, fclist);
921 STAILQ_INSERT_AFTER(&fc->binds, prev, fwb, fclist);
926 FW_GUNLOCK(fc);
934 fw_bindremove(struct firewire_comm *fc, struct fw_bind *fwb)
943 FW_GLOCK(fc);
944 STAILQ_FOREACH(tfw, &fc->binds, fclist)
946 STAILQ_REMOVE(&fc->binds, fwb, fw_bind, fclist);
951 FW_GUNLOCK(fc);
963 FW_GUNLOCK(fc);
972 struct firewire_comm *fc, void *sc, void (*hand)(struct fw_xfer *))
981 xfer->fc = fc;
1020 fw_tl_free(struct firewire_comm *fc, struct fw_xfer *xfer)
1024 mtx_lock(&fc->tlabel_lock);
1026 mtx_unlock(&fc->tlabel_lock);
1030 STAILQ_FOREACH(txfer, &fc->tlabels[xfer->tl], tlabel)
1040 mtx_unlock(&fc->tlabel_lock);
1044 STAILQ_REMOVE(&fc->tlabels[xfer->tl], xfer, fw_xfer, tlabel);
1046 mtx_unlock(&fc->tlabel_lock);
1054 fw_tl2xfer(struct firewire_comm *fc, int node, int tlabel, int tcode)
1060 mtx_lock(&fc->tlabel_lock);
1061 STAILQ_FOREACH(xfer, &fc->tlabels[tlabel], tlabel)
1063 mtx_unlock(&fc->tlabel_lock);
1069 if (xfer->fc->tcode[req].valid_res != tcode) {
1080 mtx_unlock(&fc->tlabel_lock);
1145 if (xfer->fc == NULL)
1146 panic("fw_xfer_done: why xfer->fc is NULL?");
1148 fw_tl_free(xfer->fc, xfer);
1159 if (xfer->fc != NULL) {
1160 FW_GLOCK(xfer->fc);
1168 FW_GUNLOCK(xfer->fc);
1174 fw_tl_free(xfer->fc, xfer);
1232 fw_phy_config(struct firewire_comm *fc, int root_node, int gap_count)
1237 fc->status = FWBUSPHYCONF;
1242 xfer->fc = fc;
1256 device_printf(fc->bdev, "%s: root_node=%d gap_count=%d\n",
1258 fw_asyreq(fc, -1, xfer);
1297 void fw_sidrcv(struct firewire_comm *fc, uint32_t *sid, u_int len)
1303 fc->sid_cnt = len / (sizeof(uint32_t) * 2);
1304 fc->max_node = fc->nodeid & 0x3f;
1305 CSRARC(fc, NODE_IDS) = ((uint32_t)fc->nodeid) << 16;
1306 fc->status = FWBUSCYMELECT;
1307 fc->topology_map->crc_len = 2;
1308 fc->topology_map->generation++;
1309 fc->topology_map->self_id_count = 0;
1310 fc->topology_map->node_count= 0;
1311 fc->speed_map->generation++;
1312 fc->speed_map->crc_len = 1 + (64 * 64 + 3) / 4;
1313 self_id = &fc->topology_map->self_id[0];
1314 for (i = 0; i < fc->sid_cnt; i++) {
1316 device_printf(fc->bdev,
1322 fc->topology_map->crc_len++;
1324 fc->topology_map->node_count++;
1329 if (fc->max_node < node)
1330 fc->max_node = self_id->p0.phy_id;
1332 fc->speed_map->speed[node][node] =
1335 fc->speed_map->speed[j][node] =
1336 fc->speed_map->speed[node][j] =
1337 min(fc->speed_map->speed[j][j],
1340 if ((fc->irm == -1 || self_id->p0.phy_id > fc->irm) &&
1342 fc->irm = self_id->p0.phy_id;
1354 fc->topology_map->self_id_count++;
1357 fc->topology_map->crc = fw_crc16(
1358 (uint32_t *)&fc->topology_map->generation,
1359 fc->topology_map->crc_len * 4);
1360 fc->speed_map->crc = fw_crc16(
1361 (uint32_t *)&fc->speed_map->generation,
1362 fc->speed_map->crc_len * 4);
1364 p = (uint32_t *)fc->topology_map;
1365 for (i = 0; i <= fc->topology_map->crc_len; i++)
1366 CSRARC(fc, TOPO_MAP + i * 4) = htonl(*p++);
1367 p = (uint32_t *)fc->speed_map;
1368 CSRARC(fc, SPED_MAP) = htonl(*p++);
1369 CSRARC(fc, SPED_MAP + 4) = htonl(*p++);
1371 bcopy(p, &CSRARC(fc, SPED_MAP + 8), (fc->speed_map->crc_len - 1) * 4);
1373 fc->max_hop = fc->max_node - i_branch;
1374 device_printf(fc->bdev, "%d nodes, maxhop <= %d %s irm(%d) %s\n",
1375 fc->max_node + 1, fc->max_hop,
1376 (fc->irm == -1) ? "Not IRM capable" : "cable IRM",
1377 fc->irm, (fc->irm == fc->nodeid) ? " (me) " : "");
1379 if (try_bmr && (fc->irm != -1) && (CSRARC(fc, BUS_MGR_ID) == 0x3f)) {
1380 if (fc->irm == fc->nodeid) {
1381 fc->status = FWBUSMGRDONE;
1382 CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, fc->irm);
1383 fw_bmr(fc);
1385 fc->status = FWBUSMGRELECT;
1386 callout_reset(&fc->bmr_callout, hz / 8,
1387 fw_try_bmr, fc);
1390 fc->status = FWBUSMGRDONE;
1392 callout_reset(&fc->busprobe_callout, hz / 4, fw_bus_probe, fc);
1401 struct firewire_comm *fc;
1406 fc = arg;
1407 fc->status = FWBUSEXPLORE;
1411 device_printf(fc->bdev, "%s:"
1414 STAILQ_FOREACH(fwdev, &fc->devices, link)
1419 device_printf(fc->bdev, "%s:"
1424 device_printf(fc->bdev, "%s:"
1430 wakeup(fc);
1512 struct firewire_comm *fc;
1520 fc = dfwdev->fc;
1533 device_printf(fc->bdev,
1553 device_printf(fc->bdev, "%s: node(%d) BUS INFO BLOCK:\n"
1563 STAILQ_FOREACH(fwdev, &fc->devices, link)
1571 device_printf(fc->bdev, "%s: node%d: no memory\n",
1575 fwdev->fc = fc;
1590 device_printf(fc->bdev, "%s: "
1592 fwdev->speed = fc->speed_map->speed[fc->nodeid][node];
1603 device_printf(fc->bdev,
1614 * fc->devices TAILQ, then we will add it.
1617 STAILQ_FOREACH(tfwdev, &fc->devices, link) {
1625 STAILQ_INSERT_HEAD(&fc->devices, fwdev, link);
1627 STAILQ_INSERT_AFTER(&fc->devices, pfwdev, fwdev, link);
1634 device_printf(fc->dev,
1650 device_printf(fc->dev, "%s: explore csrblock failed err(%d)\n",
1663 fw_find_self_id(struct firewire_comm *fc, int node)
1668 for (i = 0; i < fc->topology_map->self_id_count; i++) {
1669 s = &fc->topology_map->self_id[i];
1679 fw_explore(struct firewire_comm *fc)
1688 dfwdev.fc = fc;
1693 for (node = 0; node <= fc->max_node; node++) {
1695 if (node == fc->nodeid) {
1697 device_printf(fc->bdev, "%s:"
1698 "found myself node(%d) fc->nodeid(%d) fc->max_node(%d)\n",
1699 __func__, node, fc->nodeid, fc->max_node);
1702 device_printf(fc->bdev, "%s:"
1703 "node(%d) fc->max_node(%d) found\n",
1704 __func__, node, fc->max_node);
1706 fwsid = fw_find_self_id(fc, node);
1709 device_printf(fc->bdev,
1726 device_printf(fc->bdev,
1738 struct firewire_comm *fc;
1740 fc = arg;
1742 mtx_lock(&fc->wait_lock);
1743 while (fc->status != FWBUSDETACH) {
1744 if (fc->status == FWBUSEXPLORE) {
1745 mtx_unlock(&fc->wait_lock);
1746 fw_explore(fc);
1747 fc->status = FWBUSEXPDONE;
1750 fw_attach_dev(fc);
1751 mtx_lock(&fc->wait_lock);
1753 msleep((void *)fc, &fc->wait_lock, PWAIT|PCATCH, "-", 0);
1755 mtx_unlock(&fc->wait_lock);
1763 fw_attach_dev(struct firewire_comm *fc)
1771 for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL; fwdev = next) {
1778 device_printf(fc->bdev, "%s:"
1786 STAILQ_REMOVE(&fc->devices, fwdev, fw_device,
1793 err = device_get_children(fc->bdev, &devlistp, &devcnt);
1812 fw_get_tlabel(struct firewire_comm *fc, struct fw_xfer *xfer)
1820 mtx_lock(&fc->tlabel_lock);
1821 new_tlabel = (fc->last_tlabel[dst] + 1) & 0x3f;
1822 STAILQ_FOREACH(txfer, &fc->tlabels[new_tlabel], tlabel)
1826 fc->last_tlabel[dst] = new_tlabel;
1827 STAILQ_INSERT_TAIL(&fc->tlabels[new_tlabel], xfer, tlabel);
1828 mtx_unlock(&fc->tlabel_lock);
1836 mtx_unlock(&fc->tlabel_lock);
1855 tinfo = &rb->fc->tcode[pkt->mode.hdr.tcode];
1883 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))
2043 device_printf(rb->fc->bdev, "%s: "
2056 xferq = rb->fc->ir[sub];
2076 sc = device_get_softc(rb->fc->bdev);
2091 device_printf(rb->fc->bdev,"%s: unknown tcode %d\n",
2103 struct firewire_comm *fc;
2108 fc = xfer->fc;
2118 bmr = fc->nodeid;
2120 CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, bmr & 0x3f);
2122 fw_bmr(fc);
2126 device_printf(fc->bdev, "bus manager election failed\n");
2138 struct firewire_comm *fc = arg;
2146 fc->status = FWBUSMGRELECT;
2156 fp->mode.lreq.dst = FWLOCALBUS | fc->irm;
2159 xfer->send.payload[1] = htonl(fc->nodeid);
2162 err = fw_asyreq(fc, -1, xfer);
2248 fw_asyreq(xfer->fc, -1, xfer);
2280 fw_bmr(struct firewire_comm *fc)
2288 self_id = fw_find_self_id(fc, fc->max_node);
2289 if (fc->max_node > 0) {
2292 cmstr = fc->max_node;
2294 device_printf(fc->bdev,
2297 cmstr = fc->nodeid;
2303 device_printf(fc->bdev, "bus manager %d %s\n",
2304 CSRARC(fc, BUS_MGR_ID),
2305 (CSRARC(fc, BUS_MGR_ID) != fc->nodeid) ? "(me)" : "");
2306 if (CSRARC(fc, BUS_MGR_ID) != fc->nodeid) {
2312 if (fc->max_hop <= MAX_GAPHOP)
2313 fw_phy_config(fc, cmstr, gap_cnt[fc->max_hop]);
2315 if (cmstr == fc->nodeid || cmstr == -1)
2319 fwdev.fc = fc;
2333 fw_open_isodma(struct firewire_comm *fc, int tx)
2340 xferqa = &fc->it[0];
2342 xferqa = &fc->ir[0];
2344 FW_GLOCK(fc);
2345 for (i = 0; i < fc->nisodma; i++) {
2352 if (i == fc->nisodma) {
2356 FW_GUNLOCK(fc);