firewire.c (106813) | firewire.c (106815) |
---|---|
1/* 2 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 * | 1/* 2 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 * |
33 * $FreeBSD: head/sys/dev/firewire/firewire.c 106813 2002-11-12 15:22:19Z simokawa $ | 33 * $FreeBSD: head/sys/dev/firewire/firewire.c 106815 2002-11-12 17:16:20Z simokawa $ |
34 * 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/types.h> 40#include <sys/mbuf.h> 41#include <sys/socket.h> --- 355 unchanged lines hidden (view full) --- 397fw_asy_callback(struct fw_xfer *xfer){ 398 wakeup(xfer); 399 return; 400} 401/* 402 * Postpone to later retry. 403 */ 404void fw_asybusy(struct fw_xfer *xfer){ | 34 * 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/types.h> 40#include <sys/mbuf.h> 41#include <sys/socket.h> --- 355 unchanged lines hidden (view full) --- 397fw_asy_callback(struct fw_xfer *xfer){ 398 wakeup(xfer); 399 return; 400} 401/* 402 * Postpone to later retry. 403 */ 404void fw_asybusy(struct fw_xfer *xfer){ |
405#if 0 | 405#if 1 |
406 printf("fw_asybusy\n"); 407#endif 408#if XFER_TIMEOUT 409 untimeout(fw_xfer_timeout, (void *)xfer, xfer->ch); 410#endif 411/* 412 xfer->ch = timeout((timeout_t *)fw_asystart, (void *)xfer, 20000); 413*/ --- 1175 unchanged lines hidden (view full) --- 1589 fc->ongoeui.hi = 0xffffffff; fc->ongoeui.lo = 0xffffffff; 1590 while((csrd = SLIST_FIRST(&fc->ongocsr)) != NULL){ 1591 SLIST_REMOVE_HEAD(&fc->ongocsr, link); 1592 SLIST_INSERT_HEAD(&fc->csrfree, csrd, link); 1593 } 1594 fw_bus_explore(fc); 1595 return; 1596} | 406 printf("fw_asybusy\n"); 407#endif 408#if XFER_TIMEOUT 409 untimeout(fw_xfer_timeout, (void *)xfer, xfer->ch); 410#endif 411/* 412 xfer->ch = timeout((timeout_t *)fw_asystart, (void *)xfer, 20000); 413*/ --- 1175 unchanged lines hidden (view full) --- 1589 fc->ongoeui.hi = 0xffffffff; fc->ongoeui.lo = 0xffffffff; 1590 while((csrd = SLIST_FIRST(&fc->ongocsr)) != NULL){ 1591 SLIST_REMOVE_HEAD(&fc->ongocsr, link); 1592 SLIST_INSERT_HEAD(&fc->csrfree, csrd, link); 1593 } 1594 fw_bus_explore(fc); 1595 return; 1596} |
1597#if 0 1598/* 1599 * Async. write responce support for kernel internal use. 1600 */ 1601int 1602fw_writeres(struct firewire_comm *fc, u_int32_t dst, u_int32_t tlrt) 1603{ 1604 int err = 0; 1605 struct fw_xfer *xfer; 1606 struct fw_pkt *fp; | |
1607 | 1597 |
1608 xfer = fw_xfer_alloc(); 1609 if(xfer == NULL){ 1610 err = ENOMEM; 1611 return err; 1612 } 1613 xfer->send.len = 12; 1614 xfer->spd = 0; 1615 xfer->send.buf = malloc(xfer->send.len, M_DEVBUF, M_NOWAIT); 1616 if(xfer->send.buf == NULL){ 1617 return ENOMEM; 1618 } 1619 xfer->send.off = 0; 1620 fp = (struct fw_pkt *)xfer->send.buf; 1621 1622 fp->mode.wres.tlrt = tlrt; 1623 fp->mode.wres.tcode = FWTCODE_WRES; 1624 fp->mode.wres.pri = 0; 1625 fp->mode.wres.dst = htons(dst); 1626 1627 xfer->act.hand = fw_asy_callback; 1628 err = fw_asyreq(fc, -1, xfer); 1629 if(err){ 1630 fw_xfer_free( xfer); 1631 return err; 1632 } 1633 err = tsleep((caddr_t)xfer, FWPRI, "asyreq", 0); 1634 fw_xfer_free( xfer); 1635 1636 return err; 1637} 1638 | |
1639/* | 1598/* |
1640 * Async. read responce block support for kernel internal use. 1641 */ 1642int 1643fw_readresb(struct firewire_comm *fc, u_int32_t dst, u_int32_t tlrt, 1644 u_int32_t len, u_int32_t *buf) 1645{ 1646 int err = 0; 1647 struct fw_xfer *xfer ; 1648 struct fw_pkt *fp; 1649 1650 xfer = fw_xfer_alloc(); 1651 if(xfer == NULL){ 1652 err = ENOMEM; 1653 return err; 1654 } 1655 xfer->send.len = sizeof(struct fw_pkt) + len; 1656 xfer->spd = 0; 1657 xfer->send.buf = malloc(sizeof(struct fw_pkt) + 1024, M_DEVBUF, M_DONTWAIT); 1658 if(xfer->send.buf == NULL){ 1659 return ENOMEM; 1660 } 1661 xfer->send.off = 0; 1662 fp = (struct fw_pkt *)xfer->send.buf; 1663 fp->mode.rresb.tlrt = tlrt; 1664 fp->mode.rresb.tcode = FWTCODE_RRESB; 1665 fp->mode.rresb.pri = 0; 1666 fp->mode.rresb.dst = htons(dst); 1667 fp->mode.rresb.rtcode = 0; 1668 fp->mode.rresb.extcode = 0; 1669 fp->mode.rresb.len = htons(len); 1670 bcopy(buf, fp->mode.rresb.payload, len); 1671 xfer->act.hand = fw_asy_callback; 1672 err = fw_asyreq(fc, -1, xfer); 1673 if(err){ 1674 fw_xfer_free( xfer); 1675 return err; 1676 } 1677 err = tsleep((caddr_t)xfer, FWPRI, "asyreq", 0); 1678 1679 fw_xfer_free( xfer); 1680 return err; 1681} 1682 1683/* 1684 * Async. write request block support for kernel internal use. 1685 */ 1686int 1687fw_writereqb(struct firewire_comm *fc, u_int32_t addr_hi, u_int32_t addr_lo, 1688 u_int len, u_int32_t *buf) 1689{ 1690 int err = 0; 1691 struct fw_xfer *xfer ; 1692 struct fw_pkt *fp; 1693 1694 xfer = fw_xfer_alloc(); 1695 if(xfer == NULL){ 1696 err = ENOMEM; 1697 return err; 1698 } 1699 xfer->send.len = sizeof(struct fw_pkt) + len; 1700 xfer->spd = 0; 1701 xfer->send.buf = malloc(sizeof(struct fw_pkt) + 1024, M_DEVBUF, M_DONTWAIT); 1702 if(xfer->send.buf == NULL){ 1703 return ENOMEM; 1704 } 1705 xfer->send.off = 0; 1706 fp = (struct fw_pkt *)xfer->send.buf; 1707 fp->mode.wreqb.dest_hi = htonl(addr_hi & 0xffff); 1708 fp->mode.wreqb.tlrt = 0; 1709 fp->mode.wreqb.tcode = FWTCODE_WREQB; 1710 fp->mode.wreqb.pri = 0; 1711 fp->mode.wreqb.dst = htons(addr_hi >> 16); 1712 fp->mode.wreqb.dest_lo = htonl(addr_lo); 1713 fp->mode.wreqb.len = htons(len); 1714 fp->mode.wreqb.extcode = 0; 1715 bcopy(buf, fp->mode.wreqb.payload, len); 1716 xfer->act.hand = fw_asy_callback; 1717 err = fw_asyreq(fc, -1, xfer); 1718 if(err){ 1719 fw_xfer_free( xfer); 1720 return err; 1721 } 1722 err = tsleep((caddr_t)xfer, FWPRI, "asyreq", 0); 1723 1724 fw_xfer_free( xfer); 1725 return err; 1726} 1727 1728/* 1729 * Async. read request support for kernel internal use. 1730 */ 1731int 1732fw_readreqq(struct firewire_comm *fc, u_int32_t addr_hi, u_int32_t addr_lo, u_int32_t *ret){ 1733 int err = 0; 1734 struct fw_xfer *xfer ; 1735 struct fw_pkt *fp, *rfp; 1736 1737 xfer = fw_xfer_alloc(); 1738 if(xfer == NULL){ 1739 err = ENOMEM; 1740 return err; 1741 } 1742 xfer->send.len = 16; 1743 xfer->spd = 0; 1744 xfer->send.buf = malloc(16, M_DEVBUF, M_DONTWAIT); 1745 if(xfer->send.buf == NULL){ 1746 return ENOMEM; 1747 } 1748 xfer->send.off = 0; 1749 fp = (struct fw_pkt *)xfer->send.buf; 1750 fp->mode.rreqq.dest_hi = htonl(addr_hi & 0xffff); 1751 fp->mode.rreqq.tlrt = 0; 1752 fp->mode.rreqq.tcode = FWTCODE_RREQQ; 1753 fp->mode.rreqq.pri = 0; 1754 xfer->dst = addr_hi >> 16; 1755 fp->mode.rreqq.dst = htons(xfer->dst); 1756 fp->mode.rreqq.dest_lo = htonl(addr_lo); 1757 xfer->act.hand = fw_asy_callback; 1758 err = fw_asyreq(fc, -1, xfer); 1759 if(err){ 1760 fw_xfer_free( xfer); 1761 return err; 1762 } 1763 err = tsleep((caddr_t)xfer, FWPRI, "asyreq", 0); 1764 1765 if(err == 0 && xfer->recv.buf != NULL){ 1766 rfp = (struct fw_pkt *)xfer->recv.buf; 1767 *ret = ntohl(rfp->mode.rresq.data); 1768 } 1769 fw_xfer_free( xfer); 1770 return err; 1771} 1772#endif 1773/* | |
1774 * To obtain CSR register values. 1775 */ | 1599 * To obtain CSR register values. 1600 */ |
1776u_int32_t getcsrdata(struct fw_device *fwdev, u_int8_t key) | 1601u_int32_t 1602getcsrdata(struct fw_device *fwdev, u_int8_t key) |
1777{ 1778 int i; 1779 struct csrhdr *chdr; 1780 struct csrreg *creg; 1781 chdr = (struct csrhdr *)&fwdev->csrrom[0]; 1782 for( i = chdr->info_len + 4; i <= fwdev->rommax - CSRROMOFF; i+=4){ 1783 creg = (struct csrreg *)&fwdev->csrrom[i/4]; 1784 if(creg->key == key){ 1785 return (u_int32_t)creg->val; 1786 } 1787 } 1788 return 0; 1789} | 1603{ 1604 int i; 1605 struct csrhdr *chdr; 1606 struct csrreg *creg; 1607 chdr = (struct csrhdr *)&fwdev->csrrom[0]; 1608 for( i = chdr->info_len + 4; i <= fwdev->rommax - CSRROMOFF; i+=4){ 1609 creg = (struct csrreg *)&fwdev->csrrom[i/4]; 1610 if(creg->key == key){ 1611 return (u_int32_t)creg->val; 1612 } 1613 } 1614 return 0; 1615} |
1616 |
|
1790/* 1791 * To attach sub-devices layer onto IEEE1394 bus. 1792 */ | 1617/* 1618 * To attach sub-devices layer onto IEEE1394 bus. 1619 */ |
1793static void fw_attach_dev(struct firewire_comm *fc) | 1620static void 1621fw_attach_dev(struct firewire_comm *fc) |
1794{ 1795 struct fw_device *fwdev; 1796 struct fw_xfer *xfer; 1797 int i, err; 1798 device_t *devlistp; 1799 int devcnt; 1800 struct firewire_dev_comm *fdc; 1801 --- 83 unchanged lines hidden (view full) --- 1885 printf("fw_attach_dev: %d pending handlers called\n", i); 1886 if (fc->retry_count > 0) { 1887 printf("retry_count = %d\n", fc->retry_count); 1888 fc->retry_probe_handle = timeout((timeout_t *)fc->ibr, 1889 (void *)fc, hz*2); 1890 } 1891 return; 1892} | 1622{ 1623 struct fw_device *fwdev; 1624 struct fw_xfer *xfer; 1625 int i, err; 1626 device_t *devlistp; 1627 int devcnt; 1628 struct firewire_dev_comm *fdc; 1629 --- 83 unchanged lines hidden (view full) --- 1713 printf("fw_attach_dev: %d pending handlers called\n", i); 1714 if (fc->retry_count > 0) { 1715 printf("retry_count = %d\n", fc->retry_count); 1716 fc->retry_probe_handle = timeout((timeout_t *)fc->ibr, 1717 (void *)fc, hz*2); 1718 } 1719 return; 1720} |
1721 |
|
1893/* 1894 * To allocate uniq transaction label. 1895 */ | 1722/* 1723 * To allocate uniq transaction label. 1724 */ |
1896static int fw_get_tlabel(struct firewire_comm *fc, struct fw_xfer *xfer) | 1725static int 1726fw_get_tlabel(struct firewire_comm *fc, struct fw_xfer *xfer) |
1897{ 1898 u_int i; 1899 struct tlabel *tl, *tmptl; 1900 int s; 1901 static u_int32_t label = 0; 1902 1903 s = splfw(); 1904 for( i = 0 ; i < 0x40 ; i ++){ --- 14 unchanged lines hidden (view full) --- 1919 return(label); 1920 } 1921 } 1922 splx(s); 1923 1924 printf("fw_get_tlabel: no free tlabel\n"); 1925 return(-1); 1926} | 1727{ 1728 u_int i; 1729 struct tlabel *tl, *tmptl; 1730 int s; 1731 static u_int32_t label = 0; 1732 1733 s = splfw(); 1734 for( i = 0 ; i < 0x40 ; i ++){ --- 14 unchanged lines hidden (view full) --- 1749 return(label); 1750 } 1751 } 1752 splx(s); 1753 1754 printf("fw_get_tlabel: no free tlabel\n"); 1755 return(-1); 1756} |
1757 |
|
1927/* 1928 * Generic packet receving process. 1929 */ | 1758/* 1759 * Generic packet receving process. 1760 */ |
1930void fw_rcv(struct firewire_comm* fc, caddr_t buf, u_int len, u_int sub, u_int off, u_int spd) | 1761void 1762fw_rcv(struct firewire_comm* fc, caddr_t buf, u_int len, u_int sub, u_int off, u_int spd) |
1931{ 1932 struct fw_pkt *fp, *resfp; 1933 struct fw_xfer *xfer; 1934 struct fw_bind *bind; 1935 struct firewire_softc *sc; 1936 int s; 1937#if 0 1938 { --- 203 unchanged lines hidden (view full) --- 2142 } 2143 default: 2144 printf("fw_rcv: unknow tcode\n"); 2145 break; 2146 } 2147err: 2148 free(buf, M_DEVBUF); 2149} | 1763{ 1764 struct fw_pkt *fp, *resfp; 1765 struct fw_xfer *xfer; 1766 struct fw_bind *bind; 1767 struct firewire_softc *sc; 1768 int s; 1769#if 0 1770 { --- 203 unchanged lines hidden (view full) --- 1974 } 1975 default: 1976 printf("fw_rcv: unknow tcode\n"); 1977 break; 1978 } 1979err: 1980 free(buf, M_DEVBUF); 1981} |
1982 |
|
2150/* 2151 * Post process for Bus Manager election process. 2152 */ 2153static void 2154fw_try_bmr_callback(struct fw_xfer *xfer) 2155{ 2156 struct fw_pkt *sfp,*rfp; 2157 struct firewire_comm *fc; --- 24 unchanged lines hidden (view full) --- 2182 fw_phy_config(fc, -1, gap_cnt[fc->max_hop]); 2183 } 2184 }else{ 2185 printf("\n"); 2186 } 2187error: 2188 fw_xfer_free(xfer); 2189} | 1983/* 1984 * Post process for Bus Manager election process. 1985 */ 1986static void 1987fw_try_bmr_callback(struct fw_xfer *xfer) 1988{ 1989 struct fw_pkt *sfp,*rfp; 1990 struct firewire_comm *fc; --- 24 unchanged lines hidden (view full) --- 2015 fw_phy_config(fc, -1, gap_cnt[fc->max_hop]); 2016 } 2017 }else{ 2018 printf("\n"); 2019 } 2020error: 2021 fw_xfer_free(xfer); 2022} |
2023 |
|
2190/* 2191 * To candidate Bus Manager election process. 2192 */ | 2024/* 2025 * To candidate Bus Manager election process. 2026 */ |
2193void fw_try_bmr(void *arg) | 2027void 2028fw_try_bmr(void *arg) |
2194{ 2195 struct fw_xfer *xfer; 2196 struct firewire_comm *fc = (struct firewire_comm *)arg; 2197 struct fw_pkt *fp; 2198 int err = 0; 2199 2200 xfer = fw_xfer_alloc(); 2201 if(xfer == NULL){ --- 34 unchanged lines hidden (view full) --- 2236 return; 2237} 2238 2239#ifdef FW_VMACCESS 2240/* 2241 * Software implementation for physical memory block access. 2242 * XXX:Too slow, usef for debug purpose only. 2243 */ | 2029{ 2030 struct fw_xfer *xfer; 2031 struct firewire_comm *fc = (struct firewire_comm *)arg; 2032 struct fw_pkt *fp; 2033 int err = 0; 2034 2035 xfer = fw_xfer_alloc(); 2036 if(xfer == NULL){ --- 34 unchanged lines hidden (view full) --- 2071 return; 2072} 2073 2074#ifdef FW_VMACCESS 2075/* 2076 * Software implementation for physical memory block access. 2077 * XXX:Too slow, usef for debug purpose only. 2078 */ |
2244static void fw_vmaccess(struct fw_xfer *xfer){ | 2079static void 2080fw_vmaccess(struct fw_xfer *xfer){ |
2245 struct fw_pkt *rfp, *sfp = NULL; 2246 u_int32_t *ld = (u_int32_t *)(xfer->recv.buf + xfer->recv.off); 2247 2248 printf("vmaccess spd:%2x len:%03x %d data:%08x %08x %08x %08x\n", 2249 xfer->spd, xfer->recv.len, xfer->recv.off, ntohl(ld[0]), ntohl(ld[1]), ntohl(ld[2]), ntohl(ld[3])); 2250 printf("vmaccess data:%08x %08x %08x %08x\n", ntohl(ld[4]), ntohl(ld[5]), ntohl(ld[6]), ntohl(ld[7])); 2251 if(xfer->resp != 0){ 2252 fw_xfer_free( xfer); --- 58 unchanged lines hidden (view full) --- 2311/**/ 2312 return; 2313} 2314#endif 2315 2316/* 2317 * CRC16 check-sum for IEEE1394 register blocks. 2318 */ | 2081 struct fw_pkt *rfp, *sfp = NULL; 2082 u_int32_t *ld = (u_int32_t *)(xfer->recv.buf + xfer->recv.off); 2083 2084 printf("vmaccess spd:%2x len:%03x %d data:%08x %08x %08x %08x\n", 2085 xfer->spd, xfer->recv.len, xfer->recv.off, ntohl(ld[0]), ntohl(ld[1]), ntohl(ld[2]), ntohl(ld[3])); 2086 printf("vmaccess data:%08x %08x %08x %08x\n", ntohl(ld[4]), ntohl(ld[5]), ntohl(ld[6]), ntohl(ld[7])); 2087 if(xfer->resp != 0){ 2088 fw_xfer_free( xfer); --- 58 unchanged lines hidden (view full) --- 2147/**/ 2148 return; 2149} 2150#endif 2151 2152/* 2153 * CRC16 check-sum for IEEE1394 register blocks. 2154 */ |
2319u_int16_t fw_crc16(u_int32_t *ptr, u_int32_t len){ | 2155u_int16_t 2156fw_crc16(u_int32_t *ptr, u_int32_t len){ |
2320 u_int32_t i, sum, crc = 0; 2321 int shift; 2322 len = (len + 3) & ~3; 2323 for(i = 0 ; i < len ; i+= 4){ 2324 for( shift = 28 ; shift >= 0 ; shift -= 4){ 2325 sum = ((crc >> 12) ^ (ptr[i/4] >> shift)) & 0xf; 2326 crc = (crc << 4) ^ ( sum << 12 ) ^ ( sum << 5) ^ sum; 2327 } 2328 crc &= 0xffff; 2329 } 2330 return((u_int16_t) crc); 2331} | 2157 u_int32_t i, sum, crc = 0; 2158 int shift; 2159 len = (len + 3) & ~3; 2160 for(i = 0 ; i < len ; i+= 4){ 2161 for( shift = 28 ; shift >= 0 ; shift -= 4){ 2162 sum = ((crc >> 12) ^ (ptr[i/4] >> shift)) & 0xf; 2163 crc = (crc << 4) ^ ( sum << 12 ) ^ ( sum << 5) ^ sum; 2164 } 2165 crc &= 0xffff; 2166 } 2167 return((u_int16_t) crc); 2168} |
2169 |
|
2332DRIVER_MODULE(firewire,fwohci,firewire_driver,firewire_devclass,0,0); 2333MODULE_VERSION(firewire, 1); | 2170DRIVER_MODULE(firewire,fwohci,firewire_driver,firewire_devclass,0,0); 2171MODULE_VERSION(firewire, 1); |