aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2006-06-20 23:01:16 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-20 23:01:16 -0400
commit34641a58a227e498adf471ab016bd054cc399d7e (patch)
treeda1e0af965d06d0c6e13c546ac01f6a54a904d86
parent2eec0e0842ef747027eb9181d5f50d7157184d57 (diff)
parent7136b8073f0123918e3e50269ae021bbb09e1a81 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bcollins/linux1394-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/bcollins/linux1394-2.6: (28 commits) eth1394: replace __constant_htons by htons ieee1394: adjust code formatting in highlevel.c ieee1394: hl_irqs_lock is taken in hardware interrupt context ieee1394_core: switch to kthread API ieee1394: sbp2: Kconfig fix ieee1394: add preprocessor constant for invalid csr address sbp2: fix deregistration of status fifo address space [PATCH] eth1394: endian fixes Fix broken suspend/resume in ohci1394 sbp2: use __attribute__((packed)) for on-the-wire structures sbp2: provide helptext for CONFIG_IEEE1394_SBP2_PHYS_DMA and mark it experimental Update feature removal of obsolete raw1394 ISO requests. sbp2: fix S800 transfers if phys_dma is off sbp2: remove ohci1394 specific constant ohci1394: make phys_dma parameter read-only ohci1394: set address range properties ieee1394: extend lowlevel API for address range properties sbp2: log number of supported concurrent logins sbp2: remove manipulation of inquiry response ieee1394: save RAM by using a single tlabel for broadcast transactions ...
-rw-r--r--Documentation/feature-removal-schedule.txt4
-rw-r--r--drivers/ieee1394/Kconfig13
-rw-r--r--drivers/ieee1394/csr1212.c2
-rw-r--r--drivers/ieee1394/csr1212.h1
-rw-r--r--drivers/ieee1394/dma.c18
-rw-r--r--drivers/ieee1394/eth1394.c51
-rw-r--r--drivers/ieee1394/eth1394.h2
-rw-r--r--drivers/ieee1394/highlevel.c445
-rw-r--r--drivers/ieee1394/hosts.c7
-rw-r--r--drivers/ieee1394/hosts.h17
-rw-r--r--drivers/ieee1394/ieee1394_core.c62
-rw-r--r--drivers/ieee1394/ieee1394_transactions.c10
-rw-r--r--drivers/ieee1394/nodemgr.c61
-rw-r--r--drivers/ieee1394/ohci1394.c37
-rw-r--r--drivers/ieee1394/ohci1394.h10
-rw-r--r--drivers/ieee1394/raw1394.c54
-rw-r--r--drivers/ieee1394/sbp2.c85
-rw-r--r--drivers/ieee1394/sbp2.h23
-rw-r--r--drivers/ieee1394/video1394.c16
19 files changed, 462 insertions, 456 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index f50cf8fac3f0..f7293297f326 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -49,11 +49,11 @@ Who: Paul E. McKenney <paulmck@us.ibm.com>
49--------------------------- 49---------------------------
50 50
51What: raw1394: requests of type RAW1394_REQ_ISO_SEND, RAW1394_REQ_ISO_LISTEN 51What: raw1394: requests of type RAW1394_REQ_ISO_SEND, RAW1394_REQ_ISO_LISTEN
52When: November 2005 52When: November 2006
53Why: Deprecated in favour of the new ioctl-based rawiso interface, which is 53Why: Deprecated in favour of the new ioctl-based rawiso interface, which is
54 more efficient. You should really be using libraw1394 for raw1394 54 more efficient. You should really be using libraw1394 for raw1394
55 access anyway. 55 access anyway.
56Who: Jody McIntyre <scjody@steamballoon.com> 56Who: Jody McIntyre <scjody@modernduck.com>
57 57
58--------------------------- 58---------------------------
59 59
diff --git a/drivers/ieee1394/Kconfig b/drivers/ieee1394/Kconfig
index 39142e2f804b..186737539cf5 100644
--- a/drivers/ieee1394/Kconfig
+++ b/drivers/ieee1394/Kconfig
@@ -128,8 +128,17 @@ config IEEE1394_SBP2
128 1394 bus. SBP-2 devices include harddrives and DVD devices. 128 1394 bus. SBP-2 devices include harddrives and DVD devices.
129 129
130config IEEE1394_SBP2_PHYS_DMA 130config IEEE1394_SBP2_PHYS_DMA
131 bool "Enable Phys DMA support for SBP2 (Debug)" 131 bool "Enable replacement for physical DMA in SBP2"
132 depends on IEEE1394 && IEEE1394_SBP2 132 depends on IEEE1394 && IEEE1394_SBP2 && EXPERIMENTAL && (X86_32 || PPC_32)
133 help
134 This builds sbp2 for use with non-OHCI host adapters which do not
135 support physical DMA or for when ohci1394 is run with phys_dma=0.
136 Physical DMA is data movement without assistence of the drivers'
137 interrupt handlers. This option includes the interrupt handlers
138 that are required in absence of this hardware feature.
139
140 This option is buggy and currently broken on some architectures.
141 If unsure, say N.
133 142
134config IEEE1394_ETH1394 143config IEEE1394_ETH1394
135 tristate "Ethernet over 1394" 144 tristate "Ethernet over 1394"
diff --git a/drivers/ieee1394/csr1212.c b/drivers/ieee1394/csr1212.c
index 15773544234b..586f71e7346a 100644
--- a/drivers/ieee1394/csr1212.c
+++ b/drivers/ieee1394/csr1212.c
@@ -779,7 +779,7 @@ static int csr1212_append_new_cache(struct csr1212_csr *csr, size_t romsize)
779 romsize = (romsize + (csr->max_rom - 1)) & ~(csr->max_rom - 1); 779 romsize = (romsize + (csr->max_rom - 1)) & ~(csr->max_rom - 1);
780 780
781 csr_addr = csr->ops->allocate_addr_range(romsize, csr->max_rom, csr->private); 781 csr_addr = csr->ops->allocate_addr_range(romsize, csr->max_rom, csr->private);
782 if (csr_addr == ~0ULL) { 782 if (csr_addr == CSR1212_INVALID_ADDR_SPACE) {
783 return CSR1212_ENOMEM; 783 return CSR1212_ENOMEM;
784 } 784 }
785 if (csr_addr < CSR1212_REGISTER_SPACE_BASE) { 785 if (csr_addr < CSR1212_REGISTER_SPACE_BASE) {
diff --git a/drivers/ieee1394/csr1212.h b/drivers/ieee1394/csr1212.h
index cecd5871f2de..17ddd72dee4e 100644
--- a/drivers/ieee1394/csr1212.h
+++ b/drivers/ieee1394/csr1212.h
@@ -192,6 +192,7 @@
192 192
193#define CSR1212_EXTENDED_ROM_SIZE (0x10000 * sizeof(u_int32_t)) 193#define CSR1212_EXTENDED_ROM_SIZE (0x10000 * sizeof(u_int32_t))
194 194
195#define CSR1212_INVALID_ADDR_SPACE -1
195 196
196/* Config ROM image structures */ 197/* Config ROM image structures */
197struct csr1212_bus_info_block_img { 198struct csr1212_bus_info_block_img {
diff --git a/drivers/ieee1394/dma.c b/drivers/ieee1394/dma.c
index 9fb2769d9abc..ca5167de707d 100644
--- a/drivers/ieee1394/dma.c
+++ b/drivers/ieee1394/dma.c
@@ -145,12 +145,12 @@ void dma_region_free(struct dma_region *dma)
145/* find the scatterlist index and remaining offset corresponding to a 145/* find the scatterlist index and remaining offset corresponding to a
146 given offset from the beginning of the buffer */ 146 given offset from the beginning of the buffer */
147static inline int dma_region_find(struct dma_region *dma, unsigned long offset, 147static inline int dma_region_find(struct dma_region *dma, unsigned long offset,
148 unsigned long *rem) 148 unsigned int start, unsigned long *rem)
149{ 149{
150 int i; 150 int i;
151 unsigned long off = offset; 151 unsigned long off = offset;
152 152
153 for (i = 0; i < dma->n_dma_pages; i++) { 153 for (i = start; i < dma->n_dma_pages; i++) {
154 if (off < sg_dma_len(&dma->sglist[i])) { 154 if (off < sg_dma_len(&dma->sglist[i])) {
155 *rem = off; 155 *rem = off;
156 break; 156 break;
@@ -170,7 +170,7 @@ dma_addr_t dma_region_offset_to_bus(struct dma_region * dma,
170 unsigned long rem = 0; 170 unsigned long rem = 0;
171 171
172 struct scatterlist *sg = 172 struct scatterlist *sg =
173 &dma->sglist[dma_region_find(dma, offset, &rem)]; 173 &dma->sglist[dma_region_find(dma, offset, 0, &rem)];
174 return sg_dma_address(sg) + rem; 174 return sg_dma_address(sg) + rem;
175} 175}
176 176
@@ -178,13 +178,13 @@ void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset,
178 unsigned long len) 178 unsigned long len)
179{ 179{
180 int first, last; 180 int first, last;
181 unsigned long rem; 181 unsigned long rem = 0;
182 182
183 if (!len) 183 if (!len)
184 len = 1; 184 len = 1;
185 185
186 first = dma_region_find(dma, offset, &rem); 186 first = dma_region_find(dma, offset, 0, &rem);
187 last = dma_region_find(dma, offset + len - 1, &rem); 187 last = dma_region_find(dma, rem + len - 1, first, &rem);
188 188
189 pci_dma_sync_sg_for_cpu(dma->dev, &dma->sglist[first], last - first + 1, 189 pci_dma_sync_sg_for_cpu(dma->dev, &dma->sglist[first], last - first + 1,
190 dma->direction); 190 dma->direction);
@@ -194,13 +194,13 @@ void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset,
194 unsigned long len) 194 unsigned long len)
195{ 195{
196 int first, last; 196 int first, last;
197 unsigned long rem; 197 unsigned long rem = 0;
198 198
199 if (!len) 199 if (!len)
200 len = 1; 200 len = 1;
201 201
202 first = dma_region_find(dma, offset, &rem); 202 first = dma_region_find(dma, offset, 0, &rem);
203 last = dma_region_find(dma, offset + len - 1, &rem); 203 last = dma_region_find(dma, rem + len - 1, first, &rem);
204 204
205 pci_dma_sync_sg_for_device(dma->dev, &dma->sglist[first], 205 pci_dma_sync_sg_for_device(dma->dev, &dma->sglist[first],
206 last - first + 1, dma->direction); 206 last - first + 1, dma->direction);
diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c
index 30fa0d43a43a..5bda15904a08 100644
--- a/drivers/ieee1394/eth1394.c
+++ b/drivers/ieee1394/eth1394.c
@@ -367,7 +367,7 @@ static int eth1394_probe(struct device *dev)
367 spin_lock_init(&node_info->pdg.lock); 367 spin_lock_init(&node_info->pdg.lock);
368 INIT_LIST_HEAD(&node_info->pdg.list); 368 INIT_LIST_HEAD(&node_info->pdg.list);
369 node_info->pdg.sz = 0; 369 node_info->pdg.sz = 0;
370 node_info->fifo = ETHER1394_INVALID_ADDR; 370 node_info->fifo = CSR1212_INVALID_ADDR_SPACE;
371 371
372 ud->device.driver_data = node_info; 372 ud->device.driver_data = node_info;
373 new_node->ud = ud; 373 new_node->ud = ud;
@@ -502,10 +502,8 @@ static void ether1394_reset_priv (struct net_device *dev, int set_mtu)
502 502
503 /* Determine speed limit */ 503 /* Determine speed limit */
504 for (i = 0; i < host->node_count; i++) 504 for (i = 0; i < host->node_count; i++)
505 if (max_speed > host->speed_map[NODEID_TO_NODE(host->node_id) * 505 if (max_speed > host->speed[i])
506 64 + i]) 506 max_speed = host->speed[i];
507 max_speed = host->speed_map[NODEID_TO_NODE(host->node_id) *
508 64 + i];
509 priv->bc_sspd = max_speed; 507 priv->bc_sspd = max_speed;
510 508
511 /* We'll use our maxpayload as the default mtu */ 509 /* We'll use our maxpayload as the default mtu */
@@ -568,13 +566,11 @@ static void ether1394_add_host (struct hpsb_host *host)
568 if (!(host->config_roms & HPSB_CONFIG_ROM_ENTRY_IP1394)) 566 if (!(host->config_roms & HPSB_CONFIG_ROM_ENTRY_IP1394))
569 return; 567 return;
570 568
571 fifo_addr = hpsb_allocate_and_register_addrspace(&eth1394_highlevel, 569 fifo_addr = hpsb_allocate_and_register_addrspace(
572 host, 570 &eth1394_highlevel, host, &addr_ops,
573 &addr_ops, 571 ETHER1394_REGION_ADDR_LEN, ETHER1394_REGION_ADDR_LEN,
574 ETHER1394_REGION_ADDR_LEN, 572 CSR1212_INVALID_ADDR_SPACE, CSR1212_INVALID_ADDR_SPACE);
575 ETHER1394_REGION_ADDR_LEN, 573 if (fifo_addr == CSR1212_INVALID_ADDR_SPACE)
576 -1, -1);
577 if (fifo_addr == ~0ULL)
578 goto out; 574 goto out;
579 575
580 /* We should really have our own alloc_hpsbdev() function in 576 /* We should really have our own alloc_hpsbdev() function in
@@ -774,7 +770,7 @@ static int ether1394_rebuild_header(struct sk_buff *skb)
774 default: 770 default:
775 ETH1394_PRINT(KERN_DEBUG, dev->name, 771 ETH1394_PRINT(KERN_DEBUG, dev->name,
776 "unable to resolve type %04x addresses.\n", 772 "unable to resolve type %04x addresses.\n",
777 eth->h_proto); 773 ntohs(eth->h_proto));
778 break; 774 break;
779 } 775 }
780 776
@@ -796,9 +792,8 @@ static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh)
796 (16 - ETH1394_HLEN)); 792 (16 - ETH1394_HLEN));
797 struct net_device *dev = neigh->dev; 793 struct net_device *dev = neigh->dev;
798 794
799 if (type == __constant_htons(ETH_P_802_3)) { 795 if (type == htons(ETH_P_802_3))
800 return -1; 796 return -1;
801 }
802 797
803 eth->h_proto = type; 798 eth->h_proto = type;
804 memcpy(eth->h_dest, neigh->ha, dev->addr_len); 799 memcpy(eth->h_dest, neigh->ha, dev->addr_len);
@@ -887,7 +882,7 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb,
887 /* If this is an ARP packet, convert it. First, we want to make 882 /* If this is an ARP packet, convert it. First, we want to make
888 * use of some of the fields, since they tell us a little bit 883 * use of some of the fields, since they tell us a little bit
889 * about the sending machine. */ 884 * about the sending machine. */
890 if (ether_type == __constant_htons (ETH_P_ARP)) { 885 if (ether_type == htons(ETH_P_ARP)) {
891 struct eth1394_arp *arp1394 = (struct eth1394_arp*)skb->data; 886 struct eth1394_arp *arp1394 = (struct eth1394_arp*)skb->data;
892 struct arphdr *arp = (struct arphdr *)skb->data; 887 struct arphdr *arp = (struct arphdr *)skb->data;
893 unsigned char *arp_ptr = (unsigned char *)(arp + 1); 888 unsigned char *arp_ptr = (unsigned char *)(arp + 1);
@@ -935,7 +930,7 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb,
935 *(u32*)arp_ptr = arp1394->sip; /* move sender IP addr */ 930 *(u32*)arp_ptr = arp1394->sip; /* move sender IP addr */
936 arp_ptr += arp->ar_pln; /* skip over sender IP addr */ 931 arp_ptr += arp->ar_pln; /* skip over sender IP addr */
937 932
938 if (arp->ar_op == 1) 933 if (arp->ar_op == htons(ARPOP_REQUEST))
939 /* just set ARP req target unique ID to 0 */ 934 /* just set ARP req target unique ID to 0 */
940 *((u64*)arp_ptr) = 0; 935 *((u64*)arp_ptr) = 0;
941 else 936 else
@@ -943,8 +938,8 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb,
943 } 938 }
944 939
945 /* Now add the ethernet header. */ 940 /* Now add the ethernet header. */
946 if (dev->hard_header (skb, dev, __constant_ntohs (ether_type), 941 if (dev->hard_header(skb, dev, ntohs(ether_type), &dest_hw, NULL,
947 &dest_hw, NULL, skb->len) >= 0) 942 skb->len) >= 0)
948 ret = ether1394_type_trans(skb, dev); 943 ret = ether1394_type_trans(skb, dev);
949 944
950 return ret; 945 return ret;
@@ -1395,7 +1390,7 @@ static inline void ether1394_arp_to_1394arp(struct sk_buff *skb,
1395/* We need to encapsulate the standard header with our own. We use the 1390/* We need to encapsulate the standard header with our own. We use the
1396 * ethernet header's proto for our own. */ 1391 * ethernet header's proto for our own. */
1397static inline unsigned int ether1394_encapsulate_prep(unsigned int max_payload, 1392static inline unsigned int ether1394_encapsulate_prep(unsigned int max_payload,
1398 int proto, 1393 __be16 proto,
1399 union eth1394_hdr *hdr, 1394 union eth1394_hdr *hdr,
1400 u16 dg_size, u16 dgl) 1395 u16 dg_size, u16 dgl)
1401{ 1396{
@@ -1514,8 +1509,8 @@ static inline void ether1394_prep_gasp_packet(struct hpsb_packet *p,
1514 p->data = ((quadlet_t*)skb->data) - 2; 1509 p->data = ((quadlet_t*)skb->data) - 2;
1515 p->data[0] = cpu_to_be32((priv->host->node_id << 16) | 1510 p->data[0] = cpu_to_be32((priv->host->node_id << 16) |
1516 ETHER1394_GASP_SPECIFIER_ID_HI); 1511 ETHER1394_GASP_SPECIFIER_ID_HI);
1517 p->data[1] = __constant_cpu_to_be32((ETHER1394_GASP_SPECIFIER_ID_LO << 24) | 1512 p->data[1] = cpu_to_be32((ETHER1394_GASP_SPECIFIER_ID_LO << 24) |
1518 ETHER1394_GASP_VERSION); 1513 ETHER1394_GASP_VERSION);
1519 1514
1520 /* Setting the node id to ALL_NODES (not LOCAL_BUS | ALL_NODES) 1515 /* Setting the node id to ALL_NODES (not LOCAL_BUS | ALL_NODES)
1521 * prevents hpsb_send_packet() from setting the speed to an arbitrary 1516 * prevents hpsb_send_packet() from setting the speed to an arbitrary
@@ -1626,7 +1621,7 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev)
1626 gfp_t kmflags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; 1621 gfp_t kmflags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
1627 struct eth1394hdr *eth; 1622 struct eth1394hdr *eth;
1628 struct eth1394_priv *priv = netdev_priv(dev); 1623 struct eth1394_priv *priv = netdev_priv(dev);
1629 int proto; 1624 __be16 proto;
1630 unsigned long flags; 1625 unsigned long flags;
1631 nodeid_t dest_node; 1626 nodeid_t dest_node;
1632 eth1394_tx_type tx_type; 1627 eth1394_tx_type tx_type;
@@ -1670,9 +1665,9 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev)
1670 /* Set the transmission type for the packet. ARP packets and IP 1665 /* Set the transmission type for the packet. ARP packets and IP
1671 * broadcast packets are sent via GASP. */ 1666 * broadcast packets are sent via GASP. */
1672 if (memcmp(eth->h_dest, dev->broadcast, ETH1394_ALEN) == 0 || 1667 if (memcmp(eth->h_dest, dev->broadcast, ETH1394_ALEN) == 0 ||
1673 proto == __constant_htons(ETH_P_ARP) || 1668 proto == htons(ETH_P_ARP) ||
1674 (proto == __constant_htons(ETH_P_IP) && 1669 (proto == htons(ETH_P_IP) &&
1675 IN_MULTICAST(__constant_ntohl(skb->nh.iph->daddr)))) { 1670 IN_MULTICAST(ntohl(skb->nh.iph->daddr)))) {
1676 tx_type = ETH1394_GASP; 1671 tx_type = ETH1394_GASP;
1677 dest_node = LOCAL_BUS | ALL_NODES; 1672 dest_node = LOCAL_BUS | ALL_NODES;
1678 max_payload = priv->bc_maxpayload - ETHER1394_GASP_OVERHEAD; 1673 max_payload = priv->bc_maxpayload - ETHER1394_GASP_OVERHEAD;
@@ -1688,7 +1683,7 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev)
1688 goto fail; 1683 goto fail;
1689 } 1684 }
1690 node_info = (struct eth1394_node_info*)node->ud->device.driver_data; 1685 node_info = (struct eth1394_node_info*)node->ud->device.driver_data;
1691 if (node_info->fifo == ETHER1394_INVALID_ADDR) { 1686 if (node_info->fifo == CSR1212_INVALID_ADDR_SPACE) {
1692 ret = -EAGAIN; 1687 ret = -EAGAIN;
1693 goto fail; 1688 goto fail;
1694 } 1689 }
@@ -1704,7 +1699,7 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev)
1704 } 1699 }
1705 1700
1706 /* If this is an ARP packet, convert it */ 1701 /* If this is an ARP packet, convert it */
1707 if (proto == __constant_htons (ETH_P_ARP)) 1702 if (proto == htons(ETH_P_ARP))
1708 ether1394_arp_to_1394arp (skb, dev); 1703 ether1394_arp_to_1394arp (skb, dev);
1709 1704
1710 ptask->hdr.words.word1 = 0; 1705 ptask->hdr.words.word1 = 0;
diff --git a/drivers/ieee1394/eth1394.h b/drivers/ieee1394/eth1394.h
index a77213cfc483..c45cbff9138d 100644
--- a/drivers/ieee1394/eth1394.h
+++ b/drivers/ieee1394/eth1394.h
@@ -32,8 +32,6 @@
32 * S3200 (per Table 16-3 of IEEE 1394b-2002). */ 32 * S3200 (per Table 16-3 of IEEE 1394b-2002). */
33#define ETHER1394_REGION_ADDR_LEN 4096 33#define ETHER1394_REGION_ADDR_LEN 4096
34 34
35#define ETHER1394_INVALID_ADDR ~0ULL
36
37/* GASP identifier numbers for IPv4 over IEEE 1394 */ 35/* GASP identifier numbers for IPv4 over IEEE 1394 */
38#define ETHER1394_GASP_SPECIFIER_ID 0x00005E 36#define ETHER1394_GASP_SPECIFIER_ID 0x00005E
39#define ETHER1394_GASP_SPECIFIER_ID_HI ((ETHER1394_GASP_SPECIFIER_ID >> 8) & 0xffff) 37#define ETHER1394_GASP_SPECIFIER_ID_HI ((ETHER1394_GASP_SPECIFIER_ID >> 8) & 0xffff)
diff --git a/drivers/ieee1394/highlevel.c b/drivers/ieee1394/highlevel.c
index 491e6032bdec..25b22609e793 100644
--- a/drivers/ieee1394/highlevel.c
+++ b/drivers/ieee1394/highlevel.c
@@ -53,7 +53,7 @@ static struct hpsb_address_serve dummy_zero_addr, dummy_max_addr;
53 53
54 54
55static struct hl_host_info *hl_get_hostinfo(struct hpsb_highlevel *hl, 55static struct hl_host_info *hl_get_hostinfo(struct hpsb_highlevel *hl,
56 struct hpsb_host *host) 56 struct hpsb_host *host)
57{ 57{
58 struct hl_host_info *hi = NULL; 58 struct hl_host_info *hi = NULL;
59 59
@@ -68,24 +68,18 @@ static struct hl_host_info *hl_get_hostinfo(struct hpsb_highlevel *hl,
68 } 68 }
69 } 69 }
70 read_unlock(&hl->host_info_lock); 70 read_unlock(&hl->host_info_lock);
71
72 return NULL; 71 return NULL;
73} 72}
74 73
75
76/* Returns a per host/driver data structure that was previously stored by 74/* Returns a per host/driver data structure that was previously stored by
77 * hpsb_create_hostinfo. */ 75 * hpsb_create_hostinfo. */
78void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host) 76void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host)
79{ 77{
80 struct hl_host_info *hi = hl_get_hostinfo(hl, host); 78 struct hl_host_info *hi = hl_get_hostinfo(hl, host);
81 79
82 if (hi) 80 return hi ? hi->data : NULL;
83 return hi->data;
84
85 return NULL;
86} 81}
87 82
88
89/* If size is zero, then the return here is only valid for error checking */ 83/* If size is zero, then the return here is only valid for error checking */
90void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, 84void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
91 size_t data_size) 85 size_t data_size)
@@ -96,8 +90,8 @@ void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
96 90
97 hi = hl_get_hostinfo(hl, host); 91 hi = hl_get_hostinfo(hl, host);
98 if (hi) { 92 if (hi) {
99 HPSB_ERR("%s called hpsb_create_hostinfo when hostinfo already exists", 93 HPSB_ERR("%s called hpsb_create_hostinfo when hostinfo already"
100 hl->name); 94 " exists", hl->name);
101 return NULL; 95 return NULL;
102 } 96 }
103 97
@@ -120,7 +114,6 @@ void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
120 return data; 114 return data;
121} 115}
122 116
123
124int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, 117int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
125 void *data) 118 void *data)
126{ 119{
@@ -132,16 +125,14 @@ int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
132 hi->data = data; 125 hi->data = data;
133 return 0; 126 return 0;
134 } else 127 } else
135 HPSB_ERR("%s called hpsb_set_hostinfo when hostinfo already has data", 128 HPSB_ERR("%s called hpsb_set_hostinfo when hostinfo "
136 hl->name); 129 "already has data", hl->name);
137 } else 130 } else
138 HPSB_ERR("%s called hpsb_set_hostinfo when no hostinfo exists", 131 HPSB_ERR("%s called hpsb_set_hostinfo when no hostinfo exists",
139 hl->name); 132 hl->name);
140
141 return -EINVAL; 133 return -EINVAL;
142} 134}
143 135
144
145void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host) 136void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host)
146{ 137{
147 struct hl_host_info *hi; 138 struct hl_host_info *hi;
@@ -154,23 +145,20 @@ void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host)
154 write_unlock_irqrestore(&hl->host_info_lock, flags); 145 write_unlock_irqrestore(&hl->host_info_lock, flags);
155 kfree(hi); 146 kfree(hi);
156 } 147 }
157
158 return; 148 return;
159} 149}
160 150
161 151void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host,
162void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host, unsigned long key) 152 unsigned long key)
163{ 153{
164 struct hl_host_info *hi; 154 struct hl_host_info *hi;
165 155
166 hi = hl_get_hostinfo(hl, host); 156 hi = hl_get_hostinfo(hl, host);
167 if (hi) 157 if (hi)
168 hi->key = key; 158 hi->key = key;
169
170 return; 159 return;
171} 160}
172 161
173
174void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key) 162void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key)
175{ 163{
176 struct hl_host_info *hi; 164 struct hl_host_info *hi;
@@ -187,46 +175,41 @@ void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key)
187 } 175 }
188 } 176 }
189 read_unlock(&hl->host_info_lock); 177 read_unlock(&hl->host_info_lock);
190
191 return data; 178 return data;
192} 179}
193 180
194
195static int highlevel_for_each_host_reg(struct hpsb_host *host, void *__data) 181static int highlevel_for_each_host_reg(struct hpsb_host *host, void *__data)
196{ 182{
197 struct hpsb_highlevel *hl = __data; 183 struct hpsb_highlevel *hl = __data;
198 184
199 hl->add_host(host); 185 hl->add_host(host);
200 186
201 if (host->update_config_rom) { 187 if (host->update_config_rom && hpsb_update_config_rom_image(host) < 0)
202 if (hpsb_update_config_rom_image(host) < 0) { 188 HPSB_ERR("Failed to generate Configuration ROM image for host "
203 HPSB_ERR("Failed to generate Configuration ROM image for host " 189 "%s-%d", hl->name, host->id);
204 "%s-%d", hl->name, host->id);
205 }
206 }
207
208 return 0; 190 return 0;
209} 191}
210 192
211void hpsb_register_highlevel(struct hpsb_highlevel *hl) 193void hpsb_register_highlevel(struct hpsb_highlevel *hl)
212{ 194{
213 INIT_LIST_HEAD(&hl->addr_list); 195 unsigned long flags;
196
197 INIT_LIST_HEAD(&hl->addr_list);
214 INIT_LIST_HEAD(&hl->host_info_list); 198 INIT_LIST_HEAD(&hl->host_info_list);
215 199
216 rwlock_init(&hl->host_info_lock); 200 rwlock_init(&hl->host_info_lock);
217 201
218 down_write(&hl_drivers_sem); 202 down_write(&hl_drivers_sem);
219 list_add_tail(&hl->hl_list, &hl_drivers); 203 list_add_tail(&hl->hl_list, &hl_drivers);
220 up_write(&hl_drivers_sem); 204 up_write(&hl_drivers_sem);
221 205
222 write_lock(&hl_irqs_lock); 206 write_lock_irqsave(&hl_irqs_lock, flags);
223 list_add_tail(&hl->irq_list, &hl_irqs); 207 list_add_tail(&hl->irq_list, &hl_irqs);
224 write_unlock(&hl_irqs_lock); 208 write_unlock_irqrestore(&hl_irqs_lock, flags);
225 209
226 if (hl->add_host) 210 if (hl->add_host)
227 nodemgr_for_each_host(hl, highlevel_for_each_host_reg); 211 nodemgr_for_each_host(hl, highlevel_for_each_host_reg);
228 212 return;
229 return;
230} 213}
231 214
232static void __delete_addr(struct hpsb_address_serve *as) 215static void __delete_addr(struct hpsb_address_serve *as)
@@ -236,7 +219,8 @@ static void __delete_addr(struct hpsb_address_serve *as)
236 kfree(as); 219 kfree(as);
237} 220}
238 221
239static void __unregister_host(struct hpsb_highlevel *hl, struct hpsb_host *host, int update_cr) 222static void __unregister_host(struct hpsb_highlevel *hl, struct hpsb_host *host,
223 int update_cr)
240{ 224{
241 unsigned long flags; 225 unsigned long flags;
242 struct list_head *lh, *next; 226 struct list_head *lh, *next;
@@ -251,7 +235,6 @@ static void __unregister_host(struct hpsb_highlevel *hl, struct hpsb_host *host,
251 write_lock_irqsave(&addr_space_lock, flags); 235 write_lock_irqsave(&addr_space_lock, flags);
252 list_for_each_safe (lh, next, &hl->addr_list) { 236 list_for_each_safe (lh, next, &hl->addr_list) {
253 as = list_entry(lh, struct hpsb_address_serve, hl_list); 237 as = list_entry(lh, struct hpsb_address_serve, hl_list);
254
255 if (as->host == host) 238 if (as->host == host)
256 __delete_addr(as); 239 __delete_addr(as);
257 } 240 }
@@ -259,15 +242,12 @@ static void __unregister_host(struct hpsb_highlevel *hl, struct hpsb_host *host,
259 242
260 /* Now update the config-rom to reflect anything removed by the 243 /* Now update the config-rom to reflect anything removed by the
261 * highlevel driver. */ 244 * highlevel driver. */
262 if (update_cr && host->update_config_rom) { 245 if (update_cr && host->update_config_rom &&
263 if (hpsb_update_config_rom_image(host) < 0) { 246 hpsb_update_config_rom_image(host) < 0)
264 HPSB_ERR("Failed to generate Configuration ROM image for host " 247 HPSB_ERR("Failed to generate Configuration ROM image for host "
265 "%s-%d", hl->name, host->id); 248 "%s-%d", hl->name, host->id);
266 }
267 }
268 249
269 /* And finally, remove all the host info associated between these 250 /* Finally remove all the host info associated between these two. */
270 * two. */
271 hpsb_destroy_hostinfo(hl, host); 251 hpsb_destroy_hostinfo(hl, host);
272} 252}
273 253
@@ -276,18 +256,19 @@ static int highlevel_for_each_host_unreg(struct hpsb_host *host, void *__data)
276 struct hpsb_highlevel *hl = __data; 256 struct hpsb_highlevel *hl = __data;
277 257
278 __unregister_host(hl, host, 1); 258 __unregister_host(hl, host, 1);
279
280 return 0; 259 return 0;
281} 260}
282 261
283void hpsb_unregister_highlevel(struct hpsb_highlevel *hl) 262void hpsb_unregister_highlevel(struct hpsb_highlevel *hl)
284{ 263{
285 write_lock(&hl_irqs_lock); 264 unsigned long flags;
265
266 write_lock_irqsave(&hl_irqs_lock, flags);
286 list_del(&hl->irq_list); 267 list_del(&hl->irq_list);
287 write_unlock(&hl_irqs_lock); 268 write_unlock_irqrestore(&hl_irqs_lock, flags);
288 269
289 down_write(&hl_drivers_sem); 270 down_write(&hl_drivers_sem);
290 list_del(&hl->hl_list); 271 list_del(&hl->hl_list);
291 up_write(&hl_drivers_sem); 272 up_write(&hl_drivers_sem);
292 273
293 nodemgr_for_each_host(hl, highlevel_for_each_host_unreg); 274 nodemgr_for_each_host(hl, highlevel_for_each_host_unreg);
@@ -301,7 +282,7 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
301{ 282{
302 struct hpsb_address_serve *as, *a1, *a2; 283 struct hpsb_address_serve *as, *a1, *a2;
303 struct list_head *entry; 284 struct list_head *entry;
304 u64 retval = ~0ULL; 285 u64 retval = CSR1212_INVALID_ADDR_SPACE;
305 unsigned long flags; 286 unsigned long flags;
306 u64 align_mask = ~(alignment - 1); 287 u64 align_mask = ~(alignment - 1);
307 288
@@ -312,14 +293,19 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
312 return retval; 293 return retval;
313 } 294 }
314 295
315 if (start == ~0ULL && end == ~0ULL) { 296 /* default range,
316 start = CSR1212_ALL_SPACE_BASE + 0xffff00000000ULL; /* ohci1394.c limit */ 297 * avoids controller's posted write area (see OHCI 1.1 clause 1.5) */
317 end = CSR1212_ALL_SPACE_END; 298 if (start == CSR1212_INVALID_ADDR_SPACE &&
299 end == CSR1212_INVALID_ADDR_SPACE) {
300 start = host->middle_addr_space;
301 end = CSR1212_ALL_SPACE_END;
318 } 302 }
319 303
320 if (((start|end) & ~align_mask) || (start >= end) || (end > 0x1000000000000ULL)) { 304 if (((start|end) & ~align_mask) || (start >= end) ||
321 HPSB_ERR("%s called with invalid addresses (start = %012Lx end = %012Lx)", 305 (end > CSR1212_ALL_SPACE_END)) {
322 __FUNCTION__, (unsigned long long)start, (unsigned long long)end); 306 HPSB_ERR("%s called with invalid addresses "
307 "(start = %012Lx end = %012Lx)", __FUNCTION__,
308 (unsigned long long)start,(unsigned long long)end);
323 return retval; 309 return retval;
324 } 310 }
325 311
@@ -333,20 +319,21 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
333 as->host = host; 319 as->host = host;
334 320
335 write_lock_irqsave(&addr_space_lock, flags); 321 write_lock_irqsave(&addr_space_lock, flags);
336
337 list_for_each(entry, &host->addr_space) { 322 list_for_each(entry, &host->addr_space) {
338 u64 a1sa, a1ea; 323 u64 a1sa, a1ea;
339 u64 a2sa, a2ea; 324 u64 a2sa, a2ea;
340 325
341 a1 = list_entry(entry, struct hpsb_address_serve, host_list); 326 a1 = list_entry(entry, struct hpsb_address_serve, host_list);
342 a2 = list_entry(entry->next, struct hpsb_address_serve, host_list); 327 a2 = list_entry(entry->next, struct hpsb_address_serve,
328 host_list);
343 329
344 a1sa = a1->start & align_mask; 330 a1sa = a1->start & align_mask;
345 a1ea = (a1->end + alignment -1) & align_mask; 331 a1ea = (a1->end + alignment -1) & align_mask;
346 a2sa = a2->start & align_mask; 332 a2sa = a2->start & align_mask;
347 a2ea = (a2->end + alignment -1) & align_mask; 333 a2ea = (a2->end + alignment -1) & align_mask;
348 334
349 if ((a2sa - a1ea >= size) && (a2sa - start >= size) && (a2sa > start)) { 335 if ((a2sa - a1ea >= size) && (a2sa - start >= size) &&
336 (a2sa > start)) {
350 as->start = max(start, a1ea); 337 as->start = max(start, a1ea);
351 as->end = as->start + size; 338 as->end = as->start + size;
352 list_add(&as->host_list, entry); 339 list_add(&as->host_list, entry);
@@ -355,47 +342,45 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
355 break; 342 break;
356 } 343 }
357 } 344 }
358
359 write_unlock_irqrestore(&addr_space_lock, flags); 345 write_unlock_irqrestore(&addr_space_lock, flags);
360 346
361 if (retval == ~0ULL) { 347 if (retval == CSR1212_INVALID_ADDR_SPACE)
362 kfree(as); 348 kfree(as);
363 }
364
365 return retval; 349 return retval;
366} 350}
367 351
368int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, 352int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
369 struct hpsb_address_ops *ops, u64 start, u64 end) 353 struct hpsb_address_ops *ops, u64 start, u64 end)
370{ 354{
371 struct hpsb_address_serve *as; 355 struct hpsb_address_serve *as;
372 struct list_head *lh; 356 struct list_head *lh;
373 int retval = 0; 357 int retval = 0;
374 unsigned long flags; 358 unsigned long flags;
375 359
376 if (((start|end) & 3) || (start >= end) || (end > 0x1000000000000ULL)) { 360 if (((start|end) & 3) || (start >= end) ||
377 HPSB_ERR("%s called with invalid addresses", __FUNCTION__); 361 (end > CSR1212_ALL_SPACE_END)) {
378 return 0; 362 HPSB_ERR("%s called with invalid addresses", __FUNCTION__);
379 } 363 return 0;
364 }
380 365
381 as = kmalloc(sizeof(*as), GFP_ATOMIC); 366 as = kmalloc(sizeof(*as), GFP_ATOMIC);
382 if (!as) 367 if (!as)
383 return 0; 368 return 0;
384 369
385 INIT_LIST_HEAD(&as->host_list); 370 INIT_LIST_HEAD(&as->host_list);
386 INIT_LIST_HEAD(&as->hl_list); 371 INIT_LIST_HEAD(&as->hl_list);
387 as->op = ops; 372 as->op = ops;
388 as->start = start; 373 as->start = start;
389 as->end = end; 374 as->end = end;
390 as->host = host; 375 as->host = host;
391 376
392 write_lock_irqsave(&addr_space_lock, flags); 377 write_lock_irqsave(&addr_space_lock, flags);
393
394 list_for_each(lh, &host->addr_space) { 378 list_for_each(lh, &host->addr_space) {
395 struct hpsb_address_serve *as_this = 379 struct hpsb_address_serve *as_this =
396 list_entry(lh, struct hpsb_address_serve, host_list); 380 list_entry(lh, struct hpsb_address_serve, host_list);
397 struct hpsb_address_serve *as_next = 381 struct hpsb_address_serve *as_next =
398 list_entry(lh->next, struct hpsb_address_serve, host_list); 382 list_entry(lh->next, struct hpsb_address_serve,
383 host_list);
399 384
400 if (as_this->end > as->start) 385 if (as_this->end > as->start)
401 break; 386 break;
@@ -411,60 +396,51 @@ int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
411 396
412 if (retval == 0) 397 if (retval == 0)
413 kfree(as); 398 kfree(as);
414 399 return retval;
415 return retval;
416} 400}
417 401
418int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, 402int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
419 u64 start) 403 u64 start)
420{ 404{
421 int retval = 0; 405 int retval = 0;
422 struct hpsb_address_serve *as; 406 struct hpsb_address_serve *as;
423 struct list_head *lh, *next; 407 struct list_head *lh, *next;
424 unsigned long flags; 408 unsigned long flags;
425
426 write_lock_irqsave(&addr_space_lock, flags);
427 409
410 write_lock_irqsave(&addr_space_lock, flags);
428 list_for_each_safe (lh, next, &hl->addr_list) { 411 list_for_each_safe (lh, next, &hl->addr_list) {
429 as = list_entry(lh, struct hpsb_address_serve, hl_list); 412 as = list_entry(lh, struct hpsb_address_serve, hl_list);
430 if (as->start == start && as->host == host) { 413 if (as->start == start && as->host == host) {
431 __delete_addr(as); 414 __delete_addr(as);
432 retval = 1; 415 retval = 1;
433 break; 416 break;
434 } 417 }
435 } 418 }
436 419 write_unlock_irqrestore(&addr_space_lock, flags);
437 write_unlock_irqrestore(&addr_space_lock, flags); 420 return retval;
438
439 return retval;
440} 421}
441 422
442int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, 423int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
443 unsigned int channel) 424 unsigned int channel)
444{ 425{
445 if (channel > 63) { 426 if (channel > 63) {
446 HPSB_ERR("%s called with invalid channel", __FUNCTION__); 427 HPSB_ERR("%s called with invalid channel", __FUNCTION__);
447 return -EINVAL; 428 return -EINVAL;
448 } 429 }
449 430 if (host->iso_listen_count[channel]++ == 0)
450 if (host->iso_listen_count[channel]++ == 0) { 431 return host->driver->devctl(host, ISO_LISTEN_CHANNEL, channel);
451 return host->driver->devctl(host, ISO_LISTEN_CHANNEL, channel);
452 }
453
454 return 0; 432 return 0;
455} 433}
456 434
457void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, 435void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
458 unsigned int channel) 436 unsigned int channel)
459{ 437{
460 if (channel > 63) { 438 if (channel > 63) {
461 HPSB_ERR("%s called with invalid channel", __FUNCTION__); 439 HPSB_ERR("%s called with invalid channel", __FUNCTION__);
462 return; 440 return;
463 } 441 }
464 442 if (--host->iso_listen_count[channel] == 0)
465 if (--host->iso_listen_count[channel] == 0) { 443 host->driver->devctl(host, ISO_UNLISTEN_CHANNEL, channel);
466 host->driver->devctl(host, ISO_UNLISTEN_CHANNEL, channel);
467 }
468} 444}
469 445
470static void init_hpsb_highlevel(struct hpsb_host *host) 446static void init_hpsb_highlevel(struct hpsb_host *host)
@@ -485,26 +461,24 @@ static void init_hpsb_highlevel(struct hpsb_host *host)
485 461
486void highlevel_add_host(struct hpsb_host *host) 462void highlevel_add_host(struct hpsb_host *host)
487{ 463{
488 struct hpsb_highlevel *hl; 464 struct hpsb_highlevel *hl;
489 465
490 init_hpsb_highlevel(host); 466 init_hpsb_highlevel(host);
491 467
492 down_read(&hl_drivers_sem); 468 down_read(&hl_drivers_sem);
493 list_for_each_entry(hl, &hl_drivers, hl_list) { 469 list_for_each_entry(hl, &hl_drivers, hl_list) {
494 if (hl->add_host) 470 if (hl->add_host)
495 hl->add_host(host); 471 hl->add_host(host);
496 }
497 up_read(&hl_drivers_sem);
498 if (host->update_config_rom) {
499 if (hpsb_update_config_rom_image(host) < 0)
500 HPSB_ERR("Failed to generate Configuration ROM image for "
501 "host %s-%d", hl->name, host->id);
502 } 472 }
473 up_read(&hl_drivers_sem);
474 if (host->update_config_rom && hpsb_update_config_rom_image(host) < 0)
475 HPSB_ERR("Failed to generate Configuration ROM image for host "
476 "%s-%d", hl->name, host->id);
503} 477}
504 478
505void highlevel_remove_host(struct hpsb_host *host) 479void highlevel_remove_host(struct hpsb_host *host)
506{ 480{
507 struct hpsb_highlevel *hl; 481 struct hpsb_highlevel *hl;
508 482
509 down_read(&hl_drivers_sem); 483 down_read(&hl_drivers_sem);
510 list_for_each_entry(hl, &hl_drivers, hl_list) 484 list_for_each_entry(hl, &hl_drivers, hl_list)
@@ -514,184 +488,169 @@ void highlevel_remove_host(struct hpsb_host *host)
514 488
515void highlevel_host_reset(struct hpsb_host *host) 489void highlevel_host_reset(struct hpsb_host *host)
516{ 490{
517 struct hpsb_highlevel *hl; 491 unsigned long flags;
492 struct hpsb_highlevel *hl;
518 493
519 read_lock(&hl_irqs_lock); 494 read_lock_irqsave(&hl_irqs_lock, flags);
520 list_for_each_entry(hl, &hl_irqs, irq_list) { 495 list_for_each_entry(hl, &hl_irqs, irq_list) {
521 if (hl->host_reset) 496 if (hl->host_reset)
522 hl->host_reset(host); 497 hl->host_reset(host);
523 } 498 }
524 read_unlock(&hl_irqs_lock); 499 read_unlock_irqrestore(&hl_irqs_lock, flags);
525} 500}
526 501
527void highlevel_iso_receive(struct hpsb_host *host, void *data, size_t length) 502void highlevel_iso_receive(struct hpsb_host *host, void *data, size_t length)
528{ 503{
529 struct hpsb_highlevel *hl; 504 unsigned long flags;
530 int channel = (((quadlet_t *)data)[0] >> 8) & 0x3f; 505 struct hpsb_highlevel *hl;
506 int channel = (((quadlet_t *)data)[0] >> 8) & 0x3f;
531 507
532 read_lock(&hl_irqs_lock); 508 read_lock_irqsave(&hl_irqs_lock, flags);
533 list_for_each_entry(hl, &hl_irqs, irq_list) { 509 list_for_each_entry(hl, &hl_irqs, irq_list) {
534 if (hl->iso_receive) 510 if (hl->iso_receive)
535 hl->iso_receive(host, channel, data, length); 511 hl->iso_receive(host, channel, data, length);
536 } 512 }
537 read_unlock(&hl_irqs_lock); 513 read_unlock_irqrestore(&hl_irqs_lock, flags);
538} 514}
539 515
540void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction, 516void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction,
541 void *data, size_t length) 517 void *data, size_t length)
542{ 518{
543 struct hpsb_highlevel *hl; 519 unsigned long flags;
544 int cts = ((quadlet_t *)data)[0] >> 4; 520 struct hpsb_highlevel *hl;
521 int cts = ((quadlet_t *)data)[0] >> 4;
545 522
546 read_lock(&hl_irqs_lock); 523 read_lock_irqsave(&hl_irqs_lock, flags);
547 list_for_each_entry(hl, &hl_irqs, irq_list) { 524 list_for_each_entry(hl, &hl_irqs, irq_list) {
548 if (hl->fcp_request) 525 if (hl->fcp_request)
549 hl->fcp_request(host, nodeid, direction, cts, data, 526 hl->fcp_request(host, nodeid, direction, cts, data,
550 length); 527 length);
551 } 528 }
552 read_unlock(&hl_irqs_lock); 529 read_unlock_irqrestore(&hl_irqs_lock, flags);
553} 530}
554 531
555int highlevel_read(struct hpsb_host *host, int nodeid, void *data, 532int highlevel_read(struct hpsb_host *host, int nodeid, void *data, u64 addr,
556 u64 addr, unsigned int length, u16 flags) 533 unsigned int length, u16 flags)
557{ 534{
558 struct hpsb_address_serve *as; 535 struct hpsb_address_serve *as;
559 unsigned int partlength; 536 unsigned int partlength;
560 int rcode = RCODE_ADDRESS_ERROR; 537 int rcode = RCODE_ADDRESS_ERROR;
561
562 read_lock(&addr_space_lock);
563 538
539 read_lock(&addr_space_lock);
564 list_for_each_entry(as, &host->addr_space, host_list) { 540 list_for_each_entry(as, &host->addr_space, host_list) {
565 if (as->start > addr) 541 if (as->start > addr)
566 break; 542 break;
567 543
568 if (as->end > addr) { 544 if (as->end > addr) {
569 partlength = min(as->end - addr, (u64) length); 545 partlength = min(as->end - addr, (u64) length);
570 546
571 if (as->op->read) { 547 if (as->op->read)
572 rcode = as->op->read(host, nodeid, data, 548 rcode = as->op->read(host, nodeid, data,
573 addr, partlength, flags); 549 addr, partlength, flags);
574 } else { 550 else
575 rcode = RCODE_TYPE_ERROR; 551 rcode = RCODE_TYPE_ERROR;
576 }
577 552
578 data += partlength; 553 data += partlength;
579 length -= partlength; 554 length -= partlength;
580 addr += partlength; 555 addr += partlength;
581
582 if ((rcode != RCODE_COMPLETE) || !length) {
583 break;
584 }
585 }
586 }
587
588 read_unlock(&addr_space_lock);
589 556
590 if (length && (rcode == RCODE_COMPLETE)) { 557 if ((rcode != RCODE_COMPLETE) || !length)
591 rcode = RCODE_ADDRESS_ERROR; 558 break;
592 } 559 }
560 }
561 read_unlock(&addr_space_lock);
593 562
594 return rcode; 563 if (length && (rcode == RCODE_COMPLETE))
564 rcode = RCODE_ADDRESS_ERROR;
565 return rcode;
595} 566}
596 567
597int highlevel_write(struct hpsb_host *host, int nodeid, int destid, 568int highlevel_write(struct hpsb_host *host, int nodeid, int destid, void *data,
598 void *data, u64 addr, unsigned int length, u16 flags) 569 u64 addr, unsigned int length, u16 flags)
599{ 570{
600 struct hpsb_address_serve *as; 571 struct hpsb_address_serve *as;
601 unsigned int partlength; 572 unsigned int partlength;
602 int rcode = RCODE_ADDRESS_ERROR; 573 int rcode = RCODE_ADDRESS_ERROR;
603
604 read_lock(&addr_space_lock);
605 574
575 read_lock(&addr_space_lock);
606 list_for_each_entry(as, &host->addr_space, host_list) { 576 list_for_each_entry(as, &host->addr_space, host_list) {
607 if (as->start > addr) 577 if (as->start > addr)
608 break; 578 break;
609 579
610 if (as->end > addr) { 580 if (as->end > addr) {
611 partlength = min(as->end - addr, (u64) length); 581 partlength = min(as->end - addr, (u64) length);
612 582
613 if (as->op->write) { 583 if (as->op->write)
614 rcode = as->op->write(host, nodeid, destid, 584 rcode = as->op->write(host, nodeid, destid,
615 data, addr, partlength, flags); 585 data, addr, partlength,
616 } else { 586 flags);
617 rcode = RCODE_TYPE_ERROR; 587 else
618 } 588 rcode = RCODE_TYPE_ERROR;
619 589
620 data += partlength; 590 data += partlength;
621 length -= partlength; 591 length -= partlength;
622 addr += partlength; 592 addr += partlength;
623
624 if ((rcode != RCODE_COMPLETE) || !length) {
625 break;
626 }
627 }
628 }
629
630 read_unlock(&addr_space_lock);
631 593
632 if (length && (rcode == RCODE_COMPLETE)) { 594 if ((rcode != RCODE_COMPLETE) || !length)
633 rcode = RCODE_ADDRESS_ERROR; 595 break;
634 } 596 }
597 }
598 read_unlock(&addr_space_lock);
635 599
636 return rcode; 600 if (length && (rcode == RCODE_COMPLETE))
601 rcode = RCODE_ADDRESS_ERROR;
602 return rcode;
637} 603}
638 604
639
640int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store, 605int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store,
641 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, u16 flags) 606 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
607 u16 flags)
642{ 608{
643 struct hpsb_address_serve *as; 609 struct hpsb_address_serve *as;
644 int rcode = RCODE_ADDRESS_ERROR; 610 int rcode = RCODE_ADDRESS_ERROR;
645
646 read_lock(&addr_space_lock);
647 611
612 read_lock(&addr_space_lock);
648 list_for_each_entry(as, &host->addr_space, host_list) { 613 list_for_each_entry(as, &host->addr_space, host_list) {
649 if (as->start > addr) 614 if (as->start > addr)
650 break; 615 break;
651 616
652 if (as->end > addr) { 617 if (as->end > addr) {
653 if (as->op->lock) { 618 if (as->op->lock)
654 rcode = as->op->lock(host, nodeid, store, addr, 619 rcode = as->op->lock(host, nodeid, store, addr,
655 data, arg, ext_tcode, flags); 620 data, arg, ext_tcode,
656 } else { 621 flags);
657 rcode = RCODE_TYPE_ERROR; 622 else
658 } 623 rcode = RCODE_TYPE_ERROR;
659 624 break;
660 break; 625 }
661 } 626 }
662 } 627 read_unlock(&addr_space_lock);
663 628 return rcode;
664 read_unlock(&addr_space_lock);
665
666 return rcode;
667} 629}
668 630
669int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store, 631int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store,
670 u64 addr, octlet_t data, octlet_t arg, int ext_tcode, u16 flags) 632 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
633 u16 flags)
671{ 634{
672 struct hpsb_address_serve *as; 635 struct hpsb_address_serve *as;
673 int rcode = RCODE_ADDRESS_ERROR; 636 int rcode = RCODE_ADDRESS_ERROR;
674 637
675 read_lock(&addr_space_lock); 638 read_lock(&addr_space_lock);
676 639
677 list_for_each_entry(as, &host->addr_space, host_list) { 640 list_for_each_entry(as, &host->addr_space, host_list) {
678 if (as->start > addr) 641 if (as->start > addr)
679 break; 642 break;
680 643
681 if (as->end > addr) { 644 if (as->end > addr) {
682 if (as->op->lock64) { 645 if (as->op->lock64)
683 rcode = as->op->lock64(host, nodeid, store, 646 rcode = as->op->lock64(host, nodeid, store,
684 addr, data, arg, 647 addr, data, arg,
685 ext_tcode, flags); 648 ext_tcode, flags);
686 } else { 649 else
687 rcode = RCODE_TYPE_ERROR; 650 rcode = RCODE_TYPE_ERROR;
688 } 651 break;
689 652 }
690 break; 653 }
691 } 654 read_unlock(&addr_space_lock);
692 } 655 return rcode;
693
694 read_unlock(&addr_space_lock);
695
696 return rcode;
697} 656}
diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c
index ba09741fc826..2d47b11777a5 100644
--- a/drivers/ieee1394/hosts.c
+++ b/drivers/ieee1394/hosts.c
@@ -19,6 +19,7 @@
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/timer.h> 20#include <linux/timer.h>
21#include <linux/jiffies.h> 21#include <linux/jiffies.h>
22#include <linux/mutex.h>
22 23
23#include "csr1212.h" 24#include "csr1212.h"
24#include "ieee1394.h" 25#include "ieee1394.h"
@@ -105,7 +106,7 @@ static int alloc_hostnum_cb(struct hpsb_host *host, void *__data)
105 * Return Value: a pointer to the &hpsb_host if succesful, %NULL if 106 * Return Value: a pointer to the &hpsb_host if succesful, %NULL if
106 * no memory was available. 107 * no memory was available.
107 */ 108 */
108static DECLARE_MUTEX(host_num_alloc); 109static DEFINE_MUTEX(host_num_alloc);
109 110
110struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra, 111struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
111 struct device *dev) 112 struct device *dev)
@@ -148,7 +149,7 @@ struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
148 h->topology_map = h->csr.topology_map + 3; 149 h->topology_map = h->csr.topology_map + 3;
149 h->speed_map = (u8 *)(h->csr.speed_map + 2); 150 h->speed_map = (u8 *)(h->csr.speed_map + 2);
150 151
151 down(&host_num_alloc); 152 mutex_lock(&host_num_alloc);
152 153
153 while (nodemgr_for_each_host(&hostnum, alloc_hostnum_cb)) 154 while (nodemgr_for_each_host(&hostnum, alloc_hostnum_cb))
154 hostnum++; 155 hostnum++;
@@ -167,7 +168,7 @@ struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
167 class_device_register(&h->class_dev); 168 class_device_register(&h->class_dev);
168 get_device(&h->device); 169 get_device(&h->device);
169 170
170 up(&host_num_alloc); 171 mutex_unlock(&host_num_alloc);
171 172
172 return h; 173 return h;
173} 174}
diff --git a/drivers/ieee1394/hosts.h b/drivers/ieee1394/hosts.h
index 07d188ca8495..9ad4b2463077 100644
--- a/drivers/ieee1394/hosts.h
+++ b/drivers/ieee1394/hosts.h
@@ -30,13 +30,14 @@ struct hpsb_host {
30 30
31 unsigned char iso_listen_count[64]; 31 unsigned char iso_listen_count[64];
32 32
33 int node_count; /* number of identified nodes on this bus */ 33 int node_count; /* number of identified nodes on this bus */
34 int selfid_count; /* total number of SelfIDs received */ 34 int selfid_count; /* total number of SelfIDs received */
35 int nodes_active; /* number of nodes that are actually active */ 35 int nodes_active; /* number of nodes with active link layer */
36 u8 speed[ALL_NODES]; /* speed between each node and local node */
36 37
37 nodeid_t node_id; /* node ID of this host */ 38 nodeid_t node_id; /* node ID of this host */
38 nodeid_t irm_id; /* ID of this bus' isochronous resource manager */ 39 nodeid_t irm_id; /* ID of this bus' isochronous resource manager */
39 nodeid_t busmgr_id; /* ID of this bus' bus manager */ 40 nodeid_t busmgr_id; /* ID of this bus' bus manager */
40 41
41 /* this nodes state */ 42 /* this nodes state */
42 unsigned in_bus_reset:1; 43 unsigned in_bus_reset:1;
@@ -55,7 +56,7 @@ struct hpsb_host {
55 struct csr_control csr; 56 struct csr_control csr;
56 57
57 /* Per node tlabel pool allocation */ 58 /* Per node tlabel pool allocation */
58 struct hpsb_tlabel_pool tpool[64]; 59 struct hpsb_tlabel_pool tpool[ALL_NODES];
59 60
60 struct hpsb_host_driver *driver; 61 struct hpsb_host_driver *driver;
61 62
@@ -72,6 +73,8 @@ struct hpsb_host {
72 unsigned int config_roms; 73 unsigned int config_roms;
73 74
74 struct list_head addr_space; 75 struct list_head addr_space;
76 u64 low_addr_space; /* upper bound of physical DMA area */
77 u64 middle_addr_space; /* upper bound of posted write area */
75}; 78};
76 79
77 80
diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c
index be6854e25ad4..49354de9fb8a 100644
--- a/drivers/ieee1394/ieee1394_core.c
+++ b/drivers/ieee1394/ieee1394_core.c
@@ -33,6 +33,7 @@
33#include <linux/kdev_t.h> 33#include <linux/kdev_t.h>
34#include <linux/skbuff.h> 34#include <linux/skbuff.h>
35#include <linux/suspend.h> 35#include <linux/suspend.h>
36#include <linux/kthread.h>
36 37
37#include <asm/byteorder.h> 38#include <asm/byteorder.h>
38#include <asm/semaphore.h> 39#include <asm/semaphore.h>
@@ -285,9 +286,9 @@ static int check_selfids(struct hpsb_host *host)
285 286
286static void build_speed_map(struct hpsb_host *host, int nodecount) 287static void build_speed_map(struct hpsb_host *host, int nodecount)
287{ 288{
288 u8 speedcap[nodecount];
289 u8 cldcnt[nodecount]; 289 u8 cldcnt[nodecount];
290 u8 *map = host->speed_map; 290 u8 *map = host->speed_map;
291 u8 *speedcap = host->speed;
291 struct selfid *sid; 292 struct selfid *sid;
292 struct ext_selfid *esid; 293 struct ext_selfid *esid;
293 int i, j, n; 294 int i, j, n;
@@ -354,6 +355,11 @@ static void build_speed_map(struct hpsb_host *host, int nodecount)
354 } 355 }
355 } 356 }
356 } 357 }
358
359 /* assume maximum speed for 1394b PHYs, nodemgr will correct it */
360 for (n = 0; n < nodecount; n++)
361 if (speedcap[n] == 3)
362 speedcap[n] = IEEE1394_SPEED_MAX;
357} 363}
358 364
359 365
@@ -554,11 +560,10 @@ int hpsb_send_packet(struct hpsb_packet *packet)
554 return 0; 560 return 0;
555 } 561 }
556 562
557 if (packet->type == hpsb_async && packet->node_id != ALL_NODES) { 563 if (packet->type == hpsb_async &&
564 NODEID_TO_NODE(packet->node_id) != ALL_NODES)
558 packet->speed_code = 565 packet->speed_code =
559 host->speed_map[NODEID_TO_NODE(host->node_id) * 64 566 host->speed[NODEID_TO_NODE(packet->node_id)];
560 + NODEID_TO_NODE(packet->node_id)];
561 }
562 567
563 dump_packet("send packet", packet->header, packet->header_size, packet->speed_code); 568 dump_packet("send packet", packet->header, packet->header_size, packet->speed_code);
564 569
@@ -997,11 +1002,8 @@ void abort_timedouts(unsigned long __opaque)
997 * packets that have a "complete" function are sent here. This way, the 1002 * packets that have a "complete" function are sent here. This way, the
998 * completion is run out of kernel context, and doesn't block the rest of 1003 * completion is run out of kernel context, and doesn't block the rest of
999 * the stack. */ 1004 * the stack. */
1000static int khpsbpkt_pid = -1, khpsbpkt_kill; 1005static struct task_struct *khpsbpkt_thread;
1001static DECLARE_COMPLETION(khpsbpkt_complete);
1002static struct sk_buff_head hpsbpkt_queue; 1006static struct sk_buff_head hpsbpkt_queue;
1003static DECLARE_MUTEX_LOCKED(khpsbpkt_sig);
1004
1005 1007
1006static void queue_packet_complete(struct hpsb_packet *packet) 1008static void queue_packet_complete(struct hpsb_packet *packet)
1007{ 1009{
@@ -1011,9 +1013,7 @@ static void queue_packet_complete(struct hpsb_packet *packet)
1011 } 1013 }
1012 if (packet->complete_routine != NULL) { 1014 if (packet->complete_routine != NULL) {
1013 skb_queue_tail(&hpsbpkt_queue, packet->skb); 1015 skb_queue_tail(&hpsbpkt_queue, packet->skb);
1014 1016 wake_up_process(khpsbpkt_thread);
1015 /* Signal the kernel thread to handle this */
1016 up(&khpsbpkt_sig);
1017 } 1017 }
1018 return; 1018 return;
1019} 1019}
@@ -1025,19 +1025,9 @@ static int hpsbpkt_thread(void *__hi)
1025 void (*complete_routine)(void*); 1025 void (*complete_routine)(void*);
1026 void *complete_data; 1026 void *complete_data;
1027 1027
1028 daemonize("khpsbpkt");
1029
1030 current->flags |= PF_NOFREEZE; 1028 current->flags |= PF_NOFREEZE;
1031 1029
1032 while (1) { 1030 while (!kthread_should_stop()) {
1033 if (down_interruptible(&khpsbpkt_sig)) {
1034 printk("khpsbpkt: received unexpected signal?!\n" );
1035 break;
1036 }
1037
1038 if (khpsbpkt_kill)
1039 break;
1040
1041 while ((skb = skb_dequeue(&hpsbpkt_queue)) != NULL) { 1031 while ((skb = skb_dequeue(&hpsbpkt_queue)) != NULL) {
1042 packet = (struct hpsb_packet *)skb->data; 1032 packet = (struct hpsb_packet *)skb->data;
1043 1033
@@ -1048,9 +1038,13 @@ static int hpsbpkt_thread(void *__hi)
1048 1038
1049 complete_routine(complete_data); 1039 complete_routine(complete_data);
1050 } 1040 }
1051 }
1052 1041
1053 complete_and_exit(&khpsbpkt_complete, 0); 1042 set_current_state(TASK_INTERRUPTIBLE);
1043 if (!skb_peek(&hpsbpkt_queue))
1044 schedule();
1045 __set_current_state(TASK_RUNNING);
1046 }
1047 return 0;
1054} 1048}
1055 1049
1056static int __init ieee1394_init(void) 1050static int __init ieee1394_init(void)
@@ -1065,10 +1059,10 @@ static int __init ieee1394_init(void)
1065 HPSB_ERR("Some features may not be available\n"); 1059 HPSB_ERR("Some features may not be available\n");
1066 } 1060 }
1067 1061
1068 khpsbpkt_pid = kernel_thread(hpsbpkt_thread, NULL, CLONE_KERNEL); 1062 khpsbpkt_thread = kthread_run(hpsbpkt_thread, NULL, "khpsbpkt");
1069 if (khpsbpkt_pid < 0) { 1063 if (IS_ERR(khpsbpkt_thread)) {
1070 HPSB_ERR("Failed to start hpsbpkt thread!\n"); 1064 HPSB_ERR("Failed to start hpsbpkt thread!\n");
1071 ret = -ENOMEM; 1065 ret = PTR_ERR(khpsbpkt_thread);
1072 goto exit_cleanup_config_roms; 1066 goto exit_cleanup_config_roms;
1073 } 1067 }
1074 1068
@@ -1148,10 +1142,7 @@ release_all_bus:
1148release_chrdev: 1142release_chrdev:
1149 unregister_chrdev_region(IEEE1394_CORE_DEV, 256); 1143 unregister_chrdev_region(IEEE1394_CORE_DEV, 256);
1150exit_release_kernel_thread: 1144exit_release_kernel_thread:
1151 if (khpsbpkt_pid >= 0) { 1145 kthread_stop(khpsbpkt_thread);
1152 kill_proc(khpsbpkt_pid, SIGTERM, 1);
1153 wait_for_completion(&khpsbpkt_complete);
1154 }
1155exit_cleanup_config_roms: 1146exit_cleanup_config_roms:
1156 hpsb_cleanup_config_roms(); 1147 hpsb_cleanup_config_roms();
1157 return ret; 1148 return ret;
@@ -1172,12 +1163,7 @@ static void __exit ieee1394_cleanup(void)
1172 bus_remove_file(&ieee1394_bus_type, fw_bus_attrs[i]); 1163 bus_remove_file(&ieee1394_bus_type, fw_bus_attrs[i]);
1173 bus_unregister(&ieee1394_bus_type); 1164 bus_unregister(&ieee1394_bus_type);
1174 1165
1175 if (khpsbpkt_pid >= 0) { 1166 kthread_stop(khpsbpkt_thread);
1176 khpsbpkt_kill = 1;
1177 mb();
1178 up(&khpsbpkt_sig);
1179 wait_for_completion(&khpsbpkt_complete);
1180 }
1181 1167
1182 hpsb_cleanup_config_roms(); 1168 hpsb_cleanup_config_roms();
1183 1169
diff --git a/drivers/ieee1394/ieee1394_transactions.c b/drivers/ieee1394/ieee1394_transactions.c
index 3fe2f6c4a253..a114b91d606d 100644
--- a/drivers/ieee1394/ieee1394_transactions.c
+++ b/drivers/ieee1394/ieee1394_transactions.c
@@ -136,8 +136,11 @@ int hpsb_get_tlabel(struct hpsb_packet *packet)
136{ 136{
137 unsigned long flags; 137 unsigned long flags;
138 struct hpsb_tlabel_pool *tp; 138 struct hpsb_tlabel_pool *tp;
139 int n = NODEID_TO_NODE(packet->node_id);
139 140
140 tp = &packet->host->tpool[packet->node_id & NODE_MASK]; 141 if (unlikely(n == ALL_NODES))
142 return 0;
143 tp = &packet->host->tpool[n];
141 144
142 if (irqs_disabled() || in_atomic()) { 145 if (irqs_disabled() || in_atomic()) {
143 if (down_trylock(&tp->count)) 146 if (down_trylock(&tp->count))
@@ -175,8 +178,11 @@ void hpsb_free_tlabel(struct hpsb_packet *packet)
175{ 178{
176 unsigned long flags; 179 unsigned long flags;
177 struct hpsb_tlabel_pool *tp; 180 struct hpsb_tlabel_pool *tp;
181 int n = NODEID_TO_NODE(packet->node_id);
178 182
179 tp = &packet->host->tpool[packet->node_id & NODE_MASK]; 183 if (unlikely(n == ALL_NODES))
184 return;
185 tp = &packet->host->tpool[n];
180 186
181 BUG_ON(packet->tlabel > 63 || packet->tlabel < 0); 187 BUG_ON(packet->tlabel > 63 || packet->tlabel < 0);
182 188
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 082c7fd239f5..948f1b8c4238 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -38,6 +38,7 @@ struct nodemgr_csr_info {
38 struct hpsb_host *host; 38 struct hpsb_host *host;
39 nodeid_t nodeid; 39 nodeid_t nodeid;
40 unsigned int generation; 40 unsigned int generation;
41 unsigned int speed_unverified:1;
41}; 42};
42 43
43 44
@@ -57,23 +58,75 @@ static char *nodemgr_find_oui_name(int oui)
57 return NULL; 58 return NULL;
58} 59}
59 60
61/*
62 * Correct the speed map entry. This is necessary
63 * - for nodes with link speed < phy speed,
64 * - for 1394b nodes with negotiated phy port speed < IEEE1394_SPEED_MAX.
65 * A possible speed is determined by trial and error, using quadlet reads.
66 */
67static int nodemgr_check_speed(struct nodemgr_csr_info *ci, u64 addr,
68 quadlet_t *buffer)
69{
70 quadlet_t q;
71 u8 i, *speed, old_speed, good_speed;
72 int ret;
73
74 speed = ci->host->speed + NODEID_TO_NODE(ci->nodeid);
75 old_speed = *speed;
76 good_speed = IEEE1394_SPEED_MAX + 1;
77
78 /* Try every speed from S100 to old_speed.
79 * If we did it the other way around, a too low speed could be caught
80 * if the retry succeeded for some other reason, e.g. because the link
81 * just finished its initialization. */
82 for (i = IEEE1394_SPEED_100; i <= old_speed; i++) {
83 *speed = i;
84 ret = hpsb_read(ci->host, ci->nodeid, ci->generation, addr,
85 &q, sizeof(quadlet_t));
86 if (ret)
87 break;
88 *buffer = q;
89 good_speed = i;
90 }
91 if (good_speed <= IEEE1394_SPEED_MAX) {
92 HPSB_DEBUG("Speed probe of node " NODE_BUS_FMT " yields %s",
93 NODE_BUS_ARGS(ci->host, ci->nodeid),
94 hpsb_speedto_str[good_speed]);
95 *speed = good_speed;
96 ci->speed_unverified = 0;
97 return 0;
98 }
99 *speed = old_speed;
100 return ret;
101}
60 102
61static int nodemgr_bus_read(struct csr1212_csr *csr, u64 addr, u16 length, 103static int nodemgr_bus_read(struct csr1212_csr *csr, u64 addr, u16 length,
62 void *buffer, void *__ci) 104 void *buffer, void *__ci)
63{ 105{
64 struct nodemgr_csr_info *ci = (struct nodemgr_csr_info*)__ci; 106 struct nodemgr_csr_info *ci = (struct nodemgr_csr_info*)__ci;
65 int i, ret = 0; 107 int i, ret;
66 108
67 for (i = 1; ; i++) { 109 for (i = 1; ; i++) {
68 ret = hpsb_read(ci->host, ci->nodeid, ci->generation, addr, 110 ret = hpsb_read(ci->host, ci->nodeid, ci->generation, addr,
69 buffer, length); 111 buffer, length);
70 if (!ret || i == 3) 112 if (!ret) {
113 ci->speed_unverified = 0;
114 break;
115 }
116 /* Give up after 3rd failure. */
117 if (i == 3)
71 break; 118 break;
72 119
120 /* The ieee1394_core guessed the node's speed capability from
121 * the self ID. Check whether a lower speed works. */
122 if (ci->speed_unverified && length == sizeof(quadlet_t)) {
123 ret = nodemgr_check_speed(ci, addr, buffer);
124 if (!ret)
125 break;
126 }
73 if (msleep_interruptible(334)) 127 if (msleep_interruptible(334))
74 return -EINTR; 128 return -EINTR;
75 } 129 }
76
77 return ret; 130 return ret;
78} 131}
79 132
@@ -1204,6 +1257,8 @@ static void nodemgr_node_scan_one(struct host_info *hi,
1204 ci->host = host; 1257 ci->host = host;
1205 ci->nodeid = nodeid; 1258 ci->nodeid = nodeid;
1206 ci->generation = generation; 1259 ci->generation = generation;
1260 ci->speed_unverified =
1261 host->speed[NODEID_TO_NODE(nodeid)] > IEEE1394_SPEED_100;
1207 1262
1208 /* We need to detect when the ConfigROM's generation has changed, 1263 /* We need to detect when the ConfigROM's generation has changed,
1209 * so we only update the node's info when it needs to be. */ 1264 * so we only update the node's info when it needs to be. */
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index c031650a1c74..3d278412e1ca 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -163,7 +163,7 @@ printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id ,
163 163
164/* Module Parameters */ 164/* Module Parameters */
165static int phys_dma = 1; 165static int phys_dma = 1;
166module_param(phys_dma, int, 0644); 166module_param(phys_dma, int, 0444);
167MODULE_PARM_DESC(phys_dma, "Enable physical dma (default = 1)."); 167MODULE_PARM_DESC(phys_dma, "Enable physical dma (default = 1).");
168 168
169static void dma_trm_tasklet(unsigned long data); 169static void dma_trm_tasklet(unsigned long data);
@@ -553,7 +553,8 @@ static void ohci_initialize(struct ti_ohci *ohci)
553 * register content. 553 * register content.
554 * To actually enable physical responses is the job of our interrupt 554 * To actually enable physical responses is the job of our interrupt
555 * handler which programs the physical request filter. */ 555 * handler which programs the physical request filter. */
556 reg_write(ohci, OHCI1394_PhyUpperBound, 0x01000000); 556 reg_write(ohci, OHCI1394_PhyUpperBound,
557 OHCI1394_PHYS_UPPER_BOUND_PROGRAMMED >> 16);
557 558
558 DBGMSG("physUpperBoundOffset=%08x", 559 DBGMSG("physUpperBoundOffset=%08x",
559 reg_read(ohci, OHCI1394_PhyUpperBound)); 560 reg_read(ohci, OHCI1394_PhyUpperBound));
@@ -580,6 +581,7 @@ static void ohci_initialize(struct ti_ohci *ohci)
580 OHCI1394_isochRx | 581 OHCI1394_isochRx |
581 OHCI1394_isochTx | 582 OHCI1394_isochTx |
582 OHCI1394_postedWriteErr | 583 OHCI1394_postedWriteErr |
584 OHCI1394_cycleTooLong |
583 OHCI1394_cycleInconsistent); 585 OHCI1394_cycleInconsistent);
584 586
585 /* Enable link */ 587 /* Enable link */
@@ -2382,6 +2384,15 @@ static irqreturn_t ohci_irq_handler(int irq, void *dev_id,
2382 PRINT(KERN_ERR, "physical posted write error"); 2384 PRINT(KERN_ERR, "physical posted write error");
2383 /* no recovery strategy yet, had to involve protocol drivers */ 2385 /* no recovery strategy yet, had to involve protocol drivers */
2384 } 2386 }
2387 if (event & OHCI1394_cycleTooLong) {
2388 if(printk_ratelimit())
2389 PRINT(KERN_WARNING, "isochronous cycle too long");
2390 else
2391 DBGMSG("OHCI1394_cycleTooLong");
2392 reg_write(ohci, OHCI1394_LinkControlSet,
2393 OHCI1394_LinkControl_CycleMaster);
2394 event &= ~OHCI1394_cycleTooLong;
2395 }
2385 if (event & OHCI1394_cycleInconsistent) { 2396 if (event & OHCI1394_cycleInconsistent) {
2386 /* We subscribe to the cycleInconsistent event only to 2397 /* We subscribe to the cycleInconsistent event only to
2387 * clear the corresponding event bit... otherwise, 2398 * clear the corresponding event bit... otherwise,
@@ -3400,6 +3411,14 @@ static int __devinit ohci1394_pci_probe(struct pci_dev *dev,
3400 host->csr.max_rec = (reg_read(ohci, OHCI1394_BusOptions) >> 12) & 0xf; 3411 host->csr.max_rec = (reg_read(ohci, OHCI1394_BusOptions) >> 12) & 0xf;
3401 host->csr.lnk_spd = reg_read(ohci, OHCI1394_BusOptions) & 0x7; 3412 host->csr.lnk_spd = reg_read(ohci, OHCI1394_BusOptions) & 0x7;
3402 3413
3414 if (phys_dma) {
3415 host->low_addr_space =
3416 (u64) reg_read(ohci, OHCI1394_PhyUpperBound) << 16;
3417 if (!host->low_addr_space)
3418 host->low_addr_space = OHCI1394_PHYS_UPPER_BOUND_FIXED;
3419 }
3420 host->middle_addr_space = OHCI1394_MIDDLE_ADDRESS_SPACE;
3421
3403 /* Tell the highlevel this host is ready */ 3422 /* Tell the highlevel this host is ready */
3404 if (hpsb_add_host(host)) 3423 if (hpsb_add_host(host))
3405 FAIL(-ENOMEM, "Failed to register host with highlevel"); 3424 FAIL(-ENOMEM, "Failed to register host with highlevel");
@@ -3458,24 +3477,13 @@ static void ohci1394_pci_remove(struct pci_dev *pdev)
3458 case OHCI_INIT_HAVE_TXRX_BUFFERS__MAYBE: 3477 case OHCI_INIT_HAVE_TXRX_BUFFERS__MAYBE:
3459 /* The ohci_soft_reset() stops all DMA contexts, so we 3478 /* The ohci_soft_reset() stops all DMA contexts, so we
3460 * dont need to do this. */ 3479 * dont need to do this. */
3461 /* Free AR dma */
3462 free_dma_rcv_ctx(&ohci->ar_req_context); 3480 free_dma_rcv_ctx(&ohci->ar_req_context);
3463 free_dma_rcv_ctx(&ohci->ar_resp_context); 3481 free_dma_rcv_ctx(&ohci->ar_resp_context);
3464
3465 /* Free AT dma */
3466 free_dma_trm_ctx(&ohci->at_req_context); 3482 free_dma_trm_ctx(&ohci->at_req_context);
3467 free_dma_trm_ctx(&ohci->at_resp_context); 3483 free_dma_trm_ctx(&ohci->at_resp_context);
3468
3469 /* Free IR dma */
3470 free_dma_rcv_ctx(&ohci->ir_legacy_context); 3484 free_dma_rcv_ctx(&ohci->ir_legacy_context);
3471
3472 /* Free IT dma */
3473 free_dma_trm_ctx(&ohci->it_legacy_context); 3485 free_dma_trm_ctx(&ohci->it_legacy_context);
3474 3486
3475 /* Free IR legacy dma */
3476 free_dma_rcv_ctx(&ohci->ir_legacy_context);
3477
3478
3479 case OHCI_INIT_HAVE_SELFID_BUFFER: 3487 case OHCI_INIT_HAVE_SELFID_BUFFER:
3480 pci_free_consistent(ohci->dev, OHCI1394_SI_DMA_BUF_SIZE, 3488 pci_free_consistent(ohci->dev, OHCI1394_SI_DMA_BUF_SIZE,
3481 ohci->selfid_buf_cpu, 3489 ohci->selfid_buf_cpu,
@@ -3535,6 +3543,7 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
3535 } 3543 }
3536#endif /* CONFIG_PPC_PMAC */ 3544#endif /* CONFIG_PPC_PMAC */
3537 3545
3546 pci_restore_state(pdev);
3538 pci_enable_device(pdev); 3547 pci_enable_device(pdev);
3539 3548
3540 return 0; 3549 return 0;
@@ -3554,6 +3563,8 @@ static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
3554 } 3563 }
3555#endif 3564#endif
3556 3565
3566 pci_save_state(pdev);
3567
3557 return 0; 3568 return 0;
3558} 3569}
3559 3570
diff --git a/drivers/ieee1394/ohci1394.h b/drivers/ieee1394/ohci1394.h
index 7df0962144e3..fa05f113f7f0 100644
--- a/drivers/ieee1394/ohci1394.h
+++ b/drivers/ieee1394/ohci1394.h
@@ -443,6 +443,16 @@ static inline u32 reg_read(const struct ti_ohci *ohci, int offset)
443 443
444#define OHCI1394_TCODE_PHY 0xE 444#define OHCI1394_TCODE_PHY 0xE
445 445
446/* Node offset map (phys DMA area, posted write area).
447 * The value of OHCI1394_PHYS_UPPER_BOUND_PROGRAMMED may be modified but must
448 * be lower than OHCI1394_MIDDLE_ADDRESS_SPACE.
449 * OHCI1394_PHYS_UPPER_BOUND_FIXED and OHCI1394_MIDDLE_ADDRESS_SPACE are
450 * constants given by the OHCI spec.
451 */
452#define OHCI1394_PHYS_UPPER_BOUND_FIXED 0x000100000000ULL /* 4 GB */
453#define OHCI1394_PHYS_UPPER_BOUND_PROGRAMMED 0x010000000000ULL /* 1 TB */
454#define OHCI1394_MIDDLE_ADDRESS_SPACE 0xffff00000000ULL
455
446void ohci1394_init_iso_tasklet(struct ohci1394_iso_tasklet *tasklet, 456void ohci1394_init_iso_tasklet(struct ohci1394_iso_tasklet *tasklet,
447 int type, 457 int type,
448 void (*func)(unsigned long), 458 void (*func)(unsigned long),
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index f7de546f2ed6..20ce539580f1 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -408,34 +408,34 @@ static void fcp_request(struct hpsb_host *host, int nodeid, int direction,
408 408
409#ifdef CONFIG_COMPAT 409#ifdef CONFIG_COMPAT
410struct compat_raw1394_req { 410struct compat_raw1394_req {
411 __u32 type; 411 __u32 type;
412 __s32 error; 412 __s32 error;
413 __u32 misc; 413 __u32 misc;
414 414
415 __u32 generation; 415 __u32 generation;
416 __u32 length; 416 __u32 length;
417 417
418 __u64 address; 418 __u64 address;
419 419
420 __u64 tag; 420 __u64 tag;
421 421
422 __u64 sendb; 422 __u64 sendb;
423 __u64 recvb; 423 __u64 recvb;
424} __attribute__((packed)); 424} __attribute__((packed));
425 425
426static const char __user *raw1394_compat_write(const char __user *buf) 426static const char __user *raw1394_compat_write(const char __user *buf)
427{ 427{
428 struct compat_raw1394_req __user *cr = (typeof(cr)) buf; 428 struct compat_raw1394_req __user *cr = (typeof(cr)) buf;
429 struct raw1394_request __user *r; 429 struct raw1394_request __user *r;
430 r = compat_alloc_user_space(sizeof(struct raw1394_request)); 430 r = compat_alloc_user_space(sizeof(struct raw1394_request));
431 431
432#define C(x) __copy_in_user(&r->x, &cr->x, sizeof(r->x)) 432#define C(x) __copy_in_user(&r->x, &cr->x, sizeof(r->x))
433 433
434 if (copy_in_user(r, cr, sizeof(struct compat_raw1394_req)) || 434 if (copy_in_user(r, cr, sizeof(struct compat_raw1394_req)) ||
435 C(address) || 435 C(address) ||
436 C(tag) || 436 C(tag) ||
437 C(sendb) || 437 C(sendb) ||
438 C(recvb)) 438 C(recvb))
439 return ERR_PTR(-EFAULT); 439 return ERR_PTR(-EFAULT);
440 return (const char __user *)r; 440 return (const char __user *)r;
441} 441}
@@ -443,11 +443,11 @@ static const char __user *raw1394_compat_write(const char __user *buf)
443 443
444#define P(x) __put_user(r->x, &cr->x) 444#define P(x) __put_user(r->x, &cr->x)
445 445
446static int 446static int
447raw1394_compat_read(const char __user *buf, struct raw1394_request *r) 447raw1394_compat_read(const char __user *buf, struct raw1394_request *r)
448{ 448{
449 struct compat_raw1394_req __user *cr = (typeof(cr)) r; 449 struct compat_raw1394_req __user *cr = (typeof(cr)) r;
450 if (!access_ok(VERIFY_WRITE,cr,sizeof(struct compat_raw1394_req)) || 450 if (!access_ok(VERIFY_WRITE, cr, sizeof(struct compat_raw1394_req)) ||
451 P(type) || 451 P(type) ||
452 P(error) || 452 P(error) ||
453 P(misc) || 453 P(misc) ||
@@ -512,18 +512,17 @@ static ssize_t raw1394_read(struct file *file, char __user * buffer,
512 } 512 }
513 513
514#ifdef CONFIG_COMPAT 514#ifdef CONFIG_COMPAT
515 if (count == sizeof(struct compat_raw1394_req) && 515 if (count == sizeof(struct compat_raw1394_req) &&
516 sizeof(struct compat_raw1394_req) != 516 sizeof(struct compat_raw1394_req) !=
517 sizeof(struct raw1394_request)) { 517 sizeof(struct raw1394_request)) {
518 ret = raw1394_compat_read(buffer, &req->req); 518 ret = raw1394_compat_read(buffer, &req->req);
519 519 } else
520 } else
521#endif 520#endif
522 { 521 {
523 if (copy_to_user(buffer, &req->req, sizeof(req->req))) { 522 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
524 ret = -EFAULT; 523 ret = -EFAULT;
525 goto out; 524 goto out;
526 } 525 }
527 ret = (ssize_t) sizeof(struct raw1394_request); 526 ret = (ssize_t) sizeof(struct raw1394_request);
528 } 527 }
529 out: 528 out:
@@ -2348,7 +2347,6 @@ static int state_connected(struct file_info *fi, struct pending_request *req)
2348 return handle_async_request(fi, req, node); 2347 return handle_async_request(fi, req, node);
2349} 2348}
2350 2349
2351
2352static ssize_t raw1394_write(struct file *file, const char __user * buffer, 2350static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2353 size_t count, loff_t * offset_is_ignored) 2351 size_t count, loff_t * offset_is_ignored)
2354{ 2352{
@@ -2357,9 +2355,9 @@ static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2357 ssize_t retval = 0; 2355 ssize_t retval = 0;
2358 2356
2359#ifdef CONFIG_COMPAT 2357#ifdef CONFIG_COMPAT
2360 if (count == sizeof(struct compat_raw1394_req) && 2358 if (count == sizeof(struct compat_raw1394_req) &&
2361 sizeof(struct compat_raw1394_req) != 2359 sizeof(struct compat_raw1394_req) !=
2362 sizeof(struct raw1394_request)) { 2360 sizeof(struct raw1394_request)) {
2363 buffer = raw1394_compat_write(buffer); 2361 buffer = raw1394_compat_write(buffer);
2364 if (IS_ERR(buffer)) 2362 if (IS_ERR(buffer))
2365 return PTR_ERR(buffer); 2363 return PTR_ERR(buffer);
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index 5413dc43b9f1..1d5ceb7ecc83 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -127,10 +127,12 @@ MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported (default = "
127 * talking to a single sbp2 device at the same time (filesystem coherency, 127 * talking to a single sbp2 device at the same time (filesystem coherency,
128 * etc.). If you're running an sbp2 device that supports multiple logins, 128 * etc.). If you're running an sbp2 device that supports multiple logins,
129 * and you're either running read-only filesystems or some sort of special 129 * and you're either running read-only filesystems or some sort of special
130 * filesystem supporting multiple hosts (one such filesystem is OpenGFS, 130 * filesystem supporting multiple hosts, e.g. OpenGFS, Oracle Cluster
131 * see opengfs.sourceforge.net for more info), then set exclusive_login 131 * File System, or Lustre, then set exclusive_login to zero.
132 * to zero. Note: The Oxsemi OXFW911 sbp2 chipset supports up to four 132 *
133 * concurrent logins. 133 * So far only bridges from Oxford Semiconductor are known to support
134 * concurrent logins. Depending on firmware, four or two concurrent logins
135 * are possible on OXFW911 and newer Oxsemi bridges.
134 */ 136 */
135static int exclusive_login = 1; 137static int exclusive_login = 1;
136module_param(exclusive_login, int, 0644); 138module_param(exclusive_login, int, 0644);
@@ -306,8 +308,9 @@ static const struct {
306 u32 model_id; 308 u32 model_id;
307 unsigned workarounds; 309 unsigned workarounds;
308} sbp2_workarounds_table[] = { 310} sbp2_workarounds_table[] = {
309 /* TSB42AA9 */ { 311 /* DViCO Momobay CX-1 with TSB42AA9 bridge */ {
310 .firmware_revision = 0x002800, 312 .firmware_revision = 0x002800,
313 .model_id = 0x001010,
311 .workarounds = SBP2_WORKAROUND_INQUIRY_36 | 314 .workarounds = SBP2_WORKAROUND_INQUIRY_36 |
312 SBP2_WORKAROUND_MODE_SENSE_8, 315 SBP2_WORKAROUND_MODE_SENSE_8,
313 }, 316 },
@@ -791,12 +794,12 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud
791 scsi_id->ud = ud; 794 scsi_id->ud = ud;
792 scsi_id->speed_code = IEEE1394_SPEED_100; 795 scsi_id->speed_code = IEEE1394_SPEED_100;
793 scsi_id->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100]; 796 scsi_id->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100];
797 scsi_id->status_fifo_addr = CSR1212_INVALID_ADDR_SPACE;
794 atomic_set(&scsi_id->sbp2_login_complete, 0); 798 atomic_set(&scsi_id->sbp2_login_complete, 0);
795 INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_inuse); 799 INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_inuse);
796 INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed); 800 INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed);
797 INIT_LIST_HEAD(&scsi_id->scsi_list); 801 INIT_LIST_HEAD(&scsi_id->scsi_list);
798 spin_lock_init(&scsi_id->sbp2_command_orb_lock); 802 spin_lock_init(&scsi_id->sbp2_command_orb_lock);
799 scsi_id->sbp2_lun = 0;
800 803
801 ud->device.driver_data = scsi_id; 804 ud->device.driver_data = scsi_id;
802 805
@@ -844,8 +847,8 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud
844 scsi_id->status_fifo_addr = hpsb_allocate_and_register_addrspace( 847 scsi_id->status_fifo_addr = hpsb_allocate_and_register_addrspace(
845 &sbp2_highlevel, ud->ne->host, &sbp2_ops, 848 &sbp2_highlevel, ud->ne->host, &sbp2_ops,
846 sizeof(struct sbp2_status_block), sizeof(quadlet_t), 849 sizeof(struct sbp2_status_block), sizeof(quadlet_t),
847 0x010000000000ULL, CSR1212_ALL_SPACE_END); 850 ud->ne->host->low_addr_space, CSR1212_ALL_SPACE_END);
848 if (scsi_id->status_fifo_addr == ~0ULL) { 851 if (scsi_id->status_fifo_addr == CSR1212_INVALID_ADDR_SPACE) {
849 SBP2_ERR("failed to allocate status FIFO address range"); 852 SBP2_ERR("failed to allocate status FIFO address range");
850 goto failed_alloc; 853 goto failed_alloc;
851 } 854 }
@@ -1087,9 +1090,9 @@ static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id)
1087 SBP2_DMA_FREE("single query logins data"); 1090 SBP2_DMA_FREE("single query logins data");
1088 } 1091 }
1089 1092
1090 if (scsi_id->status_fifo_addr) 1093 if (scsi_id->status_fifo_addr != CSR1212_INVALID_ADDR_SPACE)
1091 hpsb_unregister_addrspace(&sbp2_highlevel, hi->host, 1094 hpsb_unregister_addrspace(&sbp2_highlevel, hi->host,
1092 scsi_id->status_fifo_addr); 1095 scsi_id->status_fifo_addr);
1093 1096
1094 scsi_id->ud->device.driver_data = NULL; 1097 scsi_id->ud->device.driver_data = NULL;
1095 1098
@@ -1213,13 +1216,11 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id)
1213 SBP2_DEBUG("length_max_logins = %x", 1216 SBP2_DEBUG("length_max_logins = %x",
1214 (unsigned int)scsi_id->query_logins_response->length_max_logins); 1217 (unsigned int)scsi_id->query_logins_response->length_max_logins);
1215 1218
1216 SBP2_DEBUG("Query logins to SBP-2 device successful");
1217
1218 max_logins = RESPONSE_GET_MAX_LOGINS(scsi_id->query_logins_response->length_max_logins); 1219 max_logins = RESPONSE_GET_MAX_LOGINS(scsi_id->query_logins_response->length_max_logins);
1219 SBP2_DEBUG("Maximum concurrent logins supported: %d", max_logins); 1220 SBP2_INFO("Maximum concurrent logins supported: %d", max_logins);
1220 1221
1221 active_logins = RESPONSE_GET_ACTIVE_LOGINS(scsi_id->query_logins_response->length_max_logins); 1222 active_logins = RESPONSE_GET_ACTIVE_LOGINS(scsi_id->query_logins_response->length_max_logins);
1222 SBP2_DEBUG("Number of active logins: %d", active_logins); 1223 SBP2_INFO("Number of active logins: %d", active_logins);
1223 1224
1224 if (active_logins >= max_logins) { 1225 if (active_logins >= max_logins) {
1225 return -EIO; 1226 return -EIO;
@@ -1648,6 +1649,8 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
1648 } 1649 }
1649} 1650}
1650 1651
1652#define SBP2_PAYLOAD_TO_BYTES(p) (1 << ((p) + 2))
1653
1651/* 1654/*
1652 * This function is called in order to determine the max speed and packet 1655 * This function is called in order to determine the max speed and packet
1653 * size we can use in our ORBs. Note, that we (the driver and host) only 1656 * size we can use in our ORBs. Note, that we (the driver and host) only
@@ -1660,13 +1663,12 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
1660static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id) 1663static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id)
1661{ 1664{
1662 struct sbp2scsi_host_info *hi = scsi_id->hi; 1665 struct sbp2scsi_host_info *hi = scsi_id->hi;
1666 u8 payload;
1663 1667
1664 SBP2_DEBUG_ENTER(); 1668 SBP2_DEBUG_ENTER();
1665 1669
1666 /* Initial setting comes from the hosts speed map */
1667 scsi_id->speed_code = 1670 scsi_id->speed_code =
1668 hi->host->speed_map[NODEID_TO_NODE(hi->host->node_id) * 64 + 1671 hi->host->speed[NODEID_TO_NODE(scsi_id->ne->nodeid)];
1669 NODEID_TO_NODE(scsi_id->ne->nodeid)];
1670 1672
1671 /* Bump down our speed if the user requested it */ 1673 /* Bump down our speed if the user requested it */
1672 if (scsi_id->speed_code > max_speed) { 1674 if (scsi_id->speed_code > max_speed) {
@@ -1677,15 +1679,22 @@ static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id)
1677 1679
1678 /* Payload size is the lesser of what our speed supports and what 1680 /* Payload size is the lesser of what our speed supports and what
1679 * our host supports. */ 1681 * our host supports. */
1680 scsi_id->max_payload_size = 1682 payload = min(sbp2_speedto_max_payload[scsi_id->speed_code],
1681 min(sbp2_speedto_max_payload[scsi_id->speed_code], 1683 (u8) (hi->host->csr.max_rec - 1));
1682 (u8) (hi->host->csr.max_rec - 1)); 1684
1685 /* If physical DMA is off, work around limitation in ohci1394:
1686 * packet size must not exceed PAGE_SIZE */
1687 if (scsi_id->ne->host->low_addr_space < (1ULL << 32))
1688 while (SBP2_PAYLOAD_TO_BYTES(payload) + 24 > PAGE_SIZE &&
1689 payload)
1690 payload--;
1683 1691
1684 HPSB_DEBUG("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]", 1692 HPSB_DEBUG("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]",
1685 NODE_BUS_ARGS(hi->host, scsi_id->ne->nodeid), 1693 NODE_BUS_ARGS(hi->host, scsi_id->ne->nodeid),
1686 hpsb_speedto_str[scsi_id->speed_code], 1694 hpsb_speedto_str[scsi_id->speed_code],
1687 1 << ((u32) scsi_id->max_payload_size + 2)); 1695 SBP2_PAYLOAD_TO_BYTES(payload));
1688 1696
1697 scsi_id->max_payload_size = payload;
1689 return 0; 1698 return 0;
1690} 1699}
1691 1700
@@ -2113,33 +2122,6 @@ static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense
2113} 2122}
2114 2123
2115/* 2124/*
2116 * This function is called after a command is completed, in order to do any necessary SBP-2
2117 * response data translations for the SCSI stack
2118 */
2119static void sbp2_check_sbp2_response(struct scsi_id_instance_data *scsi_id,
2120 struct scsi_cmnd *SCpnt)
2121{
2122 u8 *scsi_buf = SCpnt->request_buffer;
2123
2124 SBP2_DEBUG_ENTER();
2125
2126 if (SCpnt->cmnd[0] == INQUIRY && (SCpnt->cmnd[1] & 3) == 0) {
2127 /*
2128 * Make sure data length is ok. Minimum length is 36 bytes
2129 */
2130 if (scsi_buf[4] == 0) {
2131 scsi_buf[4] = 36 - 5;
2132 }
2133
2134 /*
2135 * Fix ansi revision and response data format
2136 */
2137 scsi_buf[2] |= 2;
2138 scsi_buf[3] = (scsi_buf[3] & 0xf0) | 2;
2139 }
2140}
2141
2142/*
2143 * This function deals with status writes from the SBP-2 device 2125 * This function deals with status writes from the SBP-2 device
2144 */ 2126 */
2145static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int destid, 2127static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int destid,
@@ -2478,13 +2460,6 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
2478 } 2460 }
2479 2461
2480 /* 2462 /*
2481 * Take care of any sbp2 response data mucking here (RBC stuff, etc.)
2482 */
2483 if (SCpnt->result == DID_OK << 16) {
2484 sbp2_check_sbp2_response(scsi_id, SCpnt);
2485 }
2486
2487 /*
2488 * If a bus reset is in progress and there was an error, complete 2463 * If a bus reset is in progress and there was an error, complete
2489 * the command as busy so that it will get retried. 2464 * the command as busy so that it will get retried.
2490 */ 2465 */
diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h
index f4ccc9d0fba4..b22ce1aa8fe4 100644
--- a/drivers/ieee1394/sbp2.h
+++ b/drivers/ieee1394/sbp2.h
@@ -52,7 +52,7 @@ struct sbp2_command_orb {
52 u32 data_descriptor_lo; 52 u32 data_descriptor_lo;
53 u32 misc; 53 u32 misc;
54 u8 cdb[12]; 54 u8 cdb[12];
55}; 55} __attribute__((packed));
56 56
57#define SBP2_LOGIN_REQUEST 0x0 57#define SBP2_LOGIN_REQUEST 0x0
58#define SBP2_QUERY_LOGINS_REQUEST 0x1 58#define SBP2_QUERY_LOGINS_REQUEST 0x1
@@ -80,7 +80,7 @@ struct sbp2_login_orb {
80 u32 passwd_resp_lengths; 80 u32 passwd_resp_lengths;
81 u32 status_fifo_hi; 81 u32 status_fifo_hi;
82 u32 status_fifo_lo; 82 u32 status_fifo_lo;
83}; 83} __attribute__((packed));
84 84
85#define RESPONSE_GET_LOGIN_ID(value) (value & 0xffff) 85#define RESPONSE_GET_LOGIN_ID(value) (value & 0xffff)
86#define RESPONSE_GET_LENGTH(value) ((value >> 16) & 0xffff) 86#define RESPONSE_GET_LENGTH(value) ((value >> 16) & 0xffff)
@@ -91,7 +91,7 @@ struct sbp2_login_response {
91 u32 command_block_agent_hi; 91 u32 command_block_agent_hi;
92 u32 command_block_agent_lo; 92 u32 command_block_agent_lo;
93 u32 reconnect_hold; 93 u32 reconnect_hold;
94}; 94} __attribute__((packed));
95 95
96#define ORB_SET_LOGIN_ID(value) (value & 0xffff) 96#define ORB_SET_LOGIN_ID(value) (value & 0xffff)
97 97
@@ -106,7 +106,7 @@ struct sbp2_query_logins_orb {
106 u32 reserved_resp_length; 106 u32 reserved_resp_length;
107 u32 status_fifo_hi; 107 u32 status_fifo_hi;
108 u32 status_fifo_lo; 108 u32 status_fifo_lo;
109}; 109} __attribute__((packed));
110 110
111#define RESPONSE_GET_MAX_LOGINS(value) (value & 0xffff) 111#define RESPONSE_GET_MAX_LOGINS(value) (value & 0xffff)
112#define RESPONSE_GET_ACTIVE_LOGINS(value) ((RESPONSE_GET_LENGTH(value) - 4) / 12) 112#define RESPONSE_GET_ACTIVE_LOGINS(value) ((RESPONSE_GET_LENGTH(value) - 4) / 12)
@@ -116,7 +116,7 @@ struct sbp2_query_logins_response {
116 u32 misc_IDs; 116 u32 misc_IDs;
117 u32 initiator_misc_hi; 117 u32 initiator_misc_hi;
118 u32 initiator_misc_lo; 118 u32 initiator_misc_lo;
119}; 119} __attribute__((packed));
120 120
121struct sbp2_reconnect_orb { 121struct sbp2_reconnect_orb {
122 u32 reserved1; 122 u32 reserved1;
@@ -127,7 +127,7 @@ struct sbp2_reconnect_orb {
127 u32 reserved5; 127 u32 reserved5;
128 u32 status_fifo_hi; 128 u32 status_fifo_hi;
129 u32 status_fifo_lo; 129 u32 status_fifo_lo;
130}; 130} __attribute__((packed));
131 131
132struct sbp2_logout_orb { 132struct sbp2_logout_orb {
133 u32 reserved1; 133 u32 reserved1;
@@ -138,7 +138,7 @@ struct sbp2_logout_orb {
138 u32 reserved5; 138 u32 reserved5;
139 u32 status_fifo_hi; 139 u32 status_fifo_hi;
140 u32 status_fifo_lo; 140 u32 status_fifo_lo;
141}; 141} __attribute__((packed));
142 142
143#define PAGE_TABLE_SET_SEGMENT_BASE_HI(value) (value & 0xffff) 143#define PAGE_TABLE_SET_SEGMENT_BASE_HI(value) (value & 0xffff)
144#define PAGE_TABLE_SET_SEGMENT_LENGTH(value) ((value & 0xffff) << 16) 144#define PAGE_TABLE_SET_SEGMENT_LENGTH(value) ((value & 0xffff) << 16)
@@ -146,7 +146,7 @@ struct sbp2_logout_orb {
146struct sbp2_unrestricted_page_table { 146struct sbp2_unrestricted_page_table {
147 u32 length_segment_base_hi; 147 u32 length_segment_base_hi;
148 u32 segment_base_lo; 148 u32 segment_base_lo;
149}; 149} __attribute__((packed));
150 150
151#define RESP_STATUS_REQUEST_COMPLETE 0x0 151#define RESP_STATUS_REQUEST_COMPLETE 0x0
152#define RESP_STATUS_TRANSPORT_FAILURE 0x1 152#define RESP_STATUS_TRANSPORT_FAILURE 0x1
@@ -191,7 +191,7 @@ struct sbp2_status_block {
191 u32 ORB_offset_hi_misc; 191 u32 ORB_offset_hi_misc;
192 u32 ORB_offset_lo; 192 u32 ORB_offset_lo;
193 u8 command_set_dependent[24]; 193 u8 command_set_dependent[24];
194}; 194} __attribute__((packed));
195 195
196/* 196/*
197 * Miscellaneous SBP2 related config rom defines 197 * Miscellaneous SBP2 related config rom defines
@@ -395,9 +395,8 @@ static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id,
395static int sbp2_send_command(struct scsi_id_instance_data *scsi_id, 395static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
396 struct scsi_cmnd *SCpnt, 396 struct scsi_cmnd *SCpnt,
397 void (*done)(struct scsi_cmnd *)); 397 void (*done)(struct scsi_cmnd *));
398static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense_data); 398static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status,
399static void sbp2_check_sbp2_response(struct scsi_id_instance_data *scsi_id, 399 unchar *sense_data);
400 struct scsi_cmnd *SCpnt);
401static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, 400static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
402 struct unit_directory *ud); 401 struct unit_directory *ud);
403static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id); 402static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id);
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index 4e3bd62c458d..295d0f8c3d06 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -331,7 +331,7 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc,
331 331
332 spin_lock_init(&d->lock); 332 spin_lock_init(&d->lock);
333 333
334 PRINT(KERN_INFO, ohci->host->id, "Iso %s DMA: %d buffers " 334 DBGMSG(ohci->host->id, "Iso %s DMA: %d buffers "
335 "of size %d allocated for a frame size %d, each with %d prgs", 335 "of size %d allocated for a frame size %d, each with %d prgs",
336 (type == OHCI_ISO_RECEIVE) ? "receive" : "transmit", 336 (type == OHCI_ISO_RECEIVE) ? "receive" : "transmit",
337 d->num_desc - 1, d->buf_size, d->frame_size, d->nb_cmd); 337 d->num_desc - 1, d->buf_size, d->frame_size, d->nb_cmd);
@@ -759,7 +759,7 @@ static int __video1394_ioctl(struct file *file,
759 } else { 759 } else {
760 mask = (u64)0x1<<v.channel; 760 mask = (u64)0x1<<v.channel;
761 } 761 }
762 PRINT(KERN_INFO, ohci->host->id, "mask: %08X%08X usage: %08X%08X\n", 762 DBGMSG(ohci->host->id, "mask: %08X%08X usage: %08X%08X\n",
763 (u32)(mask>>32),(u32)(mask&0xffffffff), 763 (u32)(mask>>32),(u32)(mask&0xffffffff),
764 (u32)(ohci->ISO_channel_usage>>32), 764 (u32)(ohci->ISO_channel_usage>>32),
765 (u32)(ohci->ISO_channel_usage&0xffffffff)); 765 (u32)(ohci->ISO_channel_usage&0xffffffff));
@@ -805,7 +805,7 @@ static int __video1394_ioctl(struct file *file,
805 v.buf_size = d->buf_size; 805 v.buf_size = d->buf_size;
806 list_add_tail(&d->link, &ctx->context_list); 806 list_add_tail(&d->link, &ctx->context_list);
807 807
808 PRINT(KERN_INFO, ohci->host->id, 808 DBGMSG(ohci->host->id,
809 "iso context %d listen on channel %d", 809 "iso context %d listen on channel %d",
810 d->ctx, v.channel); 810 d->ctx, v.channel);
811 } 811 }
@@ -828,7 +828,7 @@ static int __video1394_ioctl(struct file *file,
828 828
829 list_add_tail(&d->link, &ctx->context_list); 829 list_add_tail(&d->link, &ctx->context_list);
830 830
831 PRINT(KERN_INFO, ohci->host->id, 831 DBGMSG(ohci->host->id,
832 "Iso context %d talk on channel %d", d->ctx, 832 "Iso context %d talk on channel %d", d->ctx,
833 v.channel); 833 v.channel);
834 } 834 }
@@ -873,7 +873,7 @@ static int __video1394_ioctl(struct file *file,
873 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, channel); 873 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, channel);
874 874
875 if (d == NULL) return -ESRCH; 875 if (d == NULL) return -ESRCH;
876 PRINT(KERN_INFO, ohci->host->id, "Iso context %d " 876 DBGMSG(ohci->host->id, "Iso context %d "
877 "stop talking on channel %d", d->ctx, channel); 877 "stop talking on channel %d", d->ctx, channel);
878 free_dma_iso_ctx(d); 878 free_dma_iso_ctx(d);
879 879
@@ -935,7 +935,7 @@ static int __video1394_ioctl(struct file *file,
935 else { 935 else {
936 /* Wake up dma context if necessary */ 936 /* Wake up dma context if necessary */
937 if (!(reg_read(ohci, d->ctrlSet) & 0x400)) { 937 if (!(reg_read(ohci, d->ctrlSet) & 0x400)) {
938 PRINT(KERN_INFO, ohci->host->id, 938 DBGMSG(ohci->host->id,
939 "Waking up iso dma ctx=%d", d->ctx); 939 "Waking up iso dma ctx=%d", d->ctx);
940 reg_write(ohci, d->ctrlSet, 0x1000); 940 reg_write(ohci, d->ctrlSet, 0x1000);
941 } 941 }
@@ -1106,7 +1106,7 @@ static int __video1394_ioctl(struct file *file,
1106 else { 1106 else {
1107 /* Wake up dma context if necessary */ 1107 /* Wake up dma context if necessary */
1108 if (!(reg_read(ohci, d->ctrlSet) & 0x400)) { 1108 if (!(reg_read(ohci, d->ctrlSet) & 0x400)) {
1109 PRINT(KERN_INFO, ohci->host->id, 1109 DBGMSG(ohci->host->id,
1110 "Waking up iso transmit dma ctx=%d", 1110 "Waking up iso transmit dma ctx=%d",
1111 d->ctx); 1111 d->ctx);
1112 put_timestamp(ohci, d, d->last_buffer); 1112 put_timestamp(ohci, d, d->last_buffer);
@@ -1232,7 +1232,7 @@ static int video1394_release(struct inode *inode, struct file *file)
1232 "is not being used", d->channel); 1232 "is not being used", d->channel);
1233 else 1233 else
1234 ohci->ISO_channel_usage &= ~mask; 1234 ohci->ISO_channel_usage &= ~mask;
1235 PRINT(KERN_INFO, ohci->host->id, "On release: Iso %s context " 1235 DBGMSG(ohci->host->id, "On release: Iso %s context "
1236 "%d stop listening on channel %d", 1236 "%d stop listening on channel %d",
1237 d->type == OHCI_ISO_RECEIVE ? "receive" : "transmit", 1237 d->type == OHCI_ISO_RECEIVE ? "receive" : "transmit",
1238 d->ctx, d->channel); 1238 d->ctx, d->channel);