diff options
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/firewire.h | 358 |
1 files changed, 358 insertions, 0 deletions
diff --git a/include/linux/firewire.h b/include/linux/firewire.h new file mode 100644 index 000000000000..e584b7215e8b --- /dev/null +++ b/include/linux/firewire.h | |||
| @@ -0,0 +1,358 @@ | |||
| 1 | #ifndef _LINUX_FIREWIRE_H | ||
| 2 | #define _LINUX_FIREWIRE_H | ||
| 3 | |||
| 4 | #include <linux/completion.h> | ||
| 5 | #include <linux/device.h> | ||
| 6 | #include <linux/kernel.h> | ||
| 7 | #include <linux/kref.h> | ||
| 8 | #include <linux/list.h> | ||
| 9 | #include <linux/mutex.h> | ||
| 10 | #include <linux/spinlock.h> | ||
| 11 | #include <linux/sysfs.h> | ||
| 12 | #include <linux/timer.h> | ||
| 13 | #include <linux/types.h> | ||
| 14 | #include <linux/workqueue.h> | ||
| 15 | |||
| 16 | #include <asm/atomic.h> | ||
| 17 | #include <asm/byteorder.h> | ||
| 18 | |||
| 19 | #define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args) | ||
| 20 | #define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args) | ||
| 21 | |||
| 22 | static inline void fw_memcpy_from_be32(void *_dst, void *_src, size_t size) | ||
| 23 | { | ||
| 24 | u32 *dst = _dst; | ||
| 25 | __be32 *src = _src; | ||
| 26 | int i; | ||
| 27 | |||
| 28 | for (i = 0; i < size / 4; i++) | ||
| 29 | dst[i] = be32_to_cpu(src[i]); | ||
| 30 | } | ||
| 31 | |||
| 32 | static inline void fw_memcpy_to_be32(void *_dst, void *_src, size_t size) | ||
| 33 | { | ||
| 34 | fw_memcpy_from_be32(_dst, _src, size); | ||
| 35 | } | ||
| 36 | #define CSR_REGISTER_BASE 0xfffff0000000ULL | ||
| 37 | |||
| 38 | /* register offsets are relative to CSR_REGISTER_BASE */ | ||
| 39 | #define CSR_STATE_CLEAR 0x0 | ||
| 40 | #define CSR_STATE_SET 0x4 | ||
| 41 | #define CSR_NODE_IDS 0x8 | ||
| 42 | #define CSR_RESET_START 0xc | ||
| 43 | #define CSR_SPLIT_TIMEOUT_HI 0x18 | ||
| 44 | #define CSR_SPLIT_TIMEOUT_LO 0x1c | ||
| 45 | #define CSR_CYCLE_TIME 0x200 | ||
| 46 | #define CSR_BUS_TIME 0x204 | ||
| 47 | #define CSR_BUSY_TIMEOUT 0x210 | ||
| 48 | #define CSR_BUS_MANAGER_ID 0x21c | ||
| 49 | #define CSR_BANDWIDTH_AVAILABLE 0x220 | ||
| 50 | #define CSR_CHANNELS_AVAILABLE 0x224 | ||
| 51 | #define CSR_CHANNELS_AVAILABLE_HI 0x224 | ||
| 52 | #define CSR_CHANNELS_AVAILABLE_LO 0x228 | ||
| 53 | #define CSR_BROADCAST_CHANNEL 0x234 | ||
| 54 | #define CSR_CONFIG_ROM 0x400 | ||
| 55 | #define CSR_CONFIG_ROM_END 0x800 | ||
| 56 | #define CSR_FCP_COMMAND 0xB00 | ||
| 57 | #define CSR_FCP_RESPONSE 0xD00 | ||
| 58 | #define CSR_FCP_END 0xF00 | ||
| 59 | #define CSR_TOPOLOGY_MAP 0x1000 | ||
| 60 | #define CSR_TOPOLOGY_MAP_END 0x1400 | ||
| 61 | #define CSR_SPEED_MAP 0x2000 | ||
| 62 | #define CSR_SPEED_MAP_END 0x3000 | ||
| 63 | |||
| 64 | #define CSR_OFFSET 0x40 | ||
| 65 | #define CSR_LEAF 0x80 | ||
| 66 | #define CSR_DIRECTORY 0xc0 | ||
| 67 | |||
| 68 | #define CSR_DESCRIPTOR 0x01 | ||
| 69 | #define CSR_VENDOR 0x03 | ||
| 70 | #define CSR_HARDWARE_VERSION 0x04 | ||
| 71 | #define CSR_NODE_CAPABILITIES 0x0c | ||
| 72 | #define CSR_UNIT 0x11 | ||
| 73 | #define CSR_SPECIFIER_ID 0x12 | ||
| 74 | #define CSR_VERSION 0x13 | ||
| 75 | #define CSR_DEPENDENT_INFO 0x14 | ||
| 76 | #define CSR_MODEL 0x17 | ||
| 77 | #define CSR_INSTANCE 0x18 | ||
| 78 | #define CSR_DIRECTORY_ID 0x20 | ||
| 79 | |||
| 80 | struct fw_csr_iterator { | ||
| 81 | u32 *p; | ||
| 82 | u32 *end; | ||
| 83 | }; | ||
| 84 | |||
| 85 | void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p); | ||
| 86 | int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value); | ||
| 87 | |||
| 88 | extern struct bus_type fw_bus_type; | ||
| 89 | |||
| 90 | struct fw_card_driver; | ||
| 91 | struct fw_node; | ||
| 92 | |||
| 93 | struct fw_card { | ||
| 94 | const struct fw_card_driver *driver; | ||
| 95 | struct device *device; | ||
| 96 | struct kref kref; | ||
| 97 | struct completion done; | ||
| 98 | |||
| 99 | int node_id; | ||
| 100 | int generation; | ||
| 101 | int current_tlabel; | ||
| 102 | u64 tlabel_mask; | ||
| 103 | struct list_head transaction_list; | ||
| 104 | struct timer_list flush_timer; | ||
| 105 | unsigned long reset_jiffies; | ||
| 106 | |||
| 107 | unsigned long long guid; | ||
| 108 | unsigned max_receive; | ||
| 109 | int link_speed; | ||
| 110 | int config_rom_generation; | ||
| 111 | |||
| 112 | spinlock_t lock; /* Take this lock when handling the lists in | ||
| 113 | * this struct. */ | ||
| 114 | struct fw_node *local_node; | ||
| 115 | struct fw_node *root_node; | ||
| 116 | struct fw_node *irm_node; | ||
| 117 | u8 color; /* must be u8 to match the definition in struct fw_node */ | ||
| 118 | int gap_count; | ||
| 119 | bool beta_repeaters_present; | ||
| 120 | |||
| 121 | int index; | ||
| 122 | |||
| 123 | struct list_head link; | ||
| 124 | |||
| 125 | /* Work struct for BM duties. */ | ||
| 126 | struct delayed_work work; | ||
| 127 | int bm_retries; | ||
| 128 | int bm_generation; | ||
| 129 | |||
| 130 | bool broadcast_channel_allocated; | ||
| 131 | u32 broadcast_channel; | ||
| 132 | u32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4]; | ||
| 133 | }; | ||
| 134 | |||
| 135 | static inline struct fw_card *fw_card_get(struct fw_card *card) | ||
| 136 | { | ||
| 137 | kref_get(&card->kref); | ||
| 138 | |||
| 139 | return card; | ||
| 140 | } | ||
| 141 | |||
| 142 | void fw_card_release(struct kref *kref); | ||
| 143 | |||
| 144 | static inline void fw_card_put(struct fw_card *card) | ||
| 145 | { | ||
| 146 | kref_put(&card->kref, fw_card_release); | ||
| 147 | } | ||
| 148 | |||
| 149 | struct fw_attribute_group { | ||
| 150 | struct attribute_group *groups[2]; | ||
| 151 | struct attribute_group group; | ||
| 152 | struct attribute *attrs[12]; | ||
| 153 | }; | ||
| 154 | |||
| 155 | enum fw_device_state { | ||
| 156 | FW_DEVICE_INITIALIZING, | ||
| 157 | FW_DEVICE_RUNNING, | ||
| 158 | FW_DEVICE_GONE, | ||
| 159 | FW_DEVICE_SHUTDOWN, | ||
| 160 | }; | ||
| 161 | |||
| 162 | /* | ||
| 163 | * Note, fw_device.generation always has to be read before fw_device.node_id. | ||
| 164 | * Use SMP memory barriers to ensure this. Otherwise requests will be sent | ||
| 165 | * to an outdated node_id if the generation was updated in the meantime due | ||
| 166 | * to a bus reset. | ||
| 167 | * | ||
| 168 | * Likewise, fw-core will take care to update .node_id before .generation so | ||
| 169 | * that whenever fw_device.generation is current WRT the actual bus generation, | ||
| 170 | * fw_device.node_id is guaranteed to be current too. | ||
| 171 | * | ||
| 172 | * The same applies to fw_device.card->node_id vs. fw_device.generation. | ||
| 173 | * | ||
| 174 | * fw_device.config_rom and fw_device.config_rom_length may be accessed during | ||
| 175 | * the lifetime of any fw_unit belonging to the fw_device, before device_del() | ||
| 176 | * was called on the last fw_unit. Alternatively, they may be accessed while | ||
| 177 | * holding fw_device_rwsem. | ||
| 178 | */ | ||
| 179 | struct fw_device { | ||
| 180 | atomic_t state; | ||
| 181 | struct fw_node *node; | ||
| 182 | int node_id; | ||
| 183 | int generation; | ||
| 184 | unsigned max_speed; | ||
| 185 | struct fw_card *card; | ||
| 186 | struct device device; | ||
| 187 | |||
| 188 | struct mutex client_list_mutex; | ||
| 189 | struct list_head client_list; | ||
| 190 | |||
| 191 | u32 *config_rom; | ||
| 192 | size_t config_rom_length; | ||
| 193 | int config_rom_retries; | ||
| 194 | unsigned is_local:1; | ||
| 195 | unsigned max_rec:4; | ||
| 196 | unsigned cmc:1; | ||
| 197 | unsigned irmc:1; | ||
| 198 | unsigned bc_implemented:2; | ||
| 199 | |||
| 200 | struct delayed_work work; | ||
| 201 | struct fw_attribute_group attribute_group; | ||
| 202 | }; | ||
| 203 | |||
| 204 | static inline struct fw_device *fw_device(struct device *dev) | ||
| 205 | { | ||
| 206 | return container_of(dev, struct fw_device, device); | ||
| 207 | } | ||
| 208 | |||
| 209 | static inline int fw_device_is_shutdown(struct fw_device *device) | ||
| 210 | { | ||
| 211 | return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN; | ||
| 212 | } | ||
| 213 | |||
| 214 | static inline struct fw_device *fw_device_get(struct fw_device *device) | ||
| 215 | { | ||
| 216 | get_device(&device->device); | ||
| 217 | |||
| 218 | return device; | ||
| 219 | } | ||
| 220 | |||
| 221 | static inline void fw_device_put(struct fw_device *device) | ||
| 222 | { | ||
| 223 | put_device(&device->device); | ||
| 224 | } | ||
| 225 | |||
| 226 | int fw_device_enable_phys_dma(struct fw_device *device); | ||
| 227 | |||
| 228 | /* | ||
| 229 | * fw_unit.directory must not be accessed after device_del(&fw_unit.device). | ||
| 230 | */ | ||
| 231 | struct fw_unit { | ||
| 232 | struct device device; | ||
| 233 | u32 *directory; | ||
| 234 | struct fw_attribute_group attribute_group; | ||
| 235 | }; | ||
| 236 | |||
| 237 | static inline struct fw_unit *fw_unit(struct device *dev) | ||
| 238 | { | ||
| 239 | return container_of(dev, struct fw_unit, device); | ||
| 240 | } | ||
| 241 | |||
| 242 | static inline struct fw_unit *fw_unit_get(struct fw_unit *unit) | ||
| 243 | { | ||
| 244 | get_device(&unit->device); | ||
| 245 | |||
| 246 | return unit; | ||
| 247 | } | ||
| 248 | |||
| 249 | static inline void fw_unit_put(struct fw_unit *unit) | ||
| 250 | { | ||
| 251 | put_device(&unit->device); | ||
| 252 | } | ||
| 253 | |||
| 254 | static inline struct fw_device *fw_parent_device(struct fw_unit *unit) | ||
| 255 | { | ||
| 256 | return fw_device(unit->device.parent); | ||
| 257 | } | ||
| 258 | |||
| 259 | struct ieee1394_device_id; | ||
| 260 | |||
| 261 | struct fw_driver { | ||
| 262 | struct device_driver driver; | ||
| 263 | /* Called when the parent device sits through a bus reset. */ | ||
| 264 | void (*update)(struct fw_unit *unit); | ||
| 265 | const struct ieee1394_device_id *id_table; | ||
| 266 | }; | ||
| 267 | |||
| 268 | struct fw_packet; | ||
| 269 | struct fw_request; | ||
| 270 | |||
| 271 | typedef void (*fw_packet_callback_t)(struct fw_packet *packet, | ||
| 272 | struct fw_card *card, int status); | ||
| 273 | typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode, | ||
| 274 | void *data, size_t length, | ||
| 275 | void *callback_data); | ||
| 276 | /* | ||
| 277 | * Important note: The callback must guarantee that either fw_send_response() | ||
| 278 | * or kfree() is called on the @request. | ||
| 279 | */ | ||
| 280 | typedef void (*fw_address_callback_t)(struct fw_card *card, | ||
| 281 | struct fw_request *request, | ||
| 282 | int tcode, int destination, int source, | ||
| 283 | int generation, int speed, | ||
| 284 | unsigned long long offset, | ||
| 285 | void *data, size_t length, | ||
| 286 | void *callback_data); | ||
| 287 | |||
| 288 | struct fw_packet { | ||
| 289 | int speed; | ||
| 290 | int generation; | ||
| 291 | u32 header[4]; | ||
| 292 | size_t header_length; | ||
| 293 | void *payload; | ||
| 294 | size_t payload_length; | ||
| 295 | dma_addr_t payload_bus; | ||
| 296 | u32 timestamp; | ||
| 297 | |||
| 298 | /* | ||
| 299 | * This callback is called when the packet transmission has | ||
| 300 | * completed; for successful transmission, the status code is | ||
| 301 | * the ack received from the destination, otherwise it's a | ||
| 302 | * negative errno: ENOMEM, ESTALE, ETIMEDOUT, ENODEV, EIO. | ||
| 303 | * The callback can be called from tasklet context and thus | ||
| 304 | * must never block. | ||
| 305 | */ | ||
| 306 | fw_packet_callback_t callback; | ||
| 307 | int ack; | ||
| 308 | struct list_head link; | ||
| 309 | void *driver_data; | ||
| 310 | }; | ||
| 311 | |||
| 312 | struct fw_transaction { | ||
| 313 | int node_id; /* The generation is implied; it is always the current. */ | ||
| 314 | int tlabel; | ||
| 315 | int timestamp; | ||
| 316 | struct list_head link; | ||
| 317 | |||
| 318 | struct fw_packet packet; | ||
| 319 | |||
| 320 | /* | ||
| 321 | * The data passed to the callback is valid only during the | ||
| 322 | * callback. | ||
| 323 | */ | ||
| 324 | fw_transaction_callback_t callback; | ||
| 325 | void *callback_data; | ||
| 326 | }; | ||
| 327 | |||
| 328 | struct fw_address_handler { | ||
| 329 | u64 offset; | ||
| 330 | size_t length; | ||
| 331 | fw_address_callback_t address_callback; | ||
| 332 | void *callback_data; | ||
| 333 | struct list_head link; | ||
| 334 | }; | ||
| 335 | |||
| 336 | struct fw_address_region { | ||
| 337 | u64 start; | ||
| 338 | u64 end; | ||
| 339 | }; | ||
| 340 | |||
| 341 | extern const struct fw_address_region fw_high_memory_region; | ||
| 342 | |||
| 343 | int fw_core_add_address_handler(struct fw_address_handler *handler, | ||
| 344 | const struct fw_address_region *region); | ||
| 345 | void fw_core_remove_address_handler(struct fw_address_handler *handler); | ||
| 346 | void fw_send_response(struct fw_card *card, | ||
| 347 | struct fw_request *request, int rcode); | ||
| 348 | void fw_send_request(struct fw_card *card, struct fw_transaction *t, | ||
| 349 | int tcode, int destination_id, int generation, int speed, | ||
| 350 | unsigned long long offset, void *payload, size_t length, | ||
| 351 | fw_transaction_callback_t callback, void *callback_data); | ||
| 352 | int fw_cancel_transaction(struct fw_card *card, | ||
| 353 | struct fw_transaction *transaction); | ||
| 354 | int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, | ||
| 355 | int generation, int speed, unsigned long long offset, | ||
| 356 | void *payload, size_t length); | ||
| 357 | |||
| 358 | #endif /* _LINUX_FIREWIRE_H */ | ||
