aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ieee1394/csr.c31
-rw-r--r--drivers/ieee1394/csr.h109
-rw-r--r--drivers/ieee1394/dma.c7
-rw-r--r--drivers/ieee1394/dma.h90
-rw-r--r--drivers/ieee1394/dv1394-private.h6
-rw-r--r--drivers/ieee1394/dv1394.c43
-rw-r--r--drivers/ieee1394/eth1394.c11
-rw-r--r--drivers/ieee1394/highlevel.h201
-rw-r--r--drivers/ieee1394/hosts.c20
-rw-r--r--drivers/ieee1394/hosts.h32
-rw-r--r--drivers/ieee1394/ieee1394-ioctl.h9
-rw-r--r--drivers/ieee1394/ieee1394.h316
-rw-r--r--drivers/ieee1394/ieee1394_core.c4
-rw-r--r--drivers/ieee1394/ieee1394_core.h27
-rw-r--r--drivers/ieee1394/ieee1394_hotplug.h30
-rw-r--r--drivers/ieee1394/ieee1394_transactions.c6
-rw-r--r--drivers/ieee1394/ieee1394_transactions.h37
-rw-r--r--drivers/ieee1394/ieee1394_types.h45
-rw-r--r--drivers/ieee1394/iso.c5
-rw-r--r--drivers/ieee1394/iso.h87
-rw-r--r--drivers/ieee1394/nodemgr.c173
-rw-r--r--drivers/ieee1394/nodemgr.h26
-rw-r--r--drivers/ieee1394/ohci1394.c5
-rw-r--r--drivers/ieee1394/raw1394-private.h3
-rw-r--r--drivers/ieee1394/raw1394.c102
-rw-r--r--drivers/ieee1394/sbp2.c4
-rw-r--r--drivers/ieee1394/video1394.c12
27 files changed, 715 insertions, 726 deletions
diff --git a/drivers/ieee1394/csr.c b/drivers/ieee1394/csr.c
index 149573db91c5..ab0c80f61b9d 100644
--- a/drivers/ieee1394/csr.c
+++ b/drivers/ieee1394/csr.c
@@ -17,11 +17,13 @@
17 * 17 *
18 */ 18 */
19 19
20#include <linux/string.h> 20#include <linux/jiffies.h>
21#include <linux/kernel.h>
21#include <linux/module.h> 22#include <linux/module.h>
22#include <linux/moduleparam.h> 23#include <linux/moduleparam.h>
23#include <linux/param.h> 24#include <linux/param.h>
24#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <linux/string.h>
25 27
26#include "csr1212.h" 28#include "csr1212.h"
27#include "ieee1394_types.h" 29#include "ieee1394_types.h"
@@ -149,31 +151,18 @@ static void host_reset(struct hpsb_host *host)
149 151
150/* 152/*
151 * HI == seconds (bits 0:2) 153 * HI == seconds (bits 0:2)
152 * LO == fraction units of 1/8000 of a second, as per 1394 (bits 19:31) 154 * LO == fractions of a second in units of 125usec (bits 19:31)
153 *
154 * Convert to units and then to HZ, for comparison to jiffies.
155 *
156 * By default this will end up being 800 units, or 100ms (125usec per
157 * unit).
158 * 155 *
159 * NOTE: The spec says 1/8000, but also says we can compute based on 1/8192 156 * Convert SPLIT_TIMEOUT to jiffies.
160 * like CSR specifies. Should make our math less complex. 157 * The default and minimum as per 1394a-2000 clause 8.3.2.2.6 is 100ms.
161 */ 158 */
162static inline void calculate_expire(struct csr_control *csr) 159static inline void calculate_expire(struct csr_control *csr)
163{ 160{
164 unsigned long units; 161 unsigned long usecs =
165 162 (csr->split_timeout_hi & 0x07) * USEC_PER_SEC +
166 /* Take the seconds, and convert to units */ 163 (csr->split_timeout_lo >> 19) * 125L;
167 units = (unsigned long)(csr->split_timeout_hi & 0x07) << 13;
168
169 /* Add in the fractional units */
170 units += (unsigned long)(csr->split_timeout_lo >> 19);
171
172 /* Convert to jiffies */
173 csr->expire = (unsigned long)(units * HZ) >> 13UL;
174 164
175 /* Just to keep from rounding low */ 165 csr->expire = usecs_to_jiffies(usecs > 100000L ? usecs : 100000L);
176 csr->expire++;
177 166
178 HPSB_VERBOSE("CSR: setting expire to %lu, HZ=%u", csr->expire, HZ); 167 HPSB_VERBOSE("CSR: setting expire to %lu, HZ=%u", csr->expire, HZ);
179} 168}
diff --git a/drivers/ieee1394/csr.h b/drivers/ieee1394/csr.h
index ea9aa4f53ab6..f11546550d84 100644
--- a/drivers/ieee1394/csr.h
+++ b/drivers/ieee1394/csr.h
@@ -1,75 +1,73 @@
1
2#ifndef _IEEE1394_CSR_H 1#ifndef _IEEE1394_CSR_H
3#define _IEEE1394_CSR_H 2#define _IEEE1394_CSR_H
4 3
5#ifdef CONFIG_PREEMPT 4#include <linux/spinlock_types.h>
6#include <linux/sched.h>
7#endif
8 5
9#include "csr1212.h" 6#include "csr1212.h"
7#include "ieee1394_types.h"
10 8
11#define CSR_REGISTER_BASE 0xfffff0000000ULL 9#define CSR_REGISTER_BASE 0xfffff0000000ULL
12 10
13/* register offsets relative to CSR_REGISTER_BASE */ 11/* register offsets relative to CSR_REGISTER_BASE */
14#define CSR_STATE_CLEAR 0x0 12#define CSR_STATE_CLEAR 0x0
15#define CSR_STATE_SET 0x4 13#define CSR_STATE_SET 0x4
16#define CSR_NODE_IDS 0x8 14#define CSR_NODE_IDS 0x8
17#define CSR_RESET_START 0xc 15#define CSR_RESET_START 0xc
18#define CSR_SPLIT_TIMEOUT_HI 0x18 16#define CSR_SPLIT_TIMEOUT_HI 0x18
19#define CSR_SPLIT_TIMEOUT_LO 0x1c 17#define CSR_SPLIT_TIMEOUT_LO 0x1c
20#define CSR_CYCLE_TIME 0x200 18#define CSR_CYCLE_TIME 0x200
21#define CSR_BUS_TIME 0x204 19#define CSR_BUS_TIME 0x204
22#define CSR_BUSY_TIMEOUT 0x210 20#define CSR_BUSY_TIMEOUT 0x210
23#define CSR_BUS_MANAGER_ID 0x21c 21#define CSR_BUS_MANAGER_ID 0x21c
24#define CSR_BANDWIDTH_AVAILABLE 0x220 22#define CSR_BANDWIDTH_AVAILABLE 0x220
25#define CSR_CHANNELS_AVAILABLE 0x224 23#define CSR_CHANNELS_AVAILABLE 0x224
26#define CSR_CHANNELS_AVAILABLE_HI 0x224 24#define CSR_CHANNELS_AVAILABLE_HI 0x224
27#define CSR_CHANNELS_AVAILABLE_LO 0x228 25#define CSR_CHANNELS_AVAILABLE_LO 0x228
28#define CSR_BROADCAST_CHANNEL 0x234 26#define CSR_BROADCAST_CHANNEL 0x234
29#define CSR_CONFIG_ROM 0x400 27#define CSR_CONFIG_ROM 0x400
30#define CSR_CONFIG_ROM_END 0x800 28#define CSR_CONFIG_ROM_END 0x800
31#define CSR_FCP_COMMAND 0xB00 29#define CSR_FCP_COMMAND 0xB00
32#define CSR_FCP_RESPONSE 0xD00 30#define CSR_FCP_RESPONSE 0xD00
33#define CSR_FCP_END 0xF00 31#define CSR_FCP_END 0xF00
34#define CSR_TOPOLOGY_MAP 0x1000 32#define CSR_TOPOLOGY_MAP 0x1000
35#define CSR_TOPOLOGY_MAP_END 0x1400 33#define CSR_TOPOLOGY_MAP_END 0x1400
36#define CSR_SPEED_MAP 0x2000 34#define CSR_SPEED_MAP 0x2000
37#define CSR_SPEED_MAP_END 0x3000 35#define CSR_SPEED_MAP_END 0x3000
38 36
39/* IEEE 1394 bus specific Configuration ROM Key IDs */ 37/* IEEE 1394 bus specific Configuration ROM Key IDs */
40#define IEEE1394_KV_ID_POWER_REQUIREMENTS (0x30) 38#define IEEE1394_KV_ID_POWER_REQUIREMENTS (0x30)
41 39
42/* IEEE 1394 Bus Inforamation Block specifics */ 40/* IEEE 1394 Bus Information Block specifics */
43#define CSR_BUS_INFO_SIZE (5 * sizeof(quadlet_t)) 41#define CSR_BUS_INFO_SIZE (5 * sizeof(quadlet_t))
44 42
45#define CSR_IRMC_SHIFT 31 43#define CSR_IRMC_SHIFT 31
46#define CSR_CMC_SHIFT 30 44#define CSR_CMC_SHIFT 30
47#define CSR_ISC_SHIFT 29 45#define CSR_ISC_SHIFT 29
48#define CSR_BMC_SHIFT 28 46#define CSR_BMC_SHIFT 28
49#define CSR_PMC_SHIFT 27 47#define CSR_PMC_SHIFT 27
50#define CSR_CYC_CLK_ACC_SHIFT 16 48#define CSR_CYC_CLK_ACC_SHIFT 16
51#define CSR_MAX_REC_SHIFT 12 49#define CSR_MAX_REC_SHIFT 12
52#define CSR_MAX_ROM_SHIFT 8 50#define CSR_MAX_ROM_SHIFT 8
53#define CSR_GENERATION_SHIFT 4 51#define CSR_GENERATION_SHIFT 4
54 52
55#define CSR_SET_BUS_INFO_GENERATION(csr, gen) \ 53#define CSR_SET_BUS_INFO_GENERATION(csr, gen) \
56 ((csr)->bus_info_data[2] = \ 54 ((csr)->bus_info_data[2] = \
57 cpu_to_be32((be32_to_cpu((csr)->bus_info_data[2]) & \ 55 cpu_to_be32((be32_to_cpu((csr)->bus_info_data[2]) & \
58 ~(0xf << CSR_GENERATION_SHIFT)) | \ 56 ~(0xf << CSR_GENERATION_SHIFT)) | \
59 (gen) << CSR_GENERATION_SHIFT)) 57 (gen) << CSR_GENERATION_SHIFT))
60 58
61struct csr_control { 59struct csr_control {
62 spinlock_t lock; 60 spinlock_t lock;
63 61
64 quadlet_t state; 62 quadlet_t state;
65 quadlet_t node_ids; 63 quadlet_t node_ids;
66 quadlet_t split_timeout_hi, split_timeout_lo; 64 quadlet_t split_timeout_hi, split_timeout_lo;
67 unsigned long expire; // Calculated from split_timeout 65 unsigned long expire; /* Calculated from split_timeout */
68 quadlet_t cycle_time; 66 quadlet_t cycle_time;
69 quadlet_t bus_time; 67 quadlet_t bus_time;
70 quadlet_t bus_manager_id; 68 quadlet_t bus_manager_id;
71 quadlet_t bandwidth_available; 69 quadlet_t bandwidth_available;
72 quadlet_t channels_available_hi, channels_available_lo; 70 quadlet_t channels_available_hi, channels_available_lo;
73 quadlet_t broadcast_channel; 71 quadlet_t broadcast_channel;
74 72
75 /* Bus Info */ 73 /* Bus Info */
@@ -84,8 +82,8 @@ struct csr_control {
84 82
85 struct csr1212_csr *rom; 83 struct csr1212_csr *rom;
86 84
87 quadlet_t topology_map[256]; 85 quadlet_t topology_map[256];
88 quadlet_t speed_map[1024]; 86 quadlet_t speed_map[1024];
89}; 87};
90 88
91extern struct csr1212_bus_ops csr_bus_ops; 89extern struct csr1212_bus_ops csr_bus_ops;
@@ -93,4 +91,9 @@ extern struct csr1212_bus_ops csr_bus_ops;
93int init_csr(void); 91int init_csr(void);
94void cleanup_csr(void); 92void cleanup_csr(void);
95 93
94/* hpsb_update_config_rom() is deprecated */
95struct hpsb_host;
96int hpsb_update_config_rom(struct hpsb_host *host, const quadlet_t *new_rom,
97 size_t size, unsigned char rom_version);
98
96#endif /* _IEEE1394_CSR_H */ 99#endif /* _IEEE1394_CSR_H */
diff --git a/drivers/ieee1394/dma.c b/drivers/ieee1394/dma.c
index ca5167de707d..c68f328e1a29 100644
--- a/drivers/ieee1394/dma.c
+++ b/drivers/ieee1394/dma.c
@@ -7,10 +7,13 @@
7 * directory of the kernel sources for details. 7 * directory of the kernel sources for details.
8 */ 8 */
9 9
10#include <linux/mm.h>
10#include <linux/module.h> 11#include <linux/module.h>
11#include <linux/vmalloc.h> 12#include <linux/pci.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13#include <linux/mm.h> 14#include <linux/vmalloc.h>
15#include <asm/scatterlist.h>
16
14#include "dma.h" 17#include "dma.h"
15 18
16/* dma_prog_region */ 19/* dma_prog_region */
diff --git a/drivers/ieee1394/dma.h b/drivers/ieee1394/dma.h
index 061550a6fb99..a1682aba71c7 100644
--- a/drivers/ieee1394/dma.h
+++ b/drivers/ieee1394/dma.h
@@ -10,69 +10,91 @@
10#ifndef IEEE1394_DMA_H 10#ifndef IEEE1394_DMA_H
11#define IEEE1394_DMA_H 11#define IEEE1394_DMA_H
12 12
13#include <linux/pci.h> 13#include <asm/types.h>
14#include <asm/scatterlist.h> 14
15 15struct pci_dev;
16/* struct dma_prog_region 16struct scatterlist;
17 17struct vm_area_struct;
18 a small, physically-contiguous DMA buffer with random-access, 18
19 synchronous usage characteristics 19/**
20*/ 20 * struct dma_prog_region - small contiguous DMA buffer
21 21 * @kvirt: kernel virtual address
22 * @dev: PCI device
23 * @n_pages: number of kernel pages
24 * @bus_addr: base bus address
25 *
26 * a small, physically contiguous DMA buffer with random-access, synchronous
27 * usage characteristics
28 */
22struct dma_prog_region { 29struct dma_prog_region {
23 unsigned char *kvirt; /* kernel virtual address */ 30 unsigned char *kvirt;
24 struct pci_dev *dev; /* PCI device */ 31 struct pci_dev *dev;
25 unsigned int n_pages; /* # of kernel pages */ 32 unsigned int n_pages;
26 dma_addr_t bus_addr; /* base bus address */ 33 dma_addr_t bus_addr;
27}; 34};
28 35
29/* clear out all fields but do not allocate any memory */ 36/* clear out all fields but do not allocate any memory */
30void dma_prog_region_init(struct dma_prog_region *prog); 37void dma_prog_region_init(struct dma_prog_region *prog);
31int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes, struct pci_dev *dev); 38int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes,
39 struct pci_dev *dev);
32void dma_prog_region_free(struct dma_prog_region *prog); 40void dma_prog_region_free(struct dma_prog_region *prog);
33 41
34static inline dma_addr_t dma_prog_region_offset_to_bus(struct dma_prog_region *prog, unsigned long offset) 42static inline dma_addr_t dma_prog_region_offset_to_bus(
43 struct dma_prog_region *prog, unsigned long offset)
35{ 44{
36 return prog->bus_addr + offset; 45 return prog->bus_addr + offset;
37} 46}
38 47
39/* struct dma_region 48/**
40 49 * struct dma_region - large non-contiguous DMA buffer
41 a large, non-physically-contiguous DMA buffer with streaming, 50 * @virt: kernel virtual address
42 asynchronous usage characteristics 51 * @dev: PCI device
43*/ 52 * @n_pages: number of kernel pages
44 53 * @n_dma_pages: number of IOMMU pages
54 * @sglist: IOMMU mapping
55 * @direction: PCI_DMA_TODEVICE, etc.
56 *
57 * a large, non-physically-contiguous DMA buffer with streaming, asynchronous
58 * usage characteristics
59 */
45struct dma_region { 60struct dma_region {
46 unsigned char *kvirt; /* kernel virtual address */ 61 unsigned char *kvirt;
47 struct pci_dev *dev; /* PCI device */ 62 struct pci_dev *dev;
48 unsigned int n_pages; /* # of kernel pages */ 63 unsigned int n_pages;
49 unsigned int n_dma_pages; /* # of IOMMU pages */ 64 unsigned int n_dma_pages;
50 struct scatterlist *sglist; /* IOMMU mapping */ 65 struct scatterlist *sglist;
51 int direction; /* PCI_DMA_TODEVICE, etc */ 66 int direction;
52}; 67};
53 68
54/* clear out all fields but do not allocate anything */ 69/* clear out all fields but do not allocate anything */
55void dma_region_init(struct dma_region *dma); 70void dma_region_init(struct dma_region *dma);
56 71
57/* allocate the buffer and map it to the IOMMU */ 72/* allocate the buffer and map it to the IOMMU */
58int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes, struct pci_dev *dev, int direction); 73int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
74 struct pci_dev *dev, int direction);
59 75
60/* unmap and free the buffer */ 76/* unmap and free the buffer */
61void dma_region_free(struct dma_region *dma); 77void dma_region_free(struct dma_region *dma);
62 78
63/* sync the CPU's view of the buffer */ 79/* sync the CPU's view of the buffer */
64void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset, unsigned long len); 80void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset,
81 unsigned long len);
82
65/* sync the IO bus' view of the buffer */ 83/* sync the IO bus' view of the buffer */
66void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset, unsigned long len); 84void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset,
85 unsigned long len);
67 86
68/* map the buffer into a user space process */ 87/* map the buffer into a user space process */
69int dma_region_mmap(struct dma_region *dma, struct file *file, struct vm_area_struct *vma); 88int dma_region_mmap(struct dma_region *dma, struct file *file,
89 struct vm_area_struct *vma);
70 90
71/* macro to index into a DMA region (or dma_prog_region) */ 91/* macro to index into a DMA region (or dma_prog_region) */
72#define dma_region_i(_dma, _type, _index) ( ((_type*) ((_dma)->kvirt)) + (_index) ) 92#define dma_region_i(_dma, _type, _index) \
93 ( ((_type*) ((_dma)->kvirt)) + (_index) )
73 94
74/* return the DMA bus address of the byte with the given offset 95/* return the DMA bus address of the byte with the given offset
75 relative to the beginning of the dma_region */ 96 * relative to the beginning of the dma_region */
76dma_addr_t dma_region_offset_to_bus(struct dma_region *dma, unsigned long offset); 97dma_addr_t dma_region_offset_to_bus(struct dma_region *dma,
98 unsigned long offset);
77 99
78#endif /* IEEE1394_DMA_H */ 100#endif /* IEEE1394_DMA_H */
diff --git a/drivers/ieee1394/dv1394-private.h b/drivers/ieee1394/dv1394-private.h
index 80b5ac7fe383..7d1d2845b420 100644
--- a/drivers/ieee1394/dv1394-private.h
+++ b/drivers/ieee1394/dv1394-private.h
@@ -460,7 +460,7 @@ struct video_card {
460 int dma_running; 460 int dma_running;
461 461
462 /* 462 /*
463 3) the sleeping semaphore 'sem' - this is used from process context only, 463 3) the sleeping mutex 'mtx' - this is used from process context only,
464 to serialize various operations on the video_card. Even though only one 464 to serialize various operations on the video_card. Even though only one
465 open() is allowed, we still need to prevent multiple threads of execution 465 open() is allowed, we still need to prevent multiple threads of execution
466 from entering calls like read, write, ioctl, etc. 466 from entering calls like read, write, ioctl, etc.
@@ -468,9 +468,9 @@ struct video_card {
468 I honestly can't think of a good reason to use dv1394 from several threads 468 I honestly can't think of a good reason to use dv1394 from several threads
469 at once, but we need to serialize anyway to prevent oopses =). 469 at once, but we need to serialize anyway to prevent oopses =).
470 470
471 NOTE: if you need both spinlock and sem, take sem first to avoid deadlock! 471 NOTE: if you need both spinlock and mtx, take mtx first to avoid deadlock!
472 */ 472 */
473 struct semaphore sem; 473 struct mutex mtx;
474 474
475 /* people waiting for buffer space, please form a line here... */ 475 /* people waiting for buffer space, please form a line here... */
476 wait_queue_head_t waitq; 476 wait_queue_head_t waitq;
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
index 87532dd43374..6e71d68b1099 100644
--- a/drivers/ieee1394/dv1394.c
+++ b/drivers/ieee1394/dv1394.c
@@ -95,6 +95,7 @@
95#include <linux/fs.h> 95#include <linux/fs.h>
96#include <linux/poll.h> 96#include <linux/poll.h>
97#include <linux/smp_lock.h> 97#include <linux/smp_lock.h>
98#include <linux/mutex.h>
98#include <linux/bitops.h> 99#include <linux/bitops.h>
99#include <asm/byteorder.h> 100#include <asm/byteorder.h>
100#include <asm/atomic.h> 101#include <asm/atomic.h>
@@ -110,15 +111,15 @@
110#include <linux/compat.h> 111#include <linux/compat.h>
111#include <linux/cdev.h> 112#include <linux/cdev.h>
112 113
114#include "dv1394.h"
115#include "dv1394-private.h"
116#include "highlevel.h"
117#include "hosts.h"
113#include "ieee1394.h" 118#include "ieee1394.h"
119#include "ieee1394_core.h"
120#include "ieee1394_hotplug.h"
114#include "ieee1394_types.h" 121#include "ieee1394_types.h"
115#include "nodemgr.h" 122#include "nodemgr.h"
116#include "hosts.h"
117#include "ieee1394_core.h"
118#include "highlevel.h"
119#include "dv1394.h"
120#include "dv1394-private.h"
121
122#include "ohci1394.h" 123#include "ohci1394.h"
123 124
124/* DEBUG LEVELS: 125/* DEBUG LEVELS:
@@ -247,7 +248,7 @@ static void frame_delete(struct frame *f)
247 248
248 Frame_prepare() must be called OUTSIDE the video->spinlock. 249 Frame_prepare() must be called OUTSIDE the video->spinlock.
249 However, frame_prepare() must still be serialized, so 250 However, frame_prepare() must still be serialized, so
250 it should be called WITH the video->sem taken. 251 it should be called WITH the video->mtx taken.
251 */ 252 */
252 253
253static void frame_prepare(struct video_card *video, unsigned int this_frame) 254static void frame_prepare(struct video_card *video, unsigned int this_frame)
@@ -1271,7 +1272,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma)
1271 int retval = -EINVAL; 1272 int retval = -EINVAL;
1272 1273
1273 /* serialize mmap */ 1274 /* serialize mmap */
1274 down(&video->sem); 1275 mutex_lock(&video->mtx);
1275 1276
1276 if ( ! video_card_initialized(video) ) { 1277 if ( ! video_card_initialized(video) ) {
1277 retval = do_dv1394_init_default(video); 1278 retval = do_dv1394_init_default(video);
@@ -1281,7 +1282,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma)
1281 1282
1282 retval = dma_region_mmap(&video->dv_buf, file, vma); 1283 retval = dma_region_mmap(&video->dv_buf, file, vma);
1283out: 1284out:
1284 up(&video->sem); 1285 mutex_unlock(&video->mtx);
1285 return retval; 1286 return retval;
1286} 1287}
1287 1288
@@ -1337,17 +1338,17 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t
1337 1338
1338 /* serialize this to prevent multi-threaded mayhem */ 1339 /* serialize this to prevent multi-threaded mayhem */
1339 if (file->f_flags & O_NONBLOCK) { 1340 if (file->f_flags & O_NONBLOCK) {
1340 if (down_trylock(&video->sem)) 1341 if (!mutex_trylock(&video->mtx))
1341 return -EAGAIN; 1342 return -EAGAIN;
1342 } else { 1343 } else {
1343 if (down_interruptible(&video->sem)) 1344 if (mutex_lock_interruptible(&video->mtx))
1344 return -ERESTARTSYS; 1345 return -ERESTARTSYS;
1345 } 1346 }
1346 1347
1347 if ( !video_card_initialized(video) ) { 1348 if ( !video_card_initialized(video) ) {
1348 ret = do_dv1394_init_default(video); 1349 ret = do_dv1394_init_default(video);
1349 if (ret) { 1350 if (ret) {
1350 up(&video->sem); 1351 mutex_unlock(&video->mtx);
1351 return ret; 1352 return ret;
1352 } 1353 }
1353 } 1354 }
@@ -1418,7 +1419,7 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t
1418 1419
1419 remove_wait_queue(&video->waitq, &wait); 1420 remove_wait_queue(&video->waitq, &wait);
1420 set_current_state(TASK_RUNNING); 1421 set_current_state(TASK_RUNNING);
1421 up(&video->sem); 1422 mutex_unlock(&video->mtx);
1422 return ret; 1423 return ret;
1423} 1424}
1424 1425
@@ -1434,17 +1435,17 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count
1434 1435
1435 /* serialize this to prevent multi-threaded mayhem */ 1436 /* serialize this to prevent multi-threaded mayhem */
1436 if (file->f_flags & O_NONBLOCK) { 1437 if (file->f_flags & O_NONBLOCK) {
1437 if (down_trylock(&video->sem)) 1438 if (!mutex_trylock(&video->mtx))
1438 return -EAGAIN; 1439 return -EAGAIN;
1439 } else { 1440 } else {
1440 if (down_interruptible(&video->sem)) 1441 if (mutex_lock_interruptible(&video->mtx))
1441 return -ERESTARTSYS; 1442 return -ERESTARTSYS;
1442 } 1443 }
1443 1444
1444 if ( !video_card_initialized(video) ) { 1445 if ( !video_card_initialized(video) ) {
1445 ret = do_dv1394_init_default(video); 1446 ret = do_dv1394_init_default(video);
1446 if (ret) { 1447 if (ret) {
1447 up(&video->sem); 1448 mutex_unlock(&video->mtx);
1448 return ret; 1449 return ret;
1449 } 1450 }
1450 video->continuity_counter = -1; 1451 video->continuity_counter = -1;
@@ -1526,7 +1527,7 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count
1526 1527
1527 remove_wait_queue(&video->waitq, &wait); 1528 remove_wait_queue(&video->waitq, &wait);
1528 set_current_state(TASK_RUNNING); 1529 set_current_state(TASK_RUNNING);
1529 up(&video->sem); 1530 mutex_unlock(&video->mtx);
1530 return ret; 1531 return ret;
1531} 1532}
1532 1533
@@ -1547,12 +1548,12 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1547 1548
1548 /* serialize this to prevent multi-threaded mayhem */ 1549 /* serialize this to prevent multi-threaded mayhem */
1549 if (file->f_flags & O_NONBLOCK) { 1550 if (file->f_flags & O_NONBLOCK) {
1550 if (down_trylock(&video->sem)) { 1551 if (!mutex_trylock(&video->mtx)) {
1551 unlock_kernel(); 1552 unlock_kernel();
1552 return -EAGAIN; 1553 return -EAGAIN;
1553 } 1554 }
1554 } else { 1555 } else {
1555 if (down_interruptible(&video->sem)) { 1556 if (mutex_lock_interruptible(&video->mtx)) {
1556 unlock_kernel(); 1557 unlock_kernel();
1557 return -ERESTARTSYS; 1558 return -ERESTARTSYS;
1558 } 1559 }
@@ -1778,7 +1779,7 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1778 } 1779 }
1779 1780
1780 out: 1781 out:
1781 up(&video->sem); 1782 mutex_unlock(&video->mtx);
1782 unlock_kernel(); 1783 unlock_kernel();
1783 return ret; 1784 return ret;
1784} 1785}
@@ -2253,7 +2254,7 @@ static int dv1394_init(struct ti_ohci *ohci, enum pal_or_ntsc format, enum modes
2253 clear_bit(0, &video->open); 2254 clear_bit(0, &video->open);
2254 spin_lock_init(&video->spinlock); 2255 spin_lock_init(&video->spinlock);
2255 video->dma_running = 0; 2256 video->dma_running = 0;
2256 init_MUTEX(&video->sem); 2257 mutex_init(&video->mtx);
2257 init_waitqueue_head(&video->waitq); 2258 init_waitqueue_head(&video->waitq);
2258 video->fasync = NULL; 2259 video->fasync = NULL;
2259 2260
diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c
index 2d5b57be98c3..09826be86aad 100644
--- a/drivers/ieee1394/eth1394.c
+++ b/drivers/ieee1394/eth1394.c
@@ -67,16 +67,17 @@
67#include <asm/semaphore.h> 67#include <asm/semaphore.h>
68#include <net/arp.h> 68#include <net/arp.h>
69 69
70#include "config_roms.h"
70#include "csr1212.h" 71#include "csr1212.h"
71#include "ieee1394_types.h" 72#include "eth1394.h"
73#include "highlevel.h"
74#include "ieee1394.h"
72#include "ieee1394_core.h" 75#include "ieee1394_core.h"
76#include "ieee1394_hotplug.h"
73#include "ieee1394_transactions.h" 77#include "ieee1394_transactions.h"
74#include "ieee1394.h" 78#include "ieee1394_types.h"
75#include "highlevel.h"
76#include "iso.h" 79#include "iso.h"
77#include "nodemgr.h" 80#include "nodemgr.h"
78#include "eth1394.h"
79#include "config_roms.h"
80 81
81#define ETH1394_PRINT_G(level, fmt, args...) \ 82#define ETH1394_PRINT_G(level, fmt, args...) \
82 printk(level "%s: " fmt, driver_name, ## args) 83 printk(level "%s: " fmt, driver_name, ## args)
diff --git a/drivers/ieee1394/highlevel.h b/drivers/ieee1394/highlevel.h
index e119fb87e5b5..50f2dd2c7e20 100644
--- a/drivers/ieee1394/highlevel.h
+++ b/drivers/ieee1394/highlevel.h
@@ -1,60 +1,61 @@
1
2#ifndef IEEE1394_HIGHLEVEL_H 1#ifndef IEEE1394_HIGHLEVEL_H
3#define IEEE1394_HIGHLEVEL_H 2#define IEEE1394_HIGHLEVEL_H
4 3
4#include <linux/list.h>
5#include <linux/spinlock_types.h>
6#include <linux/types.h>
5 7
6struct hpsb_address_serve { 8struct module;
7 struct list_head host_list; /* per host list */
8 9
9 struct list_head hl_list; /* hpsb_highlevel list */ 10#include "ieee1394_types.h"
10 11
11 struct hpsb_address_ops *op; 12struct hpsb_host;
12 13
14/* internal to ieee1394 core */
15struct hpsb_address_serve {
16 struct list_head host_list; /* per host list */
17 struct list_head hl_list; /* hpsb_highlevel list */
18 struct hpsb_address_ops *op;
13 struct hpsb_host *host; 19 struct hpsb_host *host;
14 20 u64 start; /* first address handled, quadlet aligned */
15 /* first address handled and first address behind, quadlet aligned */ 21 u64 end; /* first address behind, quadlet aligned */
16 u64 start, end;
17}; 22};
18 23
19 24/* Only the following structures are of interest to actual highlevel drivers. */
20/*
21 * The above structs are internal to highlevel driver handling. Only the
22 * following structures are of interest to actual highlevel drivers.
23 */
24 25
25struct hpsb_highlevel { 26struct hpsb_highlevel {
26 struct module *owner; 27 struct module *owner;
27 const char *name; 28 const char *name;
28 29
29 /* Any of the following pointers can legally be NULL, except for 30 /* Any of the following pointers can legally be NULL, except for
30 * iso_receive which can only be NULL when you don't request 31 * iso_receive which can only be NULL when you don't request
31 * channels. */ 32 * channels. */
32 33
33 /* New host initialized. Will also be called during 34 /* New host initialized. Will also be called during
34 * hpsb_register_highlevel for all hosts already installed. */ 35 * hpsb_register_highlevel for all hosts already installed. */
35 void (*add_host) (struct hpsb_host *host); 36 void (*add_host)(struct hpsb_host *host);
36 37
37 /* Host about to be removed. Will also be called during 38 /* Host about to be removed. Will also be called during
38 * hpsb_unregister_highlevel once for each host. */ 39 * hpsb_unregister_highlevel once for each host. */
39 void (*remove_host) (struct hpsb_host *host); 40 void (*remove_host)(struct hpsb_host *host);
40 41
41 /* Host experienced bus reset with possible configuration changes. 42 /* Host experienced bus reset with possible configuration changes.
42 * Note that this one may occur during interrupt/bottom half handling. 43 * Note that this one may occur during interrupt/bottom half handling.
43 * You can not expect to be able to do stock hpsb_reads. */ 44 * You can not expect to be able to do stock hpsb_reads. */
44 void (*host_reset) (struct hpsb_host *host); 45 void (*host_reset)(struct hpsb_host *host);
45 46
46 /* An isochronous packet was received. Channel contains the channel 47 /* An isochronous packet was received. Channel contains the channel
47 * number for your convenience, it is also contained in the included 48 * number for your convenience, it is also contained in the included
48 * packet header (first quadlet, CRCs are missing). You may get called 49 * packet header (first quadlet, CRCs are missing). You may get called
49 * for channel/host combinations you did not request. */ 50 * for channel/host combinations you did not request. */
50 void (*iso_receive) (struct hpsb_host *host, int channel, 51 void (*iso_receive)(struct hpsb_host *host, int channel,
51 quadlet_t *data, size_t length); 52 quadlet_t *data, size_t length);
52 53
53 /* A write request was received on either the FCP_COMMAND (direction = 54 /* A write request was received on either the FCP_COMMAND (direction =
54 * 0) or the FCP_RESPONSE (direction = 1) register. The cts arg 55 * 0) or the FCP_RESPONSE (direction = 1) register. The cts arg
55 * contains the cts field (first byte of data). */ 56 * contains the cts field (first byte of data). */
56 void (*fcp_request) (struct hpsb_host *host, int nodeid, int direction, 57 void (*fcp_request)(struct hpsb_host *host, int nodeid, int direction,
57 int cts, u8 *data, size_t length); 58 int cts, u8 *data, size_t length);
58 59
59 /* These are initialized by the subsystem when the 60 /* These are initialized by the subsystem when the
60 * hpsb_higlevel is registered. */ 61 * hpsb_higlevel is registered. */
@@ -67,61 +68,62 @@ struct hpsb_highlevel {
67}; 68};
68 69
69struct hpsb_address_ops { 70struct hpsb_address_ops {
70 /* 71 /*
71 * Null function pointers will make the respective operation complete 72 * Null function pointers will make the respective operation complete
72 * with RCODE_TYPE_ERROR. Makes for easy to implement read-only 73 * with RCODE_TYPE_ERROR. Makes for easy to implement read-only
73 * registers (just leave everything but read NULL). 74 * registers (just leave everything but read NULL).
74 * 75 *
75 * All functions shall return appropriate IEEE 1394 rcodes. 76 * All functions shall return appropriate IEEE 1394 rcodes.
76 */ 77 */
77 78
78 /* These functions have to implement block reads for themselves. */ 79 /* These functions have to implement block reads for themselves.
79 /* These functions either return a response code 80 *
80 or a negative number. In the first case a response will be generated; in the 81 * These functions either return a response code or a negative number.
81 later case, no response will be sent and the driver, that handled the request 82 * In the first case a response will be generated. In the latter case,
82 will send the response itself 83 * no response will be sent and the driver which handled the request
83 */ 84 * will send the response itself. */
84 int (*read) (struct hpsb_host *host, int nodeid, quadlet_t *buffer, 85 int (*read)(struct hpsb_host *host, int nodeid, quadlet_t *buffer,
85 u64 addr, size_t length, u16 flags); 86 u64 addr, size_t length, u16 flags);
86 int (*write) (struct hpsb_host *host, int nodeid, int destid, 87 int (*write)(struct hpsb_host *host, int nodeid, int destid,
87 quadlet_t *data, u64 addr, size_t length, u16 flags); 88 quadlet_t *data, u64 addr, size_t length, u16 flags);
88 89
89 /* Lock transactions: write results of ext_tcode operation into 90 /* Lock transactions: write results of ext_tcode operation into
90 * *store. */ 91 * *store. */
91 int (*lock) (struct hpsb_host *host, int nodeid, quadlet_t *store, 92 int (*lock)(struct hpsb_host *host, int nodeid, quadlet_t *store,
92 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, u16 flags); 93 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
93 int (*lock64) (struct hpsb_host *host, int nodeid, octlet_t *store, 94 u16 flags);
94 u64 addr, octlet_t data, octlet_t arg, int ext_tcode, u16 flags); 95 int (*lock64)(struct hpsb_host *host, int nodeid, octlet_t *store,
96 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
97 u16 flags);
95}; 98};
96 99
97
98void highlevel_add_host(struct hpsb_host *host); 100void highlevel_add_host(struct hpsb_host *host);
99void highlevel_remove_host(struct hpsb_host *host); 101void highlevel_remove_host(struct hpsb_host *host);
100void highlevel_host_reset(struct hpsb_host *host); 102void highlevel_host_reset(struct hpsb_host *host);
101 103
102 104/*
103/* these functions are called to handle transactions. They are called, when 105 * These functions are called to handle transactions. They are called when a
104 a packet arrives. The flags argument contains the second word of the first header 106 * packet arrives. The flags argument contains the second word of the first
105 quadlet of the incoming packet (containing transaction label, retry code, 107 * header quadlet of the incoming packet (containing transaction label, retry
106 transaction code and priority). These functions either return a response code 108 * code, transaction code and priority). These functions either return a
107 or a negative number. In the first case a response will be generated; in the 109 * response code or a negative number. In the first case a response will be
108 later case, no response will be sent and the driver, that handled the request 110 * generated. In the latter case, no response will be sent and the driver which
109 will send the response itself. 111 * handled the request will send the response itself.
110*/ 112 */
111int highlevel_read(struct hpsb_host *host, int nodeid, void *data, 113int highlevel_read(struct hpsb_host *host, int nodeid, void *data, u64 addr,
112 u64 addr, unsigned int length, u16 flags); 114 unsigned int length, u16 flags);
113int highlevel_write(struct hpsb_host *host, int nodeid, int destid, 115int highlevel_write(struct hpsb_host *host, int nodeid, int destid, void *data,
114 void *data, u64 addr, unsigned int length, u16 flags); 116 u64 addr, unsigned int length, u16 flags);
115int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store, 117int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store,
116 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, u16 flags); 118 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
119 u16 flags);
117int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store, 120int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store,
118 u64 addr, octlet_t data, octlet_t arg, int ext_tcode, u16 flags); 121 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
122 u16 flags);
119 123
120void highlevel_iso_receive(struct hpsb_host *host, void *data, 124void highlevel_iso_receive(struct hpsb_host *host, void *data, size_t length);
121 size_t length);
122void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction, 125void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction,
123 void *data, size_t length); 126 void *data, size_t length);
124
125 127
126/* 128/*
127 * Register highlevel driver. The name pointer has to stay valid at all times 129 * Register highlevel driver. The name pointer has to stay valid at all times
@@ -132,13 +134,15 @@ void hpsb_unregister_highlevel(struct hpsb_highlevel *hl);
132 134
133/* 135/*
134 * Register handlers for host address spaces. Start and end are 48 bit pointers 136 * Register handlers for host address spaces. Start and end are 48 bit pointers
135 * and have to be quadlet aligned (end points to the first address behind the 137 * and have to be quadlet aligned. Argument "end" points to the first address
136 * handled addresses. This function can be called multiple times for a single 138 * behind the handled addresses. This function can be called multiple times for
137 * hpsb_highlevel to implement sparse register sets. The requested region must 139 * a single hpsb_highlevel to implement sparse register sets. The requested
138 * not overlap any previously allocated region, otherwise registering will fail. 140 * region must not overlap any previously allocated region, otherwise
141 * registering will fail.
139 * 142 *
140 * It returns true for successful allocation. There is no unregister function, 143 * It returns true for successful allocation. Address spaces can be
141 * all address spaces are deallocated together with the hpsb_highlevel. 144 * unregistered with hpsb_unregister_addrspace. All remaining address spaces
145 * are automatically deallocated together with the hpsb_highlevel.
142 */ 146 */
143u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl, 147u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
144 struct hpsb_host *host, 148 struct hpsb_host *host,
@@ -146,20 +150,18 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
146 u64 size, u64 alignment, 150 u64 size, u64 alignment,
147 u64 start, u64 end); 151 u64 start, u64 end);
148int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, 152int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
149 struct hpsb_address_ops *ops, u64 start, u64 end); 153 struct hpsb_address_ops *ops, u64 start, u64 end);
150
151int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, 154int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
152 u64 start); 155 u64 start);
153 156
154/* 157/*
155 * Enable or disable receving a certain isochronous channel through the 158 * Enable or disable receving a certain isochronous channel through the
156 * iso_receive op. 159 * iso_receive op.
157 */ 160 */
158int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, 161int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
159 unsigned int channel); 162 unsigned int channel);
160void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, 163void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
161 unsigned int channel); 164 unsigned int channel);
162
163 165
164/* Retrieve a hostinfo pointer bound to this driver/host */ 166/* Retrieve a hostinfo pointer bound to this driver/host */
165void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host); 167void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host);
@@ -172,19 +174,24 @@ void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
172void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host); 174void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host);
173 175
174/* Set an alternate lookup key for the hostinfo bound to this driver/host */ 176/* Set an alternate lookup key for the hostinfo bound to this driver/host */
175void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host, unsigned long key); 177void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host,
178 unsigned long key);
176 179
177/* Retrieve the alternate lookup key for the hostinfo bound to this driver/host */ 180/* Retrieve the alternate lookup key for the hostinfo bound to this
178unsigned long hpsb_get_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host); 181 * driver/host */
182unsigned long hpsb_get_hostinfo_key(struct hpsb_highlevel *hl,
183 struct hpsb_host *host);
179 184
180/* Retrieve a hostinfo pointer bound to this driver using its alternate key */ 185/* Retrieve a hostinfo pointer bound to this driver using its alternate key */
181void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key); 186void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key);
182 187
183/* Set the hostinfo pointer to something useful. Usually follows a call to 188/* Set the hostinfo pointer to something useful. Usually follows a call to
184 * hpsb_create_hostinfo, where the size is 0. */ 189 * hpsb_create_hostinfo, where the size is 0. */
185int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, void *data); 190int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
191 void *data);
186 192
187/* Retrieve hpsb_host using a highlevel handle and a key */ 193/* Retrieve hpsb_host using a highlevel handle and a key */
188struct hpsb_host *hpsb_get_host_bykey(struct hpsb_highlevel *hl, unsigned long key); 194struct hpsb_host *hpsb_get_host_bykey(struct hpsb_highlevel *hl,
195 unsigned long key);
189 196
190#endif /* IEEE1394_HIGHLEVEL_H */ 197#endif /* IEEE1394_HIGHLEVEL_H */
diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c
index 4feead4a35c5..59e6f49545bf 100644
--- a/drivers/ieee1394/hosts.c
+++ b/drivers/ieee1394/hosts.c
@@ -90,6 +90,16 @@ static int alloc_hostnum_cb(struct hpsb_host *host, void *__data)
90 return 0; 90 return 0;
91} 91}
92 92
93/*
94 * The pending_packet_queue is special in that it's processed
95 * from hardirq context too (such as hpsb_bus_reset()). Hence
96 * split the lock class from the usual networking skb-head
97 * lock class by using a separate key for it:
98 */
99static struct lock_class_key pending_packet_queue_key;
100
101static DEFINE_MUTEX(host_num_alloc);
102
93/** 103/**
94 * hpsb_alloc_host - allocate a new host controller. 104 * hpsb_alloc_host - allocate a new host controller.
95 * @drv: the driver that will manage the host controller 105 * @drv: the driver that will manage the host controller
@@ -105,16 +115,6 @@ static int alloc_hostnum_cb(struct hpsb_host *host, void *__data)
105 * Return Value: a pointer to the &hpsb_host if successful, %NULL if 115 * Return Value: a pointer to the &hpsb_host if successful, %NULL if
106 * no memory was available. 116 * no memory was available.
107 */ 117 */
108static DEFINE_MUTEX(host_num_alloc);
109
110/*
111 * The pending_packet_queue is special in that it's processed
112 * from hardirq context too (such as hpsb_bus_reset()). Hence
113 * split the lock class from the usual networking skb-head
114 * lock class by using a separate key for it:
115 */
116static struct lock_class_key pending_packet_queue_key;
117
118struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra, 118struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
119 struct device *dev) 119 struct device *dev)
120{ 120{
diff --git a/drivers/ieee1394/hosts.h b/drivers/ieee1394/hosts.h
index 9ad4b2463077..69a7c9ff5ed7 100644
--- a/drivers/ieee1394/hosts.h
+++ b/drivers/ieee1394/hosts.h
@@ -2,17 +2,19 @@
2#define _IEEE1394_HOSTS_H 2#define _IEEE1394_HOSTS_H
3 3
4#include <linux/device.h> 4#include <linux/device.h>
5#include <linux/wait.h>
6#include <linux/list.h> 5#include <linux/list.h>
7#include <linux/timer.h>
8#include <linux/skbuff.h> 6#include <linux/skbuff.h>
7#include <linux/timer.h>
8#include <linux/types.h>
9#include <linux/workqueue.h>
10#include <asm/atomic.h>
9 11
10#include <asm/semaphore.h> 12struct pci_dev;
13struct module;
11 14
12#include "ieee1394_types.h" 15#include "ieee1394_types.h"
13#include "csr.h" 16#include "csr.h"
14 17
15
16struct hpsb_packet; 18struct hpsb_packet;
17struct hpsb_iso; 19struct hpsb_iso;
18 20
@@ -112,7 +114,7 @@ enum devctl_cmd {
112 114
113enum isoctl_cmd { 115enum isoctl_cmd {
114 /* rawiso API - see iso.h for the meanings of these commands 116 /* rawiso API - see iso.h for the meanings of these commands
115 (they correspond exactly to the hpsb_iso_* API functions) 117 * (they correspond exactly to the hpsb_iso_* API functions)
116 * INIT = allocate resources 118 * INIT = allocate resources
117 * START = begin transmission/reception 119 * START = begin transmission/reception
118 * STOP = halt transmission/reception 120 * STOP = halt transmission/reception
@@ -160,7 +162,8 @@ struct hpsb_host_driver {
160 /* The hardware driver may optionally support a function that is used 162 /* The hardware driver may optionally support a function that is used
161 * to set the hardware ConfigROM if the hardware supports handling 163 * to set the hardware ConfigROM if the hardware supports handling
162 * reads to the ConfigROM on its own. */ 164 * reads to the ConfigROM on its own. */
163 void (*set_hw_config_rom) (struct hpsb_host *host, quadlet_t *config_rom); 165 void (*set_hw_config_rom)(struct hpsb_host *host,
166 quadlet_t *config_rom);
164 167
165 /* This function shall implement packet transmission based on 168 /* This function shall implement packet transmission based on
166 * packet->type. It shall CRC both parts of the packet (unless 169 * packet->type. It shall CRC both parts of the packet (unless
@@ -170,20 +173,21 @@ struct hpsb_host_driver {
170 * called. Return 0 on success, negative errno on failure. 173 * called. Return 0 on success, negative errno on failure.
171 * NOTE: The function must be callable in interrupt context. 174 * NOTE: The function must be callable in interrupt context.
172 */ 175 */
173 int (*transmit_packet) (struct hpsb_host *host, 176 int (*transmit_packet)(struct hpsb_host *host,
174 struct hpsb_packet *packet); 177 struct hpsb_packet *packet);
175 178
176 /* This function requests miscellanous services from the driver, see 179 /* This function requests miscellanous services from the driver, see
177 * above for command codes and expected actions. Return -1 for unknown 180 * above for command codes and expected actions. Return -1 for unknown
178 * command, though that should never happen. 181 * command, though that should never happen.
179 */ 182 */
180 int (*devctl) (struct hpsb_host *host, enum devctl_cmd command, int arg); 183 int (*devctl)(struct hpsb_host *host, enum devctl_cmd command, int arg);
181 184
182 /* ISO transmission/reception functions. Return 0 on success, -1 185 /* ISO transmission/reception functions. Return 0 on success, -1
183 * (or -EXXX errno code) on failure. If the low-level driver does not 186 * (or -EXXX errno code) on failure. If the low-level driver does not
184 * support the new ISO API, set isoctl to NULL. 187 * support the new ISO API, set isoctl to NULL.
185 */ 188 */
186 int (*isoctl) (struct hpsb_iso *iso, enum isoctl_cmd command, unsigned long arg); 189 int (*isoctl)(struct hpsb_iso *iso, enum isoctl_cmd command,
190 unsigned long arg);
187 191
188 /* This function is mainly to redirect local CSR reads/locks to the iso 192 /* This function is mainly to redirect local CSR reads/locks to the iso
189 * management registers (bus manager id, bandwidth available, channels 193 * management registers (bus manager id, bandwidth available, channels
@@ -196,19 +200,11 @@ struct hpsb_host_driver {
196 quadlet_t data, quadlet_t compare); 200 quadlet_t data, quadlet_t compare);
197}; 201};
198 202
199
200struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra, 203struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
201 struct device *dev); 204 struct device *dev);
202int hpsb_add_host(struct hpsb_host *host); 205int hpsb_add_host(struct hpsb_host *host);
203void hpsb_remove_host(struct hpsb_host *h); 206void hpsb_remove_host(struct hpsb_host *h);
204 207
205/* The following 2 functions are deprecated and will be removed when the
206 * raw1394/libraw1394 update is complete. */
207int hpsb_update_config_rom(struct hpsb_host *host,
208 const quadlet_t *new_rom, size_t size, unsigned char rom_version);
209int hpsb_get_config_rom(struct hpsb_host *host, quadlet_t *buffer,
210 size_t buffersize, size_t *rom_size, unsigned char *rom_version);
211
212/* Updates the configuration rom image of a host. rom_version must be the 208/* Updates the configuration rom image of a host. rom_version must be the
213 * current version, otherwise it will fail with return value -1. If this 209 * current version, otherwise it will fail with return value -1. If this
214 * host does not support config-rom-update, it will return -EINVAL. 210 * host does not support config-rom-update, it will return -EINVAL.
diff --git a/drivers/ieee1394/ieee1394-ioctl.h b/drivers/ieee1394/ieee1394-ioctl.h
index 156703986348..8f207508ed1d 100644
--- a/drivers/ieee1394/ieee1394-ioctl.h
+++ b/drivers/ieee1394/ieee1394-ioctl.h
@@ -1,5 +1,7 @@
1/* Base file for all ieee1394 ioctl's. Linux-1394 has allocated base '#' 1/*
2 * with a range of 0x00-0x3f. */ 2 * Base file for all ieee1394 ioctl's.
3 * Linux-1394 has allocated base '#' with a range of 0x00-0x3f.
4 */
3 5
4#ifndef __IEEE1394_IOCTL_H 6#ifndef __IEEE1394_IOCTL_H
5#define __IEEE1394_IOCTL_H 7#define __IEEE1394_IOCTL_H
@@ -96,8 +98,7 @@
96 _IOW ('#', 0x27, struct raw1394_iso_packets) 98 _IOW ('#', 0x27, struct raw1394_iso_packets)
97#define RAW1394_IOC_ISO_XMIT_SYNC \ 99#define RAW1394_IOC_ISO_XMIT_SYNC \
98 _IO ('#', 0x28) 100 _IO ('#', 0x28)
99#define RAW1394_IOC_ISO_RECV_FLUSH \ 101#define RAW1394_IOC_ISO_RECV_FLUSH \
100 _IO ('#', 0x29) 102 _IO ('#', 0x29)
101 103
102
103#endif /* __IEEE1394_IOCTL_H */ 104#endif /* __IEEE1394_IOCTL_H */
diff --git a/drivers/ieee1394/ieee1394.h b/drivers/ieee1394/ieee1394.h
index 936d776de00a..40492074c013 100644
--- a/drivers/ieee1394/ieee1394.h
+++ b/drivers/ieee1394/ieee1394.h
@@ -5,77 +5,78 @@
5#ifndef _IEEE1394_IEEE1394_H 5#ifndef _IEEE1394_IEEE1394_H
6#define _IEEE1394_IEEE1394_H 6#define _IEEE1394_IEEE1394_H
7 7
8#define TCODE_WRITEQ 0x0 8#define TCODE_WRITEQ 0x0
9#define TCODE_WRITEB 0x1 9#define TCODE_WRITEB 0x1
10#define TCODE_WRITE_RESPONSE 0x2 10#define TCODE_WRITE_RESPONSE 0x2
11#define TCODE_READQ 0x4 11#define TCODE_READQ 0x4
12#define TCODE_READB 0x5 12#define TCODE_READB 0x5
13#define TCODE_READQ_RESPONSE 0x6 13#define TCODE_READQ_RESPONSE 0x6
14#define TCODE_READB_RESPONSE 0x7 14#define TCODE_READB_RESPONSE 0x7
15#define TCODE_CYCLE_START 0x8 15#define TCODE_CYCLE_START 0x8
16#define TCODE_LOCK_REQUEST 0x9 16#define TCODE_LOCK_REQUEST 0x9
17#define TCODE_ISO_DATA 0xa 17#define TCODE_ISO_DATA 0xa
18#define TCODE_STREAM_DATA 0xa 18#define TCODE_STREAM_DATA 0xa
19#define TCODE_LOCK_RESPONSE 0xb 19#define TCODE_LOCK_RESPONSE 0xb
20 20
21#define RCODE_COMPLETE 0x0 21#define RCODE_COMPLETE 0x0
22#define RCODE_CONFLICT_ERROR 0x4 22#define RCODE_CONFLICT_ERROR 0x4
23#define RCODE_DATA_ERROR 0x5 23#define RCODE_DATA_ERROR 0x5
24#define RCODE_TYPE_ERROR 0x6 24#define RCODE_TYPE_ERROR 0x6
25#define RCODE_ADDRESS_ERROR 0x7 25#define RCODE_ADDRESS_ERROR 0x7
26 26
27#define EXTCODE_MASK_SWAP 0x1 27#define EXTCODE_MASK_SWAP 0x1
28#define EXTCODE_COMPARE_SWAP 0x2 28#define EXTCODE_COMPARE_SWAP 0x2
29#define EXTCODE_FETCH_ADD 0x3 29#define EXTCODE_FETCH_ADD 0x3
30#define EXTCODE_LITTLE_ADD 0x4 30#define EXTCODE_LITTLE_ADD 0x4
31#define EXTCODE_BOUNDED_ADD 0x5 31#define EXTCODE_BOUNDED_ADD 0x5
32#define EXTCODE_WRAP_ADD 0x6 32#define EXTCODE_WRAP_ADD 0x6
33 33
34#define ACK_COMPLETE 0x1 34#define ACK_COMPLETE 0x1
35#define ACK_PENDING 0x2 35#define ACK_PENDING 0x2
36#define ACK_BUSY_X 0x4 36#define ACK_BUSY_X 0x4
37#define ACK_BUSY_A 0x5 37#define ACK_BUSY_A 0x5
38#define ACK_BUSY_B 0x6 38#define ACK_BUSY_B 0x6
39#define ACK_TARDY 0xb 39#define ACK_TARDY 0xb
40#define ACK_CONFLICT_ERROR 0xc 40#define ACK_CONFLICT_ERROR 0xc
41#define ACK_DATA_ERROR 0xd 41#define ACK_DATA_ERROR 0xd
42#define ACK_TYPE_ERROR 0xe 42#define ACK_TYPE_ERROR 0xe
43#define ACK_ADDRESS_ERROR 0xf 43#define ACK_ADDRESS_ERROR 0xf
44 44
45/* Non-standard "ACK codes" for internal use */ 45/* Non-standard "ACK codes" for internal use */
46#define ACKX_NONE (-1) 46#define ACKX_NONE (-1)
47#define ACKX_SEND_ERROR (-2) 47#define ACKX_SEND_ERROR (-2)
48#define ACKX_ABORTED (-3) 48#define ACKX_ABORTED (-3)
49#define ACKX_TIMEOUT (-4) 49#define ACKX_TIMEOUT (-4)
50 50
51 51#define IEEE1394_SPEED_100 0x00
52#define IEEE1394_SPEED_100 0x00 52#define IEEE1394_SPEED_200 0x01
53#define IEEE1394_SPEED_200 0x01 53#define IEEE1394_SPEED_400 0x02
54#define IEEE1394_SPEED_400 0x02 54#define IEEE1394_SPEED_800 0x03
55#define IEEE1394_SPEED_800 0x03 55#define IEEE1394_SPEED_1600 0x04
56#define IEEE1394_SPEED_1600 0x04 56#define IEEE1394_SPEED_3200 0x05
57#define IEEE1394_SPEED_3200 0x05 57
58/* The current highest tested speed supported by the subsystem */ 58/* The current highest tested speed supported by the subsystem */
59#define IEEE1394_SPEED_MAX IEEE1394_SPEED_800 59#define IEEE1394_SPEED_MAX IEEE1394_SPEED_800
60 60
61/* Maps speed values above to a string representation */ 61/* Maps speed values above to a string representation */
62extern const char *hpsb_speedto_str[]; 62extern const char *hpsb_speedto_str[];
63 63
64
65/* 1394a cable PHY packets */ 64/* 1394a cable PHY packets */
66#define SELFID_PWRCL_NO_POWER 0x0 65#define SELFID_PWRCL_NO_POWER 0x0
67#define SELFID_PWRCL_PROVIDE_15W 0x1 66#define SELFID_PWRCL_PROVIDE_15W 0x1
68#define SELFID_PWRCL_PROVIDE_30W 0x2 67#define SELFID_PWRCL_PROVIDE_30W 0x2
69#define SELFID_PWRCL_PROVIDE_45W 0x3 68#define SELFID_PWRCL_PROVIDE_45W 0x3
70#define SELFID_PWRCL_USE_1W 0x4 69#define SELFID_PWRCL_USE_1W 0x4
71#define SELFID_PWRCL_USE_3W 0x5 70#define SELFID_PWRCL_USE_3W 0x5
72#define SELFID_PWRCL_USE_6W 0x6 71#define SELFID_PWRCL_USE_6W 0x6
73#define SELFID_PWRCL_USE_10W 0x7 72#define SELFID_PWRCL_USE_10W 0x7
74 73
75#define SELFID_PORT_CHILD 0x3 74#define SELFID_PORT_CHILD 0x3
76#define SELFID_PORT_PARENT 0x2 75#define SELFID_PORT_PARENT 0x2
77#define SELFID_PORT_NCONN 0x1 76#define SELFID_PORT_NCONN 0x1
78#define SELFID_PORT_NONE 0x0 77#define SELFID_PORT_NONE 0x0
78
79#define SELFID_SPEED_UNKNOWN 0x3 /* 1394b PHY */
79 80
80#define PHYPACKET_LINKON 0x40000000 81#define PHYPACKET_LINKON 0x40000000
81#define PHYPACKET_PHYCONFIG_R 0x00800000 82#define PHYPACKET_PHYCONFIG_R 0x00800000
@@ -91,76 +92,76 @@ extern const char *hpsb_speedto_str[];
91 92
92#define EXTPHYPACKET_TYPEMASK 0xC0FC0000 93#define EXTPHYPACKET_TYPEMASK 0xC0FC0000
93 94
94#define PHYPACKET_PORT_SHIFT 24 95#define PHYPACKET_PORT_SHIFT 24
95#define PHYPACKET_GAPCOUNT_SHIFT 16 96#define PHYPACKET_GAPCOUNT_SHIFT 16
96 97
97/* 1394a PHY register map bitmasks */ 98/* 1394a PHY register map bitmasks */
98#define PHY_00_PHYSICAL_ID 0xFC 99#define PHY_00_PHYSICAL_ID 0xFC
99#define PHY_00_R 0x02 /* Root */ 100#define PHY_00_R 0x02 /* Root */
100#define PHY_00_PS 0x01 /* Power Status*/ 101#define PHY_00_PS 0x01 /* Power Status*/
101#define PHY_01_RHB 0x80 /* Root Hold-Off */ 102#define PHY_01_RHB 0x80 /* Root Hold-Off */
102#define PHY_01_IBR 0x80 /* Initiate Bus Reset */ 103#define PHY_01_IBR 0x80 /* Initiate Bus Reset */
103#define PHY_01_GAP_COUNT 0x3F 104#define PHY_01_GAP_COUNT 0x3F
104#define PHY_02_EXTENDED 0xE0 /* 0x7 for 1394a-compliant PHY */ 105#define PHY_02_EXTENDED 0xE0 /* 0x7 for 1394a-compliant PHY */
105#define PHY_02_TOTAL_PORTS 0x1F 106#define PHY_02_TOTAL_PORTS 0x1F
106#define PHY_03_MAX_SPEED 0xE0 107#define PHY_03_MAX_SPEED 0xE0
107#define PHY_03_DELAY 0x0F 108#define PHY_03_DELAY 0x0F
108#define PHY_04_LCTRL 0x80 /* Link Active Report Control */ 109#define PHY_04_LCTRL 0x80 /* Link Active Report Control */
109#define PHY_04_CONTENDER 0x40 110#define PHY_04_CONTENDER 0x40
110#define PHY_04_JITTER 0x38 111#define PHY_04_JITTER 0x38
111#define PHY_04_PWR_CLASS 0x07 /* Power Class */ 112#define PHY_04_PWR_CLASS 0x07 /* Power Class */
112#define PHY_05_WATCHDOG 0x80 113#define PHY_05_WATCHDOG 0x80
113#define PHY_05_ISBR 0x40 /* Initiate Short Bus Reset */ 114#define PHY_05_ISBR 0x40 /* Initiate Short Bus Reset */
114#define PHY_05_LOOP 0x20 /* Loop Detect */ 115#define PHY_05_LOOP 0x20 /* Loop Detect */
115#define PHY_05_PWR_FAIL 0x10 /* Cable Power Failure Detect */ 116#define PHY_05_PWR_FAIL 0x10 /* Cable Power Failure Detect */
116#define PHY_05_TIMEOUT 0x08 /* Arbitration State Machine Timeout */ 117#define PHY_05_TIMEOUT 0x08 /* Arbitration State Machine Timeout */
117#define PHY_05_PORT_EVENT 0x04 /* Port Event Detect */ 118#define PHY_05_PORT_EVENT 0x04 /* Port Event Detect */
118#define PHY_05_ENAB_ACCEL 0x02 /* Enable Arbitration Acceleration */ 119#define PHY_05_ENAB_ACCEL 0x02 /* Enable Arbitration Acceleration */
119#define PHY_05_ENAB_MULTI 0x01 /* Ena. Multispeed Packet Concatenation */ 120#define PHY_05_ENAB_MULTI 0x01 /* Ena. Multispeed Packet Concatenation */
120 121
121#include <asm/byteorder.h> 122#include <asm/byteorder.h>
122 123
123#ifdef __BIG_ENDIAN_BITFIELD 124#ifdef __BIG_ENDIAN_BITFIELD
124 125
125struct selfid { 126struct selfid {
126 u32 packet_identifier:2; /* always binary 10 */ 127 u32 packet_identifier:2; /* always binary 10 */
127 u32 phy_id:6; 128 u32 phy_id:6;
128 /* byte */ 129 /* byte */
129 u32 extended:1; /* if true is struct ext_selfid */ 130 u32 extended:1; /* if true is struct ext_selfid */
130 u32 link_active:1; 131 u32 link_active:1;
131 u32 gap_count:6; 132 u32 gap_count:6;
132 /* byte */ 133 /* byte */
133 u32 speed:2; 134 u32 speed:2;
134 u32 phy_delay:2; 135 u32 phy_delay:2;
135 u32 contender:1; 136 u32 contender:1;
136 u32 power_class:3; 137 u32 power_class:3;
137 /* byte */ 138 /* byte */
138 u32 port0:2; 139 u32 port0:2;
139 u32 port1:2; 140 u32 port1:2;
140 u32 port2:2; 141 u32 port2:2;
141 u32 initiated_reset:1; 142 u32 initiated_reset:1;
142 u32 more_packets:1; 143 u32 more_packets:1;
143} __attribute__((packed)); 144} __attribute__((packed));
144 145
145struct ext_selfid { 146struct ext_selfid {
146 u32 packet_identifier:2; /* always binary 10 */ 147 u32 packet_identifier:2; /* always binary 10 */
147 u32 phy_id:6; 148 u32 phy_id:6;
148 /* byte */ 149 /* byte */
149 u32 extended:1; /* if false is struct selfid */ 150 u32 extended:1; /* if false is struct selfid */
150 u32 seq_nr:3; 151 u32 seq_nr:3;
151 u32 reserved:2; 152 u32 reserved:2;
152 u32 porta:2; 153 u32 porta:2;
153 /* byte */ 154 /* byte */
154 u32 portb:2; 155 u32 portb:2;
155 u32 portc:2; 156 u32 portc:2;
156 u32 portd:2; 157 u32 portd:2;
157 u32 porte:2; 158 u32 porte:2;
158 /* byte */ 159 /* byte */
159 u32 portf:2; 160 u32 portf:2;
160 u32 portg:2; 161 u32 portg:2;
161 u32 porth:2; 162 u32 porth:2;
162 u32 reserved2:1; 163 u32 reserved2:1;
163 u32 more_packets:1; 164 u32 more_packets:1;
164} __attribute__((packed)); 165} __attribute__((packed));
165 166
166#elif defined __LITTLE_ENDIAN_BITFIELD /* __BIG_ENDIAN_BITFIELD */ 167#elif defined __LITTLE_ENDIAN_BITFIELD /* __BIG_ENDIAN_BITFIELD */
@@ -171,49 +172,48 @@ struct ext_selfid {
171 */ 172 */
172 173
173struct selfid { 174struct selfid {
174 u32 phy_id:6; 175 u32 phy_id:6;
175 u32 packet_identifier:2; /* always binary 10 */ 176 u32 packet_identifier:2; /* always binary 10 */
176 /* byte */ 177 /* byte */
177 u32 gap_count:6; 178 u32 gap_count:6;
178 u32 link_active:1; 179 u32 link_active:1;
179 u32 extended:1; /* if true is struct ext_selfid */ 180 u32 extended:1; /* if true is struct ext_selfid */
180 /* byte */ 181 /* byte */
181 u32 power_class:3; 182 u32 power_class:3;
182 u32 contender:1; 183 u32 contender:1;
183 u32 phy_delay:2; 184 u32 phy_delay:2;
184 u32 speed:2; 185 u32 speed:2;
185 /* byte */ 186 /* byte */
186 u32 more_packets:1; 187 u32 more_packets:1;
187 u32 initiated_reset:1; 188 u32 initiated_reset:1;
188 u32 port2:2; 189 u32 port2:2;
189 u32 port1:2; 190 u32 port1:2;
190 u32 port0:2; 191 u32 port0:2;
191} __attribute__((packed)); 192} __attribute__((packed));
192 193
193struct ext_selfid { 194struct ext_selfid {
194 u32 phy_id:6; 195 u32 phy_id:6;
195 u32 packet_identifier:2; /* always binary 10 */ 196 u32 packet_identifier:2; /* always binary 10 */
196 /* byte */ 197 /* byte */
197 u32 porta:2; 198 u32 porta:2;
198 u32 reserved:2; 199 u32 reserved:2;
199 u32 seq_nr:3; 200 u32 seq_nr:3;
200 u32 extended:1; /* if false is struct selfid */ 201 u32 extended:1; /* if false is struct selfid */
201 /* byte */ 202 /* byte */
202 u32 porte:2; 203 u32 porte:2;
203 u32 portd:2; 204 u32 portd:2;
204 u32 portc:2; 205 u32 portc:2;
205 u32 portb:2; 206 u32 portb:2;
206 /* byte */ 207 /* byte */
207 u32 more_packets:1; 208 u32 more_packets:1;
208 u32 reserved2:1; 209 u32 reserved2:1;
209 u32 porth:2; 210 u32 porth:2;
210 u32 portg:2; 211 u32 portg:2;
211 u32 portf:2; 212 u32 portf:2;
212} __attribute__((packed)); 213} __attribute__((packed));
213 214
214#else 215#else
215#error What? PDP endian? 216#error What? PDP endian?
216#endif /* __BIG_ENDIAN_BITFIELD */ 217#endif /* __BIG_ENDIAN_BITFIELD */
217 218
218
219#endif /* _IEEE1394_IEEE1394_H */ 219#endif /* _IEEE1394_IEEE1394_H */
diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c
index f43739c5cab2..559c477092f8 100644
--- a/drivers/ieee1394/ieee1394_core.c
+++ b/drivers/ieee1394/ieee1394_core.c
@@ -355,10 +355,12 @@ static void build_speed_map(struct hpsb_host *host, int nodecount)
355 } 355 }
356 } 356 }
357 357
358#if SELFID_SPEED_UNKNOWN != IEEE1394_SPEED_MAX
358 /* assume maximum speed for 1394b PHYs, nodemgr will correct it */ 359 /* assume maximum speed for 1394b PHYs, nodemgr will correct it */
359 for (n = 0; n < nodecount; n++) 360 for (n = 0; n < nodecount; n++)
360 if (speedcap[n] == 3) 361 if (speedcap[n] == SELFID_SPEED_UNKNOWN)
361 speedcap[n] = IEEE1394_SPEED_MAX; 362 speedcap[n] = IEEE1394_SPEED_MAX;
363#endif
362} 364}
363 365
364 366
diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h
index 0ecbf335c64f..1ce172b28569 100644
--- a/drivers/ieee1394/ieee1394_core.h
+++ b/drivers/ieee1394/ieee1394_core.h
@@ -1,12 +1,16 @@
1
2#ifndef _IEEE1394_CORE_H 1#ifndef _IEEE1394_CORE_H
3#define _IEEE1394_CORE_H 2#define _IEEE1394_CORE_H
4 3
5#include <linux/slab.h> 4#include <linux/device.h>
5#include <linux/fs.h>
6#include <linux/list.h>
7#include <linux/skbuff.h>
8#include <linux/types.h>
6#include <asm/atomic.h> 9#include <asm/atomic.h>
7#include <asm/semaphore.h> 10#include <asm/semaphore.h>
8#include "hosts.h"
9 11
12#include "hosts.h"
13#include "ieee1394_types.h"
10 14
11struct hpsb_packet { 15struct hpsb_packet {
12 /* This struct is basically read-only for hosts with the exception of 16 /* This struct is basically read-only for hosts with the exception of
@@ -58,7 +62,6 @@ struct hpsb_packet {
58 size_t header_size; 62 size_t header_size;
59 size_t data_size; 63 size_t data_size;
60 64
61
62 struct hpsb_host *host; 65 struct hpsb_host *host;
63 unsigned int generation; 66 unsigned int generation;
64 67
@@ -80,7 +83,7 @@ struct hpsb_packet {
80 83
81/* Set a task for when a packet completes */ 84/* Set a task for when a packet completes */
82void hpsb_set_packet_complete_task(struct hpsb_packet *packet, 85void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
83 void (*routine)(void *), void *data); 86 void (*routine)(void *), void *data);
84 87
85static inline struct hpsb_packet *driver_packet(struct list_head *l) 88static inline struct hpsb_packet *driver_packet(struct list_head *l)
86{ 89{
@@ -92,7 +95,6 @@ void abort_timedouts(unsigned long __opaque);
92struct hpsb_packet *hpsb_alloc_packet(size_t data_size); 95struct hpsb_packet *hpsb_alloc_packet(size_t data_size);
93void hpsb_free_packet(struct hpsb_packet *packet); 96void hpsb_free_packet(struct hpsb_packet *packet);
94 97
95
96/* 98/*
97 * Generation counter for the complete 1394 subsystem. Generation gets 99 * Generation counter for the complete 1394 subsystem. Generation gets
98 * incremented on every change in the subsystem (e.g. bus reset). 100 * incremented on every change in the subsystem (e.g. bus reset).
@@ -204,10 +206,14 @@ void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
204#define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15 206#define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
205 207
206#define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0) 208#define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0)
207#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16) 209#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \
208#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_VIDEO1394 * 16) 210 IEEE1394_MINOR_BLOCK_RAW1394 * 16)
209#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16) 211#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \
210#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16) 212 IEEE1394_MINOR_BLOCK_VIDEO1394 * 16)
213#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \
214 IEEE1394_MINOR_BLOCK_DV1394 * 16)
215#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \
216 IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16)
211 217
212/* return the index (within a minor number block) of a file */ 218/* return the index (within a minor number block) of a file */
213static inline unsigned char ieee1394_file_to_instance(struct file *file) 219static inline unsigned char ieee1394_file_to_instance(struct file *file)
@@ -223,4 +229,3 @@ extern struct class hpsb_host_class;
223extern struct class *hpsb_protocol_class; 229extern struct class *hpsb_protocol_class;
224 230
225#endif /* _IEEE1394_CORE_H */ 231#endif /* _IEEE1394_CORE_H */
226
diff --git a/drivers/ieee1394/ieee1394_hotplug.h b/drivers/ieee1394/ieee1394_hotplug.h
index 5be70d31b007..dd5500ed8322 100644
--- a/drivers/ieee1394/ieee1394_hotplug.h
+++ b/drivers/ieee1394/ieee1394_hotplug.h
@@ -1,33 +1,19 @@
1#ifndef _IEEE1394_HOTPLUG_H 1#ifndef _IEEE1394_HOTPLUG_H
2#define _IEEE1394_HOTPLUG_H 2#define _IEEE1394_HOTPLUG_H
3 3
4#include <linux/kernel.h>
5#include <linux/types.h>
6#include <linux/mod_devicetable.h>
7
8/* Unit spec id and sw version entry for some protocols */ 4/* Unit spec id and sw version entry for some protocols */
9#define AVC_UNIT_SPEC_ID_ENTRY 0x0000A02D 5#define AVC_UNIT_SPEC_ID_ENTRY 0x0000A02D
10#define AVC_SW_VERSION_ENTRY 0x00010001 6#define AVC_SW_VERSION_ENTRY 0x00010001
11#define CAMERA_UNIT_SPEC_ID_ENTRY 0x0000A02D 7#define CAMERA_UNIT_SPEC_ID_ENTRY 0x0000A02D
12#define CAMERA_SW_VERSION_ENTRY 0x00000100 8#define CAMERA_SW_VERSION_ENTRY 0x00000100
13 9
14/* Check to make sure this all isn't already defined */ 10/* /include/linux/mod_devicetable.h defines:
15#ifndef IEEE1394_MATCH_VENDOR_ID 11 * IEEE1394_MATCH_VENDOR_ID
16 12 * IEEE1394_MATCH_MODEL_ID
17#define IEEE1394_MATCH_VENDOR_ID 0x0001 13 * IEEE1394_MATCH_SPECIFIER_ID
18#define IEEE1394_MATCH_MODEL_ID 0x0002 14 * IEEE1394_MATCH_VERSION
19#define IEEE1394_MATCH_SPECIFIER_ID 0x0004 15 * struct ieee1394_device_id
20#define IEEE1394_MATCH_VERSION 0x0008 16 */
21 17#include <linux/mod_devicetable.h>
22struct ieee1394_device_id {
23 u32 match_flags;
24 u32 vendor_id;
25 u32 model_id;
26 u32 specifier_id;
27 u32 version;
28 void *driver_data;
29};
30
31#endif
32 18
33#endif /* _IEEE1394_HOTPLUG_H */ 19#endif /* _IEEE1394_HOTPLUG_H */
diff --git a/drivers/ieee1394/ieee1394_transactions.c b/drivers/ieee1394/ieee1394_transactions.c
index a114b91d606d..751960037e27 100644
--- a/drivers/ieee1394/ieee1394_transactions.c
+++ b/drivers/ieee1394/ieee1394_transactions.c
@@ -14,6 +14,7 @@
14#include <linux/smp_lock.h> 14#include <linux/smp_lock.h>
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16 16
17#include <asm/bug.h>
17#include <asm/errno.h> 18#include <asm/errno.h>
18 19
19#include "ieee1394.h" 20#include "ieee1394.h"
@@ -214,7 +215,7 @@ int hpsb_packet_success(struct hpsb_packet *packet)
214 packet->node_id); 215 packet->node_id);
215 return -EAGAIN; 216 return -EAGAIN;
216 } 217 }
217 HPSB_PANIC("reached unreachable code 1 in %s", __FUNCTION__); 218 BUG();
218 219
219 case ACK_BUSY_X: 220 case ACK_BUSY_X:
220 case ACK_BUSY_A: 221 case ACK_BUSY_A:
@@ -261,8 +262,7 @@ int hpsb_packet_success(struct hpsb_packet *packet)
261 packet->ack_code, packet->node_id, packet->tcode); 262 packet->ack_code, packet->node_id, packet->tcode);
262 return -EAGAIN; 263 return -EAGAIN;
263 } 264 }
264 265 BUG();
265 HPSB_PANIC("reached unreachable code 2 in %s", __FUNCTION__);
266} 266}
267 267
268struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node, 268struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node,
diff --git a/drivers/ieee1394/ieee1394_transactions.h b/drivers/ieee1394/ieee1394_transactions.h
index 45ba784fe6da..290d37060b03 100644
--- a/drivers/ieee1394/ieee1394_transactions.h
+++ b/drivers/ieee1394/ieee1394_transactions.h
@@ -1,32 +1,32 @@
1#ifndef _IEEE1394_TRANSACTIONS_H 1#ifndef _IEEE1394_TRANSACTIONS_H
2#define _IEEE1394_TRANSACTIONS_H 2#define _IEEE1394_TRANSACTIONS_H
3 3
4#include "ieee1394_core.h" 4#include <linux/types.h>
5 5
6#include "ieee1394_types.h"
7
8struct hpsb_packet;
9struct hpsb_host;
6 10
7/*
8 * Get and free transaction labels.
9 */
10int hpsb_get_tlabel(struct hpsb_packet *packet); 11int hpsb_get_tlabel(struct hpsb_packet *packet);
11void hpsb_free_tlabel(struct hpsb_packet *packet); 12void hpsb_free_tlabel(struct hpsb_packet *packet);
12
13struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node, 13struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node,
14 u64 addr, size_t length); 14 u64 addr, size_t length);
15struct hpsb_packet *hpsb_make_lockpacket(struct hpsb_host *host, nodeid_t node, 15struct hpsb_packet *hpsb_make_lockpacket(struct hpsb_host *host, nodeid_t node,
16 u64 addr, int extcode, quadlet_t *data, 16 u64 addr, int extcode, quadlet_t *data,
17 quadlet_t arg); 17 quadlet_t arg);
18struct hpsb_packet *hpsb_make_lock64packet(struct hpsb_host *host, nodeid_t node, 18struct hpsb_packet *hpsb_make_lock64packet(struct hpsb_host *host,
19 u64 addr, int extcode, octlet_t *data, 19 nodeid_t node, u64 addr, int extcode,
20 octlet_t arg); 20 octlet_t *data, octlet_t arg);
21struct hpsb_packet *hpsb_make_phypacket(struct hpsb_host *host, 21struct hpsb_packet *hpsb_make_phypacket(struct hpsb_host *host, quadlet_t data);
22 quadlet_t data) ; 22struct hpsb_packet *hpsb_make_isopacket(struct hpsb_host *host, int length,
23struct hpsb_packet *hpsb_make_isopacket(struct hpsb_host *host, 23 int channel, int tag, int sync);
24 int length, int channel, 24struct hpsb_packet *hpsb_make_writepacket(struct hpsb_host *host,
25 int tag, int sync); 25 nodeid_t node, u64 addr,
26struct hpsb_packet *hpsb_make_writepacket (struct hpsb_host *host, nodeid_t node, 26 quadlet_t *buffer, size_t length);
27 u64 addr, quadlet_t *buffer, size_t length);
28struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 *buffer, 27struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 *buffer,
29 int length, int channel, int tag, int sync); 28 int length, int channel, int tag,
29 int sync);
30 30
31/* 31/*
32 * hpsb_packet_success - Make sense of the ack and reply codes and 32 * hpsb_packet_success - Make sense of the ack and reply codes and
@@ -40,9 +40,8 @@ struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 *buffer,
40 */ 40 */
41int hpsb_packet_success(struct hpsb_packet *packet); 41int hpsb_packet_success(struct hpsb_packet *packet);
42 42
43
44/* 43/*
45 * The generic read, write and lock functions. All recognize the local node ID 44 * The generic read and write functions. All recognize the local node ID
46 * and act accordingly. Read and write automatically use quadlet commands if 45 * and act accordingly. Read and write automatically use quadlet commands if
47 * length == 4 and and block commands otherwise (however, they do not yet 46 * length == 4 and and block commands otherwise (however, they do not yet
48 * support lengths that are not a multiple of 4). You must explicitly specifiy 47 * support lengths that are not a multiple of 4). You must explicitly specifiy
diff --git a/drivers/ieee1394/ieee1394_types.h b/drivers/ieee1394/ieee1394_types.h
index 3165609ec1ec..16fd2d0b5ed2 100644
--- a/drivers/ieee1394/ieee1394_types.h
+++ b/drivers/ieee1394/ieee1394_types.h
@@ -1,17 +1,14 @@
1
2#ifndef _IEEE1394_TYPES_H 1#ifndef _IEEE1394_TYPES_H
3#define _IEEE1394_TYPES_H 2#define _IEEE1394_TYPES_H
4 3
5#include <linux/kernel.h> 4#include <linux/kernel.h>
6#include <linux/types.h>
7#include <linux/list.h> 5#include <linux/list.h>
8#include <linux/init.h>
9#include <linux/spinlock.h> 6#include <linux/spinlock.h>
10#include <linux/string.h> 7#include <linux/string.h>
8#include <linux/types.h>
11 9
12#include <asm/semaphore.h>
13#include <asm/byteorder.h> 10#include <asm/byteorder.h>
14 11#include <asm/semaphore.h>
15 12
16/* Transaction Label handling */ 13/* Transaction Label handling */
17struct hpsb_tlabel_pool { 14struct hpsb_tlabel_pool {
@@ -31,7 +28,6 @@ do { \
31 sema_init(&(_tp)->count, 63); \ 28 sema_init(&(_tp)->count, 63); \
32} while (0) 29} while (0)
33 30
34
35typedef u32 quadlet_t; 31typedef u32 quadlet_t;
36typedef u64 octlet_t; 32typedef u64 octlet_t;
37typedef u16 nodeid_t; 33typedef u16 nodeid_t;
@@ -54,46 +50,39 @@ typedef u16 arm_length_t;
54#define NODE_BUS_ARGS(__host, __nodeid) \ 50#define NODE_BUS_ARGS(__host, __nodeid) \
55 __host->id, NODEID_TO_NODE(__nodeid), NODEID_TO_BUS(__nodeid) 51 __host->id, NODEID_TO_NODE(__nodeid), NODEID_TO_BUS(__nodeid)
56 52
57#define HPSB_PRINT(level, fmt, args...) printk(level "ieee1394: " fmt "\n" , ## args) 53#define HPSB_PRINT(level, fmt, args...) \
54 printk(level "ieee1394: " fmt "\n" , ## args)
58 55
59#define HPSB_DEBUG(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args) 56#define HPSB_DEBUG(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args)
60#define HPSB_INFO(fmt, args...) HPSB_PRINT(KERN_INFO, fmt , ## args) 57#define HPSB_INFO(fmt, args...) HPSB_PRINT(KERN_INFO, fmt , ## args)
61#define HPSB_NOTICE(fmt, args...) HPSB_PRINT(KERN_NOTICE, fmt , ## args) 58#define HPSB_NOTICE(fmt, args...) HPSB_PRINT(KERN_NOTICE, fmt , ## args)
62#define HPSB_WARN(fmt, args...) HPSB_PRINT(KERN_WARNING, fmt , ## args) 59#define HPSB_WARN(fmt, args...) HPSB_PRINT(KERN_WARNING, fmt , ## args)
63#define HPSB_ERR(fmt, args...) HPSB_PRINT(KERN_ERR, fmt , ## args) 60#define HPSB_ERR(fmt, args...) HPSB_PRINT(KERN_ERR, fmt , ## args)
64 61
65#ifdef CONFIG_IEEE1394_VERBOSEDEBUG 62#ifdef CONFIG_IEEE1394_VERBOSEDEBUG
66#define HPSB_VERBOSE(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args) 63#define HPSB_VERBOSE(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args)
67#else 64#else
68#define HPSB_VERBOSE(fmt, args...) 65#define HPSB_VERBOSE(fmt, args...)
69#endif 66#endif
70 67
71#define HPSB_PANIC(fmt, args...) panic("ieee1394: " fmt "\n" , ## args)
72
73#define HPSB_TRACE() HPSB_PRINT(KERN_INFO, "TRACE - %s, %s(), line %d", __FILE__, __FUNCTION__, __LINE__)
74
75
76#ifdef __BIG_ENDIAN 68#ifdef __BIG_ENDIAN
77 69
78static __inline__ void *memcpy_le32(u32 *dest, const u32 *__src, size_t count) 70static inline void *memcpy_le32(u32 *dest, const u32 *__src, size_t count)
79{ 71{
80 void *tmp = dest; 72 void *tmp = dest;
81 u32 *src = (u32 *)__src; 73 u32 *src = (u32 *)__src;
82 74
83 count /= 4; 75 count /= 4;
84 76 while (count--)
85 while (count--) { 77 *dest++ = swab32p(src++);
86 *dest++ = swab32p(src++); 78 return tmp;
87 }
88
89 return tmp;
90} 79}
91 80
92#else 81#else
93 82
94static __inline__ void *memcpy_le32(u32 *dest, const u32 *src, size_t count) 83static __inline__ void *memcpy_le32(u32 *dest, const u32 *src, size_t count)
95{ 84{
96 return memcpy(dest, src, count); 85 return memcpy(dest, src, count);
97} 86}
98 87
99#endif /* __BIG_ENDIAN */ 88#endif /* __BIG_ENDIAN */
diff --git a/drivers/ieee1394/iso.c b/drivers/ieee1394/iso.c
index f26680ebef7c..08bd15d2a7b6 100644
--- a/drivers/ieee1394/iso.c
+++ b/drivers/ieee1394/iso.c
@@ -9,8 +9,11 @@
9 * directory of the kernel sources for details. 9 * directory of the kernel sources for details.
10 */ 10 */
11 11
12#include <linux/slab.h> 12#include <linux/pci.h>
13#include <linux/sched.h> 13#include <linux/sched.h>
14#include <linux/slab.h>
15
16#include "hosts.h"
14#include "iso.h" 17#include "iso.h"
15 18
16void hpsb_iso_stop(struct hpsb_iso *iso) 19void hpsb_iso_stop(struct hpsb_iso *iso)
diff --git a/drivers/ieee1394/iso.h b/drivers/ieee1394/iso.h
index 3efc60b33a88..1210a97e8685 100644
--- a/drivers/ieee1394/iso.h
+++ b/drivers/ieee1394/iso.h
@@ -12,33 +12,40 @@
12#ifndef IEEE1394_ISO_H 12#ifndef IEEE1394_ISO_H
13#define IEEE1394_ISO_H 13#define IEEE1394_ISO_H
14 14
15#include "hosts.h" 15#include <linux/spinlock_types.h>
16#include <asm/atomic.h>
17#include <asm/types.h>
18
16#include "dma.h" 19#include "dma.h"
17 20
18/* high-level ISO interface */ 21struct hpsb_host;
19 22
20/* This API sends and receives isochronous packets on a large, 23/* high-level ISO interface */
21 virtually-contiguous kernel memory buffer. The buffer may be mapped
22 into a user-space process for zero-copy transmission and reception.
23 24
24 There are no explicit boundaries between packets in the buffer. A 25/*
25 packet may be transmitted or received at any location. However, 26 * This API sends and receives isochronous packets on a large,
26 low-level drivers may impose certain restrictions on alignment or 27 * virtually-contiguous kernel memory buffer. The buffer may be mapped
27 size of packets. (e.g. in OHCI no packet may cross a page boundary, 28 * into a user-space process for zero-copy transmission and reception.
28 and packets should be quadlet-aligned) 29 *
29*/ 30 * There are no explicit boundaries between packets in the buffer. A
31 * packet may be transmitted or received at any location. However,
32 * low-level drivers may impose certain restrictions on alignment or
33 * size of packets. (e.g. in OHCI no packet may cross a page boundary,
34 * and packets should be quadlet-aligned)
35 */
30 36
31/* Packet descriptor - the API maintains a ring buffer of these packet 37/* Packet descriptor - the API maintains a ring buffer of these packet
32 descriptors in kernel memory (hpsb_iso.infos[]). */ 38 * descriptors in kernel memory (hpsb_iso.infos[]). */
33
34struct hpsb_iso_packet_info { 39struct hpsb_iso_packet_info {
35 /* offset of data payload relative to the first byte of the buffer */ 40 /* offset of data payload relative to the first byte of the buffer */
36 __u32 offset; 41 __u32 offset;
37 42
38 /* length of the data payload, in bytes (not including the isochronous header) */ 43 /* length of the data payload, in bytes (not including the isochronous
44 * header) */
39 __u16 len; 45 __u16 len;
40 46
41 /* (recv only) the cycle number (mod 8000) on which the packet was received */ 47 /* (recv only) the cycle number (mod 8000) on which the packet was
48 * received */
42 __u16 cycle; 49 __u16 cycle;
43 50
44 /* (recv only) channel on which the packet was received */ 51 /* (recv only) channel on which the packet was received */
@@ -48,12 +55,10 @@ struct hpsb_iso_packet_info {
48 __u8 tag; 55 __u8 tag;
49 __u8 sy; 56 __u8 sy;
50 57
51 /* 58 /* length in bytes of the packet including header/trailer.
52 * length in bytes of the packet including header/trailer. 59 * MUST be at structure end, since the first part of this structure is
53 * MUST be at structure end, since the first part of this structure is also 60 * also defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is
54 * defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is copied to 61 * copied to userspace and is accessed there through libraw1394. */
55 * userspace and is accessed there through libraw1394.
56 */
57 __u16 total_len; 62 __u16 total_len;
58}; 63};
59 64
@@ -75,8 +80,8 @@ struct hpsb_iso {
75 void *hostdata; 80 void *hostdata;
76 81
77 /* a function to be called (from interrupt context) after 82 /* a function to be called (from interrupt context) after
78 outgoing packets have been sent, or incoming packets have 83 * outgoing packets have been sent, or incoming packets have
79 arrived */ 84 * arrived */
80 void (*callback)(struct hpsb_iso*); 85 void (*callback)(struct hpsb_iso*);
81 86
82 /* wait for buffer space */ 87 /* wait for buffer space */
@@ -88,7 +93,7 @@ struct hpsb_iso {
88 93
89 94
90 /* greatest # of packets between interrupts - controls 95 /* greatest # of packets between interrupts - controls
91 the maximum latency of the buffer */ 96 * the maximum latency of the buffer */
92 int irq_interval; 97 int irq_interval;
93 98
94 /* the buffer for packet data payloads */ 99 /* the buffer for packet data payloads */
@@ -112,8 +117,8 @@ struct hpsb_iso {
112 int pkt_dma; 117 int pkt_dma;
113 118
114 /* how many packets, starting at first_packet: 119 /* how many packets, starting at first_packet:
115 (transmit) are ready to be filled with data 120 * (transmit) are ready to be filled with data
116 (receive) contain received data */ 121 * (receive) contain received data */
117 int n_ready_packets; 122 int n_ready_packets;
118 123
119 /* how many times the buffer has overflowed or underflowed */ 124 /* how many times the buffer has overflowed or underflowed */
@@ -134,7 +139,7 @@ struct hpsb_iso {
134 int start_cycle; 139 int start_cycle;
135 140
136 /* cycle at which next packet will be transmitted, 141 /* cycle at which next packet will be transmitted,
137 -1 if not known */ 142 * -1 if not known */
138 int xmit_cycle; 143 int xmit_cycle;
139 144
140 /* ringbuffer of packet descriptors in regular kernel memory 145 /* ringbuffer of packet descriptors in regular kernel memory
@@ -170,25 +175,30 @@ int hpsb_iso_recv_unlisten_channel(struct hpsb_iso *iso, unsigned char channel);
170int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask); 175int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask);
171 176
172/* start/stop DMA */ 177/* start/stop DMA */
173int hpsb_iso_xmit_start(struct hpsb_iso *iso, int start_on_cycle, int prebuffer); 178int hpsb_iso_xmit_start(struct hpsb_iso *iso, int start_on_cycle,
174int hpsb_iso_recv_start(struct hpsb_iso *iso, int start_on_cycle, int tag_mask, int sync); 179 int prebuffer);
180int hpsb_iso_recv_start(struct hpsb_iso *iso, int start_on_cycle,
181 int tag_mask, int sync);
175void hpsb_iso_stop(struct hpsb_iso *iso); 182void hpsb_iso_stop(struct hpsb_iso *iso);
176 183
177/* deallocate buffer and DMA context */ 184/* deallocate buffer and DMA context */
178void hpsb_iso_shutdown(struct hpsb_iso *iso); 185void hpsb_iso_shutdown(struct hpsb_iso *iso);
179 186
180/* queue a packet for transmission. 'offset' is relative to the beginning of the 187/* queue a packet for transmission.
181 DMA buffer, where the packet's data payload should already have been placed */ 188 * 'offset' is relative to the beginning of the DMA buffer, where the packet's
182int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len, u8 tag, u8 sy); 189 * data payload should already have been placed. */
190int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len,
191 u8 tag, u8 sy);
183 192
184/* wait until all queued packets have been transmitted to the bus */ 193/* wait until all queued packets have been transmitted to the bus */
185int hpsb_iso_xmit_sync(struct hpsb_iso *iso); 194int hpsb_iso_xmit_sync(struct hpsb_iso *iso);
186 195
187/* N packets have been read out of the buffer, re-use the buffer space */ 196/* N packets have been read out of the buffer, re-use the buffer space */
188int hpsb_iso_recv_release_packets(struct hpsb_iso *recv, unsigned int n_packets); 197int hpsb_iso_recv_release_packets(struct hpsb_iso *recv,
198 unsigned int n_packets);
189 199
190/* check for arrival of new packets immediately (even if irq_interval 200/* check for arrival of new packets immediately (even if irq_interval
191 has not yet been reached) */ 201 * has not yet been reached) */
192int hpsb_iso_recv_flush(struct hpsb_iso *iso); 202int hpsb_iso_recv_flush(struct hpsb_iso *iso);
193 203
194/* returns # of packets ready to send or receive */ 204/* returns # of packets ready to send or receive */
@@ -197,14 +207,15 @@ int hpsb_iso_n_ready(struct hpsb_iso *iso);
197/* the following are callbacks available to low-level drivers */ 207/* the following are callbacks available to low-level drivers */
198 208
199/* call after a packet has been transmitted to the bus (interrupt context is OK) 209/* call after a packet has been transmitted to the bus (interrupt context is OK)
200 'cycle' is the _exact_ cycle the packet was sent on 210 * 'cycle' is the _exact_ cycle the packet was sent on
201 'error' should be non-zero if some sort of error occurred when sending the packet 211 * 'error' should be non-zero if some sort of error occurred when sending the
202*/ 212 * packet */
203void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error); 213void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error);
204 214
205/* call after a packet has been received (interrupt context OK) */ 215/* call after a packet has been received (interrupt context OK) */
206void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len, 216void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len,
207 u16 total_len, u16 cycle, u8 channel, u8 tag, u8 sy); 217 u16 total_len, u16 cycle, u8 channel, u8 tag,
218 u8 sy);
208 219
209/* call to wake waiting processes after buffer space has opened up. */ 220/* call to wake waiting processes after buffer space has opened up. */
210void hpsb_iso_wake(struct hpsb_iso *iso); 221void hpsb_iso_wake(struct hpsb_iso *iso);
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index d541b508a159..f8f6079cc48c 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -12,26 +12,23 @@
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/list.h> 13#include <linux/list.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/smp_lock.h>
16#include <linux/interrupt.h>
17#include <linux/kmod.h>
18#include <linux/completion.h>
19#include <linux/delay.h> 15#include <linux/delay.h>
20#include <linux/pci.h> 16#include <linux/kthread.h>
21#include <linux/moduleparam.h> 17#include <linux/moduleparam.h>
22#include <asm/atomic.h> 18#include <asm/atomic.h>
23 19
24#include "ieee1394_types.h" 20#include "csr.h"
21#include "highlevel.h"
22#include "hosts.h"
25#include "ieee1394.h" 23#include "ieee1394.h"
26#include "ieee1394_core.h" 24#include "ieee1394_core.h"
27#include "hosts.h" 25#include "ieee1394_hotplug.h"
26#include "ieee1394_types.h"
28#include "ieee1394_transactions.h" 27#include "ieee1394_transactions.h"
29#include "highlevel.h"
30#include "csr.h"
31#include "nodemgr.h" 28#include "nodemgr.h"
32 29
33static int ignore_drivers; 30static int ignore_drivers;
34module_param(ignore_drivers, int, 0444); 31module_param(ignore_drivers, int, S_IRUGO | S_IWUSR);
35MODULE_PARM_DESC(ignore_drivers, "Disable automatic probing for drivers."); 32MODULE_PARM_DESC(ignore_drivers, "Disable automatic probing for drivers.");
36 33
37struct nodemgr_csr_info { 34struct nodemgr_csr_info {
@@ -71,7 +68,7 @@ static int nodemgr_check_speed(struct nodemgr_csr_info *ci, u64 addr,
71 u8 i, *speed, old_speed, good_speed; 68 u8 i, *speed, old_speed, good_speed;
72 int ret; 69 int ret;
73 70
74 speed = ci->host->speed + NODEID_TO_NODE(ci->nodeid); 71 speed = &(ci->host->speed[NODEID_TO_NODE(ci->nodeid)]);
75 old_speed = *speed; 72 old_speed = *speed;
76 good_speed = IEEE1394_SPEED_MAX + 1; 73 good_speed = IEEE1394_SPEED_MAX + 1;
77 74
@@ -161,16 +158,12 @@ static struct csr1212_bus_ops nodemgr_csr_ops = {
161 * but now we are much simpler because of the LDM. 158 * but now we are much simpler because of the LDM.
162 */ 159 */
163 160
164static DECLARE_MUTEX(nodemgr_serialize); 161static DEFINE_MUTEX(nodemgr_serialize);
165 162
166struct host_info { 163struct host_info {
167 struct hpsb_host *host; 164 struct hpsb_host *host;
168 struct list_head list; 165 struct list_head list;
169 struct completion exited; 166 struct task_struct *thread;
170 struct semaphore reset_sem;
171 int pid;
172 char daemon_name[15];
173 int kill_me;
174}; 167};
175 168
176static int nodemgr_bus_match(struct device * dev, struct device_driver * drv); 169static int nodemgr_bus_match(struct device * dev, struct device_driver * drv);
@@ -408,26 +401,11 @@ static ssize_t fw_get_destroy_node(struct bus_type *bus, char *buf)
408} 401}
409static BUS_ATTR(destroy_node, S_IWUSR | S_IRUGO, fw_get_destroy_node, fw_set_destroy_node); 402static BUS_ATTR(destroy_node, S_IWUSR | S_IRUGO, fw_get_destroy_node, fw_set_destroy_node);
410 403
411static int nodemgr_rescan_bus_thread(void *__unused)
412{
413 /* No userlevel access needed */
414 daemonize("kfwrescan");
415
416 bus_rescan_devices(&ieee1394_bus_type);
417
418 return 0;
419}
420 404
421static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, size_t count) 405static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, size_t count)
422{ 406{
423 int state = simple_strtoul(buf, NULL, 10); 407 if (simple_strtoul(buf, NULL, 10) == 1)
424 408 bus_rescan_devices(&ieee1394_bus_type);
425 /* Don't wait for this, or care about errors. Root could do
426 * something stupid and spawn this a lot of times, but that's
427 * root's fault. */
428 if (state == 1)
429 kernel_thread(nodemgr_rescan_bus_thread, NULL, CLONE_KERNEL);
430
431 return count; 409 return count;
432} 410}
433static ssize_t fw_get_rescan(struct bus_type *bus, char *buf) 411static ssize_t fw_get_rescan(struct bus_type *bus, char *buf)
@@ -1251,6 +1229,7 @@ static void nodemgr_node_scan_one(struct host_info *hi,
1251 octlet_t guid; 1229 octlet_t guid;
1252 struct csr1212_csr *csr; 1230 struct csr1212_csr *csr;
1253 struct nodemgr_csr_info *ci; 1231 struct nodemgr_csr_info *ci;
1232 u8 *speed;
1254 1233
1255 ci = kmalloc(sizeof(*ci), GFP_KERNEL); 1234 ci = kmalloc(sizeof(*ci), GFP_KERNEL);
1256 if (!ci) 1235 if (!ci)
@@ -1259,8 +1238,12 @@ static void nodemgr_node_scan_one(struct host_info *hi,
1259 ci->host = host; 1238 ci->host = host;
1260 ci->nodeid = nodeid; 1239 ci->nodeid = nodeid;
1261 ci->generation = generation; 1240 ci->generation = generation;
1262 ci->speed_unverified = 1241
1263 host->speed[NODEID_TO_NODE(nodeid)] > IEEE1394_SPEED_100; 1242 /* Prepare for speed probe which occurs when reading the ROM */
1243 speed = &(host->speed[NODEID_TO_NODE(nodeid)]);
1244 if (*speed > host->csr.lnk_spd)
1245 *speed = host->csr.lnk_spd;
1246 ci->speed_unverified = *speed > IEEE1394_SPEED_100;
1264 1247
1265 /* We need to detect when the ConfigROM's generation has changed, 1248 /* We need to detect when the ConfigROM's generation has changed,
1266 * so we only update the node's info when it needs to be. */ 1249 * so we only update the node's info when it needs to be. */
@@ -1300,8 +1283,6 @@ static void nodemgr_node_scan_one(struct host_info *hi,
1300 nodemgr_create_node(guid, csr, hi, nodeid, generation); 1283 nodemgr_create_node(guid, csr, hi, nodeid, generation);
1301 else 1284 else
1302 nodemgr_update_node(ne, csr, hi, nodeid, generation); 1285 nodemgr_update_node(ne, csr, hi, nodeid, generation);
1303
1304 return;
1305} 1286}
1306 1287
1307 1288
@@ -1492,9 +1473,8 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
1492 /* If we had a bus reset while we were scanning the bus, it is 1473 /* If we had a bus reset while we were scanning the bus, it is
1493 * possible that we did not probe all nodes. In that case, we 1474 * possible that we did not probe all nodes. In that case, we
1494 * skip the clean up for now, since we could remove nodes that 1475 * skip the clean up for now, since we could remove nodes that
1495 * were still on the bus. The bus reset increased hi->reset_sem, 1476 * were still on the bus. Another bus scan is pending which will
1496 * so there's a bus scan pending which will do the clean up 1477 * do the clean up eventually.
1497 * eventually.
1498 * 1478 *
1499 * Now let's tell the bus to rescan our devices. This may seem 1479 * Now let's tell the bus to rescan our devices. This may seem
1500 * like overhead, but the driver-model core will only scan a 1480 * like overhead, but the driver-model core will only scan a
@@ -1622,41 +1602,37 @@ static int nodemgr_host_thread(void *__hi)
1622{ 1602{
1623 struct host_info *hi = (struct host_info *)__hi; 1603 struct host_info *hi = (struct host_info *)__hi;
1624 struct hpsb_host *host = hi->host; 1604 struct hpsb_host *host = hi->host;
1625 int reset_cycles = 0; 1605 unsigned int g, generation = get_hpsb_generation(host) - 1;
1626 1606 int i, reset_cycles = 0;
1627 /* No userlevel access needed */
1628 daemonize(hi->daemon_name);
1629 1607
1630 /* Setup our device-model entries */ 1608 /* Setup our device-model entries */
1631 nodemgr_create_host_dev_files(host); 1609 nodemgr_create_host_dev_files(host);
1632 1610
1633 /* Sit and wait for a signal to probe the nodes on the bus. This 1611 for (;;) {
1634 * happens when we get a bus reset. */ 1612 /* Sleep until next bus reset */
1635 while (1) { 1613 set_current_state(TASK_INTERRUPTIBLE);
1636 unsigned int generation = 0; 1614 if (get_hpsb_generation(host) == generation)
1637 int i; 1615 schedule();
1616 __set_current_state(TASK_RUNNING);
1638 1617
1639 if (down_interruptible(&hi->reset_sem) || 1618 /* Thread may have been woken up to freeze or to exit */
1640 down_interruptible(&nodemgr_serialize)) { 1619 if (try_to_freeze())
1620 continue;
1621 if (kthread_should_stop())
1622 goto exit;
1623
1624 if (mutex_lock_interruptible(&nodemgr_serialize)) {
1641 if (try_to_freeze()) 1625 if (try_to_freeze())
1642 continue; 1626 continue;
1643 printk("NodeMgr: received unexpected signal?!\n" ); 1627 goto exit;
1644 break;
1645 }
1646
1647 if (hi->kill_me) {
1648 up(&nodemgr_serialize);
1649 break;
1650 } 1628 }
1651 1629
1652 /* Pause for 1/4 second in 1/16 second intervals, 1630 /* Pause for 1/4 second in 1/16 second intervals,
1653 * to make sure things settle down. */ 1631 * to make sure things settle down. */
1632 g = get_hpsb_generation(host);
1654 for (i = 0; i < 4 ; i++) { 1633 for (i = 0; i < 4 ; i++) {
1655 set_current_state(TASK_INTERRUPTIBLE); 1634 if (msleep_interruptible(63) || kthread_should_stop())
1656 if (msleep_interruptible(63)) { 1635 goto unlock_exit;
1657 up(&nodemgr_serialize);
1658 goto caught_signal;
1659 }
1660 1636
1661 /* Now get the generation in which the node ID's we collect 1637 /* Now get the generation in which the node ID's we collect
1662 * are valid. During the bus scan we will use this generation 1638 * are valid. During the bus scan we will use this generation
@@ -1667,20 +1643,14 @@ static int nodemgr_host_thread(void *__hi)
1667 1643
1668 /* If we get a reset before we are done waiting, then 1644 /* If we get a reset before we are done waiting, then
1669 * start the the waiting over again */ 1645 * start the the waiting over again */
1670 while (!down_trylock(&hi->reset_sem)) 1646 if (generation != g)
1671 i = 0; 1647 g = generation, i = 0;
1672
1673 /* Check the kill_me again */
1674 if (hi->kill_me) {
1675 up(&nodemgr_serialize);
1676 goto caught_signal;
1677 }
1678 } 1648 }
1679 1649
1680 if (!nodemgr_check_irm_capability(host, reset_cycles) || 1650 if (!nodemgr_check_irm_capability(host, reset_cycles) ||
1681 !nodemgr_do_irm_duties(host, reset_cycles)) { 1651 !nodemgr_do_irm_duties(host, reset_cycles)) {
1682 reset_cycles++; 1652 reset_cycles++;
1683 up(&nodemgr_serialize); 1653 mutex_unlock(&nodemgr_serialize);
1684 continue; 1654 continue;
1685 } 1655 }
1686 reset_cycles = 0; 1656 reset_cycles = 0;
@@ -1698,13 +1668,13 @@ static int nodemgr_host_thread(void *__hi)
1698 /* Update some of our sysfs symlinks */ 1668 /* Update some of our sysfs symlinks */
1699 nodemgr_update_host_dev_links(host); 1669 nodemgr_update_host_dev_links(host);
1700 1670
1701 up(&nodemgr_serialize); 1671 mutex_unlock(&nodemgr_serialize);
1702 } 1672 }
1703 1673unlock_exit:
1704caught_signal: 1674 mutex_unlock(&nodemgr_serialize);
1675exit:
1705 HPSB_VERBOSE("NodeMgr: Exiting thread"); 1676 HPSB_VERBOSE("NodeMgr: Exiting thread");
1706 1677 return 0;
1707 complete_and_exit(&hi->exited, 0);
1708} 1678}
1709 1679
1710int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *)) 1680int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *))
@@ -1764,41 +1734,27 @@ static void nodemgr_add_host(struct hpsb_host *host)
1764 struct host_info *hi; 1734 struct host_info *hi;
1765 1735
1766 hi = hpsb_create_hostinfo(&nodemgr_highlevel, host, sizeof(*hi)); 1736 hi = hpsb_create_hostinfo(&nodemgr_highlevel, host, sizeof(*hi));
1767
1768 if (!hi) { 1737 if (!hi) {
1769 HPSB_ERR ("NodeMgr: out of memory in add host"); 1738 HPSB_ERR("NodeMgr: out of memory in add host");
1770 return; 1739 return;
1771 } 1740 }
1772
1773 hi->host = host; 1741 hi->host = host;
1774 init_completion(&hi->exited); 1742 hi->thread = kthread_run(nodemgr_host_thread, hi, "knodemgrd_%d",
1775 sema_init(&hi->reset_sem, 0); 1743 host->id);
1776 1744 if (IS_ERR(hi->thread)) {
1777 sprintf(hi->daemon_name, "knodemgrd_%d", host->id); 1745 HPSB_ERR("NodeMgr: cannot start thread for host %d", host->id);
1778
1779 hi->pid = kernel_thread(nodemgr_host_thread, hi, CLONE_KERNEL);
1780
1781 if (hi->pid < 0) {
1782 HPSB_ERR ("NodeMgr: failed to start %s thread for %s",
1783 hi->daemon_name, host->driver->name);
1784 hpsb_destroy_hostinfo(&nodemgr_highlevel, host); 1746 hpsb_destroy_hostinfo(&nodemgr_highlevel, host);
1785 return;
1786 } 1747 }
1787
1788 return;
1789} 1748}
1790 1749
1791static void nodemgr_host_reset(struct hpsb_host *host) 1750static void nodemgr_host_reset(struct hpsb_host *host)
1792{ 1751{
1793 struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host); 1752 struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host);
1794 1753
1795 if (hi != NULL) { 1754 if (hi) {
1796 HPSB_VERBOSE("NodeMgr: Processing host reset for %s", hi->daemon_name); 1755 HPSB_VERBOSE("NodeMgr: Processing reset for host %d", host->id);
1797 up(&hi->reset_sem); 1756 wake_up_process(hi->thread);
1798 } else 1757 }
1799 HPSB_ERR ("NodeMgr: could not process reset of unused host");
1800
1801 return;
1802} 1758}
1803 1759
1804static void nodemgr_remove_host(struct hpsb_host *host) 1760static void nodemgr_remove_host(struct hpsb_host *host)
@@ -1806,18 +1762,9 @@ static void nodemgr_remove_host(struct hpsb_host *host)
1806 struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host); 1762 struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host);
1807 1763
1808 if (hi) { 1764 if (hi) {
1809 if (hi->pid >= 0) { 1765 kthread_stop(hi->thread);
1810 hi->kill_me = 1; 1766 nodemgr_remove_host_dev(&host->device);
1811 mb(); 1767 }
1812 up(&hi->reset_sem);
1813 wait_for_completion(&hi->exited);
1814 nodemgr_remove_host_dev(&host->device);
1815 }
1816 } else
1817 HPSB_ERR("NodeMgr: host %s does not exist, cannot remove",
1818 host->driver->name);
1819
1820 return;
1821} 1768}
1822 1769
1823static struct hpsb_highlevel nodemgr_highlevel = { 1770static struct hpsb_highlevel nodemgr_highlevel = {
diff --git a/drivers/ieee1394/nodemgr.h b/drivers/ieee1394/nodemgr.h
index 0b26616e16c3..f649c9d321b8 100644
--- a/drivers/ieee1394/nodemgr.h
+++ b/drivers/ieee1394/nodemgr.h
@@ -21,9 +21,15 @@
21#define _IEEE1394_NODEMGR_H 21#define _IEEE1394_NODEMGR_H
22 22
23#include <linux/device.h> 23#include <linux/device.h>
24#include "csr1212.h" 24#include <asm/types.h>
25
25#include "ieee1394_core.h" 26#include "ieee1394_core.h"
26#include "ieee1394_hotplug.h" 27#include "ieee1394_types.h"
28
29struct csr1212_csr;
30struct csr1212_keyval;
31struct hpsb_host;
32struct ieee1394_device_id;
27 33
28/* '1' '3' '9' '4' in ASCII */ 34/* '1' '3' '9' '4' in ASCII */
29#define IEEE1394_BUSID_MAGIC __constant_cpu_to_be32(0x31333934) 35#define IEEE1394_BUSID_MAGIC __constant_cpu_to_be32(0x31333934)
@@ -44,7 +50,6 @@ struct bus_options {
44 u16 max_rec; /* Maximum packet size node can receive */ 50 u16 max_rec; /* Maximum packet size node can receive */
45}; 51};
46 52
47
48#define UNIT_DIRECTORY_VENDOR_ID 0x01 53#define UNIT_DIRECTORY_VENDOR_ID 0x01
49#define UNIT_DIRECTORY_MODEL_ID 0x02 54#define UNIT_DIRECTORY_MODEL_ID 0x02
50#define UNIT_DIRECTORY_SPECIFIER_ID 0x04 55#define UNIT_DIRECTORY_SPECIFIER_ID 0x04
@@ -59,8 +64,8 @@ struct bus_options {
59 * unit directory for each of these protocols. 64 * unit directory for each of these protocols.
60 */ 65 */
61struct unit_directory { 66struct unit_directory {
62 struct node_entry *ne; /* The node which this directory belongs to */ 67 struct node_entry *ne; /* The node which this directory belongs to */
63 octlet_t address; /* Address of the unit directory on the node */ 68 octlet_t address; /* Address of the unit directory on the node */
64 u8 flags; /* Indicates which entries were read */ 69 u8 flags; /* Indicates which entries were read */
65 70
66 quadlet_t vendor_id; 71 quadlet_t vendor_id;
@@ -79,11 +84,10 @@ struct unit_directory {
79 int length; /* Number of quadlets */ 84 int length; /* Number of quadlets */
80 85
81 struct device device; 86 struct device device;
82
83 struct class_device class_dev; 87 struct class_device class_dev;
84 88
85 struct csr1212_keyval *ud_kv; 89 struct csr1212_keyval *ud_kv;
86 u32 lun; /* logical unit number immediate value */ 90 u32 lun; /* logical unit number immediate value */
87}; 91};
88 92
89struct node_entry { 93struct node_entry {
@@ -106,7 +110,6 @@ struct node_entry {
106 struct hpsb_tlabel_pool *tpool; 110 struct hpsb_tlabel_pool *tpool;
107 111
108 struct device device; 112 struct device device;
109
110 struct class_device class_dev; 113 struct class_device class_dev;
111 114
112 /* Means this node is not attached anymore */ 115 /* Means this node is not attached anymore */
@@ -153,8 +156,8 @@ static inline int hpsb_node_entry_valid(struct node_entry *ne)
153/* 156/*
154 * This will fill in the given, pre-initialised hpsb_packet with the current 157 * This will fill in the given, pre-initialised hpsb_packet with the current
155 * information from the node entry (host, node ID, generation number). It will 158 * information from the node entry (host, node ID, generation number). It will
156 * return false if the node owning the GUID is not accessible (and not modify the 159 * return false if the node owning the GUID is not accessible (and not modify
157 * hpsb_packet) and return true otherwise. 160 * the hpsb_packet) and return true otherwise.
158 * 161 *
159 * Note that packet sending may still fail in hpsb_send_packet if a bus reset 162 * Note that packet sending may still fail in hpsb_send_packet if a bus reset
160 * happens while you are trying to set up the packet (due to obsolete generation 163 * happens while you are trying to set up the packet (due to obsolete generation
@@ -170,16 +173,13 @@ int hpsb_node_write(struct node_entry *ne, u64 addr,
170int hpsb_node_lock(struct node_entry *ne, u64 addr, 173int hpsb_node_lock(struct node_entry *ne, u64 addr,
171 int extcode, quadlet_t *data, quadlet_t arg); 174 int extcode, quadlet_t *data, quadlet_t arg);
172 175
173
174/* Iterate the hosts, calling a given function with supplied data for each 176/* Iterate the hosts, calling a given function with supplied data for each
175 * host. */ 177 * host. */
176int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *)); 178int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *));
177 179
178
179int init_ieee1394_nodemgr(void); 180int init_ieee1394_nodemgr(void);
180void cleanup_ieee1394_nodemgr(void); 181void cleanup_ieee1394_nodemgr(void);
181 182
182
183/* The template for a host device */ 183/* The template for a host device */
184extern struct device nodemgr_dev_template_host; 184extern struct device nodemgr_dev_template_host;
185 185
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index 448df2773377..baa090d08d20 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -2598,8 +2598,9 @@ static const int TCODE_SIZE[16] = {20, 0, 16, -1, 16, 20, 20, 0,
2598 * Determine the length of a packet in the buffer 2598 * Determine the length of a packet in the buffer
2599 * Optimization suggested by Pascal Drolet <pascal.drolet@informission.ca> 2599 * Optimization suggested by Pascal Drolet <pascal.drolet@informission.ca>
2600 */ 2600 */
2601static __inline__ int packet_length(struct dma_rcv_ctx *d, int idx, quadlet_t *buf_ptr, 2601static inline int packet_length(struct dma_rcv_ctx *d, int idx,
2602 int offset, unsigned char tcode, int noswap) 2602 quadlet_t *buf_ptr, int offset,
2603 unsigned char tcode, int noswap)
2603{ 2604{
2604 int length = -1; 2605 int length = -1;
2605 2606
diff --git a/drivers/ieee1394/raw1394-private.h b/drivers/ieee1394/raw1394-private.h
index c93587be9cab..c7731d1bcd89 100644
--- a/drivers/ieee1394/raw1394-private.h
+++ b/drivers/ieee1394/raw1394-private.h
@@ -29,9 +29,8 @@ struct file_info {
29 29
30 struct list_head req_pending; 30 struct list_head req_pending;
31 struct list_head req_complete; 31 struct list_head req_complete;
32 struct semaphore complete_sem;
33 spinlock_t reqlists_lock; 32 spinlock_t reqlists_lock;
34 wait_queue_head_t poll_wait_complete; 33 wait_queue_head_t wait_complete;
35 34
36 struct list_head addr_list; 35 struct list_head addr_list;
37 36
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index 571ea68c0cf2..840b705fd5dd 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -44,14 +44,15 @@
44#include <linux/compat.h> 44#include <linux/compat.h>
45 45
46#include "csr1212.h" 46#include "csr1212.h"
47#include "highlevel.h"
48#include "hosts.h"
47#include "ieee1394.h" 49#include "ieee1394.h"
48#include "ieee1394_types.h"
49#include "ieee1394_core.h" 50#include "ieee1394_core.h"
50#include "nodemgr.h" 51#include "ieee1394_hotplug.h"
51#include "hosts.h"
52#include "highlevel.h"
53#include "iso.h"
54#include "ieee1394_transactions.h" 52#include "ieee1394_transactions.h"
53#include "ieee1394_types.h"
54#include "iso.h"
55#include "nodemgr.h"
55#include "raw1394.h" 56#include "raw1394.h"
56#include "raw1394-private.h" 57#include "raw1394-private.h"
57 58
@@ -132,10 +133,9 @@ static void free_pending_request(struct pending_request *req)
132static void __queue_complete_req(struct pending_request *req) 133static void __queue_complete_req(struct pending_request *req)
133{ 134{
134 struct file_info *fi = req->file_info; 135 struct file_info *fi = req->file_info;
135 list_move_tail(&req->list, &fi->req_complete);
136 136
137 up(&fi->complete_sem); 137 list_move_tail(&req->list, &fi->req_complete);
138 wake_up_interruptible(&fi->poll_wait_complete); 138 wake_up(&fi->wait_complete);
139} 139}
140 140
141static void queue_complete_req(struct pending_request *req) 141static void queue_complete_req(struct pending_request *req)
@@ -463,13 +463,36 @@ raw1394_compat_read(const char __user *buf, struct raw1394_request *r)
463 463
464#endif 464#endif
465 465
466/* get next completed request (caller must hold fi->reqlists_lock) */
467static inline struct pending_request *__next_complete_req(struct file_info *fi)
468{
469 struct list_head *lh;
470 struct pending_request *req = NULL;
471
472 if (!list_empty(&fi->req_complete)) {
473 lh = fi->req_complete.next;
474 list_del(lh);
475 req = list_entry(lh, struct pending_request, list);
476 }
477 return req;
478}
479
480/* atomically get next completed request */
481static struct pending_request *next_complete_req(struct file_info *fi)
482{
483 unsigned long flags;
484 struct pending_request *req;
485
486 spin_lock_irqsave(&fi->reqlists_lock, flags);
487 req = __next_complete_req(fi);
488 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
489 return req;
490}
466 491
467static ssize_t raw1394_read(struct file *file, char __user * buffer, 492static ssize_t raw1394_read(struct file *file, char __user * buffer,
468 size_t count, loff_t * offset_is_ignored) 493 size_t count, loff_t * offset_is_ignored)
469{ 494{
470 unsigned long flags;
471 struct file_info *fi = (struct file_info *)file->private_data; 495 struct file_info *fi = (struct file_info *)file->private_data;
472 struct list_head *lh;
473 struct pending_request *req; 496 struct pending_request *req;
474 ssize_t ret; 497 ssize_t ret;
475 498
@@ -487,22 +510,21 @@ static ssize_t raw1394_read(struct file *file, char __user * buffer,
487 } 510 }
488 511
489 if (file->f_flags & O_NONBLOCK) { 512 if (file->f_flags & O_NONBLOCK) {
490 if (down_trylock(&fi->complete_sem)) { 513 if (!(req = next_complete_req(fi)))
491 return -EAGAIN; 514 return -EAGAIN;
492 }
493 } else { 515 } else {
494 if (down_interruptible(&fi->complete_sem)) { 516 /*
517 * NB: We call the macro wait_event_interruptible() with a
518 * condition argument with side effect. This is only possible
519 * because the side effect does not occur until the condition
520 * became true, and wait_event_interruptible() won't evaluate
521 * the condition again after that.
522 */
523 if (wait_event_interruptible(fi->wait_complete,
524 (req = next_complete_req(fi))))
495 return -ERESTARTSYS; 525 return -ERESTARTSYS;
496 }
497 } 526 }
498 527
499 spin_lock_irqsave(&fi->reqlists_lock, flags);
500 lh = fi->req_complete.next;
501 list_del(lh);
502 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
503
504 req = list_entry(lh, struct pending_request, list);
505
506 if (req->req.length) { 528 if (req->req.length) {
507 if (copy_to_user(int2ptr(req->req.recvb), req->data, 529 if (copy_to_user(int2ptr(req->req.recvb), req->data,
508 req->req.length)) { 530 req->req.length)) {
@@ -2744,7 +2766,7 @@ static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2744 unsigned int mask = POLLOUT | POLLWRNORM; 2766 unsigned int mask = POLLOUT | POLLWRNORM;
2745 unsigned long flags; 2767 unsigned long flags;
2746 2768
2747 poll_wait(file, &fi->poll_wait_complete, pt); 2769 poll_wait(file, &fi->wait_complete, pt);
2748 2770
2749 spin_lock_irqsave(&fi->reqlists_lock, flags); 2771 spin_lock_irqsave(&fi->reqlists_lock, flags);
2750 if (!list_empty(&fi->req_complete)) { 2772 if (!list_empty(&fi->req_complete)) {
@@ -2769,9 +2791,8 @@ static int raw1394_open(struct inode *inode, struct file *file)
2769 fi->state = opened; 2791 fi->state = opened;
2770 INIT_LIST_HEAD(&fi->req_pending); 2792 INIT_LIST_HEAD(&fi->req_pending);
2771 INIT_LIST_HEAD(&fi->req_complete); 2793 INIT_LIST_HEAD(&fi->req_complete);
2772 sema_init(&fi->complete_sem, 0);
2773 spin_lock_init(&fi->reqlists_lock); 2794 spin_lock_init(&fi->reqlists_lock);
2774 init_waitqueue_head(&fi->poll_wait_complete); 2795 init_waitqueue_head(&fi->wait_complete);
2775 INIT_LIST_HEAD(&fi->addr_list); 2796 INIT_LIST_HEAD(&fi->addr_list);
2776 2797
2777 file->private_data = fi; 2798 file->private_data = fi;
@@ -2784,7 +2805,7 @@ static int raw1394_release(struct inode *inode, struct file *file)
2784 struct file_info *fi = file->private_data; 2805 struct file_info *fi = file->private_data;
2785 struct list_head *lh; 2806 struct list_head *lh;
2786 struct pending_request *req; 2807 struct pending_request *req;
2787 int done = 0, i, fail = 0; 2808 int i, fail;
2788 int retval = 0; 2809 int retval = 0;
2789 struct list_head *entry; 2810 struct list_head *entry;
2790 struct arm_addr *addr = NULL; 2811 struct arm_addr *addr = NULL;
@@ -2864,25 +2885,28 @@ static int raw1394_release(struct inode *inode, struct file *file)
2864 "error(s) occurred \n"); 2885 "error(s) occurred \n");
2865 } 2886 }
2866 2887
2867 while (!done) { 2888 for (;;) {
2889 /* This locked section guarantees that neither
2890 * complete nor pending requests exist once i!=0 */
2868 spin_lock_irqsave(&fi->reqlists_lock, flags); 2891 spin_lock_irqsave(&fi->reqlists_lock, flags);
2869 2892 while ((req = __next_complete_req(fi)))
2870 while (!list_empty(&fi->req_complete)) {
2871 lh = fi->req_complete.next;
2872 list_del(lh);
2873
2874 req = list_entry(lh, struct pending_request, list);
2875
2876 free_pending_request(req); 2893 free_pending_request(req);
2877 }
2878
2879 if (list_empty(&fi->req_pending))
2880 done = 1;
2881 2894
2895 i = list_empty(&fi->req_pending);
2882 spin_unlock_irqrestore(&fi->reqlists_lock, flags); 2896 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2883 2897
2884 if (!done) 2898 if (i)
2885 down_interruptible(&fi->complete_sem); 2899 break;
2900 /*
2901 * Sleep until more requests can be freed.
2902 *
2903 * NB: We call the macro wait_event() with a condition argument
2904 * with side effect. This is only possible because the side
2905 * effect does not occur until the condition became true, and
2906 * wait_event() won't evaluate the condition again after that.
2907 */
2908 wait_event(fi->wait_complete, (req = next_complete_req(fi)));
2909 free_pending_request(req);
2886 } 2910 }
2887 2911
2888 /* Remove any sub-trees left by user space programs */ 2912 /* Remove any sub-trees left by user space programs */
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index b08755e2e68f..baa063c9e6e3 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -356,7 +356,7 @@ static const struct {
356/* 356/*
357 * Converts a buffer from be32 to cpu byte ordering. Length is in bytes. 357 * Converts a buffer from be32 to cpu byte ordering. Length is in bytes.
358 */ 358 */
359static __inline__ void sbp2util_be32_to_cpu_buffer(void *buffer, int length) 359static inline void sbp2util_be32_to_cpu_buffer(void *buffer, int length)
360{ 360{
361 u32 *temp = buffer; 361 u32 *temp = buffer;
362 362
@@ -369,7 +369,7 @@ static __inline__ void sbp2util_be32_to_cpu_buffer(void *buffer, int length)
369/* 369/*
370 * Converts a buffer from cpu to be32 byte ordering. Length is in bytes. 370 * Converts a buffer from cpu to be32 byte ordering. Length is in bytes.
371 */ 371 */
372static __inline__ void sbp2util_cpu_to_be32_buffer(void *buffer, int length) 372static inline void sbp2util_cpu_to_be32_buffer(void *buffer, int length)
373{ 373{
374 u32 *temp = buffer; 374 u32 *temp = buffer;
375 375
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index c6e3f02bc6d7..6b5353d81ae2 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -49,16 +49,16 @@
49#include <linux/compat.h> 49#include <linux/compat.h>
50#include <linux/cdev.h> 50#include <linux/cdev.h>
51 51
52#include "ieee1394.h" 52#include "dma.h"
53#include "ieee1394_types.h" 53#include "highlevel.h"
54#include "hosts.h" 54#include "hosts.h"
55#include "ieee1394.h"
55#include "ieee1394_core.h" 56#include "ieee1394_core.h"
56#include "highlevel.h" 57#include "ieee1394_hotplug.h"
57#include "video1394.h" 58#include "ieee1394_types.h"
58#include "nodemgr.h" 59#include "nodemgr.h"
59#include "dma.h"
60
61#include "ohci1394.h" 60#include "ohci1394.h"
61#include "video1394.h"
62 62
63#define ISO_CHANNELS 64 63#define ISO_CHANNELS 64
64 64