New firewire stack
Hi Linus,
As you may know, we've been working on a new FireWire stack over on linux1394-devel. The main driver behind this work is to get a small, maintainable and supportable FireWire stack, with an acceptable backwards compatibility story.
I've been talking to Stefan Richter about it and we feel that the new stack is ready for inclusion into mainline. What I'd like to propose is that we carry both the new and the old stack in mainline for a few releases. Once we've reached a satisfactory level of stability and worked through what regressions there may be, we can consider deprecating the old stack. Carrying two FireWire stacks in the kernel at the same time is not ideal, but it allows for wider testing of the new stack, while keeping the old stack as a fallback for cases where regressions make the new stack not usable.
There's a lot of good reasons to switch to the new stack and a lot of reasons to switch away from the old one. Highlights:
- Has been in Fedora rawhide (development branch) and -mm for 3 months, will be shipping in Fedora 7.
- Backwards compatible at the library level; existing user space libraries have been ported to use the new user space interface.
- Less than 8k lines of code compared to 30k lines of code in the old stack, and a similar size reduction in the sizes of the .ko's.
- No kernel threads, compared to one subsystem thread and one thread per FireWire controller in the old stack.
- One user space interface to support zero-copy scatter-gather streaming, as opposed to the old stacks 4 (was 5) different streaming interfaces.
- Per-device device files, letting userspace set up more finegrained access control, such as preventing direct access to FireWire storage devices.
Regressions:
- eth1394 not ported over. There is nothing preventing this from being done, though, but there's a couple of infrastructure bits that aren't done yet.
- No support for the PCILynx chipset. Nobody has this chipset anymore, and the pcilynx driver in the old stack is bit-rotting anyway.
- Some SBP-2 (storage) devices fail after significant amounts of IO. Not clear what the problem is, but I can reproduce it here and am working on fixing it.
Please pull from the juju branch in Stefans repo:
git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6.git juju
thanks,
Kristian
drivers/Makefile | 1 + drivers/firewire/Kconfig | 60 ++ drivers/firewire/Makefile | 10 + drivers/firewire/fw-card.c | 544 +++++++++++ drivers/firewire/fw-cdev.c | 954 +++++++++++++++++++ drivers/firewire/fw-device.c | 781 +++++++++++++++ drivers/firewire/fw-device.h | 149 +++ drivers/firewire/fw-iso.c | 163 ++++ drivers/firewire/fw-ohci.c | 1896 +++++++++++++++++++++++++++++++++++++ drivers/firewire/fw-ohci.h | 153 +++ drivers/firewire/fw-sbp2.c | 1165 +++++++++++++++++++++++ drivers/firewire/fw-topology.c | 519 ++++++++++ drivers/firewire/fw-topology.h | 94 ++ drivers/firewire/fw-transaction.c | 889 +++++++++++++++++ drivers/firewire/fw-transaction.h | 505 ++++++++++ drivers/ieee1394/Kconfig | 2 + include/linux/firewire-cdev.h | 268 ++++++ 17 files changed, 8153 insertions(+), 0 deletions(-)
Kristian Høgsberg wrote:
...
Quoted 4 lines
Carrying two FireWire stacks in the kernel
at the same time is not ideal, but it allows for wider testing of the new stack, while keeping the old stack as a fallback for cases where regressions make the new stack not usable.
IMO, giving the new stack full exposure will get us the required input from developers and users so that a migration schedule can be prepared.
Quoted 5 lines
There's a lot of good reasons to switch to the new stack and a lot of reasons to switch away from the old one. Highlights:
- Has been in Fedora rawhide (development branch) and -mm for 3 months, will be shipping in Fedora 7.
There were also a few enthusiasts who gave the new stack a spin via patchkits which I used to publish.
Quoted 9 lines
- Backwards compatible at the library level; existing user space libraries have been ported to use the new user space interface.
- Less than 8k lines of code compared to 30k lines of code in the old stack, and a similar size reduction in the sizes of the .ko's.
- No kernel threads, compared to one subsystem thread and one thread per FireWire controller in the old stack.
Quoted 7 lines
- One user space interface to support zero-copy scatter-gather streaming, as opposed to the old stacks 4 (was 5) different streaming interfaces.
- Per-device device files, letting userspace set up more finegrained access control, such as preventing direct access to FireWire storage devices.
Or in short, Kristian has been addressing a number of big TODOs of the old stack with his reimplementation in a relatively short timeframe, TODOs which haven't been worked on in the existing stack for years, literally. There are also some smaller but effective features in the new stack like gap count optimization for better asynchronous throughput, something which I never got around to implement for the mainline stack because I have been busy with bugfixing and janitorial work.
Quoted 5 lines
Regressions:
- eth1394 not ported over. There is nothing preventing this from being done, though, but there's a couple of infrastructure bits that aren't done yet.
Actually that's one of the reasons why I started to work on eth1394 recently.
Quoted 7 lines
- No support for the PCILynx chipset. Nobody has this chipset anymore, and the pcilynx driver in the old stack is bit-rotting anyway.
- Some SBP-2 (storage) devices fail after significant amounts of IO. Not clear what the problem is, but I can reproduce it here and am working on fixing it.
Quoted 6 lines
Please pull from the juju branch in Stefans repo:
git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6.gitjujuthanks,
Kristian
Linus,
the juju branch is branched off v2.6.21-rc3, and it contains a linear series of 121 commits:
Adrian Bunk (1)
Andrew Morton (4)
Kristian Høgsberg (91)
Marc Butler (1)
Randy Dunlap (1)
Stefan Richter (22)
Thomas Gleixner (1)
If you would rather have it rebased on e.g. 2.6.21 or otherwise reorganized, or want to have the resulting diff posted for everyone to look at, I'd gladly do that.
The stat as I get to see it locally and at master.kernel.org:
drivers/Makefile | 1 + drivers/firewire/Kconfig | 60 + drivers/firewire/Makefile | 10 + drivers/firewire/fw-card.c | 544 ++++++++ drivers/firewire/fw-cdev.c | 954 ++++++++++++++ drivers/firewire/fw-device.c | 782 +++++++++++ drivers/firewire/fw-device.h | 149 +++ drivers/firewire/fw-iso.c | 163 +++ drivers/firewire/fw-ohci.c | 1896 +++++++++++++++++++++++++++ drivers/firewire/fw-ohci.h | 153 +++ drivers/firewire/fw-sbp2.c | 1165 ++++++++++++++++ drivers/firewire/fw-topology.c | 519 ++++++++ drivers/firewire/fw-topology.h | 94 ++ drivers/firewire/fw-transaction.c | 889 +++++++++++++ drivers/firewire/fw-transaction.h | 505 +++++++ drivers/ieee1394/Kconfig | 2 + include/linux/firewire-cdev.h | 268 ++++ 17 files changed, 8154 insertions(+), 0 deletions(-) create mode 100644 drivers/firewire/Kconfig create mode 100644 drivers/firewire/Makefile create mode 100644 drivers/firewire/fw-card.c create mode 100644 drivers/firewire/fw-cdev.c create mode 100644 drivers/firewire/fw-device.c create mode 100644 drivers/firewire/fw-device.h create mode 100644 drivers/firewire/fw-iso.c create mode 100644 drivers/firewire/fw-ohci.c create mode 100644 drivers/firewire/fw-ohci.h create mode 100644 drivers/firewire/fw-sbp2.c create mode 100644 drivers/firewire/fw-topology.c create mode 100644 drivers/firewire/fw-topology.h create mode 100644 drivers/firewire/fw-transaction.c create mode 100644 drivers/firewire/fw-transaction.h create mode 100644 include/linux/firewire-cdev.h
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ----= http://arcgraph.de/sr/
Quoted 6 lines · Kristian H??gsberg
Hi Linus,
As you may know, we've been working on a new FireWire stack over on linux1394-devel. The main driver behind this work is to get a small, maintainable and supportable FireWire stack, with an acceptable backwards compatibility story.
Please send out patches for review first.
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Kristian H??gsberg
Hi Linus,
As you may know, we've been working on a new FireWire stack over on linux1394-devel. The main driver behind this work is to get a small, maintainable and supportable FireWire stack, with an acceptable backwards compatibility story.
Please send out patches for review first.
Yes, it's been a while since the last submission for review [1], and most of the changes went over linux1394-devel only. And to put it mildly, there aren't a lot of capable reviewers watching that list.
Changes since last submission, AFAIR:
- completion of the DMA engine
- completion of the userspace ABI
- extensions to exported sysfs attributes
- some other feature additions like bus manager capability
- lots of bug fixes
- some style fixes
I'll folllow up with "git diff v2.6.21-rc3..juju" ripped apart, reordered, and refreshed against 2.6.21:
[PATCH 1/6] firewire: handling of cards, buses, nodes [PATCH 2/6] firewire: isochronous and asynchronous I/O [PATCH 3/6] firewire: char device interface [PATCH 4/6] firewire: OHCI-1394 lowlevel driver [PATCH 5/6] firewire: SBP-2 highlevel driver [PATCH 6/6] firewire: add it all to kbuild
(If this division seems odd, don't blame Kristian, blame me. :-) I'm looking forward to comments.
[1] http://lkml.org/lkml/2006/12/19/306
http://lkml.org/lkml/2006/12/19/307 http://lkml.org/lkml/2006/12/19/309 http://lkml.org/lkml/2006/12/19/310 http://lkml.org/lkml/2006/12/19/308
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
PATCH 2/6 firewire: isochronous and asynchronous I/O
In reply to Stefan Richter--- drivers/firewire/fw-iso.c | 163 +++++ drivers/firewire/fw-transaction.c | 889 ++++++++++++++++++++++++++++++ drivers/firewire/fw-transaction.h | 505 +++++++++++++++++ 3 files changed, 1557 insertions(+)
drivers/firewire/fw-iso.c new file +163 -0
@@ -0,0 +1,163 @@ +/* -*- c-basic-offset: 8 -*- +* +* fw-iso.c - Isochronous IO +* Copyright (C) 2006 Kristian Hoegsberg <[email protected]> +* +* 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. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/dma-mapping.h> +#include <linux/vmalloc.h> +#include <linux/mm.h> + +#include "fw-transaction.h" +#include "fw-topology.h" +#include "fw-device.h" + +int +fw_iso_buffer_init (struct fw_iso_buffer *buffer,struct fw_card *card, +int page_count,enum dma_data_direction direction) +{ +int i, j, retval = -ENOMEM ; +dma_addr_t address; + + buffer->page_count = page_count; + buffer->direction = direction; + + buffer->pages =kmalloc (page_count *sizeof (buffer->pages[0 ]), +GFP_KERNEL ); +if (buffer->pages ==NULL ) + goto out; + +for (i =0 ; i < buffer->page_count; i++) { + buffer->pages[i] =alloc_page (GFP_KERNEL |GFP_DMA32 | __GFP_ZERO); +if (buffer->pages[i] ==NULL ) + goto out_pages; + + address =dma_map_page (card->device, buffer->pages[i], +0 ,PAGE_SIZE , direction); +if (dma_mapping_error (address)) { +__free_page (buffer->pages[i]); + goto out_pages; + } +set_page_private (buffer->pages[i], address); + } + +return 0 ; + + out_pages: +for (j =0 ; j < i; j++) { + address =page_private (buffer->pages[j]); +dma_unmap_page (card->device, address, +PAGE_SIZE ,DMA_TO_DEVICE ); +__free_page (buffer->pages[j]); + } +kfree (buffer->pages); + out: + buffer->pages =NULL ; +return retval; +} + +int fw_iso_buffer_map (struct fw_iso_buffer *buffer,struct vm_area_struct *vma) +{ +unsigned long uaddr; +int i, retval; + + uaddr = vma->vm_start; +for (i =0 ; i < buffer->page_count; i++) { + retval =vm_insert_page (vma, uaddr, buffer->pages[i]); +if (retval) +return retval; + uaddr +=PAGE_SIZE ; + } + +return 0 ; +} + +void fw_iso_buffer_destroy (struct fw_iso_buffer *buffer, +struct fw_card *card) +{ +int i; +dma_addr_t address; + +for (i =0 ; i < buffer->page_count; i++) { + address =page_private (buffer->pages[i]); +dma_unmap_page (card->device, address, +PAGE_SIZE ,DMA_TO_DEVICE ); +__free_page (buffer->pages[i]); + } + +kfree (buffer->pages); + buffer->pages =NULL ; +} + +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) +{ +struct fw_iso_context *ctx; + + ctx = card->driver->allocate_iso_context (card, type, header_size); +if (IS_ERR (ctx)) +return ctx; + + ctx->card = card; + ctx->type = type; + ctx->channel = channel; + ctx->speed = speed; + ctx->header_size = header_size; + ctx->callback = callback; + ctx->callback_data = callback_data; + +return ctx; +} +EXPORT_SYMBOL (fw_iso_context_create); + +void fw_iso_context_destroy (struct fw_iso_context *ctx) +{ +struct fw_card *card = ctx->card; + + card->driver->free_iso_context (ctx); +} +EXPORT_SYMBOL (fw_iso_context_destroy); + +int +fw_iso_context_start (struct fw_iso_context *ctx,int cycle,int sync,int tags) +{ +return ctx->card->driver->start_iso (ctx, cycle, sync, tags); +} +EXPORT_SYMBOL (fw_iso_context_start); + +int +fw_iso_context_queue (struct fw_iso_context *ctx, +struct fw_iso_packet *packet, +struct fw_iso_buffer *buffer, +unsigned long payload) +{ +struct fw_card *card = ctx->card; + +return card->driver->queue_iso (ctx, packet, buffer, payload); +} +EXPORT_SYMBOL (fw_iso_context_queue); + +int +fw_iso_context_stop (struct fw_iso_context *ctx) +{ +return ctx->card->driver->stop_iso (ctx); +} +EXPORT_SYMBOL (fw_iso_context_stop);
drivers/firewire/fw-transaction.h new file +505 -0
505 lines not on this page · raw message
drivers/firewire/fw-transaction.c new file +889 -0
889 lines not on this page · raw message
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
PATCH 1/6 firewire: handling of cards, buses, nodes
In reply to Stefan Richter--- drivers/firewire/fw-card.c | 544 ++++++++++++++++++++++ drivers/firewire/fw-device.c | 782 +++++++++++++++++++++++++++++++++ drivers/firewire/fw-device.h | 149 ++++++ drivers/firewire/fw-topology.c | 519 +++++++++++++++++++++ drivers/firewire/fw-topology.h | 94 +++ 5 files changed, 2088 insertions(+)
drivers/firewire/fw-card.c new file +544 -0
@@ -0,0 +1,544 @@ +/* -*- c-basic-offset: 8 -*- +* +* fw-card.c - card level functions +* +* Copyright (C) 2005-2006 Kristian Hoegsberg <[email protected]> +* +* 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. +*/ + +#include <linux/module.h> +#include <linux/errno.h> +#include <linux/device.h> +#include <linux/rwsem.h> +#include "fw-transaction.h" +#include "fw-topology.h" +#include "fw-device.h" + +/* The lib/crc16.c implementation uses the standard (0x8005) +* polynomial, but we need the ITU-T (or CCITT) polynomial (0x1021). +* The implementation below works on an array of host-endian u32 +* words, assuming they'll be transmited msb first. */ +u16 +crc16_itu_t (const u32 *buffer,size_t length) +{ +int shift, i; +u32 data; +u16 sum, crc =0 ; + +for (i =0 ; i < length; i++) { + data = *buffer++; +for (shift =28 ; shift >=0 ; shift -=4 ) { + sum = ((crc >>12 ) ^ (data >> shift)) &0xf ; + crc = (crc <<4 ) ^ (sum <<12 ) ^ (sum <<5 ) ^ (sum); + } + crc &=0xffff ; + } + +return crc; +} + +static DECLARE_RWSEM (card_rwsem); +static LIST_HEAD (card_list); + +static LIST_HEAD (descriptor_list); +static int descriptor_count; + +#define bib_crc (v) ((v) << 0) +#define bib_crc_length (v) ((v) << 16) +#define bib_info_length (v) ((v) << 24) + +#define bib_link_speed (v) ((v) << 0) +#define bib_generation (v) ((v) << 4) +#define bib_max_rom (v) ((v) << 8) +#define bib_max_receive (v) ((v) << 12) +#define bib_cyc_clk_acc (v) ((v) << 16) +#define bib_pmc ((1) << 27) +#define bib_bmc ((1) << 28) +#define bib_isc ((1) << 29) +#define bib_cmc ((1) << 30) +#define bib_imc ((1) << 31) + +static u32 * +generate_config_rom (struct fw_card *card,size_t *config_rom_length) +{ +struct fw_descriptor *desc; +static u32 config_rom[256 ]; +int i, j, length; + +/* Initialize contents of config rom buffer. On the OHCI +* controller, block reads to the config rom accesses the host +* memory, but quadlet read access the hardware bus info block +* registers. That's just crack, but it means we should make +* sure the contents of bus info block in host memory mathces +* the version stored in the OHCI registers. */ + +memset (config_rom,0 ,sizeof config_rom); + config_rom[0 ] =bib_crc_length (4 ) |bib_info_length (4 ) |bib_crc (0 ); + config_rom[1 ] =0x31333934 ; + + config_rom[2 ] = +bib_link_speed (card->link_speed) | +bib_generation (card->config_rom_generation++ %14 +2 ) | +bib_max_rom (2 ) | +bib_max_receive (card->max_receive) | + bib_bmc | bib_isc | bib_cmc | bib_imc; + config_rom[3 ] = card->guid >>32 ; + config_rom[4 ] = card->guid; + +/* Generate root directory. */ + i =5 ; + config_rom[i++] =0 ; + config_rom[i++] =0x0c0083c0 ;/* node capabilities */ + j = i + descriptor_count; + +/* Generate root directory entries for descriptors. */ + list_for_each_entry (desc, &descriptor_list, link) { +if (desc->immediate >0 ) + config_rom[i++] = desc->immediate; + config_rom[i] = desc->key | (j - i); + i++; + j += desc->length; + } + +/* Update root directory length. */ + config_rom[5 ] = (i -5 -1 ) <<16 ; + +/* End of root directory, now copy in descriptors. */ + list_for_each_entry (desc, &descriptor_list, link) { +memcpy (&config_rom[i], desc->data, desc->length *4 ); + i += desc->length; + } + +/* Calculate CRCs for all blocks in the config rom. This +* assumes that CRC length and info length are identical for +* the bus info block, which is always the case for this +* implementation. */ +for (i =0 ; i < j; i += length +1 ) { + length = (config_rom[i] >>16 ) &0xff ; + config_rom[i] |=crc16_itu_t (&config_rom[i +1 ], length); + } + + *config_rom_length = j; + +return config_rom; +} + +static void +update_config_roms (void ) +{ +struct fw_card *card; +u32 *config_rom; +size_t length; + + list_for_each_entry (card, &card_list, link) { + config_rom =generate_config_rom (card, &length); + card->driver->set_config_rom (card, config_rom, length); + } +} + +int +fw_core_add_descriptor (struct fw_descriptor *desc) +{ +size_t i; + +/* Check descriptor is valid; the length of all blocks in the +* descriptor has to add up to exactly the length of the +* block. */ + i =0 ; +while (i < desc->length) + i += (desc->data[i] >>16 ) +1 ; + +if (i != desc->length) +return -EINVAL ; + +down_write (&card_rwsem); + +list_add_tail (&desc->link, &descriptor_list); + descriptor_count++; +if (desc->immediate >0 ) + descriptor_count++; +update_config_roms (); + +up_write (&card_rwsem); + +return 0 ; +} +EXPORT_SYMBOL (fw_core_add_descriptor); + +void +fw_core_remove_descriptor (struct fw_descriptor *desc) +{ +down_write (&card_rwsem); + +list_del (&desc->link); + descriptor_count--; +if (desc->immediate >0 ) + descriptor_count--; +update_config_roms (); + +up_write (&card_rwsem); +} +EXPORT_SYMBOL (fw_core_remove_descriptor); + +static const char gap_count_table[] = { +63 ,5 ,7 ,8 ,10 ,13 ,16 ,18 ,21 ,24 ,26 ,29 ,32 ,35 ,37 ,40 +}; + +struct bm_data { +struct fw_transaction t; +struct { +__be32 arg; +__be32 data; + } lock; +u32 old; +int rcode; +struct completion done; +}; + +static void +complete_bm_lock (struct fw_card *card,int rcode, +void *payload,size_t length,void *data) +{ +struct bm_data *bmd = data; + +if (rcode ==RCODE_COMPLETE ) + bmd->old =be32_to_cpu (*(__be32 *) payload); + bmd->rcode = rcode; +complete (&bmd->done); +} + +static void +fw_card_bm_work (struct work_struct *work) +{ + struct fw_card *card = container_of(work, struct fw_card, work.work); +struct fw_device *root; +struct bm_data bmd; +unsigned long flags; +int root_id, new_root_id, irm_id, gap_count, generation, grace; +int do_reset =0 ; + +spin_lock_irqsave (&card->lock, flags); + + generation = card->generation; + root = card->root_node->data; + root_id = card->root_node->node_id; + grace =time_after (jiffies, card->reset_jiffies +DIV_ROUND_UP (HZ ,10 )); + +if (card->bm_generation +1 == generation || + (card->bm_generation != generation && grace)) { +/* This first step is to figure out who is IRM and +* then try to become bus manager. If the IRM is not +* well defined (e.g. does not have an active link +* layer or does not responds to our lock request, we +* will have to do a little vigilante bus management. +* In that case, we do a goto into the gap count logic +* so that when we do the reset, we still optimize the +* gap count. That could well save a reset in the +* next generation. */ + + irm_id = card->irm_node->node_id; +if (!card->irm_node->link_on) { + new_root_id = card->local_node->node_id; +fw_notify ("IRM has link off, making local node (%02x) root.\n" , + new_root_id); + goto pick_me; + } + + bmd.lock.arg =cpu_to_be32 (0x3f ); + bmd.lock.data =cpu_to_be32 (card->local_node->node_id); + +spin_unlock_irqrestore (&card->lock, flags); + +init_completion (&bmd.done); +fw_send_request (card, &bmd.t,TCODE_LOCK_COMPARE_SWAP , + irm_id, generation, +SCODE_100 ,CSR_REGISTER_BASE +CSR_BUS_MANAGER_ID , + &bmd.lock,sizeof bmd.lock, + complete_bm_lock, &bmd); +wait_for_completion (&bmd.done); + +if (bmd.rcode ==RCODE_GENERATION ) { +/* Another bus reset happened. Just return, +* the BM work has been rescheduled. */ +return ; + } + +if (bmd.rcode ==RCODE_COMPLETE && bmd.old !=0x3f ) +/* Somebody else is BM, let them do the work. */ +return ; + +spin_lock_irqsave (&card->lock, flags); +if (bmd.rcode !=RCODE_COMPLETE ) { +/* The lock request failed, maybe the IRM +* isn't really IRM capable after all. Let's +* do a bus reset and pick the local node as +* root, and thus, IRM. */ + new_root_id = card->local_node->node_id; +fw_notify ("BM lock failed, making local node (%02x) root.\n" , + new_root_id); + goto pick_me; + } + }else if (card->bm_generation != generation) { +/* OK, we weren't BM in the last generation, and it's +* less than 100ms since last bus reset. Reschedule +* this task 100ms from now. */ +spin_unlock_irqrestore (&card->lock, flags); +schedule_delayed_work (&card->work,DIV_ROUND_UP (HZ ,10 )); +return ; + } + +/* We're bus manager for this generation, so next step is to +* make sure we have an active cycle master and do gap count +* optimization. */ + card->bm_generation = generation; + +if (root ==NULL ) { +/* Either link_on is false, or we failed to read the +* config rom. In either case, pick another root. */ + new_root_id = card->local_node->node_id; + }else if (atomic_read (&root->state) !=FW_DEVICE_RUNNING ) { +/* If we haven't probed this device yet, bail out now +* and let's try again once that's done. */ +spin_unlock_irqrestore (&card->lock, flags); +return ; + }else if (root->config_rom[2 ] & bib_cmc) { +/* FIXME: I suppose we should set the cmstr bit in the +* STATE_CLEAR register of this node, as described in +* 1394-1995, 8.4.2.6. Also, send out a force root +* packet for this node. */ + new_root_id = root_id; + }else { +/* Current root has an active link layer and we +* successfully read the config rom, but it's not +* cycle master capable. */ + new_root_id = card->local_node->node_id; + } + + pick_me: +/* Now figure out what gap count to set. */ +if (card->topology_type ==FW_TOPOLOGY_A && + card->root_node->max_hops <ARRAY_SIZE (gap_count_table)) + gap_count = gap_count_table[card->root_node->max_hops]; +else + gap_count =63 ; + +/* Finally, figure out if we should do a reset or not. If we've +* done less that 5 resets with the same physical topology and we +* have either a new root or a new gap count setting, let's do it. */ + +if (card->bm_retries++ <5 && + (card->gap_count != gap_count || new_root_id != root_id)) + do_reset =1 ; + +spin_unlock_irqrestore (&card->lock, flags); + +if (do_reset) { +fw_notify ("phy config: card %d, new root=%x, gap_count=%d\n" , + card->index, new_root_id, gap_count); +fw_send_phy_config (card, new_root_id, generation, gap_count); +fw_core_initiate_bus_reset (card,1 ); + } +} + +static void +flush_timer_callback (unsigned long data) +{ +struct fw_card *card = (struct fw_card *)data; + +fw_flush_transactions (card); +} + +void +fw_card_initialize (struct fw_card *card,const struct fw_card_driver *driver, +struct device *device) +{ +static atomic_t index =ATOMIC_INIT (-1 ); + +kref_init (&card->kref); + card->index =atomic_inc_return (&index); + card->driver = driver; + card->device = device; + card->current_tlabel =0 ; + card->tlabel_mask =0 ; + card->color =0 ; + +INIT_LIST_HEAD (&card->transaction_list); +spin_lock_init (&card->lock); +setup_timer (&card->flush_timer, + flush_timer_callback, (unsigned long )card); + + card->local_node =NULL ; + +INIT_DELAYED_WORK (&card->work, fw_card_bm_work); +} +EXPORT_SYMBOL (fw_card_initialize); + +int +fw_card_add (struct fw_card *card, +u32 max_receive,u32 link_speed,u64 guid) +{ +u32 *config_rom; +size_t length; + + card->max_receive = max_receive; + card->link_speed = link_speed; + card->guid = guid; + +/* Activate link_on bit and contender bit in our self ID packets.*/ +if (card->driver->update_phy_reg (card,4 ,0 , +PHY_LINK_ACTIVE |PHY_CONTENDER ) <0 ) +return -EIO ; + +/* The subsystem grabs a reference when the card is added and +* drops it when the driver calls fw_core_remove_card. */ +fw_card_get (card); + +down_write (&card_rwsem); + config_rom =generate_config_rom (card, &length); +list_add_tail (&card->link, &card_list); +up_write (&card_rwsem); + +return card->driver->enable (card, config_rom, length); +} +EXPORT_SYMBOL (fw_card_add); + + +/* The next few functions implements a dummy driver that use once a +* card driver shuts down an fw_card. This allows the driver to +* cleanly unload, as all IO to the card will be handled by the dummy +* driver instead of calling into the (possibly) unloaded module. The +* dummy driver just fails all IO. */ + +static int +dummy_enable (struct fw_card *card,u32 *config_rom,size_t length) +{ +BUG (); +return -1 ; +} + +static int +dummy_update_phy_reg (struct fw_card *card,int address, +int clear_bits,int set_bits) +{ +return -ENODEV ; +} + +static int +dummy_set_config_rom (struct fw_card *card, +u32 *config_rom,size_t length) +{ +/* We take the card out of card_list before setting the dummy +* driver, so this should never get called. */ +BUG (); +return -1 ; +} + +static void +dummy_send_request (struct fw_card *card,struct fw_packet *packet) +{ + packet->callback (packet, card, -ENODEV ); +} + +static void +dummy_send_response (struct fw_card *card,struct fw_packet *packet) +{ + packet->callback (packet, card, -ENODEV ); +} + +static int +dummy_cancel_packet (struct fw_card *card,struct fw_packet *packet) +{ +return -ENOENT ; +} + +static int +dummy_enable_phys_dma (struct fw_card *card, +int node_id,int generation) +{ +return -ENODEV ; +} + +static struct fw_card_driver dummy_driver = { + .name ="dummy" , + .enable = dummy_enable, + .update_phy_reg = dummy_update_phy_reg, + .set_config_rom = dummy_set_config_rom, + .send_request = dummy_send_request, + .cancel_packet = dummy_cancel_packet, + .send_response = dummy_send_response, + .enable_phys_dma = dummy_enable_phys_dma, +}; + +void +fw_core_remove_card (struct fw_card *card) +{ + card->driver->update_phy_reg (card,4 , +PHY_LINK_ACTIVE |PHY_CONTENDER ,0 ); +fw_core_initiate_bus_reset (card,1 ); + +down_write (&card_rwsem); +list_del (&card->link); +up_write (&card_rwsem); + +/* Set up the dummy driver. */ + card->driver = &dummy_driver; + +fw_flush_transactions (card); + +fw_destroy_nodes (card); + +fw_card_put (card); +} +EXPORT_SYMBOL (fw_core_remove_card); + +struct fw_card * +fw_card_get (struct fw_card *card) +{ +kref_get (&card->kref); + +return card; +} +EXPORT_SYMBOL (fw_card_get); + +static void +release_card (struct kref *kref) +{ + struct fw_card *card = container_of(kref, struct fw_card, kref); + +kfree (card); +} + +/* An assumption for fw_card_put() is that the card driver allocates +* the fw_card struct with kalloc and that it has been shut down +* before the last ref is dropped. */ +void +fw_card_put (struct fw_card *card) +{ +kref_put (&card->kref, release_card); +} +EXPORT_SYMBOL (fw_card_put); + +int +fw_core_initiate_bus_reset (struct fw_card *card,int short_reset) +{ +int reg = short_reset ?5 :1 ; +/* The following values happen to be the same bit. However be +* explicit for clarity. */ +int bit = short_reset ?PHY_BUS_SHORT_RESET :PHY_BUS_RESET ; + +return card->driver->update_phy_reg (card, reg,0 , bit); +} +EXPORT_SYMBOL (fw_core_initiate_bus_reset);
drivers/firewire/fw-device.h new file +149 -0
149 lines not on this page · raw message
drivers/firewire/fw-device.c new file +782 -0
782 lines not on this page · raw message
drivers/firewire/fw-topology.h new file +94 -0
94 lines not on this page · raw message
drivers/firewire/fw-topology.c new file +519 -0
519 lines not on this page · raw message
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
PATCH 3/6 firewire: char device interface
In reply to Stefan Richter--- drivers/firewire/fw-cdev.c | 954 ++++++++++++++++++++++++++++++++++ include/linux/firewire-cdev.h | 268 +++++++++ 2 files changed, 1222 insertions(+)
include/linux/firewire-cdev.h new file +268 -0
@@ -0,0 +1,268 @@ +/* -*- c-basic-offset: 8 -*- +* +* fw-device-cdev.h -- Char device interface. +* +* Copyright (C) 2005-2006 Kristian Hoegsberg <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef __fw_cdev_h +#define __fw_cdev_h + +#include <asm/ioctl.h> +#include <asm/types.h> + +#define TCODE_WRITE_QUADLET_REQUEST 0 +#define TCODE_WRITE_BLOCK_REQUEST 1 +#define TCODE_WRITE_RESPONSE 2 +#define TCODE_READ_QUADLET_REQUEST 4 +#define TCODE_READ_BLOCK_REQUEST 5 +#define TCODE_READ_QUADLET_RESPONSE 6 +#define TCODE_READ_BLOCK_RESPONSE 7 +#define TCODE_CYCLE_START 8 +#define TCODE_LOCK_REQUEST 9 +#define TCODE_STREAM_DATA 10 +#define TCODE_LOCK_RESPONSE 11 + +#define TCODE_LOCK_MASK_SWAP 0x11 +#define TCODE_LOCK_COMPARE_SWAP 0x12 +#define TCODE_LOCK_FETCH_ADD 0x13 +#define TCODE_LOCK_LITTLE_ADD 0x14 +#define TCODE_LOCK_BOUNDED_ADD 0x15 +#define TCODE_LOCK_WRAP_ADD 0x16 +#define TCODE_LOCK_VENDOR_DEPENDENT 0x17 + +#define RCODE_COMPLETE 0x0 +#define RCODE_CONFLICT_ERROR 0x4 +#define RCODE_DATA_ERROR 0x5 +#define RCODE_TYPE_ERROR 0x6 +#define RCODE_ADDRESS_ERROR 0x7 + +#define RCODE_SEND_ERROR 0x10 +#define RCODE_CANCELLED 0x11 +#define RCODE_BUSY 0x12 +#define RCODE_GENERATION 0x13 +#define RCODE_NO_ACK 0x14 + +#define SCODE_100 0x0 +#define SCODE_200 0x1 +#define SCODE_400 0x2 +#define SCODE_800 0x3 +#define SCODE_1600 0x4 +#define SCODE_3200 0x5 + +#define FW_CDEV_EVENT_BUS_RESET 0x00 +#define FW_CDEV_EVENT_RESPONSE 0x01 +#define FW_CDEV_EVENT_REQUEST 0x02 +#define FW_CDEV_EVENT_ISO_INTERRUPT 0x03 + +/* The 'closure' fields are for user space to use. Data passed in the +* 'closure' field for a request will be returned in the corresponding +* event. It's a 64-bit type so that it's a fixed size type big +* enough to hold a pointer on all platforms. */ + +struct fw_cdev_event_common { +__u64 closure; +__u32 type; +}; + +struct fw_cdev_event_bus_reset { +__u64 closure; +__u32 type; +__u32 node_id; +__u32 local_node_id; +__u32 bm_node_id; +__u32 irm_node_id; +__u32 root_node_id; +__u32 generation; +}; + +struct fw_cdev_event_response { +__u64 closure; +__u32 type; +__u32 rcode; +__u32 length; +__u32 data[0 ]; +}; + +struct fw_cdev_event_request { +__u64 closure; +__u32 type; +__u32 tcode; +__u64 offset; +__u32 handle; +__u32 length; +__u32 data[0 ]; +}; + +struct fw_cdev_event_iso_interrupt { +__u64 closure; +__u32 type; +__u32 cycle; +__u32 header_length;/* Length in bytes of following headers. */ +__u32 header[0 ]; +}; + +union fw_cdev_event { +struct fw_cdev_event_common common; +struct fw_cdev_event_bus_reset bus_reset; +struct fw_cdev_event_response response; +struct fw_cdev_event_request request; +struct fw_cdev_event_iso_interrupt iso_interrupt; +}; + +#define FW_CDEV_IOC_GET_INFO _IOWR('#', 0x00, struct fw_cdev_get_info) +#define FW_CDEV_IOC_SEND_REQUEST _IOW('#', 0x01, struct fw_cdev_send_request) +#define FW_CDEV_IOC_ALLOCATE _IOWR('#', 0x02, struct fw_cdev_allocate) +#define FW_CDEV_IOC_DEALLOCATE _IOW('#', 0x03, struct fw_cdev_deallocate) +#define FW_CDEV_IOC_SEND_RESPONSE _IOW('#', 0x04, struct fw_cdev_send_response) +#define FW_CDEV_IOC_INITIATE_BUS_RESET _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset) +#define FW_CDEV_IOC_ADD_DESCRIPTOR _IOWR('#', 0x06, struct fw_cdev_add_descriptor) +#define FW_CDEV_IOC_REMOVE_DESCRIPTOR _IOW('#', 0x07, struct fw_cdev_remove_descriptor) + +#define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context) +#define FW_CDEV_IOC_QUEUE_ISO _IOWR('#', 0x09, struct fw_cdev_queue_iso) +#define FW_CDEV_IOC_START_ISO _IOW('#', 0x0a, struct fw_cdev_start_iso) +#define FW_CDEV_IOC_STOP_ISO _IOW('#', 0x0b, struct fw_cdev_stop_iso) + +/* FW_CDEV_VERSION History +* +* 1 Feb 18, 2007: Initial version. +*/ +#define FW_CDEV_VERSION 1 + +struct fw_cdev_get_info { +/* The version field is just a running serial number. We +* never break backwards compatibility. Userspace passes in +* the version it expects and the kernel passes back the +* highest version it can provide. Even if the structs in +* this interface are extended in a later version, the kernel +* will not copy back more data than what was present in the +* interface version userspace expects. */ +__u32 version; + +/* If non-zero, at most rom_length bytes of config rom will be +* copied into that user space address. In either case, +* rom_length is updated with the actual length of the config +* rom. */ +__u32 rom_length; +__u64 rom; + +/* If non-zero, a fw_cdev_event_bus_reset struct will be +* copied here with the current state of the bus. This does +* not cause a bus reset to happen. The value of closure in +* this and sub-sequent bus reset events is set to +* bus_reset_closure. */ +__u64 bus_reset; +__u64 bus_reset_closure; + +/* The index of the card this devices belongs to. */ +__u32 card; +}; + +struct fw_cdev_send_request { +__u32 tcode; +__u32 length; +__u64 offset; +__u64 closure; +__u64 data; +__u32 generation; +}; + +struct fw_cdev_send_response { +__u32 rcode; +__u32 length; +__u64 data; +__u32 handle; +}; + +struct fw_cdev_allocate { +__u64 offset; +__u64 closure; +__u32 length; +__u32 handle; +}; + +struct fw_cdev_deallocate { +__u32 handle; +}; + +#define FW_CDEV_LONG_RESET 0 +#define FW_CDEV_SHORT_RESET 1 + +struct fw_cdev_initiate_bus_reset { +__u32 type; +}; + +struct fw_cdev_add_descriptor { +__u32 immediate; +__u32 key; +__u64 data; +__u32 length; +__u32 handle; +}; + +struct fw_cdev_remove_descriptor { +__u32 handle; +}; + +#define FW_CDEV_ISO_CONTEXT_TRANSMIT 0 +#define FW_CDEV_ISO_CONTEXT_RECEIVE 1 + +#define FW_CDEV_ISO_CONTEXT_MATCH_TAG0 1 +#define FW_CDEV_ISO_CONTEXT_MATCH_TAG1 2 +#define FW_CDEV_ISO_CONTEXT_MATCH_TAG2 4 +#define FW_CDEV_ISO_CONTEXT_MATCH_TAG3 8 +#define FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS 15 + +struct fw_cdev_create_iso_context { +__u32 type; +__u32 header_size; +__u32 channel; +__u32 speed; +__u64 closure; +__u32 handle; +}; + +struct fw_cdev_iso_packet { +__u16 payload_length;/* Length of indirect payload. */ +__u32 interrupt :1 ;/* Generate interrupt on this packet */ +__u32 skip :1 ;/* Set to not send packet at all. */ +__u32 tag :2 ; +__u32 sy :4 ; +__u32 header_length :8 ;/* Length of immediate header. */ +__u32 header[0 ]; +}; + +struct fw_cdev_queue_iso { +__u64 packets; +__u64 data; +__u32 size; +__u32 handle; +}; + +struct fw_cdev_start_iso { +__s32 cycle; +__u32 sync; +__u32 tags; +__u32 handle; +}; + +struct fw_cdev_stop_iso { +__u32 handle; +}; + +#endif /* __fw_cdev_h */
drivers/firewire/fw-cdev.c new file +954 -0
954 lines not on this page · raw message
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
PATCH 4/6 firewire: OHCI-1394 lowlevel driver
--- drivers/firewire/fw-ohci.c | 1896 +++++++++++++++++++++++++++++++++++++ drivers/firewire/fw-ohci.h | 153 ++ 2 files changed, 2049 insertions(+)
drivers/firewire/fw-ohci.h new file +153 -0
@@ -0,0 +1,153 @@ +#ifndef __fw_ohci_h +#define __fw_ohci_h + +/* OHCI register map */ + +#define OHCI1394_Version 0x000 +#define OHCI1394_GUID_ROM 0x004 +#define OHCI1394_ATRetries 0x008 +#define OHCI1394_CSRData 0x00C +#define OHCI1394_CSRCompareData 0x010 +#define OHCI1394_CSRControl 0x014 +#define OHCI1394_ConfigROMhdr 0x018 +#define OHCI1394_BusID 0x01C +#define OHCI1394_BusOptions 0x020 +#define OHCI1394_GUIDHi 0x024 +#define OHCI1394_GUIDLo 0x028 +#define OHCI1394_ConfigROMmap 0x034 +#define OHCI1394_PostedWriteAddressLo 0x038 +#define OHCI1394_PostedWriteAddressHi 0x03C +#define OHCI1394_VendorID 0x040 +#define OHCI1394_HCControlSet 0x050 +#define OHCI1394_HCControlClear 0x054 +#define OHCI1394_HCControl_BIBimageValid 0x80000000 +#define OHCI1394_HCControl_noByteSwapData 0x40000000 +#define OHCI1394_HCControl_programPhyEnable 0x00800000 +#define OHCI1394_HCControl_aPhyEnhanceEnable 0x00400000 +#define OHCI1394_HCControl_LPS 0x00080000 +#define OHCI1394_HCControl_postedWriteEnable 0x00040000 +#define OHCI1394_HCControl_linkEnable 0x00020000 +#define OHCI1394_HCControl_softReset 0x00010000 +#define OHCI1394_SelfIDBuffer 0x064 +#define OHCI1394_SelfIDCount 0x068 +#define OHCI1394_IRMultiChanMaskHiSet 0x070 +#define OHCI1394_IRMultiChanMaskHiClear 0x074 +#define OHCI1394_IRMultiChanMaskLoSet 0x078 +#define OHCI1394_IRMultiChanMaskLoClear 0x07C +#define OHCI1394_IntEventSet 0x080 +#define OHCI1394_IntEventClear 0x084 +#define OHCI1394_IntMaskSet 0x088 +#define OHCI1394_IntMaskClear 0x08C +#define OHCI1394_IsoXmitIntEventSet 0x090 +#define OHCI1394_IsoXmitIntEventClear 0x094 +#define OHCI1394_IsoXmitIntMaskSet 0x098 +#define OHCI1394_IsoXmitIntMaskClear 0x09C +#define OHCI1394_IsoRecvIntEventSet 0x0A0 +#define OHCI1394_IsoRecvIntEventClear 0x0A4 +#define OHCI1394_IsoRecvIntMaskSet 0x0A8 +#define OHCI1394_IsoRecvIntMaskClear 0x0AC +#define OHCI1394_InitialBandwidthAvailable 0x0B0 +#define OHCI1394_InitialChannelsAvailableHi 0x0B4 +#define OHCI1394_InitialChannelsAvailableLo 0x0B8 +#define OHCI1394_FairnessControl 0x0DC +#define OHCI1394_LinkControlSet 0x0E0 +#define OHCI1394_LinkControlClear 0x0E4 +#define OHCI1394_LinkControl_rcvSelfID (1 << 9) +#define OHCI1394_LinkControl_rcvPhyPkt (1 << 10) +#define OHCI1394_LinkControl_cycleTimerEnable (1 << 20) +#define OHCI1394_LinkControl_cycleMaster (1 << 21) +#define OHCI1394_LinkControl_cycleSource (1 << 22) +#define OHCI1394_NodeID 0x0E8 +#define OHCI1394_NodeID_idValid 0x80000000 +#define OHCI1394_PhyControl 0x0EC +#define OHCI1394_PhyControl_Read (addr) (((addr) << 8) | 0x00008000) +#define OHCI1394_PhyControl_ReadDone 0x80000000 +#define OHCI1394_PhyControl_ReadData (r) (((r) & 0x00ff0000) >> 16) +#define OHCI1394_PhyControl_Write (addr, data) (((addr) << 8) | (data) | 0x00004000) +#define OHCI1394_PhyControl_WriteDone 0x00004000 +#define OHCI1394_IsochronousCycleTimer 0x0F0 +#define OHCI1394_AsReqFilterHiSet 0x100 +#define OHCI1394_AsReqFilterHiClear 0x104 +#define OHCI1394_AsReqFilterLoSet 0x108 +#define OHCI1394_AsReqFilterLoClear 0x10C +#define OHCI1394_PhyReqFilterHiSet 0x110 +#define OHCI1394_PhyReqFilterHiClear 0x114 +#define OHCI1394_PhyReqFilterLoSet 0x118 +#define OHCI1394_PhyReqFilterLoClear 0x11C +#define OHCI1394_PhyUpperBound 0x120 + +#define OHCI1394_AsReqTrContextBase 0x180 +#define OHCI1394_AsReqTrContextControlSet 0x180 +#define OHCI1394_AsReqTrContextControlClear 0x184 +#define OHCI1394_AsReqTrCommandPtr 0x18C + +#define OHCI1394_AsRspTrContextBase 0x1A0 +#define OHCI1394_AsRspTrContextControlSet 0x1A0 +#define OHCI1394_AsRspTrContextControlClear 0x1A4 +#define OHCI1394_AsRspTrCommandPtr 0x1AC + +#define OHCI1394_AsReqRcvContextBase 0x1C0 +#define OHCI1394_AsReqRcvContextControlSet 0x1C0 +#define OHCI1394_AsReqRcvContextControlClear 0x1C4 +#define OHCI1394_AsReqRcvCommandPtr 0x1CC + +#define OHCI1394_AsRspRcvContextBase 0x1E0 +#define OHCI1394_AsRspRcvContextControlSet 0x1E0 +#define OHCI1394_AsRspRcvContextControlClear 0x1E4 +#define OHCI1394_AsRspRcvCommandPtr 0x1EC + +/* Isochronous transmit registers */ +#define OHCI1394_IsoXmitContextBase (n) (0x200 + 16 * (n)) +#define OHCI1394_IsoXmitContextControlSet (n) (0x200 + 16 * (n)) +#define OHCI1394_IsoXmitContextControlClear (n) (0x204 + 16 * (n)) +#define OHCI1394_IsoXmitCommandPtr (n) (0x20C + 16 * (n)) + +/* Isochronous receive registers */ +#define OHCI1394_IsoRcvContextBase (n) (0x400 + 32 * (n)) +#define OHCI1394_IsoRcvContextControlSet (n) (0x400 + 32 * (n)) +#define OHCI1394_IsoRcvContextControlClear (n) (0x404 + 32 * (n)) +#define OHCI1394_IsoRcvCommandPtr (n) (0x40C + 32 * (n)) +#define OHCI1394_IsoRcvContextMatch (n) (0x410 + 32 * (n)) + +/* Interrupts Mask/Events */ +#define OHCI1394_reqTxComplete 0x00000001 +#define OHCI1394_respTxComplete 0x00000002 +#define OHCI1394_ARRQ 0x00000004 +#define OHCI1394_ARRS 0x00000008 +#define OHCI1394_RQPkt 0x00000010 +#define OHCI1394_RSPkt 0x00000020 +#define OHCI1394_isochTx 0x00000040 +#define OHCI1394_isochRx 0x00000080 +#define OHCI1394_postedWriteErr 0x00000100 +#define OHCI1394_lockRespErr 0x00000200 +#define OHCI1394_selfIDComplete 0x00010000 +#define OHCI1394_busReset 0x00020000 +#define OHCI1394_phy 0x00080000 +#define OHCI1394_cycleSynch 0x00100000 +#define OHCI1394_cycle64Seconds 0x00200000 +#define OHCI1394_cycleLost 0x00400000 +#define OHCI1394_cycleInconsistent 0x00800000 +#define OHCI1394_unrecoverableError 0x01000000 +#define OHCI1394_cycleTooLong 0x02000000 +#define OHCI1394_phyRegRcvd 0x04000000 +#define OHCI1394_masterIntEnable 0x80000000 + +#define OHCI1394_evt_no_status 0x0 +#define OHCI1394_evt_long_packet 0x2 +#define OHCI1394_evt_missing_ack 0x3 +#define OHCI1394_evt_underrun 0x4 +#define OHCI1394_evt_overrun 0x5 +#define OHCI1394_evt_descriptor_read 0x6 +#define OHCI1394_evt_data_read 0x7 +#define OHCI1394_evt_data_write 0x8 +#define OHCI1394_evt_bus_reset 0x9 +#define OHCI1394_evt_timeout 0xa +#define OHCI1394_evt_tcode_err 0xb +#define OHCI1394_evt_reserved_b 0xc +#define OHCI1394_evt_reserved_c 0xd +#define OHCI1394_evt_unknown 0xe +#define OHCI1394_evt_flushed 0xf + +#define OHCI1394_phy_tcode 0xe + +#endif /* __fw_ohci_h */
drivers/firewire/fw-ohci.c new file +1896 -0
1,896 lines not on this page · raw message
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
PATCH 5/6 firewire: SBP-2 highlevel driver
--- drivers/firewire/fw-sbp2.c | 1165 +++++++++++++++++++++++++++++++++++++ 1 file changed, 1165 insertions(+)
drivers/firewire/fw-sbp2.c new file +1165 -0
@@ -0,0 +1,1165 @@ +/* -*- c-basic-offset: 8 -*- +* fw-spb2.c -- SBP2 driver (SCSI over IEEE1394) +* +* Copyright (C) 2005-2007 Kristian Hoegsberg <[email protected]> +* +* 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. +*/ + +/* The basic structure of this driver is based the old storage driver, +* drivers/ieee1394/sbp2.c, originally written by +* James Goodwin <[email protected]> +* with later contributions and ongoing maintenance from +* Ben Collins <[email protected]>, +* Stefan Richter <[email protected]> +* and many others. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mod_devicetable.h> +#include <linux/device.h> +#include <linux/scatterlist.h> +#include <linux/dma-mapping.h> +#include <linux/timer.h> + +#include <scsi/scsi.h> +#include <scsi/scsi_cmnd.h> +#include <scsi/scsi_dbg.h> +#include <scsi/scsi_device.h> +#include <scsi/scsi_host.h> + +#include "fw-transaction.h" +#include "fw-topology.h" +#include "fw-device.h" + +/* I don't know why the SCSI stack doesn't define something like this... */ +typedef void (*scsi_done_fn_t ) (struct scsi_cmnd *); + +static const char sbp2_driver_name[] ="sbp2" ; + +struct sbp2_device { +struct kref kref; +struct fw_unit *unit; +struct fw_address_handler address_handler; +struct list_head orb_list; +u64 management_agent_address; +u64 command_block_agent_address; +u32 workarounds; +int login_id; + +/* We cache these addresses and only update them once we've +* logged in or reconnected to the sbp2 device. That way, any +* IO to the device will automatically fail and get retried if +* it happens in a window where the device is not ready to +* handle it (e.g. after a bus reset but before we reconnect). */ +int node_id; +int address_high; +int generation; + +int retries; +struct delayed_work work; +struct Scsi_Host *scsi_host; +}; + +#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000 +#define SBP2_MAX_SECTORS 255/* Max sectors supported */ +#define SBP2_ORB_TIMEOUT 2000/* Timeout in ms */ + +#define SBP2_ORB_NULL 0x80000000 + +#define SBP2_DIRECTION_TO_MEDIA 0x0 +#define SBP2_DIRECTION_FROM_MEDIA 0x1 + +/* Unit directory keys */ +#define SBP2_COMMAND_SET_SPECIFIER 0x38 +#define SBP2_COMMAND_SET 0x39 +#define SBP2_COMMAND_SET_REVISION 0x3b +#define SBP2_FIRMWARE_REVISION 0x3c + +/* Flags for detected oddities and brokeness */ +#define SBP2_WORKAROUND_128K_MAX_TRANS 0x1 +#define SBP2_WORKAROUND_INQUIRY_36 0x2 +#define SBP2_WORKAROUND_MODE_SENSE_8 0x4 +#define SBP2_WORKAROUND_FIX_CAPACITY 0x8 +#define SBP2_WORKAROUND_OVERRIDE 0x100 + +/* Management orb opcodes */ +#define SBP2_LOGIN_REQUEST 0x0 +#define SBP2_QUERY_LOGINS_REQUEST 0x1 +#define SBP2_RECONNECT_REQUEST 0x3 +#define SBP2_SET_PASSWORD_REQUEST 0x4 +#define SBP2_LOGOUT_REQUEST 0x7 +#define SBP2_ABORT_TASK_REQUEST 0xb +#define SBP2_ABORT_TASK_SET 0xc +#define SBP2_LOGICAL_UNIT_RESET 0xe +#define SBP2_TARGET_RESET_REQUEST 0xf + +/* Offsets for command block agent registers */ +#define SBP2_AGENT_STATE 0x00 +#define SBP2_AGENT_RESET 0x04 +#define SBP2_ORB_POINTER 0x08 +#define SBP2_DOORBELL 0x10 +#define SBP2_UNSOLICITED_STATUS_ENABLE 0x14 + +/* Status write response codes */ +#define SBP2_STATUS_REQUEST_COMPLETE 0x0 +#define SBP2_STATUS_TRANSPORT_FAILURE 0x1 +#define SBP2_STATUS_ILLEGAL_REQUEST 0x2 +#define SBP2_STATUS_VENDOR_DEPENDENT 0x3 + +#define status_get_orb_high (v) ((v).status & 0xffff) +#define status_get_sbp_status (v) (((v).status >> 16) & 0xff) +#define status_get_len (v) (((v).status >> 24) & 0x07) +#define status_get_dead (v) (((v).status >> 27) & 0x01) +#define status_get_response (v) (((v).status >> 28) & 0x03) +#define status_get_source (v) (((v).status >> 30) & 0x03) +#define status_get_orb_low (v) ((v).orb_low) +#define status_get_data (v) ((v).data) + +struct sbp2_status { +u32 status; +u32 orb_low; +u8 data[24 ]; +}; + +struct sbp2_pointer { +u32 high; +u32 low; +}; + +struct sbp2_orb { +struct fw_transaction t; +dma_addr_t request_bus; +int rcode; +struct sbp2_pointer pointer; +void (*callback) (struct sbp2_orb * orb,struct sbp2_status * status); +struct list_head link; +}; + +#define management_orb_lun (v) ((v)) +#define management_orb_function (v) ((v) << 16) +#define management_orb_reconnect (v) ((v) << 20) +#define management_orb_exclusive ((1) << 28) +#define management_orb_request_format (v) ((v) << 29) +#define management_orb_notify ((1) << 31) + +#define management_orb_response_length (v) ((v)) +#define management_orb_password_length (v) ((v) << 16) + +struct sbp2_management_orb { +struct sbp2_orb base; +struct { +struct sbp2_pointer password; +struct sbp2_pointer response; +u32 misc; +u32 length; +struct sbp2_pointer status_fifo; + } request; +__be32 response[4 ]; +dma_addr_t response_bus; +struct completion done; +struct sbp2_status status; +}; + +#define login_response_get_login_id (v) ((v).misc & 0xffff) +#define login_response_get_length (v) (((v).misc >> 16) & 0xffff) + +struct sbp2_login_response { +u32 misc; +struct sbp2_pointer command_block_agent; +u32 reconnect_hold; +}; + +#define command_orb_data_size (v) ((v)) +#define command_orb_page_size (v) ((v) << 16) +#define command_orb_page_table_present ((1) << 19) +#define command_orb_max_payload (v) ((v) << 20) +#define command_orb_speed (v) ((v) << 24) +#define command_orb_direction (v) ((v) << 27) +#define command_orb_request_format (v) ((v) << 29) +#define command_orb_notify ((1) << 31) + +struct sbp2_command_orb { +struct sbp2_orb base; +struct { +struct sbp2_pointer next; +struct sbp2_pointer data_descriptor; +u32 misc; +u8 command_block[12 ]; + } request; +struct scsi_cmnd *cmd; +scsi_done_fn_t done; +struct fw_unit *unit; + +struct sbp2_pointer page_table[SG_ALL ]; +dma_addr_t page_table_bus; +dma_addr_t request_buffer_bus; +}; + +/* +* List of devices with known bugs. +* +* The firmware_revision field, masked with 0xffff00, is the best +* indicator for the type of bridge chip of a device. It yields a few +* false positives but this did not break correctly behaving devices +* so far. We use ~0 as a wildcard, since the 24 bit values we get +* from the config rom can never match that. +*/ +static const struct { +u32 firmware_revision; +u32 model; +unsigned workarounds; +} sbp2_workarounds_table[] = { +/* DViCO Momobay CX-1 with TSB42AA9 bridge */ { + .firmware_revision =0x002800 , + .model =0x001010 , + .workarounds =SBP2_WORKAROUND_INQUIRY_36 | +SBP2_WORKAROUND_MODE_SENSE_8 , + }, +/* Initio bridges, actually only needed for some older ones */ { + .firmware_revision =0x000200 , + .model = ~0 , + .workarounds =SBP2_WORKAROUND_INQUIRY_36 , + }, +/* Symbios bridge */ { + .firmware_revision =0xa0b800 , + .model = ~0 , + .workarounds =SBP2_WORKAROUND_128K_MAX_TRANS , + }, +/* There are iPods (2nd gen, 3rd gen) with model_id == 0, but +* these iPods do not feature the read_capacity bug according +* to one report. Read_capacity behaviour as well as model_id +* could change due to Apple-supplied firmware updates though. */ +/* iPod 4th generation. */ { + .firmware_revision =0x0a2700 , + .model =0x000021 , + .workarounds =SBP2_WORKAROUND_FIX_CAPACITY , + }, +/* iPod mini */ { + .firmware_revision =0x0a2700 , + .model =0x000023 , + .workarounds =SBP2_WORKAROUND_FIX_CAPACITY , + }, +/* iPod Photo */ { + .firmware_revision =0x0a2700 , + .model =0x00007e , + .workarounds =SBP2_WORKAROUND_FIX_CAPACITY , + } +}; + +static void +sbp2_status_write (struct fw_card *card,struct fw_request *request, +int tcode,int destination,int source, +int generation,int speed, +unsigned long long offset, +void *payload,size_t length,void *callback_data) +{ +struct sbp2_device *sd = callback_data; +struct sbp2_orb *orb; +struct sbp2_status status; +size_t header_size; +unsigned long flags; + +if (tcode !=TCODE_WRITE_BLOCK_REQUEST || + length ==0 || length >sizeof status) { +fw_send_response (card, request,RCODE_TYPE_ERROR ); +return ; + } + + header_size =min (length,2 *sizeof (u32)); +fw_memcpy_from_be32 (&status, payload, header_size); +if (length > header_size) +memcpy (status.data, payload +8 , length - header_size); +if (status_get_source (status) ==2 ||status_get_source (status) ==3 ) { +fw_notify ("non-orb related status write, not handled\n" ); +fw_send_response (card, request,RCODE_COMPLETE ); +return ; + } + +/* Lookup the orb corresponding to this status write. */ +spin_lock_irqsave (&card->lock, flags); +list_for_each_entry (orb, &sd->orb_list, link) { +if (status_get_orb_high (status) ==0 && +status_get_orb_low (status) == orb->request_bus && + orb->rcode ==RCODE_COMPLETE ) { +list_del (&orb->link); +break ; + } + } +spin_unlock_irqrestore (&card->lock, flags); + +if (&orb->link != &sd->orb_list) + orb->callback (orb, &status); +else +fw_error ("status write for unknown orb\n" ); + +fw_send_response (card, request,RCODE_COMPLETE ); +} + +static void +complete_transaction (struct fw_card *card,int rcode, +void *payload,size_t length,void *data) +{ +struct sbp2_orb *orb = data; +unsigned long flags; + + orb->rcode = rcode; +if (rcode !=RCODE_COMPLETE ) { +spin_lock_irqsave (&card->lock, flags); +list_del (&orb->link); +spin_unlock_irqrestore (&card->lock, flags); + orb->callback (orb,NULL ); + } +} + +static void +sbp2_send_orb (struct sbp2_orb *orb,struct fw_unit *unit, +int node_id,int generation,u64 offset) +{ +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_device *sd = unit->device.driver_data; +unsigned long flags; + + orb->pointer.high =0 ; + orb->pointer.low = orb->request_bus; +fw_memcpy_to_be32 (&orb->pointer, &orb->pointer,sizeof orb->pointer); + +spin_lock_irqsave (&device->card->lock, flags); +list_add_tail (&orb->link, &sd->orb_list); +spin_unlock_irqrestore (&device->card->lock, flags); + +fw_send_request (device->card, &orb->t,TCODE_WRITE_BLOCK_REQUEST , + node_id, generation, + device->node->max_speed, offset, + &orb->pointer,sizeof orb->pointer, + complete_transaction, orb); +} + +static int sbp2_cancel_orbs (struct fw_unit *unit) +{ +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_device *sd = unit->device.driver_data; +struct sbp2_orb *orb, *next; +struct list_head list; +unsigned long flags; +int retval = -ENOENT ; + +INIT_LIST_HEAD (&list); +spin_lock_irqsave (&device->card->lock, flags); +list_splice_init (&sd->orb_list, &list); +spin_unlock_irqrestore (&device->card->lock, flags); + +list_for_each_entry_safe (orb, next, &list, link) { + retval =0 ; +if (fw_cancel_transaction (device->card, &orb->t) ==0 ) +continue ; + + orb->rcode =RCODE_CANCELLED ; + orb->callback (orb,NULL ); + } + +return retval; +} + +static void +complete_management_orb (struct sbp2_orb *base_orb,struct sbp2_status *status) +{ +struct sbp2_management_orb *orb = + (struct sbp2_management_orb *)base_orb; + +if (status) +memcpy (&orb->status, status,sizeof *status); +complete (&orb->done); +} + +static int +sbp2_send_management_orb (struct fw_unit *unit,int node_id,int generation, +int function,int lun,void *response) +{ +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_device *sd = unit->device.driver_data; +struct sbp2_management_orb *orb; +int retval = -ENOMEM ; + + orb =kzalloc (sizeof *orb,GFP_ATOMIC ); +if (orb ==NULL ) +return -ENOMEM ; + +/* The sbp2 device is going to send a block read request to +* read out the request from host memory, so map it for +* dma. */ + orb->base.request_bus = +dma_map_single (device->card->device, &orb->request, +sizeof orb->request,DMA_TO_DEVICE ); +if (dma_mapping_error (orb->base.request_bus)) + goto out; + + orb->response_bus = +dma_map_single (device->card->device, &orb->response, +sizeof orb->response,DMA_FROM_DEVICE ); +if (dma_mapping_error (orb->response_bus)) + goto out; + + orb->request.response.high =0 ; + orb->request.response.low = orb->response_bus; + + orb->request.misc = + management_orb_notify | +management_orb_function (function) | +management_orb_lun (lun); + orb->request.length = +management_orb_response_length (sizeof orb->response); + + orb->request.status_fifo.high = sd->address_handler.offset >>32 ; + orb->request.status_fifo.low = sd->address_handler.offset; + +/* FIXME: Yeah, ok this isn't elegant, we hardwire exclusive +* login and 1 second reconnect time. The reconnect setting +* is probably fine, but the exclusive login should be an +* option. */ +if (function ==SBP2_LOGIN_REQUEST ) { + orb->request.misc |= + management_orb_exclusive | +management_orb_reconnect (0 ); + } + +fw_memcpy_to_be32 (&orb->request, &orb->request,sizeof orb->request); + +init_completion (&orb->done); + orb->base.callback = complete_management_orb; + +sbp2_send_orb (&orb->base, unit, + node_id, generation, sd->management_agent_address); + +wait_for_completion_timeout (&orb->done, +msecs_to_jiffies (SBP2_ORB_TIMEOUT )); + + retval = -EIO ; +if (sbp2_cancel_orbs (unit) ==0 ) { +fw_error ("orb reply timed out, rcode=0x%02x\n" , + orb->base.rcode); + goto out; + } + +if (orb->base.rcode !=RCODE_COMPLETE ) { +fw_error ("management write failed, rcode 0x%02x\n" , + orb->base.rcode); + goto out; + } + +if (status_get_response (orb->status) !=0 || +status_get_sbp_status (orb->status) !=0 ) { +fw_error ("error status: %d:%d\n" , +status_get_response (orb->status), +status_get_sbp_status (orb->status)); + goto out; + } + + retval =0 ; + out: +dma_unmap_single (device->card->device, orb->base.request_bus, +sizeof orb->request,DMA_TO_DEVICE ); +dma_unmap_single (device->card->device, orb->response_bus, +sizeof orb->response,DMA_FROM_DEVICE ); + +if (response) +fw_memcpy_from_be32 (response, + orb->response,sizeof orb->response); +kfree (orb); + +return retval; +} + +static void +complete_agent_reset_write (struct fw_card *card,int rcode, +void *payload,size_t length,void *data) +{ +struct fw_transaction *t = data; + +kfree (t); +} + +static int sbp2_agent_reset (struct fw_unit *unit) +{ +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_device *sd = unit->device.driver_data; +struct fw_transaction *t; +static u32 zero; + + t =kzalloc (sizeof *t,GFP_ATOMIC ); +if (t ==NULL ) +return -ENOMEM ; + +fw_send_request (device->card, t,TCODE_WRITE_QUADLET_REQUEST , + sd->node_id, sd->generation,SCODE_400 , + sd->command_block_agent_address +SBP2_AGENT_RESET , + &zero,sizeof zero, complete_agent_reset_write, t); + +return 0 ; +} + +static int add_scsi_devices (struct fw_unit *unit); +static void remove_scsi_devices (struct fw_unit *unit); +static void sbp2_reconnect (struct work_struct *work); + +static void +release_sbp2_device (struct kref *kref) +{ + struct sbp2_device *sd = container_of(kref, struct sbp2_device, kref); + +sbp2_send_management_orb (sd->unit, sd->node_id, sd->generation, +SBP2_LOGOUT_REQUEST , sd->login_id,NULL ); + +remove_scsi_devices (sd->unit); + +fw_core_remove_address_handler (&sd->address_handler); +fw_notify ("removed sbp2 unit %s\n" , sd->unit->device.bus_id); +put_device (&sd->unit->device); +kfree (sd); +} + +static void sbp2_login (struct work_struct *work) +{ +struct sbp2_device *sd = + container_of(work, struct sbp2_device, work.work); +struct fw_unit *unit = sd->unit; +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_login_response response; +int generation, node_id, local_node_id, lun, retval; + +/* FIXME: Make this work for multi-lun devices. */ + lun =0 ; + + generation = device->card->generation; + node_id = device->node->node_id; + local_node_id = device->card->local_node->node_id; + +if (sbp2_send_management_orb (unit, node_id, generation, +SBP2_LOGIN_REQUEST , lun, &response) <0 ) { +if (sd->retries++ <5 ) { +schedule_delayed_work (&sd->work,DIV_ROUND_UP (HZ ,5 )); + }else { +fw_error ("failed to login to %s\n" , + unit->device.bus_id); +remove_scsi_devices (unit); +kref_put (&sd->kref, release_sbp2_device); + } +return ; + } + + sd->generation = generation; + sd->node_id = node_id; + sd->address_high = local_node_id <<16 ; + +/* Get command block agent offset and login id. */ + sd->command_block_agent_address = + ((u64) (response.command_block_agent.high &0xffff ) <<32 ) | + response.command_block_agent.low; + sd->login_id =login_response_get_login_id (response); + +fw_notify ("logged in to sbp2 unit %s (%d retries)\n" , + unit->device.bus_id, sd->retries); +fw_notify (" - management_agent_address: 0x%012llx\n" , + (unsigned long long ) sd->management_agent_address); +fw_notify (" - command_block_agent_address: 0x%012llx\n" , + (unsigned long long ) sd->command_block_agent_address); +fw_notify (" - status write address: 0x%012llx\n" , + (unsigned long long ) sd->address_handler.offset); + +#if 0 +/* FIXME: The linux1394 sbp2 does this last step. */ +sbp2_set_busy_timeout (scsi_id); +#endif + +PREPARE_DELAYED_WORK (&sd->work, sbp2_reconnect); +sbp2_agent_reset (unit); + + retval =add_scsi_devices (unit); +if (retval <0 ) { +sbp2_send_management_orb (unit, sd->node_id, sd->generation, +SBP2_LOGOUT_REQUEST , sd->login_id, +NULL ); +/* Set this back to sbp2_login so we fall back and +* retry login on bus reset. */ +PREPARE_DELAYED_WORK (&sd->work, sbp2_login); + } +kref_put (&sd->kref, release_sbp2_device); +} + +static int sbp2_probe (struct device *dev) +{ +struct fw_unit *unit =fw_unit (dev); +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_device *sd; +struct fw_csr_iterator ci; +int i, key, value; +u32 model, firmware_revision; + + sd =kzalloc (sizeof *sd,GFP_KERNEL ); +if (sd ==NULL ) +return -ENOMEM ; + + unit->device.driver_data = sd; + sd->unit = unit; +INIT_LIST_HEAD (&sd->orb_list); +kref_init (&sd->kref); + + sd->address_handler.length =0x100 ; + sd->address_handler.address_callback = sbp2_status_write; + sd->address_handler.callback_data = sd; + +if (fw_core_add_address_handler (&sd->address_handler, + &fw_high_memory_region) <0 ) { +kfree (sd); +return -EBUSY ; + } + +if (fw_device_enable_phys_dma (device) <0 ) { +fw_core_remove_address_handler (&sd->address_handler); +kfree (sd); +return -EBUSY ; + } + +/* Scan unit directory to get management agent address, +* firmware revison and model. Initialize firmware_revision +* and model to values that wont match anything in our table. */ + firmware_revision =0xff000000 ; + model =0xff000000 ; +fw_csr_iterator_init (&ci, unit->directory); +while (fw_csr_iterator_next (&ci, &key, &value)) { +switch (key) { +case CSR_DEPENDENT_INFO |CSR_OFFSET : + sd->management_agent_address = +0xfffff0000000ULL +4 * value; +break ; +case SBP2_FIRMWARE_REVISION : + firmware_revision = value; +break ; +case CSR_MODEL : + model = value; +break ; + } + } + +for (i =0 ; i <ARRAY_SIZE (sbp2_workarounds_table); i++) { +if (sbp2_workarounds_table[i].firmware_revision != + (firmware_revision &0xffffff00 )) +continue ; +if (sbp2_workarounds_table[i].model != model && + sbp2_workarounds_table[i].model != ~0 ) +continue ; + sd->workarounds |= sbp2_workarounds_table[i].workarounds; +break ; + } + +if (sd->workarounds) +fw_notify ("Workarounds for node %s: 0x%x " +"(firmware_revision 0x%06x, model_id 0x%06x)\n" , + unit->device.bus_id, + sd->workarounds, firmware_revision, model); + +get_device (&unit->device); + +/* We schedule work to do the login so we can easily +* reschedule retries. Always get the ref before scheduling +* work.*/ +INIT_DELAYED_WORK (&sd->work, sbp2_login); +if (schedule_delayed_work (&sd->work,0 )) +kref_get (&sd->kref); + +return 0 ; +} + +static int sbp2_remove (struct device *dev) +{ +struct fw_unit *unit =fw_unit (dev); +struct sbp2_device *sd = unit->device.driver_data; + +kref_put (&sd->kref, release_sbp2_device); + +return 0 ; +} + +static void sbp2_reconnect (struct work_struct *work) +{ +struct sbp2_device *sd = + container_of(work, struct sbp2_device, work.work); +struct fw_unit *unit = sd->unit; +struct fw_device *device =fw_device (unit->device.parent); +int generation, node_id, local_node_id; + + generation = device->card->generation; + node_id = device->node->node_id; + local_node_id = device->card->local_node->node_id; + +if (sbp2_send_management_orb (unit, node_id, generation, +SBP2_RECONNECT_REQUEST , + sd->login_id,NULL ) <0 ) { +if (sd->retries++ >=5 ) { +fw_error ("failed to reconnect to %s\n" , + unit->device.bus_id); +/* Fall back and try to log in again. */ + sd->retries =0 ; +PREPARE_DELAYED_WORK (&sd->work, sbp2_login); + } +schedule_delayed_work (&sd->work,DIV_ROUND_UP (HZ ,5 )); +return ; + } + + sd->generation = generation; + sd->node_id = node_id; + sd->address_high = local_node_id <<16 ; + +fw_notify ("reconnected to unit %s (%d retries)\n" , + unit->device.bus_id, sd->retries); +sbp2_agent_reset (unit); +sbp2_cancel_orbs (unit); +kref_put (&sd->kref, release_sbp2_device); +} + +static void sbp2_update (struct fw_unit *unit) +{ +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_device *sd = unit->device.driver_data; + + sd->retries =0 ; +fw_device_enable_phys_dma (device); +if (schedule_delayed_work (&sd->work,0 )) +kref_get (&sd->kref); +} + +#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e +#define SBP2_SW_VERSION_ENTRY 0x00010483 + +static const struct fw_device_id sbp2_id_table[] = { + { + .match_flags =FW_MATCH_SPECIFIER_ID |FW_MATCH_VERSION , + .specifier_id =SBP2_UNIT_SPEC_ID_ENTRY , + .version =SBP2_SW_VERSION_ENTRY , + }, + { } +}; + +static struct fw_driver sbp2_driver = { + .driver = { + .owner =THIS_MODULE , + .name = sbp2_driver_name, + .bus = &fw_bus_type, + .probe = sbp2_probe, + .remove = sbp2_remove, + }, + .update = sbp2_update, + .id_table = sbp2_id_table, +}; + +static unsigned int +sbp2_status_to_sense_data (u8 *sbp2_status,u8 *sense_data) +{ +int sam_status; + + sense_data[0 ] =0x70 ; + sense_data[1 ] =0x0 ; + sense_data[2 ] = sbp2_status[1 ]; + sense_data[3 ] = sbp2_status[4 ]; + sense_data[4 ] = sbp2_status[5 ]; + sense_data[5 ] = sbp2_status[6 ]; + sense_data[6 ] = sbp2_status[7 ]; + sense_data[7 ] =10 ; + sense_data[8 ] = sbp2_status[8 ]; + sense_data[9 ] = sbp2_status[9 ]; + sense_data[10 ] = sbp2_status[10 ]; + sense_data[11 ] = sbp2_status[11 ]; + sense_data[12 ] = sbp2_status[2 ]; + sense_data[13 ] = sbp2_status[3 ]; + sense_data[14 ] = sbp2_status[12 ]; + sense_data[15 ] = sbp2_status[13 ]; + + sam_status = sbp2_status[0 ] &0x3f ; + +switch (sam_status) { +case SAM_STAT_GOOD : +case SAM_STAT_CHECK_CONDITION : +case SAM_STAT_CONDITION_MET : +case SAM_STAT_BUSY : +case SAM_STAT_RESERVATION_CONFLICT : +case SAM_STAT_COMMAND_TERMINATED : +return DID_OK <<16 | sam_status; + +default : +return DID_ERROR <<16 ; + } +} + +static void +complete_command_orb (struct sbp2_orb *base_orb,struct sbp2_status *status) +{ +struct sbp2_command_orb *orb = (struct sbp2_command_orb *)base_orb; +struct fw_unit *unit = orb->unit; +struct fw_device *device =fw_device (unit->device.parent); +struct scatterlist *sg; +int result; + +if (status !=NULL ) { +if (status_get_dead (*status)) +sbp2_agent_reset (unit); + +switch (status_get_response (*status)) { +case SBP2_STATUS_REQUEST_COMPLETE : + result =DID_OK <<16 ; +break ; +case SBP2_STATUS_TRANSPORT_FAILURE : + result =DID_BUS_BUSY <<16 ; +break ; +case SBP2_STATUS_ILLEGAL_REQUEST : +case SBP2_STATUS_VENDOR_DEPENDENT : +default : + result =DID_ERROR <<16 ; +break ; + } + +if (result ==DID_OK <<16 &&status_get_len (*status) >1 ) + result =sbp2_status_to_sense_data (status_get_data (*status), + orb->cmd->sense_buffer); + }else { +/* If the orb completes with status == NULL, something +* went wrong, typically a bus reset happened mid-orb +* or when sending the write (less likely). */ + result =DID_BUS_BUSY <<16 ; + } + +dma_unmap_single (device->card->device, orb->base.request_bus, +sizeof orb->request,DMA_TO_DEVICE ); + +if (orb->cmd->use_sg >0 ) { + sg = (struct scatterlist *)orb->cmd->request_buffer; +dma_unmap_sg (device->card->device, sg, orb->cmd->use_sg, + orb->cmd->sc_data_direction); + } + +if (orb->page_table_bus !=0 ) +dma_unmap_single (device->card->device, orb->page_table_bus, +sizeof orb->page_table_bus,DMA_TO_DEVICE ); + +if (orb->request_buffer_bus !=0 ) +dma_unmap_single (device->card->device, orb->request_buffer_bus, +sizeof orb->request_buffer_bus, +DMA_FROM_DEVICE ); + + orb->cmd->result = result; + orb->done (orb->cmd); +kfree (orb); +} + +static void sbp2_command_orb_map_scatterlist (struct sbp2_command_orb *orb) +{ +struct fw_unit *unit = + (struct fw_unit *)orb->cmd->device->host->hostdata[0 ]; +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_device *sd = unit->device.driver_data; +struct scatterlist *sg; +int sg_len, l, i, j, count; +size_t size; +dma_addr_t sg_addr; + + sg = (struct scatterlist *)orb->cmd->request_buffer; + count =dma_map_sg (device->card->device, sg, orb->cmd->use_sg, + orb->cmd->sc_data_direction); + +/* Handle the special case where there is only one element in +* the scatter list by converting it to an immediate block +* request. This is also a workaround for broken devices such +* as the second generation iPod which doesn't support page +* tables. */ +if (count ==1 &&sg_dma_len (sg) <SBP2_MAX_SG_ELEMENT_LENGTH ) { + orb->request.data_descriptor.high = sd->address_high; + orb->request.data_descriptor.low =sg_dma_address (sg); + orb->request.misc |= +command_orb_data_size (sg_dma_len (sg)); +return ; + } + +/* Convert the scatterlist to an sbp2 page table. If any +* scatterlist entries are too big for sbp2 we split the as we go. */ +for (i =0 , j =0 ; i < count; i++) { + sg_len =sg_dma_len (sg + i); + sg_addr =sg_dma_address (sg + i); +while (sg_len) { + l =min (sg_len,SBP2_MAX_SG_ELEMENT_LENGTH ); + orb->page_table[j].low = sg_addr; + orb->page_table[j].high = (l <<16 ); + sg_addr += l; + sg_len -= l; + j++; + } + } + + size =sizeof orb->page_table[0 ] * j; + +/* The data_descriptor pointer is the one case where we need +* to fill in the node ID part of the address. All other +* pointers assume that the data referenced reside on the +* initiator (i.e. us), but data_descriptor can refer to data +* on other nodes so we need to put our ID in descriptor.high. */ + + orb->page_table_bus = +dma_map_single (device->card->device, orb->page_table, + size,DMA_TO_DEVICE ); + orb->request.data_descriptor.high = sd->address_high; + orb->request.data_descriptor.low = orb->page_table_bus; + orb->request.misc |= + command_orb_page_table_present | +command_orb_data_size (j); + +fw_memcpy_to_be32 (orb->page_table, orb->page_table, size); +} + +static void sbp2_command_orb_map_buffer (struct sbp2_command_orb *orb) +{ +struct fw_unit *unit = + (struct fw_unit *)orb->cmd->device->host->hostdata[0 ]; +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_device *sd = unit->device.driver_data; + +/* As for map_scatterlist, we need to fill in the high bits of +* the data_descriptor pointer. */ + + orb->request_buffer_bus = +dma_map_single (device->card->device, + orb->cmd->request_buffer, + orb->cmd->request_bufflen, + orb->cmd->sc_data_direction); + orb->request.data_descriptor.high = sd->address_high; + orb->request.data_descriptor.low = orb->request_buffer_bus; + orb->request.misc |= +command_orb_data_size (orb->cmd->request_bufflen); +} + +/* SCSI stack integration */ + +static int sbp2_scsi_queuecommand (struct scsi_cmnd *cmd,scsi_done_fn_t done) +{ +struct fw_unit *unit = (struct fw_unit *)cmd->device->host->hostdata[0 ]; +struct fw_device *device =fw_device (unit->device.parent); +struct sbp2_device *sd = unit->device.driver_data; +struct sbp2_command_orb *orb; + +/* Bidirectional commands are not yet implemented, and unknown +* transfer direction not handled. */ +if (cmd->sc_data_direction ==DMA_BIDIRECTIONAL ) { +fw_error ("Cannot handle DMA_BIDIRECTIONAL - rejecting command" ); + goto fail_alloc; + } + + orb =kzalloc (sizeof *orb,GFP_ATOMIC ); +if (orb ==NULL ) { +fw_notify ("failed to alloc orb\n" ); + goto fail_alloc; + } + +/* Initialize rcode to something not RCODE_COMPLETE. */ + orb->base.rcode =-1 ; + orb->base.request_bus = +dma_map_single (device->card->device, &orb->request, +sizeof orb->request,DMA_TO_DEVICE ); +if (dma_mapping_error (orb->base.request_bus)) + goto fail_mapping; + + orb->unit = unit; + orb->done = done; + orb->cmd = cmd; + + orb->request.next.high =SBP2_ORB_NULL ; + orb->request.next.low =0x0 ; +/* At speed 100 we can do 512 bytes per packet, at speed 200, +* 1024 bytes per packet etc. The SBP-2 max_payload field +* specifies the max payload size as 2 ^ (max_payload + 2), so +* if we set this to max_speed + 7, we get the right value. */ + orb->request.misc = +command_orb_max_payload (device->node->max_speed +7 ) | +command_orb_speed (device->node->max_speed) | + command_orb_notify; + +if (cmd->sc_data_direction ==DMA_FROM_DEVICE ) + orb->request.misc |= +command_orb_direction (SBP2_DIRECTION_FROM_MEDIA ); +else if (cmd->sc_data_direction ==DMA_TO_DEVICE ) + orb->request.misc |= +command_orb_direction (SBP2_DIRECTION_TO_MEDIA ); + +if (cmd->use_sg) { +sbp2_command_orb_map_scatterlist (orb); + }else if (cmd->request_bufflen >SBP2_MAX_SG_ELEMENT_LENGTH ) { +/* FIXME: Need to split this into a sg list... but +* could we get the scsi or blk layer to do that by +* reporting our max supported block size? */ +fw_error ("command > 64k\n" ); + goto fail_bufflen; + }else if (cmd->request_bufflen >0 ) { +sbp2_command_orb_map_buffer (orb); + } + +fw_memcpy_to_be32 (&orb->request, &orb->request,sizeof orb->request); + +memset (orb->request.command_block, +0 ,sizeof orb->request.command_block); +memcpy (orb->request.command_block, cmd->cmnd,COMMAND_SIZE (*cmd->cmnd)); + + orb->base.callback = complete_command_orb; + +sbp2_send_orb (&orb->base, unit, sd->node_id, sd->generation, + sd->command_block_agent_address +SBP2_ORB_POINTER ); + +return 0 ; + + fail_bufflen: +dma_unmap_single (device->card->device, orb->base.request_bus, +sizeof orb->request,DMA_TO_DEVICE ); + fail_mapping: +kfree (orb); + fail_alloc: + cmd->result =DID_ERROR <<16 ; +done (cmd); +return 0 ; +} + +static int sbp2_scsi_slave_alloc (struct scsi_device *sdev) +{ +struct fw_unit *unit = (struct fw_unit *)sdev->host->hostdata[0 ]; +struct sbp2_device *sd = unit->device.driver_data; + + sdev->allow_restart =1 ; + +if (sd->workarounds &SBP2_WORKAROUND_INQUIRY_36 ) + sdev->inquiry_len =36 ; +return 0 ; +} + +static int sbp2_scsi_slave_configure (struct scsi_device *sdev) +{ +struct fw_unit *unit = (struct fw_unit *)sdev->host->hostdata[0 ]; +struct sbp2_device *sd = unit->device.driver_data; + + sdev->use_10_for_rw =1 ; + +if (sdev->type ==TYPE_ROM ) + sdev->use_10_for_ms =1 ; +if (sdev->type ==TYPE_DISK && + sd->workarounds &SBP2_WORKAROUND_MODE_SENSE_8 ) + sdev->skip_ms_page_8 =1 ; +if (sd->workarounds &SBP2_WORKAROUND_FIX_CAPACITY ) { +fw_notify ("setting fix_capacity for %s\n" , unit->device.bus_id); + sdev->fix_capacity =1 ; + } + +return 0 ; +} + +/* +* Called by scsi stack when something has really gone wrong. Usually +* called when a command has timed-out for some reason. +*/ +static int sbp2_scsi_abort (struct scsi_cmnd *cmd) +{ +struct fw_unit *unit = (struct fw_unit *)cmd->device->host->hostdata[0 ]; + +fw_notify ("sbp2_scsi_abort\n" ); +sbp2_agent_reset (unit); +sbp2_cancel_orbs (unit); + +return SUCCESS ; +} + +static struct scsi_host_template scsi_driver_template = { + .module =THIS_MODULE , + .name ="SBP-2 IEEE-1394" , + .proc_name = (char *)sbp2_driver_name, + .queuecommand = sbp2_scsi_queuecommand, + .slave_alloc = sbp2_scsi_slave_alloc, + .slave_configure = sbp2_scsi_slave_configure, + .eh_abort_handler = sbp2_scsi_abort, + .this_id =-1 , + .sg_tablesize =SG_ALL , + .use_clustering =ENABLE_CLUSTERING , + .cmd_per_lun =1 , + .can_queue =1 , +}; + +static int add_scsi_devices (struct fw_unit *unit) +{ +struct sbp2_device *sd = unit->device.driver_data; +int retval, lun; + +if (sd->scsi_host !=NULL ) +return 0 ; + + sd->scsi_host =scsi_host_alloc (&scsi_driver_template, +sizeof (unsigned long )); +if (sd->scsi_host ==NULL ) { +fw_error ("failed to register scsi host\n" ); +return -1 ; + } + + sd->scsi_host->hostdata[0 ] = (unsigned long )unit; + retval =scsi_add_host (sd->scsi_host, &unit->device); +if (retval <0 ) { +fw_error ("failed to add scsi host\n" ); +scsi_host_put (sd->scsi_host); + sd->scsi_host =NULL ; +return retval; + } + +/* FIXME: Loop over luns here. */ + lun =0 ; + retval =scsi_add_device (sd->scsi_host,0 ,0 , lun); +if (retval <0 ) { +fw_error ("failed to add scsi device\n" ); +scsi_remove_host (sd->scsi_host); +scsi_host_put (sd->scsi_host); + sd->scsi_host =NULL ; +return retval; + } + +return 0 ; +} + +static void remove_scsi_devices (struct fw_unit *unit) +{ +struct sbp2_device *sd = unit->device.driver_data; + +if (sd->scsi_host !=NULL ) { +scsi_remove_host (sd->scsi_host); +scsi_host_put (sd->scsi_host); + } + sd->scsi_host =NULL ; +} + +MODULE_AUTHOR ("Kristian Hoegsberg <[email protected]>" ); +MODULE_DESCRIPTION ("SCSI over IEEE1394" ); +MODULE_LICENSE ("GPL" ); +MODULE_DEVICE_TABLE (ieee1394, sbp2_id_table); + +static int __init sbp2_init (void ) +{ +return driver_register (&sbp2_driver.driver); +} + +static void __exit sbp2_cleanup(void) +{ +driver_unregister (&sbp2_driver.driver); +} + +module_init (sbp2_init); +module_exit (sbp2_cleanup);
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
PATCH 6/6 firewire: add it all to kbuild
--- drivers/Makefile | 1 drivers/firewire/Kconfig | 60 ++++++++++++++++++++++++++++++++++++++ drivers/firewire/Makefile | 10 ++++++ drivers/ieee1394/Kconfig | 2 + 4 files changed, 73 insertions(+)
drivers/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_FC4) += fc4/ obj-$(CONFIG_SCSI) += scsi/ obj-$(CONFIG_ATA) += ata/ obj-$(CONFIG_FUSION) += message/ +obj-$(CONFIG_FIREWIRE) += firewire/ obj-$(CONFIG_IEEE1394) += ieee1394/ obj-y += cdrom/ obj-y += auxdisplay/
drivers/firewire/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# +# Makefile for the Linux IEEE 1394 implementation +# + +fw-core-objs := fw-card.o fw-topology.o fw-transaction.o fw-iso.o \ + fw-device.o fw-cdev.o + +obj-$(CONFIG_FIREWIRE) += fw-core.o +obj-$(CONFIG_FIREWIRE_OHCI) += fw-ohci.o +obj-$(CONFIG_FIREWIRE_SBP2) += fw-sbp2.o
drivers/ieee1394/Kconfig +2 -0
@@ -2,6 +2,8 @@ menu "IEEE 1394 (FireWire) support" +source "drivers/firewire/Kconfig" + config IEEE1394 tristate "IEEE 1394 (FireWire) support" depends on PCI || BROKEN
drivers/firewire/Kconfig new file +60 -0
60 lines not on this page · raw message
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
Olaf Hering
NAKQuoted 1 line · Kristian Høgsberg
drivers/firewire/Kconfig | 60 ++
NACK.
Upgrade the current drivers/ieee1394/ with the new code, and keep all existing module names.
Quoted 6 lines · Olaf Hering
Quoted 1 line · Kristian Høgsberg
drivers/firewire/Kconfig | 60 ++NACK.
Upgrade the currentdrivers/ieee1394/with the new code,
Last time I believe I was the only one who asked whether to put it into drivers/ieee1394 instead of another directory. Of course I acknowledge that everytime a new review round is started, people do reconsider. Especially since we had a gap of a few months since the last LKML review.
Quoted 1 line
and keep all existing module names.
I'm impartial to that. Using same names might ease the transition from the userspace side, as far as there is userland which relies on module names.
A certain drawback of same names would be that geeks cannot install both stacks at once during the transition period. Therefore, checking whether eventual problems are in fact regressions involves a module unload/ configure/ build/ install/ reload cycle, instead of just module unload/ reload. This especially means we can only get help from testers who are able to build kernels.
Other opinions?
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
Quoted 18 lines · Stefan Richter
Quoted 5 lines · Olaf Hering
Quoted 1 line · Kristian Høgsberg
drivers/firewire/Kconfig | 60 ++NACK.
Upgrade the currentdrivers/ieee1394/with the new code,Last time I believe I was the only one who asked whether to put it into
drivers/ieee1394instead of another directory. Of course I acknowledge that everytime a new review round is started, people do reconsider. Especially since we had a gap of a few months since the last LKML review.Quoted 1 line
and keep all existing module names.
I'm impartial to that. Using same names might ease the transition from the userspace side, as far as there is userland which relies on module names.
Quoted 8 lines
A certain drawback of same names would be that geeks cannot install both stacks at once during the transition period. Therefore, checking whether eventual problems are in fact regressions involves a module unload/ configure/ build/ install/ reload cycle, instead of just module unload/ reload. This especially means we can only get help from testers who are able to build kernels.
Other opinions?
I can and do build my own kernels so that's not a problem for me. I also have a firewire movie camera that went through absolute hell the last time a firewire upgrade came by, and it was over 5 months before I had a working kino install again. So I'd vote unconditionally to have 2 trees to select from at module load time until the shakeout has produced usable code in the 2nd tree.
Quoted 1 line
From me, its a definite ACK.
Signature · 6 lines
Cheers, Gene "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) I owe, I owe, It's off to work I go...
Quoted 19 lines · Stefan Richter
Quoted 6 lines · Olaf Hering
Quoted 1 line · Kristian Høgsberg
drivers/firewire/Kconfig | 60 ++NACK.
Upgrade the currentdrivers/ieee1394/with the new code,Last time I believe I was the only one who asked whether to put it into
drivers/ieee1394instead of another directory. Of course I acknowledge that everytime a new review round is started, people do reconsider. Especially since we had a gap of a few months since the last LKML review.Quoted 1 line
and keep all existing module names.
I'm impartial to that. Using same names might ease the transition from the userspace side, as far as there is userland which relies on module names.
Quoted 8 lines
A certain drawback of same names would be that geeks cannot install both stacks at once during the transition period. Therefore, checking whether eventual problems are in fact regressions involves a module unload/ configure/ build/ install/ reload cycle, instead of just module unload/ reload. This especially means we can only get help from testers who are able to build kernels.
Other opinions?
An advantage of changing the names is that they are now prefixed. But looking at them, there will again be the point whether everyone will think that "fw" is firmware, and perhaps switching to the (although longer) prefix "firewire" might make sense?
Quoted 1 line
Stefan Richter
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedRe: [PATCH 3/6] firewire: char device interface
In reply to Stefan RichterQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Stefan" == Stefan Richter <[email protected]> writes:
Stefan> Signed-off-by: Stefan Richter <[email protected]> Stefan> ---
Stefan> drivers/firewire/fw-cdev.c | 954 ++++++++++++++++++++++++++++++++++ Stefan> include/linux/firewire-cdev.h | 268 +++++++++ Stefan> 2 files changed, 1222 insertions(+)
Stefan> Index: linux_juju/include/linux/firewire-cdev.h
Stefan> =================================================================== Stefan> --- /dev/null
Stefan> +++ linux_juju/include/linux/firewire-cdev.h
Stefan> @@ -0,0 +1,268 @@
Stefan> +/* -*- c-basic-offset: 8 -*-
Stefan> + *
Stefan> + * fw-device-cdev.h -- Char device interface.
Stefan> + *
Stefan> + * Copyright (C) 2005-2006 Kristian Hoegsberg <[email protected]> Stefan> + *
Stefan> + * This program is free software; you can redistribute it and/or modify Stefan> + * it under the terms of the GNU General Public License as published by Stefan> + * the Free Software Foundation; either version 2 of the License, or Stefan> + * (at your option) any later version.
Stefan> + *
Stefan> + * This program is distributed in the hope that it will be useful, Stefan> + * but WITHOUT ANY WARRANTY; without even the implied warranty of Stefan> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Stefan> + * GNU General Public License for more details.
Stefan> + *
Stefan> + * You should have received a copy of the GNU General Public License Stefan> + * along with this program; if not, write to the Free Software Foundation, Stefan> + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Stefan> + */
Stefan> +
Stefan> +#ifndef __fw_cdev_h
Stefan> +#define __fw_cdev_h
Stefan> +
Stefan> +#include <asm/ioctl.h>
Stefan> +#include <asm/types.h>
Stefan> +
Stefan> +#define TCODE_WRITE_QUADLET_REQUEST 0
Stefan> +#define TCODE_WRITE_BLOCK_REQUEST 1
Stefan> +#define TCODE_WRITE_RESPONSE 2
Stefan> +#define TCODE_READ_QUADLET_REQUEST 4
Stefan> +#define TCODE_READ_BLOCK_REQUEST 5
Stefan> +#define TCODE_READ_QUADLET_RESPONSE 6
Stefan> +#define TCODE_READ_BLOCK_RESPONSE 7
Stefan> +#define TCODE_CYCLE_START 8
Stefan> +#define TCODE_LOCK_REQUEST 9
Stefan> +#define TCODE_STREAM_DATA 10
Stefan> +#define TCODE_LOCK_RESPONSE 11
Stefan> +
Stefan> +#define TCODE_LOCK_MASK_SWAP 0x11
Stefan> +#define TCODE_LOCK_COMPARE_SWAP 0x12
Stefan> +#define TCODE_LOCK_FETCH_ADD 0x13
Stefan> +#define TCODE_LOCK_LITTLE_ADD 0x14
Stefan> +#define TCODE_LOCK_BOUNDED_ADD 0x15
Stefan> +#define TCODE_LOCK_WRAP_ADD 0x16
Stefan> +#define TCODE_LOCK_VENDOR_DEPENDENT 0x17
Stefan> +
Stefan> +#define RCODE_COMPLETE 0x0
Stefan> +#define RCODE_CONFLICT_ERROR 0x4
Stefan> +#define RCODE_DATA_ERROR 0x5
Stefan> +#define RCODE_TYPE_ERROR 0x6
Stefan> +#define RCODE_ADDRESS_ERROR 0x7
Stefan> +
Stefan> +#define RCODE_SEND_ERROR 0x10
Stefan> +#define RCODE_CANCELLED 0x11
Stefan> +#define RCODE_BUSY 0x12
Stefan> +#define RCODE_GENERATION 0x13
Stefan> +#define RCODE_NO_ACK 0x14
Stefan> +
Stefan> +#define SCODE_100 0x0
Stefan> +#define SCODE_200 0x1
Stefan> +#define SCODE_400 0x2
Stefan> +#define SCODE_800 0x3
Stefan> +#define SCODE_1600 0x4
Stefan> +#define SCODE_3200 0x5
These are also defined in fw-transaction.h, though that file doesn't have all the values. Can these just be combined into a single fw-constants.h file instead?
I honestly haven't checked all your defines....
Stefan> +#define FW_CDEV_EVENT_BUS_RESET 0x00
Stefan> +#define FW_CDEV_EVENT_RESPONSE 0x01
Stefan> +#define FW_CDEV_EVENT_REQUEST 0x02
Stefan> +#define FW_CDEV_EVENT_ISO_INTERRUPT 0x03
Stefan> +
Stefan> +/* The 'closure' fields are for user space to use. Data passed in the Stefan> + * 'closure' field for a request will be returned in the corresponding Stefan> + * event. It's a 64-bit type so that it's a fixed size type big Stefan> + * enough to hold a pointer on all platforms. */
Stefan> +
Stefan> +struct fw_cdev_event_common {
Stefan> + __u64 closure;
Stefan> + __u32 type;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_event_bus_reset {
Stefan> + __u64 closure;
Stefan> + __u32 type;
Stefan> + __u32 node_id;
Stefan> + __u32 local_node_id;
Stefan> + __u32 bm_node_id;
Stefan> + __u32 irm_node_id;
Stefan> + __u32 root_node_id;
Stefan> + __u32 generation;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_event_response {
Stefan> + __u64 closure;
Stefan> + __u32 type;
Stefan> + __u32 rcode;
Stefan> + __u32 length;
Stefan> + __u32 data[0];
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_event_request {
Stefan> + __u64 closure;
Stefan> + __u32 type;
Stefan> + __u32 tcode;
Stefan> + __u64 offset;
Stefan> + __u32 handle;
Stefan> + __u32 length;
Stefan> + __u32 data[0];
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_event_iso_interrupt {
Stefan> + __u64 closure;
Stefan> + __u32 type;
Stefan> + __u32 cycle;
Stefan> + __u32 header_length; /* Length in bytes of following headers. */
Stefan> + __u32 header[0];
Stefan> +};
Stefan> +
Stefan> +union fw_cdev_event {
Stefan> + struct fw_cdev_event_common common;
Stefan> + struct fw_cdev_event_bus_reset bus_reset;
Stefan> + struct fw_cdev_event_response response;
Stefan> + struct fw_cdev_event_request request;
Stefan> + struct fw_cdev_event_iso_interrupt iso_interrupt;
Stefan> +};
Stefan> +
Stefan> +#define FW_CDEV_IOC_GET_INFO _IOWR('#', 0x00, struct fw_cdev_get_info)
Stefan> +#define FW_CDEV_IOC_SEND_REQUEST _IOW('#', 0x01, struct fw_cdev_send_request)
Stefan> +#define FW_CDEV_IOC_ALLOCATE _IOWR('#', 0x02, struct fw_cdev_allocate)
Stefan> +#define FW_CDEV_IOC_DEALLOCATE _IOW('#', 0x03, struct fw_cdev_deallocate)
Stefan> +#define FW_CDEV_IOC_SEND_RESPONSE _IOW('#', 0x04, struct fw_cdev_send_response)
Stefan> +#define FW_CDEV_IOC_INITIATE_BUS_RESET _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset)
Stefan> +#define FW_CDEV_IOC_ADD_DESCRIPTOR _IOWR('#', 0x06, struct fw_cdev_add_descriptor)
Stefan> +#define FW_CDEV_IOC_REMOVE_DESCRIPTOR _IOW('#', 0x07, struct fw_cdev_remove_descriptor)
Stefan> +
Stefan> +#define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context)
Stefan> +#define FW_CDEV_IOC_QUEUE_ISO _IOWR('#', 0x09, struct fw_cdev_queue_iso)
Stefan> +#define FW_CDEV_IOC_START_ISO _IOW('#', 0x0a, struct fw_cdev_start_iso)
Stefan> +#define FW_CDEV_IOC_STOP_ISO _IOW('#', 0x0b, struct fw_cdev_stop_iso)
Stefan> +
Stefan> +/* FW_CDEV_VERSION History
Stefan> + *
Stefan> + * 1 Feb 18, 2007: Initial version.
Stefan> + */
Stefan> +#define FW_CDEV_VERSION 1
Stefan> +
Stefan> +struct fw_cdev_get_info {
Stefan> + /* The version field is just a running serial number. We
Stefan> + * never break backwards compatibility. Userspace passes in
Stefan> + * the version it expects and the kernel passes back the
Stefan> + * highest version it can provide. Even if the structs in
Stefan> + * this interface are extended in a later version, the kernel
Stefan> + * will not copy back more data than what was present in the
Stefan> + * interface version userspace expects. */
Stefan> + __u32 version;
Stefan> +
Stefan> + /* If non-zero, at most rom_length bytes of config rom will be
Stefan> + * copied into that user space address. In either case,
Stefan> + * rom_length is updated with the actual length of the config
Stefan> + * rom. */
Stefan> + __u32 rom_length;
Stefan> + __u64 rom;
Stefan> +
Stefan> + /* If non-zero, a fw_cdev_event_bus_reset struct will be
Stefan> + * copied here with the current state of the bus. This does
Stefan> + * not cause a bus reset to happen. The value of closure in
Stefan> + * this and sub-sequent bus reset events is set to
Stefan> + * bus_reset_closure. */
Stefan> + __u64 bus_reset;
Stefan> + __u64 bus_reset_closure;
Stefan> +
Stefan> + /* The index of the card this devices belongs to. */
Stefan> + __u32 card;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_send_request {
Stefan> + __u32 tcode;
Stefan> + __u32 length;
Stefan> + __u64 offset;
Stefan> + __u64 closure;
Stefan> + __u64 data;
Stefan> + __u32 generation;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_send_response {
Stefan> + __u32 rcode;
Stefan> + __u32 length;
Stefan> + __u64 data;
Stefan> + __u32 handle;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_allocate {
Stefan> + __u64 offset;
Stefan> + __u64 closure;
Stefan> + __u32 length;
Stefan> + __u32 handle;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_deallocate {
Stefan> + __u32 handle;
Stefan> +};
Stefan> +
Stefan> +#define FW_CDEV_LONG_RESET 0
Stefan> +#define FW_CDEV_SHORT_RESET 1
Stefan> +
Stefan> +struct fw_cdev_initiate_bus_reset {
Stefan> + __u32 type;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_add_descriptor {
Stefan> + __u32 immediate;
Stefan> + __u32 key;
Stefan> + __u64 data;
Stefan> + __u32 length;
Stefan> + __u32 handle;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_remove_descriptor {
Stefan> + __u32 handle;
Stefan> +};
Stefan> +
Stefan> +#define FW_CDEV_ISO_CONTEXT_TRANSMIT 0
Stefan> +#define FW_CDEV_ISO_CONTEXT_RECEIVE 1
Stefan> +
Stefan> +#define FW_CDEV_ISO_CONTEXT_MATCH_TAG0 1
Stefan> +#define FW_CDEV_ISO_CONTEXT_MATCH_TAG1 2
Stefan> +#define FW_CDEV_ISO_CONTEXT_MATCH_TAG2 4
Stefan> +#define FW_CDEV_ISO_CONTEXT_MATCH_TAG3 8
Stefan> +#define FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS 15
Stefan> +
Stefan> +struct fw_cdev_create_iso_context {
Stefan> + __u32 type;
Stefan> + __u32 header_size;
Stefan> + __u32 channel;
Stefan> + __u32 speed;
Stefan> + __u64 closure;
Stefan> + __u32 handle;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_iso_packet {
Stefan> + __u16 payload_length; /* Length of indirect payload. */
Stefan> + __u32 interrupt : 1; /* Generate interrupt on this packet */
Stefan> + __u32 skip : 1; /* Set to not send packet at all. */
Stefan> + __u32 tag : 2;
Stefan> + __u32 sy : 4;
Stefan> + __u32 header_length : 8; /* Length of immediate header. */
Stefan> + __u32 header[0];
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_queue_iso {
Stefan> + __u64 packets;
Stefan> + __u64 data;
Stefan> + __u32 size;
Stefan> + __u32 handle;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_start_iso {
Stefan> + __s32 cycle;
Stefan> + __u32 sync;
Stefan> + __u32 tags;
Stefan> + __u32 handle;
Stefan> +};
Stefan> +
Stefan> +struct fw_cdev_stop_iso {
Stefan> + __u32 handle;
Stefan> +};
Stefan> +
Stefan> +#endif /* __fw_cdev_h */
Stefan> Index: linux_juju/drivers/firewire/fw-cdev.c
Stefan> =================================================================== Stefan> --- /dev/null
Stefan> +++ linux_juju/drivers/firewire/fw-cdev.c
Stefan> @@ -0,0 +1,954 @@
Stefan> +/* -*- c-basic-offset: 8 -*-
Stefan> + *
Stefan> + * fw-device-cdev.c - Char device for device raw access Stefan> + *
Stefan> + * Copyright (C) 2005-2006 Kristian Hoegsberg <[email protected]> Stefan> + *
Stefan> + * This program is free software; you can redistribute it and/or modify Stefan> + * it under the terms of the GNU General Public License as published by Stefan> + * the Free Software Foundation; either version 2 of the License, or Stefan> + * (at your option) any later version.
Stefan> + *
Stefan> + * This program is distributed in the hope that it will be useful, Stefan> + * but WITHOUT ANY WARRANTY; without even the implied warranty of Stefan> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Stefan> + * GNU General Public License for more details.
Stefan> + *
Stefan> + * You should have received a copy of the GNU General Public License Stefan> + * along with this program; if not, write to the Free Software Foundation, Stefan> + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Stefan> + */
Stefan> +
Stefan> +#include <linux/module.h>
Stefan> +#include <linux/kernel.h>
Stefan> +#include <linux/wait.h>
Stefan> +#include <linux/errno.h>
Stefan> +#include <linux/device.h>
Stefan> +#include <linux/vmalloc.h>
Stefan> +#include <linux/poll.h>
Stefan> +#include <linux/delay.h>
Stefan> +#include <linux/mm.h>
Stefan> +#include <linux/idr.h>
Stefan> +#include <linux/compat.h>
Stefan> +#include <linux/firewire-cdev.h>
Stefan> +#include <asm/uaccess.h>
Stefan> +#include "fw-transaction.h"
Stefan> +#include "fw-topology.h"
Stefan> +#include "fw-device.h"
Stefan> +
Stefan> +/* dequeue_event() just kfree()'s the event, so the event has to be Stefan> + * the first field in the struct. */
Stefan> +
Stefan> +struct client;
Stefan> +struct client_resource {
Stefan> + struct list_head link;
Stefan> + void (*release)(struct client *client, struct client_resource *r);
Stefan> + u32 handle;
Stefan> +};
Stefan> +
Stefan> +struct event {
Stefan> + struct { void *data; size_t size; } v[2];
Stefan> + struct list_head link;
Stefan> +};
Stefan> +
Stefan> +struct bus_reset {
Stefan> + struct event event;
Stefan> + struct fw_cdev_event_bus_reset reset;
Stefan> +};
Stefan> +
Stefan> +struct response {
Stefan> + struct event event;
Stefan> + struct fw_transaction transaction;
Stefan> + struct client *client;
Stefan> + struct client_resource resource;
Stefan> + struct fw_cdev_event_response response;
Stefan> +};
Stefan> +
Stefan> +struct iso_interrupt {
Stefan> + struct event event;
Stefan> + struct fw_cdev_event_iso_interrupt interrupt;
Stefan> +};
Stefan> +
Stefan> +struct client {
Stefan> + u32 version;
Stefan> + struct fw_device *device;
Stefan> + spinlock_t lock;
Stefan> + u32 resource_handle;
Stefan> + struct list_head resource_list;
Stefan> + struct list_head event_list;
Stefan> + wait_queue_head_t wait;
Stefan> + u64 bus_reset_closure;
Stefan> +
Stefan> + struct fw_iso_context *iso_context;
Stefan> + u64 iso_closure;
Stefan> + struct fw_iso_buffer buffer;
Stefan> + unsigned long vm_start;
Stefan> +
Stefan> + struct list_head link;
Stefan> +};
Stefan> +
Stefan> +static inline void __user *
Stefan> +u64_to_uptr(__u64 value)
Stefan> +{
Stefan> + return (void __user *)(unsigned long)value;
Stefan> +}
Stefan> +
Stefan> +static inline __u64
Stefan> +uptr_to_u64(void __user *ptr)
Stefan> +{
Stefan> + return (__u64)(unsigned long)ptr;
Stefan> +}
Stefan> +
Stefan> +static int fw_device_op_open(struct inode *inode, struct file *file) Stefan> +{
Stefan> + struct fw_device *device;
Stefan> + struct client *client;
Stefan> + unsigned long flags;
Stefan> +
Stefan> + device = fw_device_from_devt(inode->i_rdev);
Stefan> + if (device == NULL)
Stefan> + return -ENODEV;
Stefan> +
Stefan> + client = kzalloc(sizeof *client, GFP_KERNEL);
Stefan> + if (client == NULL)
Stefan> + return -ENOMEM;
Stefan> +
Stefan> + client->device = fw_device_get(device);
Stefan> + INIT_LIST_HEAD(&client->event_list);
Stefan> + INIT_LIST_HEAD(&client->resource_list);
Stefan> + spin_lock_init(&client->lock);
Stefan> + init_waitqueue_head(&client->wait);
Stefan> +
Stefan> + file->private_data = client;
Stefan> +
Stefan> + spin_lock_irqsave(&device->card->lock, flags);
Stefan> + list_add_tail(&client->link, &device->client_list);
Stefan> + spin_unlock_irqrestore(&device->card->lock, flags);
Stefan> +
Stefan> + return 0;
Stefan> +}
Stefan> +
Stefan> +static void queue_event(struct client *client, struct event *event,
Stefan> + void *data0, size_t size0, void *data1, size_t size1)
Stefan> +{
Stefan> + unsigned long flags;
Stefan> +
Stefan> + event->v[0].data = data0;
Stefan> + event->v[0].size = size0;
Stefan> + event->v[1].data = data1;
Stefan> + event->v[1].size = size1;
Stefan> +
Stefan> + spin_lock_irqsave(&client->lock, flags);
Stefan> +
Stefan> + list_add_tail(&event->link, &client->event_list);
Stefan> + wake_up_interruptible(&client->wait);
Stefan> +
Stefan> + spin_unlock_irqrestore(&client->lock, flags);
Stefan> +}
Stefan> +
Stefan> +static int
Stefan> +dequeue_event(struct client *client, char __user *buffer, size_t count) Stefan> +{
Stefan> + unsigned long flags;
Stefan> + struct event *event;
Stefan> + size_t size, total;
Stefan> + int i, retval;
Stefan> +
Stefan> + retval = wait_event_interruptible(client->wait,
Stefan> + !list_empty(&client->event_list) ||
Stefan> + fw_device_is_shutdown(client->device));
Stefan> + if (retval < 0)
Stefan> + return retval;
Stefan> +
Stefan> + if (list_empty(&client->event_list) &&
Stefan> + fw_device_is_shutdown(client->device))
Stefan> + return -ENODEV;
Stefan> +
Stefan> + spin_lock_irqsave(&client->lock, flags);
Stefan> + event = container_of(client->event_list.next, struct event, link);
Stefan> + list_del(&event->link);
Stefan> + spin_unlock_irqrestore(&client->lock, flags);
Stefan> +
Stefan> + total = 0;
Stefan> + for (i = 0; i < ARRAY_SIZE(event->v) && total < count; i++) {
Stefan> + size = min(event->v[i].size, count - total);
Stefan> + if (copy_to_user(buffer + total, event->v[i].data, size)) {
Stefan> + retval = -EFAULT;
Stefan> + goto out;
Stefan> + }
Stefan> + total += size;
Stefan> + }
Stefan> + retval = total;
Stefan> +
Stefan> + out:
Stefan> + kfree(event);
Stefan> +
Stefan> + return retval;
Stefan> +}
Stefan> +
Stefan> +static ssize_t
Stefan> +fw_device_op_read(struct file *file,
Stefan> + char __user *buffer, size_t count, loff_t *offset)
Stefan> +{
Stefan> + struct client *client = file->private_data;
Stefan> +
Stefan> + return dequeue_event(client, buffer, count);
Stefan> +}
Stefan> +
Stefan> +static void
Stefan> +fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
Stefan> + struct client *client)
Stefan> +{
Stefan> + struct fw_card *card = client->device->card;
Stefan> +
Stefan> + event->closure = client->bus_reset_closure;
Stefan> + event->type = FW_CDEV_EVENT_BUS_RESET;
Stefan> + event->node_id = client->device->node_id;
Stefan> + event->local_node_id = card->local_node->node_id;
Stefan> + event->bm_node_id = 0; /* FIXME: We don't track the BM. */ Stefan> + event->irm_node_id = card->irm_node->node_id; Stefan> + event->root_node_id = card->root_node->node_id; Stefan> + event->generation = card->generation;
Stefan> +}
Stefan> +
Stefan> +static void
Stefan> +for_each_client(struct fw_device *device,
Stefan> + void (*callback)(struct client *client))
Stefan> +{
Stefan> + struct fw_card *card = device->card;
Stefan> + struct client *c;
Stefan> + unsigned long flags;
Stefan> +
Stefan> + spin_lock_irqsave(&card->lock, flags);
Stefan> +
Stefan> + list_for_each_entry(c, &device->client_list, link)
Stefan> + callback(c);
Stefan> +
Stefan> + spin_unlock_irqrestore(&card->lock, flags);
Stefan> +}
Stefan> +
Stefan> +static void
Stefan> +queue_bus_reset_event(struct client *client)
Stefan> +{
Stefan> + struct bus_reset *bus_reset;
Stefan> +
Stefan> + bus_reset = kzalloc(sizeof *bus_reset, GFP_ATOMIC);
Stefan> + if (bus_reset == NULL) {
Stefan> + fw_notify("Out of memory when allocating bus reset event\n");
Stefan> + return;
Stefan> + }
Stefan> +
Stefan> + fill_bus_reset_event(&bus_reset->reset, client);
Stefan> +
Stefan> + queue_event(client, &bus_reset->event,
Stefan> + &bus_reset->reset, sizeof bus_reset->reset, NULL, 0);
Stefan> +}
Stefan> +
Stefan> +void fw_device_cdev_update(struct fw_device *device)
Stefan> +{
Stefan> + for_each_client(device, queue_bus_reset_event);
Stefan> +}
Stefan> +
Stefan> +static void wake_up_client(struct client *client)
Stefan> +{
Stefan> + wake_up_interruptible(&client->wait);
Stefan> +}
Stefan> +
Stefan> +void fw_device_cdev_remove(struct fw_device *device)
Stefan> +{
Stefan> + for_each_client(device, wake_up_client);
Stefan> +}
Stefan> +
Stefan> +static int ioctl_get_info(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_get_info *get_info = buffer;
Stefan> + struct fw_cdev_event_bus_reset bus_reset;
Stefan> +
Stefan> + client->version = get_info->version;
Stefan> + get_info->version = FW_CDEV_VERSION;
Stefan> +
Stefan> + if (get_info->rom != 0) {
Stefan> + void __user *uptr = u64_to_uptr(get_info->rom);
Stefan> + size_t want = get_info->rom_length;
Stefan> + size_t have = client->device->config_rom_length * 4;
Stefan> +
Stefan> + if (copy_to_user(uptr, client->device->config_rom,
Stefan> + min(want, have)))
Stefan> + return -EFAULT;
Stefan> + }
Stefan> + get_info->rom_length = client->device->config_rom_length * 4;
Stefan> +
Stefan> + client->bus_reset_closure = get_info->bus_reset_closure;
Stefan> + if (get_info->bus_reset != 0) {
Stefan> + void __user *uptr = u64_to_uptr(get_info->bus_reset);
Stefan> +
Stefan> + fill_bus_reset_event(&bus_reset, client);
Stefan> + if (copy_to_user(uptr, &bus_reset, sizeof bus_reset))
Stefan> + return -EFAULT;
Stefan> + }
Stefan> +
Stefan> + get_info->card = client->device->card->index;
Stefan> +
Stefan> + return 0;
Stefan> +}
Stefan> +
Stefan> +static void
Stefan> +add_client_resource(struct client *client, struct client_resource *resource) Stefan> +{
Stefan> + unsigned long flags;
Stefan> +
Stefan> + spin_lock_irqsave(&client->lock, flags);
Stefan> + list_add_tail(&resource->link, &client->resource_list);
Stefan> + resource->handle = client->resource_handle++;
Stefan> + spin_unlock_irqrestore(&client->lock, flags);
Stefan> +}
Stefan> +
Stefan> +static int
Stefan> +release_client_resource(struct client *client, u32 handle,
Stefan> + struct client_resource **resource)
Stefan> +{
Stefan> + struct client_resource *r;
Stefan> + unsigned long flags;
Stefan> +
Stefan> + spin_lock_irqsave(&client->lock, flags);
Stefan> + list_for_each_entry(r, &client->resource_list, link) {
Stefan> + if (r->handle == handle) {
Stefan> + list_del(&r->link);
Stefan> + break;
Stefan> + }
Stefan> + }
Stefan> + spin_unlock_irqrestore(&client->lock, flags);
Stefan> +
Stefan> + if (&r->link == &client->resource_list)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + if (resource)
Stefan> + *resource = r;
Stefan> + else
Stefan> + r->release(client, r);
Stefan> +
Stefan> + return 0;
Stefan> +}
Stefan> +
Stefan> +static void
Stefan> +release_transaction(struct client *client, struct client_resource *resource) Stefan> +{
Stefan> + struct response *response =
Stefan> + container_of(resource, struct response, resource);
Stefan> +
Stefan> + fw_cancel_transaction(client->device->card, &response->transaction);
Stefan> +}
Stefan> +
Stefan> +static void
Stefan> +complete_transaction(struct fw_card *card, int rcode,
Stefan> + void *payload, size_t length, void *data)
Stefan> +{
Stefan> + struct response *response = data;
Stefan> + struct client *client = response->client;
Stefan> + unsigned long flags;
Stefan> +
Stefan> + if (length < response->response.length)
Stefan> + response->response.length = length;
Stefan> + if (rcode == RCODE_COMPLETE)
Stefan> + memcpy(response->response.data, payload,
Stefan> + response->response.length);
Stefan> +
Stefan> + spin_lock_irqsave(&client->lock, flags);
Stefan> + list_del(&response->resource.link);
Stefan> + spin_unlock_irqrestore(&client->lock, flags);
Stefan> +
Stefan> + response->response.type = FW_CDEV_EVENT_RESPONSE;
Stefan> + response->response.rcode = rcode;
Stefan> + queue_event(client, &response->event,
Stefan> + &response->response, sizeof response->response,
Stefan> + response->response.data, response->response.length);
Stefan> +}
Stefan> +
Stefan> +static ssize_t ioctl_send_request(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_device *device = client->device;
Stefan> + struct fw_cdev_send_request *request = buffer;
Stefan> + struct response *response;
Stefan> +
Stefan> + /* What is the biggest size we'll accept, really? */
Stefan> + if (request->length > 4096)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + response = kmalloc(sizeof *response + request->length, GFP_KERNEL);
Stefan> + if (response == NULL)
Stefan> + return -ENOMEM;
Stefan> +
Stefan> + response->client = client;
Stefan> + response->response.length = request->length;
Stefan> + response->response.closure = request->closure;
Stefan> +
Stefan> + if (request->data &&
Stefan> + copy_from_user(response->response.data,
Stefan> + u64_to_uptr(request->data), request->length)) {
Stefan> + kfree(response);
Stefan> + return -EFAULT;
Stefan> + }
Stefan> +
Stefan> + response->resource.release = release_transaction;
Stefan> + add_client_resource(client, &response->resource);
Stefan> +
Stefan> + fw_send_request(device->card, &response->transaction,
Stefan> + request->tcode & 0x1f,
Stefan> + device->node->node_id,
Stefan> + request->generation,
Stefan> + device->node->max_speed,
Stefan> + request->offset,
Stefan> + response->response.data, request->length,
Stefan> + complete_transaction, response);
Stefan> +
Stefan> + if (request->data)
Stefan> + return sizeof request + request->length;
Stefan> + else
Stefan> + return sizeof request;
Stefan> +}
Stefan> +
Stefan> +struct address_handler {
Stefan> + struct fw_address_handler handler;
Stefan> + __u64 closure;
Stefan> + struct client *client;
Stefan> + struct client_resource resource;
Stefan> +};
Stefan> +
Stefan> +struct request {
Stefan> + struct fw_request *request;
Stefan> + void *data;
Stefan> + size_t length;
Stefan> + struct client_resource resource;
Stefan> +};
Stefan> +
Stefan> +struct request_event {
Stefan> + struct event event;
Stefan> + struct fw_cdev_event_request request;
Stefan> +};
Stefan> +
Stefan> +static void
Stefan> +release_request(struct client *client, struct client_resource *resource) Stefan> +{
Stefan> + struct request *request =
Stefan> + container_of(resource, struct request, resource);
Stefan> +
Stefan> + fw_send_response(client->device->card, request->request,
Stefan> + RCODE_CONFLICT_ERROR);
Stefan> + kfree(request);
Stefan> +}
Stefan> +
Stefan> +static void
Stefan> +handle_request(struct fw_card *card, struct fw_request *r,
Stefan> + int tcode, int destination, int source, Stefan> + int generation, int speed, Stefan> + unsigned long long offset, Stefan> + void *payload, size_t length, void *callback_data)
Stefan> +{
Stefan> + struct address_handler *handler = callback_data;
Stefan> + struct request *request;
Stefan> + struct request_event *e;
Stefan> + struct client *client = handler->client;
Stefan> +
Stefan> + request = kmalloc(sizeof *request, GFP_ATOMIC);
Stefan> + e = kmalloc(sizeof *e, GFP_ATOMIC);
Stefan> + if (request == NULL || e == NULL) {
Stefan> + kfree(request);
Stefan> + kfree(e);
Stefan> + fw_send_response(card, r, RCODE_CONFLICT_ERROR);
Stefan> + return;
Stefan> + }
Stefan> +
Stefan> + request->request = r;
Stefan> + request->data = payload;
Stefan> + request->length = length;
Stefan> +
Stefan> + request->resource.release = release_request;
Stefan> + add_client_resource(client, &request->resource);
Stefan> +
Stefan> + e->request.type = FW_CDEV_EVENT_REQUEST; Stefan> + e->request.tcode = tcode; Stefan> + e->request.offset = offset; Stefan> + e->request.length = length; Stefan> + e->request.handle = request->resource.handle;
Stefan> + e->request.closure = handler->closure;
Stefan> +
Stefan> + queue_event(client, &e->event,
Stefan> + &e->request, sizeof e->request, payload, length);
Stefan> +}
Stefan> +
Stefan> +static void
Stefan> +release_address_handler(struct client *client,
Stefan> + struct client_resource *resource)
Stefan> +{
Stefan> + struct address_handler *handler =
Stefan> + container_of(resource, struct address_handler, resource);
Stefan> +
Stefan> + fw_core_remove_address_handler(&handler->handler);
Stefan> + kfree(handler);
Stefan> +}
Stefan> +
Stefan> +static int ioctl_allocate(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_allocate *request = buffer;
Stefan> + struct address_handler *handler;
Stefan> + struct fw_address_region region;
Stefan> +
Stefan> + handler = kmalloc(sizeof *handler, GFP_KERNEL);
Stefan> + if (handler == NULL)
Stefan> + return -ENOMEM;
Stefan> +
Stefan> + region.start = request->offset;
Stefan> + region.end = request->offset + request->length;
Stefan> + handler->handler.length = request->length;
Stefan> + handler->handler.address_callback = handle_request;
Stefan> + handler->handler.callback_data = handler;
Stefan> + handler->closure = request->closure;
Stefan> + handler->client = client;
Stefan> +
Stefan> + if (fw_core_add_address_handler(&handler->handler, ®ion) < 0) {
Stefan> + kfree(handler);
Stefan> + return -EBUSY;
Stefan> + }
Stefan> +
Stefan> + handler->resource.release = release_address_handler;
Stefan> + add_client_resource(client, &handler->resource);
Stefan> + request->handle = handler->resource.handle;
Stefan> +
Stefan> + return 0;
Stefan> +}
Stefan> +
Stefan> +static int ioctl_deallocate(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_deallocate *request = buffer;
Stefan> +
Stefan> + return release_client_resource(client, request->handle, NULL);
Stefan> +}
Stefan> +
Stefan> +static int ioctl_send_response(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_send_response *request = buffer;
Stefan> + struct client_resource *resource;
Stefan> + struct request *r;
Stefan> +
Stefan> + if (release_client_resource(client, request->handle, &resource) < 0)
Stefan> + return -EINVAL;
Stefan> + r = container_of(resource, struct request, resource);
Stefan> + if (request->length < r->length)
Stefan> + r->length = request->length;
Stefan> + if (copy_from_user(r->data, u64_to_uptr(request->data), r->length))
Stefan> + return -EFAULT;
Stefan> +
Stefan> + fw_send_response(client->device->card, r->request, request->rcode);
Stefan> + kfree(r);
Stefan> +
Stefan> + return 0;
Stefan> +}
Stefan> +
Stefan> +static int ioctl_initiate_bus_reset(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_initiate_bus_reset *request = buffer;
Stefan> + int short_reset;
Stefan> +
Stefan> + short_reset = (request->type == FW_CDEV_SHORT_RESET);
Stefan> +
Stefan> + return fw_core_initiate_bus_reset(client->device->card, short_reset);
Stefan> +}
Stefan> +
Stefan> +struct descriptor {
Stefan> + struct fw_descriptor d;
Stefan> + struct client_resource resource;
Stefan> + u32 data[0];
Stefan> +};
Stefan> +
Stefan> +static void release_descriptor(struct client *client,
Stefan> + struct client_resource *resource)
Stefan> +{
Stefan> + struct descriptor *descriptor =
Stefan> + container_of(resource, struct descriptor, resource);
Stefan> +
Stefan> + fw_core_remove_descriptor(&descriptor->d);
Stefan> + kfree(descriptor);
Stefan> +}
Stefan> +
Stefan> +static int ioctl_add_descriptor(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_add_descriptor *request = buffer;
Stefan> + struct descriptor *descriptor;
Stefan> + int retval;
Stefan> +
Stefan> + if (request->length > 256)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + descriptor =
Stefan> + kmalloc(sizeof *descriptor + request->length * 4, GFP_KERNEL);
Stefan> + if (descriptor == NULL)
Stefan> + return -ENOMEM;
Stefan> +
Stefan> + if (copy_from_user(descriptor->data,
Stefan> + u64_to_uptr(request->data), request->length * 4)) {
Stefan> + kfree(descriptor);
Stefan> + return -EFAULT;
Stefan> + }
Stefan> +
Stefan> + descriptor->d.length = request->length;
Stefan> + descriptor->d.immediate = request->immediate;
Stefan> + descriptor->d.key = request->key;
Stefan> + descriptor->d.data = descriptor->data;
Stefan> +
Stefan> + retval = fw_core_add_descriptor(&descriptor->d);
Stefan> + if (retval < 0) {
Stefan> + kfree(descriptor);
Stefan> + return retval;
Stefan> + }
Stefan> +
Stefan> + descriptor->resource.release = release_descriptor;
Stefan> + add_client_resource(client, &descriptor->resource);
Stefan> + request->handle = descriptor->resource.handle;
Stefan> +
Stefan> + return 0;
Stefan> +}
Stefan> +
Stefan> +static int ioctl_remove_descriptor(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_remove_descriptor *request = buffer;
Stefan> +
Stefan> + return release_client_resource(client, request->handle, NULL);
Stefan> +}
Stefan> +
Stefan> +static void
Stefan> +iso_callback(struct fw_iso_context *context, u32 cycle,
Stefan> + size_t header_length, void *header, void *data)
Stefan> +{
Stefan> + struct client *client = data;
Stefan> + struct iso_interrupt *interrupt;
Stefan> +
Stefan> + interrupt = kzalloc(sizeof *interrupt + header_length, GFP_ATOMIC);
Stefan> + if (interrupt == NULL)
Stefan> + return;
Stefan> +
Stefan> + interrupt->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT; Stefan> + interrupt->interrupt.closure = client->iso_closure; Stefan> + interrupt->interrupt.cycle = cycle;
Stefan> + interrupt->interrupt.header_length = header_length;
Stefan> + memcpy(interrupt->interrupt.header, header, header_length);
Stefan> + queue_event(client, &interrupt->event,
Stefan> + &interrupt->interrupt,
Stefan> + sizeof interrupt->interrupt + header_length, NULL, 0);
Stefan> +}
Stefan> +
Stefan> +static int ioctl_create_iso_context(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_create_iso_context *request = buffer;
Stefan> +
Stefan> + if (request->channel > 63)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + switch (request->type) {
Stefan> + case FW_ISO_CONTEXT_RECEIVE:
Stefan> + if (request->header_size < 4 || (request->header_size & 3))
Stefan> + return -EINVAL;
Stefan> +
Stefan> + break;
Stefan> +
Stefan> + case FW_ISO_CONTEXT_TRANSMIT:
Stefan> + if (request->speed > SCODE_3200)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + break;
Stefan> +
Stefan> + default:
Stefan> + return -EINVAL;
Stefan> + }
Stefan> +
Stefan> + client->iso_closure = request->closure;
Stefan> + client->iso_context = fw_iso_context_create(client->device->card,
Stefan> + request->type, Stefan> + request->channel, Stefan> + request->speed, Stefan> + request->header_size, Stefan> + iso_callback, client);
Stefan> + if (IS_ERR(client->iso_context))
Stefan> + return PTR_ERR(client->iso_context);
Stefan> +
Stefan> + /* We only support one context at this time. */
Stefan> + request->handle = 0;
Stefan> +
Stefan> + return 0;
Stefan> +}
Stefan> +
Stefan> +static int ioctl_queue_iso(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_queue_iso *request = buffer;
Stefan> + struct fw_cdev_iso_packet __user *p, *end, *next;
Stefan> + struct fw_iso_context *ctx = client->iso_context;
Stefan> + unsigned long payload, buffer_end, header_length;
Stefan> + int count;
Stefan> + struct {
Stefan> + struct fw_iso_packet packet;
Stefan> + u8 header[256];
Stefan> + } u;
Stefan> +
Stefan> + if (ctx == NULL || request->handle != 0)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + /* If the user passes a non-NULL data pointer, has mmap()'ed
Stefan> + * the iso buffer, and the pointer points inside the buffer,
Stefan> + * we setup the payload pointers accordingly. Otherwise we
Stefan> + * set them both to 0, which will still let packets with
Stefan> + * payload_length == 0 through. In other words, if no packets
Stefan> + * use the indirect payload, the iso buffer need not be mapped
Stefan> + * and the request->data pointer is ignored.*/
Stefan> +
Stefan> + payload = (unsigned long)request->data - client->vm_start;
Stefan> + buffer_end = client->buffer.page_count << PAGE_SHIFT;
Stefan> + if (request->data == 0 || client->buffer.pages == NULL ||
Stefan> + payload >= buffer_end) {
Stefan> + payload = 0;
Stefan> + buffer_end = 0;
Stefan> + }
Stefan> +
Stefan> + if (!access_ok(VERIFY_READ, request->packets, request->size))
Stefan> + return -EFAULT;
Stefan> +
Stefan> + p = (struct fw_cdev_iso_packet __user *)u64_to_uptr(request->packets);
Stefan> + end = (void __user *)p + request->size;
Stefan> + count = 0;
Stefan> + while (p < end) {
Stefan> + if (__copy_from_user(&u.packet, p, sizeof *p))
Stefan> + return -EFAULT;
Stefan> +
Stefan> + if (ctx->type == FW_ISO_CONTEXT_TRANSMIT) {
Stefan> + header_length = u.packet.header_length;
Stefan> + } else {
Stefan> + /* We require that header_length is a multiple of
Stefan> + * the fixed header size, ctx->header_size */
Stefan> + if (ctx->header_size == 0) {
Stefan> + if (u.packet.header_length > 0)
Stefan> + return -EINVAL;
Stefan> + } else if (u.packet.header_length % ctx->header_size != 0) {
Stefan> + return -EINVAL;
Stefan> + }
Stefan> + header_length = 0;
Stefan> + }
Stefan> +
Stefan> + next = (struct fw_cdev_iso_packet __user *)
Stefan> + &p->header[header_length / 4];
Stefan> + if (next > end)
Stefan> + return -EINVAL;
Stefan> + if (__copy_from_user
Stefan> + (u.packet.header, p->header, header_length))
Stefan> + return -EFAULT;
Stefan> + if (u.packet.skip && ctx->type == FW_ISO_CONTEXT_TRANSMIT &&
Stefan> + u.packet.header_length + u.packet.payload_length > 0)
Stefan> + return -EINVAL;
Stefan> + if (payload + u.packet.payload_length > buffer_end)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + if (fw_iso_context_queue(ctx, &u.packet,
Stefan> + &client->buffer, payload))
Stefan> + break;
Stefan> +
Stefan> + p = next;
Stefan> + payload += u.packet.payload_length;
Stefan> + count++;
Stefan> + }
Stefan> +
Stefan> + request->size -= uptr_to_u64(p) - request->packets;
Stefan> + request->packets = uptr_to_u64(p);
Stefan> + request->data = client->vm_start + payload;
Stefan> +
Stefan> + return count;
Stefan> +}
Stefan> +
Stefan> +static int ioctl_start_iso(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_start_iso *request = buffer;
Stefan> +
Stefan> + if (request->handle != 0)
Stefan> + return -EINVAL;
Stefan> + if (client->iso_context->type == FW_ISO_CONTEXT_RECEIVE) {
Stefan> + if (request->tags == 0 || request->tags > 15)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + if (request->sync > 15)
Stefan> + return -EINVAL;
Stefan> + }
Stefan> +
Stefan> + return fw_iso_context_start(client->iso_context, request->cycle,
Stefan> + request->sync, request->tags);
Stefan> +}
Stefan> +
Stefan> +static int ioctl_stop_iso(struct client *client, void *buffer) Stefan> +{
Stefan> + struct fw_cdev_stop_iso *request = buffer;
Stefan> +
Stefan> + if (request->handle != 0)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + return fw_iso_context_stop(client->iso_context);
Stefan> +}
Stefan> +
Stefan> +static int (* const ioctl_handlers[])(struct client *client, void *buffer) = {
Stefan> + ioctl_get_info,
Stefan> + ioctl_send_request,
Stefan> + ioctl_allocate,
Stefan> + ioctl_deallocate,
Stefan> + ioctl_send_response,
Stefan> + ioctl_initiate_bus_reset,
Stefan> + ioctl_add_descriptor,
Stefan> + ioctl_remove_descriptor,
Stefan> + ioctl_create_iso_context,
Stefan> + ioctl_queue_iso,
Stefan> + ioctl_start_iso,
Stefan> + ioctl_stop_iso,
Stefan> +};
Stefan> +
Stefan> +static int
Stefan> +dispatch_ioctl(struct client *client, unsigned int cmd, void __user *arg) Stefan> +{
Stefan> + char buffer[256];
Stefan> + int retval;
Stefan> +
Stefan> + if (_IOC_TYPE(cmd) != '#' ||
Stefan> + _IOC_NR(cmd) >= ARRAY_SIZE(ioctl_handlers))
Stefan> + return -EINVAL;
Stefan> +
Stefan> + if (_IOC_DIR(cmd) & _IOC_WRITE) {
Stefan> + if (_IOC_SIZE(cmd) > sizeof buffer ||
Stefan> + copy_from_user(buffer, arg, _IOC_SIZE(cmd)))
Stefan> + return -EFAULT;
Stefan> + }
Stefan> +
Stefan> + retval = ioctl_handlers[_IOC_NR(cmd)](client, buffer);
Stefan> + if (retval < 0)
Stefan> + return retval;
Stefan> +
Stefan> + if (_IOC_DIR(cmd) & _IOC_READ) {
Stefan> + if (_IOC_SIZE(cmd) > sizeof buffer ||
Stefan> + copy_to_user(arg, buffer, _IOC_SIZE(cmd)))
Stefan> + return -EFAULT;
Stefan> + }
Stefan> +
Stefan> + return 0;
Stefan> +}
Stefan> +
Stefan> +static long
Stefan> +fw_device_op_ioctl(struct file *file,
Stefan> + unsigned int cmd, unsigned long arg)
Stefan> +{
Stefan> + struct client *client = file->private_data;
Stefan> +
Stefan> + return dispatch_ioctl(client, cmd, (void __user *) arg);
Stefan> +}
Stefan> +
Stefan> +#ifdef CONFIG_COMPAT
Stefan> +static long
Stefan> +fw_device_op_compat_ioctl(struct file *file,
Stefan> + unsigned int cmd, unsigned long arg)
Stefan> +{
Stefan> + struct client *client = file->private_data;
Stefan> +
Stefan> + return dispatch_ioctl(client, cmd, compat_ptr(arg));
Stefan> +}
Stefan> +#endif
Stefan> +
Stefan> +static int fw_device_op_mmap(struct file *file, struct vm_area_struct *vma) Stefan> +{
Stefan> + struct client *client = file->private_data;
Stefan> + enum dma_data_direction direction;
Stefan> + unsigned long size;
Stefan> + int page_count, retval;
Stefan> +
Stefan> + /* FIXME: We could support multiple buffers, but we don't. */
Stefan> + if (client->buffer.pages != NULL)
Stefan> + return -EBUSY;
Stefan> +
Stefan> + if (!(vma->vm_flags & VM_SHARED))
Stefan> + return -EINVAL;
Stefan> +
Stefan> + if (vma->vm_start & ~PAGE_MASK)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + client->vm_start = vma->vm_start;
Stefan> + size = vma->vm_end - vma->vm_start;
Stefan> + page_count = size >> PAGE_SHIFT;
Stefan> + if (size & ~PAGE_MASK)
Stefan> + return -EINVAL;
Stefan> +
Stefan> + if (vma->vm_flags & VM_WRITE)
Stefan> + direction = DMA_TO_DEVICE;
Stefan> + else
Stefan> + direction = DMA_FROM_DEVICE;
Stefan> +
Stefan> + retval = fw_iso_buffer_init(&client->buffer, client->device->card,
Stefan> + page_count, direction);
Stefan> + if (retval < 0)
Stefan> + return retval;
Stefan> +
Stefan> + retval = fw_iso_buffer_map(&client->buffer, vma);
Stefan> + if (retval < 0)
Stefan> + fw_iso_buffer_destroy(&client->buffer, client->device->card);
Stefan> +
Stefan> + return retval;
Stefan> +}
Stefan> +
Stefan> +static int fw_device_op_release(struct inode *inode, struct file *file) Stefan> +{
Stefan> + struct client *client = file->private_data;
Stefan> + struct event *e, *next_e;
Stefan> + struct client_resource *r, *next_r;
Stefan> + unsigned long flags;
Stefan> +
Stefan> + if (client->buffer.pages)
Stefan> + fw_iso_buffer_destroy(&client->buffer, client->device->card);
Stefan> +
Stefan> + if (client->iso_context)
Stefan> + fw_iso_context_destroy(client->iso_context);
Stefan> +
Stefan> + list_for_each_entry_safe(r, next_r, &client->resource_list, link)
Stefan> + r->release(client, r);
Stefan> +
Stefan> + /* FIXME: We should wait for the async tasklets to stop
Stefan> + * running before freeing the memory. */
Stefan> +
Stefan> + list_for_each_entry_safe(e, next_e, &client->event_list, link)
Stefan> + kfree(e);
Stefan> +
Stefan> + spin_lock_irqsave(&client->device->card->lock, flags);
Stefan> + list_del(&client->link);
Stefan> + spin_unlock_irqrestore(&client->device->card->lock, flags);
Stefan> +
Stefan> + fw_device_put(client->device);
Stefan> + kfree(client);
Stefan> +
Stefan> + return 0;
Stefan> +}
Stefan> +
Stefan> +static unsigned int fw_device_op_poll(struct file *file, poll_table * pt) Stefan> +{
Stefan> + struct client *client = file->private_data;
Stefan> + unsigned int mask = 0;
Stefan> +
Stefan> + poll_wait(file, &client->wait, pt);
Stefan> +
Stefan> + if (fw_device_is_shutdown(client->device))
Stefan> + mask |= POLLHUP | POLLERR;
Stefan> + if (!list_empty(&client->event_list))
Stefan> + mask |= POLLIN | POLLRDNORM;
Stefan> +
Stefan> + return mask;
Stefan> +}
Stefan> +
Stefan> +const struct file_operations fw_device_ops = {
Stefan> + .owner = THIS_MODULE,
Stefan> + .open = fw_device_op_open,
Stefan> + .read = fw_device_op_read,
Stefan> + .unlocked_ioctl = fw_device_op_ioctl,
Stefan> + .poll = fw_device_op_poll,
Stefan> + .release = fw_device_op_release,
Stefan> + .mmap = fw_device_op_mmap,
Stefan> +
Stefan> +#ifdef CONFIG_COMPAT
Stefan> + .compat_ioctl = fw_device_op_compat_ioctl,
Stefan> +#endif
Stefan> +};
Stefan> --
Stefan> Stefan Richter
Stefan> -=====-=-=== -=-= ---=-
Stefan> http://arcgraph.de/sr/
Stefan> -
Stefan> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in Stefan> the body of a message to [email protected]
Stefan> More majordomo info at http://vger.kernel.org/majordomo-info.html
Stefan> Please read the FAQ at http://www.tux.org/lkml/
Stefan> !DSPAM:463882d8304681268012190!
Re: [PATCH 1/6] firewire: handling of cards, buses, nodes
In reply to Stefan Richterdrivers/firewire/fw-card.c line 36
Quoted 7 lines · Stefan Richter
drivers/firewire/fw-card.c new file +7
-0+/* The lib/crc16.c implementation uses the standard (0x8005) +* polynomial, but we need the ITU-T (or CCITT) polynomial (0x1021). +* The implementation below works on an array of host-endian u32 +* words, assuming they'll be transmited msb first. */ +u16 +crc16_itu_t (const u32 *buffer,size_t length) +{
[snip]
So put it in lib/crc-itu-t.c? Btw, there's apparently another ITU-T implementation floating around by Ivo van Doorn.
Re: [PATCH 3/6] firewire: char device interface
In reply to John StoffelQuoted 1 line · John Stoffel
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Stefan" == Stefan Richter <[email protected]> writes:
[...]
Hmm, I'm just spotting some artifacts after a recent file-renaming patch:
Quoted 2 lines
Stefan> ---
/dev/null
Stefan> +++linux_juju/include/linux/firewire-cdev.h
^^^^^^^^^^^^^^^
Quoted 4 lines
Stefan> @@ -0,0 +1,268 @@
Stefan> +/* -*- c-basic-offset: 8 -*-
Stefan> + *
Stefan> + *fw-device-cdev.h-- Char device interface.
^^^^^^^^^^^^^^^^
[...]
Quoted 2 lines
Stefan> +#ifndef
__fw_cdev_h
Stefan> +#define__fw_cdev_h
^^^^^^^^^^^
[...]
Quoted 2 lines
Stefan> +#define
TCODE_WRITE_QUADLET_REQUEST0
Stefan> +#defineTCODE_WRITE_BLOCK_REQUEST1
[...]
Quoted 7 lines
Stefan> +#define
SCODE_1000x0
Stefan> +#defineSCODE_2000x1
Stefan> +#defineSCODE_4000x2
Stefan> +#defineSCODE_8000x3
Stefan> +#defineSCODE_16000x4
Stefan> +#defineSCODE_32000x5
Quoted 5 lines
These are also defined in
fw-transaction.h, though that file doesn't have all the values. Can these just be combined into a singlefw-constants.hfile instead?I honestly haven't checked all your defines....
[...]
Right, there are some overlaps...
Note, firewire-cdev.h declares a userspace ABI, while fw-transaction.h declares an in-kernel API. I'm not quite sure right now how it should rather be organized. Maybe rename fw-transaction.h's macros. Only fw-cdev.c (which implements the userspace ABI) includes both header files.
(PS: I'm not the author; only subsystem maintainer.)
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
Re: [PATCH 6/6] firewire: add it all to kbuild
In reply to Stefan RichterQuoted 1 line · I wrote:
Signed-off-by Stefan Richter <[email protected]>
PS, just to avoid misunderstandings: The "From:" and "Signed-off-by:" in the messages 1/6...6/6 don't signify authorship. Authorship information can be found in linux1394-2.6.git.
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
Quoted 11 lines · Gene Heskett
Quoted 10 lines · Stefan Richter
Quoted 3 lines · Olaf Hering
NACK.
Upgrade the currentdrivers/ieee1394/with the new code, and keep all existing module names.I'm impartial to that. Using same names might ease the transition from the userspace side, as far as there is userland which relies on module names.
A certain drawback of same names would be that geeks cannot install both stacks at once during the transition period.
[...]
Quoted 3 lines
So I'd vote unconditionally to have 2 trees to select
from at module load time until the shakeout has produced usable code in the 2nd tree.
[...]
Quoted 4 lines · Adrian Bunk
An advantage of changing the names is that they are now prefixed. But looking at them, there will again be the point whether everyone will think that "fw" is firmware, and perhaps switching to the (although longer) prefix "firewire" might make sense?
Whatever names the FireWire modules will get, we shouldn't change the names anymore _after_ the new code appears in mainline.
Anyway, if the same names really should be used, as Olaf demands, then it affects at most ohci1394, sbp2, eth1394, ieee1394. However, ieee1394 is probably never loaded explicitly by scripts (only auto-loaded per dependency of the others), and the other three all have proper module aliases.
If the new modules are meant to look like the old ones, then there is also the problem with module parameters. Many of the old stack's module parameters are merely there as hacks or workarounds though; therefore they shouldn't appear in shipped scripts and shipped configurations anyway.
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
Re: [PATCH 1/6] firewire: handling of cards, buses, nodes
In reply to Pekka EnbergQuoted 11 lines · Pekka Enberg
Quoted 7 lines · Stefan Richter
drivers/firewire/fw-card.c new file +7
-0+/* The lib/crc16.c implementation uses the standard (0x8005) +* polynomial, but we need the ITU-T (or CCITT) polynomial (0x1021). +* The implementation below works on an array of host-endian u32 +* words, assuming they'll be transmited msb first. */ +u16 +crc16_itu_t (const u32 *buffer,size_t length) +{[snip]
Quoted 2 lines
So put it in
lib/crc-itu-t.c? Btw, there's apparently another ITU-T implementation floating around by Ivo van Doorn.
I looked around a bit with grep -R and a few search terms but didn't find something definite. Is there any other user of a crc16_itu_t or crc_ccitt or whatever which operates on a (CPU byte ordered) u32[] instead of on a (network byte ordered) u8[]?
The only value in having a shared implementation would be a potentially smaller kernel. Sharing it to ensure correctness is not an issue; fw-topology.c::crc16_itu_t is simply the one in IEEE 1212 table 5. Performance is also not an issue (if better algorithms exist) because the FireWire stack uses it only infrequently on a moderate amount of data.
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
Re: [PATCH 1/6] firewire: handling of cards, buses, nodes
In reply to Stefan RichterQuoted 1 line · Stefan Richter
+/* -*- c-basic-offset: 8 -*-
Please don't pollute the code with annotation for some editors.
Quoted 1 line
+ *
fw-card.c- card level functions
Please don't put the filename into a comment inside the filename. It's not actually useful and it gets out of date very easily.
Quoted 1 line
+static
DECLARE_RWSEM(card_rwsem);
this one is only ever used with down_read/up_read so a normal mutex would probably better suited.
drivers/firewire/fw-card.c line 72
Quoted 9 lines
drivers/firewire/fw-card.c new file +6
-0+static LIST_HEAD (card_list); +#define bib_pmc ((1) << 27) +#define bib_bmc ((1) << 28) +#define bib_isc ((1) << 29) +#define bib_cmc ((1) << 30) +#define bib_imc ((1) << 31)
These are rather odd names for constants. They should at least start with an uppercase letter if not be all uppercase. Also an enum might be right here.
drivers/firewire/fw-card.c line 75
Quoted 2 lines
drivers/firewire/fw-card.c new file +2
-0+static u32 * +generate_config_rom (struct fw_card *card,size_t *config_rom_length)
Please don't put white spaces after the function identifier.
drivers/firewire/fw-card.c line 86
Quoted 6 lines
drivers/firewire/fw-card.c new file +6
-0+/* Initialize contents of config rom buffer. On the OHCI +* controller, block reads to the config rom accesses the host +* memory, but quadlet read access the hardware bus info block +* registers. That's just crack, but it means we should make +* sure the contents of bus info block in host memory mathces +* the version stored in the OHCI registers. */
Normal style for block comments is:
/*
* Initialize contents of config rom buffer. On the OHCI
* controller, block reads to the config rom accesses the host
* memory, but quadlet read access the hardware bus info block
* registers. That's just crack, but it means we should make
* sure the contents of bus info block in host memory mathces
* the version stored in the OHCI registers.
*/
drivers/firewire/fw-topology.h line 55
Quoted 12 lines
drivers/firewire/fw-topology.h new file +12
-0+struct fw_node { +u16 node_id; +u8 color; +u8 port_count; +unsigned link_on :1 ; +unsigned initiated_reset :1 ; +unsigned b_path :1 ; +u8 phy_speed :3 ;/* As in the self ID packet. */ +u8 max_speed :5 ;/* Minimum of all phy-speeds and port 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 */
I don't think we need to save the few bits here and can just use u8 instead of bitfields.
drivers/firewire/fw-topology.c line 268
Quoted 2 lines
drivers/firewire/fw-topology.c new file +2
-0+/* Pop the child nodes off the stack and push the new node. */ +__list_del (h->prev, &stack);
Please don't ever use __list_del directly, it's an interna implementation detail.
I also notices that close to none of the export functions have kerneldoc comment blocks. I think we really should have them on something that is a driver API.
Re: [PATCH 2/6] firewire: isochronous and asynchronous I/O
In reply to Stefan Richterdrivers/firewire/fw-iso.c line 56
Quoted 11 lines
drivers/firewire/fw-iso.c new file +11
-0+for (i =0 ; i < buffer->page_count; i++) { + buffer->pages[i] =alloc_page (GFP_KERNEL |GFP_DMA32 | __GFP_ZERO); +if (buffer->pages[i] ==NULL ) + goto out_pages; + + address =dma_map_page (card->device, buffer->pages[i], +0 ,PAGE_SIZE , direction); +if (dma_mapping_error (address)) { +__free_page (buffer->pages[i]); + goto out_pages; + }
Are you sure using streaming dma mapping is safe here? I don't see actual user in this patch, but doing the proper ownership protocol for them is quite difficult if you reuse them, and allocating them in kernelspace usually means you want to keep reusing them.
Quoted 1 line
+#include <
linux/kthread.h>
You don't actually seem to use this one ..
Quoted 1 line
+#include <
asm/uaccess.h>
.. or this one ..
Quoted 1 line
+#include <
asm/semaphore.h>
.. or this one.
drivers/firewire/fw-transaction.c line 877
Quoted 13 lines
drivers/firewire/fw-transaction.c new file +13
-0+ retval =fw_core_add_address_handler (&topology_map, + &topology_map_region); +BUG_ON (retval <0 ); + + retval =fw_core_add_address_handler (®isters, + ®isters_region); +BUG_ON (retval <0 ); + +/* Add the vendor textual descriptor. */ + retval =fw_core_add_descriptor (&vendor_id_descriptor); +BUG_ON (retval <0 ); + retval =fw_core_add_descriptor (&model_id_descriptor); +BUG_ON (retval <0 );
These kinds of bug checks look wrong. Either the operations can't fail in which case they should not return an error value or you should handle them properly.
Both the previous and this patch contain quite a lot of GFP_ATOMIC allocation which are a sign of not having a very good layering.
Re: [PATCH 3/6] firewire: char device interface
In reply to Stefan Richterinclude/linux/firewire-cdev.h line 26
Quoted 2 lines · Stefan Richter
include/linux/firewire-cdev.h new file +2
-0+#include <asm/ioctl.h> +#include <asm/types.h>
Always use the <linux/ versions.
include/linux/firewire-cdev.h line 155
Quoted 9 lines
include/linux/firewire-cdev.h new file +9
-0+struct fw_cdev_get_info { +/* The version field is just a running serial number. We +* never break backwards compatibility. Userspace passes in +* the version it expects and the kernel passes back the +* highest version it can provide. Even if the structs in +* this interface are extended in a later version, the kernel +* will not copy back more data than what was present in the +* interface version userspace expects. */ +__u32 version;
Please don't even try to build interfaces this complicated. If your current interface needs changes at some point just introduce new ioctls.
Re: [PATCH 5/6] firewire: SBP-2 highlevel driver
In reply to Stefan Richterdrivers/firewire/fw-sbp2.c line 879
Quoted 3 lines
drivers/firewire/fw-sbp2.c new file +3
-0+ sg = (struct scatterlist *)orb->cmd->request_buffer; + count =dma_map_sg (device->card->device, sg, orb->cmd->use_sg, + orb->cmd->sc_data_direction);
you need to handle the error case (count == 0)
drivers/firewire/fw-sbp2.c line 895
Quoted 2 lines
drivers/firewire/fw-sbp2.c new file +2
-0+/* Convert the scatterlist to an sbp2 page table. If any +* scatterlist entries are too big for sbp2 we split the as we go. */
Please set the max_sectors value in your host template so that the block layer doesn't build sg entries too big for you.
drivers/firewire/fw-sbp2.c line 919
Quoted 3 lines
drivers/firewire/fw-sbp2.c new file +3
-0+ orb->page_table_bus = +dma_map_single (device->card->device, orb->page_table, + size,DMA_TO_DEVICE );
This needs handling of mapping errors (dma_mapping_error())
Review
Quoted 1 line
(quoted diff) +1
-0+ orb = kzalloc(sizeof *orb, GFP_ATOMIC);
Normal kernel style is sizeof(*orb)
drivers/firewire/fw-sbp2.c line 1012
Quoted 11 lines
drivers/firewire/fw-sbp2.c new file +11
-0+if (cmd->use_sg) { +sbp2_command_orb_map_scatterlist (orb); + }else if (cmd->request_bufflen >SBP2_MAX_SG_ELEMENT_LENGTH ) { +/* FIXME: Need to split this into a sg list... but +* could we get the scsi or blk layer to do that by +* reporting our max supported block size? */ +fw_error ("command > 64k\n" ); + goto fail_bufflen; + }else if (cmd->request_bufflen >0 ) { +sbp2_command_orb_map_buffer (orb); + }
The use_sg == 0, request_bufflen != 0 case can't happen anymore.
drivers/firewire/fw-sbp2.c line 1034
Quoted 5 lines
+
fail_mapping:drivers/firewire/fw-sbp2.c new file +4
-0+kfree (orb); + fail_alloc: + cmd->result =DID_ERROR <<16 ; +done (cmd);
Failure due to ressource shortage should not complete the command but return SCSI_MLQUEUE_HOST_BUSY/SCSI_MLQUEUE_DEVICE_BUSY.
drivers/firewire/fw-sbp2.c line 1088
Quoted 7 lines
drivers/firewire/fw-sbp2.c new file +6
-0+return 0 ; +} +static struct scsi_host_template scsi_driver_template = { + .module =THIS_MODULE , + .name ="SBP-2 IEEE-1394" , + .proc_name = (char *)sbp2_driver_name,
Please don't use casrs here. Either fix up the definition so it accepts const strings or pass a non-const one.
Quoted 6 lines
drivers/firewire/fw-sbp2.c new file +6
-0+static int add_scsi_devices (struct fw_unit *unit) +{ +struct sbp2_device *sd = unit->device.driver_data; +int retval, lun; + +if (sd->scsi_host !=NULL )
drivers/firewire/fw-sbp2.c line 1115
Quoted 10 lines
drivers/firewire/fw-sbp2.c new file +10
-0+return 0 ; + + sd->scsi_host =scsi_host_alloc (&scsi_driver_template, +sizeof (unsigned long )); +if (sd->scsi_host ==NULL ) { +fw_error ("failed to register scsi host\n" ); +return -1 ; + } + + sd->scsi_host->hostdata[0 ] = (unsigned long )unit;
Please take a look ar ther other scsi drivers how this is supposed to be used.
Quoted 11 lines
drivers/firewire/fw-sbp2.c new file +11
-0+ retval =scsi_add_host (sd->scsi_host, &unit->device); +if (retval <0 ) { +fw_error ("failed to add scsi host\n" ); +scsi_host_put (sd->scsi_host); + sd->scsi_host =NULL ; +return retval; + } + +/* FIXME: Loop over luns here. */ + lun =0 ; + retval =scsi_add_device (sd->scsi_host,0 ,0 , lun);
drivers/firewire/fw-sbp2.c line 1136
Quoted 10 lines
drivers/firewire/fw-sbp2.c new file +10
-0+if (retval <0 ) { +fw_error ("failed to add scsi device\n" ); +scsi_remove_host (sd->scsi_host); +scsi_host_put (sd->scsi_host); + sd->scsi_host =NULL ; +return retval; + } + +return 0 ; +}
Do we really need another scanning algorithm? Can't you use scsi_scan_target instead and let the core scsi code handle the scanning?
drivers/firewire/fw-sbp2.c line 1147
Quoted 11 lines
drivers/firewire/fw-sbp2.c new file +11
-0+ +static void remove_scsi_devices (struct fw_unit *unit) +{ +struct sbp2_device *sd = unit->device.driver_data; + +if (sd->scsi_host !=NULL ) { +scsi_remove_host (sd->scsi_host); +scsi_host_put (sd->scsi_host); + } + sd->scsi_host =NULL ; +}
This function seems rather oddly named. And the checking and setting of scsi_host looks like you have some lifetime rule problems.
Re: [PATCH 6/6] firewire: add it all to kbuild
In reply to Stefan Richterdrivers/firewire/Makefile line 6
Quoted 2 lines
drivers/firewire/Makefile new file +2
-0+fw-core-objs := fw-card.o fw-topology.o fw-transaction.o fw-iso.o \ + fw-device.o fw-cdev.o
fw-core-y += ..
Quoted 7 lines · Olaf Hering
Quoted 1 line · Kristian Høgsberg
drivers/firewire/Kconfig | 60 ++NACK.
Upgrade the currentdrivers/ieee1394/with the new code, and keep all existing module names.
What's your reasoning here? Having different module names allows people to compile both stacks and switch between them as they wish.
Another point in favour of different module names is that the new stack doesn't actually provide the same user space interfaces as the old stack. Basically, no applications use the raw kernel interfaces and the new stack is only compatible at the library level. In the light of this, I think it's fair to change the module names.
As for putting the new stack in drivers/ieee1394 - I don't know, I think it makes sense to keep the new stack in it's own directory. If it's a deal breaker for inclusion, let's talk about moving it, but it would be nice if you could elaborate just a little bit beyond "NACK".
thanks,
Kristian
Quoted 10 lines · Kristian Høgsberg
Quoted 7 lines · Olaf Hering
Quoted 1 line · Kristian Høgsberg
drivers/firewire/Kconfig | 60 ++NACK.
Upgrade the currentdrivers/ieee1394/with the new code, and keep all existing module names.What's your reasoning here?
Whats the upgrade path for root on sbp2?
Right now mkinitrd puts 'ohci1394 spb2' into the initrd because both names are stored in a config file. How does one configure that config file to have a setup that works with kernels which provide only drivers/ieee1394 and a newer ones which provide only drivers/firewire?
Quoted 24 lines · Adrian Bunk
Quoted 23 lines · Stefan Richter
Quoted 5 lines · Olaf Hering
Quoted 1 line · Kristian Høgsberg
drivers/firewire/Kconfig | 60 ++NACK.
Upgrade the currentdrivers/ieee1394/with the new code,Last time I believe I was the only one who asked whether to put it into
drivers/ieee1394instead of another directory. Of course I acknowledge that everytime a new review round is started, people do reconsider. Especially since we had a gap of a few months since the last LKML review.Quoted 1 line
and keep all existing module names.
I'm impartial to that. Using same names might ease the transition from the userspace side, as far as there is userland which relies on module names.
A certain drawback of same names would be that geeks cannot install both stacks at once during the transition period. Therefore, checking whether eventual problems are in fact regressions involves a module unload/ configure/ build/ install/ reload cycle, instead of just module unload/ reload. This especially means we can only get help from testers who are able to build kernels.
Quoted 4 lines
Quoted 1 line
Other opinions?
An advantage of changing the names is that they are now prefixed.
But looking at them, there will again be the point whether everyone will think that "fw" is firmware, and perhaps switching to the (although longer) prefix "firewire" might make sense?
I like "firewire" better, I'm already using that for the userspace header file. Renaming the modules to firewire-core, firewire-ohci and firewire-sbp2 sounds good to me.
Kristian
Quoted 1 line · Stefan Richter
Christoph Hellwig wrote:
..
Quoted 5 lines
Quoted 1 line
Please send out patches for review first.
Yes, it's been a while since the last submission for review [1], and most of the changes went over linux1394-devel only. And to put it mildly, there aren't a lot of capable reviewers watching that list.
...
Quoted 2 lines
(If this division seems odd, don't blame Kristian, blame me. :-) I'm looking forward to comments.
Looks good to me, thanks Stefan. The first three patches don't compile on their own as they are, but it's a good split of the core stack.
Kristian
Re: [PATCH 1/6] firewire: handling of cards, buses, nodes
In reply to Stefan RichterQuoted 4 lines · Stefan Richter
I looked around a bit with grep -R and a few search terms but didn't find something definite. Is there any other user of a
crc16_itu_torcrc_ccittor whatever which operates on a (CPU byte ordered) u32[] instead of on a (network byte ordered) u8[]?
I was referring to this: http://lkml.org/lkml/2006/6/12/137
Quoted 5 lines · Stefan Richter
The only value in having a shared implementation would be a potentially smaller kernel. Sharing it to ensure correctness is not an issue; fw-topology.c::crc16_itu_t is simply the one in IEEE 1212 table 5. Performance is also not an issue (if better algorithms exist) because the FireWire stack uses it only infrequently on a moderate amount of data.
Yeah, it's not a biggie, but we do have a tradition of putting generally useful things into lib/ so that everyone doesn't invent their own.
Re: [PATCH 3/6] firewire: char device interface
In reply to John StoffelQuoted 9 lines · John Stoffel
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Stefan" == Stefan Richter <[email protected]> writes:
Stefan> Signed-off-by: Stefan Richter <[email protected]> Stefan> ---
Stefan> drivers/firewire/fw-cdev.c | 954 ++++++++++++++++++++++++++++++++++ Stefan> include/linux/firewire-cdev.h | 268 +++++++++ Stefan> 2 files changed, 1222 insertions(+)Stefan> Index:
linux_juju/include/linux/firewire-cdev.h
...
Quoted 13 lines
Stefan> +#define
RCODE_SEND_ERROR0x10
Stefan> +#defineRCODE_CANCELLED0x11
Stefan> +#defineRCODE_BUSY0x12
Stefan> +#defineRCODE_GENERATION0x13
Stefan> +#defineRCODE_NO_ACK0x14
Stefan> +
Stefan> +#defineSCODE_1000x0
Stefan> +#defineSCODE_2000x1
Stefan> +#defineSCODE_4000x2
Stefan> +#defineSCODE_8000x3
Stefan> +#defineSCODE_16000x4
Stefan> +#defineSCODE_32000x5
Quoted 5 lines
These are also defined in
fw-transaction.h, though that file doesn't have all the values. Can these just be combined into a singlefw-constants.hfile instead?I honestly haven't checked all your defines....
The firewire-cdev.h file is meant to be a self-contained userspace header file and shouldn't include other kernel header files. All duplicated values are standardized ieee1394 values and won't ever change. I should put a #ifndef __FW_COMMON_DEFINES protection around the duplicate values, I guess, but I'm just wondering why I never saw a "symbol redefined" warning...
Kristian
Re: [PATCH 1/6] firewire: handling of cards, buses, nodes
In reply to Pekka EnbergQuoted 11 lines · Pekka Enberg
Quoted 7 lines · Stefan Richter
drivers/firewire/fw-card.c new file +7
-0+/* The lib/crc16.c implementation uses the standard (0x8005) +* polynomial, but we need the ITU-T (or CCITT) polynomial (0x1021). +* The implementation below works on an array of host-endian u32 +* words, assuming they'll be transmited msb first. */ +u16 +crc16_itu_t (const u32 *buffer,size_t length) +{[snip]
Quoted 2 lines
So put it in
lib/crc-itu-t.c? Btw, there's apparently another ITU-T implementation floating around by Ivo van Doorn.
I looked into this a while back, and the kernel does have a CCITT based crc16 function. The problem is that it works on the opposite bit order from what I need, so to use it I'll have to bitswap every byte as it goes in and then bitswap the resulting crc16. That's more code and probably less efficient than just implementing the crc itself. I wouldn't mind moving it to lib/ though, but nobody else in the kernel is using this bit order.
Kristian
Re: [PATCH 5/6] firewire: SBP-2 highlevel driver
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
drivers/firewire/fw-sbp2.c line 895
Quoted 2 lines
drivers/firewire/fw-sbp2.c new file +2
-0+/* Convert the scatterlist to an sbp2 page table. If any +* scatterlist entries are too big for sbp2 we split the as we go. */ Please set the
max_sectorsvalue in your host template so that the block layer doesn't build sg entries too big for you.
Hmm, what about this:
James Bottomley wrote on 2007-01-15:
| Actually, there's one unfortunate case where Linux won't respect this: | an IOMMU that can do virtual merging. This parameter is a block queue | parameter, so block will happily make sure the request segments obey it. | However, when you get to dma_map_rq() it doesn't see the segment limits, | so, if the iommu merges, you can end up with SG elements the other side | that violate this. I've been meaning to do something about this for | ages (IDE is the other subsystem that has an absolute requirement for a | fixed maximum segment size) but never found an excuse to fix it.
http://marc.info/?l=linux-scsi&m=116889641203397
Quoted 11 lines
Quoted 11 lines
drivers/firewire/fw-sbp2.c new file +11
-0+static int add_scsi_devices (struct fw_unit *unit) +{ +struct sbp2_device *sd = unit->device.driver_data; +int retval, lun; + +if (sd->scsi_host !=NULL ) +return 0 ; + + sd->scsi_host =scsi_host_alloc (&scsi_driver_template, +sizeof (unsigned long )); +if (sd->scsi_host ==NULL ) {
Quoted 8 lines
drivers/firewire/fw-sbp2.c line 1115
Quoted 5 lines
drivers/firewire/fw-sbp2.c new file +5
-0+fw_error ("failed to register scsi host\n" ); +return -1 ; + } + + sd->scsi_host->hostdata[0 ] = (unsigned long )unit;Please take a look ar ther other scsi drivers how this is supposed to be used.
Do you mean the one Scsi_Host per LU? If it is that, then it was just taken over from drivers/ieee1394/sbp2.c. Sbp2 is doing this still today mostly for historical reasons; I just didn't find the time yet to try to get to a leaner scheme.
Or do you mean something else?
Quoted 15 lines
Quoted 15 lines
drivers/firewire/fw-sbp2.c new file +15
-0+ retval =scsi_add_host (sd->scsi_host, &unit->device); +if (retval <0 ) { +fw_error ("failed to add scsi host\n" ); +scsi_host_put (sd->scsi_host); + sd->scsi_host =NULL ; +return retval; + } + +/* FIXME: Loop over luns here. */ + lun =0 ; + retval =scsi_add_device (sd->scsi_host,0 ,0 , lun); +if (retval <0 ) { +fw_error ("failed to add scsi device\n" ); +scsi_remove_host (sd->scsi_host); +scsi_host_put (sd->scsi_host);
Quoted 8 lines
drivers/firewire/fw-sbp2.c line 1136
Quoted 6 lines
drivers/firewire/fw-sbp2.c new file +6
-0+ sd->scsi_host =NULL ; +return retval; + } + +return 0 ; +}Do we really need another scanning algorithm?
Yes.
Quoted 2 lines
Can't you use
scsi_scan_targetinstead and let the core scsi code handle the scanning?
No. The discovery of LUs of SBP-2 targets happens on the IEEE 1212 level of things. The initiator has to parse the configuration ROM of the target FireWire node; the ROM has entries for each LU. (After that, SBP-2 login protocol commences for each LU, and only after that can SCSI requests be issued. There is nothing SCSIish going on before that.)
What's missing as a /* FIXME */ here is actually implemented in the mainline sbp2.c and needs to be brought over here; converted to the new FireWire core APIs.
Quoted 7 lines
Quoted 7 lines
drivers/firewire/fw-sbp2.c new file +7
-0+ +static void remove_scsi_devices (struct fw_unit *unit) +{ +struct sbp2_device *sd = unit->device.driver_data; + +if (sd->scsi_host !=NULL ) { +scsi_remove_host (sd->scsi_host);
Quoted 9 lines
drivers/firewire/fw-sbp2.c line 1133
Quoted 4 lines
drivers/firewire/fw-sbp2.c new file +4
-0+scsi_host_put (sd->scsi_host); + } + sd->scsi_host =NULL ; +}This function seems rather oddly named. And the checking and setting of
scsi_hostlooks like you have some lifetime rule problems.
The NULL probably has to do with the ability to call remove_scsi_devices in different paths. (These paths are not concurrent.)
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---=- http://arcgraph.de/sr/
Re: [PATCH 5/6] firewire: SBP-2 highlevel driver
Quoted 18 lines · I wrote:
Quoted 4 lines · Christoph Hellwig
drivers/firewire/fw-sbp2.c line 895
Quoted 2 lines
drivers/firewire/fw-sbp2.c new file +2
-0+/* Convert the scatterlist to an sbp2 page table. If any +* scatterlist entries are too big for sbp2 we split the as we go. */ Please set the
max_sectorsvalue in your host template so that the block layer doesn't build sg entries too big for you.Hmm, what about this:
James Bottomley wrote on 2007-01-15:
| Actually, there's one unfortunate case where Linux won't respect this: | an IOMMU that can do virtual merging. This parameter is a block queue | parameter, so block will happily make sure the request segments obey it. | However, when you get to dma_map_rq() it doesn't see the segment limits, | so, if the iommu merges, you can end up with SG elements the other side | that violate this. I've been meaning to do something about this for | ages (IDE is the other subsystem that has an absolute requirement for a | fixed maximum segment size) but never found an excuse to fix it.
Quoted 1 line
PS:
Nonetheless, yes, fw-sbp2.c is curiously missing to set the template's max_sectors.
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---== http://arcgraph.de/sr/
Re: [PATCH 6/6] firewire: add it all to kbuild
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
Review
Quoted 2 lines
(quoted diff) +2
-0+fw-core-objs := fw-card.o fw-topology.o fw-transaction.o fw-iso.o \ + fw-device.o fw-cdev.ofw-core-y += ..
Like such?
drivers/usb/core/Makefile +3 -8
@@ -2,17 +2,12 @@ # Makefile for USB Core files and filesystem # -usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ +usbcore-y += usb.o hub.o hcd.o urb.o message.o driver.o \ config.o file.o buffer.o sysfs.o endpoint.o \ devio.o notify.o generic.o quirks.o -ifeq ($(CONFIG_PCI),y) - usbcore-objs += hcd-pci.o -endif - -ifeq ($(CONFIG_USB_DEVICEFS),y) - usbcore-objs += inode.o devices.o -endif +usbcore-$(CONFIG_PCI) += hcd-pci.o +usbcore-$(CONFIG_USB_DEVICEFS) += inode.o devices.o obj-$(CONFIG_USB) += usbcore.o
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---== http://arcgraph.de/sr/
Re: [PATCH 2/6] firewire: isochronous and asynchronous I/O
In reply to Christoph HellwigQuoted 8 lines · Christoph Hellwig
Quoted 8 lines
drivers/firewire/fw-iso.c new file +8
-0+for (i =0 ; i < buffer->page_count; i++) { + buffer->pages[i] =alloc_page (GFP_KERNEL |GFP_DMA32 | __GFP_ZERO); +if (buffer->pages[i] ==NULL ) + goto out_pages; + + address =dma_map_page (card->device, buffer->pages[i], +0 ,PAGE_SIZE , direction); +if (dma_mapping_error (address)) {
Quoted 8 lines
drivers/firewire/fw-iso.c line 56
Quoted 3 lines
drivers/firewire/fw-iso.c new file +3
-0+__free_page (buffer->pages[i]); + goto out_pages; + }Are you sure using streaming dma mapping is safe here? I don't see actual user in this patch, but doing the proper ownership protocol for them is quite difficult if you reuse them, and allocating them in kernelspace usually means you want to keep reusing them.
What other options are there? The only user in the stack is the userspace interface, which lets you mmap the pages in the iso_buffer from an application. The pages need to stay around and stay mapped as long as that buffer is mmapped by userspace. The buffer can be several megabytes and I don't want to set up a kernel side virtual mapping for it. The pages are only used for either outgoing or incoming data, never both, so device/driver ownership isn't too difficult to handle.
Quoted 11 lines
Quoted 1 line
+#include <
linux/kthread.h>You don't actually seem to use this one ..
Quoted 1 line
+#include <
asm/uaccess.h>.. or this one ..
Quoted 1 line
+#include <
asm/semaphore.h>.. or this one.
Ah, right, I'll get rid of those.
Quoted 9 lines
Quoted 9 lines
drivers/firewire/fw-transaction.c new file +9
-0+ retval =fw_core_add_address_handler (&topology_map, + &topology_map_region); +BUG_ON (retval <0 ); + + retval =fw_core_add_address_handler (®isters, + ®isters_region); +BUG_ON (retval <0 ); + +/* Add the vendor textual descriptor. */
Quoted 8 lines
drivers/firewire/fw-transaction.c line 877
Quoted 4 lines
drivers/firewire/fw-transaction.c new file +4
-0+ retval =fw_core_add_descriptor (&vendor_id_descriptor); +BUG_ON (retval <0 ); + retval =fw_core_add_descriptor (&model_id_descriptor); +BUG_ON (retval <0 );These kinds of bug checks look wrong. Either the operations can't fail in which case they should not return an error value or you should handle them properly.
The fw_core_add_descriptor() checks that the descriptor block it's passed is internally consistent and is used for blocks passed in from userspace too. In these two cases, the blocks are static const arrays in the driver and if fw_core_add_descriptor returns < 0 it's a bug in the driver.
Quoted 2 lines
Both the previous and this patch contain quite a lot of
GFP_ATOMICallocation which are a sign of not having a very good layering.
Looking through the GFP_ATOMIC allocations, I see a couple that could be rolled back to GFP_KERNEL. But I don't know that it means bad layering, I'm just typically using a GFP_ATOMIC kmalloc than, preallocating some fixed number of, say, packets or nodes or whatever. For example, the old SBP-2 (storage) driver uses a free-list of packets and grabs one from that list when the SCSI stacks asks it to send a request. If that list is empty, it fails and lets the SCSI stack retry the command. I'm using a GFP_ATOMIC kmalloc instead in that case, and I believe it's a better approach than implementing ad-hoc allocation data structures.
Thanks for the reviews, I'll look through your other emails. Kristian
Re: [PATCH 6/6] firewire: add it all to kbuild
In reply to Stefan RichterQuoted 8 lines · Stefan Richter
Quoted 5 lines · Christoph Hellwig
Review
Quoted 2 lines
(quoted diff) +2
-0+fw-core-objs := fw-card.o fw-topology.o fw-transaction.o fw-iso.o \ + fw-device.o fw-cdev.ofw-core-y += ..
Like such?
Yes - the latter is much more readable.
Sam
Quoted 34 lines
drivers/usb/core/Makefile +3
-8@@ -2,17 +2,12 @@ # Makefile for USB Core files and filesystem # -usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ +usbcore-y += usb.o hub.o hcd.o urb.o message.o driver.o \ config.o file.o buffer.o sysfs.o endpoint.o \ devio.o notify.o generic.o quirks.o -ifeq ($(CONFIG_PCI),y) - usbcore-objs += hcd-pci.o -endif - -ifeq ($(CONFIG_USB_DEVICEFS),y) - usbcore-objs += inode.o devices.o -endif +usbcore-$(CONFIG_PCI) += hcd-pci.o +usbcore-$(CONFIG_USB_DEVICEFS) += inode.o devices.o obj-$(CONFIG_USB) += usbcore.oSignature · 9 lines
-- Stefan Richter -=====-=-=== -=-= ---== http://arcgraph.de/sr/ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 6/6] firewire: add it all to kbuild
In reply to Stefan RichterQuoted 8 lines · Stefan Richter
Quoted 5 lines · Christoph Hellwig
Review
Quoted 2 lines
(quoted diff) +2
-0+fw-core-objs := fw-card.o fw-topology.o fw-transaction.o fw-iso.o \ + fw-device.o fw-cdev.ofw-core-y += ..
Like such?
Exactly.
Quoted 22 lines
drivers/usb/core/Makefile +3
-8@@ -2,17 +2,12 @@ # Makefile for USB Core files and filesystem # -usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ +usbcore-y += usb.o hub.o hcd.o urb.o message.o driver.o \ config.o file.o buffer.o sysfs.o endpoint.o \ devio.o notify.o generic.o quirks.o -ifeq ($(CONFIG_PCI),y) - usbcore-objs += hcd-pci.o -endif - -ifeq ($(CONFIG_USB_DEVICEFS),y) - usbcore-objs += inode.o devices.o -endif +usbcore-$(CONFIG_PCI) += hcd-pci.o +usbcore-$(CONFIG_USB_DEVICEFS) += inode.o devices.o obj-$(CONFIG_USB) += usbcore.o
Re: [PATCH 2/6] firewire: isochronous and asynchronous I/O
In reply to Kristian HøgsbergQuoted 1 line · Kristian Høgsberg
Christoph Hellwig wrote:
[...]
Quoted 11 lines
Quoted 6 lines
drivers/firewire/fw-transaction.c line 877
Quoted 2 lines
drivers/firewire/fw-transaction.c new file +2
-0+ retval =fw_core_add_descriptor (&model_id_descriptor); +BUG_ON (retval <0 );These kinds of bug checks look wrong. Either the operations can't fail in which case they should not return an error value or you should handle them properly.
The
fw_core_add_descriptor()checks that the descriptor block it's passed is internally consistent and is used for blocks passed in from userspace too. In these two cases, the blocks are static const arrays in the driver and iffw_core_add_descriptorreturns < 0 it's a bug in the driver.
When you submitted it, I too wondered whether these BUG_ONs are correct (they are) and whether they are worth having (not so sure).
A plus of a smaller stack is that we need less assertions to guard its integrity. :-)
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= ---== http://arcgraph.de/sr/
Re: [PATCH 3/6] firewire: char device interface
In reply to Kristian HøgsbergQuoted 6 lines · Kristian H??gsberg
The
firewire-cdev.hfile is meant to be a self-contained userspace header file and shouldn't include other kernel header files. All duplicated values are standardized ieee1394 values and won't ever change. I should put a #ifndef__FW_COMMON_DEFINESprotection around the duplicate values, I guess, but I'm just wondering why I never saw a "symbol redefined" warning...
No, defining things in two places is not okay. Just add a new header that defines these protocol constants, which needs to be included by userspace that wants to use them.
Re: [PATCH 5/6] firewire: SBP-2 highlevel driver
In reply to Stefan RichterQuoted 15 lines · Stefan Richter
Quoted 2 lines
Please set the
max_sectorsvalue in your host template so that the block layer doesn't build sg entries too big for you.Hmm, what about this:
James Bottomley wrote on 2007-01-15:
| Actually, there's one unfortunate case where Linux won't respect this: | an IOMMU that can do virtual merging. This parameter is a block queue | parameter, so block will happily make sure the request segments obey it. | However, when you get to dma_map_rq() it doesn't see the segment limits, | so, if the iommu merges, you can end up with SG elements the other side | that violate this. I've been meaning to do something about this for | ages (IDE is the other subsystem that has an absolute requirement for a | fixed maximum segment size) but never found an excuse to fix it.
Quoted 1 line
Hmm, okay. Probably wants a comment in there explaining it, and we should poke jejb to fix it for real :)
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
drivers/firewire/fw-sbp2.c new file +11
-0+static int add_scsi_devices (struct fw_unit *unit) +{ +struct sbp2_device *sd = unit->device.driver_data; +int retval, lun; + +if (sd->scsi_host !=NULL ) +return 0 ; + + sd->scsi_host =scsi_host_alloc (&scsi_driver_template, +sizeof (unsigned long )); +if (sd->scsi_host ==NULL ) {Quoted 8 lines
drivers/firewire/fw-sbp2.c line 1115
Quoted 5 lines
drivers/firewire/fw-sbp2.c new file +5
-0+fw_error ("failed to register scsi host\n" ); +return -1 ; + } + + sd->scsi_host->hostdata[0 ] = (unsigned long )unit;Please take a look ar ther other scsi drivers how this is supposed to be used.
Quoted 4 lines
Do you mean the one
Scsi_Hostper LU? If it is that, then it was just taken over fromdrivers/ieee1394/sbp2.c. Sbp2 is doing this still today mostly for historical reasons; I just didn't find the time yet to try to get to a leaner scheme.
No, sorry. I should have written a better explanation. scsi_host_alloc is designed to allocate space for your private data aswell. So you should call it early on an allocate the sbp2_device as part of the Scsi_Host instead of just stuffing in a pointer.
Quoted 13 lines
Quoted 1 line
Do we really need another scanning algorithm?
Yes.
Quoted 2 lines
Can't you use
scsi_scan_targetinstead and let the core scsi code handle the scanning?No. The discovery of LUs of SBP-2 targets happens on the IEEE 1212 level of things. The initiator has to parse the configuration ROM of the target FireWire node; the ROM has entries for each LU. (After that, SBP-2 login protocol commences for each LU, and only after that can SCSI requests be issued. There is nothing SCSIish going on before that.)
Quoted 3 lines
What's missing as a /* FIXME */ here is actually implemented in the mainline
sbp2.cand needs to be brought over here; converted to the new FireWire core APIs.
Okay, so sbp2 decided to be non-standard here, what a pity. It's probably better to use scsi_scan_target with a specific lun, though as scsi_add_device is a rather awkward API.
Quoted 7 lines
Quoted 4 lines
This function seems rather oddly named. And the checking and setting of
scsi_hostlooks like you have some lifetime rule problems.The NULL probably has to do with the ability to call
remove_scsi_devicesin different paths. (These paths are not concurrent.)
Needs documentation at least. And at least my preference would be to have a deleted flag instead of the null setting because the latter can easily paper over bugs.
Re: [PATCH 4/6] firewire: OHCI-1394 lowlevel driver
In reply to Stefan RichterQuoted 43 lines
drivers/firewire/fw-ohci.c new file +43
-0+/* ---------- pci subsystem interface ---------- */ + +enum { +CLEANUP_SELF_ID , +CLEANUP_REGISTERS , +CLEANUP_IOMEM , +CLEANUP_DISABLE , +CLEANUP_PUT_CARD , +}; + +static int cleanup (struct fw_ohci *ohci,int stage,int code) +{ +struct pci_dev *dev =to_pci_dev (ohci->card.device); + +switch (stage) { +case CLEANUP_SELF_ID : +dma_free_coherent (ohci->card.device,SELF_ID_BUF_SIZE , + ohci->self_id_cpu, ohci->self_id_bus); +case CLEANUP_REGISTERS : +kfree (ohci->it_context_list); +kfree (ohci->ir_context_list); +pci_iounmap (dev, ohci->registers); +case CLEANUP_IOMEM : +pci_release_region (dev,0 ); +case CLEANUP_DISABLE : +pci_disable_device (dev); +case CLEANUP_PUT_CARD : +fw_card_put (&ohci->card); + } + +return code; +} + +static int __devinit +pci_probe (struct pci_dev *dev,const struct pci_device_id *ent) +{ +struct fw_ohci *ohci; +u32 bus_options, max_receive, link_speed; +u64 guid; +int error_code; +size_t size; + + ohci =kzalloc (sizeof *ohci,GFP_KERNEL );
drivers/firewire/fw-ohci.c line 1728
Quoted 10 lines
drivers/firewire/fw-ohci.c new file +10
-0+if (ohci ==NULL ) { +fw_error ("Could not malloc fw_ohci data.\n" ); +return -ENOMEM ; + } + +fw_card_initialize (&ohci->card, &ohci_driver, &dev->dev); + +if (pci_enable_device (dev)) { +fw_error ("Failed to enable OHCI hardware.\n" ); +return cleanup (ohci,CLEANUP_PUT_CARD , -ENODEV );
Please use normal goto unwinding so the driver follows the same model as almost all other pci drivers and allows people to follow your driver more easily. Also it's not a alot of cleanup code, so removing this might actually be a net decrease in lines of code.
drivers/firewire/fw-ohci.c line 1751
Quoted 1 line
drivers/firewire/fw-ohci.c new file +1
-0+if (software_reset (ohci)) {
Please give all your function a nice prefix so that oops messages are more readable.
Re: [PATCH 5/6] firewire: SBP-2 highlevel driver
In reply to Christoph HellwigQuoted 1 line · Christoph Hellwig
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/firewire/fw-sbp2.c new file +1
-0+ sd->scsi_host->hostdata[0 ] = (unsigned long )unit;
...
Quoted 4 lines
scsi_host_alloc
is designed to allocate space for your private data aswell. So you should call it early on an allocate thesbp2_deviceas part of theScsi_Hostinstead of just stuffing in a pointer.
Aha, OK.
As long as we have 1 SBP-2 target LU == 1 instance of struct Scsi_Host, the usage of ->hostdata as backpointer to an fw_unit is appropriate though. The lifetime of the fw_unit starts before and ends after that of the Scsi_Host. Of course if we reorganize this to use Scsi_Host more as a representation of an SBP-2 initiator port (or for all our initiator ports at once), some oddities like this ->hostdata usage will go away.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
The discovery of LUs of SBP-2 targets happens on the IEEE 1212 level of things.
[...]
Quoted 1 line
Okay, so sbp2 decided to be non-standard here, what a pity.
Well, SBP-2 (the spec) is from the earlier days when the SCSI Architecture Model was young and there didn't exist that many other SCSI transports/interconnects besides SCSI Parallel Interconnect. And for better or worse, SBP-3 inherited this part of SBP-2's specialties.
Quoted 2 lines
It's probably better to use
scsi_scan_targetwith a specific lun, though asscsi_add_deviceis a rather awkward API.
Looking into these things were on my long-term agenda for mainline's sbp2 driver anyway. My plans just got dragged out when I expanded my activities from ieee1394/sbp2 to ieee1394/. As far as fw-sbp2 is concerned, I don't know if these issues (which it merely took over from sbp2) need to be addressed before integration into mainline. fw-sbp2 is something in the middle between a new submission and a gradual update.
Do you see the TODOs related to integration with the SCSI stack (which apply to sbp2 as well) as blocking for fw-sbp2?
Thanks for looking into it and for all the advice,
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= --=-- http://arcgraph.de/sr/
Re: [PATCH 1/6] firewire: handling of cards, buses, nodes
In reply to Pekka EnbergQuoted 7 lines · Pekka Enberg
Quoted 4 lines · Stefan Richter
I looked around a bit with grep -R and a few search terms but didn't find something definite. Is there any other user of a
crc16_itu_torcrc_ccittor whatever which operates on a (CPU byte ordered) u32[] instead of on a (network byte ordered) u8[]?I was referring to this: http://lkml.org/lkml/2006/6/12/137
That works. If you look closely, you can see that the ITU-T table is just
crc_itu_t_table[i] = bitrev16(crc_ccitt_table[bitrev8(i)])
but that's a expensive enough operation that I think it deserves its own table. Especially if there's another driver out there that needs this.
Quoted 10 lines · Stefan Richter
Quoted 5 lines
The only value in having a shared implementation would be a potentially smaller kernel. Sharing it to ensure correctness is not an issue; fw-topology.c::crc16_itu_t is simply the one in IEEE 1212 table 5. Performance is also not an issue (if better algorithms exist) because the FireWire stack uses it only infrequently on a moderate amount of data.
Yeah, it's not a biggie, but we do have a tradition of putting generally useful things into
lib/so that everyone doesn't invent their own.
I'll pull in Ivo's patch and add it to the firewire branch.
thanks,
Kristian
Re: [PATCH 1/6] firewire: handling of cards, buses, nodes
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Quoted 1 line · Stefan Richter
+/* -*- c-basic-offset: 8 -*-
Please don't pollute the code with annotation for some editors.
OK.
Quoted 4 lines
Quoted 1 line
+ *
fw-card.c- card level functionsPlease don't put the filename into a comment inside the filename. It's not actually useful and it gets out of date very easily.
Yeah, true.
Quoted 4 lines
Quoted 1 line
+static
DECLARE_RWSEM(card_rwsem);this one is only ever used with down_read/up_read so a normal mutex would probably better suited.
down_write/up_write, but yes, I'll change that to a mutex. The card_rwsem was previously subsystem.rwsem, but that went away.
Quoted 4 lines
Quoted 1 line
+static
LIST_HEAD(card_list);
Quoted 9 lines
drivers/firewire/fw-card.c line 72
Quoted 5 lines
drivers/firewire/fw-card.c new file +5
-0+#define bib_pmc ((1) << 27) +#define bib_bmc ((1) << 28) +#define bib_isc ((1) << 29) +#define bib_cmc ((1) << 30) +#define bib_imc ((1) << 31)These are rather odd names for constants. They should at least start with an uppercase letter if not be all uppercase. Also an enum might be right here.
Sure, I'll do that... all those uppercase letters hurt my eyes, though.
Quoted 4 lines
drivers/firewire/fw-card.c line 75
Quoted 2 lines
drivers/firewire/fw-card.c new file +2
-0+static u32 * +generate_config_rom (struct fw_card *card,size_t *config_rom_length)Please don't put white spaces after the function identifier.
Ugh, yeah, I don't know why I keep doing that...
Quoted 9 lines
drivers/firewire/fw-card.c line 86
Quoted 6 lines
drivers/firewire/fw-card.c new file +6
-0+/* Initialize contents of config rom buffer. On the OHCI +* controller, block reads to the config rom accesses the host +* memory, but quadlet read access the hardware bus info block +* registers. That's just crack, but it means we should make +* sure the contents of bus info block in host memory mathces +* the version stored in the OHCI registers. */ Normal style for block comments is:
Quoted 8 lines
/*
* Initialize contents of config rom buffer. On the OHCI
* controller, block reads to the config rom accesses the host
* memory, but quadlet read access the hardware bus info block
* registers. That's just crack, but it means we should make
* sure the contents of bus info block in host memory mathces
* the version stored in the OHCI registers.
*/
Oh, ok, I can clean that up.
Quoted 7 lines
Quoted 7 lines
drivers/firewire/fw-topology.h new file +7
-0+struct fw_node { +u16 node_id; +u8 color; +u8 port_count; +unsigned link_on :1 ; +unsigned initiated_reset :1 ; +unsigned b_path :1 ;
Quoted 8 lines
drivers/firewire/fw-topology.h line 55
Quoted 5 lines
drivers/firewire/fw-topology.h new file +5
-0+ u8 phy_speed : 3; /* As in the self ID packet. */ + u8 max_speed : 5; /* Minimum of all phy-speeds and port 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 */I don't think we need to save the few bits here and can just use u8 instead of bitfields.
These bitfields aren't used on the wire or anywhere outside the driver... what the problem? Perfomance?
Quoted 5 lines
drivers/firewire/fw-topology.c line 268
Quoted 2 lines
drivers/firewire/fw-topology.c new file +2
-0+/* Pop the child nodes off the stack and push the new node. */ +__list_del (h->prev, &stack);Please don't ever use
__list_deldirectly, it's an interna implementation detail.
Do you have an alternative suggestion here? I need to take a sub-list of the list, which is exactly what __list_del does. I could loop through the sublist, but it's pretty pointless since I have both ends of the sublist.
Quoted 3 lines
I also notices that close to none of the export functions have kerneldoc comment blocks. I think we really should have them on something that is a driver API.
Yeah... I'll sit down and try to document it better.
thanks
Kristian
Re: [PATCH 3/6] firewire: char device interface
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
include/linux/firewire-cdev.h line 26
Quoted 2 lines · Stefan Richter
include/linux/firewire-cdev.h new file +2
-0+#include <asm/ioctl.h> +#include <asm/types.h> Always use the <linux/ versions.
Fixed.
Quoted 4 lines
Quoted 4 lines
include/linux/firewire-cdev.h new file +4
-0+struct fw_cdev_get_info { +/* The version field is just a running serial number. We +* never break backwards compatibility. Userspace passes in +* the version it expects and the kernel passes back the
Quoted 8 lines
include/linux/firewire-cdev.h line 155
Quoted 5 lines
include/linux/firewire-cdev.h new file +5
-0+* highest version it can provide. Even if the structs in +* this interface are extended in a later version, the kernel +* will not copy back more data than what was present in the +* interface version userspace expects. */ +__u32 version;Please don't even try to build interfaces this complicated. If your current interface needs changes at some point just introduce new ioctls.
Sure, I don't expect a lot of changes anyway, and the few features I know that will show up down the road are strictly additions anyway. I think it makes sense to keep the version number there, though, as a way to advertise which ioctls are present.
Kristian
Re: [PATCH 6/6] firewire: add it all to kbuild
In reply to Christoph HellwigQuoted 9 lines · Christoph Hellwig
Quoted 6 lines · Stefan Richter
Quoted 4 lines · Christoph Hellwig
Review
Quoted 2 lines
(quoted diff) +2
-0+fw-core-objs := fw-card.o fw-topology.o fw-transaction.o fw-iso.o \ + fw-device.o fw-cdev.ofw-core-y += ..
Like such?
Exactly.
OK, changed that here, will push out new patches soon.
Kristian
Re: [PATCH 3/6] firewire: char device interface
In reply to Christoph HellwigQuoted 6 lines · Christoph Hellwig
Quoted 1 line · Kristian H??gsberg
The
firewire-cdev.hfile is meant to be a self-contained userspace header file and shouldn't include other kernel header files. All duplicated values are standardized ieee1394 values and won't ever change. I should put a #ifndef__FW_COMMON_DEFINESprotection around the duplicate values, I guess, but I'm just wondering why I never saw a "symbol redefined" warning...No, defining things in two places is not okay. Just add a new header that defines these protocol constants, which needs to be included by userspace that wants to use them.
Ok, I split out the shared constants into linux/firewire-constants.h which gets included by linux/firewire-cdev.h.
Kristian
Re: [PATCH 5/6] firewire: SBP-2 highlevel driver
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
drivers/firewire/fw-sbp2.c line 879
Quoted 3 lines
drivers/firewire/fw-sbp2.c new file +3
-0+ sg = (struct scatterlist *)orb->cmd->request_buffer; + count =dma_map_sg (device->card->device, sg, orb->cmd->use_sg, + orb->cmd->sc_data_direction);you need to handle the error case (count == 0)
Yup, done.
Quoted 5 lines
drivers/firewire/fw-sbp2.c line 895
Quoted 2 lines
drivers/firewire/fw-sbp2.c new file +2
-0+/* Convert the scatterlist to an sbp2 page table. If any +* scatterlist entries are too big for sbp2 we split the as we go. */ Please set the
max_sectorsvalue in your host template so that the block layer doesn't build sg entries too big for you.
As Stefan, said, dma_map_sg() breaks the limit guarantee, so we have to split things manually if sg entries got merged. I've added a comment explaining this.
Isn't max_sectors the overall size limit of the request, though? The SBP-2 protocol imposes a maximum size of 65535 bytes per sg entry, but the total size of a request can be larger. I guess, setting dma_boundary to 2^15 could work.
Quoted 5 lines
drivers/firewire/fw-sbp2.c line 919
Quoted 3 lines
drivers/firewire/fw-sbp2.c new file +3
-0+ orb->page_table_bus = +dma_map_single (device->card->device, orb->page_table, + size,DMA_TO_DEVICE );This needs handling of mapping errors (
dma_mapping_error())
Done.
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ orb = kzalloc(sizeof *orb, GFP_ATOMIC);Normal kernel style is
sizeof(*orb)
Oh, hmm... I though the kernel style typically was to avoid excess parens :) But, sure, I see the comment about preferring parens with sizeof in CodingStyle.
Quoted 5 lines
Quoted 5 lines
drivers/firewire/fw-sbp2.c new file +5
-0+if (cmd->use_sg) { +sbp2_command_orb_map_scatterlist (orb); + }else if (cmd->request_bufflen >SBP2_MAX_SG_ELEMENT_LENGTH ) { +/* FIXME: Need to split this into a sg list... but +* could we get the scsi or blk layer to do that by
Quoted 8 lines
drivers/firewire/fw-sbp2.c line 1012
Quoted 6 lines
drivers/firewire/fw-sbp2.c new file +6
-0+* reporting our max supported block size? */ +fw_error ("command > 64k\n" ); + goto fail_bufflen; + }else if (cmd->request_bufflen >0 ) { +sbp2_command_orb_map_buffer (orb); + }The
use_sg== 0,request_bufflen!= 0 case can't happen anymore.
That should simplify the code a bit. How long has that been the case?
Quoted 8 lines
drivers/firewire/fw-sbp2.c line 1034
Quoted 5 lines
+
fail_mapping:drivers/firewire/fw-sbp2.c new file +4
-0+kfree (orb); + fail_alloc: + cmd->result =DID_ERROR <<16 ; +done (cmd);Failure due to ressource shortage should not complete the command but return SCSI_MLQUEUE_HOST_BUSY/SCSI_MLQUEUE_DEVICE_BUSY.
Ok, I've changed that.
Quoted 10 lines
drivers/firewire/fw-sbp2.c line 1088
Quoted 7 lines
drivers/firewire/fw-sbp2.c new file +6
-0+return 0 ; +} +static struct scsi_host_template scsi_driver_template = { + .module =THIS_MODULE , + .name ="SBP-2 IEEE-1394" , + .proc_name = (char *)sbp2_driver_name,Please don't use casrs here. Either fix up the definition so it accepts const strings or pass a non-const one.
Ok, I'll patch the scsi host template definition.
Quoted 11 lines
Quoted 11 lines
drivers/firewire/fw-sbp2.c new file +11
-0+static int add_scsi_devices (struct fw_unit *unit) +{ +struct sbp2_device *sd = unit->device.driver_data; +int retval, lun; + +if (sd->scsi_host !=NULL ) +return 0 ; + + sd->scsi_host =scsi_host_alloc (&scsi_driver_template, +sizeof (unsigned long )); +if (sd->scsi_host ==NULL ) {
Quoted 8 lines
drivers/firewire/fw-sbp2.c line 1115
Quoted 5 lines
drivers/firewire/fw-sbp2.c new file +5
-0+fw_error ("failed to register scsi host\n" ); +return -1 ; + } + + sd->scsi_host->hostdata[0 ] = (unsigned long )unit;Please take a look ar ther other scsi drivers how this is supposed to be used.
I was trying to be clever and only allocate the host once the device had been discovered and initialized. I have now changed the code to just allocate the host up front and use the hostdata mechanism for the sbp2_device struct, which also addresses the host life cycle comments below.
Quoted 17 lines
Quoted 17 lines
drivers/firewire/fw-sbp2.c new file +17
-0+ retval =scsi_add_host (sd->scsi_host, &unit->device); +if (retval <0 ) { +fw_error ("failed to add scsi host\n" ); +scsi_host_put (sd->scsi_host); + sd->scsi_host =NULL ; +return retval; + } + +/* FIXME: Loop over luns here. */ + lun =0 ; + retval =scsi_add_device (sd->scsi_host,0 ,0 , lun); +if (retval <0 ) { +fw_error ("failed to add scsi device\n" ); +scsi_remove_host (sd->scsi_host); +scsi_host_put (sd->scsi_host); + sd->scsi_host =NULL ; +return retval;
Quoted 8 lines
drivers/firewire/fw-sbp2.c line 512
Quoted 4 lines
drivers/firewire/fw-sbp2.c new file +4
-0+ } + +return 0 ; +}Do we really need another scanning algorithm? Can't you use
scsi_scan_targetinstead and let the core scsi code handle the scanning?
Stefan addressed this one.
Quoted 7 lines
Quoted 7 lines
drivers/firewire/fw-sbp2.c new file +7
-0+ +static void remove_scsi_devices (struct fw_unit *unit) +{ +struct sbp2_device *sd = unit->device.driver_data; + +if (sd->scsi_host !=NULL ) { +scsi_remove_host (sd->scsi_host);
Quoted 8 lines
drivers/firewire/fw-sbp2.c line 1133
Quoted 4 lines
drivers/firewire/fw-sbp2.c new file +4
-0+scsi_host_put (sd->scsi_host); + } + sd->scsi_host =NULL ; +}This function seems rather oddly named. And the checking and setting of
scsi_hostlooks like you have some lifetime rule problems.
Now fixed as described above.
Thanks for the review, will send out new patches.
Kristian
Re: [PATCH 5/6] firewire: SBP-2 highlevel driver
Quoted 1 line · Kristian Høgsberg
Isn't
max_sectorsthe overall size limit of the request, though?
BTW, mainline sbp2 sets max_sectors=512 per default because one 1st generation bridge needed it. fw-sbp2 lets the SCSI stack chose the default max_sectors, which is SCSI_DEFAULT_MAX_SECTORS i.e. 1024. I think that should be fine with practically all SBP-2 bridges in use today, but max_sectors > 512 was never widely tested.
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= -=--= http://arcgraph.de/sr/
Re: [PATCH 5/6] firewire: SBP-2 highlevel driver
In reply to Kristian HøgsbergQuoted 21 lines · Kristian Høgsberg
Quoted 11 lines · Christoph Hellwig
Quoted 11 lines
drivers/firewire/fw-sbp2.c new file +11
-0+static int add_scsi_devices (struct fw_unit *unit) +{ +struct sbp2_device *sd = unit->device.driver_data; +int retval, lun; + +if (sd->scsi_host !=NULL ) +return 0 ; + + sd->scsi_host =scsi_host_alloc (&scsi_driver_template, +sizeof (unsigned long )); +if (sd->scsi_host ==NULL ) {Quoted 8 lines
drivers/firewire/fw-sbp2.c line 1115
Quoted 5 lines
drivers/firewire/fw-sbp2.c new file +5
-0+fw_error ("failed to register scsi host\n" ); +return -1 ; + } + + sd->scsi_host->hostdata[0 ] = (unsigned long )unit;Please take a look ar ther other scsi drivers how this is supposed to be used.
Quoted 5 lines
I was trying to be clever and only allocate the host once the device had been discovered and initialized. I have now changed the code to just allocate the host up front and use the hostdata mechanism for the
sbp2_devicestruct, which also addresses the host life cycle comments below.
I have doubts. IMO the previous code is 100% correct as long as 1 SBP-2 target LU maps to 1 Scsi_Host.
The lifetime of the Scsi_Host would only be longer than that of the LU if all LUs (or all LUs at the same initiator port) would be added beneath the same instance of Scsi_Host. Then the lifetime of the Scsi_Host would be that of the fw-sbp2 driver, or that of fw-sbp2's representation of a FireWire bus.
However, I'll see how it turns out in your update patch.
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= -=--= http://arcgraph.de/sr/
Re: [PATCH 5/6] firewire: SBP-2 highlevel driver
Quoted 7 lines · Stefan Richter
Quoted 5 lines · Kristian Høgsberg
I was trying to be clever and only allocate the host once the device had been discovered and initialized. I have now changed the code to just allocate the host up front and use the hostdata mechanism for the
sbp2_devicestruct, which also addresses the host life cycle comments below.
Quoted 8 lines
I have doubts. IMO the previous code is 100% correct as long as 1 SBP-2 target LU maps to 1
Scsi_Host.The lifetime of the
Scsi_Hostwould only be longer than that of the LU if all LUs (or all LUs at the same initiator port) would be added beneath the same instance ofScsi_Host. Then the lifetime of theScsi_Hostwould be that of the fw-sbp2 driver, or that of fw-sbp2's representation of a FireWire bus.
In the patch, the sbp2_device is now allocated with the scsi_host and is the hostdata part of the host struct. This mean we have to add all the LUs from the unit directory corresponding to the sbp2_device struct to that host. Is that a problem? I think we had this discussion before, but I still don't understand why this approach isn't feasible.
Kristian
Re: [PATCH 5/6] firewire: SBP-2 highlevel driver
Quoted 3 lines · Kristian Høgsberg
This mean we have to add all the LUs from the unit directory corresponding to the
sbp2_devicestruct to that host. Is that a problem?
Most certainly not for now.
Quoted 1 line
I think we had this discussion before,
I believe that was on a different aspect of multi-LU targets.
Quoted 1 line
but I still don't understand why this approach isn't feasible.
I didn't say it was infeasible. On the contrary, I too wanted (am wanting) to rework sbp2 so that it instantiates only a single Scsi_Host globally or per FireWire initiator port. It's just one of the things that I always pushed back, and where the devil is in the detail. (Notably if multiple targets, not just multiple LUs of one target, live beneath one Scsi_Host.)
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= -=-=- http://arcgraph.de/sr/
Re: [PATCH 4/6] firewire: OHCI-1394 lowlevel driver
In reply to Christoph HellwigQuoted 8 lines · Christoph Hellwig
drivers/firewire/fw-ohci.c line 1728
Quoted 3 lines
drivers/firewire/fw-ohci.c new file +3
-0+if (pci_enable_device (dev)) { +fw_error ("Failed to enable OHCI hardware.\n" ); +return cleanup (ohci,CLEANUP_PUT_CARD , -ENODEV );Please use normal goto unwinding so the driver follows the same model as almost all other pci drivers and allows people to follow your driver more easily. Also it's not a alot of cleanup code, so removing this might actually be a net decrease in lines of code.
Sure. The patch I have here says 42 insertions, 44 deletions :)
Quoted 4 lines
drivers/firewire/fw-ohci.c line 1751
Quoted 1 line
drivers/firewire/fw-ohci.c new file +1
-0+if (software_reset (ohci)) {Please give all your function a nice prefix so that oops messages are more readable.
I don't see a strong precedence for this for static functions. For example, if you grep for 'static' in drivers/usb/core, there's a mix of usb_* prefixed functions and functions without a consistent prefix. Plus, when the drivers are loaded as modules, the module name will be in the stack trace. I can track down the most generic sounding functions and give them a fw_ prefix, but doing a whole-sale prefixing of static functions will make the source more noisy and reduce readabilty - I'm not sure it's worth it.
cheers,
Kristian
[git pull] New firewire stack (updated)
In reply to Kristian HøgsbergLinus, please pull from the juju branch at
git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6.git juju
to receive the new, alternative IEEE 1394 subsystem ( --- unless you consider it too close to the end of the merge window now or have other reservations...).
Many thanks to all who reviewed the submission from May 1st. Your work is of great help and is very much appreciated.
What changed since last submission:
Ivo van Doorn (1):
CRC ITU-T V.41
Kristian Høgsberg (14):
firewire: Use lib/ implementation of CRC ITU-T.
firewire: Clean up comment style.
firewire: Convert card_rwsem to a regular mutex.
firewire: Coding style cleanup: no spaces after function names.
firewire: Uppercase most macro names.
firewire: Use linux/*.h instead of asm/*.h header files.
firewire: Break out shared IEEE1394 constant to separate header file.
firewire: Add to fw-core-y instead of assigning fw-core-objs in Makefile.
firewire: Allocate scsi_host up front and allocate the sbp2_device as hostdata.
firewire: Handle the last few DMA mapping error cases.
firewire: Return SCSI_MLQUEUE_HOST_BUSY for out of memory cases in queuecommand.
firewire: Drop single buffer request support.
firewire: Always use parens with sizeof.
firewire: Convert OHCI driver to use standard goto unwinding for error handling.
Kristian Høgsberg, Stefan Richter (1):
firewire: Add a comment to describe why we split the sg list.
Olaf Hering (1):
firewire: Provide module aliase for backwards compatibility.
What did _not_ change:
- The drivers are still named fw-core, fw-ohci, fw-sbp2 (but they feature conditional aliases sbp2 and ohci1394 now). Adrian suggested the prefix firewire- instead of fw-.
- The drivers still live in drivers/firewire/, i.e. have not been put into mainline's drivers/ieee1394/.
As mentioned in the previous submission, the main item that is still to do regarding the new codebase is to bring over IP over 1394, currently known as eth1394. But the biggest task is certainly to come up with a transition schedule for the removal of the existing stack. IMO, exposure of the new stack at this time will enable the community of IEEE 1394 developers and users to provide us with the necessary feedback to tackle that schedule.
To rehash the reasons to undertake this transition:
+ Considerably leaner codebase,
+ cleaned-up and improved in-stack APIs
(with the side effect of getting rid of a bunch of old bugs),
+ consolidation of the currently four userspace ABIs into one improved ABI (which is already supported by the two FireWire low-level libraries libraw1394 and libdc1394),
+ improved host security and device security.
As noted, linux1394-2.6.git's juju branch is based on 2.6.21-rc3. I can rebase it onto 2.6.21 or current git if you wish. The juju branch contains a linear series of now 138 commits:
Adrian Bunk (1)
Andrew Morton (4)
Ivo van Doorn (1)
Kristian Høgsberg (106)
Marc Butler (1)
Olaf Hering (1)
Randy Dunlap (1)
Stefan Richter (22)
Thomas Gleixner (1)
drivers/Makefile | 1 + drivers/firewire/Kconfig | 61 ++ drivers/firewire/Makefile | 10 + drivers/firewire/fw-card.c | 560 +++++++++++ drivers/firewire/fw-cdev.c | 961 ++++++++++++++++++ drivers/firewire/fw-device.c | 813 +++++++++++++++ drivers/firewire/fw-device.h | 146 +++ drivers/firewire/fw-iso.c | 163 +++ drivers/firewire/fw-ohci.c | 1943 ++++++++++++++++++++++++++++++++++++ drivers/firewire/fw-ohci.h | 153 +++ drivers/firewire/fw-sbp2.c | 1147 +++++++++++++++++++++ drivers/firewire/fw-topology.c | 537 ++++++++++ drivers/firewire/fw-topology.h | 92 ++ drivers/firewire/fw-transaction.c | 910 +++++++++++++++++ drivers/firewire/fw-transaction.h | 458 +++++++++ drivers/ieee1394/Kconfig | 2 + include/linux/crc-itu-t.h | 28 + include/linux/firewire-cdev.h | 229 +++++ include/linux/firewire-constants.h | 67 ++ lib/Kconfig | 8 + lib/Makefile | 1 + lib/crc-itu-t.c | 69 ++ 22 files changed, 8359 insertions(+), 0 deletions(-) create mode 100644 drivers/firewire/Kconfig create mode 100644 drivers/firewire/Makefile create mode 100644 drivers/firewire/fw-card.c create mode 100644 drivers/firewire/fw-cdev.c create mode 100644 drivers/firewire/fw-device.c create mode 100644 drivers/firewire/fw-device.h create mode 100644 drivers/firewire/fw-iso.c create mode 100644 drivers/firewire/fw-ohci.c create mode 100644 drivers/firewire/fw-ohci.h create mode 100644 drivers/firewire/fw-sbp2.c create mode 100644 drivers/firewire/fw-topology.c create mode 100644 drivers/firewire/fw-topology.h create mode 100644 drivers/firewire/fw-transaction.c create mode 100644 drivers/firewire/fw-transaction.h create mode 100644 include/linux/crc-itu-t.h create mode 100644 include/linux/firewire-cdev.h create mode 100644 include/linux/firewire-constants.h create mode 100644 lib/crc-itu-t.c
Thanks,
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= -=-=- http://arcgraph.de/sr/
Re: [git pull] New firewire stack (updated)
Quoted 4 lines · Stefan Richter
Linus, please pull from the juju branch at
git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6.git juju
ACK from me. I still have some comments but none of them is a merge blocker.
Quoted 8 lines
What did _not_ change:
- The drivers are still named fw-core, fw-ohci, fw-sbp2 (but they feature conditional aliases sbp2 and ohci1394 now). Adrian suggested the prefix firewire- instead of fw-.
- The drivers still live in
drivers/firewire/, i.e. have not been put into mainline'sdrivers/ieee1394/.
I don't quite like that. Then again git handles renames pretty nicely and I hope we'll just shift the new drivers in place when the old code goes away completely to give people a seamless migration.
Re: [git pull] New firewire stack (updated)
Quoted 15 lines · Christoph Hellwig
Quoted 4 lines · Stefan Richter
Linus, please pull from the juju branch at
git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6.git jujuACK from me. I still have some comments but none of them is a merge blocker.
Quoted 6 lines
What did _not_ change:
- The drivers are still named fw-core, fw-ohci, fw-sbp2 (but they feature conditional aliases sbp2 and ohci1394 now). Adrian suggested the prefix firewire- instead of fw-.
Quoted 6 lines
Quoted 2 lines
- The drivers still live in
drivers/firewire/, i.e. have not been put into mainline'sdrivers/ieee1394/.I don't quite like that. Then again git handles renames pretty nicely and I hope we'll just shift the new drivers in place when the old code goes away completely to give people a seamless migration.
For users it shouldn't matter where the code is located in the kernel sources (and "firewire" is IMHO for many people more meaningful than "ieee1394").
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedRe: [git pull] New firewire stack (updated)
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
Quoted 2 lines · Stefan Richter
- The drivers still live in
drivers/firewire/, i.e. have not been put into mainline'sdrivers/ieee1394/.I don't quite like that. Then again git handles renames pretty nicely and I hope we'll just shift the new drivers in place when the old code goes away completely to give people a seamless migration.
There were some comments in this and past reviews pro and contra the directory split. For me, it was easier to deal with patch handling that way since the stack went into -mm, but once the stack is in Linus' tree, my work will probably be easier anyway.
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= -=-=- http://arcgraph.de/sr/
Re: [git pull] New firewire stack (updated)
In reply to Christoph HellwigQuoted 2 lines · Christoph Hellwig
ACK from me. I still have some comments but none of them is a merge blocker.
I put one small fix that Kristian sent on hold (const char * vs char * for shostt->proc_name) to let a related patch go to scsi-misc first. So this open item is my fault, not his. :-)
Signature · 3 lines
Stefan Richter -=====-=-=== -=-= -=-=- http://arcgraph.de/sr/