Commit f8d2dc39 authored by Stefan Richter's avatar Stefan Richter

firewire: fw-core: react on bus resets while the config ROM is being fetched

read_rom() obtained a fresh new fw_device.generation for each read
transaction.  Hence it was able to continue reading in the middle of the
ROM even if a bus reset happened.  However the device may have modified
the ROM during the reset.  We would end up with a corrupt fetched ROM
image then.

Although all of this is quite unlikely, it is not impossible.
Therefore we now restart reading the ROM if the bus generation changed.

Note, the memory barrier in read_rom() is still necessary according to
tests by Jarod Wilson, despite of the ->generation access being moved up
in the call chain.
Signed-off-by: default avatarStefan Richter <stefanr@s5r6.in-berlin.de>

This is essentially what I've been beating on locally, and I've yet to hit
another config rom read failure with it.
Signed-off-by: default avatarJarod Wilson <jwilson@redhat.com>
parent b5d2a5e0
...@@ -390,12 +390,12 @@ complete_transaction(struct fw_card *card, int rcode, ...@@ -390,12 +390,12 @@ complete_transaction(struct fw_card *card, int rcode,
complete(&callback_data->done); complete(&callback_data->done);
} }
static int read_rom(struct fw_device *device, int index, u32 * data) static int
read_rom(struct fw_device *device, int generation, int index, u32 *data)
{ {
struct read_quadlet_callback_data callback_data; struct read_quadlet_callback_data callback_data;
struct fw_transaction t; struct fw_transaction t;
u64 offset; u64 offset;
int generation = device->generation;
/* device->node_id, accessed below, must not be older than generation */ /* device->node_id, accessed below, must not be older than generation */
smp_rmb(); smp_rmb();
...@@ -414,7 +414,14 @@ static int read_rom(struct fw_device *device, int index, u32 * data) ...@@ -414,7 +414,14 @@ static int read_rom(struct fw_device *device, int index, u32 * data)
return callback_data.rcode; return callback_data.rcode;
} }
static int read_bus_info_block(struct fw_device *device) /*
* Read the bus info block, perform a speed probe, and read all of the rest of
* the config ROM. We do all this with a cached bus generation. If the bus
* generation changes under us, read_bus_info_block will fail and get retried.
* It's better to start all over in this case because the node from which we
* are reading the ROM may have changed the ROM during the reset.
*/
static int read_bus_info_block(struct fw_device *device, int generation)
{ {
static u32 rom[256]; static u32 rom[256];
u32 stack[16], sp, key; u32 stack[16], sp, key;
...@@ -424,7 +431,7 @@ static int read_bus_info_block(struct fw_device *device) ...@@ -424,7 +431,7 @@ static int read_bus_info_block(struct fw_device *device)
/* First read the bus info block. */ /* First read the bus info block. */
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
if (read_rom(device, i, &rom[i]) != RCODE_COMPLETE) if (read_rom(device, generation, i, &rom[i]) != RCODE_COMPLETE)
return -1; return -1;
/* /*
* As per IEEE1212 7.2, during power-up, devices can * As per IEEE1212 7.2, during power-up, devices can
...@@ -459,7 +466,8 @@ static int read_bus_info_block(struct fw_device *device) ...@@ -459,7 +466,8 @@ static int read_bus_info_block(struct fw_device *device)
device->max_speed = device->card->link_speed; device->max_speed = device->card->link_speed;
while (device->max_speed > SCODE_100) { while (device->max_speed > SCODE_100) {
if (read_rom(device, 0, &dummy) == RCODE_COMPLETE) if (read_rom(device, generation, 0, &dummy) ==
RCODE_COMPLETE)
break; break;
device->max_speed--; device->max_speed--;
} }
...@@ -492,7 +500,7 @@ static int read_bus_info_block(struct fw_device *device) ...@@ -492,7 +500,7 @@ static int read_bus_info_block(struct fw_device *device)
return -1; return -1;
/* Read header quadlet for the block to get the length. */ /* Read header quadlet for the block to get the length. */
if (read_rom(device, i, &rom[i]) != RCODE_COMPLETE) if (read_rom(device, generation, i, &rom[i]) != RCODE_COMPLETE)
return -1; return -1;
end = i + (rom[i] >> 16) + 1; end = i + (rom[i] >> 16) + 1;
i++; i++;
...@@ -511,7 +519,8 @@ static int read_bus_info_block(struct fw_device *device) ...@@ -511,7 +519,8 @@ static int read_bus_info_block(struct fw_device *device)
* it references another block, and push it in that case. * it references another block, and push it in that case.
*/ */
while (i < end) { while (i < end) {
if (read_rom(device, i, &rom[i]) != RCODE_COMPLETE) if (read_rom(device, generation, i, &rom[i]) !=
RCODE_COMPLETE)
return -1; return -1;
if ((key >> 30) == 3 && (rom[i] >> 30) > 1 && if ((key >> 30) == 3 && (rom[i] >> 30) > 1 &&
sp < ARRAY_SIZE(stack)) sp < ARRAY_SIZE(stack))
...@@ -658,7 +667,7 @@ static void fw_device_init(struct work_struct *work) ...@@ -658,7 +667,7 @@ static void fw_device_init(struct work_struct *work)
* device. * device.
*/ */
if (read_bus_info_block(device) < 0) { if (read_bus_info_block(device, device->generation) < 0) {
if (device->config_rom_retries < MAX_RETRIES) { if (device->config_rom_retries < MAX_RETRIES) {
device->config_rom_retries++; device->config_rom_retries++;
schedule_delayed_work(&device->work, RETRY_DELAY); schedule_delayed_work(&device->work, RETRY_DELAY);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment