aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-11-01 18:02:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-11-01 18:02:38 -0400
commitc18ae42aa5b3473c00f51b6937d0c00bdb6ce2d2 (patch)
tree327ca3f9c0a7eae6031eb1b610d48efa0940db87
parent1c398651518c7e25a9fb3f08b456c73d5ca22469 (diff)
parenta572e688cf5d99d2382016c7241ec37b523b0137 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394: firewire: ohci: fix isochronous DMA synchronization firewire: ohci: work around selfID junk due to wrong gap count firewire: net: Use posted writes firewire: use clamp and min3 macros firewire: ohci: optimize TSB41BA3D detection firewire: ohci: TSB41BA3D support tweaks firewire: ohci: Add support for TSB41BA3D phy firewire: ohci: Move code from the bus reset tasklet into a workqueue firewire: sbp2: fold two functions into one firewire: sbp2: move some code to more sensible places firewire: sbp2: remove obsolete reference counting
-rw-r--r--drivers/firewire/core-transaction.c4
-rw-r--r--drivers/firewire/net.c15
-rw-r--r--drivers/firewire/ohci.c255
-rw-r--r--drivers/firewire/sbp2.c260
4 files changed, 362 insertions, 172 deletions
diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
index 334b82a3542c..855ab3f5936f 100644
--- a/drivers/firewire/core-transaction.c
+++ b/drivers/firewire/core-transaction.c
@@ -1046,8 +1046,8 @@ static void update_split_timeout(struct fw_card *card)
1046 1046
1047 cycles = card->split_timeout_hi * 8000 + (card->split_timeout_lo >> 19); 1047 cycles = card->split_timeout_hi * 8000 + (card->split_timeout_lo >> 19);
1048 1048
1049 cycles = max(cycles, 800u); /* minimum as per the spec */ 1049 /* minimum per IEEE 1394, maximum which doesn't overflow OHCI */
1050 cycles = min(cycles, 3u * 8000u); /* maximum OHCI timeout */ 1050 cycles = clamp(cycles, 800u, 3u * 8000u);
1051 1051
1052 card->split_timeout_cycles = cycles; 1052 card->split_timeout_cycles = cycles;
1053 card->split_timeout_jiffies = DIV_ROUND_UP(cycles * HZ, 8000); 1053 card->split_timeout_jiffies = DIV_ROUND_UP(cycles * HZ, 8000);
diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c
index 03a7a85d0424..a20f45b1e7e5 100644
--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -502,11 +502,7 @@ static struct fwnet_peer *fwnet_peer_find_by_node_id(struct fwnet_device *dev,
502static unsigned fwnet_max_payload(unsigned max_rec, unsigned speed) 502static unsigned fwnet_max_payload(unsigned max_rec, unsigned speed)
503{ 503{
504 max_rec = min(max_rec, speed + 8); 504 max_rec = min(max_rec, speed + 8);
505 max_rec = min(max_rec, 0xbU); /* <= 4096 */ 505 max_rec = clamp(max_rec, 8U, 11U); /* 512...4096 */
506 if (max_rec < 8) {
507 fw_notify("max_rec %x out of range\n", max_rec);
508 max_rec = 8;
509 }
510 506
511 return (1 << (max_rec + 1)) - RFC2374_FRAG_HDR_SIZE; 507 return (1 << (max_rec + 1)) - RFC2374_FRAG_HDR_SIZE;
512} 508}
@@ -1125,17 +1121,12 @@ static int fwnet_broadcast_start(struct fwnet_device *dev)
1125 unsigned u; 1121 unsigned u;
1126 1122
1127 if (dev->local_fifo == FWNET_NO_FIFO_ADDR) { 1123 if (dev->local_fifo == FWNET_NO_FIFO_ADDR) {
1128 /* outside OHCI posted write area? */
1129 static const struct fw_address_region region = {
1130 .start = 0xffff00000000ULL,
1131 .end = CSR_REGISTER_BASE,
1132 };
1133
1134 dev->handler.length = 4096; 1124 dev->handler.length = 4096;
1135 dev->handler.address_callback = fwnet_receive_packet; 1125 dev->handler.address_callback = fwnet_receive_packet;
1136 dev->handler.callback_data = dev; 1126 dev->handler.callback_data = dev;
1137 1127
1138 retval = fw_core_add_address_handler(&dev->handler, &region); 1128 retval = fw_core_add_address_handler(&dev->handler,
1129 &fw_high_memory_region);
1139 if (retval < 0) 1130 if (retval < 0)
1140 goto failed_initial; 1131 goto failed_initial;
1141 1132
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index fd7170a9ad2c..6628feaa7622 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -42,6 +42,7 @@
42#include <linux/string.h> 42#include <linux/string.h>
43#include <linux/time.h> 43#include <linux/time.h>
44#include <linux/vmalloc.h> 44#include <linux/vmalloc.h>
45#include <linux/workqueue.h>
45 46
46#include <asm/byteorder.h> 47#include <asm/byteorder.h>
47#include <asm/page.h> 48#include <asm/page.h>
@@ -125,6 +126,7 @@ struct context {
125 struct fw_ohci *ohci; 126 struct fw_ohci *ohci;
126 u32 regs; 127 u32 regs;
127 int total_allocation; 128 int total_allocation;
129 u32 current_bus;
128 bool running; 130 bool running;
129 bool flushing; 131 bool flushing;
130 132
@@ -226,7 +228,7 @@ struct fw_ohci {
226 228
227 __le32 *self_id_cpu; 229 __le32 *self_id_cpu;
228 dma_addr_t self_id_bus; 230 dma_addr_t self_id_bus;
229 struct tasklet_struct bus_reset_tasklet; 231 struct work_struct bus_reset_work;
230 232
231 u32 self_id_buffer[512]; 233 u32 self_id_buffer[512];
232}; 234};
@@ -263,6 +265,8 @@ static char ohci_driver_name[] = KBUILD_MODNAME;
263#define PCI_DEVICE_ID_AGERE_FW643 0x5901 265#define PCI_DEVICE_ID_AGERE_FW643 0x5901
264#define PCI_DEVICE_ID_JMICRON_JMB38X_FW 0x2380 266#define PCI_DEVICE_ID_JMICRON_JMB38X_FW 0x2380
265#define PCI_DEVICE_ID_TI_TSB12LV22 0x8009 267#define PCI_DEVICE_ID_TI_TSB12LV22 0x8009
268#define PCI_DEVICE_ID_TI_TSB12LV26 0x8020
269#define PCI_DEVICE_ID_TI_TSB82AA2 0x8025
266#define PCI_VENDOR_ID_PINNACLE_SYSTEMS 0x11bd 270#define PCI_VENDOR_ID_PINNACLE_SYSTEMS 0x11bd
267 271
268#define QUIRK_CYCLE_TIMER 1 272#define QUIRK_CYCLE_TIMER 1
@@ -270,6 +274,7 @@ static char ohci_driver_name[] = KBUILD_MODNAME;
270#define QUIRK_BE_HEADERS 4 274#define QUIRK_BE_HEADERS 4
271#define QUIRK_NO_1394A 8 275#define QUIRK_NO_1394A 8
272#define QUIRK_NO_MSI 16 276#define QUIRK_NO_MSI 16
277#define QUIRK_TI_SLLZ059 32
273 278
274/* In case of multiple matches in ohci_quirks[], only the first one is used. */ 279/* In case of multiple matches in ohci_quirks[], only the first one is used. */
275static const struct { 280static const struct {
@@ -299,6 +304,12 @@ static const struct {
299 {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV22, PCI_ANY_ID, 304 {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV22, PCI_ANY_ID,
300 QUIRK_CYCLE_TIMER | QUIRK_RESET_PACKET | QUIRK_NO_1394A}, 305 QUIRK_CYCLE_TIMER | QUIRK_RESET_PACKET | QUIRK_NO_1394A},
301 306
307 {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV26, PCI_ANY_ID,
308 QUIRK_RESET_PACKET | QUIRK_TI_SLLZ059},
309
310 {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB82AA2, PCI_ANY_ID,
311 QUIRK_RESET_PACKET | QUIRK_TI_SLLZ059},
312
302 {PCI_VENDOR_ID_TI, PCI_ANY_ID, PCI_ANY_ID, 313 {PCI_VENDOR_ID_TI, PCI_ANY_ID, PCI_ANY_ID,
303 QUIRK_RESET_PACKET}, 314 QUIRK_RESET_PACKET},
304 315
@@ -315,6 +326,7 @@ MODULE_PARM_DESC(quirks, "Chip quirks (default = 0"
315 ", AR/selfID endianess = " __stringify(QUIRK_BE_HEADERS) 326 ", AR/selfID endianess = " __stringify(QUIRK_BE_HEADERS)
316 ", no 1394a enhancements = " __stringify(QUIRK_NO_1394A) 327 ", no 1394a enhancements = " __stringify(QUIRK_NO_1394A)
317 ", disable MSI = " __stringify(QUIRK_NO_MSI) 328 ", disable MSI = " __stringify(QUIRK_NO_MSI)
329 ", TI SLLZ059 erratum = " __stringify(QUIRK_TI_SLLZ059)
318 ")"); 330 ")");
319 331
320#define OHCI_PARAM_DEBUG_AT_AR 1 332#define OHCI_PARAM_DEBUG_AT_AR 1
@@ -859,7 +871,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
859 * 871 *
860 * Alas some chips sometimes emit bus reset packets with a 872 * Alas some chips sometimes emit bus reset packets with a
861 * wrong generation. We set the correct generation for these 873 * wrong generation. We set the correct generation for these
862 * at a slightly incorrect time (in bus_reset_tasklet). 874 * at a slightly incorrect time (in bus_reset_work).
863 */ 875 */
864 if (evt == OHCI1394_evt_bus_reset) { 876 if (evt == OHCI1394_evt_bus_reset) {
865 if (!(ohci->quirks & QUIRK_RESET_PACKET)) 877 if (!(ohci->quirks & QUIRK_RESET_PACKET))
@@ -1046,6 +1058,7 @@ static void context_tasklet(unsigned long data)
1046 address = le32_to_cpu(last->branch_address); 1058 address = le32_to_cpu(last->branch_address);
1047 z = address & 0xf; 1059 z = address & 0xf;
1048 address &= ~0xf; 1060 address &= ~0xf;
1061 ctx->current_bus = address;
1049 1062
1050 /* If the branch address points to a buffer outside of the 1063 /* If the branch address points to a buffer outside of the
1051 * current buffer, advance to the next buffer. */ 1064 * current buffer, advance to the next buffer. */
@@ -1713,9 +1726,94 @@ static u32 update_bus_time(struct fw_ohci *ohci)
1713 return ohci->bus_time | cycle_time_seconds; 1726 return ohci->bus_time | cycle_time_seconds;
1714} 1727}
1715 1728
1716static void bus_reset_tasklet(unsigned long data) 1729static int get_status_for_port(struct fw_ohci *ohci, int port_index)
1730{
1731 int reg;
1732
1733 mutex_lock(&ohci->phy_reg_mutex);
1734 reg = write_phy_reg(ohci, 7, port_index);
1735 if (reg >= 0)
1736 reg = read_phy_reg(ohci, 8);
1737 mutex_unlock(&ohci->phy_reg_mutex);
1738 if (reg < 0)
1739 return reg;
1740
1741 switch (reg & 0x0f) {
1742 case 0x06:
1743 return 2; /* is child node (connected to parent node) */
1744 case 0x0e:
1745 return 3; /* is parent node (connected to child node) */
1746 }
1747 return 1; /* not connected */
1748}
1749
1750static int get_self_id_pos(struct fw_ohci *ohci, u32 self_id,
1751 int self_id_count)
1752{
1753 int i;
1754 u32 entry;
1755
1756 for (i = 0; i < self_id_count; i++) {
1757 entry = ohci->self_id_buffer[i];
1758 if ((self_id & 0xff000000) == (entry & 0xff000000))
1759 return -1;
1760 if ((self_id & 0xff000000) < (entry & 0xff000000))
1761 return i;
1762 }
1763 return i;
1764}
1765
1766/*
1767 * TI TSB82AA2B and TSB12LV26 do not receive the selfID of a locally
1768 * attached TSB41BA3D phy; see http://www.ti.com/litv/pdf/sllz059.
1769 * Construct the selfID from phy register contents.
1770 * FIXME: How to determine the selfID.i flag?
1771 */
1772static int find_and_insert_self_id(struct fw_ohci *ohci, int self_id_count)
1773{
1774 int reg, i, pos, status;
1775 /* link active 1, speed 3, bridge 0, contender 1, more packets 0 */
1776 u32 self_id = 0x8040c800;
1777
1778 reg = reg_read(ohci, OHCI1394_NodeID);
1779 if (!(reg & OHCI1394_NodeID_idValid)) {
1780 fw_notify("node ID not valid, new bus reset in progress\n");
1781 return -EBUSY;
1782 }
1783 self_id |= ((reg & 0x3f) << 24); /* phy ID */
1784
1785 reg = ohci_read_phy_reg(&ohci->card, 4);
1786 if (reg < 0)
1787 return reg;
1788 self_id |= ((reg & 0x07) << 8); /* power class */
1789
1790 reg = ohci_read_phy_reg(&ohci->card, 1);
1791 if (reg < 0)
1792 return reg;
1793 self_id |= ((reg & 0x3f) << 16); /* gap count */
1794
1795 for (i = 0; i < 3; i++) {
1796 status = get_status_for_port(ohci, i);
1797 if (status < 0)
1798 return status;
1799 self_id |= ((status & 0x3) << (6 - (i * 2)));
1800 }
1801
1802 pos = get_self_id_pos(ohci, self_id, self_id_count);
1803 if (pos >= 0) {
1804 memmove(&(ohci->self_id_buffer[pos+1]),
1805 &(ohci->self_id_buffer[pos]),
1806 (self_id_count - pos) * sizeof(*ohci->self_id_buffer));
1807 ohci->self_id_buffer[pos] = self_id;
1808 self_id_count++;
1809 }
1810 return self_id_count;
1811}
1812
1813static void bus_reset_work(struct work_struct *work)
1717{ 1814{
1718 struct fw_ohci *ohci = (struct fw_ohci *)data; 1815 struct fw_ohci *ohci =
1816 container_of(work, struct fw_ohci, bus_reset_work);
1719 int self_id_count, i, j, reg; 1817 int self_id_count, i, j, reg;
1720 int generation, new_generation; 1818 int generation, new_generation;
1721 unsigned long flags; 1819 unsigned long flags;
@@ -1753,21 +1851,50 @@ static void bus_reset_tasklet(unsigned long data)
1753 * bit extra to get the actual number of self IDs. 1851 * bit extra to get the actual number of self IDs.
1754 */ 1852 */
1755 self_id_count = (reg >> 3) & 0xff; 1853 self_id_count = (reg >> 3) & 0xff;
1756 if (self_id_count == 0 || self_id_count > 252) { 1854
1855 if (self_id_count > 252) {
1757 fw_notify("inconsistent self IDs\n"); 1856 fw_notify("inconsistent self IDs\n");
1758 return; 1857 return;
1759 } 1858 }
1859
1760 generation = (cond_le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff; 1860 generation = (cond_le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff;
1761 rmb(); 1861 rmb();
1762 1862
1763 for (i = 1, j = 0; j < self_id_count; i += 2, j++) { 1863 for (i = 1, j = 0; j < self_id_count; i += 2, j++) {
1764 if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1]) { 1864 if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1]) {
1765 fw_notify("inconsistent self IDs\n"); 1865 /*
1766 return; 1866 * If the invalid data looks like a cycle start packet,
1867 * it's likely to be the result of the cycle master
1868 * having a wrong gap count. In this case, the self IDs
1869 * so far are valid and should be processed so that the
1870 * bus manager can then correct the gap count.
1871 */
1872 if (cond_le32_to_cpu(ohci->self_id_cpu[i])
1873 == 0xffff008f) {
1874 fw_notify("ignoring spurious self IDs\n");
1875 self_id_count = j;
1876 break;
1877 } else {
1878 fw_notify("inconsistent self IDs\n");
1879 return;
1880 }
1767 } 1881 }
1768 ohci->self_id_buffer[j] = 1882 ohci->self_id_buffer[j] =
1769 cond_le32_to_cpu(ohci->self_id_cpu[i]); 1883 cond_le32_to_cpu(ohci->self_id_cpu[i]);
1770 } 1884 }
1885
1886 if (ohci->quirks & QUIRK_TI_SLLZ059) {
1887 self_id_count = find_and_insert_self_id(ohci, self_id_count);
1888 if (self_id_count < 0) {
1889 fw_notify("could not construct local self ID\n");
1890 return;
1891 }
1892 }
1893
1894 if (self_id_count == 0) {
1895 fw_notify("inconsistent self IDs\n");
1896 return;
1897 }
1771 rmb(); 1898 rmb();
1772 1899
1773 /* 1900 /*
@@ -1887,7 +2014,7 @@ static irqreturn_t irq_handler(int irq, void *data)
1887 log_irqs(event); 2014 log_irqs(event);
1888 2015
1889 if (event & OHCI1394_selfIDComplete) 2016 if (event & OHCI1394_selfIDComplete)
1890 tasklet_schedule(&ohci->bus_reset_tasklet); 2017 queue_work(fw_workqueue, &ohci->bus_reset_work);
1891 2018
1892 if (event & OHCI1394_RQPkt) 2019 if (event & OHCI1394_RQPkt)
1893 tasklet_schedule(&ohci->ar_request_ctx.tasklet); 2020 tasklet_schedule(&ohci->ar_request_ctx.tasklet);
@@ -1934,7 +2061,8 @@ static irqreturn_t irq_handler(int irq, void *data)
1934 reg_read(ohci, OHCI1394_PostedWriteAddressLo); 2061 reg_read(ohci, OHCI1394_PostedWriteAddressLo);
1935 reg_write(ohci, OHCI1394_IntEventClear, 2062 reg_write(ohci, OHCI1394_IntEventClear,
1936 OHCI1394_postedWriteErr); 2063 OHCI1394_postedWriteErr);
1937 fw_error("PCI posted write error\n"); 2064 if (printk_ratelimit())
2065 fw_error("PCI posted write error\n");
1938 } 2066 }
1939 2067
1940 if (unlikely(event & OHCI1394_cycleTooLong)) { 2068 if (unlikely(event & OHCI1394_cycleTooLong)) {
@@ -2048,6 +2176,28 @@ static int configure_1394a_enhancements(struct fw_ohci *ohci)
2048 return 0; 2176 return 0;
2049} 2177}
2050 2178
2179static int probe_tsb41ba3d(struct fw_ohci *ohci)
2180{
2181 /* TI vendor ID = 0x080028, TSB41BA3D product ID = 0x833005 (sic) */
2182 static const u8 id[] = { 0x08, 0x00, 0x28, 0x83, 0x30, 0x05, };
2183 int reg, i;
2184
2185 reg = read_phy_reg(ohci, 2);
2186 if (reg < 0)
2187 return reg;
2188 if ((reg & PHY_EXTENDED_REGISTERS) != PHY_EXTENDED_REGISTERS)
2189 return 0;
2190
2191 for (i = ARRAY_SIZE(id) - 1; i >= 0; i--) {
2192 reg = read_paged_phy_reg(ohci, 1, i + 10);
2193 if (reg < 0)
2194 return reg;
2195 if (reg != id[i])
2196 return 0;
2197 }
2198 return 1;
2199}
2200
2051static int ohci_enable(struct fw_card *card, 2201static int ohci_enable(struct fw_card *card,
2052 const __be32 *config_rom, size_t length) 2202 const __be32 *config_rom, size_t length)
2053{ 2203{
@@ -2085,6 +2235,16 @@ static int ohci_enable(struct fw_card *card,
2085 return -EIO; 2235 return -EIO;
2086 } 2236 }
2087 2237
2238 if (ohci->quirks & QUIRK_TI_SLLZ059) {
2239 ret = probe_tsb41ba3d(ohci);
2240 if (ret < 0)
2241 return ret;
2242 if (ret)
2243 fw_notify("local TSB41BA3D phy\n");
2244 else
2245 ohci->quirks &= ~QUIRK_TI_SLLZ059;
2246 }
2247
2088 reg_write(ohci, OHCI1394_HCControlClear, 2248 reg_write(ohci, OHCI1394_HCControlClear,
2089 OHCI1394_HCControl_noByteSwapData); 2249 OHCI1394_HCControl_noByteSwapData);
2090 2250
@@ -2260,7 +2420,7 @@ static int ohci_set_config_rom(struct fw_card *card,
2260 * then set up the real values for the two registers. 2420 * then set up the real values for the two registers.
2261 * 2421 *
2262 * We use ohci->lock to avoid racing with the code that sets 2422 * We use ohci->lock to avoid racing with the code that sets
2263 * ohci->next_config_rom to NULL (see bus_reset_tasklet). 2423 * ohci->next_config_rom to NULL (see bus_reset_work).
2264 */ 2424 */
2265 2425
2266 next_config_rom = 2426 next_config_rom =
@@ -2539,6 +2699,7 @@ static int handle_ir_packet_per_buffer(struct context *context,
2539 struct iso_context *ctx = 2699 struct iso_context *ctx =
2540 container_of(context, struct iso_context, context); 2700 container_of(context, struct iso_context, context);
2541 struct descriptor *pd; 2701 struct descriptor *pd;
2702 u32 buffer_dma;
2542 __le32 *ir_header; 2703 __le32 *ir_header;
2543 void *p; 2704 void *p;
2544 2705
@@ -2549,6 +2710,16 @@ static int handle_ir_packet_per_buffer(struct context *context,
2549 /* Descriptor(s) not done yet, stop iteration */ 2710 /* Descriptor(s) not done yet, stop iteration */
2550 return 0; 2711 return 0;
2551 2712
2713 while (!(d->control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS))) {
2714 d++;
2715 buffer_dma = le32_to_cpu(d->data_address);
2716 dma_sync_single_range_for_cpu(context->ohci->card.device,
2717 buffer_dma & PAGE_MASK,
2718 buffer_dma & ~PAGE_MASK,
2719 le16_to_cpu(d->req_count),
2720 DMA_FROM_DEVICE);
2721 }
2722
2552 p = last + 1; 2723 p = last + 1;
2553 copy_iso_headers(ctx, p); 2724 copy_iso_headers(ctx, p);
2554 2725
@@ -2571,11 +2742,19 @@ static int handle_ir_buffer_fill(struct context *context,
2571{ 2742{
2572 struct iso_context *ctx = 2743 struct iso_context *ctx =
2573 container_of(context, struct iso_context, context); 2744 container_of(context, struct iso_context, context);
2745 u32 buffer_dma;
2574 2746
2575 if (!last->transfer_status) 2747 if (!last->transfer_status)
2576 /* Descriptor(s) not done yet, stop iteration */ 2748 /* Descriptor(s) not done yet, stop iteration */
2577 return 0; 2749 return 0;
2578 2750
2751 buffer_dma = le32_to_cpu(last->data_address);
2752 dma_sync_single_range_for_cpu(context->ohci->card.device,
2753 buffer_dma & PAGE_MASK,
2754 buffer_dma & ~PAGE_MASK,
2755 le16_to_cpu(last->req_count),
2756 DMA_FROM_DEVICE);
2757
2579 if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) 2758 if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS)
2580 ctx->base.callback.mc(&ctx->base, 2759 ctx->base.callback.mc(&ctx->base,
2581 le32_to_cpu(last->data_address) + 2760 le32_to_cpu(last->data_address) +
@@ -2586,6 +2765,43 @@ static int handle_ir_buffer_fill(struct context *context,
2586 return 1; 2765 return 1;
2587} 2766}
2588 2767
2768static inline void sync_it_packet_for_cpu(struct context *context,
2769 struct descriptor *pd)
2770{
2771 __le16 control;
2772 u32 buffer_dma;
2773
2774 /* only packets beginning with OUTPUT_MORE* have data buffers */
2775 if (pd->control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS))
2776 return;
2777
2778 /* skip over the OUTPUT_MORE_IMMEDIATE descriptor */
2779 pd += 2;
2780
2781 /*
2782 * If the packet has a header, the first OUTPUT_MORE/LAST descriptor's
2783 * data buffer is in the context program's coherent page and must not
2784 * be synced.
2785 */
2786 if ((le32_to_cpu(pd->data_address) & PAGE_MASK) ==
2787 (context->current_bus & PAGE_MASK)) {
2788 if (pd->control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS))
2789 return;
2790 pd++;
2791 }
2792
2793 do {
2794 buffer_dma = le32_to_cpu(pd->data_address);
2795 dma_sync_single_range_for_cpu(context->ohci->card.device,
2796 buffer_dma & PAGE_MASK,
2797 buffer_dma & ~PAGE_MASK,
2798 le16_to_cpu(pd->req_count),
2799 DMA_TO_DEVICE);
2800 control = pd->control;
2801 pd++;
2802 } while (!(control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS)));
2803}
2804
2589static int handle_it_packet(struct context *context, 2805static int handle_it_packet(struct context *context,
2590 struct descriptor *d, 2806 struct descriptor *d,
2591 struct descriptor *last) 2807 struct descriptor *last)
@@ -2602,6 +2818,8 @@ static int handle_it_packet(struct context *context,
2602 /* Descriptor(s) not done yet, stop iteration */ 2818 /* Descriptor(s) not done yet, stop iteration */
2603 return 0; 2819 return 0;
2604 2820
2821 sync_it_packet_for_cpu(context, d);
2822
2605 i = ctx->header_length; 2823 i = ctx->header_length;
2606 if (i + 4 < PAGE_SIZE) { 2824 if (i + 4 < PAGE_SIZE) {
2607 /* Present this value as big-endian to match the receive code */ 2825 /* Present this value as big-endian to match the receive code */
@@ -2971,6 +3189,10 @@ static int queue_iso_transmit(struct iso_context *ctx,
2971 page_bus = page_private(buffer->pages[page]); 3189 page_bus = page_private(buffer->pages[page]);
2972 pd[i].data_address = cpu_to_le32(page_bus + offset); 3190 pd[i].data_address = cpu_to_le32(page_bus + offset);
2973 3191
3192 dma_sync_single_range_for_device(ctx->context.ohci->card.device,
3193 page_bus, offset, length,
3194 DMA_TO_DEVICE);
3195
2974 payload_index += length; 3196 payload_index += length;
2975 } 3197 }
2976 3198
@@ -2995,6 +3217,7 @@ static int queue_iso_packet_per_buffer(struct iso_context *ctx,
2995 struct fw_iso_buffer *buffer, 3217 struct fw_iso_buffer *buffer,
2996 unsigned long payload) 3218 unsigned long payload)
2997{ 3219{
3220 struct device *device = ctx->context.ohci->card.device;
2998 struct descriptor *d, *pd; 3221 struct descriptor *d, *pd;
2999 dma_addr_t d_bus, page_bus; 3222 dma_addr_t d_bus, page_bus;
3000 u32 z, header_z, rest; 3223 u32 z, header_z, rest;
@@ -3049,6 +3272,10 @@ static int queue_iso_packet_per_buffer(struct iso_context *ctx,
3049 page_bus = page_private(buffer->pages[page]); 3272 page_bus = page_private(buffer->pages[page]);
3050 pd->data_address = cpu_to_le32(page_bus + offset); 3273 pd->data_address = cpu_to_le32(page_bus + offset);
3051 3274
3275 dma_sync_single_range_for_device(device, page_bus,
3276 offset, length,
3277 DMA_FROM_DEVICE);
3278
3052 offset = (offset + length) & ~PAGE_MASK; 3279 offset = (offset + length) & ~PAGE_MASK;
3053 rest -= length; 3280 rest -= length;
3054 if (offset == 0) 3281 if (offset == 0)
@@ -3108,6 +3335,10 @@ static int queue_iso_buffer_fill(struct iso_context *ctx,
3108 page_bus = page_private(buffer->pages[page]); 3335 page_bus = page_private(buffer->pages[page]);
3109 d->data_address = cpu_to_le32(page_bus + offset); 3336 d->data_address = cpu_to_le32(page_bus + offset);
3110 3337
3338 dma_sync_single_range_for_device(ctx->context.ohci->card.device,
3339 page_bus, offset, length,
3340 DMA_FROM_DEVICE);
3341
3111 rest -= length; 3342 rest -= length;
3112 offset = 0; 3343 offset = 0;
3113 page++; 3344 page++;
@@ -3239,8 +3470,7 @@ static int __devinit pci_probe(struct pci_dev *dev,
3239 spin_lock_init(&ohci->lock); 3470 spin_lock_init(&ohci->lock);
3240 mutex_init(&ohci->phy_reg_mutex); 3471 mutex_init(&ohci->phy_reg_mutex);
3241 3472
3242 tasklet_init(&ohci->bus_reset_tasklet, 3473 INIT_WORK(&ohci->bus_reset_work, bus_reset_work);
3243 bus_reset_tasklet, (unsigned long)ohci);
3244 3474
3245 err = pci_request_region(dev, 0, ohci_driver_name); 3475 err = pci_request_region(dev, 0, ohci_driver_name);
3246 if (err) { 3476 if (err) {
@@ -3382,6 +3612,7 @@ static void pci_remove(struct pci_dev *dev)
3382 ohci = pci_get_drvdata(dev); 3612 ohci = pci_get_drvdata(dev);
3383 reg_write(ohci, OHCI1394_IntMaskClear, ~0); 3613 reg_write(ohci, OHCI1394_IntMaskClear, ~0);
3384 flush_writes(ohci); 3614 flush_writes(ohci);
3615 cancel_work_sync(&ohci->bus_reset_work);
3385 fw_core_remove_card(&ohci->card); 3616 fw_core_remove_card(&ohci->card);
3386 3617
3387 /* 3618 /*
diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c
index 17cef864506a..68375bc3aef6 100644
--- a/drivers/firewire/sbp2.c
+++ b/drivers/firewire/sbp2.c
@@ -154,12 +154,16 @@ struct sbp2_logical_unit {
154 bool blocked; 154 bool blocked;
155}; 155};
156 156
157static void sbp2_queue_work(struct sbp2_logical_unit *lu, unsigned long delay)
158{
159 queue_delayed_work(fw_workqueue, &lu->work, delay);
160}
161
157/* 162/*
158 * We create one struct sbp2_target per IEEE 1212 Unit Directory 163 * We create one struct sbp2_target per IEEE 1212 Unit Directory
159 * and one struct Scsi_Host per sbp2_target. 164 * and one struct Scsi_Host per sbp2_target.
160 */ 165 */
161struct sbp2_target { 166struct sbp2_target {
162 struct kref kref;
163 struct fw_unit *unit; 167 struct fw_unit *unit;
164 const char *bus_id; 168 const char *bus_id;
165 struct list_head lu_list; 169 struct list_head lu_list;
@@ -772,71 +776,6 @@ static int sbp2_lun2int(u16 lun)
772 return scsilun_to_int(&eight_bytes_lun); 776 return scsilun_to_int(&eight_bytes_lun);
773} 777}
774 778
775static void sbp2_release_target(struct kref *kref)
776{
777 struct sbp2_target *tgt = container_of(kref, struct sbp2_target, kref);
778 struct sbp2_logical_unit *lu, *next;
779 struct Scsi_Host *shost =
780 container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
781 struct scsi_device *sdev;
782 struct fw_device *device = target_device(tgt);
783
784 /* prevent deadlocks */
785 sbp2_unblock(tgt);
786
787 list_for_each_entry_safe(lu, next, &tgt->lu_list, link) {
788 sdev = scsi_device_lookup(shost, 0, 0, sbp2_lun2int(lu->lun));
789 if (sdev) {
790 scsi_remove_device(sdev);
791 scsi_device_put(sdev);
792 }
793 if (lu->login_id != INVALID_LOGIN_ID) {
794 int generation, node_id;
795 /*
796 * tgt->node_id may be obsolete here if we failed
797 * during initial login or after a bus reset where
798 * the topology changed.
799 */
800 generation = device->generation;
801 smp_rmb(); /* node_id vs. generation */
802 node_id = device->node_id;
803 sbp2_send_management_orb(lu, node_id, generation,
804 SBP2_LOGOUT_REQUEST,
805 lu->login_id, NULL);
806 }
807 fw_core_remove_address_handler(&lu->address_handler);
808 list_del(&lu->link);
809 kfree(lu);
810 }
811 scsi_remove_host(shost);
812 fw_notify("released %s, target %d:0:0\n", tgt->bus_id, shost->host_no);
813
814 fw_unit_put(tgt->unit);
815 scsi_host_put(shost);
816 fw_device_put(device);
817}
818
819static void sbp2_target_get(struct sbp2_target *tgt)
820{
821 kref_get(&tgt->kref);
822}
823
824static void sbp2_target_put(struct sbp2_target *tgt)
825{
826 kref_put(&tgt->kref, sbp2_release_target);
827}
828
829/*
830 * Always get the target's kref when scheduling work on one its units.
831 * Each workqueue job is responsible to call sbp2_target_put() upon return.
832 */
833static void sbp2_queue_work(struct sbp2_logical_unit *lu, unsigned long delay)
834{
835 sbp2_target_get(lu->tgt);
836 if (!queue_delayed_work(fw_workqueue, &lu->work, delay))
837 sbp2_target_put(lu->tgt);
838}
839
840/* 779/*
841 * Write retransmit retry values into the BUSY_TIMEOUT register. 780 * Write retransmit retry values into the BUSY_TIMEOUT register.
842 * - The single-phase retry protocol is supported by all SBP-2 devices, but the 781 * - The single-phase retry protocol is supported by all SBP-2 devices, but the
@@ -877,7 +816,7 @@ static void sbp2_login(struct work_struct *work)
877 int generation, node_id, local_node_id; 816 int generation, node_id, local_node_id;
878 817
879 if (fw_device_is_shutdown(device)) 818 if (fw_device_is_shutdown(device))
880 goto out; 819 return;
881 820
882 generation = device->generation; 821 generation = device->generation;
883 smp_rmb(); /* node IDs must not be older than generation */ 822 smp_rmb(); /* node IDs must not be older than generation */
@@ -899,7 +838,7 @@ static void sbp2_login(struct work_struct *work)
899 /* Let any waiting I/O fail from now on. */ 838 /* Let any waiting I/O fail from now on. */
900 sbp2_unblock(lu->tgt); 839 sbp2_unblock(lu->tgt);
901 } 840 }
902 goto out; 841 return;
903 } 842 }
904 843
905 tgt->node_id = node_id; 844 tgt->node_id = node_id;
@@ -925,7 +864,8 @@ static void sbp2_login(struct work_struct *work)
925 if (lu->has_sdev) { 864 if (lu->has_sdev) {
926 sbp2_cancel_orbs(lu); 865 sbp2_cancel_orbs(lu);
927 sbp2_conditionally_unblock(lu); 866 sbp2_conditionally_unblock(lu);
928 goto out; 867
868 return;
929 } 869 }
930 870
931 if (lu->tgt->workarounds & SBP2_WORKAROUND_DELAY_INQUIRY) 871 if (lu->tgt->workarounds & SBP2_WORKAROUND_DELAY_INQUIRY)
@@ -957,7 +897,8 @@ static void sbp2_login(struct work_struct *work)
957 lu->has_sdev = true; 897 lu->has_sdev = true;
958 scsi_device_put(sdev); 898 scsi_device_put(sdev);
959 sbp2_allow_block(lu); 899 sbp2_allow_block(lu);
960 goto out; 900
901 return;
961 902
962 out_logout_login: 903 out_logout_login:
963 smp_rmb(); /* generation may have changed */ 904 smp_rmb(); /* generation may have changed */
@@ -971,8 +912,57 @@ static void sbp2_login(struct work_struct *work)
971 * lu->work already. Reset the work from reconnect to login. 912 * lu->work already. Reset the work from reconnect to login.
972 */ 913 */
973 PREPARE_DELAYED_WORK(&lu->work, sbp2_login); 914 PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
974 out: 915}
975 sbp2_target_put(tgt); 916
917static void sbp2_reconnect(struct work_struct *work)
918{
919 struct sbp2_logical_unit *lu =
920 container_of(work, struct sbp2_logical_unit, work.work);
921 struct sbp2_target *tgt = lu->tgt;
922 struct fw_device *device = target_device(tgt);
923 int generation, node_id, local_node_id;
924
925 if (fw_device_is_shutdown(device))
926 return;
927
928 generation = device->generation;
929 smp_rmb(); /* node IDs must not be older than generation */
930 node_id = device->node_id;
931 local_node_id = device->card->node_id;
932
933 if (sbp2_send_management_orb(lu, node_id, generation,
934 SBP2_RECONNECT_REQUEST,
935 lu->login_id, NULL) < 0) {
936 /*
937 * If reconnect was impossible even though we are in the
938 * current generation, fall back and try to log in again.
939 *
940 * We could check for "Function rejected" status, but
941 * looking at the bus generation as simpler and more general.
942 */
943 smp_rmb(); /* get current card generation */
944 if (generation == device->card->generation ||
945 lu->retries++ >= 5) {
946 fw_error("%s: failed to reconnect\n", tgt->bus_id);
947 lu->retries = 0;
948 PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
949 }
950 sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
951
952 return;
953 }
954
955 tgt->node_id = node_id;
956 tgt->address_high = local_node_id << 16;
957 smp_wmb(); /* node IDs must not be older than generation */
958 lu->generation = generation;
959
960 fw_notify("%s: reconnected to LUN %04x (%d retries)\n",
961 tgt->bus_id, lu->lun, lu->retries);
962
963 sbp2_agent_reset(lu);
964 sbp2_cancel_orbs(lu);
965 sbp2_conditionally_unblock(lu);
976} 966}
977 967
978static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry) 968static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
@@ -1120,6 +1110,7 @@ static void sbp2_init_workarounds(struct sbp2_target *tgt, u32 model,
1120} 1110}
1121 1111
1122static struct scsi_host_template scsi_driver_template; 1112static struct scsi_host_template scsi_driver_template;
1113static int sbp2_remove(struct device *dev);
1123 1114
1124static int sbp2_probe(struct device *dev) 1115static int sbp2_probe(struct device *dev)
1125{ 1116{
@@ -1141,7 +1132,6 @@ static int sbp2_probe(struct device *dev)
1141 tgt = (struct sbp2_target *)shost->hostdata; 1132 tgt = (struct sbp2_target *)shost->hostdata;
1142 dev_set_drvdata(&unit->device, tgt); 1133 dev_set_drvdata(&unit->device, tgt);
1143 tgt->unit = unit; 1134 tgt->unit = unit;
1144 kref_init(&tgt->kref);
1145 INIT_LIST_HEAD(&tgt->lu_list); 1135 INIT_LIST_HEAD(&tgt->lu_list);
1146 tgt->bus_id = dev_name(&unit->device); 1136 tgt->bus_id = dev_name(&unit->device);
1147 tgt->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; 1137 tgt->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4];
@@ -1154,9 +1144,6 @@ static int sbp2_probe(struct device *dev)
1154 if (scsi_add_host(shost, &unit->device) < 0) 1144 if (scsi_add_host(shost, &unit->device) < 0)
1155 goto fail_shost_put; 1145 goto fail_shost_put;
1156 1146
1157 fw_device_get(device);
1158 fw_unit_get(unit);
1159
1160 /* implicit directory ID */ 1147 /* implicit directory ID */
1161 tgt->directory_id = ((unit->directory - device->config_rom) * 4 1148 tgt->directory_id = ((unit->directory - device->config_rom) * 4
1162 + CSR_CONFIG_ROM) & 0xffffff; 1149 + CSR_CONFIG_ROM) & 0xffffff;
@@ -1166,7 +1153,7 @@ static int sbp2_probe(struct device *dev)
1166 1153
1167 if (sbp2_scan_unit_dir(tgt, unit->directory, &model, 1154 if (sbp2_scan_unit_dir(tgt, unit->directory, &model,
1168 &firmware_revision) < 0) 1155 &firmware_revision) < 0)
1169 goto fail_tgt_put; 1156 goto fail_remove;
1170 1157
1171 sbp2_clamp_management_orb_timeout(tgt); 1158 sbp2_clamp_management_orb_timeout(tgt);
1172 sbp2_init_workarounds(tgt, model, firmware_revision); 1159 sbp2_init_workarounds(tgt, model, firmware_revision);
@@ -1177,16 +1164,17 @@ static int sbp2_probe(struct device *dev)
1177 * specifies the max payload size as 2 ^ (max_payload + 2), so 1164 * specifies the max payload size as 2 ^ (max_payload + 2), so
1178 * if we set this to max_speed + 7, we get the right value. 1165 * if we set this to max_speed + 7, we get the right value.
1179 */ 1166 */
1180 tgt->max_payload = min(device->max_speed + 7, 10U); 1167 tgt->max_payload = min3(device->max_speed + 7, 10U,
1181 tgt->max_payload = min(tgt->max_payload, device->card->max_receive - 1); 1168 device->card->max_receive - 1);
1182 1169
1183 /* Do the login in a workqueue so we can easily reschedule retries. */ 1170 /* Do the login in a workqueue so we can easily reschedule retries. */
1184 list_for_each_entry(lu, &tgt->lu_list, link) 1171 list_for_each_entry(lu, &tgt->lu_list, link)
1185 sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5)); 1172 sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
1173
1186 return 0; 1174 return 0;
1187 1175
1188 fail_tgt_put: 1176 fail_remove:
1189 sbp2_target_put(tgt); 1177 sbp2_remove(dev);
1190 return -ENOMEM; 1178 return -ENOMEM;
1191 1179
1192 fail_shost_put: 1180 fail_shost_put:
@@ -1194,71 +1182,6 @@ static int sbp2_probe(struct device *dev)
1194 return -ENOMEM; 1182 return -ENOMEM;
1195} 1183}
1196 1184
1197static int sbp2_remove(struct device *dev)
1198{
1199 struct fw_unit *unit = fw_unit(dev);
1200 struct sbp2_target *tgt = dev_get_drvdata(&unit->device);
1201 struct sbp2_logical_unit *lu;
1202
1203 list_for_each_entry(lu, &tgt->lu_list, link)
1204 cancel_delayed_work_sync(&lu->work);
1205
1206 sbp2_target_put(tgt);
1207 return 0;
1208}
1209
1210static void sbp2_reconnect(struct work_struct *work)
1211{
1212 struct sbp2_logical_unit *lu =
1213 container_of(work, struct sbp2_logical_unit, work.work);
1214 struct sbp2_target *tgt = lu->tgt;
1215 struct fw_device *device = target_device(tgt);
1216 int generation, node_id, local_node_id;
1217
1218 if (fw_device_is_shutdown(device))
1219 goto out;
1220
1221 generation = device->generation;
1222 smp_rmb(); /* node IDs must not be older than generation */
1223 node_id = device->node_id;
1224 local_node_id = device->card->node_id;
1225
1226 if (sbp2_send_management_orb(lu, node_id, generation,
1227 SBP2_RECONNECT_REQUEST,
1228 lu->login_id, NULL) < 0) {
1229 /*
1230 * If reconnect was impossible even though we are in the
1231 * current generation, fall back and try to log in again.
1232 *
1233 * We could check for "Function rejected" status, but
1234 * looking at the bus generation as simpler and more general.
1235 */
1236 smp_rmb(); /* get current card generation */
1237 if (generation == device->card->generation ||
1238 lu->retries++ >= 5) {
1239 fw_error("%s: failed to reconnect\n", tgt->bus_id);
1240 lu->retries = 0;
1241 PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
1242 }
1243 sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
1244 goto out;
1245 }
1246
1247 tgt->node_id = node_id;
1248 tgt->address_high = local_node_id << 16;
1249 smp_wmb(); /* node IDs must not be older than generation */
1250 lu->generation = generation;
1251
1252 fw_notify("%s: reconnected to LUN %04x (%d retries)\n",
1253 tgt->bus_id, lu->lun, lu->retries);
1254
1255 sbp2_agent_reset(lu);
1256 sbp2_cancel_orbs(lu);
1257 sbp2_conditionally_unblock(lu);
1258 out:
1259 sbp2_target_put(tgt);
1260}
1261
1262static void sbp2_update(struct fw_unit *unit) 1185static void sbp2_update(struct fw_unit *unit)
1263{ 1186{
1264 struct sbp2_target *tgt = dev_get_drvdata(&unit->device); 1187 struct sbp2_target *tgt = dev_get_drvdata(&unit->device);
@@ -1277,6 +1200,51 @@ static void sbp2_update(struct fw_unit *unit)
1277 } 1200 }
1278} 1201}
1279 1202
1203static int sbp2_remove(struct device *dev)
1204{
1205 struct fw_unit *unit = fw_unit(dev);
1206 struct fw_device *device = fw_parent_device(unit);
1207 struct sbp2_target *tgt = dev_get_drvdata(&unit->device);
1208 struct sbp2_logical_unit *lu, *next;
1209 struct Scsi_Host *shost =
1210 container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
1211 struct scsi_device *sdev;
1212
1213 /* prevent deadlocks */
1214 sbp2_unblock(tgt);
1215
1216 list_for_each_entry_safe(lu, next, &tgt->lu_list, link) {
1217 cancel_delayed_work_sync(&lu->work);
1218 sdev = scsi_device_lookup(shost, 0, 0, sbp2_lun2int(lu->lun));
1219 if (sdev) {
1220 scsi_remove_device(sdev);
1221 scsi_device_put(sdev);
1222 }
1223 if (lu->login_id != INVALID_LOGIN_ID) {
1224 int generation, node_id;
1225 /*
1226 * tgt->node_id may be obsolete here if we failed
1227 * during initial login or after a bus reset where
1228 * the topology changed.
1229 */
1230 generation = device->generation;
1231 smp_rmb(); /* node_id vs. generation */
1232 node_id = device->node_id;
1233 sbp2_send_management_orb(lu, node_id, generation,
1234 SBP2_LOGOUT_REQUEST,
1235 lu->login_id, NULL);
1236 }
1237 fw_core_remove_address_handler(&lu->address_handler);
1238 list_del(&lu->link);
1239 kfree(lu);
1240 }
1241 scsi_remove_host(shost);
1242 fw_notify("released %s, target %d:0:0\n", tgt->bus_id, shost->host_no);
1243
1244 scsi_host_put(shost);
1245 return 0;
1246}
1247
1280#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e 1248#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
1281#define SBP2_SW_VERSION_ENTRY 0x00010483 1249#define SBP2_SW_VERSION_ENTRY 0x00010483
1282 1250