From 92368890d551794ee8d7e90477d8498bb7f82a9b Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Wed, 13 May 2009 21:42:14 +0200 Subject: [PATCH 01/14] firewire: core: improve check for local node My recently added test for a device being local in fw-cdev.c got it slightly wrong: Comparisons of node IDs are only valid if the generation is current, which I forgot to check. Normally, serialization by card->lock takes care of this, but a device in FW_DEVICE_GONE state will necessarily have a wrong generation and invalid node_id. The "is it local?" check is made 100% correct and simpler now by means of a struct fw_device flag which is set at fw_device creation. Besides the fw-cdev site which was to be fixed, there is another site which can make use of the new flag, and an RFC-2734 driver will benefit from it too. Signed-off-by: Stefan Richter --- drivers/firewire/fw-cdev.c | 6 +----- drivers/firewire/fw-device.c | 3 ++- drivers/firewire/fw-device.h | 1 + 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/firewire/fw-cdev.c b/drivers/firewire/fw-cdev.c index 7eb6594cc3e5..8a5e6ae2552c 100644 --- a/drivers/firewire/fw-cdev.c +++ b/drivers/firewire/fw-cdev.c @@ -739,15 +739,11 @@ static void release_descriptor(struct client *client, static int ioctl_add_descriptor(struct client *client, void *buffer) { struct fw_cdev_add_descriptor *request = buffer; - struct fw_card *card = client->device->card; struct descriptor_resource *r; int ret; /* Access policy: Allow this ioctl only on local nodes' device files. */ - spin_lock_irq(&card->lock); - ret = client->device->node_id != card->local_node->node_id; - spin_unlock_irq(&card->lock); - if (ret) + if (!client->device->is_local) return -ENOSYS; if (request->length > 256) diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c index a47e2129d83d..a38a68b97b58 100644 --- a/drivers/firewire/fw-device.c +++ b/drivers/firewire/fw-device.c @@ -1042,6 +1042,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event) device->node = fw_node_get(node); device->node_id = node->node_id; device->generation = card->generation; + device->is_local = node == card->local_node; mutex_init(&device->client_list_mutex); INIT_LIST_HEAD(&device->client_list); @@ -1075,7 +1076,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event) FW_DEVICE_INITIALIZING) == FW_DEVICE_RUNNING) { PREPARE_DELAYED_WORK(&device->work, fw_device_refresh); schedule_delayed_work(&device->work, - node == card->local_node ? 0 : INITIAL_DELAY); + device->is_local ? 0 : INITIAL_DELAY); } break; diff --git a/drivers/firewire/fw-device.h b/drivers/firewire/fw-device.h index 97588937c018..623cfee289bd 100644 --- a/drivers/firewire/fw-device.h +++ b/drivers/firewire/fw-device.h @@ -80,6 +80,7 @@ struct fw_device { u32 *config_rom; size_t config_rom_length; int config_rom_retries; + unsigned is_local:1; unsigned cmc:1; unsigned bc_implemented:2; From e5333db9285e088a98f4bad5147bfb0b4665fafb Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Fri, 22 May 2009 23:16:27 +0200 Subject: [PATCH 02/14] firewire: core: check for missing struct update at build time, not run time struct fw_attribute_group.attrs.[] must have enough room for all attributes. This can and should be checked at build time. Our previous check at run time was a little late and not reliable since most of the time less than the available attributes are populated. Furthermore, omit an increment of an index at its last usage. Signed-off-by: Stefan Richter --- drivers/firewire/fw-device.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c index a38a68b97b58..98ce0841f4c9 100644 --- a/drivers/firewire/fw-device.c +++ b/drivers/firewire/fw-device.c @@ -292,8 +292,7 @@ static void init_fw_attribute_group(struct device *dev, group->attrs[j++] = &attr->attr; } - BUG_ON(j >= ARRAY_SIZE(group->attrs)); - group->attrs[j++] = NULL; + group->attrs[j] = NULL; group->groups[0] = &group->group; group->groups[1] = NULL; group->group.attrs = group->attrs; @@ -570,9 +569,13 @@ static void create_units(struct fw_device *device) unit->device.parent = &device->device; dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++); + BUILD_BUG_ON(ARRAY_SIZE(unit->attribute_group.attrs) < + ARRAY_SIZE(fw_unit_attributes) + + ARRAY_SIZE(config_rom_attributes)); init_fw_attribute_group(&unit->device, fw_unit_attributes, &unit->attribute_group); + if (device_register(&unit->device) < 0) goto skip_unit; @@ -849,9 +852,13 @@ static void fw_device_init(struct work_struct *work) device->device.devt = MKDEV(fw_cdev_major, minor); dev_set_name(&device->device, "fw%d", minor); + BUILD_BUG_ON(ARRAY_SIZE(device->attribute_group.attrs) < + ARRAY_SIZE(fw_device_attributes) + + ARRAY_SIZE(config_rom_attributes)); init_fw_attribute_group(&device->device, fw_device_attributes, &device->attribute_group); + if (device_add(&device->device)) { fw_error("Failed to add device.\n"); goto error_with_cdev; From 0210b66dd88a2a1e451901b00378a2068b6ccb35 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sat, 23 May 2009 00:03:29 +0200 Subject: [PATCH 03/14] firewire: core: add sysfs attribute for easier udev rules This adds the attribute /sys/bus/firewire/devices/fw[0-9]+/units. It can be used in udev rules like the following ones: # IIDC devices: industrial cameras and some webcams SUBSYSTEM=="firewire", ATTR{units}=="*0x00a02d:0x00010?*", GROUP="video" # AV/C devices: camcorders, set-top boxes, TV sets, audio devices, ... SUBSYSTEM=="firewire", ATTR{units}=="*0x00a02d:0x010001*", GROUP="video" Background: firewire-core manages two device types: - fw_device is a FireWire node. A character device file is associated with it. - fw_unit is a unit directory on a node. Each fw_device may have 0..n children of type fw_unit. The units tell us what kinds of protocols a node implements. We want to set ownership or ACLs or permissions of the character device file of an fw_device, or/and create symlinks to it, based on available protocols. Until now udev rules had to look at the fw_unit devices and then modify their parent's character device file accordingly. This is problematic for two reasons: 1) It happens sometime after the creation of the fw_device, 2) an access policy may require that information from all children is evaluated before a decision about the parent is made. Problem 1) can ultimately not be avoided since this is the nature of FireWire nodes: They may add or remove unit directories at any point in time. However, we can still help userland a lot by providing the protocol type information of all units in a summary sysfs attribute directly at the fw_device. This way, - the information is immediately available at the affected device when userspace goes about to handle an ADD or CHANGE event of the fw_device, - with most policies, it won't be necessary anymore to dig through child attributes. The new attribute is called "units". It contains space-separated tuples of specifier_id and version of each present unit. The delimiter within tuples is a colon. Specifier_id and version are printed as 0x%06x. Here is an example of a node which implements an IPv4 unit and an IPv6 unit: $ cat /sys/bus/firewire/devices/fw2/units 0x00005e:0x000001 0x00005e:0x000002 Signed-off-by: Stefan Richter --- drivers/firewire/fw-device.c | 50 ++++++++++++++++++++++++++++++++++++ drivers/firewire/fw-device.h | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c index 98ce0841f4c9..551588342898 100644 --- a/drivers/firewire/fw-device.c +++ b/drivers/firewire/fw-device.c @@ -355,9 +355,56 @@ static ssize_t guid_show(struct device *dev, return ret; } +static int units_sprintf(char *buf, u32 *directory) +{ + struct fw_csr_iterator ci; + int key, value; + int specifier_id = 0; + int version = 0; + + fw_csr_iterator_init(&ci, directory); + while (fw_csr_iterator_next(&ci, &key, &value)) { + switch (key) { + case CSR_SPECIFIER_ID: + specifier_id = value; + break; + case CSR_VERSION: + version = value; + break; + } + } + + return sprintf(buf, "0x%06x:0x%06x ", specifier_id, version); +} + +static ssize_t units_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct fw_device *device = fw_device(dev); + struct fw_csr_iterator ci; + int key, value, i = 0; + + down_read(&fw_device_rwsem); + fw_csr_iterator_init(&ci, &device->config_rom[5]); + while (fw_csr_iterator_next(&ci, &key, &value)) { + if (key != (CSR_UNIT | CSR_DIRECTORY)) + continue; + i += units_sprintf(&buf[i], ci.p + value - 1); + if (i >= PAGE_SIZE - (8 + 1 + 8 + 1)) + break; + } + up_read(&fw_device_rwsem); + + if (i) + buf[i - 1] = '\n'; + + return i; +} + static struct device_attribute fw_device_attributes[] = { __ATTR_RO(config_rom), __ATTR_RO(guid), + __ATTR_RO(units), __ATTR_NULL, }; @@ -1000,6 +1047,9 @@ static void fw_device_refresh(struct work_struct *work) create_units(device); + /* Userspace may want to re-read attributes. */ + kobject_uevent(&device->device.kobj, KOBJ_CHANGE); + if (atomic_cmpxchg(&device->state, FW_DEVICE_INITIALIZING, FW_DEVICE_RUNNING) == FW_DEVICE_GONE) diff --git a/drivers/firewire/fw-device.h b/drivers/firewire/fw-device.h index 623cfee289bd..892dd5916276 100644 --- a/drivers/firewire/fw-device.h +++ b/drivers/firewire/fw-device.h @@ -42,7 +42,7 @@ enum fw_device_state { struct fw_attribute_group { struct attribute_group *groups[2]; struct attribute_group group; - struct attribute *attrs[11]; + struct attribute *attrs[12]; }; struct fw_node; From b3b2988841ac6215e137e34e38b71acc915d1f00 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 15 Feb 2009 23:12:34 +0100 Subject: [PATCH 04/14] firewire: share device ID table type with ieee1394 That way, the new firedtv driver will be able to use a single ID table in builds against ieee1394 core and/or against firewire core. Signed-off-by: Stefan Richter --- drivers/firewire/fw-device.c | 16 +++++++++------- drivers/firewire/fw-device.h | 19 +++---------------- drivers/firewire/fw-sbp2.c | 5 +++-- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c index 551588342898..47b5b422616b 100644 --- a/drivers/firewire/fw-device.c +++ b/drivers/firewire/fw-device.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -57,7 +58,8 @@ EXPORT_SYMBOL(fw_csr_iterator_next); static int is_fw_unit(struct device *dev); -static int match_unit_directory(u32 * directory, const struct fw_device_id *id) +static int match_unit_directory(u32 *directory, + const struct ieee1394_device_id *id) { struct fw_csr_iterator ci; int key, value, match; @@ -65,14 +67,14 @@ static int match_unit_directory(u32 * directory, const struct fw_device_id *id) match = 0; fw_csr_iterator_init(&ci, directory); while (fw_csr_iterator_next(&ci, &key, &value)) { - if (key == CSR_VENDOR && value == id->vendor) - match |= FW_MATCH_VENDOR; - if (key == CSR_MODEL && value == id->model) - match |= FW_MATCH_MODEL; + if (key == CSR_VENDOR && value == id->vendor_id) + match |= IEEE1394_MATCH_VENDOR_ID; + if (key == CSR_MODEL && value == id->model_id) + match |= IEEE1394_MATCH_MODEL_ID; if (key == CSR_SPECIFIER_ID && value == id->specifier_id) - match |= FW_MATCH_SPECIFIER_ID; + match |= IEEE1394_MATCH_SPECIFIER_ID; if (key == CSR_VERSION && value == id->version) - match |= FW_MATCH_VERSION; + match |= IEEE1394_MATCH_VERSION; } return (match & id->match_flags) == id->match_flags; diff --git a/drivers/firewire/fw-device.h b/drivers/firewire/fw-device.h index 892dd5916276..e973c4361f48 100644 --- a/drivers/firewire/fw-device.h +++ b/drivers/firewire/fw-device.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -172,25 +173,11 @@ 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); - const struct fw_device_id *id_table; + void (*update)(struct fw_unit *unit); + const struct ieee1394_device_id *id_table; }; static inline struct fw_driver *fw_driver(struct device_driver *drv) diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c index 2bcf51557c72..2a707754532b 100644 --- a/drivers/firewire/fw-sbp2.c +++ b/drivers/firewire/fw-sbp2.c @@ -1259,9 +1259,10 @@ static void sbp2_update(struct fw_unit *unit) #define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e #define SBP2_SW_VERSION_ENTRY 0x00010483 -static const struct fw_device_id sbp2_id_table[] = { +static const struct ieee1394_device_id sbp2_id_table[] = { { - .match_flags = FW_MATCH_SPECIFIER_ID | FW_MATCH_VERSION, + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | + IEEE1394_MATCH_VERSION, .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY, .version = SBP2_SW_VERSION_ENTRY, }, From e41f8d709c31b42129a34305a99d29c38aff75c4 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 16 Feb 2009 00:22:05 +0100 Subject: [PATCH 05/14] firewire: also use vendor ID in root directory for driver matches Due to AV/C protocol extensions, FireDTV devices need a vendor-specific driver. But their configuration ROM features a vendor ID only in the root directory, not in the unit directory. Signed-off-by: Stefan Richter --- drivers/firewire/fw-device.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c index 47b5b422616b..7d2f6135e009 100644 --- a/drivers/firewire/fw-device.c +++ b/drivers/firewire/fw-device.c @@ -58,7 +58,7 @@ EXPORT_SYMBOL(fw_csr_iterator_next); static int is_fw_unit(struct device *dev); -static int match_unit_directory(u32 *directory, +static int match_unit_directory(u32 *directory, u32 match_flags, const struct ieee1394_device_id *id) { struct fw_csr_iterator ci; @@ -77,21 +77,31 @@ static int match_unit_directory(u32 *directory, match |= IEEE1394_MATCH_VERSION; } - return (match & id->match_flags) == id->match_flags; + return (match & match_flags) == match_flags; } static int fw_unit_match(struct device *dev, struct device_driver *drv) { struct fw_unit *unit = fw_unit(dev); - struct fw_driver *driver = fw_driver(drv); - int i; + struct fw_device *device; + const struct ieee1394_device_id *id; /* We only allow binding to fw_units. */ if (!is_fw_unit(dev)) return 0; - for (i = 0; driver->id_table[i].match_flags != 0; i++) { - if (match_unit_directory(unit->directory, &driver->id_table[i])) + device = fw_device(unit->device.parent); + + for (id = fw_driver(drv)->id_table; id->match_flags != 0; id++) { + if (match_unit_directory(unit->directory, id->match_flags, id)) + return 1; + + /* Also check vendor ID in the root directory. */ + if ((id->match_flags & IEEE1394_MATCH_VENDOR_ID) && + match_unit_directory(&device->config_rom[5], + IEEE1394_MATCH_VENDOR_ID, id) && + match_unit_directory(unit->directory, id->match_flags + & ~IEEE1394_MATCH_VENDOR_ID, id)) return 1; } From 3dcdc50079bc2c9dbc6524518976353f743f7ec8 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Thu, 4 Jun 2009 21:08:43 +0200 Subject: [PATCH 06/14] firewire: ohci: access bus_seconds atomically In the unlikely event that card->driver->get_bus_time() is called during a cycle64Seconds interrupt, we could read garbage unless atomic accesses are used. The switch to atomic ops requires to change the 64 seconds counter from unsigned to signed, but this shouldn't matter to the end result. Signed-off-by: Stefan Richter --- drivers/firewire/fw-ohci.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c index 1180d0be0bb4..1b6590f92543 100644 --- a/drivers/firewire/fw-ohci.c +++ b/drivers/firewire/fw-ohci.c @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -178,7 +179,7 @@ struct fw_ohci { int node_id; int generation; int request_generation; /* for timestamping incoming requests */ - u32 bus_seconds; + atomic_t bus_seconds; bool use_dualbuffer; bool old_uninorth; @@ -1434,7 +1435,7 @@ static irqreturn_t irq_handler(int irq, void *data) if (event & OHCI1394_cycle64Seconds) { cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer); if ((cycle_time & 0x80000000) == 0) - ohci->bus_seconds++; + atomic_inc(&ohci->bus_seconds); } return IRQ_HANDLED; @@ -1770,7 +1771,7 @@ static u64 ohci_get_bus_time(struct fw_card *card) u64 bus_time; cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer); - bus_time = ((u64) ohci->bus_seconds << 32) | cycle_time; + bus_time = ((u64)atomic_read(&ohci->bus_seconds) << 32) | cycle_time; return bus_time; } From e8ca97021c8eb127bb04aec4e2420e1d66be371d Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Thu, 4 Jun 2009 21:09:38 +0200 Subject: [PATCH 07/14] firewire: clean up includes Include required headers which were only indirectly included. Remove unused includes and an unused constant. Signed-off-by: Stefan Richter --- drivers/firewire/fw-card.c | 15 ++++++++++++--- drivers/firewire/fw-device.c | 3 +++ drivers/firewire/fw-iso.c | 2 ++ drivers/firewire/fw-ohci.c | 7 ++++++- drivers/firewire/fw-sbp2.c | 12 ++++++++++-- drivers/firewire/fw-topology.c | 16 ++++++++++++---- drivers/firewire/fw-transaction.c | 30 +++++++++++++++++------------- 7 files changed, 62 insertions(+), 23 deletions(-) diff --git a/drivers/firewire/fw-card.c b/drivers/firewire/fw-card.c index 8b8c8c22f0fc..b6f55e262e7f 100644 --- a/drivers/firewire/fw-card.c +++ b/drivers/firewire/fw-card.c @@ -16,18 +16,27 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include #include #include -#include #include #include +#include +#include #include +#include #include #include +#include +#include +#include + +#include +#include -#include "fw-transaction.h" -#include "fw-topology.h" #include "fw-device.h" +#include "fw-topology.h" +#include "fw-transaction.h" int fw_compute_block_crc(u32 *block) { diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c index 7d2f6135e009..238acac5badb 100644 --- a/drivers/firewire/fw-device.c +++ b/drivers/firewire/fw-device.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,8 @@ #include #include +#include +#include #include #include "fw-device.h" diff --git a/drivers/firewire/fw-iso.c b/drivers/firewire/fw-iso.c index 2baf1007253e..0ff3e9c42eb1 100644 --- a/drivers/firewire/fw-iso.c +++ b/drivers/firewire/fw-iso.c @@ -28,6 +28,8 @@ #include #include +#include + #include "fw-topology.h" #include "fw-transaction.h" diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c index 1b6590f92543..d296d12909d6 100644 --- a/drivers/firewire/fw-ohci.c +++ b/drivers/firewire/fw-ohci.c @@ -20,18 +20,24 @@ #include #include +#include #include +#include #include #include #include +#include #include +#include #include #include #include #include #include +#include #include +#include #include #include @@ -232,7 +238,6 @@ static inline struct fw_ohci *fw_ohci(struct fw_card *card) #define OHCI1394_MAX_AT_RESP_RETRIES 0x2 #define OHCI1394_MAX_PHYS_RESP_RETRIES 0x8 -#define FW_OHCI_MAJOR 240 #define OHCI1394_REGISTER_SIZE 0x800 #define OHCI_LOOP_COUNT 500 #define OHCI1394_PCI_HCI_Control 0x40 diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c index 2a707754532b..027b91f4a6e7 100644 --- a/drivers/firewire/fw-sbp2.c +++ b/drivers/firewire/fw-sbp2.c @@ -30,18 +30,27 @@ #include #include +#include #include #include #include +#include +#include +#include #include +#include +#include #include #include #include #include +#include +#include #include #include -#include #include + +#include #include #include @@ -50,7 +59,6 @@ #include #include "fw-device.h" -#include "fw-topology.h" #include "fw-transaction.h" /* diff --git a/drivers/firewire/fw-topology.c b/drivers/firewire/fw-topology.c index d0deecc4de93..6d0ea1bb7e23 100644 --- a/drivers/firewire/fw-topology.c +++ b/drivers/firewire/fw-topology.c @@ -18,13 +18,21 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include -#include +#include #include -#include +#include +#include +#include +#include +#include +#include +#include + +#include #include -#include "fw-transaction.h" + #include "fw-topology.h" +#include "fw-transaction.h" #define SELF_ID_PHY_ID(q) (((q) >> 24) & 0x3f) #define SELF_ID_EXTENDED(q) (((q) >> 23) & 0x01) diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/fw-transaction.c index 283dac6d327d..7008214e3336 100644 --- a/drivers/firewire/fw-transaction.c +++ b/drivers/firewire/fw-transaction.c @@ -18,24 +18,28 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include +#include +#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include + +#include "fw-device.h" /* for fw_device_ops */ #include "fw-transaction.h" -#include "fw-topology.h" -#include "fw-device.h" #define HEADER_PRI(pri) ((pri) << 0) #define HEADER_TCODE(tcode) ((tcode) << 4) From 77c9a5daa9c4d9b37812c9c69c7bcbb3f9399c3c Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Fri, 5 Jun 2009 16:26:18 +0200 Subject: [PATCH 08/14] firewire: reorganize header files The three header files of firewire-core, i.e. "drivers/firewire/fw-device.h", "drivers/firewire/fw-topology.h", "drivers/firewire/fw-transaction.h", are replaced by "drivers/firewire/core.h", "include/linux/firewire.h". The latter includes everything which a firewire high-level driver (like firewire-sbp2) needs besides linux/firewire-constants.h, while core.h contains the rest which is needed by firewire-core itself and by low- level drivers (card drivers) like firewire-ohci. High-level drivers can now also reside outside of drivers/firewire without having to add drivers/firewire to the header file search path in makefiles. At least the firedtv driver will be such a driver. I also considered to spread the contents of core.h over several files, one for each .c file where the respective implementation resides. But it turned out that most core .c files will end up including most of the core .h files. Also, the combined core.h isn't unreasonably big, and it will lose more of its contents to linux/firewire.h anyway soon when more firewire drivers are added. (IP-over-1394, firedtv, and there are plans for one or two more.) Furthermore, fw-ohci.h is renamed to ohci.h. The name of core.h and ohci.h is chosen with regard to name changes of the .c files in a follow-up change. Signed-off-by: Stefan Richter --- drivers/firewire/core.h | 293 ++++++++++++++++ drivers/firewire/fw-card.c | 6 +- drivers/firewire/fw-cdev.c | 5 +- drivers/firewire/fw-device.c | 9 +- drivers/firewire/fw-device.h | 190 ----------- drivers/firewire/fw-iso.c | 4 +- drivers/firewire/fw-ohci.c | 5 +- drivers/firewire/fw-sbp2.c | 4 +- drivers/firewire/fw-topology.c | 10 +- drivers/firewire/fw-topology.h | 77 ----- drivers/firewire/fw-transaction.c | 8 +- drivers/firewire/fw-transaction.h | 446 ------------------------- drivers/firewire/{fw-ohci.h => ohci.h} | 6 +- include/linux/firewire.h | 350 +++++++++++++++++++ 14 files changed, 676 insertions(+), 737 deletions(-) create mode 100644 drivers/firewire/core.h delete mode 100644 drivers/firewire/fw-device.h delete mode 100644 drivers/firewire/fw-topology.h delete mode 100644 drivers/firewire/fw-transaction.h rename drivers/firewire/{fw-ohci.h => ohci.h} (98%) create mode 100644 include/linux/firewire.h diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h new file mode 100644 index 000000000000..273f0ab82928 --- /dev/null +++ b/drivers/firewire/core.h @@ -0,0 +1,293 @@ +#ifndef _FIREWIRE_CORE_H +#define _FIREWIRE_CORE_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct device; +struct fw_card; +struct fw_device; +struct fw_iso_buffer; +struct fw_iso_context; +struct fw_iso_packet; +struct fw_node; +struct fw_packet; + + +/* -card */ + +/* bitfields within the PHY registers */ +#define PHY_LINK_ACTIVE 0x80 +#define PHY_CONTENDER 0x40 +#define PHY_BUS_RESET 0x40 +#define PHY_BUS_SHORT_RESET 0x40 + +#define BANDWIDTH_AVAILABLE_INITIAL 4915 +#define BROADCAST_CHANNEL_INITIAL (1 << 31 | 31) +#define BROADCAST_CHANNEL_VALID (1 << 30) + +struct fw_card_driver { + /* + * Enable the given card with the given initial config rom. + * This function is expected to activate the card, and either + * enable the PHY or set the link_on bit and initiate a bus + * reset. + */ + int (*enable)(struct fw_card *card, u32 *config_rom, size_t length); + + int (*update_phy_reg)(struct fw_card *card, int address, + int clear_bits, int set_bits); + + /* + * Update the config rom for an enabled card. This function + * should change the config rom that is presented on the bus + * an initiate a bus reset. + */ + int (*set_config_rom)(struct fw_card *card, + u32 *config_rom, size_t length); + + void (*send_request)(struct fw_card *card, struct fw_packet *packet); + void (*send_response)(struct fw_card *card, struct fw_packet *packet); + /* Calling cancel is valid once a packet has been submitted. */ + int (*cancel_packet)(struct fw_card *card, struct fw_packet *packet); + + /* + * Allow the specified node ID to do direct DMA out and in of + * host memory. The card will disable this for all node when + * a bus reset happens, so driver need to reenable this after + * bus reset. Returns 0 on success, -ENODEV if the card + * doesn't support this, -ESTALE if the generation doesn't + * match. + */ + int (*enable_phys_dma)(struct fw_card *card, + int node_id, int generation); + + u64 (*get_bus_time)(struct fw_card *card); + + struct fw_iso_context * + (*allocate_iso_context)(struct fw_card *card, + int type, int channel, size_t header_size); + void (*free_iso_context)(struct fw_iso_context *ctx); + + int (*start_iso)(struct fw_iso_context *ctx, + s32 cycle, u32 sync, u32 tags); + + int (*queue_iso)(struct fw_iso_context *ctx, + struct fw_iso_packet *packet, + struct fw_iso_buffer *buffer, + unsigned long payload); + + int (*stop_iso)(struct fw_iso_context *ctx); +}; + +void fw_card_initialize(struct fw_card *card, + const struct fw_card_driver *driver, struct device *device); +int fw_card_add(struct fw_card *card, + u32 max_receive, u32 link_speed, u64 guid); +void fw_core_remove_card(struct fw_card *card); +int fw_core_initiate_bus_reset(struct fw_card *card, int short_reset); +int fw_compute_block_crc(u32 *block); +void fw_schedule_bm_work(struct fw_card *card, unsigned long delay); + +struct fw_descriptor { + struct list_head link; + size_t length; + u32 immediate; + u32 key; + const u32 *data; +}; + +int fw_core_add_descriptor(struct fw_descriptor *desc); +void fw_core_remove_descriptor(struct fw_descriptor *desc); + + +/* -cdev */ + +extern const struct file_operations fw_device_ops; + +void fw_device_cdev_update(struct fw_device *device); +void fw_device_cdev_remove(struct fw_device *device); + + +/* -device */ + +extern struct rw_semaphore fw_device_rwsem; +extern struct idr fw_device_idr; +extern int fw_cdev_major; + +struct fw_device *fw_device_get_by_devt(dev_t devt); +void fw_device_set_broadcast_channel(struct fw_device *device, int generation); +void fw_node_event(struct fw_card *card, struct fw_node *node, int event); + + +/* -iso */ + +/* + * The iso packet format allows for an immediate header/payload part + * stored in 'header' immediately after the packet info plus an + * indirect payload part that is pointer to by the 'payload' field. + * Applications can use one or the other or both to implement simple + * low-bandwidth streaming (e.g. audio) or more advanced + * scatter-gather streaming (e.g. assembling video frame automatically). + */ +struct fw_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]; +}; + +#define FW_ISO_CONTEXT_TRANSMIT 0 +#define FW_ISO_CONTEXT_RECEIVE 1 + +#define FW_ISO_CONTEXT_MATCH_TAG0 1 +#define FW_ISO_CONTEXT_MATCH_TAG1 2 +#define FW_ISO_CONTEXT_MATCH_TAG2 4 +#define FW_ISO_CONTEXT_MATCH_TAG3 8 +#define FW_ISO_CONTEXT_MATCH_ALL_TAGS 15 + +/* + * An iso buffer is just a set of pages mapped for DMA in the + * specified direction. Since the pages are to be used for DMA, they + * are not mapped into the kernel virtual address space. We store the + * DMA address in the page private. The helper function + * fw_iso_buffer_map() will map the pages into a given vma. + */ +struct fw_iso_buffer { + enum dma_data_direction direction; + struct page **pages; + int page_count; +}; + +typedef void (*fw_iso_callback_t)(struct fw_iso_context *context, + u32 cycle, size_t header_length, + void *header, void *data); + +struct fw_iso_context { + struct fw_card *card; + int type; + int channel; + int speed; + size_t header_size; + fw_iso_callback_t callback; + void *callback_data; +}; + +int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card, + int page_count, enum dma_data_direction direction); +int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma); +void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card); + +struct fw_iso_context *fw_iso_context_create(struct fw_card *card, + int type, int channel, int speed, size_t header_size, + fw_iso_callback_t callback, void *callback_data); +int fw_iso_context_queue(struct fw_iso_context *ctx, + struct fw_iso_packet *packet, + struct fw_iso_buffer *buffer, + unsigned long payload); +int fw_iso_context_start(struct fw_iso_context *ctx, + int cycle, int sync, int tags); +int fw_iso_context_stop(struct fw_iso_context *ctx); +void fw_iso_context_destroy(struct fw_iso_context *ctx); + +void fw_iso_resource_manage(struct fw_card *card, int generation, + u64 channels_mask, int *channel, int *bandwidth, bool allocate); + + +/* -topology */ + +enum { + FW_NODE_CREATED, + FW_NODE_UPDATED, + FW_NODE_DESTROYED, + FW_NODE_LINK_ON, + FW_NODE_LINK_OFF, + FW_NODE_INITIATED_RESET, +}; + +struct fw_node { + u16 node_id; + u8 color; + u8 port_count; + u8 link_on:1; + u8 initiated_reset:1; + u8 b_path:1; + u8 phy_speed:2; /* As in the self ID packet. */ + u8 max_speed:2; /* Minimum of all phy-speeds on the path from the + * local node to this node. */ + u8 max_depth:4; /* Maximum depth to any leaf node */ + u8 max_hops:4; /* Max hops in this sub tree */ + atomic_t ref_count; + + /* For serializing node topology into a list. */ + struct list_head link; + + /* Upper layer specific data. */ + void *data; + + struct fw_node *ports[0]; +}; + +static inline struct fw_node *fw_node_get(struct fw_node *node) +{ + atomic_inc(&node->ref_count); + + return node; +} + +static inline void fw_node_put(struct fw_node *node) +{ + if (atomic_dec_and_test(&node->ref_count)) + kfree(node); +} + +void fw_core_handle_bus_reset(struct fw_card *card, int node_id, + int generation, int self_id_count, u32 *self_ids); +void fw_destroy_nodes(struct fw_card *card); + +/* + * Check whether new_generation is the immediate successor of old_generation. + * Take counter roll-over at 255 (as per OHCI) into account. + */ +static inline bool is_next_generation(int new_generation, int old_generation) +{ + return (new_generation & 0xff) == ((old_generation + 1) & 0xff); +} + + +/* -transaction */ + +#define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4) +#define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0) +#define TCODE_IS_REQUEST(tcode) (((tcode) & 2) == 0) +#define TCODE_IS_RESPONSE(tcode) (((tcode) & 2) != 0) +#define TCODE_HAS_REQUEST_DATA(tcode) (((tcode) & 12) != 4) +#define TCODE_HAS_RESPONSE_DATA(tcode) (((tcode) & 12) != 0) + +#define LOCAL_BUS 0xffc0 + +void fw_core_handle_request(struct fw_card *card, struct fw_packet *request); +void fw_core_handle_response(struct fw_card *card, struct fw_packet *packet); +void fw_fill_response(struct fw_packet *response, u32 *request_header, + int rcode, void *payload, size_t length); +void fw_flush_transactions(struct fw_card *card); +void fw_send_phy_config(struct fw_card *card, + int node_id, int generation, int gap_count); + +static inline int fw_stream_packet_destination_id(int tag, int channel, int sy) +{ + return tag << 14 | channel << 8 | sy; +} + +#endif /* _FIREWIRE_CORE_H */ diff --git a/drivers/firewire/fw-card.c b/drivers/firewire/fw-card.c index b6f55e262e7f..ba6cd70b8518 100644 --- a/drivers/firewire/fw-card.c +++ b/drivers/firewire/fw-card.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include #include @@ -34,9 +36,7 @@ #include #include -#include "fw-device.h" -#include "fw-topology.h" -#include "fw-transaction.h" +#include "core.h" int fw_compute_block_crc(u32 *block) { diff --git a/drivers/firewire/fw-cdev.c b/drivers/firewire/fw-cdev.c index 8a5e6ae2552c..042c04540474 100644 --- a/drivers/firewire/fw-cdev.c +++ b/drivers/firewire/fw-cdev.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -41,9 +42,7 @@ #include #include -#include "fw-device.h" -#include "fw-topology.h" -#include "fw-transaction.h" +#include "core.h" struct client { u32 version; diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c index 238acac5badb..65d84dd6c1de 100644 --- a/drivers/firewire/fw-device.c +++ b/drivers/firewire/fw-device.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,9 +41,7 @@ #include #include -#include "fw-device.h" -#include "fw-topology.h" -#include "fw-transaction.h" +#include "core.h" void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 * p) { @@ -94,8 +94,9 @@ static int fw_unit_match(struct device *dev, struct device_driver *drv) return 0; device = fw_device(unit->device.parent); + id = container_of(drv, struct fw_driver, driver)->id_table; - for (id = fw_driver(drv)->id_table; id->match_flags != 0; id++) { + for (; id->match_flags != 0; id++) { if (match_unit_directory(unit->directory, id->match_flags, id)) return 1; diff --git a/drivers/firewire/fw-device.h b/drivers/firewire/fw-device.h deleted file mode 100644 index e973c4361f48..000000000000 --- a/drivers/firewire/fw-device.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (C) 2005-2006 Kristian Hoegsberg - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -enum fw_device_state { - FW_DEVICE_INITIALIZING, - FW_DEVICE_RUNNING, - FW_DEVICE_GONE, - FW_DEVICE_SHUTDOWN, -}; - -struct fw_attribute_group { - struct attribute_group *groups[2]; - struct attribute_group group; - struct attribute *attrs[12]; -}; - -struct fw_node; -struct fw_card; - -/* - * Note, fw_device.generation always has to be read before fw_device.node_id. - * Use SMP memory barriers to ensure this. Otherwise requests will be sent - * to an outdated node_id if the generation was updated in the meantime due - * to a bus reset. - * - * Likewise, fw-core will take care to update .node_id before .generation so - * that whenever fw_device.generation is current WRT the actual bus generation, - * fw_device.node_id is guaranteed to be current too. - * - * 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 { - atomic_t state; - struct fw_node *node; - int node_id; - int generation; - unsigned max_speed; - struct fw_card *card; - struct device device; - - struct mutex client_list_mutex; - struct list_head client_list; - - u32 *config_rom; - size_t config_rom_length; - int config_rom_retries; - unsigned is_local:1; - unsigned cmc:1; - unsigned bc_implemented:2; - - struct delayed_work work; - struct fw_attribute_group attribute_group; -}; - -static inline struct fw_device *fw_device(struct device *dev) -{ - return container_of(dev, struct fw_device, device); -} - -static inline int fw_device_is_shutdown(struct fw_device *device) -{ - return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN; -} - -static inline struct fw_device *fw_device_get(struct fw_device *device) -{ - get_device(&device->device); - - return device; -} - -static inline void fw_device_put(struct fw_device *device) -{ - put_device(&device->device); -} - -struct fw_device *fw_device_get_by_devt(dev_t devt); -int fw_device_enable_phys_dma(struct fw_device *device); -void fw_device_set_broadcast_channel(struct fw_device *device, int generation); - -void fw_device_cdev_update(struct fw_device *device); -void fw_device_cdev_remove(struct fw_device *device); - -extern struct rw_semaphore fw_device_rwsem; -extern struct idr fw_device_idr; -extern int fw_cdev_major; - -/* - * fw_unit.directory must not be accessed after device_del(&fw_unit.device). - */ -struct fw_unit { - struct device device; - u32 *directory; - struct fw_attribute_group attribute_group; -}; - -static inline struct fw_unit *fw_unit(struct device *dev) -{ - return container_of(dev, struct fw_unit, device); -} - -static inline struct fw_unit *fw_unit_get(struct fw_unit *unit) -{ - get_device(&unit->device); - - return unit; -} - -static inline void fw_unit_put(struct fw_unit *unit) -{ - put_device(&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 CSR_DIRECTORY_ID 0x20 - -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); - -struct fw_driver { - struct device_driver driver; - /* Called when the parent device sits through a bus reset. */ - void (*update)(struct fw_unit *unit); - const struct ieee1394_device_id *id_table; -}; - -static inline struct fw_driver *fw_driver(struct device_driver *drv) -{ - return container_of(drv, struct fw_driver, driver); -} - -extern const struct file_operations fw_device_ops; - -#endif /* __fw_device_h */ diff --git a/drivers/firewire/fw-iso.c b/drivers/firewire/fw-iso.c index 0ff3e9c42eb1..28076c892d7e 100644 --- a/drivers/firewire/fw-iso.c +++ b/drivers/firewire/fw-iso.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -30,8 +31,7 @@ #include -#include "fw-topology.h" -#include "fw-transaction.h" +#include "core.h" /* * Isochronous DMA context management diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c index d296d12909d6..ecddd11b797a 100644 --- a/drivers/firewire/fw-ohci.c +++ b/drivers/firewire/fw-ohci.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -45,8 +46,8 @@ #include #endif -#include "fw-ohci.h" -#include "fw-transaction.h" +#include "core.h" +#include "ohci.h" #define DESCRIPTOR_OUTPUT_MORE 0 #define DESCRIPTOR_OUTPUT_LAST (1 << 12) diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c index 027b91f4a6e7..d41cb6e455bc 100644 --- a/drivers/firewire/fw-sbp2.c +++ b/drivers/firewire/fw-sbp2.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -58,9 +59,6 @@ #include #include -#include "fw-device.h" -#include "fw-transaction.h" - /* * So far only bridges from Oxford Semiconductor are known to support * concurrent logins. Depending on firmware, four or two concurrent logins diff --git a/drivers/firewire/fw-topology.c b/drivers/firewire/fw-topology.c index 6d0ea1bb7e23..fddf2b358936 100644 --- a/drivers/firewire/fw-topology.c +++ b/drivers/firewire/fw-topology.c @@ -20,6 +20,8 @@ #include #include +#include +#include #include #include #include @@ -31,8 +33,7 @@ #include #include -#include "fw-topology.h" -#include "fw-transaction.h" +#include "core.h" #define SELF_ID_PHY_ID(q) (((q) >> 24) & 0x3f) #define SELF_ID_EXTENDED(q) (((q) >> 23) & 0x01) @@ -45,6 +46,11 @@ #define SELF_ID_EXT_SEQUENCE(q) (((q) >> 20) & 0x07) +#define SELFID_PORT_CHILD 0x3 +#define SELFID_PORT_PARENT 0x2 +#define SELFID_PORT_NCONN 0x1 +#define SELFID_PORT_NONE 0x0 + static u32 *count_ports(u32 *sid, int *total_port_count, int *child_port_count) { u32 q; diff --git a/drivers/firewire/fw-topology.h b/drivers/firewire/fw-topology.h deleted file mode 100644 index 3c497bb4fae4..000000000000 --- a/drivers/firewire/fw-topology.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2003-2006 Kristian Hoegsberg - * - * 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_topology_h -#define __fw_topology_h - -#include -#include - -#include - -enum { - FW_NODE_CREATED, - FW_NODE_UPDATED, - FW_NODE_DESTROYED, - FW_NODE_LINK_ON, - FW_NODE_LINK_OFF, - FW_NODE_INITIATED_RESET, -}; - -struct fw_node { - u16 node_id; - u8 color; - u8 port_count; - u8 link_on : 1; - u8 initiated_reset : 1; - u8 b_path : 1; - u8 phy_speed : 2; /* As in the self ID packet. */ - u8 max_speed : 2; /* Minimum of all phy-speeds on the path from the - * local node to this node. */ - u8 max_depth : 4; /* Maximum depth to any leaf node */ - u8 max_hops : 4; /* Max hops in this sub tree */ - atomic_t ref_count; - - /* For serializing node topology into a list. */ - struct list_head link; - - /* Upper layer specific data. */ - void *data; - - struct fw_node *ports[0]; -}; - -static inline struct fw_node *fw_node_get(struct fw_node *node) -{ - atomic_inc(&node->ref_count); - - return node; -} - -static inline void fw_node_put(struct fw_node *node) -{ - if (atomic_dec_and_test(&node->ref_count)) - kfree(node); -} - -struct fw_card; -void fw_destroy_nodes(struct fw_card *card); - -int fw_compute_block_crc(u32 *block); - -#endif /* __fw_topology_h */ diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/fw-transaction.c index 7008214e3336..9a6ce9ab2a67 100644 --- a/drivers/firewire/fw-transaction.c +++ b/drivers/firewire/fw-transaction.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -38,8 +39,7 @@ #include -#include "fw-device.h" /* for fw_device_ops */ -#include "fw-transaction.h" +#include "core.h" #define HEADER_PRI(pri) ((pri) << 0) #define HEADER_TCODE(tcode) ((tcode) << 4) @@ -64,6 +64,10 @@ #define HEADER_DESTINATION_IS_BROADCAST(q) \ (((q) & HEADER_DESTINATION(0x3f)) == HEADER_DESTINATION(0x3f)) +#define PHY_PACKET_CONFIG 0x0 +#define PHY_PACKET_LINK_ON 0x1 +#define PHY_PACKET_SELF_ID 0x2 + #define PHY_CONFIG_GAP_COUNT(gap_count) (((gap_count) << 16) | (1 << 22)) #define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23)) #define PHY_IDENTIFIER(id) ((id) << 30) diff --git a/drivers/firewire/fw-transaction.h b/drivers/firewire/fw-transaction.h deleted file mode 100644 index dfa799068f89..000000000000 --- a/drivers/firewire/fw-transaction.h +++ /dev/null @@ -1,446 +0,0 @@ -/* - * Copyright (C) 2003-2006 Kristian Hoegsberg - * - * 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_transaction_h -#define __fw_transaction_h - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4) -#define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0) -#define TCODE_IS_REQUEST(tcode) (((tcode) & 2) == 0) -#define TCODE_IS_RESPONSE(tcode) (((tcode) & 2) != 0) -#define TCODE_HAS_REQUEST_DATA(tcode) (((tcode) & 12) != 4) -#define TCODE_HAS_RESPONSE_DATA(tcode) (((tcode) & 12) != 0) - -#define LOCAL_BUS 0xffc0 - -#define SELFID_PORT_CHILD 0x3 -#define SELFID_PORT_PARENT 0x2 -#define SELFID_PORT_NCONN 0x1 -#define SELFID_PORT_NONE 0x0 - -#define PHY_PACKET_CONFIG 0x0 -#define PHY_PACKET_LINK_ON 0x1 -#define PHY_PACKET_SELF_ID 0x2 - -/* Bit fields _within_ the PHY registers. */ -#define PHY_LINK_ACTIVE 0x80 -#define PHY_CONTENDER 0x40 -#define PHY_BUS_RESET 0x40 -#define PHY_BUS_SHORT_RESET 0x40 - -#define CSR_REGISTER_BASE 0xfffff0000000ULL - -/* register offsets relative to CSR_REGISTER_BASE */ -#define CSR_STATE_CLEAR 0x0 -#define CSR_STATE_SET 0x4 -#define CSR_NODE_IDS 0x8 -#define CSR_RESET_START 0xc -#define CSR_SPLIT_TIMEOUT_HI 0x18 -#define CSR_SPLIT_TIMEOUT_LO 0x1c -#define CSR_CYCLE_TIME 0x200 -#define CSR_BUS_TIME 0x204 -#define CSR_BUSY_TIMEOUT 0x210 -#define CSR_BUS_MANAGER_ID 0x21c -#define CSR_BANDWIDTH_AVAILABLE 0x220 -#define CSR_CHANNELS_AVAILABLE 0x224 -#define CSR_CHANNELS_AVAILABLE_HI 0x224 -#define CSR_CHANNELS_AVAILABLE_LO 0x228 -#define CSR_BROADCAST_CHANNEL 0x234 -#define CSR_CONFIG_ROM 0x400 -#define CSR_CONFIG_ROM_END 0x800 -#define CSR_FCP_COMMAND 0xB00 -#define CSR_FCP_RESPONSE 0xD00 -#define CSR_FCP_END 0xF00 -#define CSR_TOPOLOGY_MAP 0x1000 -#define CSR_TOPOLOGY_MAP_END 0x1400 -#define CSR_SPEED_MAP 0x2000 -#define CSR_SPEED_MAP_END 0x3000 - -#define BANDWIDTH_AVAILABLE_INITIAL 4915 -#define BROADCAST_CHANNEL_INITIAL (1 << 31 | 31) -#define BROADCAST_CHANNEL_VALID (1 << 30) - -#define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args) -#define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args) - -static inline void fw_memcpy_from_be32(void *_dst, void *_src, size_t size) -{ - u32 *dst = _dst; - __be32 *src = _src; - int i; - - for (i = 0; i < size / 4; i++) - dst[i] = be32_to_cpu(src[i]); -} - -static inline void fw_memcpy_to_be32(void *_dst, void *_src, size_t size) -{ - fw_memcpy_from_be32(_dst, _src, size); -} - -struct fw_card; -struct fw_packet; -struct fw_node; -struct fw_request; - -struct fw_descriptor { - struct list_head link; - size_t length; - u32 immediate; - u32 key; - const u32 *data; -}; - -int fw_core_add_descriptor(struct fw_descriptor *desc); -void fw_core_remove_descriptor(struct fw_descriptor *desc); - -typedef void (*fw_packet_callback_t)(struct fw_packet *packet, - struct fw_card *card, int status); - -typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode, - void *data, size_t length, - void *callback_data); - -/* - * Important note: The callback must guarantee that either fw_send_response() - * or kfree() is called on the @request. - */ -typedef void (*fw_address_callback_t)(struct fw_card *card, - struct fw_request *request, - int tcode, int destination, int source, - int generation, int speed, - unsigned long long offset, - void *data, size_t length, - void *callback_data); - -struct fw_packet { - int speed; - int generation; - u32 header[4]; - size_t header_length; - void *payload; - size_t payload_length; - dma_addr_t payload_bus; - u32 timestamp; - - /* - * This callback is called when the packet transmission has - * completed; for successful transmission, the status code is - * the ack received from the destination, otherwise it's a - * negative errno: ENOMEM, ESTALE, ETIMEDOUT, ENODEV, EIO. - * The callback can be called from tasklet context and thus - * must never block. - */ - fw_packet_callback_t callback; - int ack; - struct list_head link; - void *driver_data; -}; - -struct fw_transaction { - int node_id; /* The generation is implied; it is always the current. */ - int tlabel; - int timestamp; - struct list_head link; - - struct fw_packet packet; - - /* - * The data passed to the callback is valid only during the - * callback. - */ - fw_transaction_callback_t callback; - void *callback_data; -}; - -struct fw_address_handler { - u64 offset; - size_t length; - fw_address_callback_t address_callback; - void *callback_data; - struct list_head link; -}; - -struct fw_address_region { - u64 start; - u64 end; -}; - -extern const struct fw_address_region fw_high_memory_region; - -int fw_core_add_address_handler(struct fw_address_handler *handler, - const struct fw_address_region *region); -void fw_core_remove_address_handler(struct fw_address_handler *handler); -void fw_fill_response(struct fw_packet *response, u32 *request_header, - int rcode, void *payload, size_t length); -void fw_send_response(struct fw_card *card, - struct fw_request *request, int rcode); - -extern struct bus_type fw_bus_type; - -struct fw_card { - const struct fw_card_driver *driver; - struct device *device; - struct kref kref; - struct completion done; - - int node_id; - int generation; - int current_tlabel, tlabel_mask; - struct list_head transaction_list; - struct timer_list flush_timer; - unsigned long reset_jiffies; - - unsigned long long guid; - unsigned max_receive; - int link_speed; - int config_rom_generation; - - spinlock_t lock; /* Take this lock when handling the lists in - * this struct. */ - struct fw_node *local_node; - struct fw_node *root_node; - struct fw_node *irm_node; - u8 color; /* must be u8 to match the definition in struct fw_node */ - int gap_count; - bool beta_repeaters_present; - - int index; - - struct list_head link; - - /* Work struct for BM duties. */ - struct delayed_work work; - int bm_retries; - int bm_generation; - - bool broadcast_channel_allocated; - u32 broadcast_channel; - u32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4]; -}; - -static inline struct fw_card *fw_card_get(struct fw_card *card) -{ - kref_get(&card->kref); - - return card; -} - -void fw_card_release(struct kref *kref); - -static inline void fw_card_put(struct fw_card *card) -{ - kref_put(&card->kref, fw_card_release); -} - -extern void fw_schedule_bm_work(struct fw_card *card, unsigned long delay); - -/* - * Check whether new_generation is the immediate successor of old_generation. - * Take counter roll-over at 255 (as per to OHCI) into account. - */ -static inline bool is_next_generation(int new_generation, int old_generation) -{ - return (new_generation & 0xff) == ((old_generation + 1) & 0xff); -} - -/* - * The iso packet format allows for an immediate header/payload part - * stored in 'header' immediately after the packet info plus an - * indirect payload part that is pointer to by the 'payload' field. - * Applications can use one or the other or both to implement simple - * low-bandwidth streaming (e.g. audio) or more advanced - * scatter-gather streaming (e.g. assembling video frame automatically). - */ - -struct fw_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]; -}; - -#define FW_ISO_CONTEXT_TRANSMIT 0 -#define FW_ISO_CONTEXT_RECEIVE 1 - -#define FW_ISO_CONTEXT_MATCH_TAG0 1 -#define FW_ISO_CONTEXT_MATCH_TAG1 2 -#define FW_ISO_CONTEXT_MATCH_TAG2 4 -#define FW_ISO_CONTEXT_MATCH_TAG3 8 -#define FW_ISO_CONTEXT_MATCH_ALL_TAGS 15 - -struct fw_iso_context; - -typedef void (*fw_iso_callback_t)(struct fw_iso_context *context, - u32 cycle, size_t header_length, - void *header, void *data); - -/* - * An iso buffer is just a set of pages mapped for DMA in the - * specified direction. Since the pages are to be used for DMA, they - * are not mapped into the kernel virtual address space. We store the - * DMA address in the page private. The helper function - * fw_iso_buffer_map() will map the pages into a given vma. - */ - -struct fw_iso_buffer { - enum dma_data_direction direction; - struct page **pages; - int page_count; -}; - -struct fw_iso_context { - struct fw_card *card; - int type; - int channel; - int speed; - size_t header_size; - fw_iso_callback_t callback; - void *callback_data; -}; - -int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card, - int page_count, enum dma_data_direction direction); -int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma); -void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card); - -struct fw_iso_context *fw_iso_context_create(struct fw_card *card, - int type, int channel, int speed, size_t header_size, - fw_iso_callback_t callback, void *callback_data); -int fw_iso_context_queue(struct fw_iso_context *ctx, - struct fw_iso_packet *packet, - struct fw_iso_buffer *buffer, - unsigned long payload); -int fw_iso_context_start(struct fw_iso_context *ctx, - int cycle, int sync, int tags); -int fw_iso_context_stop(struct fw_iso_context *ctx); -void fw_iso_context_destroy(struct fw_iso_context *ctx); - -void fw_iso_resource_manage(struct fw_card *card, int generation, - u64 channels_mask, int *channel, int *bandwidth, bool allocate); - -struct fw_card_driver { - /* - * Enable the given card with the given initial config rom. - * This function is expected to activate the card, and either - * enable the PHY or set the link_on bit and initiate a bus - * reset. - */ - int (*enable)(struct fw_card *card, u32 *config_rom, size_t length); - - int (*update_phy_reg)(struct fw_card *card, int address, - int clear_bits, int set_bits); - - /* - * Update the config rom for an enabled card. This function - * should change the config rom that is presented on the bus - * an initiate a bus reset. - */ - int (*set_config_rom)(struct fw_card *card, - u32 *config_rom, size_t length); - - void (*send_request)(struct fw_card *card, struct fw_packet *packet); - void (*send_response)(struct fw_card *card, struct fw_packet *packet); - /* Calling cancel is valid once a packet has been submitted. */ - int (*cancel_packet)(struct fw_card *card, struct fw_packet *packet); - - /* - * Allow the specified node ID to do direct DMA out and in of - * host memory. The card will disable this for all node when - * a bus reset happens, so driver need to reenable this after - * bus reset. Returns 0 on success, -ENODEV if the card - * doesn't support this, -ESTALE if the generation doesn't - * match. - */ - int (*enable_phys_dma)(struct fw_card *card, - int node_id, int generation); - - u64 (*get_bus_time)(struct fw_card *card); - - struct fw_iso_context * - (*allocate_iso_context)(struct fw_card *card, - int type, int channel, size_t header_size); - void (*free_iso_context)(struct fw_iso_context *ctx); - - int (*start_iso)(struct fw_iso_context *ctx, - s32 cycle, u32 sync, u32 tags); - - int (*queue_iso)(struct fw_iso_context *ctx, - struct fw_iso_packet *packet, - struct fw_iso_buffer *buffer, - unsigned long payload); - - int (*stop_iso)(struct fw_iso_context *ctx); -}; - -int fw_core_initiate_bus_reset(struct fw_card *card, int short_reset); - -void fw_send_request(struct fw_card *card, struct fw_transaction *t, - int tcode, int destination_id, int generation, int speed, - unsigned long long offset, void *payload, size_t length, - fw_transaction_callback_t callback, void *callback_data); -int fw_cancel_transaction(struct fw_card *card, - struct fw_transaction *transaction); -void fw_flush_transactions(struct fw_card *card); -int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, - int generation, int speed, unsigned long long offset, - void *payload, size_t length); -void fw_send_phy_config(struct fw_card *card, - int node_id, int generation, int gap_count); - -static inline int fw_stream_packet_destination_id(int tag, int channel, int sy) -{ - return tag << 14 | channel << 8 | sy; -} - -/* - * Called by the topology code to inform the device code of node - * activity; found, lost, or updated nodes. - */ -void fw_node_event(struct fw_card *card, struct fw_node *node, int event); - -/* API used by card level drivers */ - -void fw_card_initialize(struct fw_card *card, - const struct fw_card_driver *driver, struct device *device); -int fw_card_add(struct fw_card *card, - u32 max_receive, u32 link_speed, u64 guid); -void fw_core_remove_card(struct fw_card *card); -void fw_core_handle_bus_reset(struct fw_card *card, int node_id, - int generation, int self_id_count, u32 *self_ids); -void fw_core_handle_request(struct fw_card *card, struct fw_packet *request); -void fw_core_handle_response(struct fw_card *card, struct fw_packet *packet); - -extern int fw_irm_set_broadcast_channel_register(struct device *dev, - void *data); - -#endif /* __fw_transaction_h */ diff --git a/drivers/firewire/fw-ohci.h b/drivers/firewire/ohci.h similarity index 98% rename from drivers/firewire/fw-ohci.h rename to drivers/firewire/ohci.h index a2fbb6240ca7..ba492d85c516 100644 --- a/drivers/firewire/fw-ohci.h +++ b/drivers/firewire/ohci.h @@ -1,5 +1,5 @@ -#ifndef __fw_ohci_h -#define __fw_ohci_h +#ifndef _FIREWIRE_OHCI_H +#define _FIREWIRE_OHCI_H /* OHCI register map */ @@ -154,4 +154,4 @@ #define OHCI1394_phy_tcode 0xe -#endif /* __fw_ohci_h */ +#endif /* _FIREWIRE_OHCI_H */ diff --git a/include/linux/firewire.h b/include/linux/firewire.h new file mode 100644 index 000000000000..e979f9b22cb6 --- /dev/null +++ b/include/linux/firewire.h @@ -0,0 +1,350 @@ +#ifndef _LINUX_FIREWIRE_H +#define _LINUX_FIREWIRE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args) +#define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args) + +static inline void fw_memcpy_from_be32(void *_dst, void *_src, size_t size) +{ + u32 *dst = _dst; + __be32 *src = _src; + int i; + + for (i = 0; i < size / 4; i++) + dst[i] = be32_to_cpu(src[i]); +} + +static inline void fw_memcpy_to_be32(void *_dst, void *_src, size_t size) +{ + fw_memcpy_from_be32(_dst, _src, size); +} +#define CSR_REGISTER_BASE 0xfffff0000000ULL + +/* register offsets are relative to CSR_REGISTER_BASE */ +#define CSR_STATE_CLEAR 0x0 +#define CSR_STATE_SET 0x4 +#define CSR_NODE_IDS 0x8 +#define CSR_RESET_START 0xc +#define CSR_SPLIT_TIMEOUT_HI 0x18 +#define CSR_SPLIT_TIMEOUT_LO 0x1c +#define CSR_CYCLE_TIME 0x200 +#define CSR_BUS_TIME 0x204 +#define CSR_BUSY_TIMEOUT 0x210 +#define CSR_BUS_MANAGER_ID 0x21c +#define CSR_BANDWIDTH_AVAILABLE 0x220 +#define CSR_CHANNELS_AVAILABLE 0x224 +#define CSR_CHANNELS_AVAILABLE_HI 0x224 +#define CSR_CHANNELS_AVAILABLE_LO 0x228 +#define CSR_BROADCAST_CHANNEL 0x234 +#define CSR_CONFIG_ROM 0x400 +#define CSR_CONFIG_ROM_END 0x800 +#define CSR_FCP_COMMAND 0xB00 +#define CSR_FCP_RESPONSE 0xD00 +#define CSR_FCP_END 0xF00 +#define CSR_TOPOLOGY_MAP 0x1000 +#define CSR_TOPOLOGY_MAP_END 0x1400 +#define CSR_SPEED_MAP 0x2000 +#define CSR_SPEED_MAP_END 0x3000 + +#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 CSR_DIRECTORY_ID 0x20 + +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); + +extern struct bus_type fw_bus_type; + +struct fw_card_driver; +struct fw_node; + +struct fw_card { + const struct fw_card_driver *driver; + struct device *device; + struct kref kref; + struct completion done; + + int node_id; + int generation; + int current_tlabel, tlabel_mask; + struct list_head transaction_list; + struct timer_list flush_timer; + unsigned long reset_jiffies; + + unsigned long long guid; + unsigned max_receive; + int link_speed; + int config_rom_generation; + + spinlock_t lock; /* Take this lock when handling the lists in + * this struct. */ + struct fw_node *local_node; + struct fw_node *root_node; + struct fw_node *irm_node; + u8 color; /* must be u8 to match the definition in struct fw_node */ + int gap_count; + bool beta_repeaters_present; + + int index; + + struct list_head link; + + /* Work struct for BM duties. */ + struct delayed_work work; + int bm_retries; + int bm_generation; + + bool broadcast_channel_allocated; + u32 broadcast_channel; + u32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4]; +}; + +static inline struct fw_card *fw_card_get(struct fw_card *card) +{ + kref_get(&card->kref); + + return card; +} + +void fw_card_release(struct kref *kref); + +static inline void fw_card_put(struct fw_card *card) +{ + kref_put(&card->kref, fw_card_release); +} + +struct fw_attribute_group { + struct attribute_group *groups[2]; + struct attribute_group group; + struct attribute *attrs[12]; +}; + +enum fw_device_state { + FW_DEVICE_INITIALIZING, + FW_DEVICE_RUNNING, + FW_DEVICE_GONE, + FW_DEVICE_SHUTDOWN, +}; + +/* + * Note, fw_device.generation always has to be read before fw_device.node_id. + * Use SMP memory barriers to ensure this. Otherwise requests will be sent + * to an outdated node_id if the generation was updated in the meantime due + * to a bus reset. + * + * Likewise, fw-core will take care to update .node_id before .generation so + * that whenever fw_device.generation is current WRT the actual bus generation, + * fw_device.node_id is guaranteed to be current too. + * + * 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 { + atomic_t state; + struct fw_node *node; + int node_id; + int generation; + unsigned max_speed; + struct fw_card *card; + struct device device; + + struct mutex client_list_mutex; + struct list_head client_list; + + u32 *config_rom; + size_t config_rom_length; + int config_rom_retries; + unsigned is_local:1; + unsigned cmc:1; + unsigned bc_implemented:2; + + struct delayed_work work; + struct fw_attribute_group attribute_group; +}; + +static inline struct fw_device *fw_device(struct device *dev) +{ + return container_of(dev, struct fw_device, device); +} + +static inline int fw_device_is_shutdown(struct fw_device *device) +{ + return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN; +} + +static inline struct fw_device *fw_device_get(struct fw_device *device) +{ + get_device(&device->device); + + return device; +} + +static inline void fw_device_put(struct fw_device *device) +{ + put_device(&device->device); +} + +int fw_device_enable_phys_dma(struct fw_device *device); + +/* + * fw_unit.directory must not be accessed after device_del(&fw_unit.device). + */ +struct fw_unit { + struct device device; + u32 *directory; + struct fw_attribute_group attribute_group; +}; + +static inline struct fw_unit *fw_unit(struct device *dev) +{ + return container_of(dev, struct fw_unit, device); +} + +static inline struct fw_unit *fw_unit_get(struct fw_unit *unit) +{ + get_device(&unit->device); + + return unit; +} + +static inline void fw_unit_put(struct fw_unit *unit) +{ + put_device(&unit->device); +} + +struct ieee1394_device_id; + +struct fw_driver { + struct device_driver driver; + /* Called when the parent device sits through a bus reset. */ + void (*update)(struct fw_unit *unit); + const struct ieee1394_device_id *id_table; +}; + +struct fw_packet; +struct fw_request; + +typedef void (*fw_packet_callback_t)(struct fw_packet *packet, + struct fw_card *card, int status); +typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode, + void *data, size_t length, + void *callback_data); +/* + * Important note: The callback must guarantee that either fw_send_response() + * or kfree() is called on the @request. + */ +typedef void (*fw_address_callback_t)(struct fw_card *card, + struct fw_request *request, + int tcode, int destination, int source, + int generation, int speed, + unsigned long long offset, + void *data, size_t length, + void *callback_data); + +struct fw_packet { + int speed; + int generation; + u32 header[4]; + size_t header_length; + void *payload; + size_t payload_length; + dma_addr_t payload_bus; + u32 timestamp; + + /* + * This callback is called when the packet transmission has + * completed; for successful transmission, the status code is + * the ack received from the destination, otherwise it's a + * negative errno: ENOMEM, ESTALE, ETIMEDOUT, ENODEV, EIO. + * The callback can be called from tasklet context and thus + * must never block. + */ + fw_packet_callback_t callback; + int ack; + struct list_head link; + void *driver_data; +}; + +struct fw_transaction { + int node_id; /* The generation is implied; it is always the current. */ + int tlabel; + int timestamp; + struct list_head link; + + struct fw_packet packet; + + /* + * The data passed to the callback is valid only during the + * callback. + */ + fw_transaction_callback_t callback; + void *callback_data; +}; + +struct fw_address_handler { + u64 offset; + size_t length; + fw_address_callback_t address_callback; + void *callback_data; + struct list_head link; +}; + +struct fw_address_region { + u64 start; + u64 end; +}; + +extern const struct fw_address_region fw_high_memory_region; + +int fw_core_add_address_handler(struct fw_address_handler *handler, + const struct fw_address_region *region); +void fw_core_remove_address_handler(struct fw_address_handler *handler); +void fw_send_response(struct fw_card *card, + struct fw_request *request, int rcode); +void fw_send_request(struct fw_card *card, struct fw_transaction *t, + int tcode, int destination_id, int generation, int speed, + unsigned long long offset, void *payload, size_t length, + fw_transaction_callback_t callback, void *callback_data); +int fw_cancel_transaction(struct fw_card *card, + struct fw_transaction *transaction); +int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, + int generation, int speed, unsigned long long offset, + void *payload, size_t length); + +#endif /* _LINUX_FIREWIRE_H */ From e71d31da062095d8b0b02a26fb5e8879e8d3d0de Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Fri, 5 Jun 2009 16:26:18 +0200 Subject: [PATCH 09/14] firewire: rename source files The source files of firewire-core, firewire-ohci, firewire-sbp2, i.e. "drivers/firewire/fw-*.c" are renamed to "drivers/firewire/core-*.c", "drivers/firewire/ohci.c", "drivers/firewire/sbp2.c". The old fw- prefix was redundant to the directory name. The new core- prefix distinguishes the files according to which driver they belong to. This change comes a little late, but still before further firewire drivers are added as anticipated RSN. Signed-off-by: Stefan Richter --- drivers/firewire/Makefile | 8 ++++---- drivers/firewire/{fw-card.c => core-card.c} | 0 drivers/firewire/{fw-cdev.c => core-cdev.c} | 0 drivers/firewire/{fw-device.c => core-device.c} | 0 drivers/firewire/{fw-iso.c => core-iso.c} | 0 drivers/firewire/{fw-topology.c => core-topology.c} | 0 drivers/firewire/{fw-transaction.c => core-transaction.c} | 0 drivers/firewire/{fw-ohci.c => ohci.c} | 0 drivers/firewire/{fw-sbp2.c => sbp2.c} | 0 9 files changed, 4 insertions(+), 4 deletions(-) rename drivers/firewire/{fw-card.c => core-card.c} (100%) rename drivers/firewire/{fw-cdev.c => core-cdev.c} (100%) rename drivers/firewire/{fw-device.c => core-device.c} (100%) rename drivers/firewire/{fw-iso.c => core-iso.c} (100%) rename drivers/firewire/{fw-topology.c => core-topology.c} (100%) rename drivers/firewire/{fw-transaction.c => core-transaction.c} (100%) rename drivers/firewire/{fw-ohci.c => ohci.c} (100%) rename drivers/firewire/{fw-sbp2.c => sbp2.c} (100%) diff --git a/drivers/firewire/Makefile b/drivers/firewire/Makefile index a7c31e9039c1..bc3b9bf822bf 100644 --- a/drivers/firewire/Makefile +++ b/drivers/firewire/Makefile @@ -2,10 +2,10 @@ # Makefile for the Linux IEEE 1394 implementation # -firewire-core-y += fw-card.o fw-topology.o fw-transaction.o fw-iso.o \ - fw-device.o fw-cdev.o -firewire-ohci-y += fw-ohci.o -firewire-sbp2-y += fw-sbp2.o +firewire-core-y += core-card.o core-cdev.o core-device.o \ + core-iso.o core-topology.o core-transaction.o +firewire-ohci-y += ohci.o +firewire-sbp2-y += sbp2.o obj-$(CONFIG_FIREWIRE) += firewire-core.o obj-$(CONFIG_FIREWIRE_OHCI) += firewire-ohci.o diff --git a/drivers/firewire/fw-card.c b/drivers/firewire/core-card.c similarity index 100% rename from drivers/firewire/fw-card.c rename to drivers/firewire/core-card.c diff --git a/drivers/firewire/fw-cdev.c b/drivers/firewire/core-cdev.c similarity index 100% rename from drivers/firewire/fw-cdev.c rename to drivers/firewire/core-cdev.c diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/core-device.c similarity index 100% rename from drivers/firewire/fw-device.c rename to drivers/firewire/core-device.c diff --git a/drivers/firewire/fw-iso.c b/drivers/firewire/core-iso.c similarity index 100% rename from drivers/firewire/fw-iso.c rename to drivers/firewire/core-iso.c diff --git a/drivers/firewire/fw-topology.c b/drivers/firewire/core-topology.c similarity index 100% rename from drivers/firewire/fw-topology.c rename to drivers/firewire/core-topology.c diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/core-transaction.c similarity index 100% rename from drivers/firewire/fw-transaction.c rename to drivers/firewire/core-transaction.c diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/ohci.c similarity index 100% rename from drivers/firewire/fw-ohci.c rename to drivers/firewire/ohci.c diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/sbp2.c similarity index 100% rename from drivers/firewire/fw-sbp2.c rename to drivers/firewire/sbp2.c From e5110d011e03030926872457f05e49e3d5031737 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sat, 6 Jun 2009 18:35:27 +0200 Subject: [PATCH 10/14] firewire: add parent-of-unit accessor Retrieval of an fw_unit's parent is a common pattern in high-level code. Wrap it up as device = fw_parent_device(unit). Signed-off-by: Stefan Richter --- drivers/firewire/core-device.c | 4 ++-- drivers/firewire/sbp2.c | 37 +++++++++++++++++++--------------- include/linux/firewire.h | 5 +++++ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index 65d84dd6c1de..3f4e646367b7 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -93,7 +93,7 @@ static int fw_unit_match(struct device *dev, struct device_driver *drv) if (!is_fw_unit(dev)) return 0; - device = fw_device(unit->device.parent); + device = fw_parent_device(unit); id = container_of(drv, struct fw_driver, driver)->id_table; for (; id->match_flags != 0; id++) { @@ -114,7 +114,7 @@ static int fw_unit_match(struct device *dev, struct device_driver *drv) static int get_modalias(struct fw_unit *unit, char *buffer, size_t buffer_size) { - struct fw_device *device = fw_device(unit->device.parent); + struct fw_device *device = fw_parent_device(unit); struct fw_csr_iterator ci; int key, value; diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c index d41cb6e455bc..2353643721c1 100644 --- a/drivers/firewire/sbp2.c +++ b/drivers/firewire/sbp2.c @@ -180,6 +180,11 @@ struct sbp2_target { int blocked; /* ditto */ }; +static struct fw_device *target_device(struct sbp2_target *tgt) +{ + return fw_parent_device(tgt->unit); +} + /* Impossible login_id, to detect logout attempt before successful login */ #define INVALID_LOGIN_ID 0x10000 @@ -488,7 +493,7 @@ static void complete_transaction(struct fw_card *card, int rcode, static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu, int node_id, int generation, u64 offset) { - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); + struct fw_device *device = target_device(lu->tgt); unsigned long flags; orb->pointer.high = 0; @@ -510,7 +515,7 @@ static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu, static int sbp2_cancel_orbs(struct sbp2_logical_unit *lu) { - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); + struct fw_device *device = target_device(lu->tgt); struct sbp2_orb *orb, *next; struct list_head list; unsigned long flags; @@ -548,7 +553,7 @@ static int sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id, int generation, int function, int lun_or_login_id, void *response) { - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); + struct fw_device *device = target_device(lu->tgt); struct sbp2_management_orb *orb; unsigned int timeout; int retval = -ENOMEM; @@ -644,7 +649,7 @@ static int sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id, static void sbp2_agent_reset(struct sbp2_logical_unit *lu) { - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); + struct fw_device *device = target_device(lu->tgt); __be32 d = 0; fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, @@ -661,7 +666,7 @@ static void complete_agent_reset_write_no_wait(struct fw_card *card, static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu) { - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); + struct fw_device *device = target_device(lu->tgt); struct fw_transaction *t; static __be32 d; @@ -700,7 +705,7 @@ static inline void sbp2_allow_block(struct sbp2_logical_unit *lu) static void sbp2_conditionally_block(struct sbp2_logical_unit *lu) { struct sbp2_target *tgt = lu->tgt; - struct fw_card *card = fw_device(tgt->unit->device.parent)->card; + struct fw_card *card = target_device(tgt)->card; struct Scsi_Host *shost = container_of((void *)tgt, struct Scsi_Host, hostdata[0]); unsigned long flags; @@ -724,7 +729,7 @@ static void sbp2_conditionally_block(struct sbp2_logical_unit *lu) static void sbp2_conditionally_unblock(struct sbp2_logical_unit *lu) { struct sbp2_target *tgt = lu->tgt; - struct fw_card *card = fw_device(tgt->unit->device.parent)->card; + struct fw_card *card = target_device(tgt)->card; struct Scsi_Host *shost = container_of((void *)tgt, struct Scsi_Host, hostdata[0]); unsigned long flags; @@ -749,7 +754,7 @@ static void sbp2_conditionally_unblock(struct sbp2_logical_unit *lu) */ static void sbp2_unblock(struct sbp2_target *tgt) { - struct fw_card *card = fw_device(tgt->unit->device.parent)->card; + struct fw_card *card = target_device(tgt)->card; struct Scsi_Host *shost = container_of((void *)tgt, struct Scsi_Host, hostdata[0]); unsigned long flags; @@ -779,7 +784,7 @@ static void sbp2_release_target(struct kref *kref) struct Scsi_Host *shost = container_of((void *)tgt, struct Scsi_Host, hostdata[0]); struct scsi_device *sdev; - struct fw_device *device = fw_device(tgt->unit->device.parent); + struct fw_device *device = target_device(tgt); /* prevent deadlocks */ sbp2_unblock(tgt); @@ -852,7 +857,7 @@ static void sbp2_queue_work(struct sbp2_logical_unit *lu, unsigned long delay) */ static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu) { - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); + struct fw_device *device = target_device(lu->tgt); __be32 d = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT); fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, @@ -868,7 +873,7 @@ static void sbp2_login(struct work_struct *work) struct sbp2_logical_unit *lu = container_of(work, struct sbp2_logical_unit, work.work); struct sbp2_target *tgt = lu->tgt; - struct fw_device *device = fw_device(tgt->unit->device.parent); + struct fw_device *device = target_device(tgt); struct Scsi_Host *shost; struct scsi_device *sdev; struct sbp2_login_response response; @@ -1116,7 +1121,7 @@ static struct scsi_host_template scsi_driver_template; static int sbp2_probe(struct device *dev) { struct fw_unit *unit = fw_unit(dev); - struct fw_device *device = fw_device(unit->device.parent); + struct fw_device *device = fw_parent_device(unit); struct sbp2_target *tgt; struct sbp2_logical_unit *lu; struct Scsi_Host *shost; @@ -1197,7 +1202,7 @@ static void sbp2_reconnect(struct work_struct *work) struct sbp2_logical_unit *lu = container_of(work, struct sbp2_logical_unit, work.work); struct sbp2_target *tgt = lu->tgt; - struct fw_device *device = fw_device(tgt->unit->device.parent); + struct fw_device *device = target_device(tgt); int generation, node_id, local_node_id; if (fw_device_is_shutdown(device)) @@ -1249,7 +1254,7 @@ static void sbp2_update(struct fw_unit *unit) struct sbp2_target *tgt = unit->device.driver_data; struct sbp2_logical_unit *lu; - fw_device_enable_phys_dma(fw_device(unit->device.parent)); + fw_device_enable_phys_dma(fw_parent_device(unit)); /* * Fw-core serializes sbp2_update() against sbp2_remove(). @@ -1342,7 +1347,7 @@ static void complete_command_orb(struct sbp2_orb *base_orb, { struct sbp2_command_orb *orb = container_of(base_orb, struct sbp2_command_orb, base); - struct fw_device *device = fw_device(orb->lu->tgt->unit->device.parent); + struct fw_device *device = target_device(orb->lu->tgt); int result; if (status != NULL) { @@ -1449,7 +1454,7 @@ static int sbp2_map_scatterlist(struct sbp2_command_orb *orb, static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) { struct sbp2_logical_unit *lu = cmd->device->hostdata; - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); + struct fw_device *device = target_device(lu->tgt); struct sbp2_command_orb *orb; int generation, retval = SCSI_MLQUEUE_HOST_BUSY; diff --git a/include/linux/firewire.h b/include/linux/firewire.h index e979f9b22cb6..a69aea0394e3 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -248,6 +248,11 @@ static inline void fw_unit_put(struct fw_unit *unit) put_device(&unit->device); } +static inline struct fw_device *fw_parent_device(struct fw_unit *unit) +{ + return fw_device(unit->device.parent); +} + struct ieee1394_device_id; struct fw_driver { From e034d242593f12533c11742ce38c245a33e57dc7 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sat, 6 Jun 2009 18:36:24 +0200 Subject: [PATCH 11/14] firewire: core: include linux/uaccess.h instead of asm/uaccess.h Signed-off-by: Stefan Richter --- drivers/firewire/core-cdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 042c04540474..d1d30c615b0f 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -35,12 +35,12 @@ #include #include #include +#include #include #include #include #include -#include #include "core.h" From 099d54143e49d49c33cd25779ca725191df59b73 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sat, 6 Jun 2009 18:37:25 +0200 Subject: [PATCH 12/14] firewire: core: prepare for non-core children of card devices The IP-over-1394 driver will add child devices beneath card devices which are not of type fw_device. Hence firewire-core's callbacks in device_for_each_child() and device_find_child() need to check for the device type now. Initial version written by Jay Fenlason. Signed-off-by: Stefan Richter --- drivers/firewire/core-card.c | 8 +------- drivers/firewire/core-device.c | 24 ++++++++++++++++++++---- drivers/firewire/core.h | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c index ba6cd70b8518..4c1be64fdddd 100644 --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c @@ -190,12 +190,6 @@ void fw_core_remove_descriptor(struct fw_descriptor *desc) mutex_unlock(&card_mutex); } -static int set_broadcast_channel(struct device *dev, void *data) -{ - fw_device_set_broadcast_channel(fw_device(dev), (long)data); - return 0; -} - static void allocate_broadcast_channel(struct fw_card *card, int generation) { int channel, bandwidth = 0; @@ -205,7 +199,7 @@ static void allocate_broadcast_channel(struct fw_card *card, int generation) if (channel == 31) { card->broadcast_channel_allocated = true; device_for_each_child(card->device, (void *)(long)generation, - set_broadcast_channel); + fw_device_set_broadcast_channel); } } diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index 3f4e646367b7..d6e54a5173fc 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -59,7 +59,7 @@ int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value) } EXPORT_SYMBOL(fw_csr_iterator_next); -static int is_fw_unit(struct device *dev); +static bool is_fw_unit(struct device *dev); static int match_unit_directory(u32 *directory, u32 match_flags, const struct ieee1394_device_id *id) @@ -599,7 +599,7 @@ static struct device_type fw_unit_type = { .release = fw_unit_release, }; -static int is_fw_unit(struct device *dev) +static bool is_fw_unit(struct device *dev) { return dev->type == &fw_unit_type; } @@ -749,6 +749,11 @@ static struct device_type fw_device_type = { .release = fw_device_release, }; +static bool is_fw_device(struct device *dev) +{ + return dev->type == &fw_device_type; +} + static int update_unit(struct device *dev, void *data) { struct fw_unit *unit = fw_unit(dev); @@ -785,6 +790,9 @@ static int lookup_existing_device(struct device *dev, void *data) struct fw_card *card = new->card; int match = 0; + if (!is_fw_device(dev)) + return 0; + down_read(&fw_device_rwsem); /* serialize config_rom access */ spin_lock_irq(&card->lock); /* serialize node access */ @@ -824,7 +832,7 @@ static int lookup_existing_device(struct device *dev, void *data) enum { BC_UNKNOWN = 0, BC_UNIMPLEMENTED, BC_IMPLEMENTED, }; -void fw_device_set_broadcast_channel(struct fw_device *device, int generation) +static void set_broadcast_channel(struct fw_device *device, int generation) { struct fw_card *card = device->card; __be32 data; @@ -860,6 +868,14 @@ void fw_device_set_broadcast_channel(struct fw_device *device, int generation) } } +int fw_device_set_broadcast_channel(struct device *dev, void *gen) +{ + if (is_fw_device(dev)) + set_broadcast_channel(fw_device(dev), (long)gen); + + return 0; +} + static void fw_device_init(struct work_struct *work) { struct fw_device *device = @@ -958,7 +974,7 @@ static void fw_device_init(struct work_struct *work) 1 << device->max_speed); device->config_rom_retries = 0; - fw_device_set_broadcast_channel(device, device->generation); + set_broadcast_channel(device, device->generation); } /* diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index 273f0ab82928..0a25a7b38a80 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h @@ -124,7 +124,7 @@ extern struct idr fw_device_idr; extern int fw_cdev_major; struct fw_device *fw_device_get_by_devt(dev_t devt); -void fw_device_set_broadcast_channel(struct fw_device *device, int generation); +int fw_device_set_broadcast_channel(struct device *dev, void *gen); void fw_node_event(struct fw_card *card, struct fw_node *node, int event); From 837ec787d85fda8d73193a399ebcea0288e4765b Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Tue, 9 Jun 2009 23:56:55 +0200 Subject: [PATCH 13/14] firewire: core: don't update Broadcast_Channel if RFC 2734 conditions aren't met This extra check will avoid Broadcast_Channel register related traffic to many IIDC, SBP-2, and AV/C devices which aren't IRMC or have a max_rec < 8 (i.e. support < 512 bytes async payload). This avoids a little bit of traffic after bus reset and is even more careful with devices which don't implement this CSR. The assumption is that no other protocol than IP over 1394 uses the broadcast channel for streams. Signed-off-by: Stefan Richter --- drivers/firewire/core-device.c | 18 +++++++++++++++++- include/linux/firewire.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index d6e54a5173fc..97e656af2d22 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -580,7 +580,9 @@ static int read_bus_info_block(struct fw_device *device, int generation) kfree(old_rom); ret = 0; - device->cmc = rom[2] >> 30 & 1; + device->max_rec = rom[2] >> 12 & 0xf; + device->cmc = rom[2] >> 30 & 1; + device->irmc = rom[2] >> 31 & 1; out: kfree(rom); @@ -841,6 +843,20 @@ static void set_broadcast_channel(struct fw_device *device, int generation) if (!card->broadcast_channel_allocated) return; + /* + * The Broadcast_Channel Valid bit is required by nodes which want to + * transmit on this channel. Such transmissions are practically + * exclusive to IP over 1394 (RFC 2734). IP capable nodes are required + * to be IRM capable and have a max_rec of 8 or more. We use this fact + * to narrow down to which nodes we send Broadcast_Channel updates. + */ + if (!device->irmc || device->max_rec < 8) + return; + + /* + * Some 1394-1995 nodes crash if this 1394a-2000 register is written. + * Perform a read test first. + */ if (device->bc_implemented == BC_UNKNOWN) { rcode = fw_run_transaction(card, TCODE_READ_QUADLET_REQUEST, device->node_id, generation, device->max_speed, diff --git a/include/linux/firewire.h b/include/linux/firewire.h index a69aea0394e3..610eade8abb4 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -191,7 +191,9 @@ struct fw_device { size_t config_rom_length; int config_rom_retries; unsigned is_local:1; + unsigned max_rec:4; unsigned cmc:1; + unsigned irmc:1; unsigned bc_implemented:2; struct delayed_work work; From 1e626fdcef61460dc75fe7377f38bb019722b848 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 14 Jun 2009 13:23:58 +0200 Subject: [PATCH 14/14] firewire: core: use more outbound tlabels Tlabel is a 6 bits wide datum. Wrap it after 63 rather than 31 for more safety against transaction label exhaustion and potential responders' transaction layer bugs. (As noted by Guus Sliepen, this change requires an expansion of tlabel_mask to 64 bits.) Signed-off-by: Stefan Richter --- drivers/firewire/core-transaction.c | 8 ++++---- include/linux/firewire.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c index 9a6ce9ab2a67..479b22f5a1eb 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -82,7 +82,7 @@ static int close_transaction(struct fw_transaction *transaction, list_for_each_entry(t, &card->transaction_list, link) { if (t == transaction) { list_del(&t->link); - card->tlabel_mask &= ~(1 << t->tlabel); + card->tlabel_mask &= ~(1ULL << t->tlabel); break; } } @@ -288,14 +288,14 @@ void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, spin_lock_irqsave(&card->lock, flags); tlabel = card->current_tlabel; - if (card->tlabel_mask & (1 << tlabel)) { + if (card->tlabel_mask & (1ULL << tlabel)) { spin_unlock_irqrestore(&card->lock, flags); callback(card, RCODE_SEND_ERROR, NULL, 0, callback_data); return; } - card->current_tlabel = (card->current_tlabel + 1) & 0x1f; - card->tlabel_mask |= (1 << tlabel); + card->current_tlabel = (card->current_tlabel + 1) & 0x3f; + card->tlabel_mask |= (1ULL << tlabel); t->node_id = destination_id; t->tlabel = tlabel; diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 610eade8abb4..e584b7215e8b 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -98,7 +98,8 @@ struct fw_card { int node_id; int generation; - int current_tlabel, tlabel_mask; + int current_tlabel; + u64 tlabel_mask; struct list_head transaction_list; struct timer_list flush_timer; unsigned long reset_jiffies;