1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __fw_device_h
20#define __fw_device_h
21
22#include <linux/fs.h>
23#include <linux/cdev.h>
24#include <linux/rwsem.h>
25#include <asm/atomic.h>
26
27enum fw_device_state {
28 FW_DEVICE_INITIALIZING,
29 FW_DEVICE_RUNNING,
30 FW_DEVICE_SHUTDOWN,
31};
32
33struct fw_attribute_group {
34 struct attribute_group *groups[2];
35 struct attribute_group group;
36 struct attribute *attrs[11];
37};
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56struct fw_device {
57 atomic_t state;
58 struct fw_node *node;
59 int node_id;
60 int generation;
61 unsigned max_speed;
62 bool cmc;
63 struct fw_card *card;
64 struct device device;
65 struct list_head client_list;
66 u32 *config_rom;
67 size_t config_rom_length;
68 int config_rom_retries;
69 struct delayed_work work;
70 struct fw_attribute_group attribute_group;
71};
72
73static inline struct fw_device *fw_device(struct device *dev)
74{
75 return container_of(dev, struct fw_device, device);
76}
77
78static inline int fw_device_is_shutdown(struct fw_device *device)
79{
80 return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
81}
82
83static inline struct fw_device *fw_device_get(struct fw_device *device)
84{
85 get_device(&device->device);
86
87 return device;
88}
89
90static inline void fw_device_put(struct fw_device *device)
91{
92 put_device(&device->device);
93}
94
95struct fw_device *fw_device_get_by_devt(dev_t devt);
96int fw_device_enable_phys_dma(struct fw_device *device);
97
98void fw_device_cdev_update(struct fw_device *device);
99void fw_device_cdev_remove(struct fw_device *device);
100
101extern struct rw_semaphore fw_device_rwsem;
102extern int fw_cdev_major;
103
104
105
106
107struct fw_unit {
108 struct device device;
109 u32 *directory;
110 struct fw_attribute_group attribute_group;
111};
112
113static inline struct fw_unit *fw_unit(struct device *dev)
114{
115 return container_of(dev, struct fw_unit, device);
116}
117
118static inline struct fw_unit *fw_unit_get(struct fw_unit *unit)
119{
120 get_device(&unit->device);
121
122 return unit;
123}
124
125static inline void fw_unit_put(struct fw_unit *unit)
126{
127 put_device(&unit->device);
128}
129
130#define CSR_OFFSET 0x40
131#define CSR_LEAF 0x80
132#define CSR_DIRECTORY 0xc0
133
134#define CSR_DESCRIPTOR 0x01
135#define CSR_VENDOR 0x03
136#define CSR_HARDWARE_VERSION 0x04
137#define CSR_NODE_CAPABILITIES 0x0c
138#define CSR_UNIT 0x11
139#define CSR_SPECIFIER_ID 0x12
140#define CSR_VERSION 0x13
141#define CSR_DEPENDENT_INFO 0x14
142#define CSR_MODEL 0x17
143#define CSR_INSTANCE 0x18
144#define CSR_DIRECTORY_ID 0x20
145
146struct fw_csr_iterator {
147 u32 *p;
148 u32 *end;
149};
150
151void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
152int fw_csr_iterator_next(struct fw_csr_iterator *ci,
153 int *key, int *value);
154
155#define FW_MATCH_VENDOR 0x0001
156#define FW_MATCH_MODEL 0x0002
157#define FW_MATCH_SPECIFIER_ID 0x0004
158#define FW_MATCH_VERSION 0x0008
159
160struct fw_device_id {
161 u32 match_flags;
162 u32 vendor;
163 u32 model;
164 u32 specifier_id;
165 u32 version;
166 void *driver_data;
167};
168
169struct fw_driver {
170 struct device_driver driver;
171
172 void (*update) (struct fw_unit *unit);
173 const struct fw_device_id *id_table;
174};
175
176static inline struct fw_driver *
177fw_driver(struct device_driver *drv)
178{
179 return container_of(drv, struct fw_driver, driver);
180}
181
182extern const struct file_operations fw_device_ops;
183
184#endif
185