177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#ifndef _FIREWIRE_CORE_H 277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define _FIREWIRE_CORE_H 377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 426b4950de174bc96c27b77546370dec84fb75ae7Stefan Richter#include <linux/compiler.h> 5210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter#include <linux/device.h> 60b6c4857f7684f6d3f59e0506f62953575346978Stefan Richter#include <linux/dma-mapping.h> 777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#include <linux/fs.h> 877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#include <linux/list.h> 977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#include <linux/idr.h> 1077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#include <linux/mm_types.h> 1177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#include <linux/rwsem.h> 1277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#include <linux/slab.h> 1377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#include <linux/types.h> 1477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 1560063497a95e716c9a689af3be2687d261f115b4Arun Sharma#include <linux/atomic.h> 1677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 1777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct device; 1877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct fw_card; 1977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct fw_device; 2077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct fw_iso_buffer; 2177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct fw_iso_context; 2277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct fw_iso_packet; 2377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct fw_node; 2477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct fw_packet; 2577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 2677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 2777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter/* -card */ 2877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 2926b4950de174bc96c27b77546370dec84fb75ae7Stefan Richterextern __printf(2, 3) 3026b4950de174bc96c27b77546370dec84fb75ae7Stefan Richtervoid fw_err(const struct fw_card *card, const char *fmt, ...); 3126b4950de174bc96c27b77546370dec84fb75ae7Stefan Richterextern __printf(2, 3) 3226b4950de174bc96c27b77546370dec84fb75ae7Stefan Richtervoid fw_notice(const struct fw_card *card, const char *fmt, ...); 3326b4950de174bc96c27b77546370dec84fb75ae7Stefan Richter 3477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter/* bitfields within the PHY registers */ 3577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define PHY_LINK_ACTIVE 0x80 3677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define PHY_CONTENDER 0x40 3777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define PHY_BUS_RESET 0x40 38925e7a6504966b838c519f009086982c68e0666fClemens Ladisch#define PHY_EXTENDED_REGISTERS 0xe0 3977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define PHY_BUS_SHORT_RESET 0x40 40e7014dada041982ae12ba7fd1967ca0ab0243e04Clemens Ladisch#define PHY_INT_STATUS_BITS 0x3c 41925e7a6504966b838c519f009086982c68e0666fClemens Ladisch#define PHY_ENABLE_ACCEL 0x02 42925e7a6504966b838c519f009086982c68e0666fClemens Ladisch#define PHY_ENABLE_MULTI 0x01 43925e7a6504966b838c519f009086982c68e0666fClemens Ladisch#define PHY_PAGE_SELECT 0xe0 4477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 4577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define BANDWIDTH_AVAILABLE_INITIAL 4915 4677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define BROADCAST_CHANNEL_INITIAL (1 << 31 | 31) 4777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define BROADCAST_CHANNEL_VALID (1 << 30) 4877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 494ffb7a6a066e4be4577976d1c08e237c7479770aClemens Ladisch#define CSR_STATE_BIT_CMSTR (1 << 8) 507e0e314f198d5048b74c8f0ef9f4c1c02e5ecfc9Clemens Ladisch#define CSR_STATE_BIT_ABDICATE (1 << 10) 514ffb7a6a066e4be4577976d1c08e237c7479770aClemens Ladisch 5277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct fw_card_driver { 5377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter /* 5477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * Enable the given card with the given initial config rom. 5577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * This function is expected to activate the card, and either 5677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * enable the PHY or set the link_on bit and initiate a bus 5777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * reset. 5877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter */ 598e85973efc87dfae8508f1a3440fd44612897458Stefan Richter int (*enable)(struct fw_card *card, 608e85973efc87dfae8508f1a3440fd44612897458Stefan Richter const __be32 *config_rom, size_t length); 6177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 6202d37bed188c500ee7afb0a2dc6b65a80704c58eStefan Richter int (*read_phy_reg)(struct fw_card *card, int address); 6377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int (*update_phy_reg)(struct fw_card *card, int address, 6477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int clear_bits, int set_bits); 6577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 6677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter /* 6777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * Update the config rom for an enabled card. This function 6877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * should change the config rom that is presented on the bus 698e85973efc87dfae8508f1a3440fd44612897458Stefan Richter * and initiate a bus reset. 7077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter */ 7177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int (*set_config_rom)(struct fw_card *card, 728e85973efc87dfae8508f1a3440fd44612897458Stefan Richter const __be32 *config_rom, size_t length); 7377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 7477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter void (*send_request)(struct fw_card *card, struct fw_packet *packet); 7577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter void (*send_response)(struct fw_card *card, struct fw_packet *packet); 7677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter /* Calling cancel is valid once a packet has been submitted. */ 7777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int (*cancel_packet)(struct fw_card *card, struct fw_packet *packet); 7877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 7977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter /* 8077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * Allow the specified node ID to do direct DMA out and in of 8177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * host memory. The card will disable this for all node when 8277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * a bus reset happens, so driver need to reenable this after 8377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * bus reset. Returns 0 on success, -ENODEV if the card 8477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * doesn't support this, -ESTALE if the generation doesn't 8577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * match. 8677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter */ 8777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int (*enable_phys_dma)(struct fw_card *card, 8877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int node_id, int generation); 8977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 900fcff4e39323f466a47684d7c8ffa77e1be86c8aStefan Richter u32 (*read_csr)(struct fw_card *card, int csr_offset); 910fcff4e39323f466a47684d7c8ffa77e1be86c8aStefan Richter void (*write_csr)(struct fw_card *card, int csr_offset, u32 value); 9277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 9377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter struct fw_iso_context * 9477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter (*allocate_iso_context)(struct fw_card *card, 9577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int type, int channel, size_t header_size); 9677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter void (*free_iso_context)(struct fw_iso_context *ctx); 9777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 9877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int (*start_iso)(struct fw_iso_context *ctx, 9977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter s32 cycle, u32 sync, u32 tags); 10077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 101872e330e38806d835bd6c311c93ab998e2fb9058Stefan Richter int (*set_iso_channels)(struct fw_iso_context *ctx, u64 *channels); 102872e330e38806d835bd6c311c93ab998e2fb9058Stefan Richter 10377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int (*queue_iso)(struct fw_iso_context *ctx, 10477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter struct fw_iso_packet *packet, 10577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter struct fw_iso_buffer *buffer, 10677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter unsigned long payload); 10777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 10813882a82ee1646336c3996c93b4a560a55d2a419Clemens Ladisch void (*flush_queue_iso)(struct fw_iso_context *ctx); 10913882a82ee1646336c3996c93b4a560a55d2a419Clemens Ladisch 110d1bbd20972936b9b178fda3eb1ec417cb27fdc01Clemens Ladisch int (*flush_iso_completions)(struct fw_iso_context *ctx); 111d1bbd20972936b9b178fda3eb1ec417cb27fdc01Clemens Ladisch 11277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int (*stop_iso)(struct fw_iso_context *ctx); 11377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter}; 11477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 11577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_card_initialize(struct fw_card *card, 11677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter const struct fw_card_driver *driver, struct device *device); 11777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterint fw_card_add(struct fw_card *card, 11877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u32 max_receive, u32 link_speed, u64 guid); 11977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_core_remove_card(struct fw_card *card); 120cb7c96da3651111efbe088fa12f9bed61836ea93Stefan Richterint fw_compute_block_crc(__be32 *block); 12177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_schedule_bm_work(struct fw_card *card, unsigned long delay); 12277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 12377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter/* -cdev */ 12477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 12577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterextern const struct file_operations fw_device_ops; 12677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 12777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_device_cdev_update(struct fw_device *device); 12877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_device_cdev_remove(struct fw_device *device); 129bf54e1462b9192fdef7ea9e2bc44fdc16a4b87bcStefan Richtervoid fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p); 13077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 13177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 13277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter/* -device */ 13377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 13477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterextern struct rw_semaphore fw_device_rwsem; 13577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterextern struct idr fw_device_idr; 13677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterextern int fw_cdev_major; 13777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 138210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richterstatic inline struct fw_device *fw_device_get(struct fw_device *device) 139210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter{ 140210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter get_device(&device->device); 141210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter 142210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter return device; 143210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter} 144210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter 145210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richterstatic inline void fw_device_put(struct fw_device *device) 146210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter{ 147210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter put_device(&device->device); 148210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter} 149210762268466634ddbfaddb48fdf5181ce4b5f2dStefan Richter 15077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct fw_device *fw_device_get_by_devt(dev_t devt); 151099d54143e49d49c33cd25779ca725191df59b73Stefan Richterint fw_device_set_broadcast_channel(struct device *dev, void *gen); 15277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_node_event(struct fw_card *card, struct fw_node *node, int event); 15377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 15477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 15577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter/* -iso */ 15677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 1570b6c4857f7684f6d3f59e0506f62953575346978Stefan Richterint fw_iso_buffer_alloc(struct fw_iso_buffer *buffer, int page_count); 1580b6c4857f7684f6d3f59e0506f62953575346978Stefan Richterint fw_iso_buffer_map_dma(struct fw_iso_buffer *buffer, struct fw_card *card, 1590b6c4857f7684f6d3f59e0506f62953575346978Stefan Richter enum dma_data_direction direction); 1600b6c4857f7684f6d3f59e0506f62953575346978Stefan Richterint fw_iso_buffer_map_vma(struct fw_iso_buffer *buffer, 1610b6c4857f7684f6d3f59e0506f62953575346978Stefan Richter struct vm_area_struct *vma); 16277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 16377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 16477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter/* -topology */ 16577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 16677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterenum { 16777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter FW_NODE_CREATED, 16877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter FW_NODE_UPDATED, 16977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter FW_NODE_DESTROYED, 17077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter FW_NODE_LINK_ON, 17177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter FW_NODE_LINK_OFF, 17277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter FW_NODE_INITIATED_RESET, 17377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter}; 17477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 17577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstruct fw_node { 17677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u16 node_id; 17777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u8 color; 17877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u8 port_count; 17977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u8 link_on:1; 18077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u8 initiated_reset:1; 18177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u8 b_path:1; 18277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u8 phy_speed:2; /* As in the self ID packet. */ 18377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u8 max_speed:2; /* Minimum of all phy-speeds on the path from the 18477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * local node to this node. */ 18577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u8 max_depth:4; /* Maximum depth to any leaf node */ 18677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter u8 max_hops:4; /* Max hops in this sub tree */ 18777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter atomic_t ref_count; 18877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 18977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter /* For serializing node topology into a list. */ 19077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter struct list_head link; 19177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 19277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter /* Upper layer specific data. */ 19377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter void *data; 19477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 19577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter struct fw_node *ports[0]; 19677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter}; 19777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 19877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstatic inline struct fw_node *fw_node_get(struct fw_node *node) 19977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter{ 20077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter atomic_inc(&node->ref_count); 20177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 20277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter return node; 20377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter} 20477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 20577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstatic inline void fw_node_put(struct fw_node *node) 20677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter{ 20777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter if (atomic_dec_and_test(&node->ref_count)) 20877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter kfree(node); 20977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter} 21077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 21177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_core_handle_bus_reset(struct fw_card *card, int node_id, 212c8a94ded57e9cc2498d401b2f5c856213a3e19fbStefan Richter int generation, int self_id_count, u32 *self_ids, bool bm_abdicate); 21377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_destroy_nodes(struct fw_card *card); 21477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 21577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter/* 21677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * Check whether new_generation is the immediate successor of old_generation. 21777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter * Take counter roll-over at 255 (as per OHCI) into account. 21877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter */ 21977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richterstatic inline bool is_next_generation(int new_generation, int old_generation) 22077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter{ 22177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter return (new_generation & 0xff) == ((old_generation + 1) & 0xff); 22277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter} 22377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 22477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 22577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter/* -transaction */ 22677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 2275b06db166c4d38638980283505259fa165d4f369Clemens Ladisch#define TCODE_LINK_INTERNAL 0xe 2285b06db166c4d38638980283505259fa165d4f369Clemens Ladisch 22977c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4) 23077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0) 2315b06db166c4d38638980283505259fa165d4f369Clemens Ladisch#define TCODE_IS_LINK_INTERNAL(tcode) ((tcode) == TCODE_LINK_INTERNAL) 23277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define TCODE_IS_REQUEST(tcode) (((tcode) & 2) == 0) 23377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define TCODE_IS_RESPONSE(tcode) (((tcode) & 2) != 0) 23477c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define TCODE_HAS_REQUEST_DATA(tcode) (((tcode) & 12) != 4) 23577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define TCODE_HAS_RESPONSE_DATA(tcode) (((tcode) & 12) != 0) 23677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 23777c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#define LOCAL_BUS 0xffc0 23877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 2392fe2023adf695d08af5b598b2be3b288a95d563cStefan Richter/* OHCI-1394's default upper bound for physical DMA: 4 GB */ 2402fe2023adf695d08af5b598b2be3b288a95d563cStefan Richter#define FW_MAX_PHYSICAL_RANGE (1ULL << 32) 241fcd46b34425da52703fe65b7f08850c509dcb0edStefan Richter 24277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_core_handle_request(struct fw_card *card, struct fw_packet *request); 24377c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_core_handle_response(struct fw_card *card, struct fw_packet *packet); 244a10c0ce76098857b899505d05de9f2e13ddf7a7aClemens Ladischint fw_get_response_length(struct fw_request *request); 24577c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_fill_response(struct fw_packet *response, u32 *request_header, 24677c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int rcode, void *payload, size_t length); 24702d37bed188c500ee7afb0a2dc6b65a80704c58eStefan Richter 24802d37bed188c500ee7afb0a2dc6b65a80704c58eStefan Richter#define FW_PHY_CONFIG_NO_NODE_ID -1 24902d37bed188c500ee7afb0a2dc6b65a80704c58eStefan Richter#define FW_PHY_CONFIG_CURRENT_GAP_COUNT -1 25077c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richtervoid fw_send_phy_config(struct fw_card *card, 25177c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter int node_id, int generation, int gap_count); 25277c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter 253cc550216ae9a2993ef3973464714dc1a39ab1f86Stefan Richterstatic inline bool is_ping_packet(u32 *data) 254cc550216ae9a2993ef3973464714dc1a39ab1f86Stefan Richter{ 255cc550216ae9a2993ef3973464714dc1a39ab1f86Stefan Richter return (data[0] & 0xc0ffffff) == 0 && ~data[0] == data[1]; 256cc550216ae9a2993ef3973464714dc1a39ab1f86Stefan Richter} 257cc550216ae9a2993ef3973464714dc1a39ab1f86Stefan Richter 25877c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3cStefan Richter#endif /* _FIREWIRE_CORE_H */ 259