177c9a5daSStefan Richter #ifndef _LINUX_FIREWIRE_H 277c9a5daSStefan Richter #define _LINUX_FIREWIRE_H 377c9a5daSStefan Richter 477c9a5daSStefan Richter #include <linux/completion.h> 5f68c56b7SPaul Gortmaker #include <linux/device.h> 6c76acec6SJay Fenlason #include <linux/dma-mapping.h> 777c9a5daSStefan Richter #include <linux/kernel.h> 877c9a5daSStefan Richter #include <linux/kref.h> 977c9a5daSStefan Richter #include <linux/list.h> 1077c9a5daSStefan Richter #include <linux/mutex.h> 1177c9a5daSStefan Richter #include <linux/spinlock.h> 1277c9a5daSStefan Richter #include <linux/sysfs.h> 1377c9a5daSStefan Richter #include <linux/timer.h> 1477c9a5daSStefan Richter #include <linux/types.h> 1577c9a5daSStefan Richter #include <linux/workqueue.h> 1677c9a5daSStefan Richter 1760063497SArun Sharma #include <linux/atomic.h> 1877c9a5daSStefan Richter #include <asm/byteorder.h> 1977c9a5daSStefan Richter 2077c9a5daSStefan Richter #define CSR_REGISTER_BASE 0xfffff0000000ULL 2177c9a5daSStefan Richter 2277c9a5daSStefan Richter /* register offsets are relative to CSR_REGISTER_BASE */ 2377c9a5daSStefan Richter #define CSR_STATE_CLEAR 0x0 2477c9a5daSStefan Richter #define CSR_STATE_SET 0x4 2577c9a5daSStefan Richter #define CSR_NODE_IDS 0x8 2677c9a5daSStefan Richter #define CSR_RESET_START 0xc 2777c9a5daSStefan Richter #define CSR_SPLIT_TIMEOUT_HI 0x18 2877c9a5daSStefan Richter #define CSR_SPLIT_TIMEOUT_LO 0x1c 2977c9a5daSStefan Richter #define CSR_CYCLE_TIME 0x200 3077c9a5daSStefan Richter #define CSR_BUS_TIME 0x204 3177c9a5daSStefan Richter #define CSR_BUSY_TIMEOUT 0x210 32a1a1132bSClemens Ladisch #define CSR_PRIORITY_BUDGET 0x218 3377c9a5daSStefan Richter #define CSR_BUS_MANAGER_ID 0x21c 3477c9a5daSStefan Richter #define CSR_BANDWIDTH_AVAILABLE 0x220 3577c9a5daSStefan Richter #define CSR_CHANNELS_AVAILABLE 0x224 3677c9a5daSStefan Richter #define CSR_CHANNELS_AVAILABLE_HI 0x224 3777c9a5daSStefan Richter #define CSR_CHANNELS_AVAILABLE_LO 0x228 383d1f46ebSClemens Ladisch #define CSR_MAINT_UTILITY 0x230 3977c9a5daSStefan Richter #define CSR_BROADCAST_CHANNEL 0x234 4077c9a5daSStefan Richter #define CSR_CONFIG_ROM 0x400 4177c9a5daSStefan Richter #define CSR_CONFIG_ROM_END 0x800 4231ef9134SClemens Ladisch #define CSR_OMPR 0x900 4331ef9134SClemens Ladisch #define CSR_OPCR(i) (0x904 + (i) * 4) 4431ef9134SClemens Ladisch #define CSR_IMPR 0x980 4531ef9134SClemens Ladisch #define CSR_IPCR(i) (0x984 + (i) * 4) 4677c9a5daSStefan Richter #define CSR_FCP_COMMAND 0xB00 4777c9a5daSStefan Richter #define CSR_FCP_RESPONSE 0xD00 4877c9a5daSStefan Richter #define CSR_FCP_END 0xF00 4977c9a5daSStefan Richter #define CSR_TOPOLOGY_MAP 0x1000 5077c9a5daSStefan Richter #define CSR_TOPOLOGY_MAP_END 0x1400 5177c9a5daSStefan Richter #define CSR_SPEED_MAP 0x2000 5277c9a5daSStefan Richter #define CSR_SPEED_MAP_END 0x3000 5377c9a5daSStefan Richter 5477c9a5daSStefan Richter #define CSR_OFFSET 0x40 5577c9a5daSStefan Richter #define CSR_LEAF 0x80 5677c9a5daSStefan Richter #define CSR_DIRECTORY 0xc0 5777c9a5daSStefan Richter 5877c9a5daSStefan Richter #define CSR_DESCRIPTOR 0x01 5977c9a5daSStefan Richter #define CSR_VENDOR 0x03 6077c9a5daSStefan Richter #define CSR_HARDWARE_VERSION 0x04 6177c9a5daSStefan Richter #define CSR_UNIT 0x11 6277c9a5daSStefan Richter #define CSR_SPECIFIER_ID 0x12 6377c9a5daSStefan Richter #define CSR_VERSION 0x13 6477c9a5daSStefan Richter #define CSR_DEPENDENT_INFO 0x14 6577c9a5daSStefan Richter #define CSR_MODEL 0x17 6677c9a5daSStefan Richter #define CSR_DIRECTORY_ID 0x20 6777c9a5daSStefan Richter 6877c9a5daSStefan Richter struct fw_csr_iterator { 6913b302d0SStefan Richter const u32 *p; 7013b302d0SStefan Richter const u32 *end; 7177c9a5daSStefan Richter }; 7277c9a5daSStefan Richter 7313b302d0SStefan Richter void fw_csr_iterator_init(struct fw_csr_iterator *ci, const u32 *p); 7477c9a5daSStefan Richter int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value); 7513b302d0SStefan Richter int fw_csr_string(const u32 *directory, int key, char *buf, size_t size); 761f8fef7bSClemens Ladisch 7777c9a5daSStefan Richter extern struct bus_type fw_bus_type; 7877c9a5daSStefan Richter 7977c9a5daSStefan Richter struct fw_card_driver; 8077c9a5daSStefan Richter struct fw_node; 8177c9a5daSStefan Richter 8277c9a5daSStefan Richter struct fw_card { 8377c9a5daSStefan Richter const struct fw_card_driver *driver; 8477c9a5daSStefan Richter struct device *device; 8577c9a5daSStefan Richter struct kref kref; 8677c9a5daSStefan Richter struct completion done; 8777c9a5daSStefan Richter 8877c9a5daSStefan Richter int node_id; 8977c9a5daSStefan Richter int generation; 901e626fdcSStefan Richter int current_tlabel; 911e626fdcSStefan Richter u64 tlabel_mask; 9277c9a5daSStefan Richter struct list_head transaction_list; 93e71084afSClemens Ladisch u64 reset_jiffies; 9477c9a5daSStefan Richter 958e4b50f9SClemens Ladisch u32 split_timeout_hi; 968e4b50f9SClemens Ladisch u32 split_timeout_lo; 978e4b50f9SClemens Ladisch unsigned int split_timeout_cycles; 988e4b50f9SClemens Ladisch unsigned int split_timeout_jiffies; 998e4b50f9SClemens Ladisch 10077c9a5daSStefan Richter unsigned long long guid; 10177c9a5daSStefan Richter unsigned max_receive; 10277c9a5daSStefan Richter int link_speed; 10377c9a5daSStefan Richter int config_rom_generation; 10477c9a5daSStefan Richter 10577c9a5daSStefan Richter spinlock_t lock; /* Take this lock when handling the lists in 10677c9a5daSStefan Richter * this struct. */ 10777c9a5daSStefan Richter struct fw_node *local_node; 10877c9a5daSStefan Richter struct fw_node *root_node; 10977c9a5daSStefan Richter struct fw_node *irm_node; 11077c9a5daSStefan Richter u8 color; /* must be u8 to match the definition in struct fw_node */ 11177c9a5daSStefan Richter int gap_count; 11277c9a5daSStefan Richter bool beta_repeaters_present; 11377c9a5daSStefan Richter 11477c9a5daSStefan Richter int index; 11577c9a5daSStefan Richter struct list_head link; 11677c9a5daSStefan Richter 117bf54e146SStefan Richter struct list_head phy_receiver_list; 118bf54e146SStefan Richter 11902d37bedSStefan Richter struct delayed_work br_work; /* bus reset job */ 12002d37bedSStefan Richter bool br_short; 12102d37bedSStefan Richter 12202d37bedSStefan Richter struct delayed_work bm_work; /* bus manager job */ 12377c9a5daSStefan Richter int bm_retries; 12477c9a5daSStefan Richter int bm_generation; 125250b2b6dSStefan Richter int bm_node_id; 126c8a94dedSStefan Richter bool bm_abdicate; 12777c9a5daSStefan Richter 128db3c9cc1SStefan Richter bool priority_budget_implemented; /* controller feature */ 129db3c9cc1SStefan Richter bool broadcast_channel_auto_allocated; /* controller feature */ 130db3c9cc1SStefan Richter 13177c9a5daSStefan Richter bool broadcast_channel_allocated; 13277c9a5daSStefan Richter u32 broadcast_channel; 133cb7c96daSStefan Richter __be32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4]; 1343d1f46ebSClemens Ladisch 1353d1f46ebSClemens Ladisch __be32 maint_utility_register; 13677c9a5daSStefan Richter }; 13777c9a5daSStefan Richter 138fc5f80b1SChris Boot static inline struct fw_card *fw_card_get(struct fw_card *card) 139fc5f80b1SChris Boot { 140fc5f80b1SChris Boot kref_get(&card->kref); 141fc5f80b1SChris Boot 142fc5f80b1SChris Boot return card; 143fc5f80b1SChris Boot } 144fc5f80b1SChris Boot 145fc5f80b1SChris Boot void fw_card_release(struct kref *kref); 146fc5f80b1SChris Boot 147fc5f80b1SChris Boot static inline void fw_card_put(struct fw_card *card) 148fc5f80b1SChris Boot { 149fc5f80b1SChris Boot kref_put(&card->kref, fw_card_release); 150fc5f80b1SChris Boot } 151fc5f80b1SChris Boot 15277c9a5daSStefan Richter struct fw_attribute_group { 15377c9a5daSStefan Richter struct attribute_group *groups[2]; 15477c9a5daSStefan Richter struct attribute_group group; 155baedee17SClemens Ladisch struct attribute *attrs[13]; 15677c9a5daSStefan Richter }; 15777c9a5daSStefan Richter 15877c9a5daSStefan Richter enum fw_device_state { 15977c9a5daSStefan Richter FW_DEVICE_INITIALIZING, 16077c9a5daSStefan Richter FW_DEVICE_RUNNING, 16177c9a5daSStefan Richter FW_DEVICE_GONE, 16277c9a5daSStefan Richter FW_DEVICE_SHUTDOWN, 16377c9a5daSStefan Richter }; 16477c9a5daSStefan Richter 16577c9a5daSStefan Richter /* 16677c9a5daSStefan Richter * Note, fw_device.generation always has to be read before fw_device.node_id. 16777c9a5daSStefan Richter * Use SMP memory barriers to ensure this. Otherwise requests will be sent 16877c9a5daSStefan Richter * to an outdated node_id if the generation was updated in the meantime due 16977c9a5daSStefan Richter * to a bus reset. 17077c9a5daSStefan Richter * 17177c9a5daSStefan Richter * Likewise, fw-core will take care to update .node_id before .generation so 17277c9a5daSStefan Richter * that whenever fw_device.generation is current WRT the actual bus generation, 17377c9a5daSStefan Richter * fw_device.node_id is guaranteed to be current too. 17477c9a5daSStefan Richter * 17577c9a5daSStefan Richter * The same applies to fw_device.card->node_id vs. fw_device.generation. 17677c9a5daSStefan Richter * 17777c9a5daSStefan Richter * fw_device.config_rom and fw_device.config_rom_length may be accessed during 17877c9a5daSStefan Richter * the lifetime of any fw_unit belonging to the fw_device, before device_del() 17977c9a5daSStefan Richter * was called on the last fw_unit. Alternatively, they may be accessed while 18077c9a5daSStefan Richter * holding fw_device_rwsem. 18177c9a5daSStefan Richter */ 18277c9a5daSStefan Richter struct fw_device { 18377c9a5daSStefan Richter atomic_t state; 18477c9a5daSStefan Richter struct fw_node *node; 18577c9a5daSStefan Richter int node_id; 18677c9a5daSStefan Richter int generation; 18777c9a5daSStefan Richter unsigned max_speed; 18877c9a5daSStefan Richter struct fw_card *card; 18977c9a5daSStefan Richter struct device device; 19077c9a5daSStefan Richter 19177c9a5daSStefan Richter struct mutex client_list_mutex; 19277c9a5daSStefan Richter struct list_head client_list; 19377c9a5daSStefan Richter 19413b302d0SStefan Richter const u32 *config_rom; 19577c9a5daSStefan Richter size_t config_rom_length; 19677c9a5daSStefan Richter int config_rom_retries; 19777c9a5daSStefan Richter unsigned is_local:1; 198837ec787SStefan Richter unsigned max_rec:4; 19977c9a5daSStefan Richter unsigned cmc:1; 200837ec787SStefan Richter unsigned irmc:1; 20177c9a5daSStefan Richter unsigned bc_implemented:2; 20277c9a5daSStefan Richter 20370044d71STejun Heo work_func_t workfn; 20477c9a5daSStefan Richter struct delayed_work work; 20577c9a5daSStefan Richter struct fw_attribute_group attribute_group; 20677c9a5daSStefan Richter }; 20777c9a5daSStefan Richter 20877c9a5daSStefan Richter static inline struct fw_device *fw_device(struct device *dev) 20977c9a5daSStefan Richter { 21077c9a5daSStefan Richter return container_of(dev, struct fw_device, device); 21177c9a5daSStefan Richter } 21277c9a5daSStefan Richter 21377c9a5daSStefan Richter static inline int fw_device_is_shutdown(struct fw_device *device) 21477c9a5daSStefan Richter { 21577c9a5daSStefan Richter return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN; 21677c9a5daSStefan Richter } 21777c9a5daSStefan Richter 21877c9a5daSStefan Richter int fw_device_enable_phys_dma(struct fw_device *device); 21977c9a5daSStefan Richter 22077c9a5daSStefan Richter /* 22177c9a5daSStefan Richter * fw_unit.directory must not be accessed after device_del(&fw_unit.device). 22277c9a5daSStefan Richter */ 22377c9a5daSStefan Richter struct fw_unit { 22477c9a5daSStefan Richter struct device device; 22513b302d0SStefan Richter const u32 *directory; 22677c9a5daSStefan Richter struct fw_attribute_group attribute_group; 22777c9a5daSStefan Richter }; 22877c9a5daSStefan Richter 22977c9a5daSStefan Richter static inline struct fw_unit *fw_unit(struct device *dev) 23077c9a5daSStefan Richter { 23177c9a5daSStefan Richter return container_of(dev, struct fw_unit, device); 23277c9a5daSStefan Richter } 23377c9a5daSStefan Richter 23477c9a5daSStefan Richter static inline struct fw_unit *fw_unit_get(struct fw_unit *unit) 23577c9a5daSStefan Richter { 23677c9a5daSStefan Richter get_device(&unit->device); 23777c9a5daSStefan Richter 23877c9a5daSStefan Richter return unit; 23977c9a5daSStefan Richter } 24077c9a5daSStefan Richter 24177c9a5daSStefan Richter static inline void fw_unit_put(struct fw_unit *unit) 24277c9a5daSStefan Richter { 24377c9a5daSStefan Richter put_device(&unit->device); 24477c9a5daSStefan Richter } 24577c9a5daSStefan Richter 246e5110d01SStefan Richter static inline struct fw_device *fw_parent_device(struct fw_unit *unit) 247e5110d01SStefan Richter { 248e5110d01SStefan Richter return fw_device(unit->device.parent); 249e5110d01SStefan Richter } 250e5110d01SStefan Richter 25177c9a5daSStefan Richter struct ieee1394_device_id; 25277c9a5daSStefan Richter 25377c9a5daSStefan Richter struct fw_driver { 25477c9a5daSStefan Richter struct device_driver driver; 25594a87157SStefan Richter int (*probe)(struct fw_unit *unit, const struct ieee1394_device_id *id); 25677c9a5daSStefan Richter /* Called when the parent device sits through a bus reset. */ 25777c9a5daSStefan Richter void (*update)(struct fw_unit *unit); 25894a87157SStefan Richter void (*remove)(struct fw_unit *unit); 25977c9a5daSStefan Richter const struct ieee1394_device_id *id_table; 26077c9a5daSStefan Richter }; 26177c9a5daSStefan Richter 26277c9a5daSStefan Richter struct fw_packet; 26377c9a5daSStefan Richter struct fw_request; 26477c9a5daSStefan Richter 26577c9a5daSStefan Richter typedef void (*fw_packet_callback_t)(struct fw_packet *packet, 26677c9a5daSStefan Richter struct fw_card *card, int status); 26777c9a5daSStefan Richter typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode, 26877c9a5daSStefan Richter void *data, size_t length, 26977c9a5daSStefan Richter void *callback_data); 27077c9a5daSStefan Richter /* 2714d50c443SStefan Richter * This callback handles an inbound request subaction. It is called in 2724d50c443SStefan Richter * RCU read-side context, therefore must not sleep. 2734d50c443SStefan Richter * 2744d50c443SStefan Richter * The callback should not initiate outbound request subactions directly. 2754d50c443SStefan Richter * Otherwise there is a danger of recursion of inbound and outbound 2764d50c443SStefan Richter * transactions from and to the local node. 2774d50c443SStefan Richter * 2784d50c443SStefan Richter * The callback is responsible that either fw_send_response() or kfree() 2794d50c443SStefan Richter * is called on the @request, except for FCP registers for which the core 2804d50c443SStefan Richter * takes care of that. 28177c9a5daSStefan Richter */ 28277c9a5daSStefan Richter typedef void (*fw_address_callback_t)(struct fw_card *card, 28377c9a5daSStefan Richter struct fw_request *request, 28477c9a5daSStefan Richter int tcode, int destination, int source, 28533e553feSStefan Richter int generation, 28677c9a5daSStefan Richter unsigned long long offset, 28777c9a5daSStefan Richter void *data, size_t length, 28877c9a5daSStefan Richter void *callback_data); 28977c9a5daSStefan Richter 29077c9a5daSStefan Richter struct fw_packet { 29177c9a5daSStefan Richter int speed; 29277c9a5daSStefan Richter int generation; 29377c9a5daSStefan Richter u32 header[4]; 29477c9a5daSStefan Richter size_t header_length; 29577c9a5daSStefan Richter void *payload; 29677c9a5daSStefan Richter size_t payload_length; 29777c9a5daSStefan Richter dma_addr_t payload_bus; 29819593ffdSStefan Richter bool payload_mapped; 29977c9a5daSStefan Richter u32 timestamp; 30077c9a5daSStefan Richter 30177c9a5daSStefan Richter /* 30218d0cdfdSStefan Richter * This callback is called when the packet transmission has completed. 30318d0cdfdSStefan Richter * For successful transmission, the status code is the ack received 30418d0cdfdSStefan Richter * from the destination. Otherwise it is one of the juju-specific 30518d0cdfdSStefan Richter * rcodes: RCODE_SEND_ERROR, _CANCELLED, _BUSY, _GENERATION, _NO_ACK. 30677c9a5daSStefan Richter * The callback can be called from tasklet context and thus 30777c9a5daSStefan Richter * must never block. 30877c9a5daSStefan Richter */ 30977c9a5daSStefan Richter fw_packet_callback_t callback; 31077c9a5daSStefan Richter int ack; 31177c9a5daSStefan Richter struct list_head link; 31277c9a5daSStefan Richter void *driver_data; 31377c9a5daSStefan Richter }; 31477c9a5daSStefan Richter 31577c9a5daSStefan Richter struct fw_transaction { 31677c9a5daSStefan Richter int node_id; /* The generation is implied; it is always the current. */ 31777c9a5daSStefan Richter int tlabel; 31877c9a5daSStefan Richter struct list_head link; 3195c40cbfeSClemens Ladisch struct fw_card *card; 320410cf2bdSClemens Ladisch bool is_split_transaction; 3215c40cbfeSClemens Ladisch struct timer_list split_timeout_timer; 32277c9a5daSStefan Richter 32377c9a5daSStefan Richter struct fw_packet packet; 32477c9a5daSStefan Richter 32577c9a5daSStefan Richter /* 32677c9a5daSStefan Richter * The data passed to the callback is valid only during the 32777c9a5daSStefan Richter * callback. 32877c9a5daSStefan Richter */ 32977c9a5daSStefan Richter fw_transaction_callback_t callback; 33077c9a5daSStefan Richter void *callback_data; 33177c9a5daSStefan Richter }; 33277c9a5daSStefan Richter 33377c9a5daSStefan Richter struct fw_address_handler { 33477c9a5daSStefan Richter u64 offset; 335188726ecSClemens Ladisch u64 length; 33677c9a5daSStefan Richter fw_address_callback_t address_callback; 33777c9a5daSStefan Richter void *callback_data; 33877c9a5daSStefan Richter struct list_head link; 33977c9a5daSStefan Richter }; 34077c9a5daSStefan Richter 34177c9a5daSStefan Richter struct fw_address_region { 34277c9a5daSStefan Richter u64 start; 34377c9a5daSStefan Richter u64 end; 34477c9a5daSStefan Richter }; 34577c9a5daSStefan Richter 34677c9a5daSStefan Richter extern const struct fw_address_region fw_high_memory_region; 34777c9a5daSStefan Richter 34877c9a5daSStefan Richter int fw_core_add_address_handler(struct fw_address_handler *handler, 34977c9a5daSStefan Richter const struct fw_address_region *region); 35077c9a5daSStefan Richter void fw_core_remove_address_handler(struct fw_address_handler *handler); 35177c9a5daSStefan Richter void fw_send_response(struct fw_card *card, 35277c9a5daSStefan Richter struct fw_request *request, int rcode); 353253d9237SChris Boot int fw_get_request_speed(struct fw_request *request); 35477c9a5daSStefan Richter void fw_send_request(struct fw_card *card, struct fw_transaction *t, 35577c9a5daSStefan Richter int tcode, int destination_id, int generation, int speed, 35677c9a5daSStefan Richter unsigned long long offset, void *payload, size_t length, 35777c9a5daSStefan Richter fw_transaction_callback_t callback, void *callback_data); 35877c9a5daSStefan Richter int fw_cancel_transaction(struct fw_card *card, 35977c9a5daSStefan Richter struct fw_transaction *transaction); 36077c9a5daSStefan Richter int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, 36177c9a5daSStefan Richter int generation, int speed, unsigned long long offset, 36277c9a5daSStefan Richter void *payload, size_t length); 3637bdbff67SClemens Ladisch const char *fw_rcode_string(int rcode); 36477c9a5daSStefan Richter 365c76acec6SJay Fenlason static inline int fw_stream_packet_destination_id(int tag, int channel, int sy) 366c76acec6SJay Fenlason { 367c76acec6SJay Fenlason return tag << 14 | channel << 8 | sy; 368c76acec6SJay Fenlason } 369c76acec6SJay Fenlason 370*9b1ee0b2STakashi Sakamoto void fw_schedule_bus_reset(struct fw_card *card, bool delayed, 371*9b1ee0b2STakashi Sakamoto bool short_reset); 372*9b1ee0b2STakashi Sakamoto 373c76acec6SJay Fenlason struct fw_descriptor { 374c76acec6SJay Fenlason struct list_head link; 375c76acec6SJay Fenlason size_t length; 376c76acec6SJay Fenlason u32 immediate; 377c76acec6SJay Fenlason u32 key; 378c76acec6SJay Fenlason const u32 *data; 379c76acec6SJay Fenlason }; 380c76acec6SJay Fenlason 381c76acec6SJay Fenlason int fw_core_add_descriptor(struct fw_descriptor *desc); 382c76acec6SJay Fenlason void fw_core_remove_descriptor(struct fw_descriptor *desc); 383c76acec6SJay Fenlason 384c76acec6SJay Fenlason /* 385c76acec6SJay Fenlason * The iso packet format allows for an immediate header/payload part 386c76acec6SJay Fenlason * stored in 'header' immediately after the packet info plus an 387c76acec6SJay Fenlason * indirect payload part that is pointer to by the 'payload' field. 388c76acec6SJay Fenlason * Applications can use one or the other or both to implement simple 389c76acec6SJay Fenlason * low-bandwidth streaming (e.g. audio) or more advanced 390c76acec6SJay Fenlason * scatter-gather streaming (e.g. assembling video frame automatically). 391c76acec6SJay Fenlason */ 392c76acec6SJay Fenlason struct fw_iso_packet { 393872e330eSStefan Richter u16 payload_length; /* Length of indirect payload */ 394c76acec6SJay Fenlason u32 interrupt:1; /* Generate interrupt on this packet */ 395872e330eSStefan Richter u32 skip:1; /* tx: Set to not send packet at all */ 396872e330eSStefan Richter /* rx: Sync bit, wait for matching sy */ 397872e330eSStefan Richter u32 tag:2; /* tx: Tag in packet header */ 398872e330eSStefan Richter u32 sy:4; /* tx: Sy in packet header */ 399872e330eSStefan Richter u32 header_length:8; /* Length of immediate header */ 400872e330eSStefan Richter u32 header[0]; /* tx: Top of 1394 isoch. data_block */ 401c76acec6SJay Fenlason }; 402c76acec6SJay Fenlason 403c76acec6SJay Fenlason #define FW_ISO_CONTEXT_TRANSMIT 0 404c76acec6SJay Fenlason #define FW_ISO_CONTEXT_RECEIVE 1 405872e330eSStefan Richter #define FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL 2 406c76acec6SJay Fenlason 407c76acec6SJay Fenlason #define FW_ISO_CONTEXT_MATCH_TAG0 1 408c76acec6SJay Fenlason #define FW_ISO_CONTEXT_MATCH_TAG1 2 409c76acec6SJay Fenlason #define FW_ISO_CONTEXT_MATCH_TAG2 4 410c76acec6SJay Fenlason #define FW_ISO_CONTEXT_MATCH_TAG3 8 411c76acec6SJay Fenlason #define FW_ISO_CONTEXT_MATCH_ALL_TAGS 15 412c76acec6SJay Fenlason 413c76acec6SJay Fenlason /* 414c76acec6SJay Fenlason * An iso buffer is just a set of pages mapped for DMA in the 415c76acec6SJay Fenlason * specified direction. Since the pages are to be used for DMA, they 416c76acec6SJay Fenlason * are not mapped into the kernel virtual address space. We store the 417c76acec6SJay Fenlason * DMA address in the page private. The helper function 418c76acec6SJay Fenlason * fw_iso_buffer_map() will map the pages into a given vma. 419c76acec6SJay Fenlason */ 420c76acec6SJay Fenlason struct fw_iso_buffer { 421c76acec6SJay Fenlason enum dma_data_direction direction; 422c76acec6SJay Fenlason struct page **pages; 423c76acec6SJay Fenlason int page_count; 4240b6c4857SStefan Richter int page_count_mapped; 425c76acec6SJay Fenlason }; 426c76acec6SJay Fenlason 427c76acec6SJay Fenlason int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card, 428c76acec6SJay Fenlason int page_count, enum dma_data_direction direction); 429c76acec6SJay Fenlason void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card); 430872e330eSStefan Richter size_t fw_iso_buffer_lookup(struct fw_iso_buffer *buffer, dma_addr_t completed); 431c76acec6SJay Fenlason 432c76acec6SJay Fenlason struct fw_iso_context; 433c76acec6SJay Fenlason typedef void (*fw_iso_callback_t)(struct fw_iso_context *context, 434c76acec6SJay Fenlason u32 cycle, size_t header_length, 435c76acec6SJay Fenlason void *header, void *data); 436872e330eSStefan Richter typedef void (*fw_iso_mc_callback_t)(struct fw_iso_context *context, 437872e330eSStefan Richter dma_addr_t completed, void *data); 438c76acec6SJay Fenlason struct fw_iso_context { 439c76acec6SJay Fenlason struct fw_card *card; 440c76acec6SJay Fenlason int type; 441c76acec6SJay Fenlason int channel; 442c76acec6SJay Fenlason int speed; 4430699a73aSClemens Ladisch bool drop_overflow_headers; 444c76acec6SJay Fenlason size_t header_size; 445872e330eSStefan Richter union { 446872e330eSStefan Richter fw_iso_callback_t sc; 447872e330eSStefan Richter fw_iso_mc_callback_t mc; 448872e330eSStefan Richter } callback; 449c76acec6SJay Fenlason void *callback_data; 450c76acec6SJay Fenlason }; 451c76acec6SJay Fenlason 452c76acec6SJay Fenlason struct fw_iso_context *fw_iso_context_create(struct fw_card *card, 453c76acec6SJay Fenlason int type, int channel, int speed, size_t header_size, 454c76acec6SJay Fenlason fw_iso_callback_t callback, void *callback_data); 455872e330eSStefan Richter int fw_iso_context_set_channels(struct fw_iso_context *ctx, u64 *channels); 456c76acec6SJay Fenlason int fw_iso_context_queue(struct fw_iso_context *ctx, 457c76acec6SJay Fenlason struct fw_iso_packet *packet, 458c76acec6SJay Fenlason struct fw_iso_buffer *buffer, 459c76acec6SJay Fenlason unsigned long payload); 46013882a82SClemens Ladisch void fw_iso_context_queue_flush(struct fw_iso_context *ctx); 461d1bbd209SClemens Ladisch int fw_iso_context_flush_completions(struct fw_iso_context *ctx); 462c76acec6SJay Fenlason int fw_iso_context_start(struct fw_iso_context *ctx, 463c76acec6SJay Fenlason int cycle, int sync, int tags); 464c76acec6SJay Fenlason int fw_iso_context_stop(struct fw_iso_context *ctx); 465c76acec6SJay Fenlason void fw_iso_context_destroy(struct fw_iso_context *ctx); 46631ef9134SClemens Ladisch void fw_iso_resource_manage(struct fw_card *card, int generation, 46731ef9134SClemens Ladisch u64 channels_mask, int *channel, int *bandwidth, 468f30e6d3eSStefan Richter bool allocate); 469c76acec6SJay Fenlason 470105e53f8SStefan Richter extern struct workqueue_struct *fw_workqueue; 471105e53f8SStefan Richter 47277c9a5daSStefan Richter #endif /* _LINUX_FIREWIRE_H */ 473