diff options
author | Clemens Ladisch <clemens@ladisch.de> | 2010-06-10 02:33:07 -0400 |
---|---|---|
committer | Clemens Ladisch <clemens@ladisch.de> | 2010-06-10 02:33:07 -0400 |
commit | a48777e03ad53777ed119a5f86dd22a6c5a378ad (patch) | |
tree | 651a3fb567a2b9d6ab111ff07415d87397ba8202 /drivers/firewire | |
parent | 9ab5071cd4a16001e4ba790172a7da5e4172462b (diff) |
firewire: add CSR BUS_TIME support
Implement the BUS_TIME register, which is required for cycle master
capable nodes and tested for by the Base 1393 Test Suite. Even when
there is not yet bus master initialization support, this register allows
us to work together with other bus masters.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Diffstat (limited to 'drivers/firewire')
-rw-r--r-- | drivers/firewire/core-transaction.c | 14 | ||||
-rw-r--r-- | drivers/firewire/ohci.c | 168 |
2 files changed, 120 insertions, 62 deletions
diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c index e3925f67ec12..2a390726fa76 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c | |||
@@ -1104,6 +1104,17 @@ static void handle_registers(struct fw_card *card, struct fw_request *request, | |||
1104 | rcode = RCODE_TYPE_ERROR; | 1104 | rcode = RCODE_TYPE_ERROR; |
1105 | break; | 1105 | break; |
1106 | 1106 | ||
1107 | case CSR_BUS_TIME: | ||
1108 | if (tcode == TCODE_READ_QUADLET_REQUEST) | ||
1109 | *data = cpu_to_be32(card->driver-> | ||
1110 | read_csr_reg(card, CSR_BUS_TIME)); | ||
1111 | else if (tcode == TCODE_WRITE_QUADLET_REQUEST) | ||
1112 | card->driver->write_csr_reg(card, CSR_BUS_TIME, | ||
1113 | be32_to_cpu(*data)); | ||
1114 | else | ||
1115 | rcode = RCODE_TYPE_ERROR; | ||
1116 | break; | ||
1117 | |||
1107 | case CSR_BROADCAST_CHANNEL: | 1118 | case CSR_BROADCAST_CHANNEL: |
1108 | if (tcode == TCODE_READ_QUADLET_REQUEST) | 1119 | if (tcode == TCODE_READ_QUADLET_REQUEST) |
1109 | *data = cpu_to_be32(card->broadcast_channel); | 1120 | *data = cpu_to_be32(card->broadcast_channel); |
@@ -1132,9 +1143,6 @@ static void handle_registers(struct fw_card *card, struct fw_request *request, | |||
1132 | case CSR_BUSY_TIMEOUT: | 1143 | case CSR_BUSY_TIMEOUT: |
1133 | /* FIXME: Implement this. */ | 1144 | /* FIXME: Implement this. */ |
1134 | 1145 | ||
1135 | case CSR_BUS_TIME: | ||
1136 | /* Useless without initialization by the bus manager. */ | ||
1137 | |||
1138 | default: | 1146 | default: |
1139 | rcode = RCODE_ADDRESS_ERROR; | 1147 | rcode = RCODE_ADDRESS_ERROR; |
1140 | break; | 1148 | break; |
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 777811a736b2..3d4badb7c79b 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c | |||
@@ -170,6 +170,7 @@ struct fw_ohci { | |||
170 | int generation; | 170 | int generation; |
171 | int request_generation; /* for timestamping incoming requests */ | 171 | int request_generation; /* for timestamping incoming requests */ |
172 | unsigned quirks; | 172 | unsigned quirks; |
173 | u32 bus_time; | ||
173 | 174 | ||
174 | /* | 175 | /* |
175 | * Spinlock for accessing fw_ohci data. Never call out of | 176 | * Spinlock for accessing fw_ohci data. Never call out of |
@@ -292,7 +293,7 @@ static void log_irqs(u32 evt) | |||
292 | !(evt & OHCI1394_busReset)) | 293 | !(evt & OHCI1394_busReset)) |
293 | return; | 294 | return; |
294 | 295 | ||
295 | fw_notify("IRQ %08x%s%s%s%s%s%s%s%s%s%s%s%s%s\n", evt, | 296 | fw_notify("IRQ %08x%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", evt, |
296 | evt & OHCI1394_selfIDComplete ? " selfID" : "", | 297 | evt & OHCI1394_selfIDComplete ? " selfID" : "", |
297 | evt & OHCI1394_RQPkt ? " AR_req" : "", | 298 | evt & OHCI1394_RQPkt ? " AR_req" : "", |
298 | evt & OHCI1394_RSPkt ? " AR_resp" : "", | 299 | evt & OHCI1394_RSPkt ? " AR_resp" : "", |
@@ -302,6 +303,7 @@ static void log_irqs(u32 evt) | |||
302 | evt & OHCI1394_isochTx ? " IT" : "", | 303 | evt & OHCI1394_isochTx ? " IT" : "", |
303 | evt & OHCI1394_postedWriteErr ? " postedWriteErr" : "", | 304 | evt & OHCI1394_postedWriteErr ? " postedWriteErr" : "", |
304 | evt & OHCI1394_cycleTooLong ? " cycleTooLong" : "", | 305 | evt & OHCI1394_cycleTooLong ? " cycleTooLong" : "", |
306 | evt & OHCI1394_cycle64Seconds ? " cycle64Seconds" : "", | ||
305 | evt & OHCI1394_cycleInconsistent ? " cycleInconsistent" : "", | 307 | evt & OHCI1394_cycleInconsistent ? " cycleInconsistent" : "", |
306 | evt & OHCI1394_regAccessFail ? " regAccessFail" : "", | 308 | evt & OHCI1394_regAccessFail ? " regAccessFail" : "", |
307 | evt & OHCI1394_busReset ? " busReset" : "", | 309 | evt & OHCI1394_busReset ? " busReset" : "", |
@@ -309,7 +311,8 @@ static void log_irqs(u32 evt) | |||
309 | OHCI1394_RSPkt | OHCI1394_reqTxComplete | | 311 | OHCI1394_RSPkt | OHCI1394_reqTxComplete | |
310 | OHCI1394_respTxComplete | OHCI1394_isochRx | | 312 | OHCI1394_respTxComplete | OHCI1394_isochRx | |
311 | OHCI1394_isochTx | OHCI1394_postedWriteErr | | 313 | OHCI1394_isochTx | OHCI1394_postedWriteErr | |
312 | OHCI1394_cycleTooLong | OHCI1394_cycleInconsistent | | 314 | OHCI1394_cycleTooLong | OHCI1394_cycle64Seconds | |
315 | OHCI1394_cycleInconsistent | | ||
313 | OHCI1394_regAccessFail | OHCI1394_busReset) | 316 | OHCI1394_regAccessFail | OHCI1394_busReset) |
314 | ? " ?" : ""); | 317 | ? " ?" : ""); |
315 | } | 318 | } |
@@ -1316,6 +1319,78 @@ static void at_context_transmit(struct context *ctx, struct fw_packet *packet) | |||
1316 | 1319 | ||
1317 | } | 1320 | } |
1318 | 1321 | ||
1322 | static u32 cycle_timer_ticks(u32 cycle_timer) | ||
1323 | { | ||
1324 | u32 ticks; | ||
1325 | |||
1326 | ticks = cycle_timer & 0xfff; | ||
1327 | ticks += 3072 * ((cycle_timer >> 12) & 0x1fff); | ||
1328 | ticks += (3072 * 8000) * (cycle_timer >> 25); | ||
1329 | |||
1330 | return ticks; | ||
1331 | } | ||
1332 | |||
1333 | /* | ||
1334 | * Some controllers exhibit one or more of the following bugs when updating the | ||
1335 | * iso cycle timer register: | ||
1336 | * - When the lowest six bits are wrapping around to zero, a read that happens | ||
1337 | * at the same time will return garbage in the lowest ten bits. | ||
1338 | * - When the cycleOffset field wraps around to zero, the cycleCount field is | ||
1339 | * not incremented for about 60 ns. | ||
1340 | * - Occasionally, the entire register reads zero. | ||
1341 | * | ||
1342 | * To catch these, we read the register three times and ensure that the | ||
1343 | * difference between each two consecutive reads is approximately the same, i.e. | ||
1344 | * less than twice the other. Furthermore, any negative difference indicates an | ||
1345 | * error. (A PCI read should take at least 20 ticks of the 24.576 MHz timer to | ||
1346 | * execute, so we have enough precision to compute the ratio of the differences.) | ||
1347 | */ | ||
1348 | static u32 get_cycle_time(struct fw_ohci *ohci) | ||
1349 | { | ||
1350 | u32 c0, c1, c2; | ||
1351 | u32 t0, t1, t2; | ||
1352 | s32 diff01, diff12; | ||
1353 | int i; | ||
1354 | |||
1355 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1356 | |||
1357 | if (ohci->quirks & QUIRK_CYCLE_TIMER) { | ||
1358 | i = 0; | ||
1359 | c1 = c2; | ||
1360 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1361 | do { | ||
1362 | c0 = c1; | ||
1363 | c1 = c2; | ||
1364 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1365 | t0 = cycle_timer_ticks(c0); | ||
1366 | t1 = cycle_timer_ticks(c1); | ||
1367 | t2 = cycle_timer_ticks(c2); | ||
1368 | diff01 = t1 - t0; | ||
1369 | diff12 = t2 - t1; | ||
1370 | } while ((diff01 <= 0 || diff12 <= 0 || | ||
1371 | diff01 / diff12 >= 2 || diff12 / diff01 >= 2) | ||
1372 | && i++ < 20); | ||
1373 | } | ||
1374 | |||
1375 | return c2; | ||
1376 | } | ||
1377 | |||
1378 | /* | ||
1379 | * This function has to be called at least every 64 seconds. The bus_time | ||
1380 | * field stores not only the upper 25 bits of the BUS_TIME register but also | ||
1381 | * the most significant bit of the cycle timer in bit 6 so that we can detect | ||
1382 | * changes in this bit. | ||
1383 | */ | ||
1384 | static u32 update_bus_time(struct fw_ohci *ohci) | ||
1385 | { | ||
1386 | u32 cycle_time_seconds = get_cycle_time(ohci) >> 25; | ||
1387 | |||
1388 | if ((ohci->bus_time & 0x40) != (cycle_time_seconds & 0x40)) | ||
1389 | ohci->bus_time += 0x40; | ||
1390 | |||
1391 | return ohci->bus_time | cycle_time_seconds; | ||
1392 | } | ||
1393 | |||
1319 | static void bus_reset_tasklet(unsigned long data) | 1394 | static void bus_reset_tasklet(unsigned long data) |
1320 | { | 1395 | { |
1321 | struct fw_ohci *ohci = (struct fw_ohci *)data; | 1396 | struct fw_ohci *ohci = (struct fw_ohci *)data; |
@@ -1520,6 +1595,12 @@ static irqreturn_t irq_handler(int irq, void *data) | |||
1520 | fw_notify("isochronous cycle inconsistent\n"); | 1595 | fw_notify("isochronous cycle inconsistent\n"); |
1521 | } | 1596 | } |
1522 | 1597 | ||
1598 | if (event & OHCI1394_cycle64Seconds) { | ||
1599 | spin_lock(&ohci->lock); | ||
1600 | update_bus_time(ohci); | ||
1601 | spin_unlock(&ohci->lock); | ||
1602 | } | ||
1603 | |||
1523 | return IRQ_HANDLED; | 1604 | return IRQ_HANDLED; |
1524 | } | 1605 | } |
1525 | 1606 | ||
@@ -1604,7 +1685,7 @@ static int ohci_enable(struct fw_card *card, | |||
1604 | { | 1685 | { |
1605 | struct fw_ohci *ohci = fw_ohci(card); | 1686 | struct fw_ohci *ohci = fw_ohci(card); |
1606 | struct pci_dev *dev = to_pci_dev(card->device); | 1687 | struct pci_dev *dev = to_pci_dev(card->device); |
1607 | u32 lps, irqs; | 1688 | u32 lps, seconds, irqs; |
1608 | int i, ret; | 1689 | int i, ret; |
1609 | 1690 | ||
1610 | if (software_reset(ohci)) { | 1691 | if (software_reset(ohci)) { |
@@ -1652,6 +1733,10 @@ static int ohci_enable(struct fw_card *card, | |||
1652 | (OHCI1394_MAX_AT_RESP_RETRIES << 4) | | 1733 | (OHCI1394_MAX_AT_RESP_RETRIES << 4) | |
1653 | (OHCI1394_MAX_PHYS_RESP_RETRIES << 8)); | 1734 | (OHCI1394_MAX_PHYS_RESP_RETRIES << 8)); |
1654 | 1735 | ||
1736 | seconds = lower_32_bits(get_seconds()); | ||
1737 | reg_write(ohci, OHCI1394_IsochronousCycleTimer, seconds << 25); | ||
1738 | ohci->bus_time = seconds & ~0x3f; | ||
1739 | |||
1655 | ar_context_run(&ohci->ar_request_ctx); | 1740 | ar_context_run(&ohci->ar_request_ctx); |
1656 | ar_context_run(&ohci->ar_response_ctx); | 1741 | ar_context_run(&ohci->ar_response_ctx); |
1657 | 1742 | ||
@@ -1732,6 +1817,7 @@ static int ohci_enable(struct fw_card *card, | |||
1732 | OHCI1394_postedWriteErr | | 1817 | OHCI1394_postedWriteErr | |
1733 | OHCI1394_selfIDComplete | | 1818 | OHCI1394_selfIDComplete | |
1734 | OHCI1394_regAccessFail | | 1819 | OHCI1394_regAccessFail | |
1820 | OHCI1394_cycle64Seconds | | ||
1735 | OHCI1394_cycleInconsistent | OHCI1394_cycleTooLong | | 1821 | OHCI1394_cycleInconsistent | OHCI1394_cycleTooLong | |
1736 | OHCI1394_masterIntEnable; | 1822 | OHCI1394_masterIntEnable; |
1737 | if (param_debug & OHCI_PARAM_DEBUG_BUSRESETS) | 1823 | if (param_debug & OHCI_PARAM_DEBUG_BUSRESETS) |
@@ -1913,65 +1999,11 @@ static int ohci_enable_phys_dma(struct fw_card *card, | |||
1913 | #endif /* CONFIG_FIREWIRE_OHCI_REMOTE_DMA */ | 1999 | #endif /* CONFIG_FIREWIRE_OHCI_REMOTE_DMA */ |
1914 | } | 2000 | } |
1915 | 2001 | ||
1916 | static u32 cycle_timer_ticks(u32 cycle_timer) | ||
1917 | { | ||
1918 | u32 ticks; | ||
1919 | |||
1920 | ticks = cycle_timer & 0xfff; | ||
1921 | ticks += 3072 * ((cycle_timer >> 12) & 0x1fff); | ||
1922 | ticks += (3072 * 8000) * (cycle_timer >> 25); | ||
1923 | |||
1924 | return ticks; | ||
1925 | } | ||
1926 | |||
1927 | /* | ||
1928 | * Some controllers exhibit one or more of the following bugs when updating the | ||
1929 | * iso cycle timer register: | ||
1930 | * - When the lowest six bits are wrapping around to zero, a read that happens | ||
1931 | * at the same time will return garbage in the lowest ten bits. | ||
1932 | * - When the cycleOffset field wraps around to zero, the cycleCount field is | ||
1933 | * not incremented for about 60 ns. | ||
1934 | * - Occasionally, the entire register reads zero. | ||
1935 | * | ||
1936 | * To catch these, we read the register three times and ensure that the | ||
1937 | * difference between each two consecutive reads is approximately the same, i.e. | ||
1938 | * less than twice the other. Furthermore, any negative difference indicates an | ||
1939 | * error. (A PCI read should take at least 20 ticks of the 24.576 MHz timer to | ||
1940 | * execute, so we have enough precision to compute the ratio of the differences.) | ||
1941 | */ | ||
1942 | static u32 get_cycle_time(struct fw_ohci *ohci) | ||
1943 | { | ||
1944 | u32 c0, c1, c2; | ||
1945 | u32 t0, t1, t2; | ||
1946 | s32 diff01, diff12; | ||
1947 | int i; | ||
1948 | |||
1949 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1950 | |||
1951 | if (ohci->quirks & QUIRK_CYCLE_TIMER) { | ||
1952 | i = 0; | ||
1953 | c1 = c2; | ||
1954 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1955 | do { | ||
1956 | c0 = c1; | ||
1957 | c1 = c2; | ||
1958 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1959 | t0 = cycle_timer_ticks(c0); | ||
1960 | t1 = cycle_timer_ticks(c1); | ||
1961 | t2 = cycle_timer_ticks(c2); | ||
1962 | diff01 = t1 - t0; | ||
1963 | diff12 = t2 - t1; | ||
1964 | } while ((diff01 <= 0 || diff12 <= 0 || | ||
1965 | diff01 / diff12 >= 2 || diff12 / diff01 >= 2) | ||
1966 | && i++ < 20); | ||
1967 | } | ||
1968 | |||
1969 | return c2; | ||
1970 | } | ||
1971 | |||
1972 | static u32 ohci_read_csr_reg(struct fw_card *card, int csr_offset) | 2002 | static u32 ohci_read_csr_reg(struct fw_card *card, int csr_offset) |
1973 | { | 2003 | { |
1974 | struct fw_ohci *ohci = fw_ohci(card); | 2004 | struct fw_ohci *ohci = fw_ohci(card); |
2005 | unsigned long flags; | ||
2006 | u32 value; | ||
1975 | 2007 | ||
1976 | switch (csr_offset) { | 2008 | switch (csr_offset) { |
1977 | case CSR_NODE_IDS: | 2009 | case CSR_NODE_IDS: |
@@ -1980,6 +2012,17 @@ static u32 ohci_read_csr_reg(struct fw_card *card, int csr_offset) | |||
1980 | case CSR_CYCLE_TIME: | 2012 | case CSR_CYCLE_TIME: |
1981 | return get_cycle_time(ohci); | 2013 | return get_cycle_time(ohci); |
1982 | 2014 | ||
2015 | case CSR_BUS_TIME: | ||
2016 | /* | ||
2017 | * We might be called just after the cycle timer has wrapped | ||
2018 | * around but just before the cycle64Seconds handler, so we | ||
2019 | * better check here, too, if the bus time needs to be updated. | ||
2020 | */ | ||
2021 | spin_lock_irqsave(&ohci->lock, flags); | ||
2022 | value = update_bus_time(ohci); | ||
2023 | spin_unlock_irqrestore(&ohci->lock, flags); | ||
2024 | return value; | ||
2025 | |||
1983 | default: | 2026 | default: |
1984 | WARN_ON(1); | 2027 | WARN_ON(1); |
1985 | return 0; | 2028 | return 0; |
@@ -1989,6 +2032,7 @@ static u32 ohci_read_csr_reg(struct fw_card *card, int csr_offset) | |||
1989 | static void ohci_write_csr_reg(struct fw_card *card, int csr_offset, u32 value) | 2032 | static void ohci_write_csr_reg(struct fw_card *card, int csr_offset, u32 value) |
1990 | { | 2033 | { |
1991 | struct fw_ohci *ohci = fw_ohci(card); | 2034 | struct fw_ohci *ohci = fw_ohci(card); |
2035 | unsigned long flags; | ||
1992 | 2036 | ||
1993 | switch (csr_offset) { | 2037 | switch (csr_offset) { |
1994 | case CSR_NODE_IDS: | 2038 | case CSR_NODE_IDS: |
@@ -2003,6 +2047,12 @@ static void ohci_write_csr_reg(struct fw_card *card, int csr_offset, u32 value) | |||
2003 | flush_writes(ohci); | 2047 | flush_writes(ohci); |
2004 | break; | 2048 | break; |
2005 | 2049 | ||
2050 | case CSR_BUS_TIME: | ||
2051 | spin_lock_irqsave(&ohci->lock, flags); | ||
2052 | ohci->bus_time = (ohci->bus_time & 0x7f) | (value & ~0x7f); | ||
2053 | spin_unlock_irqrestore(&ohci->lock, flags); | ||
2054 | break; | ||
2055 | |||
2006 | default: | 2056 | default: |
2007 | WARN_ON(1); | 2057 | WARN_ON(1); |
2008 | break; | 2058 | break; |