Commit c9755e14 authored by Stefan Richter's avatar Stefan Richter

firewire: reread config ROM when device reset the bus

When a device changes its configuration ROM, it announces this with a
bus reset.  firewire-core has to check which node initiated a bus reset
and whether any unit directories went away or were added on this node.

Tested with an IOI FWB-IDE01AB which has its link-on bit set if bus
power is available but does not respond to ROM read requests if self
power is off.  This implements
  - recognition of the units if self power is switched on after fw-core
    gave up the initial attempt to read the config ROM,
  - shutdown of the units when self power is switched off.

Also tested with a second PC running Linux/ieee1394.  When the eth1394
driver is inserted and removed on that node, fw-core now notices the
addition and removal of the IPv4 unit on the ieee1394 node.
Signed-off-by: default avatarStefan Richter <stefanr@s5r6.in-berlin.de>
parent 1dadff71
...@@ -331,7 +331,7 @@ fw_card_bm_work(struct work_struct *work) ...@@ -331,7 +331,7 @@ fw_card_bm_work(struct work_struct *work)
*/ */
spin_unlock_irqrestore(&card->lock, flags); spin_unlock_irqrestore(&card->lock, flags);
goto out; goto out;
} else if (root_device->config_rom[2] & BIB_CMC) { } else if (root_device->cmc) {
/* /*
* FIXME: I suppose we should set the cmstr bit in the * FIXME: I suppose we should set the cmstr bit in the
* STATE_CLEAR register of this node, as described in * STATE_CLEAR register of this node, as described in
......
...@@ -269,21 +269,28 @@ static int ioctl_get_info(struct client *client, void *buffer) ...@@ -269,21 +269,28 @@ static int ioctl_get_info(struct client *client, void *buffer)
{ {
struct fw_cdev_get_info *get_info = buffer; struct fw_cdev_get_info *get_info = buffer;
struct fw_cdev_event_bus_reset bus_reset; struct fw_cdev_event_bus_reset bus_reset;
unsigned long ret = 0;
client->version = get_info->version; client->version = get_info->version;
get_info->version = FW_CDEV_VERSION; get_info->version = FW_CDEV_VERSION;
down_read(&fw_device_rwsem);
if (get_info->rom != 0) { if (get_info->rom != 0) {
void __user *uptr = u64_to_uptr(get_info->rom); void __user *uptr = u64_to_uptr(get_info->rom);
size_t want = get_info->rom_length; size_t want = get_info->rom_length;
size_t have = client->device->config_rom_length * 4; size_t have = client->device->config_rom_length * 4;
if (copy_to_user(uptr, client->device->config_rom, ret = copy_to_user(uptr, client->device->config_rom,
min(want, have))) min(want, have));
return -EFAULT;
} }
get_info->rom_length = client->device->config_rom_length * 4; get_info->rom_length = client->device->config_rom_length * 4;
up_read(&fw_device_rwsem);
if (ret != 0)
return -EFAULT;
client->bus_reset_closure = get_info->bus_reset_closure; client->bus_reset_closure = get_info->bus_reset_closure;
if (get_info->bus_reset != 0) { if (get_info->bus_reset != 0) {
void __user *uptr = u64_to_uptr(get_info->bus_reset); void __user *uptr = u64_to_uptr(get_info->bus_reset);
......
This diff is collapsed.
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/cdev.h> #include <linux/cdev.h>
#include <linux/rwsem.h>
#include <asm/atomic.h> #include <asm/atomic.h>
enum fw_device_state { enum fw_device_state {
...@@ -46,6 +47,11 @@ struct fw_attribute_group { ...@@ -46,6 +47,11 @@ struct fw_attribute_group {
* fw_device.node_id is guaranteed to be current too. * fw_device.node_id is guaranteed to be current too.
* *
* The same applies to fw_device.card->node_id vs. fw_device.generation. * The same applies to fw_device.card->node_id vs. fw_device.generation.
*
* fw_device.config_rom and fw_device.config_rom_length may be accessed during
* the lifetime of any fw_unit belonging to the fw_device, before device_del()
* was called on the last fw_unit. Alternatively, they may be accessed while
* holding fw_device_rwsem.
*/ */
struct fw_device { struct fw_device {
atomic_t state; atomic_t state;
...@@ -53,6 +59,7 @@ struct fw_device { ...@@ -53,6 +59,7 @@ struct fw_device {
int node_id; int node_id;
int generation; int generation;
unsigned max_speed; unsigned max_speed;
bool cmc;
struct fw_card *card; struct fw_card *card;
struct device device; struct device device;
struct list_head link; struct list_head link;
...@@ -92,8 +99,12 @@ int fw_device_enable_phys_dma(struct fw_device *device); ...@@ -92,8 +99,12 @@ int fw_device_enable_phys_dma(struct fw_device *device);
void fw_device_cdev_update(struct fw_device *device); void fw_device_cdev_update(struct fw_device *device);
void fw_device_cdev_remove(struct fw_device *device); void fw_device_cdev_remove(struct fw_device *device);
extern struct rw_semaphore fw_device_rwsem;
extern int fw_cdev_major; extern int fw_cdev_major;
/*
* fw_unit.directory must not be accessed after device_del(&fw_unit.device).
*/
struct fw_unit { struct fw_unit {
struct device device; struct device device;
u32 *directory; u32 *directory;
......
...@@ -153,6 +153,7 @@ struct sbp2_target { ...@@ -153,6 +153,7 @@ struct sbp2_target {
struct list_head lu_list; struct list_head lu_list;
u64 management_agent_address; u64 management_agent_address;
u64 guid;
int directory_id; int directory_id;
int node_id; int node_id;
int address_high; int address_high;
...@@ -1114,6 +1115,7 @@ static int sbp2_probe(struct device *dev) ...@@ -1114,6 +1115,7 @@ static int sbp2_probe(struct device *dev)
kref_init(&tgt->kref); kref_init(&tgt->kref);
INIT_LIST_HEAD(&tgt->lu_list); INIT_LIST_HEAD(&tgt->lu_list);
tgt->bus_id = unit->device.bus_id; tgt->bus_id = unit->device.bus_id;
tgt->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4];
if (fw_device_enable_phys_dma(device) < 0) if (fw_device_enable_phys_dma(device) < 0)
goto fail_shost_put; goto fail_shost_put;
...@@ -1571,16 +1573,14 @@ sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr, ...@@ -1571,16 +1573,14 @@ sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr,
{ {
struct scsi_device *sdev = to_scsi_device(dev); struct scsi_device *sdev = to_scsi_device(dev);
struct sbp2_logical_unit *lu; struct sbp2_logical_unit *lu;
struct fw_device *device;
if (!sdev) if (!sdev)
return 0; return 0;
lu = sdev->hostdata; lu = sdev->hostdata;
device = fw_device(lu->tgt->unit->device.parent);
return sprintf(buf, "%08x%08x:%06x:%04x\n", return sprintf(buf, "%016llx:%06x:%04x\n",
device->config_rom[3], device->config_rom[4], (unsigned long long)lu->tgt->guid,
lu->tgt->directory_id, lu->lun); lu->tgt->directory_id, lu->lun);
} }
......
...@@ -108,6 +108,7 @@ static struct fw_node *fw_node_create(u32 sid, int port_count, int color) ...@@ -108,6 +108,7 @@ static struct fw_node *fw_node_create(u32 sid, int port_count, int color)
node->node_id = LOCAL_BUS | SELF_ID_PHY_ID(sid); node->node_id = LOCAL_BUS | SELF_ID_PHY_ID(sid);
node->link_on = SELF_ID_LINK_ON(sid); node->link_on = SELF_ID_LINK_ON(sid);
node->phy_speed = SELF_ID_PHY_SPEED(sid); node->phy_speed = SELF_ID_PHY_SPEED(sid);
node->initiated_reset = SELF_ID_PHY_INITIATOR(sid);
node->port_count = port_count; node->port_count = port_count;
atomic_set(&node->ref_count, 1); atomic_set(&node->ref_count, 1);
...@@ -431,6 +432,8 @@ update_tree(struct fw_card *card, struct fw_node *root) ...@@ -431,6 +432,8 @@ update_tree(struct fw_card *card, struct fw_node *root)
event = FW_NODE_LINK_OFF; event = FW_NODE_LINK_OFF;
else if (!node0->link_on && node1->link_on) else if (!node0->link_on && node1->link_on)
event = FW_NODE_LINK_ON; event = FW_NODE_LINK_ON;
else if (node1->initiated_reset && node1->link_on)
event = FW_NODE_INITIATED_RESET;
else else
event = FW_NODE_UPDATED; event = FW_NODE_UPDATED;
......
...@@ -20,11 +20,12 @@ ...@@ -20,11 +20,12 @@
#define __fw_topology_h #define __fw_topology_h
enum { enum {
FW_NODE_CREATED = 0x00, FW_NODE_CREATED,
FW_NODE_UPDATED = 0x01, FW_NODE_UPDATED,
FW_NODE_DESTROYED = 0x02, FW_NODE_DESTROYED,
FW_NODE_LINK_ON = 0x03, FW_NODE_LINK_ON,
FW_NODE_LINK_OFF = 0x04, FW_NODE_LINK_OFF,
FW_NODE_INITIATED_RESET,
}; };
struct fw_node { struct fw_node {
......
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