diff options
| -rw-r--r-- | MAINTAINERS | 4 | ||||
| -rw-r--r-- | drivers/firewire/fw-cdev.c | 3 | ||||
| -rw-r--r-- | drivers/firewire/fw-device.c | 38 | ||||
| -rw-r--r-- | drivers/firewire/fw-device.h | 12 | ||||
| -rw-r--r-- | drivers/firewire/fw-ohci.c | 390 | ||||
| -rw-r--r-- | drivers/firewire/fw-sbp2.c | 127 | ||||
| -rw-r--r-- | drivers/firewire/fw-topology.c | 6 | ||||
| -rw-r--r-- | drivers/firewire/fw-transaction.c | 4 | ||||
| -rw-r--r-- | drivers/ieee1394/dma.c | 39 | ||||
| -rw-r--r-- | drivers/ieee1394/ieee1394_transactions.c | 68 | ||||
| -rw-r--r-- | drivers/ieee1394/ohci1394.c | 12 | ||||
| -rw-r--r-- | drivers/ieee1394/raw1394.c | 4 | ||||
| -rw-r--r-- | drivers/ieee1394/sbp2.c | 52 | ||||
| -rw-r--r-- | drivers/ieee1394/sbp2.h | 1 |
14 files changed, 424 insertions, 336 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index ba05e8058689..2d5ff3e34699 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -1595,7 +1595,7 @@ P: Alexander Viro | |||
| 1595 | M: viro@zeniv.linux.org.uk | 1595 | M: viro@zeniv.linux.org.uk |
| 1596 | S: Maintained | 1596 | S: Maintained |
| 1597 | 1597 | ||
| 1598 | FIREWIRE SUBSYSTEM | 1598 | FIREWIRE SUBSYSTEM (drivers/firewire, <linux/firewire*.h>) |
| 1599 | P: Kristian Hoegsberg, Stefan Richter | 1599 | P: Kristian Hoegsberg, Stefan Richter |
| 1600 | M: krh@redhat.com, stefanr@s5r6.in-berlin.de | 1600 | M: krh@redhat.com, stefanr@s5r6.in-berlin.de |
| 1601 | L: linux1394-devel@lists.sourceforge.net | 1601 | L: linux1394-devel@lists.sourceforge.net |
| @@ -1917,7 +1917,7 @@ L: linux-ide@vger.kernel.org | |||
| 1917 | L: linux-scsi@vger.kernel.org | 1917 | L: linux-scsi@vger.kernel.org |
| 1918 | S: Orphan | 1918 | S: Orphan |
| 1919 | 1919 | ||
| 1920 | IEEE 1394 SUBSYSTEM | 1920 | IEEE 1394 SUBSYSTEM (drivers/ieee1394) |
| 1921 | P: Ben Collins | 1921 | P: Ben Collins |
| 1922 | M: ben.collins@ubuntu.com | 1922 | M: ben.collins@ubuntu.com |
| 1923 | P: Stefan Richter | 1923 | P: Stefan Richter |
diff --git a/drivers/firewire/fw-cdev.c b/drivers/firewire/fw-cdev.c index 60f1a8924a95..7e73cbaa4121 100644 --- a/drivers/firewire/fw-cdev.c +++ b/drivers/firewire/fw-cdev.c | |||
| @@ -206,12 +206,13 @@ fill_bus_reset_event(struct fw_cdev_event_bus_reset *event, | |||
| 206 | 206 | ||
| 207 | event->closure = client->bus_reset_closure; | 207 | event->closure = client->bus_reset_closure; |
| 208 | event->type = FW_CDEV_EVENT_BUS_RESET; | 208 | event->type = FW_CDEV_EVENT_BUS_RESET; |
| 209 | event->generation = client->device->generation; | ||
| 210 | smp_rmb(); /* node_id must not be older than generation */ | ||
| 209 | event->node_id = client->device->node_id; | 211 | event->node_id = client->device->node_id; |
| 210 | event->local_node_id = card->local_node->node_id; | 212 | event->local_node_id = card->local_node->node_id; |
| 211 | event->bm_node_id = 0; /* FIXME: We don't track the BM. */ | 213 | event->bm_node_id = 0; /* FIXME: We don't track the BM. */ |
| 212 | event->irm_node_id = card->irm_node->node_id; | 214 | event->irm_node_id = card->irm_node->node_id; |
| 213 | event->root_node_id = card->root_node->node_id; | 215 | event->root_node_id = card->root_node->node_id; |
| 214 | event->generation = card->generation; | ||
| 215 | } | 216 | } |
| 216 | 217 | ||
| 217 | static void | 218 | static void |
diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c index 56681b3b297b..de9066e69adf 100644 --- a/drivers/firewire/fw-device.c +++ b/drivers/firewire/fw-device.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <linux/idr.h> | 27 | #include <linux/idr.h> |
| 28 | #include <linux/rwsem.h> | 28 | #include <linux/rwsem.h> |
| 29 | #include <asm/semaphore.h> | 29 | #include <asm/semaphore.h> |
| 30 | #include <asm/system.h> | ||
| 30 | #include <linux/ctype.h> | 31 | #include <linux/ctype.h> |
| 31 | #include "fw-transaction.h" | 32 | #include "fw-transaction.h" |
| 32 | #include "fw-topology.h" | 33 | #include "fw-topology.h" |
| @@ -182,9 +183,14 @@ static void fw_device_release(struct device *dev) | |||
| 182 | 183 | ||
| 183 | int fw_device_enable_phys_dma(struct fw_device *device) | 184 | int fw_device_enable_phys_dma(struct fw_device *device) |
| 184 | { | 185 | { |
| 186 | int generation = device->generation; | ||
| 187 | |||
| 188 | /* device->node_id, accessed below, must not be older than generation */ | ||
| 189 | smp_rmb(); | ||
| 190 | |||
| 185 | return device->card->driver->enable_phys_dma(device->card, | 191 | return device->card->driver->enable_phys_dma(device->card, |
| 186 | device->node_id, | 192 | device->node_id, |
| 187 | device->generation); | 193 | generation); |
| 188 | } | 194 | } |
| 189 | EXPORT_SYMBOL(fw_device_enable_phys_dma); | 195 | EXPORT_SYMBOL(fw_device_enable_phys_dma); |
| 190 | 196 | ||
| @@ -384,17 +390,21 @@ complete_transaction(struct fw_card *card, int rcode, | |||
| 384 | complete(&callback_data->done); | 390 | complete(&callback_data->done); |
| 385 | } | 391 | } |
| 386 | 392 | ||
| 387 | static int read_rom(struct fw_device *device, int index, u32 * data) | 393 | static int |
| 394 | read_rom(struct fw_device *device, int generation, int index, u32 *data) | ||
| 388 | { | 395 | { |
| 389 | struct read_quadlet_callback_data callback_data; | 396 | struct read_quadlet_callback_data callback_data; |
| 390 | struct fw_transaction t; | 397 | struct fw_transaction t; |
| 391 | u64 offset; | 398 | u64 offset; |
| 392 | 399 | ||
| 400 | /* device->node_id, accessed below, must not be older than generation */ | ||
| 401 | smp_rmb(); | ||
| 402 | |||
| 393 | init_completion(&callback_data.done); | 403 | init_completion(&callback_data.done); |
| 394 | 404 | ||
| 395 | offset = 0xfffff0000400ULL + index * 4; | 405 | offset = 0xfffff0000400ULL + index * 4; |
| 396 | fw_send_request(device->card, &t, TCODE_READ_QUADLET_REQUEST, | 406 | fw_send_request(device->card, &t, TCODE_READ_QUADLET_REQUEST, |
| 397 | device->node_id, device->generation, device->max_speed, | 407 | device->node_id, generation, device->max_speed, |
| 398 | offset, NULL, 4, complete_transaction, &callback_data); | 408 | offset, NULL, 4, complete_transaction, &callback_data); |
| 399 | 409 | ||
| 400 | wait_for_completion(&callback_data.done); | 410 | wait_for_completion(&callback_data.done); |
| @@ -404,7 +414,14 @@ static int read_rom(struct fw_device *device, int index, u32 * data) | |||
| 404 | return callback_data.rcode; | 414 | return callback_data.rcode; |
| 405 | } | 415 | } |
| 406 | 416 | ||
| 407 | static int read_bus_info_block(struct fw_device *device) | 417 | /* |
| 418 | * Read the bus info block, perform a speed probe, and read all of the rest of | ||
| 419 | * the config ROM. We do all this with a cached bus generation. If the bus | ||
| 420 | * generation changes under us, read_bus_info_block will fail and get retried. | ||
| 421 | * It's better to start all over in this case because the node from which we | ||
| 422 | * are reading the ROM may have changed the ROM during the reset. | ||
| 423 | */ | ||
| 424 | static int read_bus_info_block(struct fw_device *device, int generation) | ||
| 408 | { | 425 | { |
| 409 | static u32 rom[256]; | 426 | static u32 rom[256]; |
| 410 | u32 stack[16], sp, key; | 427 | u32 stack[16], sp, key; |
| @@ -414,7 +431,7 @@ static int read_bus_info_block(struct fw_device *device) | |||
| 414 | 431 | ||
| 415 | /* First read the bus info block. */ | 432 | /* First read the bus info block. */ |
| 416 | for (i = 0; i < 5; i++) { | 433 | for (i = 0; i < 5; i++) { |
| 417 | if (read_rom(device, i, &rom[i]) != RCODE_COMPLETE) | 434 | if (read_rom(device, generation, i, &rom[i]) != RCODE_COMPLETE) |
| 418 | return -1; | 435 | return -1; |
| 419 | /* | 436 | /* |
| 420 | * As per IEEE1212 7.2, during power-up, devices can | 437 | * As per IEEE1212 7.2, during power-up, devices can |
| @@ -449,7 +466,8 @@ static int read_bus_info_block(struct fw_device *device) | |||
| 449 | device->max_speed = device->card->link_speed; | 466 | device->max_speed = device->card->link_speed; |
| 450 | 467 | ||
| 451 | while (device->max_speed > SCODE_100) { | 468 | while (device->max_speed > SCODE_100) { |
| 452 | if (read_rom(device, 0, &dummy) == RCODE_COMPLETE) | 469 | if (read_rom(device, generation, 0, &dummy) == |
| 470 | RCODE_COMPLETE) | ||
| 453 | break; | 471 | break; |
| 454 | device->max_speed--; | 472 | device->max_speed--; |
| 455 | } | 473 | } |
| @@ -482,7 +500,7 @@ static int read_bus_info_block(struct fw_device *device) | |||
| 482 | return -1; | 500 | return -1; |
| 483 | 501 | ||
| 484 | /* Read header quadlet for the block to get the length. */ | 502 | /* Read header quadlet for the block to get the length. */ |
| 485 | if (read_rom(device, i, &rom[i]) != RCODE_COMPLETE) | 503 | if (read_rom(device, generation, i, &rom[i]) != RCODE_COMPLETE) |
| 486 | return -1; | 504 | return -1; |
| 487 | end = i + (rom[i] >> 16) + 1; | 505 | end = i + (rom[i] >> 16) + 1; |
| 488 | i++; | 506 | i++; |
| @@ -501,7 +519,8 @@ static int read_bus_info_block(struct fw_device *device) | |||
| 501 | * it references another block, and push it in that case. | 519 | * it references another block, and push it in that case. |
| 502 | */ | 520 | */ |
| 503 | while (i < end) { | 521 | while (i < end) { |
| 504 | if (read_rom(device, i, &rom[i]) != RCODE_COMPLETE) | 522 | if (read_rom(device, generation, i, &rom[i]) != |
| 523 | RCODE_COMPLETE) | ||
| 505 | return -1; | 524 | return -1; |
| 506 | if ((key >> 30) == 3 && (rom[i] >> 30) > 1 && | 525 | if ((key >> 30) == 3 && (rom[i] >> 30) > 1 && |
| 507 | sp < ARRAY_SIZE(stack)) | 526 | sp < ARRAY_SIZE(stack)) |
| @@ -648,7 +667,7 @@ static void fw_device_init(struct work_struct *work) | |||
| 648 | * device. | 667 | * device. |
| 649 | */ | 668 | */ |
| 650 | 669 | ||
| 651 | if (read_bus_info_block(device) < 0) { | 670 | if (read_bus_info_block(device, device->generation) < 0) { |
| 652 | if (device->config_rom_retries < MAX_RETRIES) { | 671 | if (device->config_rom_retries < MAX_RETRIES) { |
| 653 | device->config_rom_retries++; | 672 | device->config_rom_retries++; |
| 654 | schedule_delayed_work(&device->work, RETRY_DELAY); | 673 | schedule_delayed_work(&device->work, RETRY_DELAY); |
| @@ -801,6 +820,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event) | |||
| 801 | 820 | ||
| 802 | device = node->data; | 821 | device = node->data; |
| 803 | device->node_id = node->node_id; | 822 | device->node_id = node->node_id; |
| 823 | smp_wmb(); /* update node_id before generation */ | ||
| 804 | device->generation = card->generation; | 824 | device->generation = card->generation; |
| 805 | if (atomic_read(&device->state) == FW_DEVICE_RUNNING) { | 825 | if (atomic_read(&device->state) == FW_DEVICE_RUNNING) { |
| 806 | PREPARE_DELAYED_WORK(&device->work, fw_device_update); | 826 | PREPARE_DELAYED_WORK(&device->work, fw_device_update); |
diff --git a/drivers/firewire/fw-device.h b/drivers/firewire/fw-device.h index 894d4a92a18e..0854fe2bc110 100644 --- a/drivers/firewire/fw-device.h +++ b/drivers/firewire/fw-device.h | |||
| @@ -35,6 +35,18 @@ struct fw_attribute_group { | |||
| 35 | struct attribute *attrs[11]; | 35 | struct attribute *attrs[11]; |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | /* | ||
| 39 | * Note, fw_device.generation always has to be read before fw_device.node_id. | ||
| 40 | * Use SMP memory barriers to ensure this. Otherwise requests will be sent | ||
| 41 | * to an outdated node_id if the generation was updated in the meantime due | ||
| 42 | * to a bus reset. | ||
| 43 | * | ||
| 44 | * Likewise, fw-core will take care to update .node_id before .generation so | ||
| 45 | * that whenever fw_device.generation is current WRT the actual bus generation, | ||
| 46 | * fw_device.node_id is guaranteed to be current too. | ||
| 47 | * | ||
| 48 | * The same applies to fw_device.card->node_id vs. fw_device.generation. | ||
| 49 | */ | ||
| 38 | struct fw_device { | 50 | struct fw_device { |
| 39 | atomic_t state; | 51 | atomic_t state; |
| 40 | struct fw_node *node; | 52 | struct fw_node *node; |
diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c index 436a855a4c60..7ebad3c14cb8 100644 --- a/drivers/firewire/fw-ohci.c +++ b/drivers/firewire/fw-ohci.c | |||
| @@ -98,17 +98,48 @@ struct context; | |||
| 98 | typedef int (*descriptor_callback_t)(struct context *ctx, | 98 | typedef int (*descriptor_callback_t)(struct context *ctx, |
| 99 | struct descriptor *d, | 99 | struct descriptor *d, |
| 100 | struct descriptor *last); | 100 | struct descriptor *last); |
| 101 | |||
| 102 | /* | ||
| 103 | * A buffer that contains a block of DMA-able coherent memory used for | ||
| 104 | * storing a portion of a DMA descriptor program. | ||
| 105 | */ | ||
| 106 | struct descriptor_buffer { | ||
| 107 | struct list_head list; | ||
| 108 | dma_addr_t buffer_bus; | ||
| 109 | size_t buffer_size; | ||
| 110 | size_t used; | ||
| 111 | struct descriptor buffer[0]; | ||
| 112 | }; | ||
| 113 | |||
| 101 | struct context { | 114 | struct context { |
| 102 | struct fw_ohci *ohci; | 115 | struct fw_ohci *ohci; |
| 103 | u32 regs; | 116 | u32 regs; |
| 117 | int total_allocation; | ||
| 104 | 118 | ||
| 105 | struct descriptor *buffer; | 119 | /* |
| 106 | dma_addr_t buffer_bus; | 120 | * List of page-sized buffers for storing DMA descriptors. |
| 107 | size_t buffer_size; | 121 | * Head of list contains buffers in use and tail of list contains |
| 108 | struct descriptor *head_descriptor; | 122 | * free buffers. |
| 109 | struct descriptor *tail_descriptor; | 123 | */ |
| 110 | struct descriptor *tail_descriptor_last; | 124 | struct list_head buffer_list; |
| 111 | struct descriptor *prev_descriptor; | 125 | |
| 126 | /* | ||
| 127 | * Pointer to a buffer inside buffer_list that contains the tail | ||
| 128 | * end of the current DMA program. | ||
| 129 | */ | ||
| 130 | struct descriptor_buffer *buffer_tail; | ||
| 131 | |||
| 132 | /* | ||
| 133 | * The descriptor containing the branch address of the first | ||
| 134 | * descriptor that has not yet been filled by the device. | ||
| 135 | */ | ||
| 136 | struct descriptor *last; | ||
| 137 | |||
| 138 | /* | ||
| 139 | * The last descriptor in the DMA program. It contains the branch | ||
| 140 | * address that must be updated upon appending a new descriptor. | ||
| 141 | */ | ||
| 142 | struct descriptor *prev; | ||
| 112 | 143 | ||
| 113 | descriptor_callback_t callback; | 144 | descriptor_callback_t callback; |
| 114 | 145 | ||
| @@ -125,6 +156,7 @@ struct context { | |||
| 125 | struct iso_context { | 156 | struct iso_context { |
| 126 | struct fw_iso_context base; | 157 | struct fw_iso_context base; |
| 127 | struct context context; | 158 | struct context context; |
| 159 | int excess_bytes; | ||
| 128 | void *header; | 160 | void *header; |
| 129 | size_t header_length; | 161 | size_t header_length; |
| 130 | }; | 162 | }; |
| @@ -197,8 +229,6 @@ static inline struct fw_ohci *fw_ohci(struct fw_card *card) | |||
| 197 | #define SELF_ID_BUF_SIZE 0x800 | 229 | #define SELF_ID_BUF_SIZE 0x800 |
| 198 | #define OHCI_TCODE_PHY_PACKET 0x0e | 230 | #define OHCI_TCODE_PHY_PACKET 0x0e |
| 199 | #define OHCI_VERSION_1_1 0x010010 | 231 | #define OHCI_VERSION_1_1 0x010010 |
| 200 | #define ISO_BUFFER_SIZE (64 * 1024) | ||
| 201 | #define AT_BUFFER_SIZE 4096 | ||
| 202 | 232 | ||
| 203 | static char ohci_driver_name[] = KBUILD_MODNAME; | 233 | static char ohci_driver_name[] = KBUILD_MODNAME; |
| 204 | 234 | ||
| @@ -455,71 +485,108 @@ find_branch_descriptor(struct descriptor *d, int z) | |||
| 455 | static void context_tasklet(unsigned long data) | 485 | static void context_tasklet(unsigned long data) |
| 456 | { | 486 | { |
| 457 | struct context *ctx = (struct context *) data; | 487 | struct context *ctx = (struct context *) data; |
| 458 | struct fw_ohci *ohci = ctx->ohci; | ||
| 459 | struct descriptor *d, *last; | 488 | struct descriptor *d, *last; |
| 460 | u32 address; | 489 | u32 address; |
| 461 | int z; | 490 | int z; |
| 491 | struct descriptor_buffer *desc; | ||
| 462 | 492 | ||
| 463 | dma_sync_single_for_cpu(ohci->card.device, ctx->buffer_bus, | 493 | desc = list_entry(ctx->buffer_list.next, |
| 464 | ctx->buffer_size, DMA_TO_DEVICE); | 494 | struct descriptor_buffer, list); |
| 465 | 495 | last = ctx->last; | |
| 466 | d = ctx->tail_descriptor; | ||
| 467 | last = ctx->tail_descriptor_last; | ||
| 468 | |||
| 469 | while (last->branch_address != 0) { | 496 | while (last->branch_address != 0) { |
| 497 | struct descriptor_buffer *old_desc = desc; | ||
| 470 | address = le32_to_cpu(last->branch_address); | 498 | address = le32_to_cpu(last->branch_address); |
| 471 | z = address & 0xf; | 499 | z = address & 0xf; |
| 472 | d = ctx->buffer + (address - ctx->buffer_bus) / sizeof(*d); | 500 | address &= ~0xf; |
| 501 | |||
| 502 | /* If the branch address points to a buffer outside of the | ||
| 503 | * current buffer, advance to the next buffer. */ | ||
| 504 | if (address < desc->buffer_bus || | ||
| 505 | address >= desc->buffer_bus + desc->used) | ||
| 506 | desc = list_entry(desc->list.next, | ||
| 507 | struct descriptor_buffer, list); | ||
| 508 | d = desc->buffer + (address - desc->buffer_bus) / sizeof(*d); | ||
| 473 | last = find_branch_descriptor(d, z); | 509 | last = find_branch_descriptor(d, z); |
| 474 | 510 | ||
| 475 | if (!ctx->callback(ctx, d, last)) | 511 | if (!ctx->callback(ctx, d, last)) |
| 476 | break; | 512 | break; |
| 477 | 513 | ||
| 478 | ctx->tail_descriptor = d; | 514 | if (old_desc != desc) { |
| 479 | ctx->tail_descriptor_last = last; | 515 | /* If we've advanced to the next buffer, move the |
| 516 | * previous buffer to the free list. */ | ||
| 517 | unsigned long flags; | ||
| 518 | old_desc->used = 0; | ||
| 519 | spin_lock_irqsave(&ctx->ohci->lock, flags); | ||
| 520 | list_move_tail(&old_desc->list, &ctx->buffer_list); | ||
| 521 | spin_unlock_irqrestore(&ctx->ohci->lock, flags); | ||
| 522 | } | ||
| 523 | ctx->last = last; | ||
| 480 | } | 524 | } |
| 481 | } | 525 | } |
| 482 | 526 | ||
| 527 | /* | ||
| 528 | * Allocate a new buffer and add it to the list of free buffers for this | ||
| 529 | * context. Must be called with ohci->lock held. | ||
| 530 | */ | ||
| 531 | static int | ||
| 532 | context_add_buffer(struct context *ctx) | ||
| 533 | { | ||
| 534 | struct descriptor_buffer *desc; | ||
| 535 | dma_addr_t bus_addr; | ||
| 536 | int offset; | ||
| 537 | |||
| 538 | /* | ||
| 539 | * 16MB of descriptors should be far more than enough for any DMA | ||
| 540 | * program. This will catch run-away userspace or DoS attacks. | ||
| 541 | */ | ||
| 542 | if (ctx->total_allocation >= 16*1024*1024) | ||
| 543 | return -ENOMEM; | ||
| 544 | |||
| 545 | desc = dma_alloc_coherent(ctx->ohci->card.device, PAGE_SIZE, | ||
| 546 | &bus_addr, GFP_ATOMIC); | ||
| 547 | if (!desc) | ||
| 548 | return -ENOMEM; | ||
| 549 | |||
| 550 | offset = (void *)&desc->buffer - (void *)desc; | ||
| 551 | desc->buffer_size = PAGE_SIZE - offset; | ||
| 552 | desc->buffer_bus = bus_addr + offset; | ||
| 553 | desc->used = 0; | ||
| 554 | |||
| 555 | list_add_tail(&desc->list, &ctx->buffer_list); | ||
| 556 | ctx->total_allocation += PAGE_SIZE; | ||
| 557 | |||
| 558 | return 0; | ||
| 559 | } | ||
| 560 | |||
| 483 | static int | 561 | static int |
| 484 | context_init(struct context *ctx, struct fw_ohci *ohci, | 562 | context_init(struct context *ctx, struct fw_ohci *ohci, |
| 485 | size_t buffer_size, u32 regs, | 563 | u32 regs, descriptor_callback_t callback) |
| 486 | descriptor_callback_t callback) | ||
| 487 | { | 564 | { |
| 488 | ctx->ohci = ohci; | 565 | ctx->ohci = ohci; |
| 489 | ctx->regs = regs; | 566 | ctx->regs = regs; |
| 490 | ctx->buffer_size = buffer_size; | 567 | ctx->total_allocation = 0; |
| 491 | ctx->buffer = kmalloc(buffer_size, GFP_KERNEL); | 568 | |
| 492 | if (ctx->buffer == NULL) | 569 | INIT_LIST_HEAD(&ctx->buffer_list); |
| 570 | if (context_add_buffer(ctx) < 0) | ||
| 493 | return -ENOMEM; | 571 | return -ENOMEM; |
| 494 | 572 | ||
| 573 | ctx->buffer_tail = list_entry(ctx->buffer_list.next, | ||
| 574 | struct descriptor_buffer, list); | ||
| 575 | |||
| 495 | tasklet_init(&ctx->tasklet, context_tasklet, (unsigned long)ctx); | 576 | tasklet_init(&ctx->tasklet, context_tasklet, (unsigned long)ctx); |
| 496 | ctx->callback = callback; | 577 | ctx->callback = callback; |
| 497 | 578 | ||
| 498 | ctx->buffer_bus = | ||
| 499 | dma_map_single(ohci->card.device, ctx->buffer, | ||
| 500 | buffer_size, DMA_TO_DEVICE); | ||
| 501 | if (dma_mapping_error(ctx->buffer_bus)) { | ||
| 502 | kfree(ctx->buffer); | ||
| 503 | return -ENOMEM; | ||
| 504 | } | ||
| 505 | |||
| 506 | ctx->head_descriptor = ctx->buffer; | ||
| 507 | ctx->prev_descriptor = ctx->buffer; | ||
| 508 | ctx->tail_descriptor = ctx->buffer; | ||
| 509 | ctx->tail_descriptor_last = ctx->buffer; | ||
| 510 | |||
| 511 | /* | 579 | /* |
| 512 | * We put a dummy descriptor in the buffer that has a NULL | 580 | * We put a dummy descriptor in the buffer that has a NULL |
| 513 | * branch address and looks like it's been sent. That way we | 581 | * branch address and looks like it's been sent. That way we |
| 514 | * have a descriptor to append DMA programs to. Also, the | 582 | * have a descriptor to append DMA programs to. |
| 515 | * ring buffer invariant is that it always has at least one | ||
| 516 | * element so that head == tail means buffer full. | ||
| 517 | */ | 583 | */ |
| 518 | 584 | memset(ctx->buffer_tail->buffer, 0, sizeof(*ctx->buffer_tail->buffer)); | |
| 519 | memset(ctx->head_descriptor, 0, sizeof(*ctx->head_descriptor)); | 585 | ctx->buffer_tail->buffer->control = cpu_to_le16(DESCRIPTOR_OUTPUT_LAST); |
| 520 | ctx->head_descriptor->control = cpu_to_le16(DESCRIPTOR_OUTPUT_LAST); | 586 | ctx->buffer_tail->buffer->transfer_status = cpu_to_le16(0x8011); |
| 521 | ctx->head_descriptor->transfer_status = cpu_to_le16(0x8011); | 587 | ctx->buffer_tail->used += sizeof(*ctx->buffer_tail->buffer); |
| 522 | ctx->head_descriptor++; | 588 | ctx->last = ctx->buffer_tail->buffer; |
| 589 | ctx->prev = ctx->buffer_tail->buffer; | ||
| 523 | 590 | ||
| 524 | return 0; | 591 | return 0; |
| 525 | } | 592 | } |
| @@ -528,35 +595,42 @@ static void | |||
| 528 | context_release(struct context *ctx) | 595 | context_release(struct context *ctx) |
| 529 | { | 596 | { |
| 530 | struct fw_card *card = &ctx->ohci->card; | 597 | struct fw_card *card = &ctx->ohci->card; |
| 598 | struct descriptor_buffer *desc, *tmp; | ||
| 531 | 599 | ||
| 532 | dma_unmap_single(card->device, ctx->buffer_bus, | 600 | list_for_each_entry_safe(desc, tmp, &ctx->buffer_list, list) |
| 533 | ctx->buffer_size, DMA_TO_DEVICE); | 601 | dma_free_coherent(card->device, PAGE_SIZE, desc, |
| 534 | kfree(ctx->buffer); | 602 | desc->buffer_bus - |
| 603 | ((void *)&desc->buffer - (void *)desc)); | ||
| 535 | } | 604 | } |
| 536 | 605 | ||
| 606 | /* Must be called with ohci->lock held */ | ||
| 537 | static struct descriptor * | 607 | static struct descriptor * |
| 538 | context_get_descriptors(struct context *ctx, int z, dma_addr_t *d_bus) | 608 | context_get_descriptors(struct context *ctx, int z, dma_addr_t *d_bus) |
| 539 | { | 609 | { |
| 540 | struct descriptor *d, *tail, *end; | 610 | struct descriptor *d = NULL; |
| 541 | 611 | struct descriptor_buffer *desc = ctx->buffer_tail; | |
| 542 | d = ctx->head_descriptor; | 612 | |
| 543 | tail = ctx->tail_descriptor; | 613 | if (z * sizeof(*d) > desc->buffer_size) |
| 544 | end = ctx->buffer + ctx->buffer_size / sizeof(*d); | 614 | return NULL; |
| 545 | |||
| 546 | if (d + z <= tail) { | ||
| 547 | goto has_space; | ||
| 548 | } else if (d > tail && d + z <= end) { | ||
| 549 | goto has_space; | ||
| 550 | } else if (d > tail && ctx->buffer + z <= tail) { | ||
| 551 | d = ctx->buffer; | ||
| 552 | goto has_space; | ||
| 553 | } | ||
| 554 | 615 | ||
| 555 | return NULL; | 616 | if (z * sizeof(*d) > desc->buffer_size - desc->used) { |
| 617 | /* No room for the descriptor in this buffer, so advance to the | ||
| 618 | * next one. */ | ||
| 619 | |||
| 620 | if (desc->list.next == &ctx->buffer_list) { | ||
| 621 | /* If there is no free buffer next in the list, | ||
| 622 | * allocate one. */ | ||
| 623 | if (context_add_buffer(ctx) < 0) | ||
| 624 | return NULL; | ||
| 625 | } | ||
| 626 | desc = list_entry(desc->list.next, | ||
| 627 | struct descriptor_buffer, list); | ||
| 628 | ctx->buffer_tail = desc; | ||
| 629 | } | ||
| 556 | 630 | ||
| 557 | has_space: | 631 | d = desc->buffer + desc->used / sizeof(*d); |
| 558 | memset(d, 0, z * sizeof(*d)); | 632 | memset(d, 0, z * sizeof(*d)); |
| 559 | *d_bus = ctx->buffer_bus + (d - ctx->buffer) * sizeof(*d); | 633 | *d_bus = desc->buffer_bus + desc->used; |
| 560 | 634 | ||
| 561 | return d; | 635 | return d; |
| 562 | } | 636 | } |
| @@ -566,7 +640,7 @@ static void context_run(struct context *ctx, u32 extra) | |||
| 566 | struct fw_ohci *ohci = ctx->ohci; | 640 | struct fw_ohci *ohci = ctx->ohci; |
| 567 | 641 | ||
| 568 | reg_write(ohci, COMMAND_PTR(ctx->regs), | 642 | reg_write(ohci, COMMAND_PTR(ctx->regs), |
| 569 | le32_to_cpu(ctx->tail_descriptor_last->branch_address)); | 643 | le32_to_cpu(ctx->last->branch_address)); |
| 570 | reg_write(ohci, CONTROL_CLEAR(ctx->regs), ~0); | 644 | reg_write(ohci, CONTROL_CLEAR(ctx->regs), ~0); |
| 571 | reg_write(ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN | extra); | 645 | reg_write(ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN | extra); |
| 572 | flush_writes(ohci); | 646 | flush_writes(ohci); |
| @@ -576,15 +650,13 @@ static void context_append(struct context *ctx, | |||
| 576 | struct descriptor *d, int z, int extra) | 650 | struct descriptor *d, int z, int extra) |
| 577 | { | 651 | { |
| 578 | dma_addr_t d_bus; | 652 | dma_addr_t d_bus; |
| 653 | struct descriptor_buffer *desc = ctx->buffer_tail; | ||
| 579 | 654 | ||
| 580 | d_bus = ctx->buffer_bus + (d - ctx->buffer) * sizeof(*d); | 655 | d_bus = desc->buffer_bus + (d - desc->buffer) * sizeof(*d); |
| 581 | 656 | ||
| 582 | ctx->head_descriptor = d + z + extra; | 657 | desc->used += (z + extra) * sizeof(*d); |
| 583 | ctx->prev_descriptor->branch_address = cpu_to_le32(d_bus | z); | 658 | ctx->prev->branch_address = cpu_to_le32(d_bus | z); |
| 584 | ctx->prev_descriptor = find_branch_descriptor(d, z); | 659 | ctx->prev = find_branch_descriptor(d, z); |
| 585 | |||
| 586 | dma_sync_single_for_device(ctx->ohci->card.device, ctx->buffer_bus, | ||
| 587 | ctx->buffer_size, DMA_TO_DEVICE); | ||
| 588 | 660 | ||
| 589 | reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE); | 661 | reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE); |
| 590 | flush_writes(ctx->ohci); | 662 | flush_writes(ctx->ohci); |
| @@ -1078,6 +1150,13 @@ static irqreturn_t irq_handler(int irq, void *data) | |||
| 1078 | if (unlikely(event & OHCI1394_postedWriteErr)) | 1150 | if (unlikely(event & OHCI1394_postedWriteErr)) |
| 1079 | fw_error("PCI posted write error\n"); | 1151 | fw_error("PCI posted write error\n"); |
| 1080 | 1152 | ||
| 1153 | if (unlikely(event & OHCI1394_cycleTooLong)) { | ||
| 1154 | if (printk_ratelimit()) | ||
| 1155 | fw_notify("isochronous cycle too long\n"); | ||
| 1156 | reg_write(ohci, OHCI1394_LinkControlSet, | ||
| 1157 | OHCI1394_LinkControl_cycleMaster); | ||
| 1158 | } | ||
| 1159 | |||
| 1081 | if (event & OHCI1394_cycle64Seconds) { | 1160 | if (event & OHCI1394_cycle64Seconds) { |
| 1082 | cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | 1161 | cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer); |
| 1083 | if ((cycle_time & 0x80000000) == 0) | 1162 | if ((cycle_time & 0x80000000) == 0) |
| @@ -1151,8 +1230,8 @@ static int ohci_enable(struct fw_card *card, u32 *config_rom, size_t length) | |||
| 1151 | OHCI1394_RQPkt | OHCI1394_RSPkt | | 1230 | OHCI1394_RQPkt | OHCI1394_RSPkt | |
| 1152 | OHCI1394_reqTxComplete | OHCI1394_respTxComplete | | 1231 | OHCI1394_reqTxComplete | OHCI1394_respTxComplete | |
| 1153 | OHCI1394_isochRx | OHCI1394_isochTx | | 1232 | OHCI1394_isochRx | OHCI1394_isochTx | |
| 1154 | OHCI1394_postedWriteErr | OHCI1394_cycle64Seconds | | 1233 | OHCI1394_postedWriteErr | OHCI1394_cycleTooLong | |
| 1155 | OHCI1394_masterIntEnable); | 1234 | OHCI1394_cycle64Seconds | OHCI1394_masterIntEnable); |
| 1156 | 1235 | ||
| 1157 | /* Activate link_on bit and contender bit in our self ID packets.*/ | 1236 | /* Activate link_on bit and contender bit in our self ID packets.*/ |
| 1158 | if (ohci_update_phy_reg(card, 4, 0, | 1237 | if (ohci_update_phy_reg(card, 4, 0, |
| @@ -1408,9 +1487,13 @@ static int handle_ir_dualbuffer_packet(struct context *context, | |||
| 1408 | void *p, *end; | 1487 | void *p, *end; |
| 1409 | int i; | 1488 | int i; |
| 1410 | 1489 | ||
| 1411 | if (db->first_res_count > 0 && db->second_res_count > 0) | 1490 | if (db->first_res_count > 0 && db->second_res_count > 0) { |
| 1412 | /* This descriptor isn't done yet, stop iteration. */ | 1491 | if (ctx->excess_bytes <= le16_to_cpu(db->second_req_count)) { |
| 1413 | return 0; | 1492 | /* This descriptor isn't done yet, stop iteration. */ |
| 1493 | return 0; | ||
| 1494 | } | ||
| 1495 | ctx->excess_bytes -= le16_to_cpu(db->second_req_count); | ||
| 1496 | } | ||
| 1414 | 1497 | ||
| 1415 | header_length = le16_to_cpu(db->first_req_count) - | 1498 | header_length = le16_to_cpu(db->first_req_count) - |
| 1416 | le16_to_cpu(db->first_res_count); | 1499 | le16_to_cpu(db->first_res_count); |
| @@ -1429,11 +1512,15 @@ static int handle_ir_dualbuffer_packet(struct context *context, | |||
| 1429 | *(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4)); | 1512 | *(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4)); |
| 1430 | memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4); | 1513 | memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4); |
| 1431 | i += ctx->base.header_size; | 1514 | i += ctx->base.header_size; |
| 1515 | ctx->excess_bytes += | ||
| 1516 | (le32_to_cpu(*(u32 *)(p + 4)) >> 16) & 0xffff; | ||
| 1432 | p += ctx->base.header_size + 4; | 1517 | p += ctx->base.header_size + 4; |
| 1433 | } | 1518 | } |
| 1434 | |||
| 1435 | ctx->header_length = i; | 1519 | ctx->header_length = i; |
| 1436 | 1520 | ||
| 1521 | ctx->excess_bytes -= le16_to_cpu(db->second_req_count) - | ||
| 1522 | le16_to_cpu(db->second_res_count); | ||
| 1523 | |||
| 1437 | if (le16_to_cpu(db->control) & DESCRIPTOR_IRQ_ALWAYS) { | 1524 | if (le16_to_cpu(db->control) & DESCRIPTOR_IRQ_ALWAYS) { |
| 1438 | ir_header = (__le32 *) (db + 1); | 1525 | ir_header = (__le32 *) (db + 1); |
| 1439 | ctx->base.callback(&ctx->base, | 1526 | ctx->base.callback(&ctx->base, |
| @@ -1452,24 +1539,24 @@ static int handle_ir_packet_per_buffer(struct context *context, | |||
| 1452 | { | 1539 | { |
| 1453 | struct iso_context *ctx = | 1540 | struct iso_context *ctx = |
| 1454 | container_of(context, struct iso_context, context); | 1541 | container_of(context, struct iso_context, context); |
| 1455 | struct descriptor *pd = d + 1; | 1542 | struct descriptor *pd; |
| 1456 | __le32 *ir_header; | 1543 | __le32 *ir_header; |
| 1457 | size_t header_length; | 1544 | void *p; |
| 1458 | void *p, *end; | 1545 | int i; |
| 1459 | int i, z; | ||
| 1460 | 1546 | ||
| 1461 | if (pd->res_count == pd->req_count) | 1547 | for (pd = d; pd <= last; pd++) { |
| 1548 | if (pd->transfer_status) | ||
| 1549 | break; | ||
| 1550 | } | ||
| 1551 | if (pd > last) | ||
| 1462 | /* Descriptor(s) not done yet, stop iteration */ | 1552 | /* Descriptor(s) not done yet, stop iteration */ |
| 1463 | return 0; | 1553 | return 0; |
| 1464 | 1554 | ||
| 1465 | header_length = le16_to_cpu(d->req_count); | ||
| 1466 | |||
| 1467 | i = ctx->header_length; | 1555 | i = ctx->header_length; |
| 1468 | z = le32_to_cpu(pd->branch_address) & 0xf; | 1556 | p = last + 1; |
| 1469 | p = d + z; | ||
| 1470 | end = p + header_length; | ||
| 1471 | 1557 | ||
| 1472 | while (p < end && i + ctx->base.header_size <= PAGE_SIZE) { | 1558 | if (ctx->base.header_size > 0 && |
| 1559 | i + ctx->base.header_size <= PAGE_SIZE) { | ||
| 1473 | /* | 1560 | /* |
| 1474 | * The iso header is byteswapped to little endian by | 1561 | * The iso header is byteswapped to little endian by |
| 1475 | * the controller, but the remaining header quadlets | 1562 | * the controller, but the remaining header quadlets |
| @@ -1478,14 +1565,11 @@ static int handle_ir_packet_per_buffer(struct context *context, | |||
| 1478 | */ | 1565 | */ |
| 1479 | *(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4)); | 1566 | *(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4)); |
| 1480 | memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4); | 1567 | memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4); |
| 1481 | i += ctx->base.header_size; | 1568 | ctx->header_length += ctx->base.header_size; |
| 1482 | p += ctx->base.header_size + 4; | ||
| 1483 | } | 1569 | } |
| 1484 | 1570 | ||
| 1485 | ctx->header_length = i; | 1571 | if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) { |
| 1486 | 1572 | ir_header = (__le32 *) p; | |
| 1487 | if (le16_to_cpu(pd->control) & DESCRIPTOR_IRQ_ALWAYS) { | ||
| 1488 | ir_header = (__le32 *) (d + z); | ||
| 1489 | ctx->base.callback(&ctx->base, | 1573 | ctx->base.callback(&ctx->base, |
| 1490 | le32_to_cpu(ir_header[0]) & 0xffff, | 1574 | le32_to_cpu(ir_header[0]) & 0xffff, |
| 1491 | ctx->header_length, ctx->header, | 1575 | ctx->header_length, ctx->header, |
| @@ -1493,7 +1577,6 @@ static int handle_ir_packet_per_buffer(struct context *context, | |||
| 1493 | ctx->header_length = 0; | 1577 | ctx->header_length = 0; |
| 1494 | } | 1578 | } |
| 1495 | 1579 | ||
| 1496 | |||
| 1497 | return 1; | 1580 | return 1; |
| 1498 | } | 1581 | } |
| 1499 | 1582 | ||
| @@ -1559,8 +1642,7 @@ ohci_allocate_iso_context(struct fw_card *card, int type, size_t header_size) | |||
| 1559 | if (ctx->header == NULL) | 1642 | if (ctx->header == NULL) |
| 1560 | goto out; | 1643 | goto out; |
| 1561 | 1644 | ||
| 1562 | retval = context_init(&ctx->context, ohci, ISO_BUFFER_SIZE, | 1645 | retval = context_init(&ctx->context, ohci, regs, callback); |
| 1563 | regs, callback); | ||
| 1564 | if (retval < 0) | 1646 | if (retval < 0) |
| 1565 | goto out_with_header; | 1647 | goto out_with_header; |
| 1566 | 1648 | ||
| @@ -1775,19 +1857,6 @@ ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base, | |||
| 1775 | * packet, retransmit or terminate.. | 1857 | * packet, retransmit or terminate.. |
| 1776 | */ | 1858 | */ |
| 1777 | 1859 | ||
| 1778 | if (packet->skip) { | ||
| 1779 | d = context_get_descriptors(&ctx->context, 2, &d_bus); | ||
| 1780 | if (d == NULL) | ||
| 1781 | return -ENOMEM; | ||
| 1782 | |||
| 1783 | db = (struct db_descriptor *) d; | ||
| 1784 | db->control = cpu_to_le16(DESCRIPTOR_STATUS | | ||
| 1785 | DESCRIPTOR_BRANCH_ALWAYS | | ||
| 1786 | DESCRIPTOR_WAIT); | ||
| 1787 | db->first_size = cpu_to_le16(ctx->base.header_size + 4); | ||
| 1788 | context_append(&ctx->context, d, 2, 0); | ||
| 1789 | } | ||
| 1790 | |||
| 1791 | p = packet; | 1860 | p = packet; |
| 1792 | z = 2; | 1861 | z = 2; |
| 1793 | 1862 | ||
| @@ -1815,11 +1884,18 @@ ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base, | |||
| 1815 | db->control = cpu_to_le16(DESCRIPTOR_STATUS | | 1884 | db->control = cpu_to_le16(DESCRIPTOR_STATUS | |
| 1816 | DESCRIPTOR_BRANCH_ALWAYS); | 1885 | DESCRIPTOR_BRANCH_ALWAYS); |
| 1817 | db->first_size = cpu_to_le16(ctx->base.header_size + 4); | 1886 | db->first_size = cpu_to_le16(ctx->base.header_size + 4); |
| 1818 | db->first_req_count = cpu_to_le16(header_size); | 1887 | if (p->skip && rest == p->payload_length) { |
| 1888 | db->control |= cpu_to_le16(DESCRIPTOR_WAIT); | ||
| 1889 | db->first_req_count = db->first_size; | ||
| 1890 | } else { | ||
| 1891 | db->first_req_count = cpu_to_le16(header_size); | ||
| 1892 | } | ||
| 1819 | db->first_res_count = db->first_req_count; | 1893 | db->first_res_count = db->first_req_count; |
| 1820 | db->first_buffer = cpu_to_le32(d_bus + sizeof(*db)); | 1894 | db->first_buffer = cpu_to_le32(d_bus + sizeof(*db)); |
| 1821 | 1895 | ||
| 1822 | if (offset + rest < PAGE_SIZE) | 1896 | if (p->skip && rest == p->payload_length) |
| 1897 | length = 4; | ||
| 1898 | else if (offset + rest < PAGE_SIZE) | ||
| 1823 | length = rest; | 1899 | length = rest; |
| 1824 | else | 1900 | else |
| 1825 | length = PAGE_SIZE - offset; | 1901 | length = PAGE_SIZE - offset; |
| @@ -1835,7 +1911,8 @@ ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base, | |||
| 1835 | context_append(&ctx->context, d, z, header_z); | 1911 | context_append(&ctx->context, d, z, header_z); |
| 1836 | offset = (offset + length) & ~PAGE_MASK; | 1912 | offset = (offset + length) & ~PAGE_MASK; |
| 1837 | rest -= length; | 1913 | rest -= length; |
| 1838 | page++; | 1914 | if (offset == 0) |
| 1915 | page++; | ||
| 1839 | } | 1916 | } |
| 1840 | 1917 | ||
| 1841 | return 0; | 1918 | return 0; |
| @@ -1849,67 +1926,70 @@ ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base, | |||
| 1849 | { | 1926 | { |
| 1850 | struct iso_context *ctx = container_of(base, struct iso_context, base); | 1927 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
| 1851 | struct descriptor *d = NULL, *pd = NULL; | 1928 | struct descriptor *d = NULL, *pd = NULL; |
| 1852 | struct fw_iso_packet *p; | 1929 | struct fw_iso_packet *p = packet; |
| 1853 | dma_addr_t d_bus, page_bus; | 1930 | dma_addr_t d_bus, page_bus; |
| 1854 | u32 z, header_z, rest; | 1931 | u32 z, header_z, rest; |
| 1855 | int i, page, offset, packet_count, header_size; | 1932 | int i, j, length; |
| 1856 | 1933 | int page, offset, packet_count, header_size, payload_per_buffer; | |
| 1857 | if (packet->skip) { | ||
| 1858 | d = context_get_descriptors(&ctx->context, 1, &d_bus); | ||
| 1859 | if (d == NULL) | ||
| 1860 | return -ENOMEM; | ||
| 1861 | |||
| 1862 | d->control = cpu_to_le16(DESCRIPTOR_STATUS | | ||
| 1863 | DESCRIPTOR_INPUT_LAST | | ||
| 1864 | DESCRIPTOR_BRANCH_ALWAYS | | ||
| 1865 | DESCRIPTOR_WAIT); | ||
| 1866 | context_append(&ctx->context, d, 1, 0); | ||
| 1867 | } | ||
| 1868 | |||
| 1869 | /* one descriptor for header, one for payload */ | ||
| 1870 | /* FIXME: handle cases where we need multiple desc. for payload */ | ||
| 1871 | z = 2; | ||
| 1872 | p = packet; | ||
| 1873 | 1934 | ||
| 1874 | /* | 1935 | /* |
| 1875 | * The OHCI controller puts the status word in the | 1936 | * The OHCI controller puts the status word in the |
| 1876 | * buffer too, so we need 4 extra bytes per packet. | 1937 | * buffer too, so we need 4 extra bytes per packet. |
| 1877 | */ | 1938 | */ |
| 1878 | packet_count = p->header_length / ctx->base.header_size; | 1939 | packet_count = p->header_length / ctx->base.header_size; |
| 1879 | header_size = packet_count * (ctx->base.header_size + 4); | 1940 | header_size = ctx->base.header_size + 4; |
| 1880 | 1941 | ||
| 1881 | /* Get header size in number of descriptors. */ | 1942 | /* Get header size in number of descriptors. */ |
| 1882 | header_z = DIV_ROUND_UP(header_size, sizeof(*d)); | 1943 | header_z = DIV_ROUND_UP(header_size, sizeof(*d)); |
| 1883 | page = payload >> PAGE_SHIFT; | 1944 | page = payload >> PAGE_SHIFT; |
| 1884 | offset = payload & ~PAGE_MASK; | 1945 | offset = payload & ~PAGE_MASK; |
| 1885 | rest = p->payload_length; | 1946 | payload_per_buffer = p->payload_length / packet_count; |
| 1886 | 1947 | ||
| 1887 | for (i = 0; i < packet_count; i++) { | 1948 | for (i = 0; i < packet_count; i++) { |
| 1888 | /* d points to the header descriptor */ | 1949 | /* d points to the header descriptor */ |
| 1950 | z = DIV_ROUND_UP(payload_per_buffer + offset, PAGE_SIZE) + 1; | ||
| 1889 | d = context_get_descriptors(&ctx->context, | 1951 | d = context_get_descriptors(&ctx->context, |
| 1890 | z + header_z, &d_bus); | 1952 | z + header_z, &d_bus); |
| 1891 | if (d == NULL) | 1953 | if (d == NULL) |
| 1892 | return -ENOMEM; | 1954 | return -ENOMEM; |
| 1893 | 1955 | ||
| 1894 | d->control = cpu_to_le16(DESCRIPTOR_INPUT_MORE); | 1956 | d->control = cpu_to_le16(DESCRIPTOR_STATUS | |
| 1957 | DESCRIPTOR_INPUT_MORE); | ||
| 1958 | if (p->skip && i == 0) | ||
| 1959 | d->control |= cpu_to_le16(DESCRIPTOR_WAIT); | ||
| 1895 | d->req_count = cpu_to_le16(header_size); | 1960 | d->req_count = cpu_to_le16(header_size); |
| 1896 | d->res_count = d->req_count; | 1961 | d->res_count = d->req_count; |
| 1962 | d->transfer_status = 0; | ||
| 1897 | d->data_address = cpu_to_le32(d_bus + (z * sizeof(*d))); | 1963 | d->data_address = cpu_to_le32(d_bus + (z * sizeof(*d))); |
| 1898 | 1964 | ||
| 1899 | /* pd points to the payload descriptor */ | 1965 | rest = payload_per_buffer; |
| 1900 | pd = d + 1; | 1966 | for (j = 1; j < z; j++) { |
| 1967 | pd = d + j; | ||
| 1968 | pd->control = cpu_to_le16(DESCRIPTOR_STATUS | | ||
| 1969 | DESCRIPTOR_INPUT_MORE); | ||
| 1970 | |||
| 1971 | if (offset + rest < PAGE_SIZE) | ||
| 1972 | length = rest; | ||
| 1973 | else | ||
| 1974 | length = PAGE_SIZE - offset; | ||
| 1975 | pd->req_count = cpu_to_le16(length); | ||
| 1976 | pd->res_count = pd->req_count; | ||
| 1977 | pd->transfer_status = 0; | ||
| 1978 | |||
| 1979 | page_bus = page_private(buffer->pages[page]); | ||
| 1980 | pd->data_address = cpu_to_le32(page_bus + offset); | ||
| 1981 | |||
| 1982 | offset = (offset + length) & ~PAGE_MASK; | ||
| 1983 | rest -= length; | ||
| 1984 | if (offset == 0) | ||
| 1985 | page++; | ||
| 1986 | } | ||
| 1901 | pd->control = cpu_to_le16(DESCRIPTOR_STATUS | | 1987 | pd->control = cpu_to_le16(DESCRIPTOR_STATUS | |
| 1902 | DESCRIPTOR_INPUT_LAST | | 1988 | DESCRIPTOR_INPUT_LAST | |
| 1903 | DESCRIPTOR_BRANCH_ALWAYS); | 1989 | DESCRIPTOR_BRANCH_ALWAYS); |
| 1904 | if (p->interrupt) | 1990 | if (p->interrupt && i == packet_count - 1) |
| 1905 | pd->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS); | 1991 | pd->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS); |
| 1906 | 1992 | ||
| 1907 | pd->req_count = cpu_to_le16(rest); | ||
| 1908 | pd->res_count = pd->req_count; | ||
| 1909 | |||
| 1910 | page_bus = page_private(buffer->pages[page]); | ||
| 1911 | pd->data_address = cpu_to_le32(page_bus + offset); | ||
| 1912 | |||
| 1913 | context_append(&ctx->context, d, z, header_z); | 1993 | context_append(&ctx->context, d, z, header_z); |
| 1914 | } | 1994 | } |
| 1915 | 1995 | ||
| @@ -1923,16 +2003,22 @@ ohci_queue_iso(struct fw_iso_context *base, | |||
| 1923 | unsigned long payload) | 2003 | unsigned long payload) |
| 1924 | { | 2004 | { |
| 1925 | struct iso_context *ctx = container_of(base, struct iso_context, base); | 2005 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
| 2006 | unsigned long flags; | ||
| 2007 | int retval; | ||
| 1926 | 2008 | ||
| 2009 | spin_lock_irqsave(&ctx->context.ohci->lock, flags); | ||
| 1927 | if (base->type == FW_ISO_CONTEXT_TRANSMIT) | 2010 | if (base->type == FW_ISO_CONTEXT_TRANSMIT) |
| 1928 | return ohci_queue_iso_transmit(base, packet, buffer, payload); | 2011 | retval = ohci_queue_iso_transmit(base, packet, buffer, payload); |
| 1929 | else if (ctx->context.ohci->version >= OHCI_VERSION_1_1) | 2012 | else if (ctx->context.ohci->version >= OHCI_VERSION_1_1) |
| 1930 | return ohci_queue_iso_receive_dualbuffer(base, packet, | 2013 | retval = ohci_queue_iso_receive_dualbuffer(base, packet, |
| 1931 | buffer, payload); | 2014 | buffer, payload); |
| 1932 | else | 2015 | else |
| 1933 | return ohci_queue_iso_receive_packet_per_buffer(base, packet, | 2016 | retval = ohci_queue_iso_receive_packet_per_buffer(base, packet, |
| 1934 | buffer, | 2017 | buffer, |
| 1935 | payload); | 2018 | payload); |
| 2019 | spin_unlock_irqrestore(&ctx->context.ohci->lock, flags); | ||
| 2020 | |||
| 2021 | return retval; | ||
| 1936 | } | 2022 | } |
| 1937 | 2023 | ||
| 1938 | static const struct fw_card_driver ohci_driver = { | 2024 | static const struct fw_card_driver ohci_driver = { |
| @@ -2004,10 +2090,10 @@ pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) | |||
| 2004 | ar_context_init(&ohci->ar_response_ctx, ohci, | 2090 | ar_context_init(&ohci->ar_response_ctx, ohci, |
| 2005 | OHCI1394_AsRspRcvContextControlSet); | 2091 | OHCI1394_AsRspRcvContextControlSet); |
| 2006 | 2092 | ||
| 2007 | context_init(&ohci->at_request_ctx, ohci, AT_BUFFER_SIZE, | 2093 | context_init(&ohci->at_request_ctx, ohci, |
| 2008 | OHCI1394_AsReqTrContextControlSet, handle_at_packet); | 2094 | OHCI1394_AsReqTrContextControlSet, handle_at_packet); |
| 2009 | 2095 | ||
| 2010 | context_init(&ohci->at_response_ctx, ohci, AT_BUFFER_SIZE, | 2096 | context_init(&ohci->at_response_ctx, ohci, |
| 2011 | OHCI1394_AsRspTrContextControlSet, handle_at_packet); | 2097 | OHCI1394_AsRspTrContextControlSet, handle_at_packet); |
| 2012 | 2098 | ||
| 2013 | reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, ~0); | 2099 | reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, ~0); |
diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c index c2169d215bf7..19ece9b6d742 100644 --- a/drivers/firewire/fw-sbp2.c +++ b/drivers/firewire/fw-sbp2.c | |||
| @@ -40,6 +40,7 @@ | |||
| 40 | #include <linux/stringify.h> | 40 | #include <linux/stringify.h> |
| 41 | #include <linux/timer.h> | 41 | #include <linux/timer.h> |
| 42 | #include <linux/workqueue.h> | 42 | #include <linux/workqueue.h> |
| 43 | #include <asm/system.h> | ||
| 43 | 44 | ||
| 44 | #include <scsi/scsi.h> | 45 | #include <scsi/scsi.h> |
| 45 | #include <scsi/scsi_cmnd.h> | 46 | #include <scsi/scsi_cmnd.h> |
| @@ -148,18 +149,26 @@ struct sbp2_target { | |||
| 148 | 149 | ||
| 149 | unsigned workarounds; | 150 | unsigned workarounds; |
| 150 | struct list_head lu_list; | 151 | struct list_head lu_list; |
| 152 | |||
| 153 | unsigned int mgt_orb_timeout; | ||
| 151 | }; | 154 | }; |
| 152 | 155 | ||
| 153 | #define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000 | 156 | /* |
| 154 | #define SBP2_MAX_SECTORS 255 /* Max sectors supported */ | 157 | * Per section 7.4.8 of the SBP-2 spec, a mgt_ORB_timeout value can be |
| 158 | * provided in the config rom. Most devices do provide a value, which | ||
| 159 | * we'll use for login management orbs, but with some sane limits. | ||
| 160 | */ | ||
| 161 | #define SBP2_MIN_LOGIN_ORB_TIMEOUT 5000U /* Timeout in ms */ | ||
| 162 | #define SBP2_MAX_LOGIN_ORB_TIMEOUT 40000U /* Timeout in ms */ | ||
| 155 | #define SBP2_ORB_TIMEOUT 2000 /* Timeout in ms */ | 163 | #define SBP2_ORB_TIMEOUT 2000 /* Timeout in ms */ |
| 156 | |||
| 157 | #define SBP2_ORB_NULL 0x80000000 | 164 | #define SBP2_ORB_NULL 0x80000000 |
| 165 | #define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000 | ||
| 158 | 166 | ||
| 159 | #define SBP2_DIRECTION_TO_MEDIA 0x0 | 167 | #define SBP2_DIRECTION_TO_MEDIA 0x0 |
| 160 | #define SBP2_DIRECTION_FROM_MEDIA 0x1 | 168 | #define SBP2_DIRECTION_FROM_MEDIA 0x1 |
| 161 | 169 | ||
| 162 | /* Unit directory keys */ | 170 | /* Unit directory keys */ |
| 171 | #define SBP2_CSR_UNIT_CHARACTERISTICS 0x3a | ||
| 163 | #define SBP2_CSR_FIRMWARE_REVISION 0x3c | 172 | #define SBP2_CSR_FIRMWARE_REVISION 0x3c |
| 164 | #define SBP2_CSR_LOGICAL_UNIT_NUMBER 0x14 | 173 | #define SBP2_CSR_LOGICAL_UNIT_NUMBER 0x14 |
| 165 | #define SBP2_CSR_LOGICAL_UNIT_DIRECTORY 0xd4 | 174 | #define SBP2_CSR_LOGICAL_UNIT_DIRECTORY 0xd4 |
| @@ -489,6 +498,7 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id, | |||
| 489 | { | 498 | { |
| 490 | struct fw_device *device = fw_device(lu->tgt->unit->device.parent); | 499 | struct fw_device *device = fw_device(lu->tgt->unit->device.parent); |
| 491 | struct sbp2_management_orb *orb; | 500 | struct sbp2_management_orb *orb; |
| 501 | unsigned int timeout; | ||
| 492 | int retval = -ENOMEM; | 502 | int retval = -ENOMEM; |
| 493 | 503 | ||
| 494 | orb = kzalloc(sizeof(*orb), GFP_ATOMIC); | 504 | orb = kzalloc(sizeof(*orb), GFP_ATOMIC); |
| @@ -516,9 +526,13 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id, | |||
| 516 | orb->request.status_fifo.low = lu->address_handler.offset; | 526 | orb->request.status_fifo.low = lu->address_handler.offset; |
| 517 | 527 | ||
| 518 | if (function == SBP2_LOGIN_REQUEST) { | 528 | if (function == SBP2_LOGIN_REQUEST) { |
| 529 | /* Ask for 2^2 == 4 seconds reconnect grace period */ | ||
| 519 | orb->request.misc |= | 530 | orb->request.misc |= |
| 520 | MANAGEMENT_ORB_EXCLUSIVE(sbp2_param_exclusive_login) | | 531 | MANAGEMENT_ORB_RECONNECT(2) | |
| 521 | MANAGEMENT_ORB_RECONNECT(0); | 532 | MANAGEMENT_ORB_EXCLUSIVE(sbp2_param_exclusive_login); |
| 533 | timeout = lu->tgt->mgt_orb_timeout; | ||
| 534 | } else { | ||
| 535 | timeout = SBP2_ORB_TIMEOUT; | ||
| 522 | } | 536 | } |
| 523 | 537 | ||
| 524 | fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request)); | 538 | fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request)); |
| @@ -535,8 +549,7 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id, | |||
| 535 | sbp2_send_orb(&orb->base, lu, node_id, generation, | 549 | sbp2_send_orb(&orb->base, lu, node_id, generation, |
| 536 | lu->tgt->management_agent_address); | 550 | lu->tgt->management_agent_address); |
| 537 | 551 | ||
| 538 | wait_for_completion_timeout(&orb->done, | 552 | wait_for_completion_timeout(&orb->done, msecs_to_jiffies(timeout)); |
| 539 | msecs_to_jiffies(SBP2_ORB_TIMEOUT)); | ||
| 540 | 553 | ||
| 541 | retval = -EIO; | 554 | retval = -EIO; |
| 542 | if (sbp2_cancel_orbs(lu) == 0) { | 555 | if (sbp2_cancel_orbs(lu) == 0) { |
| @@ -608,13 +621,17 @@ static void sbp2_release_target(struct kref *kref) | |||
| 608 | struct sbp2_logical_unit *lu, *next; | 621 | struct sbp2_logical_unit *lu, *next; |
| 609 | struct Scsi_Host *shost = | 622 | struct Scsi_Host *shost = |
| 610 | container_of((void *)tgt, struct Scsi_Host, hostdata[0]); | 623 | container_of((void *)tgt, struct Scsi_Host, hostdata[0]); |
| 624 | struct fw_device *device = fw_device(tgt->unit->device.parent); | ||
| 611 | 625 | ||
| 612 | list_for_each_entry_safe(lu, next, &tgt->lu_list, link) { | 626 | list_for_each_entry_safe(lu, next, &tgt->lu_list, link) { |
| 613 | if (lu->sdev) | 627 | if (lu->sdev) |
| 614 | scsi_remove_device(lu->sdev); | 628 | scsi_remove_device(lu->sdev); |
| 615 | 629 | ||
| 616 | sbp2_send_management_orb(lu, tgt->node_id, lu->generation, | 630 | if (!fw_device_is_shutdown(device)) |
| 617 | SBP2_LOGOUT_REQUEST, lu->login_id, NULL); | 631 | sbp2_send_management_orb(lu, tgt->node_id, |
| 632 | lu->generation, SBP2_LOGOUT_REQUEST, | ||
| 633 | lu->login_id, NULL); | ||
| 634 | |||
| 618 | fw_core_remove_address_handler(&lu->address_handler); | 635 | fw_core_remove_address_handler(&lu->address_handler); |
| 619 | list_del(&lu->link); | 636 | list_del(&lu->link); |
| 620 | kfree(lu); | 637 | kfree(lu); |
| @@ -628,6 +645,21 @@ static void sbp2_release_target(struct kref *kref) | |||
| 628 | 645 | ||
| 629 | static struct workqueue_struct *sbp2_wq; | 646 | static struct workqueue_struct *sbp2_wq; |
| 630 | 647 | ||
| 648 | /* | ||
| 649 | * Always get the target's kref when scheduling work on one its units. | ||
| 650 | * Each workqueue job is responsible to call sbp2_target_put() upon return. | ||
| 651 | */ | ||
| 652 | static void sbp2_queue_work(struct sbp2_logical_unit *lu, unsigned long delay) | ||
| 653 | { | ||
| 654 | if (queue_delayed_work(sbp2_wq, &lu->work, delay)) | ||
| 655 | kref_get(&lu->tgt->kref); | ||
| 656 | } | ||
| 657 | |||
| 658 | static void sbp2_target_put(struct sbp2_target *tgt) | ||
| 659 | { | ||
| 660 | kref_put(&tgt->kref, sbp2_release_target); | ||
| 661 | } | ||
| 662 | |||
| 631 | static void sbp2_reconnect(struct work_struct *work); | 663 | static void sbp2_reconnect(struct work_struct *work); |
| 632 | 664 | ||
| 633 | static void sbp2_login(struct work_struct *work) | 665 | static void sbp2_login(struct work_struct *work) |
| @@ -643,22 +675,19 @@ static void sbp2_login(struct work_struct *work) | |||
| 643 | struct sbp2_login_response response; | 675 | struct sbp2_login_response response; |
| 644 | int generation, node_id, local_node_id; | 676 | int generation, node_id, local_node_id; |
| 645 | 677 | ||
| 646 | generation = device->card->generation; | 678 | generation = device->generation; |
| 647 | node_id = device->node->node_id; | 679 | smp_rmb(); /* node_id must not be older than generation */ |
| 648 | local_node_id = device->card->local_node->node_id; | 680 | node_id = device->node_id; |
| 681 | local_node_id = device->card->node_id; | ||
| 649 | 682 | ||
| 650 | if (sbp2_send_management_orb(lu, node_id, generation, | 683 | if (sbp2_send_management_orb(lu, node_id, generation, |
| 651 | SBP2_LOGIN_REQUEST, lu->lun, &response) < 0) { | 684 | SBP2_LOGIN_REQUEST, lu->lun, &response) < 0) { |
| 652 | if (lu->retries++ < 5) { | 685 | if (lu->retries++ < 5) |
| 653 | if (queue_delayed_work(sbp2_wq, &lu->work, | 686 | sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5)); |
| 654 | DIV_ROUND_UP(HZ, 5))) | 687 | else |
| 655 | kref_get(&lu->tgt->kref); | ||
| 656 | } else { | ||
| 657 | fw_error("failed to login to %s LUN %04x\n", | 688 | fw_error("failed to login to %s LUN %04x\n", |
| 658 | unit->device.bus_id, lu->lun); | 689 | unit->device.bus_id, lu->lun); |
| 659 | } | 690 | goto out; |
| 660 | kref_put(&lu->tgt->kref, sbp2_release_target); | ||
| 661 | return; | ||
| 662 | } | 691 | } |
| 663 | 692 | ||
| 664 | lu->generation = generation; | 693 | lu->generation = generation; |
| @@ -700,7 +729,8 @@ static void sbp2_login(struct work_struct *work) | |||
| 700 | lu->sdev = sdev; | 729 | lu->sdev = sdev; |
| 701 | scsi_device_put(sdev); | 730 | scsi_device_put(sdev); |
| 702 | } | 731 | } |
| 703 | kref_put(&lu->tgt->kref, sbp2_release_target); | 732 | out: |
| 733 | sbp2_target_put(lu->tgt); | ||
| 704 | } | 734 | } |
| 705 | 735 | ||
| 706 | static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry) | 736 | static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry) |
| @@ -750,6 +780,7 @@ static int sbp2_scan_unit_dir(struct sbp2_target *tgt, u32 *directory, | |||
| 750 | { | 780 | { |
| 751 | struct fw_csr_iterator ci; | 781 | struct fw_csr_iterator ci; |
| 752 | int key, value; | 782 | int key, value; |
| 783 | unsigned int timeout; | ||
| 753 | 784 | ||
| 754 | fw_csr_iterator_init(&ci, directory); | 785 | fw_csr_iterator_init(&ci, directory); |
| 755 | while (fw_csr_iterator_next(&ci, &key, &value)) { | 786 | while (fw_csr_iterator_next(&ci, &key, &value)) { |
| @@ -772,6 +803,21 @@ static int sbp2_scan_unit_dir(struct sbp2_target *tgt, u32 *directory, | |||
| 772 | *firmware_revision = value; | 803 | *firmware_revision = value; |
| 773 | break; | 804 | break; |
| 774 | 805 | ||
| 806 | case SBP2_CSR_UNIT_CHARACTERISTICS: | ||
| 807 | /* the timeout value is stored in 500ms units */ | ||
| 808 | timeout = ((unsigned int) value >> 8 & 0xff) * 500; | ||
| 809 | timeout = max(timeout, SBP2_MIN_LOGIN_ORB_TIMEOUT); | ||
| 810 | tgt->mgt_orb_timeout = | ||
| 811 | min(timeout, SBP2_MAX_LOGIN_ORB_TIMEOUT); | ||
| 812 | |||
| 813 | if (timeout > tgt->mgt_orb_timeout) | ||
| 814 | fw_notify("%s: config rom contains %ds " | ||
| 815 | "management ORB timeout, limiting " | ||
| 816 | "to %ds\n", tgt->unit->device.bus_id, | ||
| 817 | timeout / 1000, | ||
| 818 | tgt->mgt_orb_timeout / 1000); | ||
| 819 | break; | ||
| 820 | |||
| 775 | case SBP2_CSR_LOGICAL_UNIT_NUMBER: | 821 | case SBP2_CSR_LOGICAL_UNIT_NUMBER: |
| 776 | if (sbp2_add_logical_unit(tgt, value) < 0) | 822 | if (sbp2_add_logical_unit(tgt, value) < 0) |
| 777 | return -ENOMEM; | 823 | return -ENOMEM; |
| @@ -865,18 +911,13 @@ static int sbp2_probe(struct device *dev) | |||
| 865 | 911 | ||
| 866 | get_device(&unit->device); | 912 | get_device(&unit->device); |
| 867 | 913 | ||
| 868 | /* | 914 | /* Do the login in a workqueue so we can easily reschedule retries. */ |
| 869 | * We schedule work to do the login so we can easily | ||
| 870 | * reschedule retries. Always get the ref before scheduling | ||
| 871 | * work. | ||
| 872 | */ | ||
| 873 | list_for_each_entry(lu, &tgt->lu_list, link) | 915 | list_for_each_entry(lu, &tgt->lu_list, link) |
| 874 | if (queue_delayed_work(sbp2_wq, &lu->work, 0)) | 916 | sbp2_queue_work(lu, 0); |
| 875 | kref_get(&tgt->kref); | ||
| 876 | return 0; | 917 | return 0; |
| 877 | 918 | ||
| 878 | fail_tgt_put: | 919 | fail_tgt_put: |
| 879 | kref_put(&tgt->kref, sbp2_release_target); | 920 | sbp2_target_put(tgt); |
| 880 | return -ENOMEM; | 921 | return -ENOMEM; |
| 881 | 922 | ||
| 882 | fail_shost_put: | 923 | fail_shost_put: |
| @@ -889,7 +930,7 @@ static int sbp2_remove(struct device *dev) | |||
| 889 | struct fw_unit *unit = fw_unit(dev); | 930 | struct fw_unit *unit = fw_unit(dev); |
| 890 | struct sbp2_target *tgt = unit->device.driver_data; | 931 | struct sbp2_target *tgt = unit->device.driver_data; |
| 891 | 932 | ||
| 892 | kref_put(&tgt->kref, sbp2_release_target); | 933 | sbp2_target_put(tgt); |
| 893 | return 0; | 934 | return 0; |
| 894 | } | 935 | } |
| 895 | 936 | ||
| @@ -901,9 +942,10 @@ static void sbp2_reconnect(struct work_struct *work) | |||
| 901 | struct fw_device *device = fw_device(unit->device.parent); | 942 | struct fw_device *device = fw_device(unit->device.parent); |
| 902 | int generation, node_id, local_node_id; | 943 | int generation, node_id, local_node_id; |
| 903 | 944 | ||
| 904 | generation = device->card->generation; | 945 | generation = device->generation; |
| 905 | node_id = device->node->node_id; | 946 | smp_rmb(); /* node_id must not be older than generation */ |
| 906 | local_node_id = device->card->local_node->node_id; | 947 | node_id = device->node_id; |
| 948 | local_node_id = device->card->node_id; | ||
| 907 | 949 | ||
| 908 | if (sbp2_send_management_orb(lu, node_id, generation, | 950 | if (sbp2_send_management_orb(lu, node_id, generation, |
| 909 | SBP2_RECONNECT_REQUEST, | 951 | SBP2_RECONNECT_REQUEST, |
| @@ -915,10 +957,8 @@ static void sbp2_reconnect(struct work_struct *work) | |||
| 915 | lu->retries = 0; | 957 | lu->retries = 0; |
| 916 | PREPARE_DELAYED_WORK(&lu->work, sbp2_login); | 958 | PREPARE_DELAYED_WORK(&lu->work, sbp2_login); |
| 917 | } | 959 | } |
| 918 | if (queue_delayed_work(sbp2_wq, &lu->work, DIV_ROUND_UP(HZ, 5))) | 960 | sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5)); |
| 919 | kref_get(&lu->tgt->kref); | 961 | goto out; |
| 920 | kref_put(&lu->tgt->kref, sbp2_release_target); | ||
| 921 | return; | ||
| 922 | } | 962 | } |
| 923 | 963 | ||
| 924 | lu->generation = generation; | 964 | lu->generation = generation; |
| @@ -930,8 +970,8 @@ static void sbp2_reconnect(struct work_struct *work) | |||
| 930 | 970 | ||
| 931 | sbp2_agent_reset(lu); | 971 | sbp2_agent_reset(lu); |
| 932 | sbp2_cancel_orbs(lu); | 972 | sbp2_cancel_orbs(lu); |
| 933 | 973 | out: | |
| 934 | kref_put(&lu->tgt->kref, sbp2_release_target); | 974 | sbp2_target_put(lu->tgt); |
| 935 | } | 975 | } |
| 936 | 976 | ||
| 937 | static void sbp2_update(struct fw_unit *unit) | 977 | static void sbp2_update(struct fw_unit *unit) |
| @@ -947,8 +987,7 @@ static void sbp2_update(struct fw_unit *unit) | |||
| 947 | */ | 987 | */ |
| 948 | list_for_each_entry(lu, &tgt->lu_list, link) { | 988 | list_for_each_entry(lu, &tgt->lu_list, link) { |
| 949 | lu->retries = 0; | 989 | lu->retries = 0; |
| 950 | if (queue_delayed_work(sbp2_wq, &lu->work, 0)) | 990 | sbp2_queue_work(lu, 0); |
| 951 | kref_get(&tgt->kref); | ||
| 952 | } | 991 | } |
| 953 | } | 992 | } |
| 954 | 993 | ||
| @@ -1103,9 +1142,9 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, | |||
| 1103 | * elements larger than 65535 bytes, some IOMMUs may merge sg elements | 1142 | * elements larger than 65535 bytes, some IOMMUs may merge sg elements |
| 1104 | * during DMA mapping, and Linux currently doesn't prevent this. | 1143 | * during DMA mapping, and Linux currently doesn't prevent this. |
| 1105 | */ | 1144 | */ |
| 1106 | for (i = 0, j = 0; i < count; i++) { | 1145 | for (i = 0, j = 0; i < count; i++, sg = sg_next(sg)) { |
| 1107 | sg_len = sg_dma_len(sg + i); | 1146 | sg_len = sg_dma_len(sg); |
| 1108 | sg_addr = sg_dma_address(sg + i); | 1147 | sg_addr = sg_dma_address(sg); |
| 1109 | while (sg_len) { | 1148 | while (sg_len) { |
| 1110 | /* FIXME: This won't get us out of the pinch. */ | 1149 | /* FIXME: This won't get us out of the pinch. */ |
| 1111 | if (unlikely(j >= ARRAY_SIZE(orb->page_table))) { | 1150 | if (unlikely(j >= ARRAY_SIZE(orb->page_table))) { |
diff --git a/drivers/firewire/fw-topology.c b/drivers/firewire/fw-topology.c index 0fc9b000e99d..172c1867e9aa 100644 --- a/drivers/firewire/fw-topology.c +++ b/drivers/firewire/fw-topology.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
| 22 | #include <linux/wait.h> | 22 | #include <linux/wait.h> |
| 23 | #include <linux/errno.h> | 23 | #include <linux/errno.h> |
| 24 | #include <asm/system.h> | ||
| 24 | #include "fw-transaction.h" | 25 | #include "fw-transaction.h" |
| 25 | #include "fw-topology.h" | 26 | #include "fw-topology.h" |
| 26 | 27 | ||
| @@ -518,6 +519,11 @@ fw_core_handle_bus_reset(struct fw_card *card, | |||
| 518 | card->bm_retries = 0; | 519 | card->bm_retries = 0; |
| 519 | 520 | ||
| 520 | card->node_id = node_id; | 521 | card->node_id = node_id; |
| 522 | /* | ||
| 523 | * Update node_id before generation to prevent anybody from using | ||
| 524 | * a stale node_id together with a current generation. | ||
| 525 | */ | ||
| 526 | smp_wmb(); | ||
| 521 | card->generation = generation; | 527 | card->generation = generation; |
| 522 | card->reset_jiffies = jiffies; | 528 | card->reset_jiffies = jiffies; |
| 523 | schedule_delayed_work(&card->work, 0); | 529 | schedule_delayed_work(&card->work, 0); |
diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/fw-transaction.c index c00d4a9b39e5..7fcc59dedf08 100644 --- a/drivers/firewire/fw-transaction.c +++ b/drivers/firewire/fw-transaction.c | |||
| @@ -153,7 +153,7 @@ fw_fill_request(struct fw_packet *packet, int tcode, int tlabel, | |||
| 153 | int ext_tcode; | 153 | int ext_tcode; |
| 154 | 154 | ||
| 155 | if (tcode > 0x10) { | 155 | if (tcode > 0x10) { |
| 156 | ext_tcode = tcode - 0x10; | 156 | ext_tcode = tcode & ~0x10; |
| 157 | tcode = TCODE_LOCK_REQUEST; | 157 | tcode = TCODE_LOCK_REQUEST; |
| 158 | } else | 158 | } else |
| 159 | ext_tcode = 0; | 159 | ext_tcode = 0; |
| @@ -650,7 +650,7 @@ fw_core_handle_request(struct fw_card *card, struct fw_packet *p) | |||
| 650 | HEADER_GET_OFFSET_HIGH(p->header[1]) << 32) | p->header[2]; | 650 | HEADER_GET_OFFSET_HIGH(p->header[1]) << 32) | p->header[2]; |
| 651 | tcode = HEADER_GET_TCODE(p->header[0]); | 651 | tcode = HEADER_GET_TCODE(p->header[0]); |
| 652 | destination = HEADER_GET_DESTINATION(p->header[0]); | 652 | destination = HEADER_GET_DESTINATION(p->header[0]); |
| 653 | source = HEADER_GET_SOURCE(p->header[0]); | 653 | source = HEADER_GET_SOURCE(p->header[1]); |
| 654 | 654 | ||
| 655 | spin_lock_irqsave(&address_handler_lock, flags); | 655 | spin_lock_irqsave(&address_handler_lock, flags); |
| 656 | handler = lookup_enclosing_address_handler(&address_handler_list, | 656 | handler = lookup_enclosing_address_handler(&address_handler_list, |
diff --git a/drivers/ieee1394/dma.c b/drivers/ieee1394/dma.c index 7c4eb39b7024..73685e7dc7e4 100644 --- a/drivers/ieee1394/dma.c +++ b/drivers/ieee1394/dma.c | |||
| @@ -231,37 +231,24 @@ void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset, | |||
| 231 | 231 | ||
| 232 | #ifdef CONFIG_MMU | 232 | #ifdef CONFIG_MMU |
| 233 | 233 | ||
| 234 | /* nopage() handler for mmap access */ | 234 | static int dma_region_pagefault(struct vm_area_struct *vma, |
| 235 | 235 | struct vm_fault *vmf) | |
| 236 | static struct page *dma_region_pagefault(struct vm_area_struct *area, | ||
| 237 | unsigned long address, int *type) | ||
| 238 | { | 236 | { |
| 239 | unsigned long offset; | 237 | struct dma_region *dma = (struct dma_region *)vma->vm_private_data; |
| 240 | unsigned long kernel_virt_addr; | ||
| 241 | struct page *ret = NOPAGE_SIGBUS; | ||
| 242 | |||
| 243 | struct dma_region *dma = (struct dma_region *)area->vm_private_data; | ||
| 244 | 238 | ||
| 245 | if (!dma->kvirt) | 239 | if (!dma->kvirt) |
| 246 | goto out; | 240 | return VM_FAULT_SIGBUS; |
| 247 | 241 | ||
| 248 | if ((address < (unsigned long)area->vm_start) || | 242 | if (vmf->pgoff >= dma->n_pages) |
| 249 | (address > | 243 | return VM_FAULT_SIGBUS; |
| 250 | (unsigned long)area->vm_start + (dma->n_pages << PAGE_SHIFT))) | 244 | |
| 251 | goto out; | 245 | vmf->page = vmalloc_to_page(dma->kvirt + (vmf->pgoff << PAGE_SHIFT)); |
| 252 | 246 | get_page(vmf->page); | |
| 253 | if (type) | 247 | return 0; |
| 254 | *type = VM_FAULT_MINOR; | ||
| 255 | offset = address - area->vm_start; | ||
| 256 | kernel_virt_addr = (unsigned long)dma->kvirt + offset; | ||
| 257 | ret = vmalloc_to_page((void *)kernel_virt_addr); | ||
| 258 | get_page(ret); | ||
| 259 | out: | ||
| 260 | return ret; | ||
| 261 | } | 248 | } |
| 262 | 249 | ||
| 263 | static struct vm_operations_struct dma_region_vm_ops = { | 250 | static struct vm_operations_struct dma_region_vm_ops = { |
| 264 | .nopage = dma_region_pagefault, | 251 | .fault = dma_region_pagefault, |
| 265 | }; | 252 | }; |
| 266 | 253 | ||
| 267 | /** | 254 | /** |
| @@ -275,7 +262,7 @@ int dma_region_mmap(struct dma_region *dma, struct file *file, | |||
| 275 | if (!dma->kvirt) | 262 | if (!dma->kvirt) |
| 276 | return -EINVAL; | 263 | return -EINVAL; |
| 277 | 264 | ||
| 278 | /* must be page-aligned */ | 265 | /* must be page-aligned (XXX: comment is wrong, we could allow pgoff) */ |
| 279 | if (vma->vm_pgoff != 0) | 266 | if (vma->vm_pgoff != 0) |
| 280 | return -EINVAL; | 267 | return -EINVAL; |
| 281 | 268 | ||
diff --git a/drivers/ieee1394/ieee1394_transactions.c b/drivers/ieee1394/ieee1394_transactions.c index 677989320951..10c3d9f8c038 100644 --- a/drivers/ieee1394/ieee1394_transactions.c +++ b/drivers/ieee1394/ieee1394_transactions.c | |||
| @@ -570,71 +570,3 @@ int hpsb_write(struct hpsb_host *host, nodeid_t node, unsigned int generation, | |||
| 570 | 570 | ||
| 571 | return retval; | 571 | return retval; |
| 572 | } | 572 | } |
| 573 | |||
| 574 | #if 0 | ||
| 575 | |||
| 576 | int hpsb_lock(struct hpsb_host *host, nodeid_t node, unsigned int generation, | ||
| 577 | u64 addr, int extcode, quadlet_t * data, quadlet_t arg) | ||
| 578 | { | ||
| 579 | struct hpsb_packet *packet; | ||
| 580 | int retval = 0; | ||
| 581 | |||
| 582 | BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet | ||
| 583 | |||
| 584 | packet = hpsb_make_lockpacket(host, node, addr, extcode, data, arg); | ||
| 585 | if (!packet) | ||
| 586 | return -ENOMEM; | ||
| 587 | |||
| 588 | packet->generation = generation; | ||
| 589 | retval = hpsb_send_packet_and_wait(packet); | ||
| 590 | if (retval < 0) | ||
| 591 | goto hpsb_lock_fail; | ||
| 592 | |||
| 593 | retval = hpsb_packet_success(packet); | ||
| 594 | |||
| 595 | if (retval == 0) { | ||
| 596 | *data = packet->data[0]; | ||
| 597 | } | ||
| 598 | |||
| 599 | hpsb_lock_fail: | ||
| 600 | hpsb_free_tlabel(packet); | ||
| 601 | hpsb_free_packet(packet); | ||
| 602 | |||
| 603 | return retval; | ||
| 604 | } | ||
| 605 | |||
| 606 | int hpsb_send_gasp(struct hpsb_host *host, int channel, unsigned int generation, | ||
| 607 | quadlet_t * buffer, size_t length, u32 specifier_id, | ||
| 608 | unsigned int version) | ||
| 609 | { | ||
| 610 | struct hpsb_packet *packet; | ||
| 611 | int retval = 0; | ||
| 612 | u16 specifier_id_hi = (specifier_id & 0x00ffff00) >> 8; | ||
| 613 | u8 specifier_id_lo = specifier_id & 0xff; | ||
| 614 | |||
| 615 | HPSB_VERBOSE("Send GASP: channel = %d, length = %Zd", channel, length); | ||
| 616 | |||
| 617 | length += 8; | ||
| 618 | |||
| 619 | packet = hpsb_make_streampacket(host, NULL, length, channel, 3, 0); | ||
| 620 | if (!packet) | ||
| 621 | return -ENOMEM; | ||
| 622 | |||
| 623 | packet->data[0] = cpu_to_be32((host->node_id << 16) | specifier_id_hi); | ||
| 624 | packet->data[1] = | ||
| 625 | cpu_to_be32((specifier_id_lo << 24) | (version & 0x00ffffff)); | ||
| 626 | |||
| 627 | memcpy(&(packet->data[2]), buffer, length - 8); | ||
| 628 | |||
| 629 | packet->generation = generation; | ||
| 630 | |||
| 631 | packet->no_waiter = 1; | ||
| 632 | |||
| 633 | retval = hpsb_send_packet(packet); | ||
| 634 | if (retval < 0) | ||
| 635 | hpsb_free_packet(packet); | ||
| 636 | |||
| 637 | return retval; | ||
| 638 | } | ||
| 639 | |||
| 640 | #endif /* 0 */ | ||
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index 372c5c16eb31..969de2a2d633 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c | |||
| @@ -2126,10 +2126,14 @@ static void ohci_schedule_iso_tasklets(struct ti_ohci *ohci, | |||
| 2126 | list_for_each_entry(t, &ohci->iso_tasklet_list, link) { | 2126 | list_for_each_entry(t, &ohci->iso_tasklet_list, link) { |
| 2127 | mask = 1 << t->context; | 2127 | mask = 1 << t->context; |
| 2128 | 2128 | ||
| 2129 | if (t->type == OHCI_ISO_TRANSMIT && tx_event & mask) | 2129 | if (t->type == OHCI_ISO_TRANSMIT) { |
| 2130 | tasklet_schedule(&t->tasklet); | 2130 | if (tx_event & mask) |
| 2131 | else if (rx_event & mask) | 2131 | tasklet_schedule(&t->tasklet); |
| 2132 | tasklet_schedule(&t->tasklet); | 2132 | } else { |
| 2133 | /* OHCI_ISO_RECEIVE or OHCI_ISO_MULTICHANNEL_RECEIVE */ | ||
| 2134 | if (rx_event & mask) | ||
| 2135 | tasklet_schedule(&t->tasklet); | ||
| 2136 | } | ||
| 2133 | } | 2137 | } |
| 2134 | 2138 | ||
| 2135 | spin_unlock_irqrestore(&ohci->iso_tasklet_list_lock, flags); | 2139 | spin_unlock_irqrestore(&ohci->iso_tasklet_list_lock, flags); |
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c index cadf0479cce5..37e7e109af38 100644 --- a/drivers/ieee1394/raw1394.c +++ b/drivers/ieee1394/raw1394.c | |||
| @@ -858,7 +858,7 @@ static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer, | |||
| 858 | int found = 0, size = 0, rcode = -1; | 858 | int found = 0, size = 0, rcode = -1; |
| 859 | struct arm_request_response *arm_req_resp = NULL; | 859 | struct arm_request_response *arm_req_resp = NULL; |
| 860 | 860 | ||
| 861 | DBGMSG("arm_read called by node: %X" | 861 | DBGMSG("arm_read called by node: %X " |
| 862 | "addr: %4.4x %8.8x length: %Zu", nodeid, | 862 | "addr: %4.4x %8.8x length: %Zu", nodeid, |
| 863 | (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF), | 863 | (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF), |
| 864 | length); | 864 | length); |
| @@ -1012,7 +1012,7 @@ static int arm_write(struct hpsb_host *host, int nodeid, int destid, | |||
| 1012 | int found = 0, size = 0, rcode = -1, length_conflict = 0; | 1012 | int found = 0, size = 0, rcode = -1, length_conflict = 0; |
| 1013 | struct arm_request_response *arm_req_resp = NULL; | 1013 | struct arm_request_response *arm_req_resp = NULL; |
| 1014 | 1014 | ||
| 1015 | DBGMSG("arm_write called by node: %X" | 1015 | DBGMSG("arm_write called by node: %X " |
| 1016 | "addr: %4.4x %8.8x length: %Zu", nodeid, | 1016 | "addr: %4.4x %8.8x length: %Zu", nodeid, |
| 1017 | (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF), | 1017 | (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF), |
| 1018 | length); | 1018 | length); |
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 1eda11abeb1e..2b889d91e673 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c | |||
| @@ -51,6 +51,7 @@ | |||
| 51 | * Grep for inline FIXME comments below. | 51 | * Grep for inline FIXME comments below. |
| 52 | */ | 52 | */ |
| 53 | 53 | ||
| 54 | #include <linux/blkdev.h> | ||
| 54 | #include <linux/compiler.h> | 55 | #include <linux/compiler.h> |
| 55 | #include <linux/delay.h> | 56 | #include <linux/delay.h> |
| 56 | #include <linux/device.h> | 57 | #include <linux/device.h> |
| @@ -127,17 +128,21 @@ MODULE_PARM_DESC(serialize_io, "Serialize requests coming from SCSI drivers " | |||
| 127 | "(default = Y, faster but buggy = N)"); | 128 | "(default = Y, faster but buggy = N)"); |
| 128 | 129 | ||
| 129 | /* | 130 | /* |
| 130 | * Bump up max_sectors if you'd like to support very large sized | 131 | * Adjust max_sectors if you'd like to influence how many sectors each SCSI |
| 131 | * transfers. Please note that some older sbp2 bridge chips are broken for | 132 | * command can transfer at most. Please note that some older SBP-2 bridge |
| 132 | * transfers greater or equal to 128KB. Default is a value of 255 | 133 | * chips are broken for transfers greater or equal to 128KB, therefore |
| 133 | * sectors, or just under 128KB (at 512 byte sector size). I can note that | 134 | * max_sectors used to be a safe 255 sectors for many years. We now have a |
| 134 | * the Oxsemi sbp2 chipsets have no problems supporting very large | 135 | * default of 0 here which means that we let the SCSI stack choose a limit. |
| 135 | * transfer sizes. | 136 | * |
| 137 | * The SBP2_WORKAROUND_128K_MAX_TRANS flag, if set either in the workarounds | ||
| 138 | * module parameter or in the sbp2_workarounds_table[], will override the | ||
| 139 | * value of max_sectors. We should use sbp2_workarounds_table[] to cover any | ||
| 140 | * bridge chip which becomes known to need the 255 sectors limit. | ||
| 136 | */ | 141 | */ |
| 137 | static int sbp2_max_sectors = SBP2_MAX_SECTORS; | 142 | static int sbp2_max_sectors; |
| 138 | module_param_named(max_sectors, sbp2_max_sectors, int, 0444); | 143 | module_param_named(max_sectors, sbp2_max_sectors, int, 0444); |
| 139 | MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported " | 144 | MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported " |
| 140 | "(default = " __stringify(SBP2_MAX_SECTORS) ")"); | 145 | "(default = 0 = use SCSI stack's default)"); |
| 141 | 146 | ||
| 142 | /* | 147 | /* |
| 143 | * Exclusive login to sbp2 device? In most cases, the sbp2 driver should | 148 | * Exclusive login to sbp2 device? In most cases, the sbp2 driver should |
| @@ -1451,7 +1456,7 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb, | |||
| 1451 | struct sbp2_fwhost_info *hi, | 1456 | struct sbp2_fwhost_info *hi, |
| 1452 | struct sbp2_command_info *cmd, | 1457 | struct sbp2_command_info *cmd, |
| 1453 | unsigned int scsi_use_sg, | 1458 | unsigned int scsi_use_sg, |
| 1454 | struct scatterlist *sgpnt, | 1459 | struct scatterlist *sg, |
| 1455 | u32 orb_direction, | 1460 | u32 orb_direction, |
| 1456 | enum dma_data_direction dma_dir) | 1461 | enum dma_data_direction dma_dir) |
| 1457 | { | 1462 | { |
| @@ -1461,12 +1466,12 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb, | |||
| 1461 | 1466 | ||
| 1462 | /* special case if only one element (and less than 64KB in size) */ | 1467 | /* special case if only one element (and less than 64KB in size) */ |
| 1463 | if ((scsi_use_sg == 1) && | 1468 | if ((scsi_use_sg == 1) && |
| 1464 | (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) { | 1469 | (sg_dma_len(sg) <= SBP2_MAX_SG_ELEMENT_LENGTH)) { |
| 1465 | 1470 | ||
| 1466 | cmd->dma_size = sgpnt[0].length; | 1471 | cmd->dma_size = sg_dma_len(sg); |
| 1467 | cmd->dma_type = CMD_DMA_PAGE; | 1472 | cmd->dma_type = CMD_DMA_PAGE; |
| 1468 | cmd->cmd_dma = dma_map_page(hi->host->device.parent, | 1473 | cmd->cmd_dma = dma_map_page(hi->host->device.parent, |
| 1469 | sg_page(&sgpnt[0]), sgpnt[0].offset, | 1474 | sg_page(sg), sg->offset, |
| 1470 | cmd->dma_size, cmd->dma_dir); | 1475 | cmd->dma_size, cmd->dma_dir); |
| 1471 | 1476 | ||
| 1472 | orb->data_descriptor_lo = cmd->cmd_dma; | 1477 | orb->data_descriptor_lo = cmd->cmd_dma; |
| @@ -1477,11 +1482,11 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb, | |||
| 1477 | &cmd->scatter_gather_element[0]; | 1482 | &cmd->scatter_gather_element[0]; |
| 1478 | u32 sg_count, sg_len; | 1483 | u32 sg_count, sg_len; |
| 1479 | dma_addr_t sg_addr; | 1484 | dma_addr_t sg_addr; |
| 1480 | int i, count = dma_map_sg(hi->host->device.parent, sgpnt, | 1485 | int i, count = dma_map_sg(hi->host->device.parent, sg, |
| 1481 | scsi_use_sg, dma_dir); | 1486 | scsi_use_sg, dma_dir); |
| 1482 | 1487 | ||
| 1483 | cmd->dma_size = scsi_use_sg; | 1488 | cmd->dma_size = scsi_use_sg; |
| 1484 | cmd->sge_buffer = sgpnt; | 1489 | cmd->sge_buffer = sg; |
| 1485 | 1490 | ||
| 1486 | /* use page tables (s/g) */ | 1491 | /* use page tables (s/g) */ |
| 1487 | orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); | 1492 | orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); |
| @@ -1489,9 +1494,9 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb, | |||
| 1489 | 1494 | ||
| 1490 | /* loop through and fill out our SBP-2 page tables | 1495 | /* loop through and fill out our SBP-2 page tables |
| 1491 | * (and split up anything too large) */ | 1496 | * (and split up anything too large) */ |
| 1492 | for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) { | 1497 | for (i = 0, sg_count = 0; i < count; i++, sg = sg_next(sg)) { |
| 1493 | sg_len = sg_dma_len(sgpnt); | 1498 | sg_len = sg_dma_len(sg); |
| 1494 | sg_addr = sg_dma_address(sgpnt); | 1499 | sg_addr = sg_dma_address(sg); |
| 1495 | while (sg_len) { | 1500 | while (sg_len) { |
| 1496 | sg_element[sg_count].segment_base_lo = sg_addr; | 1501 | sg_element[sg_count].segment_base_lo = sg_addr; |
| 1497 | if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { | 1502 | if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { |
| @@ -1521,11 +1526,10 @@ static void sbp2_create_command_orb(struct sbp2_lu *lu, | |||
| 1521 | unchar *scsi_cmd, | 1526 | unchar *scsi_cmd, |
| 1522 | unsigned int scsi_use_sg, | 1527 | unsigned int scsi_use_sg, |
| 1523 | unsigned int scsi_request_bufflen, | 1528 | unsigned int scsi_request_bufflen, |
| 1524 | void *scsi_request_buffer, | 1529 | struct scatterlist *sg, |
| 1525 | enum dma_data_direction dma_dir) | 1530 | enum dma_data_direction dma_dir) |
| 1526 | { | 1531 | { |
| 1527 | struct sbp2_fwhost_info *hi = lu->hi; | 1532 | struct sbp2_fwhost_info *hi = lu->hi; |
| 1528 | struct scatterlist *sgpnt = (struct scatterlist *)scsi_request_buffer; | ||
| 1529 | struct sbp2_command_orb *orb = &cmd->command_orb; | 1533 | struct sbp2_command_orb *orb = &cmd->command_orb; |
| 1530 | u32 orb_direction; | 1534 | u32 orb_direction; |
| 1531 | 1535 | ||
| @@ -1560,7 +1564,7 @@ static void sbp2_create_command_orb(struct sbp2_lu *lu, | |||
| 1560 | orb->data_descriptor_lo = 0x0; | 1564 | orb->data_descriptor_lo = 0x0; |
| 1561 | orb->misc |= ORB_SET_DIRECTION(1); | 1565 | orb->misc |= ORB_SET_DIRECTION(1); |
| 1562 | } else | 1566 | } else |
| 1563 | sbp2_prep_command_orb_sg(orb, hi, cmd, scsi_use_sg, sgpnt, | 1567 | sbp2_prep_command_orb_sg(orb, hi, cmd, scsi_use_sg, sg, |
| 1564 | orb_direction, dma_dir); | 1568 | orb_direction, dma_dir); |
| 1565 | 1569 | ||
| 1566 | sbp2util_cpu_to_be32_buffer(orb, sizeof(*orb)); | 1570 | sbp2util_cpu_to_be32_buffer(orb, sizeof(*orb)); |
| @@ -1650,7 +1654,6 @@ static int sbp2_send_command(struct sbp2_lu *lu, struct scsi_cmnd *SCpnt, | |||
| 1650 | void (*done)(struct scsi_cmnd *)) | 1654 | void (*done)(struct scsi_cmnd *)) |
| 1651 | { | 1655 | { |
| 1652 | unchar *scsi_cmd = (unchar *)SCpnt->cmnd; | 1656 | unchar *scsi_cmd = (unchar *)SCpnt->cmnd; |
| 1653 | unsigned int request_bufflen = scsi_bufflen(SCpnt); | ||
| 1654 | struct sbp2_command_info *cmd; | 1657 | struct sbp2_command_info *cmd; |
| 1655 | 1658 | ||
| 1656 | cmd = sbp2util_allocate_command_orb(lu, SCpnt, done); | 1659 | cmd = sbp2util_allocate_command_orb(lu, SCpnt, done); |
| @@ -1658,7 +1661,7 @@ static int sbp2_send_command(struct sbp2_lu *lu, struct scsi_cmnd *SCpnt, | |||
| 1658 | return -EIO; | 1661 | return -EIO; |
| 1659 | 1662 | ||
| 1660 | sbp2_create_command_orb(lu, cmd, scsi_cmd, scsi_sg_count(SCpnt), | 1663 | sbp2_create_command_orb(lu, cmd, scsi_cmd, scsi_sg_count(SCpnt), |
| 1661 | request_bufflen, scsi_sglist(SCpnt), | 1664 | scsi_bufflen(SCpnt), scsi_sglist(SCpnt), |
| 1662 | SCpnt->sc_data_direction); | 1665 | SCpnt->sc_data_direction); |
| 1663 | sbp2_link_orb_command(lu, cmd); | 1666 | sbp2_link_orb_command(lu, cmd); |
| 1664 | 1667 | ||
| @@ -1987,6 +1990,8 @@ static int sbp2scsi_slave_configure(struct scsi_device *sdev) | |||
| 1987 | sdev->skip_ms_page_8 = 1; | 1990 | sdev->skip_ms_page_8 = 1; |
| 1988 | if (lu->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) | 1991 | if (lu->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) |
| 1989 | sdev->fix_capacity = 1; | 1992 | sdev->fix_capacity = 1; |
| 1993 | if (lu->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS) | ||
| 1994 | blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512); | ||
| 1990 | return 0; | 1995 | return 0; |
| 1991 | } | 1996 | } |
| 1992 | 1997 | ||
| @@ -2093,9 +2098,6 @@ static int sbp2_module_init(void) | |||
| 2093 | sbp2_shost_template.cmd_per_lun = 1; | 2098 | sbp2_shost_template.cmd_per_lun = 1; |
| 2094 | } | 2099 | } |
| 2095 | 2100 | ||
| 2096 | if (sbp2_default_workarounds & SBP2_WORKAROUND_128K_MAX_TRANS && | ||
| 2097 | (sbp2_max_sectors * 512) > (128 * 1024)) | ||
| 2098 | sbp2_max_sectors = 128 * 1024 / 512; | ||
| 2099 | sbp2_shost_template.max_sectors = sbp2_max_sectors; | 2101 | sbp2_shost_template.max_sectors = sbp2_max_sectors; |
| 2100 | 2102 | ||
| 2101 | hpsb_register_highlevel(&sbp2_highlevel); | 2103 | hpsb_register_highlevel(&sbp2_highlevel); |
diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h index 333a4bb76743..d2ecb0d8a1bb 100644 --- a/drivers/ieee1394/sbp2.h +++ b/drivers/ieee1394/sbp2.h | |||
| @@ -222,7 +222,6 @@ struct sbp2_status_block { | |||
| 222 | */ | 222 | */ |
| 223 | 223 | ||
| 224 | #define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000 | 224 | #define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000 |
| 225 | #define SBP2_MAX_SECTORS 255 | ||
| 226 | /* There is no real limitation of the queue depth (i.e. length of the linked | 225 | /* There is no real limitation of the queue depth (i.e. length of the linked |
| 227 | * list of command ORBs) at the target. The chosen depth is merely an | 226 | * list of command ORBs) at the target. The chosen depth is merely an |
| 228 | * implementation detail of the sbp2 driver. */ | 227 | * implementation detail of the sbp2 driver. */ |
