Commit 19a15b93 authored by Kristian Høgsberg's avatar Kristian Høgsberg Committed by Stefan Richter

firewire: Add device probing and sysfs integration.

Signed-off-by: default avatarKristian Høgsberg <krh@redhat.com>
Signed-off-by: default avatarStefan Richter <stefanr@s5r6.in-berlin.de>
parent 3038e353
......@@ -2,6 +2,7 @@
# Makefile for the Linux IEEE 1394 implementation
#
fw-core-objs := fw-card.o fw-topology.o fw-transaction.o fw-iso.o
fw-core-objs := fw-card.o fw-topology.o fw-transaction.o fw-iso.o \
fw-device.o fw-device-cdev.o
obj-$(CONFIG_FW) += fw-core.o
......@@ -24,6 +24,7 @@
#include <linux/device.h>
#include "fw-transaction.h"
#include "fw-topology.h"
#include "fw-device.h"
/* The lib/crc16.c implementation uses the standard (0x8005)
* polynomial, but we need the ITU-T (or CCITT) polynomial (0x1021).
......@@ -185,6 +186,59 @@ fw_core_remove_descriptor (struct fw_descriptor *desc)
}
EXPORT_SYMBOL(fw_core_remove_descriptor);
static void
fw_card_irm_work(struct work_struct *work)
{
struct fw_card *card =
container_of(work, struct fw_card, work.work);
struct fw_device *root;
unsigned long flags;
int new_irm_id, generation;
/* FIXME: This simple bus management unconditionally picks a
* cycle master if the current root can't do it. We need to
* not do this if there is a bus manager already. Also, some
* hubs set the contender bit, which is bogus, so we should
* probably do a little sanity check on the IRM (like, read
* the bandwidth register) if it's not us. */
spin_lock_irqsave(&card->lock, flags);
generation = card->generation;
root = card->root_node->data;
if (root == NULL)
/* Either link_on is false, or we failed to read the
* config rom. In either case, pick another root. */
new_irm_id = card->local_node->node_id;
else if (root->state != FW_DEVICE_RUNNING)
/* If we haven't probed this device yet, bail out now
* and let's try again once that's done. */
new_irm_id = -1;
else if (root->config_rom[2] & bib_cmc)
/* FIXME: I suppose we should set the cmstr bit in the
* STATE_CLEAR register of this node, as described in
* 1394-1995, 8.4.2.6. Also, send out a force root
* packet for this node. */
new_irm_id = -1;
else
/* Current root has an active link layer and we
* successfully read the config rom, but it's not
* cycle master capable. */
new_irm_id = card->local_node->node_id;
if (card->irm_retries++ > 5)
new_irm_id = -1;
spin_unlock_irqrestore(&card->lock, flags);
if (new_irm_id > 0) {
fw_notify("Trying to become root (card %d)\n", card->index);
fw_send_force_root(card, new_irm_id, generation);
fw_core_initiate_bus_reset(card, 1);
}
}
static void
release_card(struct device *device)
{
......@@ -222,6 +276,8 @@ fw_card_initialize(struct fw_card *card, struct fw_card_driver *driver,
card->local_node = NULL;
INIT_DELAYED_WORK(&card->work, fw_card_irm_work);
card->card_device.bus = &fw_bus_type;
card->card_device.release = release_card;
card->card_device.parent = card->device;
......
This diff is collapsed.
/* -*- c-basic-offset: 8 -*-
*
* fw-device-cdev.h -- Char device interface.
*
* Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __fw_cdev_h
#define __fw_cdev_h
#include <asm/ioctl.h>
#include <asm/types.h>
#define TCODE_WRITE_QUADLET_REQUEST 0
#define TCODE_WRITE_BLOCK_REQUEST 1
#define TCODE_WRITE_RESPONSE 2
#define TCODE_READ_QUADLET_REQUEST 4
#define TCODE_READ_BLOCK_REQUEST 5
#define TCODE_READ_QUADLET_RESPONSE 6
#define TCODE_READ_BLOCK_RESPONSE 7
#define TCODE_CYCLE_START 8
#define TCODE_LOCK_REQUEST 9
#define TCODE_STREAM_DATA 10
#define TCODE_LOCK_RESPONSE 11
#define RCODE_COMPLETE 0x0
#define RCODE_CONFLICT_ERROR 0x4
#define RCODE_DATA_ERROR 0x5
#define RCODE_TYPE_ERROR 0x6
#define RCODE_ADDRESS_ERROR 0x7
#define SCODE_100 0x0
#define SCODE_200 0x1
#define SCODE_400 0x2
#define SCODE_800 0x3
#define SCODE_1600 0x4
#define SCODE_3200 0x5
#define FW_CDEV_EVENT_RESPONSE 0x00
#define FW_CDEV_EVENT_REQUEST 0x01
#define FW_CDEV_EVENT_ISO_INTERRUPT 0x02
/* The 'closure' fields are for user space to use. Data passed in the
* 'closure' field for a request will be returned in the corresponding
* event. It's a 64-bit type so that it's a fixed size type big
* enough to hold a pointer on all platforms. */
struct fw_cdev_event_response {
__u32 type;
__u32 rcode;
__u64 closure;
__u32 length;
__u32 data[0];
};
struct fw_cdev_event_request {
__u32 type;
__u32 tcode;
__u64 offset;
__u64 closure;
__u32 serial;
__u32 length;
__u32 data[0];
};
struct fw_cdev_event_iso_interrupt {
__u32 type;
__u32 cycle;
__u64 closure;
};
#define FW_CDEV_IOC_GET_CONFIG_ROM _IOR('#', 0x00, struct fw_cdev_get_config_rom)
#define FW_CDEV_IOC_SEND_REQUEST _IO('#', 0x01)
#define FW_CDEV_IOC_ALLOCATE _IO('#', 0x02)
#define FW_CDEV_IOC_SEND_RESPONSE _IO('#', 0x03)
#define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IO('#', 0x04)
#define FW_CDEV_IOC_QUEUE_ISO _IO('#', 0x05)
#define FW_CDEV_IOC_SEND_ISO _IO('#', 0x06)
struct fw_cdev_get_config_rom {
__u32 length;
__u32 data[256];
};
struct fw_cdev_send_request {
__u32 tcode;
__u32 length;
__u64 offset;
__u64 closure;
__u64 data;
};
struct fw_cdev_send_response {
__u32 rcode;
__u32 length;
__u64 data;
__u32 serial;
};
struct fw_cdev_allocate {
__u64 offset;
__u64 closure;
__u32 length;
};
struct fw_cdev_create_iso_context {
__u32 buffer_size;
};
struct fw_cdev_iso_packet {
__u16 payload_length; /* Length of indirect payload. */
__u32 interrupt : 1; /* Generate interrupt on this packet */
__u32 skip : 1; /* Set to not send packet at all. */
__u32 tag : 2;
__u32 sy : 4;
__u32 header_length : 8; /* Length of immediate header. */
__u32 header[0];
};
struct fw_cdev_queue_iso {
__u32 size;
__u64 packets;
__u64 data;
};
struct fw_cdev_send_iso {
__u32 channel;
__u32 speed;
__s32 cycle;
};
#endif
This diff is collapsed.
/* -*- c-basic-offset: 8 -*-
*
* fw-device.h - Device probing and sysfs code.
*
* Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __fw_device_h
#define __fw_device_h
#include <linux/fs.h>
#include <linux/cdev.h>
enum fw_device_state {
FW_DEVICE_INITIALIZING,
FW_DEVICE_RUNNING,
FW_DEVICE_SHUTDOWN
};
struct fw_device {
int state;
struct fw_node *node;
int node_id;
int generation;
struct fw_card *card;
struct device device;
struct cdev cdev;
__be32 *config_rom;
size_t config_rom_length;
int config_rom_retries;
struct delayed_work work;
};
static inline struct fw_device *
fw_device(struct device *dev)
{
return container_of(dev, struct fw_device, device);
}
struct fw_device *fw_device_get(struct fw_device *device);
void fw_device_put(struct fw_device *device);
int fw_device_enable_phys_dma(struct fw_device *device);
struct fw_unit {
struct device device;
u32 *directory;
};
static inline struct fw_unit *
fw_unit(struct device *dev)
{
return container_of(dev, struct fw_unit, device);
}
#define CSR_OFFSET 0x40
#define CSR_LEAF 0x80
#define CSR_DIRECTORY 0xc0
#define CSR_DESCRIPTOR 0x01
#define CSR_VENDOR 0x03
#define CSR_HARDWARE_VERSION 0x04
#define CSR_NODE_CAPABILITIES 0x0c
#define CSR_UNIT 0x11
#define CSR_SPECIFIER_ID 0x12
#define CSR_VERSION 0x13
#define CSR_DEPENDENT_INFO 0x14
#define CSR_MODEL 0x17
#define CSR_INSTANCE 0x18
#define SBP2_COMMAND_SET_SPECIFIER 0x38
#define SBP2_COMMAND_SET 0x39
#define SBP2_COMMAND_SET_REVISION 0x3b
#define SBP2_FIRMWARE_REVISION 0x3c
struct fw_csr_iterator {
u32 *p;
u32 *end;
};
void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
int fw_csr_iterator_next(struct fw_csr_iterator *ci,
int *key, int *value);
#define FW_MATCH_VENDOR 0x0001
#define FW_MATCH_MODEL 0x0002
#define FW_MATCH_SPECIFIER_ID 0x0004
#define FW_MATCH_VERSION 0x0008
struct fw_device_id {
u32 match_flags;
u32 vendor;
u32 model;
u32 specifier_id;
u32 version;
void *driver_data;
};
struct fw_driver {
struct device_driver driver;
/* Called when the parent device sits through a bus reset. */
void (*update) (struct fw_unit *unit);
struct fw_device_id *id_table;
};
static inline struct fw_driver *
fw_driver(struct device_driver *drv)
{
return container_of(drv, struct fw_driver, driver);
}
extern struct file_operations fw_device_ops;
#endif
......@@ -26,6 +26,7 @@
#include "fw-transaction.h"
#include "fw-topology.h"
#include "fw-device.h"
static int
setup_iso_buffer(struct fw_iso_context *ctx, size_t size,
......
......@@ -434,13 +434,15 @@ fw_core_handle_bus_reset(struct fw_card *card,
for_each_fw_node(card, local_node, report_found_node);
} else {
update_tree(card, local_node, &changed);
if (changed)
card->irm_retries = 0;
}
/* If we're not the root node, we may have to do some IRM work. */
if (card->local_node != card->root_node)
schedule_delayed_work(&card->work, 0);
spin_unlock_irqrestore(&card->lock, flags);
}
EXPORT_SYMBOL(fw_core_handle_bus_reset);
void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
{
}
......@@ -33,6 +33,7 @@
#include "fw-transaction.h"
#include "fw-topology.h"
#include "fw-device.h"
#define header_pri(pri) ((pri) << 0)
#define header_tcode(tcode) ((tcode) << 4)
......@@ -702,10 +703,6 @@ static struct fw_descriptor vendor_textual_descriptor = {
.data = vendor_textual_descriptor_data
};
struct bus_type fw_bus_type = {
.name = "fw",
};
static int __init fw_core_init(void)
{
int retval;
......
......@@ -265,6 +265,10 @@ struct fw_card {
struct device card_device;
struct list_head link;
/* Work struct for IRM duties. */
struct delayed_work work;
int irm_retries;
};
struct fw_card *fw_card_get(struct fw_card *card);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment