diff options
Diffstat (limited to 'drivers/firewire/fw-card.c')
-rw-r--r-- | drivers/firewire/fw-card.c | 149 |
1 files changed, 80 insertions, 69 deletions
diff --git a/drivers/firewire/fw-card.c b/drivers/firewire/fw-card.c index a5dd7a665aa8..8b8c8c22f0fc 100644 --- a/drivers/firewire/fw-card.c +++ b/drivers/firewire/fw-card.c | |||
@@ -63,8 +63,7 @@ static int descriptor_count; | |||
63 | #define BIB_CMC ((1) << 30) | 63 | #define BIB_CMC ((1) << 30) |
64 | #define BIB_IMC ((1) << 31) | 64 | #define BIB_IMC ((1) << 31) |
65 | 65 | ||
66 | static u32 * | 66 | static u32 *generate_config_rom(struct fw_card *card, size_t *config_rom_length) |
67 | generate_config_rom(struct fw_card *card, size_t *config_rom_length) | ||
68 | { | 67 | { |
69 | struct fw_descriptor *desc; | 68 | struct fw_descriptor *desc; |
70 | static u32 config_rom[256]; | 69 | static u32 config_rom[256]; |
@@ -128,8 +127,7 @@ generate_config_rom(struct fw_card *card, size_t *config_rom_length) | |||
128 | return config_rom; | 127 | return config_rom; |
129 | } | 128 | } |
130 | 129 | ||
131 | static void | 130 | static void update_config_roms(void) |
132 | update_config_roms(void) | ||
133 | { | 131 | { |
134 | struct fw_card *card; | 132 | struct fw_card *card; |
135 | u32 *config_rom; | 133 | u32 *config_rom; |
@@ -141,8 +139,7 @@ update_config_roms(void) | |||
141 | } | 139 | } |
142 | } | 140 | } |
143 | 141 | ||
144 | int | 142 | int fw_core_add_descriptor(struct fw_descriptor *desc) |
145 | fw_core_add_descriptor(struct fw_descriptor *desc) | ||
146 | { | 143 | { |
147 | size_t i; | 144 | size_t i; |
148 | 145 | ||
@@ -171,8 +168,7 @@ fw_core_add_descriptor(struct fw_descriptor *desc) | |||
171 | return 0; | 168 | return 0; |
172 | } | 169 | } |
173 | 170 | ||
174 | void | 171 | void fw_core_remove_descriptor(struct fw_descriptor *desc) |
175 | fw_core_remove_descriptor(struct fw_descriptor *desc) | ||
176 | { | 172 | { |
177 | mutex_lock(&card_mutex); | 173 | mutex_lock(&card_mutex); |
178 | 174 | ||
@@ -185,12 +181,30 @@ fw_core_remove_descriptor(struct fw_descriptor *desc) | |||
185 | mutex_unlock(&card_mutex); | 181 | mutex_unlock(&card_mutex); |
186 | } | 182 | } |
187 | 183 | ||
184 | static int set_broadcast_channel(struct device *dev, void *data) | ||
185 | { | ||
186 | fw_device_set_broadcast_channel(fw_device(dev), (long)data); | ||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | static void allocate_broadcast_channel(struct fw_card *card, int generation) | ||
191 | { | ||
192 | int channel, bandwidth = 0; | ||
193 | |||
194 | fw_iso_resource_manage(card, generation, 1ULL << 31, | ||
195 | &channel, &bandwidth, true); | ||
196 | if (channel == 31) { | ||
197 | card->broadcast_channel_allocated = true; | ||
198 | device_for_each_child(card->device, (void *)(long)generation, | ||
199 | set_broadcast_channel); | ||
200 | } | ||
201 | } | ||
202 | |||
188 | static const char gap_count_table[] = { | 203 | static const char gap_count_table[] = { |
189 | 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40 | 204 | 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40 |
190 | }; | 205 | }; |
191 | 206 | ||
192 | void | 207 | void fw_schedule_bm_work(struct fw_card *card, unsigned long delay) |
193 | fw_schedule_bm_work(struct fw_card *card, unsigned long delay) | ||
194 | { | 208 | { |
195 | int scheduled; | 209 | int scheduled; |
196 | 210 | ||
@@ -200,37 +214,38 @@ fw_schedule_bm_work(struct fw_card *card, unsigned long delay) | |||
200 | fw_card_put(card); | 214 | fw_card_put(card); |
201 | } | 215 | } |
202 | 216 | ||
203 | static void | 217 | static void fw_card_bm_work(struct work_struct *work) |
204 | fw_card_bm_work(struct work_struct *work) | ||
205 | { | 218 | { |
206 | struct fw_card *card = container_of(work, struct fw_card, work.work); | 219 | struct fw_card *card = container_of(work, struct fw_card, work.work); |
207 | struct fw_device *root_device; | 220 | struct fw_device *root_device; |
208 | struct fw_node *root_node, *local_node; | 221 | struct fw_node *root_node; |
209 | unsigned long flags; | 222 | unsigned long flags; |
210 | int root_id, new_root_id, irm_id, gap_count, generation, grace, rcode; | 223 | int root_id, new_root_id, irm_id, local_id; |
224 | int gap_count, generation, grace, rcode; | ||
211 | bool do_reset = false; | 225 | bool do_reset = false; |
212 | bool root_device_is_running; | 226 | bool root_device_is_running; |
213 | bool root_device_is_cmc; | 227 | bool root_device_is_cmc; |
214 | __be32 lock_data[2]; | 228 | __be32 lock_data[2]; |
215 | 229 | ||
216 | spin_lock_irqsave(&card->lock, flags); | 230 | spin_lock_irqsave(&card->lock, flags); |
217 | local_node = card->local_node; | ||
218 | root_node = card->root_node; | ||
219 | 231 | ||
220 | if (local_node == NULL) { | 232 | if (card->local_node == NULL) { |
221 | spin_unlock_irqrestore(&card->lock, flags); | 233 | spin_unlock_irqrestore(&card->lock, flags); |
222 | goto out_put_card; | 234 | goto out_put_card; |
223 | } | 235 | } |
224 | fw_node_get(local_node); | ||
225 | fw_node_get(root_node); | ||
226 | 236 | ||
227 | generation = card->generation; | 237 | generation = card->generation; |
238 | root_node = card->root_node; | ||
239 | fw_node_get(root_node); | ||
228 | root_device = root_node->data; | 240 | root_device = root_node->data; |
229 | root_device_is_running = root_device && | 241 | root_device_is_running = root_device && |
230 | atomic_read(&root_device->state) == FW_DEVICE_RUNNING; | 242 | atomic_read(&root_device->state) == FW_DEVICE_RUNNING; |
231 | root_device_is_cmc = root_device && root_device->cmc; | 243 | root_device_is_cmc = root_device && root_device->cmc; |
232 | root_id = root_node->node_id; | 244 | root_id = root_node->node_id; |
233 | grace = time_after(jiffies, card->reset_jiffies + DIV_ROUND_UP(HZ, 10)); | 245 | irm_id = card->irm_node->node_id; |
246 | local_id = card->local_node->node_id; | ||
247 | |||
248 | grace = time_after(jiffies, card->reset_jiffies + DIV_ROUND_UP(HZ, 8)); | ||
234 | 249 | ||
235 | if (is_next_generation(generation, card->bm_generation) || | 250 | if (is_next_generation(generation, card->bm_generation) || |
236 | (card->bm_generation != generation && grace)) { | 251 | (card->bm_generation != generation && grace)) { |
@@ -246,16 +261,15 @@ fw_card_bm_work(struct work_struct *work) | |||
246 | * next generation. | 261 | * next generation. |
247 | */ | 262 | */ |
248 | 263 | ||
249 | irm_id = card->irm_node->node_id; | ||
250 | if (!card->irm_node->link_on) { | 264 | if (!card->irm_node->link_on) { |
251 | new_root_id = local_node->node_id; | 265 | new_root_id = local_id; |
252 | fw_notify("IRM has link off, making local node (%02x) root.\n", | 266 | fw_notify("IRM has link off, making local node (%02x) root.\n", |
253 | new_root_id); | 267 | new_root_id); |
254 | goto pick_me; | 268 | goto pick_me; |
255 | } | 269 | } |
256 | 270 | ||
257 | lock_data[0] = cpu_to_be32(0x3f); | 271 | lock_data[0] = cpu_to_be32(0x3f); |
258 | lock_data[1] = cpu_to_be32(local_node->node_id); | 272 | lock_data[1] = cpu_to_be32(local_id); |
259 | 273 | ||
260 | spin_unlock_irqrestore(&card->lock, flags); | 274 | spin_unlock_irqrestore(&card->lock, flags); |
261 | 275 | ||
@@ -269,9 +283,14 @@ fw_card_bm_work(struct work_struct *work) | |||
269 | goto out; | 283 | goto out; |
270 | 284 | ||
271 | if (rcode == RCODE_COMPLETE && | 285 | if (rcode == RCODE_COMPLETE && |
272 | lock_data[0] != cpu_to_be32(0x3f)) | 286 | lock_data[0] != cpu_to_be32(0x3f)) { |
273 | /* Somebody else is BM, let them do the work. */ | 287 | |
288 | /* Somebody else is BM. Only act as IRM. */ | ||
289 | if (local_id == irm_id) | ||
290 | allocate_broadcast_channel(card, generation); | ||
291 | |||
274 | goto out; | 292 | goto out; |
293 | } | ||
275 | 294 | ||
276 | spin_lock_irqsave(&card->lock, flags); | 295 | spin_lock_irqsave(&card->lock, flags); |
277 | 296 | ||
@@ -282,19 +301,18 @@ fw_card_bm_work(struct work_struct *work) | |||
282 | * do a bus reset and pick the local node as | 301 | * do a bus reset and pick the local node as |
283 | * root, and thus, IRM. | 302 | * root, and thus, IRM. |
284 | */ | 303 | */ |
285 | new_root_id = local_node->node_id; | 304 | new_root_id = local_id; |
286 | fw_notify("BM lock failed, making local node (%02x) root.\n", | 305 | fw_notify("BM lock failed, making local node (%02x) root.\n", |
287 | new_root_id); | 306 | new_root_id); |
288 | goto pick_me; | 307 | goto pick_me; |
289 | } | 308 | } |
290 | } else if (card->bm_generation != generation) { | 309 | } else if (card->bm_generation != generation) { |
291 | /* | 310 | /* |
292 | * OK, we weren't BM in the last generation, and it's | 311 | * We weren't BM in the last generation, and the last |
293 | * less than 100ms since last bus reset. Reschedule | 312 | * bus reset is less than 125ms ago. Reschedule this job. |
294 | * this task 100ms from now. | ||
295 | */ | 313 | */ |
296 | spin_unlock_irqrestore(&card->lock, flags); | 314 | spin_unlock_irqrestore(&card->lock, flags); |
297 | fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 10)); | 315 | fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8)); |
298 | goto out; | 316 | goto out; |
299 | } | 317 | } |
300 | 318 | ||
@@ -310,7 +328,7 @@ fw_card_bm_work(struct work_struct *work) | |||
310 | * Either link_on is false, or we failed to read the | 328 | * Either link_on is false, or we failed to read the |
311 | * config rom. In either case, pick another root. | 329 | * config rom. In either case, pick another root. |
312 | */ | 330 | */ |
313 | new_root_id = local_node->node_id; | 331 | new_root_id = local_id; |
314 | } else if (!root_device_is_running) { | 332 | } else if (!root_device_is_running) { |
315 | /* | 333 | /* |
316 | * If we haven't probed this device yet, bail out now | 334 | * If we haven't probed this device yet, bail out now |
@@ -332,7 +350,7 @@ fw_card_bm_work(struct work_struct *work) | |||
332 | * successfully read the config rom, but it's not | 350 | * successfully read the config rom, but it's not |
333 | * cycle master capable. | 351 | * cycle master capable. |
334 | */ | 352 | */ |
335 | new_root_id = local_node->node_id; | 353 | new_root_id = local_id; |
336 | } | 354 | } |
337 | 355 | ||
338 | pick_me: | 356 | pick_me: |
@@ -363,25 +381,28 @@ fw_card_bm_work(struct work_struct *work) | |||
363 | card->index, new_root_id, gap_count); | 381 | card->index, new_root_id, gap_count); |
364 | fw_send_phy_config(card, new_root_id, generation, gap_count); | 382 | fw_send_phy_config(card, new_root_id, generation, gap_count); |
365 | fw_core_initiate_bus_reset(card, 1); | 383 | fw_core_initiate_bus_reset(card, 1); |
384 | /* Will allocate broadcast channel after the reset. */ | ||
385 | } else { | ||
386 | if (local_id == irm_id) | ||
387 | allocate_broadcast_channel(card, generation); | ||
366 | } | 388 | } |
389 | |||
367 | out: | 390 | out: |
368 | fw_node_put(root_node); | 391 | fw_node_put(root_node); |
369 | fw_node_put(local_node); | ||
370 | out_put_card: | 392 | out_put_card: |
371 | fw_card_put(card); | 393 | fw_card_put(card); |
372 | } | 394 | } |
373 | 395 | ||
374 | static void | 396 | static void flush_timer_callback(unsigned long data) |
375 | flush_timer_callback(unsigned long data) | ||
376 | { | 397 | { |
377 | struct fw_card *card = (struct fw_card *)data; | 398 | struct fw_card *card = (struct fw_card *)data; |
378 | 399 | ||
379 | fw_flush_transactions(card); | 400 | fw_flush_transactions(card); |
380 | } | 401 | } |
381 | 402 | ||
382 | void | 403 | void fw_card_initialize(struct fw_card *card, |
383 | fw_card_initialize(struct fw_card *card, const struct fw_card_driver *driver, | 404 | const struct fw_card_driver *driver, |
384 | struct device *device) | 405 | struct device *device) |
385 | { | 406 | { |
386 | static atomic_t index = ATOMIC_INIT(-1); | 407 | static atomic_t index = ATOMIC_INIT(-1); |
387 | 408 | ||
@@ -406,13 +427,12 @@ fw_card_initialize(struct fw_card *card, const struct fw_card_driver *driver, | |||
406 | } | 427 | } |
407 | EXPORT_SYMBOL(fw_card_initialize); | 428 | EXPORT_SYMBOL(fw_card_initialize); |
408 | 429 | ||
409 | int | 430 | int fw_card_add(struct fw_card *card, |
410 | fw_card_add(struct fw_card *card, | 431 | u32 max_receive, u32 link_speed, u64 guid) |
411 | u32 max_receive, u32 link_speed, u64 guid) | ||
412 | { | 432 | { |
413 | u32 *config_rom; | 433 | u32 *config_rom; |
414 | size_t length; | 434 | size_t length; |
415 | int err; | 435 | int ret; |
416 | 436 | ||
417 | card->max_receive = max_receive; | 437 | card->max_receive = max_receive; |
418 | card->link_speed = link_speed; | 438 | card->link_speed = link_speed; |
@@ -423,13 +443,14 @@ fw_card_add(struct fw_card *card, | |||
423 | list_add_tail(&card->link, &card_list); | 443 | list_add_tail(&card->link, &card_list); |
424 | mutex_unlock(&card_mutex); | 444 | mutex_unlock(&card_mutex); |
425 | 445 | ||
426 | err = card->driver->enable(card, config_rom, length); | 446 | ret = card->driver->enable(card, config_rom, length); |
427 | if (err < 0) { | 447 | if (ret < 0) { |
428 | mutex_lock(&card_mutex); | 448 | mutex_lock(&card_mutex); |
429 | list_del(&card->link); | 449 | list_del(&card->link); |
430 | mutex_unlock(&card_mutex); | 450 | mutex_unlock(&card_mutex); |
431 | } | 451 | } |
432 | return err; | 452 | |
453 | return ret; | ||
433 | } | 454 | } |
434 | EXPORT_SYMBOL(fw_card_add); | 455 | EXPORT_SYMBOL(fw_card_add); |
435 | 456 | ||
@@ -442,23 +463,20 @@ EXPORT_SYMBOL(fw_card_add); | |||
442 | * dummy driver just fails all IO. | 463 | * dummy driver just fails all IO. |
443 | */ | 464 | */ |
444 | 465 | ||
445 | static int | 466 | static int dummy_enable(struct fw_card *card, u32 *config_rom, size_t length) |
446 | dummy_enable(struct fw_card *card, u32 *config_rom, size_t length) | ||
447 | { | 467 | { |
448 | BUG(); | 468 | BUG(); |
449 | return -1; | 469 | return -1; |
450 | } | 470 | } |
451 | 471 | ||
452 | static int | 472 | static int dummy_update_phy_reg(struct fw_card *card, int address, |
453 | dummy_update_phy_reg(struct fw_card *card, int address, | 473 | int clear_bits, int set_bits) |
454 | int clear_bits, int set_bits) | ||
455 | { | 474 | { |
456 | return -ENODEV; | 475 | return -ENODEV; |
457 | } | 476 | } |
458 | 477 | ||
459 | static int | 478 | static int dummy_set_config_rom(struct fw_card *card, |
460 | dummy_set_config_rom(struct fw_card *card, | 479 | u32 *config_rom, size_t length) |
461 | u32 *config_rom, size_t length) | ||
462 | { | 480 | { |
463 | /* | 481 | /* |
464 | * We take the card out of card_list before setting the dummy | 482 | * We take the card out of card_list before setting the dummy |
@@ -468,27 +486,23 @@ dummy_set_config_rom(struct fw_card *card, | |||
468 | return -1; | 486 | return -1; |
469 | } | 487 | } |
470 | 488 | ||
471 | static void | 489 | static void dummy_send_request(struct fw_card *card, struct fw_packet *packet) |
472 | dummy_send_request(struct fw_card *card, struct fw_packet *packet) | ||
473 | { | 490 | { |
474 | packet->callback(packet, card, -ENODEV); | 491 | packet->callback(packet, card, -ENODEV); |
475 | } | 492 | } |
476 | 493 | ||
477 | static void | 494 | static void dummy_send_response(struct fw_card *card, struct fw_packet *packet) |
478 | dummy_send_response(struct fw_card *card, struct fw_packet *packet) | ||
479 | { | 495 | { |
480 | packet->callback(packet, card, -ENODEV); | 496 | packet->callback(packet, card, -ENODEV); |
481 | } | 497 | } |
482 | 498 | ||
483 | static int | 499 | static int dummy_cancel_packet(struct fw_card *card, struct fw_packet *packet) |
484 | dummy_cancel_packet(struct fw_card *card, struct fw_packet *packet) | ||
485 | { | 500 | { |
486 | return -ENOENT; | 501 | return -ENOENT; |
487 | } | 502 | } |
488 | 503 | ||
489 | static int | 504 | static int dummy_enable_phys_dma(struct fw_card *card, |
490 | dummy_enable_phys_dma(struct fw_card *card, | 505 | int node_id, int generation) |
491 | int node_id, int generation) | ||
492 | { | 506 | { |
493 | return -ENODEV; | 507 | return -ENODEV; |
494 | } | 508 | } |
@@ -503,16 +517,14 @@ static struct fw_card_driver dummy_driver = { | |||
503 | .enable_phys_dma = dummy_enable_phys_dma, | 517 | .enable_phys_dma = dummy_enable_phys_dma, |
504 | }; | 518 | }; |
505 | 519 | ||
506 | void | 520 | void fw_card_release(struct kref *kref) |
507 | fw_card_release(struct kref *kref) | ||
508 | { | 521 | { |
509 | struct fw_card *card = container_of(kref, struct fw_card, kref); | 522 | struct fw_card *card = container_of(kref, struct fw_card, kref); |
510 | 523 | ||
511 | complete(&card->done); | 524 | complete(&card->done); |
512 | } | 525 | } |
513 | 526 | ||
514 | void | 527 | void fw_core_remove_card(struct fw_card *card) |
515 | fw_core_remove_card(struct fw_card *card) | ||
516 | { | 528 | { |
517 | card->driver->update_phy_reg(card, 4, | 529 | card->driver->update_phy_reg(card, 4, |
518 | PHY_LINK_ACTIVE | PHY_CONTENDER, 0); | 530 | PHY_LINK_ACTIVE | PHY_CONTENDER, 0); |
@@ -536,8 +548,7 @@ fw_core_remove_card(struct fw_card *card) | |||
536 | } | 548 | } |
537 | EXPORT_SYMBOL(fw_core_remove_card); | 549 | EXPORT_SYMBOL(fw_core_remove_card); |
538 | 550 | ||
539 | int | 551 | int fw_core_initiate_bus_reset(struct fw_card *card, int short_reset) |
540 | fw_core_initiate_bus_reset(struct fw_card *card, int short_reset) | ||
541 | { | 552 | { |
542 | int reg = short_reset ? 5 : 1; | 553 | int reg = short_reset ? 5 : 1; |
543 | int bit = short_reset ? PHY_BUS_SHORT_RESET : PHY_BUS_RESET; | 554 | int bit = short_reset ? PHY_BUS_SHORT_RESET : PHY_BUS_RESET; |