diff options
Diffstat (limited to 'drivers/firewire/ohci.c')
-rw-r--r-- | drivers/firewire/ohci.c | 364 |
1 files changed, 123 insertions, 241 deletions
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 43ebf337b131..75dc6988cffd 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c | |||
@@ -38,7 +38,6 @@ | |||
38 | #include <linux/spinlock.h> | 38 | #include <linux/spinlock.h> |
39 | #include <linux/string.h> | 39 | #include <linux/string.h> |
40 | 40 | ||
41 | #include <asm/atomic.h> | ||
42 | #include <asm/byteorder.h> | 41 | #include <asm/byteorder.h> |
43 | #include <asm/page.h> | 42 | #include <asm/page.h> |
44 | #include <asm/system.h> | 43 | #include <asm/system.h> |
@@ -73,20 +72,6 @@ struct descriptor { | |||
73 | __le16 transfer_status; | 72 | __le16 transfer_status; |
74 | } __attribute__((aligned(16))); | 73 | } __attribute__((aligned(16))); |
75 | 74 | ||
76 | struct db_descriptor { | ||
77 | __le16 first_size; | ||
78 | __le16 control; | ||
79 | __le16 second_req_count; | ||
80 | __le16 first_req_count; | ||
81 | __le32 branch_address; | ||
82 | __le16 second_res_count; | ||
83 | __le16 first_res_count; | ||
84 | __le32 reserved0; | ||
85 | __le32 first_buffer; | ||
86 | __le32 second_buffer; | ||
87 | __le32 reserved1; | ||
88 | } __attribute__((aligned(16))); | ||
89 | |||
90 | #define CONTROL_SET(regs) (regs) | 75 | #define CONTROL_SET(regs) (regs) |
91 | #define CONTROL_CLEAR(regs) ((regs) + 4) | 76 | #define CONTROL_CLEAR(regs) ((regs) + 4) |
92 | #define COMMAND_PTR(regs) ((regs) + 12) | 77 | #define COMMAND_PTR(regs) ((regs) + 12) |
@@ -181,31 +166,16 @@ struct fw_ohci { | |||
181 | struct fw_card card; | 166 | struct fw_card card; |
182 | 167 | ||
183 | __iomem char *registers; | 168 | __iomem char *registers; |
184 | dma_addr_t self_id_bus; | ||
185 | __le32 *self_id_cpu; | ||
186 | struct tasklet_struct bus_reset_tasklet; | ||
187 | int node_id; | 169 | int node_id; |
188 | int generation; | 170 | int generation; |
189 | int request_generation; /* for timestamping incoming requests */ | 171 | int request_generation; /* for timestamping incoming requests */ |
190 | atomic_t bus_seconds; | 172 | unsigned quirks; |
191 | |||
192 | bool use_dualbuffer; | ||
193 | bool old_uninorth; | ||
194 | bool bus_reset_packet_quirk; | ||
195 | 173 | ||
196 | /* | 174 | /* |
197 | * Spinlock for accessing fw_ohci data. Never call out of | 175 | * Spinlock for accessing fw_ohci data. Never call out of |
198 | * this driver with this lock held. | 176 | * this driver with this lock held. |
199 | */ | 177 | */ |
200 | spinlock_t lock; | 178 | spinlock_t lock; |
201 | u32 self_id_buffer[512]; | ||
202 | |||
203 | /* Config rom buffers */ | ||
204 | __be32 *config_rom; | ||
205 | dma_addr_t config_rom_bus; | ||
206 | __be32 *next_config_rom; | ||
207 | dma_addr_t next_config_rom_bus; | ||
208 | __be32 next_header; | ||
209 | 179 | ||
210 | struct ar_context ar_request_ctx; | 180 | struct ar_context ar_request_ctx; |
211 | struct ar_context ar_response_ctx; | 181 | struct ar_context ar_response_ctx; |
@@ -217,6 +187,18 @@ struct fw_ohci { | |||
217 | u64 ir_context_channels; | 187 | u64 ir_context_channels; |
218 | u32 ir_context_mask; | 188 | u32 ir_context_mask; |
219 | struct iso_context *ir_context_list; | 189 | struct iso_context *ir_context_list; |
190 | |||
191 | __be32 *config_rom; | ||
192 | dma_addr_t config_rom_bus; | ||
193 | __be32 *next_config_rom; | ||
194 | dma_addr_t next_config_rom_bus; | ||
195 | __be32 next_header; | ||
196 | |||
197 | __le32 *self_id_cpu; | ||
198 | dma_addr_t self_id_bus; | ||
199 | struct tasklet_struct bus_reset_tasklet; | ||
200 | |||
201 | u32 self_id_buffer[512]; | ||
220 | }; | 202 | }; |
221 | 203 | ||
222 | static inline struct fw_ohci *fw_ohci(struct fw_card *card) | 204 | static inline struct fw_ohci *fw_ohci(struct fw_card *card) |
@@ -249,6 +231,30 @@ static inline struct fw_ohci *fw_ohci(struct fw_card *card) | |||
249 | 231 | ||
250 | static char ohci_driver_name[] = KBUILD_MODNAME; | 232 | static char ohci_driver_name[] = KBUILD_MODNAME; |
251 | 233 | ||
234 | #define QUIRK_CYCLE_TIMER 1 | ||
235 | #define QUIRK_RESET_PACKET 2 | ||
236 | #define QUIRK_BE_HEADERS 4 | ||
237 | |||
238 | /* In case of multiple matches in ohci_quirks[], only the first one is used. */ | ||
239 | static const struct { | ||
240 | unsigned short vendor, device, flags; | ||
241 | } ohci_quirks[] = { | ||
242 | {PCI_VENDOR_ID_TI, PCI_ANY_ID, QUIRK_RESET_PACKET}, | ||
243 | {PCI_VENDOR_ID_AL, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, | ||
244 | {PCI_VENDOR_ID_NEC, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, | ||
245 | {PCI_VENDOR_ID_VIA, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, | ||
246 | {PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_FW, QUIRK_BE_HEADERS}, | ||
247 | }; | ||
248 | |||
249 | /* This overrides anything that was found in ohci_quirks[]. */ | ||
250 | static int param_quirks; | ||
251 | module_param_named(quirks, param_quirks, int, 0644); | ||
252 | MODULE_PARM_DESC(quirks, "Chip quirks (default = 0" | ||
253 | ", nonatomic cycle timer = " __stringify(QUIRK_CYCLE_TIMER) | ||
254 | ", reset packet generation = " __stringify(QUIRK_RESET_PACKET) | ||
255 | ", AR/selfID endianess = " __stringify(QUIRK_BE_HEADERS) | ||
256 | ")"); | ||
257 | |||
252 | #ifdef CONFIG_FIREWIRE_OHCI_DEBUG | 258 | #ifdef CONFIG_FIREWIRE_OHCI_DEBUG |
253 | 259 | ||
254 | #define OHCI_PARAM_DEBUG_AT_AR 1 | 260 | #define OHCI_PARAM_DEBUG_AT_AR 1 |
@@ -275,7 +281,7 @@ static void log_irqs(u32 evt) | |||
275 | !(evt & OHCI1394_busReset)) | 281 | !(evt & OHCI1394_busReset)) |
276 | return; | 282 | return; |
277 | 283 | ||
278 | fw_notify("IRQ %08x%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", evt, | 284 | fw_notify("IRQ %08x%s%s%s%s%s%s%s%s%s%s%s%s%s\n", evt, |
279 | evt & OHCI1394_selfIDComplete ? " selfID" : "", | 285 | evt & OHCI1394_selfIDComplete ? " selfID" : "", |
280 | evt & OHCI1394_RQPkt ? " AR_req" : "", | 286 | evt & OHCI1394_RQPkt ? " AR_req" : "", |
281 | evt & OHCI1394_RSPkt ? " AR_resp" : "", | 287 | evt & OHCI1394_RSPkt ? " AR_resp" : "", |
@@ -285,7 +291,6 @@ static void log_irqs(u32 evt) | |||
285 | evt & OHCI1394_isochTx ? " IT" : "", | 291 | evt & OHCI1394_isochTx ? " IT" : "", |
286 | evt & OHCI1394_postedWriteErr ? " postedWriteErr" : "", | 292 | evt & OHCI1394_postedWriteErr ? " postedWriteErr" : "", |
287 | evt & OHCI1394_cycleTooLong ? " cycleTooLong" : "", | 293 | evt & OHCI1394_cycleTooLong ? " cycleTooLong" : "", |
288 | evt & OHCI1394_cycle64Seconds ? " cycle64Seconds" : "", | ||
289 | evt & OHCI1394_cycleInconsistent ? " cycleInconsistent" : "", | 294 | evt & OHCI1394_cycleInconsistent ? " cycleInconsistent" : "", |
290 | evt & OHCI1394_regAccessFail ? " regAccessFail" : "", | 295 | evt & OHCI1394_regAccessFail ? " regAccessFail" : "", |
291 | evt & OHCI1394_busReset ? " busReset" : "", | 296 | evt & OHCI1394_busReset ? " busReset" : "", |
@@ -293,8 +298,7 @@ static void log_irqs(u32 evt) | |||
293 | OHCI1394_RSPkt | OHCI1394_reqTxComplete | | 298 | OHCI1394_RSPkt | OHCI1394_reqTxComplete | |
294 | OHCI1394_respTxComplete | OHCI1394_isochRx | | 299 | OHCI1394_respTxComplete | OHCI1394_isochRx | |
295 | OHCI1394_isochTx | OHCI1394_postedWriteErr | | 300 | OHCI1394_isochTx | OHCI1394_postedWriteErr | |
296 | OHCI1394_cycleTooLong | OHCI1394_cycle64Seconds | | 301 | OHCI1394_cycleTooLong | OHCI1394_cycleInconsistent | |
297 | OHCI1394_cycleInconsistent | | ||
298 | OHCI1394_regAccessFail | OHCI1394_busReset) | 302 | OHCI1394_regAccessFail | OHCI1394_busReset) |
299 | ? " ?" : ""); | 303 | ? " ?" : ""); |
300 | } | 304 | } |
@@ -524,7 +528,7 @@ static void ar_context_release(struct ar_context *ctx) | |||
524 | 528 | ||
525 | #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) | 529 | #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) |
526 | #define cond_le32_to_cpu(v) \ | 530 | #define cond_le32_to_cpu(v) \ |
527 | (ohci->old_uninorth ? (__force __u32)(v) : le32_to_cpu(v)) | 531 | (ohci->quirks & QUIRK_BE_HEADERS ? (__force __u32)(v) : le32_to_cpu(v)) |
528 | #else | 532 | #else |
529 | #define cond_le32_to_cpu(v) le32_to_cpu(v) | 533 | #define cond_le32_to_cpu(v) le32_to_cpu(v) |
530 | #endif | 534 | #endif |
@@ -605,7 +609,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer) | |||
605 | * at a slightly incorrect time (in bus_reset_tasklet). | 609 | * at a slightly incorrect time (in bus_reset_tasklet). |
606 | */ | 610 | */ |
607 | if (evt == OHCI1394_evt_bus_reset) { | 611 | if (evt == OHCI1394_evt_bus_reset) { |
608 | if (!ohci->bus_reset_packet_quirk) | 612 | if (!(ohci->quirks & QUIRK_RESET_PACKET)) |
609 | ohci->request_generation = (p.header[2] >> 16) & 0xff; | 613 | ohci->request_generation = (p.header[2] >> 16) & 0xff; |
610 | } else if (ctx == &ohci->ar_request_ctx) { | 614 | } else if (ctx == &ohci->ar_request_ctx) { |
611 | fw_core_handle_request(&ohci->card, &p); | 615 | fw_core_handle_request(&ohci->card, &p); |
@@ -1329,7 +1333,7 @@ static void bus_reset_tasklet(unsigned long data) | |||
1329 | context_stop(&ohci->at_response_ctx); | 1333 | context_stop(&ohci->at_response_ctx); |
1330 | reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset); | 1334 | reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset); |
1331 | 1335 | ||
1332 | if (ohci->bus_reset_packet_quirk) | 1336 | if (ohci->quirks & QUIRK_RESET_PACKET) |
1333 | ohci->request_generation = generation; | 1337 | ohci->request_generation = generation; |
1334 | 1338 | ||
1335 | /* | 1339 | /* |
@@ -1384,7 +1388,7 @@ static void bus_reset_tasklet(unsigned long data) | |||
1384 | static irqreturn_t irq_handler(int irq, void *data) | 1388 | static irqreturn_t irq_handler(int irq, void *data) |
1385 | { | 1389 | { |
1386 | struct fw_ohci *ohci = data; | 1390 | struct fw_ohci *ohci = data; |
1387 | u32 event, iso_event, cycle_time; | 1391 | u32 event, iso_event; |
1388 | int i; | 1392 | int i; |
1389 | 1393 | ||
1390 | event = reg_read(ohci, OHCI1394_IntEventClear); | 1394 | event = reg_read(ohci, OHCI1394_IntEventClear); |
@@ -1454,12 +1458,6 @@ static irqreturn_t irq_handler(int irq, void *data) | |||
1454 | fw_notify("isochronous cycle inconsistent\n"); | 1458 | fw_notify("isochronous cycle inconsistent\n"); |
1455 | } | 1459 | } |
1456 | 1460 | ||
1457 | if (event & OHCI1394_cycle64Seconds) { | ||
1458 | cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1459 | if ((cycle_time & 0x80000000) == 0) | ||
1460 | atomic_inc(&ohci->bus_seconds); | ||
1461 | } | ||
1462 | |||
1463 | return IRQ_HANDLED; | 1461 | return IRQ_HANDLED; |
1464 | } | 1462 | } |
1465 | 1463 | ||
@@ -1553,8 +1551,7 @@ static int ohci_enable(struct fw_card *card, | |||
1553 | OHCI1394_reqTxComplete | OHCI1394_respTxComplete | | 1551 | OHCI1394_reqTxComplete | OHCI1394_respTxComplete | |
1554 | OHCI1394_isochRx | OHCI1394_isochTx | | 1552 | OHCI1394_isochRx | OHCI1394_isochTx | |
1555 | OHCI1394_postedWriteErr | OHCI1394_cycleTooLong | | 1553 | OHCI1394_postedWriteErr | OHCI1394_cycleTooLong | |
1556 | OHCI1394_cycleInconsistent | | 1554 | OHCI1394_cycleInconsistent | OHCI1394_regAccessFail | |
1557 | OHCI1394_cycle64Seconds | OHCI1394_regAccessFail | | ||
1558 | OHCI1394_masterIntEnable); | 1555 | OHCI1394_masterIntEnable); |
1559 | if (param_debug & OHCI_PARAM_DEBUG_BUSRESETS) | 1556 | if (param_debug & OHCI_PARAM_DEBUG_BUSRESETS) |
1560 | reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset); | 1557 | reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset); |
@@ -1794,16 +1791,61 @@ static int ohci_enable_phys_dma(struct fw_card *card, | |||
1794 | #endif /* CONFIG_FIREWIRE_OHCI_REMOTE_DMA */ | 1791 | #endif /* CONFIG_FIREWIRE_OHCI_REMOTE_DMA */ |
1795 | } | 1792 | } |
1796 | 1793 | ||
1797 | static u64 ohci_get_bus_time(struct fw_card *card) | 1794 | static u32 cycle_timer_ticks(u32 cycle_timer) |
1798 | { | 1795 | { |
1799 | struct fw_ohci *ohci = fw_ohci(card); | 1796 | u32 ticks; |
1800 | u32 cycle_time; | ||
1801 | u64 bus_time; | ||
1802 | 1797 | ||
1803 | cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | 1798 | ticks = cycle_timer & 0xfff; |
1804 | bus_time = ((u64)atomic_read(&ohci->bus_seconds) << 32) | cycle_time; | 1799 | ticks += 3072 * ((cycle_timer >> 12) & 0x1fff); |
1800 | ticks += (3072 * 8000) * (cycle_timer >> 25); | ||
1801 | |||
1802 | return ticks; | ||
1803 | } | ||
1804 | |||
1805 | /* | ||
1806 | * Some controllers exhibit one or more of the following bugs when updating the | ||
1807 | * iso cycle timer register: | ||
1808 | * - When the lowest six bits are wrapping around to zero, a read that happens | ||
1809 | * at the same time will return garbage in the lowest ten bits. | ||
1810 | * - When the cycleOffset field wraps around to zero, the cycleCount field is | ||
1811 | * not incremented for about 60 ns. | ||
1812 | * - Occasionally, the entire register reads zero. | ||
1813 | * | ||
1814 | * To catch these, we read the register three times and ensure that the | ||
1815 | * difference between each two consecutive reads is approximately the same, i.e. | ||
1816 | * less than twice the other. Furthermore, any negative difference indicates an | ||
1817 | * error. (A PCI read should take at least 20 ticks of the 24.576 MHz timer to | ||
1818 | * execute, so we have enough precision to compute the ratio of the differences.) | ||
1819 | */ | ||
1820 | static u32 ohci_get_cycle_time(struct fw_card *card) | ||
1821 | { | ||
1822 | struct fw_ohci *ohci = fw_ohci(card); | ||
1823 | u32 c0, c1, c2; | ||
1824 | u32 t0, t1, t2; | ||
1825 | s32 diff01, diff12; | ||
1826 | int i; | ||
1805 | 1827 | ||
1806 | return bus_time; | 1828 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); |
1829 | |||
1830 | if (ohci->quirks & QUIRK_CYCLE_TIMER) { | ||
1831 | i = 0; | ||
1832 | c1 = c2; | ||
1833 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1834 | do { | ||
1835 | c0 = c1; | ||
1836 | c1 = c2; | ||
1837 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1838 | t0 = cycle_timer_ticks(c0); | ||
1839 | t1 = cycle_timer_ticks(c1); | ||
1840 | t2 = cycle_timer_ticks(c2); | ||
1841 | diff01 = t1 - t0; | ||
1842 | diff12 = t2 - t1; | ||
1843 | } while ((diff01 <= 0 || diff12 <= 0 || | ||
1844 | diff01 / diff12 >= 2 || diff12 / diff01 >= 2) | ||
1845 | && i++ < 20); | ||
1846 | } | ||
1847 | |||
1848 | return c2; | ||
1807 | } | 1849 | } |
1808 | 1850 | ||
1809 | static void copy_iso_headers(struct iso_context *ctx, void *p) | 1851 | static void copy_iso_headers(struct iso_context *ctx, void *p) |
@@ -1828,52 +1870,6 @@ static void copy_iso_headers(struct iso_context *ctx, void *p) | |||
1828 | ctx->header_length += ctx->base.header_size; | 1870 | ctx->header_length += ctx->base.header_size; |
1829 | } | 1871 | } |
1830 | 1872 | ||
1831 | static int handle_ir_dualbuffer_packet(struct context *context, | ||
1832 | struct descriptor *d, | ||
1833 | struct descriptor *last) | ||
1834 | { | ||
1835 | struct iso_context *ctx = | ||
1836 | container_of(context, struct iso_context, context); | ||
1837 | struct db_descriptor *db = (struct db_descriptor *) d; | ||
1838 | __le32 *ir_header; | ||
1839 | size_t header_length; | ||
1840 | void *p, *end; | ||
1841 | |||
1842 | if (db->first_res_count != 0 && db->second_res_count != 0) { | ||
1843 | if (ctx->excess_bytes <= le16_to_cpu(db->second_req_count)) { | ||
1844 | /* This descriptor isn't done yet, stop iteration. */ | ||
1845 | return 0; | ||
1846 | } | ||
1847 | ctx->excess_bytes -= le16_to_cpu(db->second_req_count); | ||
1848 | } | ||
1849 | |||
1850 | header_length = le16_to_cpu(db->first_req_count) - | ||
1851 | le16_to_cpu(db->first_res_count); | ||
1852 | |||
1853 | p = db + 1; | ||
1854 | end = p + header_length; | ||
1855 | while (p < end) { | ||
1856 | copy_iso_headers(ctx, p); | ||
1857 | ctx->excess_bytes += | ||
1858 | (le32_to_cpu(*(__le32 *)(p + 4)) >> 16) & 0xffff; | ||
1859 | p += max(ctx->base.header_size, (size_t)8); | ||
1860 | } | ||
1861 | |||
1862 | ctx->excess_bytes -= le16_to_cpu(db->second_req_count) - | ||
1863 | le16_to_cpu(db->second_res_count); | ||
1864 | |||
1865 | if (le16_to_cpu(db->control) & DESCRIPTOR_IRQ_ALWAYS) { | ||
1866 | ir_header = (__le32 *) (db + 1); | ||
1867 | ctx->base.callback(&ctx->base, | ||
1868 | le32_to_cpu(ir_header[0]) & 0xffff, | ||
1869 | ctx->header_length, ctx->header, | ||
1870 | ctx->base.callback_data); | ||
1871 | ctx->header_length = 0; | ||
1872 | } | ||
1873 | |||
1874 | return 1; | ||
1875 | } | ||
1876 | |||
1877 | static int handle_ir_packet_per_buffer(struct context *context, | 1873 | static int handle_ir_packet_per_buffer(struct context *context, |
1878 | struct descriptor *d, | 1874 | struct descriptor *d, |
1879 | struct descriptor *last) | 1875 | struct descriptor *last) |
@@ -1960,10 +1956,7 @@ static struct fw_iso_context *ohci_allocate_iso_context(struct fw_card *card, | |||
1960 | channels = &ohci->ir_context_channels; | 1956 | channels = &ohci->ir_context_channels; |
1961 | mask = &ohci->ir_context_mask; | 1957 | mask = &ohci->ir_context_mask; |
1962 | list = ohci->ir_context_list; | 1958 | list = ohci->ir_context_list; |
1963 | if (ohci->use_dualbuffer) | 1959 | callback = handle_ir_packet_per_buffer; |
1964 | callback = handle_ir_dualbuffer_packet; | ||
1965 | else | ||
1966 | callback = handle_ir_packet_per_buffer; | ||
1967 | } | 1960 | } |
1968 | 1961 | ||
1969 | spin_lock_irqsave(&ohci->lock, flags); | 1962 | spin_lock_irqsave(&ohci->lock, flags); |
@@ -2026,8 +2019,6 @@ static int ohci_start_iso(struct fw_iso_context *base, | |||
2026 | } else { | 2019 | } else { |
2027 | index = ctx - ohci->ir_context_list; | 2020 | index = ctx - ohci->ir_context_list; |
2028 | control = IR_CONTEXT_ISOCH_HEADER; | 2021 | control = IR_CONTEXT_ISOCH_HEADER; |
2029 | if (ohci->use_dualbuffer) | ||
2030 | control |= IR_CONTEXT_DUAL_BUFFER_MODE; | ||
2031 | match = (tags << 28) | (sync << 8) | ctx->base.channel; | 2022 | match = (tags << 28) | (sync << 8) | ctx->base.channel; |
2032 | if (cycle >= 0) { | 2023 | if (cycle >= 0) { |
2033 | match |= (cycle & 0x07fff) << 12; | 2024 | match |= (cycle & 0x07fff) << 12; |
@@ -2188,92 +2179,6 @@ static int ohci_queue_iso_transmit(struct fw_iso_context *base, | |||
2188 | return 0; | 2179 | return 0; |
2189 | } | 2180 | } |
2190 | 2181 | ||
2191 | static int ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base, | ||
2192 | struct fw_iso_packet *packet, | ||
2193 | struct fw_iso_buffer *buffer, | ||
2194 | unsigned long payload) | ||
2195 | { | ||
2196 | struct iso_context *ctx = container_of(base, struct iso_context, base); | ||
2197 | struct db_descriptor *db = NULL; | ||
2198 | struct descriptor *d; | ||
2199 | struct fw_iso_packet *p; | ||
2200 | dma_addr_t d_bus, page_bus; | ||
2201 | u32 z, header_z, length, rest; | ||
2202 | int page, offset, packet_count, header_size; | ||
2203 | |||
2204 | /* | ||
2205 | * FIXME: Cycle lost behavior should be configurable: lose | ||
2206 | * packet, retransmit or terminate.. | ||
2207 | */ | ||
2208 | |||
2209 | p = packet; | ||
2210 | z = 2; | ||
2211 | |||
2212 | /* | ||
2213 | * The OHCI controller puts the isochronous header and trailer in the | ||
2214 | * buffer, so we need at least 8 bytes. | ||
2215 | */ | ||
2216 | packet_count = p->header_length / ctx->base.header_size; | ||
2217 | header_size = packet_count * max(ctx->base.header_size, (size_t)8); | ||
2218 | |||
2219 | /* Get header size in number of descriptors. */ | ||
2220 | header_z = DIV_ROUND_UP(header_size, sizeof(*d)); | ||
2221 | page = payload >> PAGE_SHIFT; | ||
2222 | offset = payload & ~PAGE_MASK; | ||
2223 | rest = p->payload_length; | ||
2224 | /* | ||
2225 | * The controllers I've tested have not worked correctly when | ||
2226 | * second_req_count is zero. Rather than do something we know won't | ||
2227 | * work, return an error | ||
2228 | */ | ||
2229 | if (rest == 0) | ||
2230 | return -EINVAL; | ||
2231 | |||
2232 | while (rest > 0) { | ||
2233 | d = context_get_descriptors(&ctx->context, | ||
2234 | z + header_z, &d_bus); | ||
2235 | if (d == NULL) | ||
2236 | return -ENOMEM; | ||
2237 | |||
2238 | db = (struct db_descriptor *) d; | ||
2239 | db->control = cpu_to_le16(DESCRIPTOR_STATUS | | ||
2240 | DESCRIPTOR_BRANCH_ALWAYS); | ||
2241 | db->first_size = | ||
2242 | cpu_to_le16(max(ctx->base.header_size, (size_t)8)); | ||
2243 | if (p->skip && rest == p->payload_length) { | ||
2244 | db->control |= cpu_to_le16(DESCRIPTOR_WAIT); | ||
2245 | db->first_req_count = db->first_size; | ||
2246 | } else { | ||
2247 | db->first_req_count = cpu_to_le16(header_size); | ||
2248 | } | ||
2249 | db->first_res_count = db->first_req_count; | ||
2250 | db->first_buffer = cpu_to_le32(d_bus + sizeof(*db)); | ||
2251 | |||
2252 | if (p->skip && rest == p->payload_length) | ||
2253 | length = 4; | ||
2254 | else if (offset + rest < PAGE_SIZE) | ||
2255 | length = rest; | ||
2256 | else | ||
2257 | length = PAGE_SIZE - offset; | ||
2258 | |||
2259 | db->second_req_count = cpu_to_le16(length); | ||
2260 | db->second_res_count = db->second_req_count; | ||
2261 | page_bus = page_private(buffer->pages[page]); | ||
2262 | db->second_buffer = cpu_to_le32(page_bus + offset); | ||
2263 | |||
2264 | if (p->interrupt && length == rest) | ||
2265 | db->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS); | ||
2266 | |||
2267 | context_append(&ctx->context, d, z, header_z); | ||
2268 | offset = (offset + length) & ~PAGE_MASK; | ||
2269 | rest -= length; | ||
2270 | if (offset == 0) | ||
2271 | page++; | ||
2272 | } | ||
2273 | |||
2274 | return 0; | ||
2275 | } | ||
2276 | |||
2277 | static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base, | 2182 | static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base, |
2278 | struct fw_iso_packet *packet, | 2183 | struct fw_iso_packet *packet, |
2279 | struct fw_iso_buffer *buffer, | 2184 | struct fw_iso_buffer *buffer, |
@@ -2364,9 +2269,6 @@ static int ohci_queue_iso(struct fw_iso_context *base, | |||
2364 | spin_lock_irqsave(&ctx->context.ohci->lock, flags); | 2269 | spin_lock_irqsave(&ctx->context.ohci->lock, flags); |
2365 | if (base->type == FW_ISO_CONTEXT_TRANSMIT) | 2270 | if (base->type == FW_ISO_CONTEXT_TRANSMIT) |
2366 | ret = ohci_queue_iso_transmit(base, packet, buffer, payload); | 2271 | ret = ohci_queue_iso_transmit(base, packet, buffer, payload); |
2367 | else if (ctx->context.ohci->use_dualbuffer) | ||
2368 | ret = ohci_queue_iso_receive_dualbuffer(base, packet, | ||
2369 | buffer, payload); | ||
2370 | else | 2272 | else |
2371 | ret = ohci_queue_iso_receive_packet_per_buffer(base, packet, | 2273 | ret = ohci_queue_iso_receive_packet_per_buffer(base, packet, |
2372 | buffer, payload); | 2274 | buffer, payload); |
@@ -2383,7 +2285,7 @@ static const struct fw_card_driver ohci_driver = { | |||
2383 | .send_response = ohci_send_response, | 2285 | .send_response = ohci_send_response, |
2384 | .cancel_packet = ohci_cancel_packet, | 2286 | .cancel_packet = ohci_cancel_packet, |
2385 | .enable_phys_dma = ohci_enable_phys_dma, | 2287 | .enable_phys_dma = ohci_enable_phys_dma, |
2386 | .get_bus_time = ohci_get_bus_time, | 2288 | .get_cycle_time = ohci_get_cycle_time, |
2387 | 2289 | ||
2388 | .allocate_iso_context = ohci_allocate_iso_context, | 2290 | .allocate_iso_context = ohci_allocate_iso_context, |
2389 | .free_iso_context = ohci_free_iso_context, | 2291 | .free_iso_context = ohci_free_iso_context, |
@@ -2421,17 +2323,13 @@ static void ohci_pmac_off(struct pci_dev *dev) | |||
2421 | #define ohci_pmac_off(dev) | 2323 | #define ohci_pmac_off(dev) |
2422 | #endif /* CONFIG_PPC_PMAC */ | 2324 | #endif /* CONFIG_PPC_PMAC */ |
2423 | 2325 | ||
2424 | #define PCI_VENDOR_ID_AGERE PCI_VENDOR_ID_ATT | ||
2425 | #define PCI_DEVICE_ID_AGERE_FW643 0x5901 | ||
2426 | #define PCI_DEVICE_ID_TI_TSB43AB23 0x8024 | ||
2427 | |||
2428 | static int __devinit pci_probe(struct pci_dev *dev, | 2326 | static int __devinit pci_probe(struct pci_dev *dev, |
2429 | const struct pci_device_id *ent) | 2327 | const struct pci_device_id *ent) |
2430 | { | 2328 | { |
2431 | struct fw_ohci *ohci; | 2329 | struct fw_ohci *ohci; |
2432 | u32 bus_options, max_receive, link_speed, version; | 2330 | u32 bus_options, max_receive, link_speed, version; |
2433 | u64 guid; | 2331 | u64 guid; |
2434 | int err; | 2332 | int i, err, n_ir, n_it; |
2435 | size_t size; | 2333 | size_t size; |
2436 | 2334 | ||
2437 | ohci = kzalloc(sizeof(*ohci), GFP_KERNEL); | 2335 | ohci = kzalloc(sizeof(*ohci), GFP_KERNEL); |
@@ -2472,36 +2370,15 @@ static int __devinit pci_probe(struct pci_dev *dev, | |||
2472 | goto fail_iomem; | 2370 | goto fail_iomem; |
2473 | } | 2371 | } |
2474 | 2372 | ||
2475 | version = reg_read(ohci, OHCI1394_Version) & 0x00ff00ff; | 2373 | for (i = 0; i < ARRAY_SIZE(ohci_quirks); i++) |
2476 | #if 0 | 2374 | if (ohci_quirks[i].vendor == dev->vendor && |
2477 | /* FIXME: make it a context option or remove dual-buffer mode */ | 2375 | (ohci_quirks[i].device == dev->device || |
2478 | ohci->use_dualbuffer = version >= OHCI_VERSION_1_1; | 2376 | ohci_quirks[i].device == (unsigned short)PCI_ANY_ID)) { |
2479 | #endif | 2377 | ohci->quirks = ohci_quirks[i].flags; |
2480 | 2378 | break; | |
2481 | /* dual-buffer mode is broken if more than one IR context is active */ | 2379 | } |
2482 | if (dev->vendor == PCI_VENDOR_ID_AGERE && | 2380 | if (param_quirks) |
2483 | dev->device == PCI_DEVICE_ID_AGERE_FW643) | 2381 | ohci->quirks = param_quirks; |
2484 | ohci->use_dualbuffer = false; | ||
2485 | |||
2486 | /* dual-buffer mode is broken */ | ||
2487 | if (dev->vendor == PCI_VENDOR_ID_RICOH && | ||
2488 | dev->device == PCI_DEVICE_ID_RICOH_R5C832) | ||
2489 | ohci->use_dualbuffer = false; | ||
2490 | |||
2491 | /* x86-32 currently doesn't use highmem for dma_alloc_coherent */ | ||
2492 | #if !defined(CONFIG_X86_32) | ||
2493 | /* dual-buffer mode is broken with descriptor addresses above 2G */ | ||
2494 | if (dev->vendor == PCI_VENDOR_ID_TI && | ||
2495 | (dev->device == PCI_DEVICE_ID_TI_TSB43AB22 || | ||
2496 | dev->device == PCI_DEVICE_ID_TI_TSB43AB23)) | ||
2497 | ohci->use_dualbuffer = false; | ||
2498 | #endif | ||
2499 | |||
2500 | #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) | ||
2501 | ohci->old_uninorth = dev->vendor == PCI_VENDOR_ID_APPLE && | ||
2502 | dev->device == PCI_DEVICE_ID_APPLE_UNI_N_FW; | ||
2503 | #endif | ||
2504 | ohci->bus_reset_packet_quirk = dev->vendor == PCI_VENDOR_ID_TI; | ||
2505 | 2382 | ||
2506 | ar_context_init(&ohci->ar_request_ctx, ohci, | 2383 | ar_context_init(&ohci->ar_request_ctx, ohci, |
2507 | OHCI1394_AsReqRcvContextControlSet); | 2384 | OHCI1394_AsReqRcvContextControlSet); |
@@ -2516,17 +2393,19 @@ static int __devinit pci_probe(struct pci_dev *dev, | |||
2516 | OHCI1394_AsRspTrContextControlSet, handle_at_packet); | 2393 | OHCI1394_AsRspTrContextControlSet, handle_at_packet); |
2517 | 2394 | ||
2518 | reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, ~0); | 2395 | reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, ~0); |
2519 | ohci->it_context_mask = reg_read(ohci, OHCI1394_IsoRecvIntMaskSet); | 2396 | ohci->ir_context_channels = ~0ULL; |
2397 | ohci->ir_context_mask = reg_read(ohci, OHCI1394_IsoRecvIntMaskSet); | ||
2520 | reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, ~0); | 2398 | reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, ~0); |
2521 | size = sizeof(struct iso_context) * hweight32(ohci->it_context_mask); | 2399 | n_ir = hweight32(ohci->ir_context_mask); |
2522 | ohci->it_context_list = kzalloc(size, GFP_KERNEL); | 2400 | size = sizeof(struct iso_context) * n_ir; |
2401 | ohci->ir_context_list = kzalloc(size, GFP_KERNEL); | ||
2523 | 2402 | ||
2524 | reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0); | 2403 | reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0); |
2525 | ohci->ir_context_channels = ~0ULL; | 2404 | ohci->it_context_mask = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet); |
2526 | ohci->ir_context_mask = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet); | ||
2527 | reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0); | 2405 | reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0); |
2528 | size = sizeof(struct iso_context) * hweight32(ohci->ir_context_mask); | 2406 | n_it = hweight32(ohci->it_context_mask); |
2529 | ohci->ir_context_list = kzalloc(size, GFP_KERNEL); | 2407 | size = sizeof(struct iso_context) * n_it; |
2408 | ohci->it_context_list = kzalloc(size, GFP_KERNEL); | ||
2530 | 2409 | ||
2531 | if (ohci->it_context_list == NULL || ohci->ir_context_list == NULL) { | 2410 | if (ohci->it_context_list == NULL || ohci->ir_context_list == NULL) { |
2532 | err = -ENOMEM; | 2411 | err = -ENOMEM; |
@@ -2553,8 +2432,11 @@ static int __devinit pci_probe(struct pci_dev *dev, | |||
2553 | if (err) | 2432 | if (err) |
2554 | goto fail_self_id; | 2433 | goto fail_self_id; |
2555 | 2434 | ||
2556 | fw_notify("Added fw-ohci device %s, OHCI version %x.%x\n", | 2435 | version = reg_read(ohci, OHCI1394_Version) & 0x00ff00ff; |
2557 | dev_name(&dev->dev), version >> 16, version & 0xff); | 2436 | fw_notify("Added fw-ohci device %s, OHCI v%x.%x, " |
2437 | "%d IR + %d IT contexts, quirks 0x%x\n", | ||
2438 | dev_name(&dev->dev), version >> 16, version & 0xff, | ||
2439 | n_ir, n_it, ohci->quirks); | ||
2558 | 2440 | ||
2559 | return 0; | 2441 | return 0; |
2560 | 2442 | ||
@@ -2662,7 +2544,7 @@ static int pci_resume(struct pci_dev *dev) | |||
2662 | } | 2544 | } |
2663 | #endif | 2545 | #endif |
2664 | 2546 | ||
2665 | static struct pci_device_id pci_table[] = { | 2547 | static const struct pci_device_id pci_table[] = { |
2666 | { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_FIREWIRE_OHCI, ~0) }, | 2548 | { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_FIREWIRE_OHCI, ~0) }, |
2667 | { } | 2549 | { } |
2668 | }; | 2550 | }; |