Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/ieee1394/linux1394-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6:
  firewire: don't respond to broadcast write requests
  firewire: clean up fw_card reference counting
  firewire: clean up some includes
  firewire: remove unused struct members
  firewire: implement broadcast_channel CSR for 1394a compliance
  ieee1394: dump mmapped iso buffers in core files
  ieee1394: raw1394: Push the BKL down into the driver ioctls
  ieee1394: video1394: reorder module init, prepare BKL removal
  ieee1394: reduce log noise about config ROM CRC errors
  • Loading branch information
Linus Torvalds committed Jul 15, 2008
2 parents b9d2252 + a7ea678 commit 849c529
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 53 deletions.
32 changes: 21 additions & 11 deletions drivers/firewire/fw-card.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <linux/module.h>
#include <linux/errno.h>
#include <linux/completion.h>
#include <linux/crc-itu-t.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/kref.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/crc-itu-t.h>

#include "fw-transaction.h"
#include "fw-topology.h"
#include "fw-device.h"
Expand Down Expand Up @@ -396,14 +399,16 @@ fw_card_initialize(struct fw_card *card, const struct fw_card_driver *driver,
{
static atomic_t index = ATOMIC_INIT(-1);

atomic_set(&card->device_count, 0);
card->index = atomic_inc_return(&index);
card->driver = driver;
card->device = device;
card->current_tlabel = 0;
card->tlabel_mask = 0;
card->color = 0;
card->broadcast_channel = BROADCAST_CHANNEL_INITIAL;

kref_init(&card->kref);
init_completion(&card->done);
INIT_LIST_HEAD(&card->transaction_list);
spin_lock_init(&card->lock);
setup_timer(&card->flush_timer,
Expand Down Expand Up @@ -496,7 +501,6 @@ dummy_enable_phys_dma(struct fw_card *card,
}

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,
Expand All @@ -506,6 +510,14 @@ static struct fw_card_driver dummy_driver = {
.enable_phys_dma = dummy_enable_phys_dma,
};

void
fw_card_release(struct kref *kref)
{
struct fw_card *card = container_of(kref, struct fw_card, kref);

complete(&card->done);
}

void
fw_core_remove_card(struct fw_card *card)
{
Expand All @@ -521,12 +533,10 @@ fw_core_remove_card(struct fw_card *card)
card->driver = &dummy_driver;

fw_destroy_nodes(card);
/*
* Wait for all device workqueue jobs to finish. Otherwise the
* firewire-core module could be unloaded before the jobs ran.
*/
while (atomic_read(&card->device_count) > 0)
msleep(100);

/* Wait for all users, especially device workqueue jobs, to finish. */
fw_card_put(card);
wait_for_completion(&card->done);

cancel_delayed_work_sync(&card->work);
fw_flush_transactions(card);
Expand Down
5 changes: 2 additions & 3 deletions drivers/firewire/fw-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static void fw_device_release(struct device *dev)
fw_node_put(device->node);
kfree(device->config_rom);
kfree(device);
atomic_dec(&card->device_count);
fw_card_put(card);
}

int fw_device_enable_phys_dma(struct fw_device *device)
Expand Down Expand Up @@ -946,8 +946,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
*/
device_initialize(&device->device);
atomic_set(&device->state, FW_DEVICE_INITIALIZING);
atomic_inc(&card->device_count);
device->card = card;
device->card = fw_card_get(card);
device->node = fw_node_get(node);
device->node_id = node->node_id;
device->generation = card->generation;
Expand Down
1 change: 0 additions & 1 deletion drivers/firewire/fw-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ struct fw_device {
bool cmc;
struct fw_card *card;
struct device device;
struct list_head link;
struct list_head client_list;
u32 *config_rom;
size_t config_rom_length;
Expand Down
1 change: 0 additions & 1 deletion drivers/firewire/fw-ohci.c
Original file line number Diff line number Diff line change
Expand Up @@ -2292,7 +2292,6 @@ ohci_queue_iso(struct fw_iso_context *base,
}

static const struct fw_card_driver ohci_driver = {
.name = ohci_driver_name,
.enable = ohci_enable,
.update_phy_reg = ohci_update_phy_reg,
.set_config_rom = ohci_set_config_rom,
Expand Down
32 changes: 23 additions & 9 deletions drivers/firewire/fw-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff)
#define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff)

#define HEADER_DESTINATION_IS_BROADCAST(q) \
(((q) & HEADER_DESTINATION(0x3f)) == HEADER_DESTINATION(0x3f))

#define PHY_CONFIG_GAP_COUNT(gap_count) (((gap_count) << 16) | (1 << 22))
#define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23))
#define PHY_IDENTIFIER(id) ((id) << 30)
Expand Down Expand Up @@ -624,12 +627,9 @@ allocate_request(struct fw_packet *p)
void
fw_send_response(struct fw_card *card, struct fw_request *request, int rcode)
{
/*
* Broadcast packets are reported as ACK_COMPLETE, so this
* check is sufficient to ensure we don't send response to
* broadcast packets or posted writes.
*/
if (request->ack != ACK_PENDING) {
/* unified transaction or broadcast transaction: don't respond */
if (request->ack != ACK_PENDING ||
HEADER_DESTINATION_IS_BROADCAST(request->request_header[0])) {
kfree(request);
return;
}
Expand Down Expand Up @@ -817,12 +817,13 @@ handle_registers(struct fw_card *card, struct fw_request *request,
int reg = offset & ~CSR_REGISTER_BASE;
unsigned long long bus_time;
__be32 *data = payload;
int rcode = RCODE_COMPLETE;

switch (reg) {
case CSR_CYCLE_TIME:
case CSR_BUS_TIME:
if (!TCODE_IS_READ_REQUEST(tcode) || length != 4) {
fw_send_response(card, request, RCODE_TYPE_ERROR);
rcode = RCODE_TYPE_ERROR;
break;
}

Expand All @@ -831,7 +832,17 @@ handle_registers(struct fw_card *card, struct fw_request *request,
*data = cpu_to_be32(bus_time);
else
*data = cpu_to_be32(bus_time >> 25);
fw_send_response(card, request, RCODE_COMPLETE);
break;

case CSR_BROADCAST_CHANNEL:
if (tcode == TCODE_READ_QUADLET_REQUEST)
*data = cpu_to_be32(card->broadcast_channel);
else if (tcode == TCODE_WRITE_QUADLET_REQUEST)
card->broadcast_channel =
(be32_to_cpu(*data) & BROADCAST_CHANNEL_VALID) |
BROADCAST_CHANNEL_INITIAL;
else
rcode = RCODE_TYPE_ERROR;
break;

case CSR_BUS_MANAGER_ID:
Expand All @@ -850,10 +861,13 @@ handle_registers(struct fw_card *card, struct fw_request *request,

case CSR_BUSY_TIMEOUT:
/* FIXME: Implement this. */

default:
fw_send_response(card, request, RCODE_ADDRESS_ERROR);
rcode = RCODE_ADDRESS_ERROR;
break;
}

fw_send_response(card, request, rcode);
}

static struct fw_address_handler registers = {
Expand Down
34 changes: 26 additions & 8 deletions drivers/firewire/fw-transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
#ifndef __fw_transaction_h
#define __fw_transaction_h

#include <linux/completion.h>
#include <linux/device.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/fs.h>
#include <linux/dma-mapping.h>
#include <linux/firewire-constants.h>
#include <asm/atomic.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/spinlock_types.h>
#include <linux/timer.h>
#include <linux/workqueue.h>

#define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4)
#define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0)
Expand Down Expand Up @@ -80,6 +81,9 @@
#define CSR_SPEED_MAP 0x2000
#define CSR_SPEED_MAP_END 0x3000

#define BROADCAST_CHANNEL_INITIAL (1 << 31 | 31)
#define BROADCAST_CHANNEL_VALID (1 << 30)

#define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
#define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)

Expand Down Expand Up @@ -216,7 +220,8 @@ extern struct bus_type fw_bus_type;
struct fw_card {
const struct fw_card_driver *driver;
struct device *device;
atomic_t device_count;
struct kref kref;
struct completion done;

int node_id;
int generation;
Expand All @@ -236,6 +241,7 @@ struct fw_card {
*/
int self_id_count;
u32 topology_map[252 + 3];
u32 broadcast_channel;

spinlock_t lock; /* Take this lock when handling the lists in
* this struct. */
Expand All @@ -256,6 +262,20 @@ struct fw_card {
int bm_generation;
};

static inline struct fw_card *fw_card_get(struct fw_card *card)
{
kref_get(&card->kref);

return card;
}

void fw_card_release(struct kref *kref);

static inline void fw_card_put(struct fw_card *card)
{
kref_put(&card->kref, fw_card_release);
}

/*
* The iso packet format allows for an immediate header/payload part
* stored in 'header' immediately after the packet info plus an
Expand Down Expand Up @@ -348,8 +368,6 @@ int
fw_iso_context_stop(struct fw_iso_context *ctx);

struct fw_card_driver {
const char *name;

/*
* Enable the given card with the given initial config rom.
* This function is expected to activate the card, and either
Expand Down
32 changes: 22 additions & 10 deletions drivers/ieee1394/csr1212.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,24 @@ int csr1212_read(struct csr1212_csr *csr, u32 offset, void *buffer, u32 len)
return -ENOENT;
}

/*
* Apparently there are many different wrong implementations of the CRC
* algorithm. We don't fail, we just warn... approximately once per GUID.
*/
static void
csr1212_check_crc(const u32 *buffer, size_t length, u16 crc, __be32 *guid)
{
static u64 last_bad_eui64;
u64 eui64 = ((u64)be32_to_cpu(guid[0]) << 32) | be32_to_cpu(guid[1]);

if (csr1212_crc16(buffer, length) == crc ||
csr1212_msft_crc16(buffer, length) == crc ||
eui64 == last_bad_eui64)
return;

printk(KERN_DEBUG "ieee1394: config ROM CRC error\n");
last_bad_eui64 = eui64;
}

/* Parse a chunk of data as a Config ROM */

Expand Down Expand Up @@ -1092,11 +1110,8 @@ static int csr1212_parse_bus_info_block(struct csr1212_csr *csr)
return ret;
}

/* Apparently there are many different wrong implementations of the CRC
* algorithm. We don't fail, we just warn. */
if ((csr1212_crc16(bi->data, bi->crc_length) != bi->crc) &&
(csr1212_msft_crc16(bi->data, bi->crc_length) != bi->crc))
printk(KERN_DEBUG "IEEE 1394 device has ROM CRC error\n");
csr1212_check_crc(bi->data, bi->crc_length, bi->crc,
&csr->bus_info_data[3]);

cr = CSR1212_MALLOC(sizeof(*cr));
if (!cr)
Expand Down Expand Up @@ -1205,11 +1220,8 @@ int csr1212_parse_keyval(struct csr1212_keyval *kv,
&cache->data[bytes_to_quads(kv->offset - cache->offset)];
kvi_len = be16_to_cpu(kvi->length);

/* Apparently there are many different wrong implementations of the CRC
* algorithm. We don't fail, we just warn. */
if ((csr1212_crc16(kvi->data, kvi_len) != kvi->crc) &&
(csr1212_msft_crc16(kvi->data, kvi_len) != kvi->crc))
printk(KERN_DEBUG "IEEE 1394 device has ROM CRC error\n");
/* GUID is wrong in here in case of extended ROM. We don't care. */
csr1212_check_crc(kvi->data, kvi_len, kvi->crc, &cache->data[3]);

switch (kv->key.type) {
case CSR1212_KV_TYPE_DIRECTORY:
Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee1394/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ int dma_region_mmap(struct dma_region *dma, struct file *file,
vma->vm_ops = &dma_region_vm_ops;
vma->vm_private_data = dma;
vma->vm_file = file;
vma->vm_flags |= VM_RESERVED;
vma->vm_flags |= VM_RESERVED | VM_ALWAYSDUMP;

return 0;
}
Expand Down
4 changes: 1 addition & 3 deletions drivers/ieee1394/highlevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,8 @@ void hpsb_register_highlevel(struct hpsb_highlevel *hl)
{
unsigned long flags;

hpsb_init_highlevel(hl);
INIT_LIST_HEAD(&hl->addr_list);
INIT_LIST_HEAD(&hl->host_info_list);

rwlock_init(&hl->host_info_lock);

down_write(&hl_drivers_sem);
list_add_tail(&hl->hl_list, &hl_drivers);
Expand Down
13 changes: 12 additions & 1 deletion drivers/ieee1394/highlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define IEEE1394_HIGHLEVEL_H

#include <linux/list.h>
#include <linux/spinlock_types.h>
#include <linux/spinlock.h>
#include <linux/types.h>

struct module;
Expand Down Expand Up @@ -103,6 +103,17 @@ int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store,
void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction,
void *data, size_t length);

/**
* hpsb_init_highlevel - initialize a struct hpsb_highlevel
*
* This is only necessary if hpsb_get_hostinfo_bykey can be called
* before hpsb_register_highlevel.
*/
static inline void hpsb_init_highlevel(struct hpsb_highlevel *hl)
{
rwlock_init(&hl->host_info_lock);
INIT_LIST_HEAD(&hl->host_info_list);
}
void hpsb_register_highlevel(struct hpsb_highlevel *hl);
void hpsb_unregister_highlevel(struct hpsb_highlevel *hl);

Expand Down
Loading

0 comments on commit 849c529

Please sign in to comment.