diff options
Diffstat (limited to 'drivers/firewire')
-rw-r--r-- | drivers/firewire/core-card.c | 264 | ||||
-rw-r--r-- | drivers/firewire/core-cdev.c | 417 | ||||
-rw-r--r-- | drivers/firewire/core-device.c | 11 | ||||
-rw-r--r-- | drivers/firewire/core-iso.c | 34 | ||||
-rw-r--r-- | drivers/firewire/core-topology.c | 22 | ||||
-rw-r--r-- | drivers/firewire/core-transaction.c | 400 | ||||
-rw-r--r-- | drivers/firewire/core.h | 30 | ||||
-rw-r--r-- | drivers/firewire/net.c | 4 | ||||
-rw-r--r-- | drivers/firewire/ohci.c | 867 | ||||
-rw-r--r-- | drivers/firewire/ohci.h | 11 | ||||
-rw-r--r-- | drivers/firewire/sbp2.c | 13 |
11 files changed, 1567 insertions, 506 deletions
diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c index 5045156c5313..be0492398ef9 100644 --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
31 | #include <linux/mutex.h> | 31 | #include <linux/mutex.h> |
32 | #include <linux/spinlock.h> | 32 | #include <linux/spinlock.h> |
33 | #include <linux/timer.h> | ||
34 | #include <linux/workqueue.h> | 33 | #include <linux/workqueue.h> |
35 | 34 | ||
36 | #include <asm/atomic.h> | 35 | #include <asm/atomic.h> |
@@ -63,7 +62,7 @@ static size_t config_rom_length = 1 + 4 + 1 + 1; | |||
63 | #define BIB_CRC(v) ((v) << 0) | 62 | #define BIB_CRC(v) ((v) << 0) |
64 | #define BIB_CRC_LENGTH(v) ((v) << 16) | 63 | #define BIB_CRC_LENGTH(v) ((v) << 16) |
65 | #define BIB_INFO_LENGTH(v) ((v) << 24) | 64 | #define BIB_INFO_LENGTH(v) ((v) << 24) |
66 | 65 | #define BIB_BUS_NAME 0x31333934 /* "1394" */ | |
67 | #define BIB_LINK_SPEED(v) ((v) << 0) | 66 | #define BIB_LINK_SPEED(v) ((v) << 0) |
68 | #define BIB_GENERATION(v) ((v) << 4) | 67 | #define BIB_GENERATION(v) ((v) << 4) |
69 | #define BIB_MAX_ROM(v) ((v) << 8) | 68 | #define BIB_MAX_ROM(v) ((v) << 8) |
@@ -73,7 +72,8 @@ static size_t config_rom_length = 1 + 4 + 1 + 1; | |||
73 | #define BIB_BMC ((1) << 28) | 72 | #define BIB_BMC ((1) << 28) |
74 | #define BIB_ISC ((1) << 29) | 73 | #define BIB_ISC ((1) << 29) |
75 | #define BIB_CMC ((1) << 30) | 74 | #define BIB_CMC ((1) << 30) |
76 | #define BIB_IMC ((1) << 31) | 75 | #define BIB_IRMC ((1) << 31) |
76 | #define NODE_CAPABILITIES 0x0c0083c0 /* per IEEE 1394 clause 8.3.2.6.5.2 */ | ||
77 | 77 | ||
78 | static void generate_config_rom(struct fw_card *card, __be32 *config_rom) | 78 | static void generate_config_rom(struct fw_card *card, __be32 *config_rom) |
79 | { | 79 | { |
@@ -91,18 +91,18 @@ static void generate_config_rom(struct fw_card *card, __be32 *config_rom) | |||
91 | 91 | ||
92 | config_rom[0] = cpu_to_be32( | 92 | config_rom[0] = cpu_to_be32( |
93 | BIB_CRC_LENGTH(4) | BIB_INFO_LENGTH(4) | BIB_CRC(0)); | 93 | BIB_CRC_LENGTH(4) | BIB_INFO_LENGTH(4) | BIB_CRC(0)); |
94 | config_rom[1] = cpu_to_be32(0x31333934); | 94 | config_rom[1] = cpu_to_be32(BIB_BUS_NAME); |
95 | config_rom[2] = cpu_to_be32( | 95 | config_rom[2] = cpu_to_be32( |
96 | BIB_LINK_SPEED(card->link_speed) | | 96 | BIB_LINK_SPEED(card->link_speed) | |
97 | BIB_GENERATION(card->config_rom_generation++ % 14 + 2) | | 97 | BIB_GENERATION(card->config_rom_generation++ % 14 + 2) | |
98 | BIB_MAX_ROM(2) | | 98 | BIB_MAX_ROM(2) | |
99 | BIB_MAX_RECEIVE(card->max_receive) | | 99 | BIB_MAX_RECEIVE(card->max_receive) | |
100 | BIB_BMC | BIB_ISC | BIB_CMC | BIB_IMC); | 100 | BIB_BMC | BIB_ISC | BIB_CMC | BIB_IRMC); |
101 | config_rom[3] = cpu_to_be32(card->guid >> 32); | 101 | config_rom[3] = cpu_to_be32(card->guid >> 32); |
102 | config_rom[4] = cpu_to_be32(card->guid); | 102 | config_rom[4] = cpu_to_be32(card->guid); |
103 | 103 | ||
104 | /* Generate root directory. */ | 104 | /* Generate root directory. */ |
105 | config_rom[6] = cpu_to_be32(0x0c0083c0); /* node capabilities */ | 105 | config_rom[6] = cpu_to_be32(NODE_CAPABILITIES); |
106 | i = 7; | 106 | i = 7; |
107 | j = 7 + descriptor_count; | 107 | j = 7 + descriptor_count; |
108 | 108 | ||
@@ -204,17 +204,62 @@ void fw_core_remove_descriptor(struct fw_descriptor *desc) | |||
204 | } | 204 | } |
205 | EXPORT_SYMBOL(fw_core_remove_descriptor); | 205 | EXPORT_SYMBOL(fw_core_remove_descriptor); |
206 | 206 | ||
207 | static int reset_bus(struct fw_card *card, bool short_reset) | ||
208 | { | ||
209 | int reg = short_reset ? 5 : 1; | ||
210 | int bit = short_reset ? PHY_BUS_SHORT_RESET : PHY_BUS_RESET; | ||
211 | |||
212 | return card->driver->update_phy_reg(card, reg, 0, bit); | ||
213 | } | ||
214 | |||
215 | void fw_schedule_bus_reset(struct fw_card *card, bool delayed, bool short_reset) | ||
216 | { | ||
217 | /* We don't try hard to sort out requests of long vs. short resets. */ | ||
218 | card->br_short = short_reset; | ||
219 | |||
220 | /* Use an arbitrary short delay to combine multiple reset requests. */ | ||
221 | fw_card_get(card); | ||
222 | if (!schedule_delayed_work(&card->br_work, | ||
223 | delayed ? DIV_ROUND_UP(HZ, 100) : 0)) | ||
224 | fw_card_put(card); | ||
225 | } | ||
226 | EXPORT_SYMBOL(fw_schedule_bus_reset); | ||
227 | |||
228 | static void br_work(struct work_struct *work) | ||
229 | { | ||
230 | struct fw_card *card = container_of(work, struct fw_card, br_work.work); | ||
231 | |||
232 | /* Delay for 2s after last reset per IEEE 1394 clause 8.2.1. */ | ||
233 | if (card->reset_jiffies != 0 && | ||
234 | time_is_after_jiffies(card->reset_jiffies + 2 * HZ)) { | ||
235 | if (!schedule_delayed_work(&card->br_work, 2 * HZ)) | ||
236 | fw_card_put(card); | ||
237 | return; | ||
238 | } | ||
239 | |||
240 | fw_send_phy_config(card, FW_PHY_CONFIG_NO_NODE_ID, card->generation, | ||
241 | FW_PHY_CONFIG_CURRENT_GAP_COUNT); | ||
242 | reset_bus(card, card->br_short); | ||
243 | fw_card_put(card); | ||
244 | } | ||
245 | |||
207 | static void allocate_broadcast_channel(struct fw_card *card, int generation) | 246 | static void allocate_broadcast_channel(struct fw_card *card, int generation) |
208 | { | 247 | { |
209 | int channel, bandwidth = 0; | 248 | int channel, bandwidth = 0; |
210 | 249 | ||
211 | fw_iso_resource_manage(card, generation, 1ULL << 31, &channel, | 250 | if (!card->broadcast_channel_allocated) { |
212 | &bandwidth, true, card->bm_transaction_data); | 251 | fw_iso_resource_manage(card, generation, 1ULL << 31, |
213 | if (channel == 31) { | 252 | &channel, &bandwidth, true, |
253 | card->bm_transaction_data); | ||
254 | if (channel != 31) { | ||
255 | fw_notify("failed to allocate broadcast channel\n"); | ||
256 | return; | ||
257 | } | ||
214 | card->broadcast_channel_allocated = true; | 258 | card->broadcast_channel_allocated = true; |
215 | device_for_each_child(card->device, (void *)(long)generation, | ||
216 | fw_device_set_broadcast_channel); | ||
217 | } | 259 | } |
260 | |||
261 | device_for_each_child(card->device, (void *)(long)generation, | ||
262 | fw_device_set_broadcast_channel); | ||
218 | } | 263 | } |
219 | 264 | ||
220 | static const char gap_count_table[] = { | 265 | static const char gap_count_table[] = { |
@@ -224,43 +269,50 @@ static const char gap_count_table[] = { | |||
224 | void fw_schedule_bm_work(struct fw_card *card, unsigned long delay) | 269 | void fw_schedule_bm_work(struct fw_card *card, unsigned long delay) |
225 | { | 270 | { |
226 | fw_card_get(card); | 271 | fw_card_get(card); |
227 | if (!schedule_delayed_work(&card->work, delay)) | 272 | if (!schedule_delayed_work(&card->bm_work, delay)) |
228 | fw_card_put(card); | 273 | fw_card_put(card); |
229 | } | 274 | } |
230 | 275 | ||
231 | static void fw_card_bm_work(struct work_struct *work) | 276 | static void bm_work(struct work_struct *work) |
232 | { | 277 | { |
233 | struct fw_card *card = container_of(work, struct fw_card, work.work); | 278 | struct fw_card *card = container_of(work, struct fw_card, bm_work.work); |
234 | struct fw_device *root_device; | 279 | struct fw_device *root_device, *irm_device; |
235 | struct fw_node *root_node; | 280 | struct fw_node *root_node; |
236 | unsigned long flags; | 281 | int root_id, new_root_id, irm_id, bm_id, local_id; |
237 | int root_id, new_root_id, irm_id, local_id; | ||
238 | int gap_count, generation, grace, rcode; | 282 | int gap_count, generation, grace, rcode; |
239 | bool do_reset = false; | 283 | bool do_reset = false; |
240 | bool root_device_is_running; | 284 | bool root_device_is_running; |
241 | bool root_device_is_cmc; | 285 | bool root_device_is_cmc; |
286 | bool irm_is_1394_1995_only; | ||
242 | 287 | ||
243 | spin_lock_irqsave(&card->lock, flags); | 288 | spin_lock_irq(&card->lock); |
244 | 289 | ||
245 | if (card->local_node == NULL) { | 290 | if (card->local_node == NULL) { |
246 | spin_unlock_irqrestore(&card->lock, flags); | 291 | spin_unlock_irq(&card->lock); |
247 | goto out_put_card; | 292 | goto out_put_card; |
248 | } | 293 | } |
249 | 294 | ||
250 | generation = card->generation; | 295 | generation = card->generation; |
296 | |||
251 | root_node = card->root_node; | 297 | root_node = card->root_node; |
252 | fw_node_get(root_node); | 298 | fw_node_get(root_node); |
253 | root_device = root_node->data; | 299 | root_device = root_node->data; |
254 | root_device_is_running = root_device && | 300 | root_device_is_running = root_device && |
255 | atomic_read(&root_device->state) == FW_DEVICE_RUNNING; | 301 | atomic_read(&root_device->state) == FW_DEVICE_RUNNING; |
256 | root_device_is_cmc = root_device && root_device->cmc; | 302 | root_device_is_cmc = root_device && root_device->cmc; |
303 | |||
304 | irm_device = card->irm_node->data; | ||
305 | irm_is_1394_1995_only = irm_device && irm_device->config_rom && | ||
306 | (irm_device->config_rom[2] & 0x000000f0) == 0; | ||
307 | |||
257 | root_id = root_node->node_id; | 308 | root_id = root_node->node_id; |
258 | irm_id = card->irm_node->node_id; | 309 | irm_id = card->irm_node->node_id; |
259 | local_id = card->local_node->node_id; | 310 | local_id = card->local_node->node_id; |
260 | 311 | ||
261 | grace = time_after(jiffies, card->reset_jiffies + DIV_ROUND_UP(HZ, 8)); | 312 | grace = time_after(jiffies, card->reset_jiffies + DIV_ROUND_UP(HZ, 8)); |
262 | 313 | ||
263 | if (is_next_generation(generation, card->bm_generation) || | 314 | if ((is_next_generation(generation, card->bm_generation) && |
315 | !card->bm_abdicate) || | ||
264 | (card->bm_generation != generation && grace)) { | 316 | (card->bm_generation != generation && grace)) { |
265 | /* | 317 | /* |
266 | * This first step is to figure out who is IRM and | 318 | * This first step is to figure out who is IRM and |
@@ -276,29 +328,41 @@ static void fw_card_bm_work(struct work_struct *work) | |||
276 | 328 | ||
277 | if (!card->irm_node->link_on) { | 329 | if (!card->irm_node->link_on) { |
278 | new_root_id = local_id; | 330 | new_root_id = local_id; |
279 | fw_notify("IRM has link off, making local node (%02x) root.\n", | 331 | fw_notify("%s, making local node (%02x) root.\n", |
280 | new_root_id); | 332 | "IRM has link off", new_root_id); |
333 | goto pick_me; | ||
334 | } | ||
335 | |||
336 | if (irm_is_1394_1995_only) { | ||
337 | new_root_id = local_id; | ||
338 | fw_notify("%s, making local node (%02x) root.\n", | ||
339 | "IRM is not 1394a compliant", new_root_id); | ||
281 | goto pick_me; | 340 | goto pick_me; |
282 | } | 341 | } |
283 | 342 | ||
284 | card->bm_transaction_data[0] = cpu_to_be32(0x3f); | 343 | card->bm_transaction_data[0] = cpu_to_be32(0x3f); |
285 | card->bm_transaction_data[1] = cpu_to_be32(local_id); | 344 | card->bm_transaction_data[1] = cpu_to_be32(local_id); |
286 | 345 | ||
287 | spin_unlock_irqrestore(&card->lock, flags); | 346 | spin_unlock_irq(&card->lock); |
288 | 347 | ||
289 | rcode = fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP, | 348 | rcode = fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP, |
290 | irm_id, generation, SCODE_100, | 349 | irm_id, generation, SCODE_100, |
291 | CSR_REGISTER_BASE + CSR_BUS_MANAGER_ID, | 350 | CSR_REGISTER_BASE + CSR_BUS_MANAGER_ID, |
292 | card->bm_transaction_data, | 351 | card->bm_transaction_data, 8); |
293 | sizeof(card->bm_transaction_data)); | ||
294 | 352 | ||
295 | if (rcode == RCODE_GENERATION) | 353 | if (rcode == RCODE_GENERATION) |
296 | /* Another bus reset, BM work has been rescheduled. */ | 354 | /* Another bus reset, BM work has been rescheduled. */ |
297 | goto out; | 355 | goto out; |
298 | 356 | ||
299 | if (rcode == RCODE_COMPLETE && | 357 | bm_id = be32_to_cpu(card->bm_transaction_data[0]); |
300 | card->bm_transaction_data[0] != cpu_to_be32(0x3f)) { | 358 | |
359 | spin_lock_irq(&card->lock); | ||
360 | if (rcode == RCODE_COMPLETE && generation == card->generation) | ||
361 | card->bm_node_id = | ||
362 | bm_id == 0x3f ? local_id : 0xffc0 | bm_id; | ||
363 | spin_unlock_irq(&card->lock); | ||
301 | 364 | ||
365 | if (rcode == RCODE_COMPLETE && bm_id != 0x3f) { | ||
302 | /* Somebody else is BM. Only act as IRM. */ | 366 | /* Somebody else is BM. Only act as IRM. */ |
303 | if (local_id == irm_id) | 367 | if (local_id == irm_id) |
304 | allocate_broadcast_channel(card, generation); | 368 | allocate_broadcast_channel(card, generation); |
@@ -306,7 +370,17 @@ static void fw_card_bm_work(struct work_struct *work) | |||
306 | goto out; | 370 | goto out; |
307 | } | 371 | } |
308 | 372 | ||
309 | spin_lock_irqsave(&card->lock, flags); | 373 | if (rcode == RCODE_SEND_ERROR) { |
374 | /* | ||
375 | * We have been unable to send the lock request due to | ||
376 | * some local problem. Let's try again later and hope | ||
377 | * that the problem has gone away by then. | ||
378 | */ | ||
379 | fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8)); | ||
380 | goto out; | ||
381 | } | ||
382 | |||
383 | spin_lock_irq(&card->lock); | ||
310 | 384 | ||
311 | if (rcode != RCODE_COMPLETE) { | 385 | if (rcode != RCODE_COMPLETE) { |
312 | /* | 386 | /* |
@@ -316,8 +390,8 @@ static void fw_card_bm_work(struct work_struct *work) | |||
316 | * root, and thus, IRM. | 390 | * root, and thus, IRM. |
317 | */ | 391 | */ |
318 | new_root_id = local_id; | 392 | new_root_id = local_id; |
319 | fw_notify("BM lock failed, making local node (%02x) root.\n", | 393 | fw_notify("%s, making local node (%02x) root.\n", |
320 | new_root_id); | 394 | "BM lock failed", new_root_id); |
321 | goto pick_me; | 395 | goto pick_me; |
322 | } | 396 | } |
323 | } else if (card->bm_generation != generation) { | 397 | } else if (card->bm_generation != generation) { |
@@ -325,7 +399,7 @@ static void fw_card_bm_work(struct work_struct *work) | |||
325 | * We weren't BM in the last generation, and the last | 399 | * We weren't BM in the last generation, and the last |
326 | * bus reset is less than 125ms ago. Reschedule this job. | 400 | * bus reset is less than 125ms ago. Reschedule this job. |
327 | */ | 401 | */ |
328 | spin_unlock_irqrestore(&card->lock, flags); | 402 | spin_unlock_irq(&card->lock); |
329 | fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8)); | 403 | fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8)); |
330 | goto out; | 404 | goto out; |
331 | } | 405 | } |
@@ -348,14 +422,12 @@ static void fw_card_bm_work(struct work_struct *work) | |||
348 | * If we haven't probed this device yet, bail out now | 422 | * If we haven't probed this device yet, bail out now |
349 | * and let's try again once that's done. | 423 | * and let's try again once that's done. |
350 | */ | 424 | */ |
351 | spin_unlock_irqrestore(&card->lock, flags); | 425 | spin_unlock_irq(&card->lock); |
352 | goto out; | 426 | goto out; |
353 | } else if (root_device_is_cmc) { | 427 | } else if (root_device_is_cmc) { |
354 | /* | 428 | /* |
355 | * FIXME: I suppose we should set the cmstr bit in the | 429 | * We will send out a force root packet for this |
356 | * STATE_CLEAR register of this node, as described in | 430 | * node as part of the gap count optimization. |
357 | * 1394-1995, 8.4.2.6. Also, send out a force root | ||
358 | * packet for this node. | ||
359 | */ | 431 | */ |
360 | new_root_id = root_id; | 432 | new_root_id = root_id; |
361 | } else { | 433 | } else { |
@@ -388,32 +460,39 @@ static void fw_card_bm_work(struct work_struct *work) | |||
388 | (card->gap_count != gap_count || new_root_id != root_id)) | 460 | (card->gap_count != gap_count || new_root_id != root_id)) |
389 | do_reset = true; | 461 | do_reset = true; |
390 | 462 | ||
391 | spin_unlock_irqrestore(&card->lock, flags); | 463 | spin_unlock_irq(&card->lock); |
392 | 464 | ||
393 | if (do_reset) { | 465 | if (do_reset) { |
394 | fw_notify("phy config: card %d, new root=%x, gap_count=%d\n", | 466 | fw_notify("phy config: card %d, new root=%x, gap_count=%d\n", |
395 | card->index, new_root_id, gap_count); | 467 | card->index, new_root_id, gap_count); |
396 | fw_send_phy_config(card, new_root_id, generation, gap_count); | 468 | fw_send_phy_config(card, new_root_id, generation, gap_count); |
397 | fw_core_initiate_bus_reset(card, 1); | 469 | reset_bus(card, true); |
398 | /* Will allocate broadcast channel after the reset. */ | 470 | /* Will allocate broadcast channel after the reset. */ |
399 | } else { | 471 | goto out; |
400 | if (local_id == irm_id) | 472 | } |
401 | allocate_broadcast_channel(card, generation); | 473 | |
474 | if (root_device_is_cmc) { | ||
475 | /* | ||
476 | * Make sure that the cycle master sends cycle start packets. | ||
477 | */ | ||
478 | card->bm_transaction_data[0] = cpu_to_be32(CSR_STATE_BIT_CMSTR); | ||
479 | rcode = fw_run_transaction(card, TCODE_WRITE_QUADLET_REQUEST, | ||
480 | root_id, generation, SCODE_100, | ||
481 | CSR_REGISTER_BASE + CSR_STATE_SET, | ||
482 | card->bm_transaction_data, 4); | ||
483 | if (rcode == RCODE_GENERATION) | ||
484 | goto out; | ||
402 | } | 485 | } |
403 | 486 | ||
487 | if (local_id == irm_id) | ||
488 | allocate_broadcast_channel(card, generation); | ||
489 | |||
404 | out: | 490 | out: |
405 | fw_node_put(root_node); | 491 | fw_node_put(root_node); |
406 | out_put_card: | 492 | out_put_card: |
407 | fw_card_put(card); | 493 | fw_card_put(card); |
408 | } | 494 | } |
409 | 495 | ||
410 | static void flush_timer_callback(unsigned long data) | ||
411 | { | ||
412 | struct fw_card *card = (struct fw_card *)data; | ||
413 | |||
414 | fw_flush_transactions(card); | ||
415 | } | ||
416 | |||
417 | void fw_card_initialize(struct fw_card *card, | 496 | void fw_card_initialize(struct fw_card *card, |
418 | const struct fw_card_driver *driver, | 497 | const struct fw_card_driver *driver, |
419 | struct device *device) | 498 | struct device *device) |
@@ -425,19 +504,23 @@ void fw_card_initialize(struct fw_card *card, | |||
425 | card->device = device; | 504 | card->device = device; |
426 | card->current_tlabel = 0; | 505 | card->current_tlabel = 0; |
427 | card->tlabel_mask = 0; | 506 | card->tlabel_mask = 0; |
507 | card->split_timeout_hi = 0; | ||
508 | card->split_timeout_lo = 800 << 19; | ||
509 | card->split_timeout_cycles = 800; | ||
510 | card->split_timeout_jiffies = DIV_ROUND_UP(HZ, 10); | ||
428 | card->color = 0; | 511 | card->color = 0; |
429 | card->broadcast_channel = BROADCAST_CHANNEL_INITIAL; | 512 | card->broadcast_channel = BROADCAST_CHANNEL_INITIAL; |
430 | 513 | ||
431 | kref_init(&card->kref); | 514 | kref_init(&card->kref); |
432 | init_completion(&card->done); | 515 | init_completion(&card->done); |
433 | INIT_LIST_HEAD(&card->transaction_list); | 516 | INIT_LIST_HEAD(&card->transaction_list); |
517 | INIT_LIST_HEAD(&card->phy_receiver_list); | ||
434 | spin_lock_init(&card->lock); | 518 | spin_lock_init(&card->lock); |
435 | setup_timer(&card->flush_timer, | ||
436 | flush_timer_callback, (unsigned long)card); | ||
437 | 519 | ||
438 | card->local_node = NULL; | 520 | card->local_node = NULL; |
439 | 521 | ||
440 | INIT_DELAYED_WORK(&card->work, fw_card_bm_work); | 522 | INIT_DELAYED_WORK(&card->br_work, br_work); |
523 | INIT_DELAYED_WORK(&card->bm_work, bm_work); | ||
441 | } | 524 | } |
442 | EXPORT_SYMBOL(fw_card_initialize); | 525 | EXPORT_SYMBOL(fw_card_initialize); |
443 | 526 | ||
@@ -463,20 +546,22 @@ int fw_card_add(struct fw_card *card, | |||
463 | } | 546 | } |
464 | EXPORT_SYMBOL(fw_card_add); | 547 | EXPORT_SYMBOL(fw_card_add); |
465 | 548 | ||
466 | |||
467 | /* | 549 | /* |
468 | * The next few functions implement a dummy driver that is used once a card | 550 | * The next few functions implement a dummy driver that is used once a card |
469 | * driver shuts down an fw_card. This allows the driver to cleanly unload, | 551 | * driver shuts down an fw_card. This allows the driver to cleanly unload, |
470 | * as all IO to the card will be handled (and failed) by the dummy driver | 552 | * as all IO to the card will be handled (and failed) by the dummy driver |
471 | * instead of calling into the module. Only functions for iso context | 553 | * instead of calling into the module. Only functions for iso context |
472 | * shutdown still need to be provided by the card driver. | 554 | * shutdown still need to be provided by the card driver. |
555 | * | ||
556 | * .read/write_csr() should never be called anymore after the dummy driver | ||
557 | * was bound since they are only used within request handler context. | ||
558 | * .set_config_rom() is never called since the card is taken out of card_list | ||
559 | * before switching to the dummy driver. | ||
473 | */ | 560 | */ |
474 | 561 | ||
475 | static int dummy_enable(struct fw_card *card, | 562 | static int dummy_read_phy_reg(struct fw_card *card, int address) |
476 | const __be32 *config_rom, size_t length) | ||
477 | { | 563 | { |
478 | BUG(); | 564 | return -ENODEV; |
479 | return -1; | ||
480 | } | 565 | } |
481 | 566 | ||
482 | static int dummy_update_phy_reg(struct fw_card *card, int address, | 567 | static int dummy_update_phy_reg(struct fw_card *card, int address, |
@@ -485,25 +570,14 @@ static int dummy_update_phy_reg(struct fw_card *card, int address, | |||
485 | return -ENODEV; | 570 | return -ENODEV; |
486 | } | 571 | } |
487 | 572 | ||
488 | static int dummy_set_config_rom(struct fw_card *card, | ||
489 | const __be32 *config_rom, size_t length) | ||
490 | { | ||
491 | /* | ||
492 | * We take the card out of card_list before setting the dummy | ||
493 | * driver, so this should never get called. | ||
494 | */ | ||
495 | BUG(); | ||
496 | return -1; | ||
497 | } | ||
498 | |||
499 | static void dummy_send_request(struct fw_card *card, struct fw_packet *packet) | 573 | static void dummy_send_request(struct fw_card *card, struct fw_packet *packet) |
500 | { | 574 | { |
501 | packet->callback(packet, card, -ENODEV); | 575 | packet->callback(packet, card, RCODE_CANCELLED); |
502 | } | 576 | } |
503 | 577 | ||
504 | static void dummy_send_response(struct fw_card *card, struct fw_packet *packet) | 578 | static void dummy_send_response(struct fw_card *card, struct fw_packet *packet) |
505 | { | 579 | { |
506 | packet->callback(packet, card, -ENODEV); | 580 | packet->callback(packet, card, RCODE_CANCELLED); |
507 | } | 581 | } |
508 | 582 | ||
509 | static int dummy_cancel_packet(struct fw_card *card, struct fw_packet *packet) | 583 | static int dummy_cancel_packet(struct fw_card *card, struct fw_packet *packet) |
@@ -517,14 +591,40 @@ static int dummy_enable_phys_dma(struct fw_card *card, | |||
517 | return -ENODEV; | 591 | return -ENODEV; |
518 | } | 592 | } |
519 | 593 | ||
594 | static struct fw_iso_context *dummy_allocate_iso_context(struct fw_card *card, | ||
595 | int type, int channel, size_t header_size) | ||
596 | { | ||
597 | return ERR_PTR(-ENODEV); | ||
598 | } | ||
599 | |||
600 | static int dummy_start_iso(struct fw_iso_context *ctx, | ||
601 | s32 cycle, u32 sync, u32 tags) | ||
602 | { | ||
603 | return -ENODEV; | ||
604 | } | ||
605 | |||
606 | static int dummy_set_iso_channels(struct fw_iso_context *ctx, u64 *channels) | ||
607 | { | ||
608 | return -ENODEV; | ||
609 | } | ||
610 | |||
611 | static int dummy_queue_iso(struct fw_iso_context *ctx, struct fw_iso_packet *p, | ||
612 | struct fw_iso_buffer *buffer, unsigned long payload) | ||
613 | { | ||
614 | return -ENODEV; | ||
615 | } | ||
616 | |||
520 | static const struct fw_card_driver dummy_driver_template = { | 617 | static const struct fw_card_driver dummy_driver_template = { |
521 | .enable = dummy_enable, | 618 | .read_phy_reg = dummy_read_phy_reg, |
522 | .update_phy_reg = dummy_update_phy_reg, | 619 | .update_phy_reg = dummy_update_phy_reg, |
523 | .set_config_rom = dummy_set_config_rom, | 620 | .send_request = dummy_send_request, |
524 | .send_request = dummy_send_request, | 621 | .send_response = dummy_send_response, |
525 | .cancel_packet = dummy_cancel_packet, | 622 | .cancel_packet = dummy_cancel_packet, |
526 | .send_response = dummy_send_response, | 623 | .enable_phys_dma = dummy_enable_phys_dma, |
527 | .enable_phys_dma = dummy_enable_phys_dma, | 624 | .allocate_iso_context = dummy_allocate_iso_context, |
625 | .start_iso = dummy_start_iso, | ||
626 | .set_iso_channels = dummy_set_iso_channels, | ||
627 | .queue_iso = dummy_queue_iso, | ||
528 | }; | 628 | }; |
529 | 629 | ||
530 | void fw_card_release(struct kref *kref) | 630 | void fw_card_release(struct kref *kref) |
@@ -540,7 +640,7 @@ void fw_core_remove_card(struct fw_card *card) | |||
540 | 640 | ||
541 | card->driver->update_phy_reg(card, 4, | 641 | card->driver->update_phy_reg(card, 4, |
542 | PHY_LINK_ACTIVE | PHY_CONTENDER, 0); | 642 | PHY_LINK_ACTIVE | PHY_CONTENDER, 0); |
543 | fw_core_initiate_bus_reset(card, 1); | 643 | fw_schedule_bus_reset(card, false, true); |
544 | 644 | ||
545 | mutex_lock(&card_mutex); | 645 | mutex_lock(&card_mutex); |
546 | list_del_init(&card->link); | 646 | list_del_init(&card->link); |
@@ -558,15 +658,5 @@ void fw_core_remove_card(struct fw_card *card) | |||
558 | wait_for_completion(&card->done); | 658 | wait_for_completion(&card->done); |
559 | 659 | ||
560 | WARN_ON(!list_empty(&card->transaction_list)); | 660 | WARN_ON(!list_empty(&card->transaction_list)); |
561 | del_timer_sync(&card->flush_timer); | ||
562 | } | 661 | } |
563 | EXPORT_SYMBOL(fw_core_remove_card); | 662 | EXPORT_SYMBOL(fw_core_remove_card); |
564 | |||
565 | int fw_core_initiate_bus_reset(struct fw_card *card, int short_reset) | ||
566 | { | ||
567 | int reg = short_reset ? 5 : 1; | ||
568 | int bit = short_reset ? PHY_BUS_SHORT_RESET : PHY_BUS_RESET; | ||
569 | |||
570 | return card->driver->update_phy_reg(card, reg, 0, bit); | ||
571 | } | ||
572 | EXPORT_SYMBOL(fw_core_initiate_bus_reset); | ||
diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 14a34d99eea2..14bb7b7b5dd7 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c | |||
@@ -18,6 +18,7 @@ | |||
18 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <linux/bug.h> | ||
21 | #include <linux/compat.h> | 22 | #include <linux/compat.h> |
22 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
23 | #include <linux/device.h> | 24 | #include <linux/device.h> |
@@ -33,7 +34,7 @@ | |||
33 | #include <linux/module.h> | 34 | #include <linux/module.h> |
34 | #include <linux/mutex.h> | 35 | #include <linux/mutex.h> |
35 | #include <linux/poll.h> | 36 | #include <linux/poll.h> |
36 | #include <linux/sched.h> | 37 | #include <linux/sched.h> /* required for linux/wait.h */ |
37 | #include <linux/slab.h> | 38 | #include <linux/slab.h> |
38 | #include <linux/spinlock.h> | 39 | #include <linux/spinlock.h> |
39 | #include <linux/string.h> | 40 | #include <linux/string.h> |
@@ -47,6 +48,13 @@ | |||
47 | 48 | ||
48 | #include "core.h" | 49 | #include "core.h" |
49 | 50 | ||
51 | /* | ||
52 | * ABI version history is documented in linux/firewire-cdev.h. | ||
53 | */ | ||
54 | #define FW_CDEV_KERNEL_VERSION 4 | ||
55 | #define FW_CDEV_VERSION_EVENT_REQUEST2 4 | ||
56 | #define FW_CDEV_VERSION_ALLOCATE_REGION_END 4 | ||
57 | |||
50 | struct client { | 58 | struct client { |
51 | u32 version; | 59 | u32 version; |
52 | struct fw_device *device; | 60 | struct fw_device *device; |
@@ -63,6 +71,9 @@ struct client { | |||
63 | struct fw_iso_buffer buffer; | 71 | struct fw_iso_buffer buffer; |
64 | unsigned long vm_start; | 72 | unsigned long vm_start; |
65 | 73 | ||
74 | struct list_head phy_receiver_link; | ||
75 | u64 phy_receiver_closure; | ||
76 | |||
66 | struct list_head link; | 77 | struct list_head link; |
67 | struct kref kref; | 78 | struct kref kref; |
68 | }; | 79 | }; |
@@ -107,6 +118,7 @@ struct outbound_transaction_resource { | |||
107 | 118 | ||
108 | struct inbound_transaction_resource { | 119 | struct inbound_transaction_resource { |
109 | struct client_resource resource; | 120 | struct client_resource resource; |
121 | struct fw_card *card; | ||
110 | struct fw_request *request; | 122 | struct fw_request *request; |
111 | void *data; | 123 | void *data; |
112 | size_t length; | 124 | size_t length; |
@@ -171,7 +183,10 @@ struct outbound_transaction_event { | |||
171 | 183 | ||
172 | struct inbound_transaction_event { | 184 | struct inbound_transaction_event { |
173 | struct event event; | 185 | struct event event; |
174 | struct fw_cdev_event_request request; | 186 | union { |
187 | struct fw_cdev_event_request request; | ||
188 | struct fw_cdev_event_request2 request2; | ||
189 | } req; | ||
175 | }; | 190 | }; |
176 | 191 | ||
177 | struct iso_interrupt_event { | 192 | struct iso_interrupt_event { |
@@ -179,11 +194,28 @@ struct iso_interrupt_event { | |||
179 | struct fw_cdev_event_iso_interrupt interrupt; | 194 | struct fw_cdev_event_iso_interrupt interrupt; |
180 | }; | 195 | }; |
181 | 196 | ||
197 | struct iso_interrupt_mc_event { | ||
198 | struct event event; | ||
199 | struct fw_cdev_event_iso_interrupt_mc interrupt; | ||
200 | }; | ||
201 | |||
182 | struct iso_resource_event { | 202 | struct iso_resource_event { |
183 | struct event event; | 203 | struct event event; |
184 | struct fw_cdev_event_iso_resource iso_resource; | 204 | struct fw_cdev_event_iso_resource iso_resource; |
185 | }; | 205 | }; |
186 | 206 | ||
207 | struct outbound_phy_packet_event { | ||
208 | struct event event; | ||
209 | struct client *client; | ||
210 | struct fw_packet p; | ||
211 | struct fw_cdev_event_phy_packet phy_packet; | ||
212 | }; | ||
213 | |||
214 | struct inbound_phy_packet_event { | ||
215 | struct event event; | ||
216 | struct fw_cdev_event_phy_packet phy_packet; | ||
217 | }; | ||
218 | |||
187 | static inline void __user *u64_to_uptr(__u64 value) | 219 | static inline void __user *u64_to_uptr(__u64 value) |
188 | { | 220 | { |
189 | return (void __user *)(unsigned long)value; | 221 | return (void __user *)(unsigned long)value; |
@@ -219,6 +251,7 @@ static int fw_device_op_open(struct inode *inode, struct file *file) | |||
219 | idr_init(&client->resource_idr); | 251 | idr_init(&client->resource_idr); |
220 | INIT_LIST_HEAD(&client->event_list); | 252 | INIT_LIST_HEAD(&client->event_list); |
221 | init_waitqueue_head(&client->wait); | 253 | init_waitqueue_head(&client->wait); |
254 | INIT_LIST_HEAD(&client->phy_receiver_link); | ||
222 | kref_init(&client->kref); | 255 | kref_init(&client->kref); |
223 | 256 | ||
224 | file->private_data = client; | 257 | file->private_data = client; |
@@ -227,7 +260,7 @@ static int fw_device_op_open(struct inode *inode, struct file *file) | |||
227 | list_add_tail(&client->link, &device->client_list); | 260 | list_add_tail(&client->link, &device->client_list); |
228 | mutex_unlock(&device->client_list_mutex); | 261 | mutex_unlock(&device->client_list_mutex); |
229 | 262 | ||
230 | return 0; | 263 | return nonseekable_open(inode, file); |
231 | } | 264 | } |
232 | 265 | ||
233 | static void queue_event(struct client *client, struct event *event, | 266 | static void queue_event(struct client *client, struct event *event, |
@@ -309,7 +342,7 @@ static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event, | |||
309 | event->generation = client->device->generation; | 342 | event->generation = client->device->generation; |
310 | event->node_id = client->device->node_id; | 343 | event->node_id = client->device->node_id; |
311 | event->local_node_id = card->local_node->node_id; | 344 | event->local_node_id = card->local_node->node_id; |
312 | event->bm_node_id = 0; /* FIXME: We don't track the BM. */ | 345 | event->bm_node_id = card->bm_node_id; |
313 | event->irm_node_id = card->irm_node->node_id; | 346 | event->irm_node_id = card->irm_node->node_id; |
314 | event->root_node_id = card->root_node->node_id; | 347 | event->root_node_id = card->root_node->node_id; |
315 | 348 | ||
@@ -340,7 +373,7 @@ static void queue_bus_reset_event(struct client *client) | |||
340 | 373 | ||
341 | e = kzalloc(sizeof(*e), GFP_KERNEL); | 374 | e = kzalloc(sizeof(*e), GFP_KERNEL); |
342 | if (e == NULL) { | 375 | if (e == NULL) { |
343 | fw_notify("Out of memory when allocating bus reset event\n"); | 376 | fw_notify("Out of memory when allocating event\n"); |
344 | return; | 377 | return; |
345 | } | 378 | } |
346 | 379 | ||
@@ -386,6 +419,9 @@ union ioctl_arg { | |||
386 | struct fw_cdev_allocate_iso_resource allocate_iso_resource; | 419 | struct fw_cdev_allocate_iso_resource allocate_iso_resource; |
387 | struct fw_cdev_send_stream_packet send_stream_packet; | 420 | struct fw_cdev_send_stream_packet send_stream_packet; |
388 | struct fw_cdev_get_cycle_timer2 get_cycle_timer2; | 421 | struct fw_cdev_get_cycle_timer2 get_cycle_timer2; |
422 | struct fw_cdev_send_phy_packet send_phy_packet; | ||
423 | struct fw_cdev_receive_phy_packets receive_phy_packets; | ||
424 | struct fw_cdev_set_iso_channels set_iso_channels; | ||
389 | }; | 425 | }; |
390 | 426 | ||
391 | static int ioctl_get_info(struct client *client, union ioctl_arg *arg) | 427 | static int ioctl_get_info(struct client *client, union ioctl_arg *arg) |
@@ -395,7 +431,7 @@ static int ioctl_get_info(struct client *client, union ioctl_arg *arg) | |||
395 | unsigned long ret = 0; | 431 | unsigned long ret = 0; |
396 | 432 | ||
397 | client->version = a->version; | 433 | client->version = a->version; |
398 | a->version = FW_CDEV_VERSION; | 434 | a->version = FW_CDEV_KERNEL_VERSION; |
399 | a->card = client->device->card->index; | 435 | a->card = client->device->card->index; |
400 | 436 | ||
401 | down_read(&fw_device_rwsem); | 437 | down_read(&fw_device_rwsem); |
@@ -554,6 +590,10 @@ static int init_request(struct client *client, | |||
554 | (request->length > 4096 || request->length > 512 << speed)) | 590 | (request->length > 4096 || request->length > 512 << speed)) |
555 | return -EIO; | 591 | return -EIO; |
556 | 592 | ||
593 | if (request->tcode == TCODE_WRITE_QUADLET_REQUEST && | ||
594 | request->length < 4) | ||
595 | return -EINVAL; | ||
596 | |||
557 | e = kmalloc(sizeof(*e) + request->length, GFP_KERNEL); | 597 | e = kmalloc(sizeof(*e) + request->length, GFP_KERNEL); |
558 | if (e == NULL) | 598 | if (e == NULL) |
559 | return -ENOMEM; | 599 | return -ENOMEM; |
@@ -626,28 +666,34 @@ static void release_request(struct client *client, | |||
626 | if (is_fcp_request(r->request)) | 666 | if (is_fcp_request(r->request)) |
627 | kfree(r->data); | 667 | kfree(r->data); |
628 | else | 668 | else |
629 | fw_send_response(client->device->card, r->request, | 669 | fw_send_response(r->card, r->request, RCODE_CONFLICT_ERROR); |
630 | RCODE_CONFLICT_ERROR); | 670 | |
671 | fw_card_put(r->card); | ||
631 | kfree(r); | 672 | kfree(r); |
632 | } | 673 | } |
633 | 674 | ||
634 | static void handle_request(struct fw_card *card, struct fw_request *request, | 675 | static void handle_request(struct fw_card *card, struct fw_request *request, |
635 | int tcode, int destination, int source, | 676 | int tcode, int destination, int source, |
636 | int generation, int speed, | 677 | int generation, unsigned long long offset, |
637 | unsigned long long offset, | ||
638 | void *payload, size_t length, void *callback_data) | 678 | void *payload, size_t length, void *callback_data) |
639 | { | 679 | { |
640 | struct address_handler_resource *handler = callback_data; | 680 | struct address_handler_resource *handler = callback_data; |
641 | struct inbound_transaction_resource *r; | 681 | struct inbound_transaction_resource *r; |
642 | struct inbound_transaction_event *e; | 682 | struct inbound_transaction_event *e; |
683 | size_t event_size0; | ||
643 | void *fcp_frame = NULL; | 684 | void *fcp_frame = NULL; |
644 | int ret; | 685 | int ret; |
645 | 686 | ||
687 | /* card may be different from handler->client->device->card */ | ||
688 | fw_card_get(card); | ||
689 | |||
646 | r = kmalloc(sizeof(*r), GFP_ATOMIC); | 690 | r = kmalloc(sizeof(*r), GFP_ATOMIC); |
647 | e = kmalloc(sizeof(*e), GFP_ATOMIC); | 691 | e = kmalloc(sizeof(*e), GFP_ATOMIC); |
648 | if (r == NULL || e == NULL) | 692 | if (r == NULL || e == NULL) { |
693 | fw_notify("Out of memory when allocating event\n"); | ||
649 | goto failed; | 694 | goto failed; |
650 | 695 | } | |
696 | r->card = card; | ||
651 | r->request = request; | 697 | r->request = request; |
652 | r->data = payload; | 698 | r->data = payload; |
653 | r->length = length; | 699 | r->length = length; |
@@ -669,15 +715,37 @@ static void handle_request(struct fw_card *card, struct fw_request *request, | |||
669 | if (ret < 0) | 715 | if (ret < 0) |
670 | goto failed; | 716 | goto failed; |
671 | 717 | ||
672 | e->request.type = FW_CDEV_EVENT_REQUEST; | 718 | if (handler->client->version < FW_CDEV_VERSION_EVENT_REQUEST2) { |
673 | e->request.tcode = tcode; | 719 | struct fw_cdev_event_request *req = &e->req.request; |
674 | e->request.offset = offset; | 720 | |
675 | e->request.length = length; | 721 | if (tcode & 0x10) |
676 | e->request.handle = r->resource.handle; | 722 | tcode = TCODE_LOCK_REQUEST; |
677 | e->request.closure = handler->closure; | 723 | |
724 | req->type = FW_CDEV_EVENT_REQUEST; | ||
725 | req->tcode = tcode; | ||
726 | req->offset = offset; | ||
727 | req->length = length; | ||
728 | req->handle = r->resource.handle; | ||
729 | req->closure = handler->closure; | ||
730 | event_size0 = sizeof(*req); | ||
731 | } else { | ||
732 | struct fw_cdev_event_request2 *req = &e->req.request2; | ||
733 | |||
734 | req->type = FW_CDEV_EVENT_REQUEST2; | ||
735 | req->tcode = tcode; | ||
736 | req->offset = offset; | ||
737 | req->source_node_id = source; | ||
738 | req->destination_node_id = destination; | ||
739 | req->card = card->index; | ||
740 | req->generation = generation; | ||
741 | req->length = length; | ||
742 | req->handle = r->resource.handle; | ||
743 | req->closure = handler->closure; | ||
744 | event_size0 = sizeof(*req); | ||
745 | } | ||
678 | 746 | ||
679 | queue_event(handler->client, &e->event, | 747 | queue_event(handler->client, &e->event, |
680 | &e->request, sizeof(e->request), r->data, length); | 748 | &e->req, event_size0, r->data, length); |
681 | return; | 749 | return; |
682 | 750 | ||
683 | failed: | 751 | failed: |
@@ -687,6 +755,8 @@ static void handle_request(struct fw_card *card, struct fw_request *request, | |||
687 | 755 | ||
688 | if (!is_fcp_request(request)) | 756 | if (!is_fcp_request(request)) |
689 | fw_send_response(card, request, RCODE_CONFLICT_ERROR); | 757 | fw_send_response(card, request, RCODE_CONFLICT_ERROR); |
758 | |||
759 | fw_card_put(card); | ||
690 | } | 760 | } |
691 | 761 | ||
692 | static void release_address_handler(struct client *client, | 762 | static void release_address_handler(struct client *client, |
@@ -711,7 +781,11 @@ static int ioctl_allocate(struct client *client, union ioctl_arg *arg) | |||
711 | return -ENOMEM; | 781 | return -ENOMEM; |
712 | 782 | ||
713 | region.start = a->offset; | 783 | region.start = a->offset; |
714 | region.end = a->offset + a->length; | 784 | if (client->version < FW_CDEV_VERSION_ALLOCATE_REGION_END) |
785 | region.end = a->offset + a->length; | ||
786 | else | ||
787 | region.end = a->region_end; | ||
788 | |||
715 | r->handler.length = a->length; | 789 | r->handler.length = a->length; |
716 | r->handler.address_callback = handle_request; | 790 | r->handler.address_callback = handle_request; |
717 | r->handler.callback_data = r; | 791 | r->handler.callback_data = r; |
@@ -723,6 +797,7 @@ static int ioctl_allocate(struct client *client, union ioctl_arg *arg) | |||
723 | kfree(r); | 797 | kfree(r); |
724 | return ret; | 798 | return ret; |
725 | } | 799 | } |
800 | a->offset = r->handler.offset; | ||
726 | 801 | ||
727 | r->resource.release = release_address_handler; | 802 | r->resource.release = release_address_handler; |
728 | ret = add_client_resource(client, &r->resource, GFP_KERNEL); | 803 | ret = add_client_resource(client, &r->resource, GFP_KERNEL); |
@@ -757,15 +832,19 @@ static int ioctl_send_response(struct client *client, union ioctl_arg *arg) | |||
757 | if (is_fcp_request(r->request)) | 832 | if (is_fcp_request(r->request)) |
758 | goto out; | 833 | goto out; |
759 | 834 | ||
760 | if (a->length < r->length) | 835 | if (a->length != fw_get_response_length(r->request)) { |
761 | r->length = a->length; | 836 | ret = -EINVAL; |
762 | if (copy_from_user(r->data, u64_to_uptr(a->data), r->length)) { | 837 | kfree(r->request); |
838 | goto out; | ||
839 | } | ||
840 | if (copy_from_user(r->data, u64_to_uptr(a->data), a->length)) { | ||
763 | ret = -EFAULT; | 841 | ret = -EFAULT; |
764 | kfree(r->request); | 842 | kfree(r->request); |
765 | goto out; | 843 | goto out; |
766 | } | 844 | } |
767 | fw_send_response(client->device->card, r->request, a->rcode); | 845 | fw_send_response(r->card, r->request, a->rcode); |
768 | out: | 846 | out: |
847 | fw_card_put(r->card); | ||
769 | kfree(r); | 848 | kfree(r); |
770 | 849 | ||
771 | return ret; | 850 | return ret; |
@@ -773,8 +852,9 @@ static int ioctl_send_response(struct client *client, union ioctl_arg *arg) | |||
773 | 852 | ||
774 | static int ioctl_initiate_bus_reset(struct client *client, union ioctl_arg *arg) | 853 | static int ioctl_initiate_bus_reset(struct client *client, union ioctl_arg *arg) |
775 | { | 854 | { |
776 | return fw_core_initiate_bus_reset(client->device->card, | 855 | fw_schedule_bus_reset(client->device->card, true, |
777 | arg->initiate_bus_reset.type == FW_CDEV_SHORT_RESET); | 856 | arg->initiate_bus_reset.type == FW_CDEV_SHORT_RESET); |
857 | return 0; | ||
778 | } | 858 | } |
779 | 859 | ||
780 | static void release_descriptor(struct client *client, | 860 | static void release_descriptor(struct client *client, |
@@ -845,10 +925,11 @@ static void iso_callback(struct fw_iso_context *context, u32 cycle, | |||
845 | struct client *client = data; | 925 | struct client *client = data; |
846 | struct iso_interrupt_event *e; | 926 | struct iso_interrupt_event *e; |
847 | 927 | ||
848 | e = kzalloc(sizeof(*e) + header_length, GFP_ATOMIC); | 928 | e = kmalloc(sizeof(*e) + header_length, GFP_ATOMIC); |
849 | if (e == NULL) | 929 | if (e == NULL) { |
930 | fw_notify("Out of memory when allocating event\n"); | ||
850 | return; | 931 | return; |
851 | 932 | } | |
852 | e->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT; | 933 | e->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT; |
853 | e->interrupt.closure = client->iso_closure; | 934 | e->interrupt.closure = client->iso_closure; |
854 | e->interrupt.cycle = cycle; | 935 | e->interrupt.cycle = cycle; |
@@ -858,27 +939,54 @@ static void iso_callback(struct fw_iso_context *context, u32 cycle, | |||
858 | sizeof(e->interrupt) + header_length, NULL, 0); | 939 | sizeof(e->interrupt) + header_length, NULL, 0); |
859 | } | 940 | } |
860 | 941 | ||
942 | static void iso_mc_callback(struct fw_iso_context *context, | ||
943 | dma_addr_t completed, void *data) | ||
944 | { | ||
945 | struct client *client = data; | ||
946 | struct iso_interrupt_mc_event *e; | ||
947 | |||
948 | e = kmalloc(sizeof(*e), GFP_ATOMIC); | ||
949 | if (e == NULL) { | ||
950 | fw_notify("Out of memory when allocating event\n"); | ||
951 | return; | ||
952 | } | ||
953 | e->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL; | ||
954 | e->interrupt.closure = client->iso_closure; | ||
955 | e->interrupt.completed = fw_iso_buffer_lookup(&client->buffer, | ||
956 | completed); | ||
957 | queue_event(client, &e->event, &e->interrupt, | ||
958 | sizeof(e->interrupt), NULL, 0); | ||
959 | } | ||
960 | |||
861 | static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg) | 961 | static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg) |
862 | { | 962 | { |
863 | struct fw_cdev_create_iso_context *a = &arg->create_iso_context; | 963 | struct fw_cdev_create_iso_context *a = &arg->create_iso_context; |
864 | struct fw_iso_context *context; | 964 | struct fw_iso_context *context; |
965 | fw_iso_callback_t cb; | ||
865 | 966 | ||
866 | /* We only support one context at this time. */ | 967 | BUILD_BUG_ON(FW_CDEV_ISO_CONTEXT_TRANSMIT != FW_ISO_CONTEXT_TRANSMIT || |
867 | if (client->iso_context != NULL) | 968 | FW_CDEV_ISO_CONTEXT_RECEIVE != FW_ISO_CONTEXT_RECEIVE || |
868 | return -EBUSY; | 969 | FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL != |
869 | 970 | FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL); | |
870 | if (a->channel > 63) | ||
871 | return -EINVAL; | ||
872 | 971 | ||
873 | switch (a->type) { | 972 | switch (a->type) { |
874 | case FW_ISO_CONTEXT_RECEIVE: | 973 | case FW_ISO_CONTEXT_TRANSMIT: |
875 | if (a->header_size < 4 || (a->header_size & 3)) | 974 | if (a->speed > SCODE_3200 || a->channel > 63) |
876 | return -EINVAL; | 975 | return -EINVAL; |
976 | |||
977 | cb = iso_callback; | ||
877 | break; | 978 | break; |
878 | 979 | ||
879 | case FW_ISO_CONTEXT_TRANSMIT: | 980 | case FW_ISO_CONTEXT_RECEIVE: |
880 | if (a->speed > SCODE_3200) | 981 | if (a->header_size < 4 || (a->header_size & 3) || |
982 | a->channel > 63) | ||
881 | return -EINVAL; | 983 | return -EINVAL; |
984 | |||
985 | cb = iso_callback; | ||
986 | break; | ||
987 | |||
988 | case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: | ||
989 | cb = (fw_iso_callback_t)iso_mc_callback; | ||
882 | break; | 990 | break; |
883 | 991 | ||
884 | default: | 992 | default: |
@@ -886,20 +994,37 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg) | |||
886 | } | 994 | } |
887 | 995 | ||
888 | context = fw_iso_context_create(client->device->card, a->type, | 996 | context = fw_iso_context_create(client->device->card, a->type, |
889 | a->channel, a->speed, a->header_size, | 997 | a->channel, a->speed, a->header_size, cb, client); |
890 | iso_callback, client); | ||
891 | if (IS_ERR(context)) | 998 | if (IS_ERR(context)) |
892 | return PTR_ERR(context); | 999 | return PTR_ERR(context); |
893 | 1000 | ||
1001 | /* We only support one context at this time. */ | ||
1002 | spin_lock_irq(&client->lock); | ||
1003 | if (client->iso_context != NULL) { | ||
1004 | spin_unlock_irq(&client->lock); | ||
1005 | fw_iso_context_destroy(context); | ||
1006 | return -EBUSY; | ||
1007 | } | ||
894 | client->iso_closure = a->closure; | 1008 | client->iso_closure = a->closure; |
895 | client->iso_context = context; | 1009 | client->iso_context = context; |
1010 | spin_unlock_irq(&client->lock); | ||
896 | 1011 | ||
897 | /* We only support one context at this time. */ | ||
898 | a->handle = 0; | 1012 | a->handle = 0; |
899 | 1013 | ||
900 | return 0; | 1014 | return 0; |
901 | } | 1015 | } |
902 | 1016 | ||
1017 | static int ioctl_set_iso_channels(struct client *client, union ioctl_arg *arg) | ||
1018 | { | ||
1019 | struct fw_cdev_set_iso_channels *a = &arg->set_iso_channels; | ||
1020 | struct fw_iso_context *ctx = client->iso_context; | ||
1021 | |||
1022 | if (ctx == NULL || a->handle != 0) | ||
1023 | return -EINVAL; | ||
1024 | |||
1025 | return fw_iso_context_set_channels(ctx, &a->channels); | ||
1026 | } | ||
1027 | |||
903 | /* Macros for decoding the iso packet control header. */ | 1028 | /* Macros for decoding the iso packet control header. */ |
904 | #define GET_PAYLOAD_LENGTH(v) ((v) & 0xffff) | 1029 | #define GET_PAYLOAD_LENGTH(v) ((v) & 0xffff) |
905 | #define GET_INTERRUPT(v) (((v) >> 16) & 0x01) | 1030 | #define GET_INTERRUPT(v) (((v) >> 16) & 0x01) |
@@ -913,7 +1038,7 @@ static int ioctl_queue_iso(struct client *client, union ioctl_arg *arg) | |||
913 | struct fw_cdev_queue_iso *a = &arg->queue_iso; | 1038 | struct fw_cdev_queue_iso *a = &arg->queue_iso; |
914 | struct fw_cdev_iso_packet __user *p, *end, *next; | 1039 | struct fw_cdev_iso_packet __user *p, *end, *next; |
915 | struct fw_iso_context *ctx = client->iso_context; | 1040 | struct fw_iso_context *ctx = client->iso_context; |
916 | unsigned long payload, buffer_end, header_length; | 1041 | unsigned long payload, buffer_end, transmit_header_bytes = 0; |
917 | u32 control; | 1042 | u32 control; |
918 | int count; | 1043 | int count; |
919 | struct { | 1044 | struct { |
@@ -933,7 +1058,6 @@ static int ioctl_queue_iso(struct client *client, union ioctl_arg *arg) | |||
933 | * use the indirect payload, the iso buffer need not be mapped | 1058 | * use the indirect payload, the iso buffer need not be mapped |
934 | * and the a->data pointer is ignored. | 1059 | * and the a->data pointer is ignored. |
935 | */ | 1060 | */ |
936 | |||
937 | payload = (unsigned long)a->data - client->vm_start; | 1061 | payload = (unsigned long)a->data - client->vm_start; |
938 | buffer_end = client->buffer.page_count << PAGE_SHIFT; | 1062 | buffer_end = client->buffer.page_count << PAGE_SHIFT; |
939 | if (a->data == 0 || client->buffer.pages == NULL || | 1063 | if (a->data == 0 || client->buffer.pages == NULL || |
@@ -942,8 +1066,10 @@ static int ioctl_queue_iso(struct client *client, union ioctl_arg *arg) | |||
942 | buffer_end = 0; | 1066 | buffer_end = 0; |
943 | } | 1067 | } |
944 | 1068 | ||
945 | p = (struct fw_cdev_iso_packet __user *)u64_to_uptr(a->packets); | 1069 | if (ctx->type == FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL && payload & 3) |
1070 | return -EINVAL; | ||
946 | 1071 | ||
1072 | p = (struct fw_cdev_iso_packet __user *)u64_to_uptr(a->packets); | ||
947 | if (!access_ok(VERIFY_READ, p, a->size)) | 1073 | if (!access_ok(VERIFY_READ, p, a->size)) |
948 | return -EFAULT; | 1074 | return -EFAULT; |
949 | 1075 | ||
@@ -959,31 +1085,32 @@ static int ioctl_queue_iso(struct client *client, union ioctl_arg *arg) | |||
959 | u.packet.sy = GET_SY(control); | 1085 | u.packet.sy = GET_SY(control); |
960 | u.packet.header_length = GET_HEADER_LENGTH(control); | 1086 | u.packet.header_length = GET_HEADER_LENGTH(control); |
961 | 1087 | ||
962 | if (ctx->type == FW_ISO_CONTEXT_TRANSMIT) { | 1088 | switch (ctx->type) { |
963 | if (u.packet.header_length % 4 != 0) | 1089 | case FW_ISO_CONTEXT_TRANSMIT: |
1090 | if (u.packet.header_length & 3) | ||
964 | return -EINVAL; | 1091 | return -EINVAL; |
965 | header_length = u.packet.header_length; | 1092 | transmit_header_bytes = u.packet.header_length; |
966 | } else { | 1093 | break; |
967 | /* | 1094 | |
968 | * We require that header_length is a multiple of | 1095 | case FW_ISO_CONTEXT_RECEIVE: |
969 | * the fixed header size, ctx->header_size. | 1096 | if (u.packet.header_length == 0 || |
970 | */ | 1097 | u.packet.header_length % ctx->header_size != 0) |
971 | if (ctx->header_size == 0) { | 1098 | return -EINVAL; |
972 | if (u.packet.header_length > 0) | 1099 | break; |
973 | return -EINVAL; | 1100 | |
974 | } else if (u.packet.header_length == 0 || | 1101 | case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: |
975 | u.packet.header_length % ctx->header_size != 0) { | 1102 | if (u.packet.payload_length == 0 || |
1103 | u.packet.payload_length & 3) | ||
976 | return -EINVAL; | 1104 | return -EINVAL; |
977 | } | 1105 | break; |
978 | header_length = 0; | ||
979 | } | 1106 | } |
980 | 1107 | ||
981 | next = (struct fw_cdev_iso_packet __user *) | 1108 | next = (struct fw_cdev_iso_packet __user *) |
982 | &p->header[header_length / 4]; | 1109 | &p->header[transmit_header_bytes / 4]; |
983 | if (next > end) | 1110 | if (next > end) |
984 | return -EINVAL; | 1111 | return -EINVAL; |
985 | if (__copy_from_user | 1112 | if (__copy_from_user |
986 | (u.packet.header, p->header, header_length)) | 1113 | (u.packet.header, p->header, transmit_header_bytes)) |
987 | return -EFAULT; | 1114 | return -EFAULT; |
988 | if (u.packet.skip && ctx->type == FW_ISO_CONTEXT_TRANSMIT && | 1115 | if (u.packet.skip && ctx->type == FW_ISO_CONTEXT_TRANSMIT && |
989 | u.packet.header_length + u.packet.payload_length > 0) | 1116 | u.packet.header_length + u.packet.payload_length > 0) |
@@ -1011,6 +1138,13 @@ static int ioctl_start_iso(struct client *client, union ioctl_arg *arg) | |||
1011 | { | 1138 | { |
1012 | struct fw_cdev_start_iso *a = &arg->start_iso; | 1139 | struct fw_cdev_start_iso *a = &arg->start_iso; |
1013 | 1140 | ||
1141 | BUILD_BUG_ON( | ||
1142 | FW_CDEV_ISO_CONTEXT_MATCH_TAG0 != FW_ISO_CONTEXT_MATCH_TAG0 || | ||
1143 | FW_CDEV_ISO_CONTEXT_MATCH_TAG1 != FW_ISO_CONTEXT_MATCH_TAG1 || | ||
1144 | FW_CDEV_ISO_CONTEXT_MATCH_TAG2 != FW_ISO_CONTEXT_MATCH_TAG2 || | ||
1145 | FW_CDEV_ISO_CONTEXT_MATCH_TAG3 != FW_ISO_CONTEXT_MATCH_TAG3 || | ||
1146 | FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS != FW_ISO_CONTEXT_MATCH_ALL_TAGS); | ||
1147 | |||
1014 | if (client->iso_context == NULL || a->handle != 0) | 1148 | if (client->iso_context == NULL || a->handle != 0) |
1015 | return -EINVAL; | 1149 | return -EINVAL; |
1016 | 1150 | ||
@@ -1042,7 +1176,7 @@ static int ioctl_get_cycle_timer2(struct client *client, union ioctl_arg *arg) | |||
1042 | 1176 | ||
1043 | local_irq_disable(); | 1177 | local_irq_disable(); |
1044 | 1178 | ||
1045 | cycle_time = card->driver->get_cycle_time(card); | 1179 | cycle_time = card->driver->read_csr(card, CSR_CYCLE_TIME); |
1046 | 1180 | ||
1047 | switch (a->clk_id) { | 1181 | switch (a->clk_id) { |
1048 | case CLOCK_REALTIME: getnstimeofday(&ts); break; | 1182 | case CLOCK_REALTIME: getnstimeofday(&ts); break; |
@@ -1323,28 +1457,135 @@ static int ioctl_send_stream_packet(struct client *client, union ioctl_arg *arg) | |||
1323 | return init_request(client, &request, dest, a->speed); | 1457 | return init_request(client, &request, dest, a->speed); |
1324 | } | 1458 | } |
1325 | 1459 | ||
1460 | static void outbound_phy_packet_callback(struct fw_packet *packet, | ||
1461 | struct fw_card *card, int status) | ||
1462 | { | ||
1463 | struct outbound_phy_packet_event *e = | ||
1464 | container_of(packet, struct outbound_phy_packet_event, p); | ||
1465 | |||
1466 | switch (status) { | ||
1467 | /* expected: */ | ||
1468 | case ACK_COMPLETE: e->phy_packet.rcode = RCODE_COMPLETE; break; | ||
1469 | /* should never happen with PHY packets: */ | ||
1470 | case ACK_PENDING: e->phy_packet.rcode = RCODE_COMPLETE; break; | ||
1471 | case ACK_BUSY_X: | ||
1472 | case ACK_BUSY_A: | ||
1473 | case ACK_BUSY_B: e->phy_packet.rcode = RCODE_BUSY; break; | ||
1474 | case ACK_DATA_ERROR: e->phy_packet.rcode = RCODE_DATA_ERROR; break; | ||
1475 | case ACK_TYPE_ERROR: e->phy_packet.rcode = RCODE_TYPE_ERROR; break; | ||
1476 | /* stale generation; cancelled; on certain controllers: no ack */ | ||
1477 | default: e->phy_packet.rcode = status; break; | ||
1478 | } | ||
1479 | e->phy_packet.data[0] = packet->timestamp; | ||
1480 | |||
1481 | queue_event(e->client, &e->event, &e->phy_packet, | ||
1482 | sizeof(e->phy_packet) + e->phy_packet.length, NULL, 0); | ||
1483 | client_put(e->client); | ||
1484 | } | ||
1485 | |||
1486 | static int ioctl_send_phy_packet(struct client *client, union ioctl_arg *arg) | ||
1487 | { | ||
1488 | struct fw_cdev_send_phy_packet *a = &arg->send_phy_packet; | ||
1489 | struct fw_card *card = client->device->card; | ||
1490 | struct outbound_phy_packet_event *e; | ||
1491 | |||
1492 | /* Access policy: Allow this ioctl only on local nodes' device files. */ | ||
1493 | if (!client->device->is_local) | ||
1494 | return -ENOSYS; | ||
1495 | |||
1496 | e = kzalloc(sizeof(*e) + 4, GFP_KERNEL); | ||
1497 | if (e == NULL) | ||
1498 | return -ENOMEM; | ||
1499 | |||
1500 | client_get(client); | ||
1501 | e->client = client; | ||
1502 | e->p.speed = SCODE_100; | ||
1503 | e->p.generation = a->generation; | ||
1504 | e->p.header[0] = a->data[0]; | ||
1505 | e->p.header[1] = a->data[1]; | ||
1506 | e->p.header_length = 8; | ||
1507 | e->p.callback = outbound_phy_packet_callback; | ||
1508 | e->phy_packet.closure = a->closure; | ||
1509 | e->phy_packet.type = FW_CDEV_EVENT_PHY_PACKET_SENT; | ||
1510 | if (is_ping_packet(a->data)) | ||
1511 | e->phy_packet.length = 4; | ||
1512 | |||
1513 | card->driver->send_request(card, &e->p); | ||
1514 | |||
1515 | return 0; | ||
1516 | } | ||
1517 | |||
1518 | static int ioctl_receive_phy_packets(struct client *client, union ioctl_arg *arg) | ||
1519 | { | ||
1520 | struct fw_cdev_receive_phy_packets *a = &arg->receive_phy_packets; | ||
1521 | struct fw_card *card = client->device->card; | ||
1522 | |||
1523 | /* Access policy: Allow this ioctl only on local nodes' device files. */ | ||
1524 | if (!client->device->is_local) | ||
1525 | return -ENOSYS; | ||
1526 | |||
1527 | spin_lock_irq(&card->lock); | ||
1528 | |||
1529 | list_move_tail(&client->phy_receiver_link, &card->phy_receiver_list); | ||
1530 | client->phy_receiver_closure = a->closure; | ||
1531 | |||
1532 | spin_unlock_irq(&card->lock); | ||
1533 | |||
1534 | return 0; | ||
1535 | } | ||
1536 | |||
1537 | void fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p) | ||
1538 | { | ||
1539 | struct client *client; | ||
1540 | struct inbound_phy_packet_event *e; | ||
1541 | unsigned long flags; | ||
1542 | |||
1543 | spin_lock_irqsave(&card->lock, flags); | ||
1544 | |||
1545 | list_for_each_entry(client, &card->phy_receiver_list, phy_receiver_link) { | ||
1546 | e = kmalloc(sizeof(*e) + 8, GFP_ATOMIC); | ||
1547 | if (e == NULL) { | ||
1548 | fw_notify("Out of memory when allocating event\n"); | ||
1549 | break; | ||
1550 | } | ||
1551 | e->phy_packet.closure = client->phy_receiver_closure; | ||
1552 | e->phy_packet.type = FW_CDEV_EVENT_PHY_PACKET_RECEIVED; | ||
1553 | e->phy_packet.rcode = RCODE_COMPLETE; | ||
1554 | e->phy_packet.length = 8; | ||
1555 | e->phy_packet.data[0] = p->header[1]; | ||
1556 | e->phy_packet.data[1] = p->header[2]; | ||
1557 | queue_event(client, &e->event, | ||
1558 | &e->phy_packet, sizeof(e->phy_packet) + 8, NULL, 0); | ||
1559 | } | ||
1560 | |||
1561 | spin_unlock_irqrestore(&card->lock, flags); | ||
1562 | } | ||
1563 | |||
1326 | static int (* const ioctl_handlers[])(struct client *, union ioctl_arg *) = { | 1564 | static int (* const ioctl_handlers[])(struct client *, union ioctl_arg *) = { |
1327 | ioctl_get_info, | 1565 | [0x00] = ioctl_get_info, |
1328 | ioctl_send_request, | 1566 | [0x01] = ioctl_send_request, |
1329 | ioctl_allocate, | 1567 | [0x02] = ioctl_allocate, |
1330 | ioctl_deallocate, | 1568 | [0x03] = ioctl_deallocate, |
1331 | ioctl_send_response, | 1569 | [0x04] = ioctl_send_response, |
1332 | ioctl_initiate_bus_reset, | 1570 | [0x05] = ioctl_initiate_bus_reset, |
1333 | ioctl_add_descriptor, | 1571 | [0x06] = ioctl_add_descriptor, |
1334 | ioctl_remove_descriptor, | 1572 | [0x07] = ioctl_remove_descriptor, |
1335 | ioctl_create_iso_context, | 1573 | [0x08] = ioctl_create_iso_context, |
1336 | ioctl_queue_iso, | 1574 | [0x09] = ioctl_queue_iso, |
1337 | ioctl_start_iso, | 1575 | [0x0a] = ioctl_start_iso, |
1338 | ioctl_stop_iso, | 1576 | [0x0b] = ioctl_stop_iso, |
1339 | ioctl_get_cycle_timer, | 1577 | [0x0c] = ioctl_get_cycle_timer, |
1340 | ioctl_allocate_iso_resource, | 1578 | [0x0d] = ioctl_allocate_iso_resource, |
1341 | ioctl_deallocate_iso_resource, | 1579 | [0x0e] = ioctl_deallocate_iso_resource, |
1342 | ioctl_allocate_iso_resource_once, | 1580 | [0x0f] = ioctl_allocate_iso_resource_once, |
1343 | ioctl_deallocate_iso_resource_once, | 1581 | [0x10] = ioctl_deallocate_iso_resource_once, |
1344 | ioctl_get_speed, | 1582 | [0x11] = ioctl_get_speed, |
1345 | ioctl_send_broadcast_request, | 1583 | [0x12] = ioctl_send_broadcast_request, |
1346 | ioctl_send_stream_packet, | 1584 | [0x13] = ioctl_send_stream_packet, |
1347 | ioctl_get_cycle_timer2, | 1585 | [0x14] = ioctl_get_cycle_timer2, |
1586 | [0x15] = ioctl_send_phy_packet, | ||
1587 | [0x16] = ioctl_receive_phy_packets, | ||
1588 | [0x17] = ioctl_set_iso_channels, | ||
1348 | }; | 1589 | }; |
1349 | 1590 | ||
1350 | static int dispatch_ioctl(struct client *client, | 1591 | static int dispatch_ioctl(struct client *client, |
@@ -1452,6 +1693,10 @@ static int fw_device_op_release(struct inode *inode, struct file *file) | |||
1452 | struct client *client = file->private_data; | 1693 | struct client *client = file->private_data; |
1453 | struct event *event, *next_event; | 1694 | struct event *event, *next_event; |
1454 | 1695 | ||
1696 | spin_lock_irq(&client->device->card->lock); | ||
1697 | list_del(&client->phy_receiver_link); | ||
1698 | spin_unlock_irq(&client->device->card->lock); | ||
1699 | |||
1455 | mutex_lock(&client->device->client_list_mutex); | 1700 | mutex_lock(&client->device->client_list_mutex); |
1456 | list_del(&client->link); | 1701 | list_del(&client->link); |
1457 | mutex_unlock(&client->device->client_list_mutex); | 1702 | mutex_unlock(&client->device->client_list_mutex); |
@@ -1496,13 +1741,13 @@ static unsigned int fw_device_op_poll(struct file *file, poll_table * pt) | |||
1496 | 1741 | ||
1497 | const struct file_operations fw_device_ops = { | 1742 | const struct file_operations fw_device_ops = { |
1498 | .owner = THIS_MODULE, | 1743 | .owner = THIS_MODULE, |
1744 | .llseek = no_llseek, | ||
1499 | .open = fw_device_op_open, | 1745 | .open = fw_device_op_open, |
1500 | .read = fw_device_op_read, | 1746 | .read = fw_device_op_read, |
1501 | .unlocked_ioctl = fw_device_op_ioctl, | 1747 | .unlocked_ioctl = fw_device_op_ioctl, |
1502 | .poll = fw_device_op_poll, | ||
1503 | .release = fw_device_op_release, | ||
1504 | .mmap = fw_device_op_mmap, | 1748 | .mmap = fw_device_op_mmap, |
1505 | 1749 | .release = fw_device_op_release, | |
1750 | .poll = fw_device_op_poll, | ||
1506 | #ifdef CONFIG_COMPAT | 1751 | #ifdef CONFIG_COMPAT |
1507 | .compat_ioctl = fw_device_op_compat_ioctl, | 1752 | .compat_ioctl = fw_device_op_compat_ioctl, |
1508 | #endif | 1753 | #endif |
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index 4b8523f00dce..6113b896e790 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c | |||
@@ -107,11 +107,11 @@ static int textual_leaf_to_string(const u32 *block, char *buf, size_t size) | |||
107 | } | 107 | } |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * fw_csr_string - reads a string from the configuration ROM | 110 | * fw_csr_string() - reads a string from the configuration ROM |
111 | * @directory: e.g. root directory or unit directory | 111 | * @directory: e.g. root directory or unit directory |
112 | * @key: the key of the preceding directory entry | 112 | * @key: the key of the preceding directory entry |
113 | * @buf: where to put the string | 113 | * @buf: where to put the string |
114 | * @size: size of @buf, in bytes | 114 | * @size: size of @buf, in bytes |
115 | * | 115 | * |
116 | * The string is taken from a minimal ASCII text descriptor leaf after | 116 | * The string is taken from a minimal ASCII text descriptor leaf after |
117 | * the immediate entry with @key. The string is zero-terminated. | 117 | * the immediate entry with @key. The string is zero-terminated. |
@@ -1136,6 +1136,7 @@ static void fw_device_refresh(struct work_struct *work) | |||
1136 | goto give_up; | 1136 | goto give_up; |
1137 | } | 1137 | } |
1138 | 1138 | ||
1139 | fw_device_cdev_update(device); | ||
1139 | create_units(device); | 1140 | create_units(device); |
1140 | 1141 | ||
1141 | /* Userspace may want to re-read attributes. */ | 1142 | /* Userspace may want to re-read attributes. */ |
diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c index 8f5aebfb29df..c003fa4e2db1 100644 --- a/drivers/firewire/core-iso.c +++ b/drivers/firewire/core-iso.c | |||
@@ -118,6 +118,23 @@ void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, | |||
118 | } | 118 | } |
119 | EXPORT_SYMBOL(fw_iso_buffer_destroy); | 119 | EXPORT_SYMBOL(fw_iso_buffer_destroy); |
120 | 120 | ||
121 | /* Convert DMA address to offset into virtually contiguous buffer. */ | ||
122 | size_t fw_iso_buffer_lookup(struct fw_iso_buffer *buffer, dma_addr_t completed) | ||
123 | { | ||
124 | int i; | ||
125 | dma_addr_t address; | ||
126 | ssize_t offset; | ||
127 | |||
128 | for (i = 0; i < buffer->page_count; i++) { | ||
129 | address = page_private(buffer->pages[i]); | ||
130 | offset = (ssize_t)completed - (ssize_t)address; | ||
131 | if (offset > 0 && offset <= PAGE_SIZE) | ||
132 | return (i << PAGE_SHIFT) + offset; | ||
133 | } | ||
134 | |||
135 | return 0; | ||
136 | } | ||
137 | |||
121 | struct fw_iso_context *fw_iso_context_create(struct fw_card *card, | 138 | struct fw_iso_context *fw_iso_context_create(struct fw_card *card, |
122 | int type, int channel, int speed, size_t header_size, | 139 | int type, int channel, int speed, size_t header_size, |
123 | fw_iso_callback_t callback, void *callback_data) | 140 | fw_iso_callback_t callback, void *callback_data) |
@@ -134,7 +151,7 @@ struct fw_iso_context *fw_iso_context_create(struct fw_card *card, | |||
134 | ctx->channel = channel; | 151 | ctx->channel = channel; |
135 | ctx->speed = speed; | 152 | ctx->speed = speed; |
136 | ctx->header_size = header_size; | 153 | ctx->header_size = header_size; |
137 | ctx->callback = callback; | 154 | ctx->callback.sc = callback; |
138 | ctx->callback_data = callback_data; | 155 | ctx->callback_data = callback_data; |
139 | 156 | ||
140 | return ctx; | 157 | return ctx; |
@@ -143,9 +160,7 @@ EXPORT_SYMBOL(fw_iso_context_create); | |||
143 | 160 | ||
144 | void fw_iso_context_destroy(struct fw_iso_context *ctx) | 161 | void fw_iso_context_destroy(struct fw_iso_context *ctx) |
145 | { | 162 | { |
146 | struct fw_card *card = ctx->card; | 163 | ctx->card->driver->free_iso_context(ctx); |
147 | |||
148 | card->driver->free_iso_context(ctx); | ||
149 | } | 164 | } |
150 | EXPORT_SYMBOL(fw_iso_context_destroy); | 165 | EXPORT_SYMBOL(fw_iso_context_destroy); |
151 | 166 | ||
@@ -156,14 +171,17 @@ int fw_iso_context_start(struct fw_iso_context *ctx, | |||
156 | } | 171 | } |
157 | EXPORT_SYMBOL(fw_iso_context_start); | 172 | EXPORT_SYMBOL(fw_iso_context_start); |
158 | 173 | ||
174 | int fw_iso_context_set_channels(struct fw_iso_context *ctx, u64 *channels) | ||
175 | { | ||
176 | return ctx->card->driver->set_iso_channels(ctx, channels); | ||
177 | } | ||
178 | |||
159 | int fw_iso_context_queue(struct fw_iso_context *ctx, | 179 | int fw_iso_context_queue(struct fw_iso_context *ctx, |
160 | struct fw_iso_packet *packet, | 180 | struct fw_iso_packet *packet, |
161 | struct fw_iso_buffer *buffer, | 181 | struct fw_iso_buffer *buffer, |
162 | unsigned long payload) | 182 | unsigned long payload) |
163 | { | 183 | { |
164 | struct fw_card *card = ctx->card; | 184 | return ctx->card->driver->queue_iso(ctx, packet, buffer, payload); |
165 | |||
166 | return card->driver->queue_iso(ctx, packet, buffer, payload); | ||
167 | } | 185 | } |
168 | EXPORT_SYMBOL(fw_iso_context_queue); | 186 | EXPORT_SYMBOL(fw_iso_context_queue); |
169 | 187 | ||
@@ -279,7 +297,7 @@ static void deallocate_channel(struct fw_card *card, int irm_id, | |||
279 | } | 297 | } |
280 | 298 | ||
281 | /** | 299 | /** |
282 | * fw_iso_resource_manage - Allocate or deallocate a channel and/or bandwidth | 300 | * fw_iso_resource_manage() - Allocate or deallocate a channel and/or bandwidth |
283 | * | 301 | * |
284 | * In parameters: card, generation, channels_mask, bandwidth, allocate | 302 | * In parameters: card, generation, channels_mask, bandwidth, allocate |
285 | * Out parameters: channel, bandwidth | 303 | * Out parameters: channel, bandwidth |
diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topology.c index 93ec64cdeef7..09be1a635505 100644 --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c | |||
@@ -174,12 +174,7 @@ static inline struct fw_node *fw_node(struct list_head *l) | |||
174 | return list_entry(l, struct fw_node, link); | 174 | return list_entry(l, struct fw_node, link); |
175 | } | 175 | } |
176 | 176 | ||
177 | /** | 177 | /* |
178 | * build_tree - Build the tree representation of the topology | ||
179 | * @self_ids: array of self IDs to create the tree from | ||
180 | * @self_id_count: the length of the self_ids array | ||
181 | * @local_id: the node ID of the local node | ||
182 | * | ||
183 | * This function builds the tree representation of the topology given | 178 | * This function builds the tree representation of the topology given |
184 | * by the self IDs from the latest bus reset. During the construction | 179 | * by the self IDs from the latest bus reset. During the construction |
185 | * of the tree, the function checks that the self IDs are valid and | 180 | * of the tree, the function checks that the self IDs are valid and |
@@ -420,11 +415,10 @@ static void move_tree(struct fw_node *node0, struct fw_node *node1, int port) | |||
420 | } | 415 | } |
421 | } | 416 | } |
422 | 417 | ||
423 | /** | 418 | /* |
424 | * update_tree - compare the old topology tree for card with the new | 419 | * Compare the old topology tree for card with the new one specified by root. |
425 | * one specified by root. Queue the nodes and mark them as either | 420 | * Queue the nodes and mark them as either found, lost or updated. |
426 | * found, lost or updated. Update the nodes in the card topology tree | 421 | * Update the nodes in the card topology tree as we go. |
427 | * as we go. | ||
428 | */ | 422 | */ |
429 | static void update_tree(struct fw_card *card, struct fw_node *root) | 423 | static void update_tree(struct fw_card *card, struct fw_node *root) |
430 | { | 424 | { |
@@ -524,7 +518,7 @@ static void update_topology_map(struct fw_card *card, | |||
524 | } | 518 | } |
525 | 519 | ||
526 | void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation, | 520 | void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation, |
527 | int self_id_count, u32 *self_ids) | 521 | int self_id_count, u32 *self_ids, bool bm_abdicate) |
528 | { | 522 | { |
529 | struct fw_node *local_node; | 523 | struct fw_node *local_node; |
530 | unsigned long flags; | 524 | unsigned long flags; |
@@ -543,7 +537,7 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation, | |||
543 | 537 | ||
544 | spin_lock_irqsave(&card->lock, flags); | 538 | spin_lock_irqsave(&card->lock, flags); |
545 | 539 | ||
546 | card->broadcast_channel_allocated = false; | 540 | card->broadcast_channel_allocated = card->broadcast_channel_auto_allocated; |
547 | card->node_id = node_id; | 541 | card->node_id = node_id; |
548 | /* | 542 | /* |
549 | * Update node_id before generation to prevent anybody from using | 543 | * Update node_id before generation to prevent anybody from using |
@@ -552,6 +546,8 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation, | |||
552 | smp_wmb(); | 546 | smp_wmb(); |
553 | card->generation = generation; | 547 | card->generation = generation; |
554 | card->reset_jiffies = jiffies; | 548 | card->reset_jiffies = jiffies; |
549 | card->bm_node_id = 0xffff; | ||
550 | card->bm_abdicate = bm_abdicate; | ||
555 | fw_schedule_bm_work(card, 0); | 551 | fw_schedule_bm_work(card, 0); |
556 | 552 | ||
557 | local_node = build_tree(card, self_ids, self_id_count); | 553 | local_node = build_tree(card, self_ids, self_id_count); |
diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c index 673b03f8b4ec..ca7ca56661e0 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c | |||
@@ -81,7 +81,7 @@ static int close_transaction(struct fw_transaction *transaction, | |||
81 | spin_lock_irqsave(&card->lock, flags); | 81 | spin_lock_irqsave(&card->lock, flags); |
82 | list_for_each_entry(t, &card->transaction_list, link) { | 82 | list_for_each_entry(t, &card->transaction_list, link) { |
83 | if (t == transaction) { | 83 | if (t == transaction) { |
84 | list_del(&t->link); | 84 | list_del_init(&t->link); |
85 | card->tlabel_mask &= ~(1ULL << t->tlabel); | 85 | card->tlabel_mask &= ~(1ULL << t->tlabel); |
86 | break; | 86 | break; |
87 | } | 87 | } |
@@ -89,6 +89,7 @@ static int close_transaction(struct fw_transaction *transaction, | |||
89 | spin_unlock_irqrestore(&card->lock, flags); | 89 | spin_unlock_irqrestore(&card->lock, flags); |
90 | 90 | ||
91 | if (&t->link != &card->transaction_list) { | 91 | if (&t->link != &card->transaction_list) { |
92 | del_timer_sync(&t->split_timeout_timer); | ||
92 | t->callback(card, rcode, NULL, 0, t->callback_data); | 93 | t->callback(card, rcode, NULL, 0, t->callback_data); |
93 | return 0; | 94 | return 0; |
94 | } | 95 | } |
@@ -121,6 +122,31 @@ int fw_cancel_transaction(struct fw_card *card, | |||
121 | } | 122 | } |
122 | EXPORT_SYMBOL(fw_cancel_transaction); | 123 | EXPORT_SYMBOL(fw_cancel_transaction); |
123 | 124 | ||
125 | static void split_transaction_timeout_callback(unsigned long data) | ||
126 | { | ||
127 | struct fw_transaction *t = (struct fw_transaction *)data; | ||
128 | struct fw_card *card = t->card; | ||
129 | unsigned long flags; | ||
130 | |||
131 | spin_lock_irqsave(&card->lock, flags); | ||
132 | if (list_empty(&t->link)) { | ||
133 | spin_unlock_irqrestore(&card->lock, flags); | ||
134 | return; | ||
135 | } | ||
136 | list_del(&t->link); | ||
137 | card->tlabel_mask &= ~(1ULL << t->tlabel); | ||
138 | spin_unlock_irqrestore(&card->lock, flags); | ||
139 | |||
140 | card->driver->cancel_packet(card, &t->packet); | ||
141 | |||
142 | /* | ||
143 | * At this point cancel_packet will never call the transaction | ||
144 | * callback, since we just took the transaction out of the list. | ||
145 | * So do it here. | ||
146 | */ | ||
147 | t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data); | ||
148 | } | ||
149 | |||
124 | static void transmit_complete_callback(struct fw_packet *packet, | 150 | static void transmit_complete_callback(struct fw_packet *packet, |
125 | struct fw_card *card, int status) | 151 | struct fw_card *card, int status) |
126 | { | 152 | { |
@@ -220,7 +246,7 @@ static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel, | |||
220 | break; | 246 | break; |
221 | 247 | ||
222 | default: | 248 | default: |
223 | WARN(1, KERN_ERR "wrong tcode %d", tcode); | 249 | WARN(1, "wrong tcode %d", tcode); |
224 | } | 250 | } |
225 | common: | 251 | common: |
226 | packet->speed = speed; | 252 | packet->speed = speed; |
@@ -229,44 +255,70 @@ static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel, | |||
229 | packet->payload_mapped = false; | 255 | packet->payload_mapped = false; |
230 | } | 256 | } |
231 | 257 | ||
258 | static int allocate_tlabel(struct fw_card *card) | ||
259 | { | ||
260 | int tlabel; | ||
261 | |||
262 | tlabel = card->current_tlabel; | ||
263 | while (card->tlabel_mask & (1ULL << tlabel)) { | ||
264 | tlabel = (tlabel + 1) & 0x3f; | ||
265 | if (tlabel == card->current_tlabel) | ||
266 | return -EBUSY; | ||
267 | } | ||
268 | |||
269 | card->current_tlabel = (tlabel + 1) & 0x3f; | ||
270 | card->tlabel_mask |= 1ULL << tlabel; | ||
271 | |||
272 | return tlabel; | ||
273 | } | ||
274 | |||
232 | /** | 275 | /** |
233 | * This function provides low-level access to the IEEE1394 transaction | 276 | * fw_send_request() - submit a request packet for transmission |
234 | * logic. Most C programs would use either fw_read(), fw_write() or | 277 | * @card: interface to send the request at |
235 | * fw_lock() instead - those function are convenience wrappers for | 278 | * @t: transaction instance to which the request belongs |
236 | * this function. The fw_send_request() function is primarily | 279 | * @tcode: transaction code |
237 | * provided as a flexible, one-stop entry point for languages bindings | 280 | * @destination_id: destination node ID, consisting of bus_ID and phy_ID |
238 | * and protocol bindings. | 281 | * @generation: bus generation in which request and response are valid |
239 | * | 282 | * @speed: transmission speed |
240 | * FIXME: Document this function further, in particular the possible | 283 | * @offset: 48bit wide offset into destination's address space |
241 | * values for rcode in the callback. In short, we map ACK_COMPLETE to | 284 | * @payload: data payload for the request subaction |
242 | * RCODE_COMPLETE, internal errors set errno and set rcode to | 285 | * @length: length of the payload, in bytes |
243 | * RCODE_SEND_ERROR (which is out of range for standard ieee1394 | 286 | * @callback: function to be called when the transaction is completed |
244 | * rcodes). All other rcodes are forwarded unchanged. For all | 287 | * @callback_data: data to be passed to the transaction completion callback |
245 | * errors, payload is NULL, length is 0. | ||
246 | * | 288 | * |
247 | * Can not expect the callback to be called before the function | 289 | * Submit a request packet into the asynchronous request transmission queue. |
248 | * returns, though this does happen in some cases (ACK_COMPLETE and | 290 | * Can be called from atomic context. If you prefer a blocking API, use |
249 | * errors). | 291 | * fw_run_transaction() in a context that can sleep. |
250 | * | 292 | * |
251 | * The payload is only used for write requests and must not be freed | 293 | * In case of lock requests, specify one of the firewire-core specific %TCODE_ |
252 | * until the callback has been called. | 294 | * constants instead of %TCODE_LOCK_REQUEST in @tcode. |
253 | * | 295 | * |
254 | * @param card the card from which to send the request | 296 | * Make sure that the value in @destination_id is not older than the one in |
255 | * @param tcode the tcode for this transaction. Do not use | 297 | * @generation. Otherwise the request is in danger to be sent to a wrong node. |
256 | * TCODE_LOCK_REQUEST directly, instead use TCODE_LOCK_MASK_SWAP | ||
257 | * etc. to specify tcode and ext_tcode. | ||
258 | * @param node_id the destination node ID (bus ID and PHY ID concatenated) | ||
259 | * @param generation the generation for which node_id is valid | ||
260 | * @param speed the speed to use for sending the request | ||
261 | * @param offset the 48 bit offset on the destination node | ||
262 | * @param payload the data payload for the request subaction | ||
263 | * @param length the length in bytes of the data to read | ||
264 | * @param callback function to be called when the transaction is completed | ||
265 | * @param callback_data pointer to arbitrary data, which will be | ||
266 | * passed to the callback | ||
267 | * | 298 | * |
268 | * In case of asynchronous stream packets i.e. TCODE_STREAM_DATA, the caller | 299 | * In case of asynchronous stream packets i.e. %TCODE_STREAM_DATA, the caller |
269 | * needs to synthesize @destination_id with fw_stream_packet_destination_id(). | 300 | * needs to synthesize @destination_id with fw_stream_packet_destination_id(). |
301 | * It will contain tag, channel, and sy data instead of a node ID then. | ||
302 | * | ||
303 | * The payload buffer at @data is going to be DMA-mapped except in case of | ||
304 | * quadlet-sized payload or of local (loopback) requests. Hence make sure that | ||
305 | * the buffer complies with the restrictions for DMA-mapped memory. The | ||
306 | * @payload must not be freed before the @callback is called. | ||
307 | * | ||
308 | * In case of request types without payload, @data is NULL and @length is 0. | ||
309 | * | ||
310 | * After the transaction is completed successfully or unsuccessfully, the | ||
311 | * @callback will be called. Among its parameters is the response code which | ||
312 | * is either one of the rcodes per IEEE 1394 or, in case of internal errors, | ||
313 | * the firewire-core specific %RCODE_SEND_ERROR. The other firewire-core | ||
314 | * specific rcodes (%RCODE_CANCELLED, %RCODE_BUSY, %RCODE_GENERATION, | ||
315 | * %RCODE_NO_ACK) denote transaction timeout, busy responder, stale request | ||
316 | * generation, or missing ACK respectively. | ||
317 | * | ||
318 | * Note some timing corner cases: fw_send_request() may complete much earlier | ||
319 | * than when the request packet actually hits the wire. On the other hand, | ||
320 | * transaction completion and hence execution of @callback may happen even | ||
321 | * before fw_send_request() returns. | ||
270 | */ | 322 | */ |
271 | void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, | 323 | void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, |
272 | int destination_id, int generation, int speed, | 324 | int destination_id, int generation, int speed, |
@@ -277,31 +329,27 @@ void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, | |||
277 | int tlabel; | 329 | int tlabel; |
278 | 330 | ||
279 | /* | 331 | /* |
280 | * Bump the flush timer up 100ms first of all so we | ||
281 | * don't race with a flush timer callback. | ||
282 | */ | ||
283 | |||
284 | mod_timer(&card->flush_timer, jiffies + DIV_ROUND_UP(HZ, 10)); | ||
285 | |||
286 | /* | ||
287 | * Allocate tlabel from the bitmap and put the transaction on | 332 | * Allocate tlabel from the bitmap and put the transaction on |
288 | * the list while holding the card spinlock. | 333 | * the list while holding the card spinlock. |
289 | */ | 334 | */ |
290 | 335 | ||
291 | spin_lock_irqsave(&card->lock, flags); | 336 | spin_lock_irqsave(&card->lock, flags); |
292 | 337 | ||
293 | tlabel = card->current_tlabel; | 338 | tlabel = allocate_tlabel(card); |
294 | if (card->tlabel_mask & (1ULL << tlabel)) { | 339 | if (tlabel < 0) { |
295 | spin_unlock_irqrestore(&card->lock, flags); | 340 | spin_unlock_irqrestore(&card->lock, flags); |
296 | callback(card, RCODE_SEND_ERROR, NULL, 0, callback_data); | 341 | callback(card, RCODE_SEND_ERROR, NULL, 0, callback_data); |
297 | return; | 342 | return; |
298 | } | 343 | } |
299 | 344 | ||
300 | card->current_tlabel = (card->current_tlabel + 1) & 0x3f; | ||
301 | card->tlabel_mask |= (1ULL << tlabel); | ||
302 | |||
303 | t->node_id = destination_id; | 345 | t->node_id = destination_id; |
304 | t->tlabel = tlabel; | 346 | t->tlabel = tlabel; |
347 | t->card = card; | ||
348 | setup_timer(&t->split_timeout_timer, | ||
349 | split_transaction_timeout_callback, (unsigned long)t); | ||
350 | /* FIXME: start this timer later, relative to t->timestamp */ | ||
351 | mod_timer(&t->split_timeout_timer, | ||
352 | jiffies + card->split_timeout_jiffies); | ||
305 | t->callback = callback; | 353 | t->callback = callback; |
306 | t->callback_data = callback_data; | 354 | t->callback_data = callback_data; |
307 | 355 | ||
@@ -336,9 +384,11 @@ static void transaction_callback(struct fw_card *card, int rcode, | |||
336 | } | 384 | } |
337 | 385 | ||
338 | /** | 386 | /** |
339 | * fw_run_transaction - send request and sleep until transaction is completed | 387 | * fw_run_transaction() - send request and sleep until transaction is completed |
340 | * | 388 | * |
341 | * Returns the RCODE. | 389 | * Returns the RCODE. See fw_send_request() for parameter documentation. |
390 | * Unlike fw_send_request(), @data points to the payload of the request or/and | ||
391 | * to the payload of the response. | ||
342 | */ | 392 | */ |
343 | int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, | 393 | int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, |
344 | int generation, int speed, unsigned long long offset, | 394 | int generation, int speed, unsigned long long offset, |
@@ -347,11 +397,13 @@ int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, | |||
347 | struct transaction_callback_data d; | 397 | struct transaction_callback_data d; |
348 | struct fw_transaction t; | 398 | struct fw_transaction t; |
349 | 399 | ||
400 | init_timer_on_stack(&t.split_timeout_timer); | ||
350 | init_completion(&d.done); | 401 | init_completion(&d.done); |
351 | d.payload = payload; | 402 | d.payload = payload; |
352 | fw_send_request(card, &t, tcode, destination_id, generation, speed, | 403 | fw_send_request(card, &t, tcode, destination_id, generation, speed, |
353 | offset, payload, length, transaction_callback, &d); | 404 | offset, payload, length, transaction_callback, &d); |
354 | wait_for_completion(&d.done); | 405 | wait_for_completion(&d.done); |
406 | destroy_timer_on_stack(&t.split_timeout_timer); | ||
355 | 407 | ||
356 | return d.rcode; | 408 | return d.rcode; |
357 | } | 409 | } |
@@ -377,9 +429,21 @@ void fw_send_phy_config(struct fw_card *card, | |||
377 | int node_id, int generation, int gap_count) | 429 | int node_id, int generation, int gap_count) |
378 | { | 430 | { |
379 | long timeout = DIV_ROUND_UP(HZ, 10); | 431 | long timeout = DIV_ROUND_UP(HZ, 10); |
380 | u32 data = PHY_IDENTIFIER(PHY_PACKET_CONFIG) | | 432 | u32 data = PHY_IDENTIFIER(PHY_PACKET_CONFIG); |
381 | PHY_CONFIG_ROOT_ID(node_id) | | 433 | |
382 | PHY_CONFIG_GAP_COUNT(gap_count); | 434 | if (node_id != FW_PHY_CONFIG_NO_NODE_ID) |
435 | data |= PHY_CONFIG_ROOT_ID(node_id); | ||
436 | |||
437 | if (gap_count == FW_PHY_CONFIG_CURRENT_GAP_COUNT) { | ||
438 | gap_count = card->driver->read_phy_reg(card, 1); | ||
439 | if (gap_count < 0) | ||
440 | return; | ||
441 | |||
442 | gap_count &= 63; | ||
443 | if (gap_count == 63) | ||
444 | return; | ||
445 | } | ||
446 | data |= PHY_CONFIG_GAP_COUNT(gap_count); | ||
383 | 447 | ||
384 | mutex_lock(&phy_config_mutex); | 448 | mutex_lock(&phy_config_mutex); |
385 | 449 | ||
@@ -394,30 +458,6 @@ void fw_send_phy_config(struct fw_card *card, | |||
394 | mutex_unlock(&phy_config_mutex); | 458 | mutex_unlock(&phy_config_mutex); |
395 | } | 459 | } |
396 | 460 | ||
397 | void fw_flush_transactions(struct fw_card *card) | ||
398 | { | ||
399 | struct fw_transaction *t, *next; | ||
400 | struct list_head list; | ||
401 | unsigned long flags; | ||
402 | |||
403 | INIT_LIST_HEAD(&list); | ||
404 | spin_lock_irqsave(&card->lock, flags); | ||
405 | list_splice_init(&card->transaction_list, &list); | ||
406 | card->tlabel_mask = 0; | ||
407 | spin_unlock_irqrestore(&card->lock, flags); | ||
408 | |||
409 | list_for_each_entry_safe(t, next, &list, link) { | ||
410 | card->driver->cancel_packet(card, &t->packet); | ||
411 | |||
412 | /* | ||
413 | * At this point cancel_packet will never call the | ||
414 | * transaction callback, since we just took all the | ||
415 | * transactions out of the list. So do it here. | ||
416 | */ | ||
417 | t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data); | ||
418 | } | ||
419 | } | ||
420 | |||
421 | static struct fw_address_handler *lookup_overlapping_address_handler( | 461 | static struct fw_address_handler *lookup_overlapping_address_handler( |
422 | struct list_head *list, unsigned long long offset, size_t length) | 462 | struct list_head *list, unsigned long long offset, size_t length) |
423 | { | 463 | { |
@@ -478,9 +518,9 @@ static bool is_in_fcp_region(u64 offset, size_t length) | |||
478 | } | 518 | } |
479 | 519 | ||
480 | /** | 520 | /** |
481 | * fw_core_add_address_handler - register for incoming requests | 521 | * fw_core_add_address_handler() - register for incoming requests |
482 | * @handler: callback | 522 | * @handler: callback |
483 | * @region: region in the IEEE 1212 node space address range | 523 | * @region: region in the IEEE 1212 node space address range |
484 | * | 524 | * |
485 | * region->start, ->end, and handler->length have to be quadlet-aligned. | 525 | * region->start, ->end, and handler->length have to be quadlet-aligned. |
486 | * | 526 | * |
@@ -503,8 +543,8 @@ int fw_core_add_address_handler(struct fw_address_handler *handler, | |||
503 | int ret = -EBUSY; | 543 | int ret = -EBUSY; |
504 | 544 | ||
505 | if (region->start & 0xffff000000000003ULL || | 545 | if (region->start & 0xffff000000000003ULL || |
506 | region->end & 0xffff000000000003ULL || | ||
507 | region->start >= region->end || | 546 | region->start >= region->end || |
547 | region->end > 0x0001000000000000ULL || | ||
508 | handler->length & 3 || | 548 | handler->length & 3 || |
509 | handler->length == 0) | 549 | handler->length == 0) |
510 | return -EINVAL; | 550 | return -EINVAL; |
@@ -535,7 +575,7 @@ int fw_core_add_address_handler(struct fw_address_handler *handler, | |||
535 | EXPORT_SYMBOL(fw_core_add_address_handler); | 575 | EXPORT_SYMBOL(fw_core_add_address_handler); |
536 | 576 | ||
537 | /** | 577 | /** |
538 | * fw_core_remove_address_handler - unregister an address handler | 578 | * fw_core_remove_address_handler() - unregister an address handler |
539 | */ | 579 | */ |
540 | void fw_core_remove_address_handler(struct fw_address_handler *handler) | 580 | void fw_core_remove_address_handler(struct fw_address_handler *handler) |
541 | { | 581 | { |
@@ -564,6 +604,41 @@ static void free_response_callback(struct fw_packet *packet, | |||
564 | kfree(request); | 604 | kfree(request); |
565 | } | 605 | } |
566 | 606 | ||
607 | int fw_get_response_length(struct fw_request *r) | ||
608 | { | ||
609 | int tcode, ext_tcode, data_length; | ||
610 | |||
611 | tcode = HEADER_GET_TCODE(r->request_header[0]); | ||
612 | |||
613 | switch (tcode) { | ||
614 | case TCODE_WRITE_QUADLET_REQUEST: | ||
615 | case TCODE_WRITE_BLOCK_REQUEST: | ||
616 | return 0; | ||
617 | |||
618 | case TCODE_READ_QUADLET_REQUEST: | ||
619 | return 4; | ||
620 | |||
621 | case TCODE_READ_BLOCK_REQUEST: | ||
622 | data_length = HEADER_GET_DATA_LENGTH(r->request_header[3]); | ||
623 | return data_length; | ||
624 | |||
625 | case TCODE_LOCK_REQUEST: | ||
626 | ext_tcode = HEADER_GET_EXTENDED_TCODE(r->request_header[3]); | ||
627 | data_length = HEADER_GET_DATA_LENGTH(r->request_header[3]); | ||
628 | switch (ext_tcode) { | ||
629 | case EXTCODE_FETCH_ADD: | ||
630 | case EXTCODE_LITTLE_ADD: | ||
631 | return data_length; | ||
632 | default: | ||
633 | return data_length / 2; | ||
634 | } | ||
635 | |||
636 | default: | ||
637 | WARN(1, "wrong tcode %d", tcode); | ||
638 | return 0; | ||
639 | } | ||
640 | } | ||
641 | |||
567 | void fw_fill_response(struct fw_packet *response, u32 *request_header, | 642 | void fw_fill_response(struct fw_packet *response, u32 *request_header, |
568 | int rcode, void *payload, size_t length) | 643 | int rcode, void *payload, size_t length) |
569 | { | 644 | { |
@@ -615,18 +690,35 @@ void fw_fill_response(struct fw_packet *response, u32 *request_header, | |||
615 | break; | 690 | break; |
616 | 691 | ||
617 | default: | 692 | default: |
618 | WARN(1, KERN_ERR "wrong tcode %d", tcode); | 693 | WARN(1, "wrong tcode %d", tcode); |
619 | } | 694 | } |
620 | 695 | ||
621 | response->payload_mapped = false; | 696 | response->payload_mapped = false; |
622 | } | 697 | } |
623 | EXPORT_SYMBOL(fw_fill_response); | 698 | EXPORT_SYMBOL(fw_fill_response); |
624 | 699 | ||
625 | static struct fw_request *allocate_request(struct fw_packet *p) | 700 | static u32 compute_split_timeout_timestamp(struct fw_card *card, |
701 | u32 request_timestamp) | ||
702 | { | ||
703 | unsigned int cycles; | ||
704 | u32 timestamp; | ||
705 | |||
706 | cycles = card->split_timeout_cycles; | ||
707 | cycles += request_timestamp & 0x1fff; | ||
708 | |||
709 | timestamp = request_timestamp & ~0x1fff; | ||
710 | timestamp += (cycles / 8000) << 13; | ||
711 | timestamp |= cycles % 8000; | ||
712 | |||
713 | return timestamp; | ||
714 | } | ||
715 | |||
716 | static struct fw_request *allocate_request(struct fw_card *card, | ||
717 | struct fw_packet *p) | ||
626 | { | 718 | { |
627 | struct fw_request *request; | 719 | struct fw_request *request; |
628 | u32 *data, length; | 720 | u32 *data, length; |
629 | int request_tcode, t; | 721 | int request_tcode; |
630 | 722 | ||
631 | request_tcode = HEADER_GET_TCODE(p->header[0]); | 723 | request_tcode = HEADER_GET_TCODE(p->header[0]); |
632 | switch (request_tcode) { | 724 | switch (request_tcode) { |
@@ -661,14 +753,9 @@ static struct fw_request *allocate_request(struct fw_packet *p) | |||
661 | if (request == NULL) | 753 | if (request == NULL) |
662 | return NULL; | 754 | return NULL; |
663 | 755 | ||
664 | t = (p->timestamp & 0x1fff) + 4000; | ||
665 | if (t >= 8000) | ||
666 | t = (p->timestamp & ~0x1fff) + 0x2000 + t - 8000; | ||
667 | else | ||
668 | t = (p->timestamp & ~0x1fff) + t; | ||
669 | |||
670 | request->response.speed = p->speed; | 756 | request->response.speed = p->speed; |
671 | request->response.timestamp = t; | 757 | request->response.timestamp = |
758 | compute_split_timeout_timestamp(card, p->timestamp); | ||
672 | request->response.generation = p->generation; | 759 | request->response.generation = p->generation; |
673 | request->response.ack = 0; | 760 | request->response.ack = 0; |
674 | request->response.callback = free_response_callback; | 761 | request->response.callback = free_response_callback; |
@@ -697,7 +784,8 @@ void fw_send_response(struct fw_card *card, | |||
697 | 784 | ||
698 | if (rcode == RCODE_COMPLETE) | 785 | if (rcode == RCODE_COMPLETE) |
699 | fw_fill_response(&request->response, request->request_header, | 786 | fw_fill_response(&request->response, request->request_header, |
700 | rcode, request->data, request->length); | 787 | rcode, request->data, |
788 | fw_get_response_length(request)); | ||
701 | else | 789 | else |
702 | fw_fill_response(&request->response, request->request_header, | 790 | fw_fill_response(&request->response, request->request_header, |
703 | rcode, NULL, 0); | 791 | rcode, NULL, 0); |
@@ -715,9 +803,11 @@ static void handle_exclusive_region_request(struct fw_card *card, | |||
715 | unsigned long flags; | 803 | unsigned long flags; |
716 | int tcode, destination, source; | 804 | int tcode, destination, source; |
717 | 805 | ||
718 | tcode = HEADER_GET_TCODE(p->header[0]); | ||
719 | destination = HEADER_GET_DESTINATION(p->header[0]); | 806 | destination = HEADER_GET_DESTINATION(p->header[0]); |
720 | source = HEADER_GET_SOURCE(p->header[1]); | 807 | source = HEADER_GET_SOURCE(p->header[1]); |
808 | tcode = HEADER_GET_TCODE(p->header[0]); | ||
809 | if (tcode == TCODE_LOCK_REQUEST) | ||
810 | tcode = 0x10 + HEADER_GET_EXTENDED_TCODE(p->header[3]); | ||
721 | 811 | ||
722 | spin_lock_irqsave(&address_handler_lock, flags); | 812 | spin_lock_irqsave(&address_handler_lock, flags); |
723 | handler = lookup_enclosing_address_handler(&address_handler_list, | 813 | handler = lookup_enclosing_address_handler(&address_handler_list, |
@@ -737,7 +827,7 @@ static void handle_exclusive_region_request(struct fw_card *card, | |||
737 | else | 827 | else |
738 | handler->address_callback(card, request, | 828 | handler->address_callback(card, request, |
739 | tcode, destination, source, | 829 | tcode, destination, source, |
740 | p->generation, p->speed, offset, | 830 | p->generation, offset, |
741 | request->data, request->length, | 831 | request->data, request->length, |
742 | handler->callback_data); | 832 | handler->callback_data); |
743 | } | 833 | } |
@@ -775,8 +865,8 @@ static void handle_fcp_region_request(struct fw_card *card, | |||
775 | if (is_enclosing_handler(handler, offset, request->length)) | 865 | if (is_enclosing_handler(handler, offset, request->length)) |
776 | handler->address_callback(card, NULL, tcode, | 866 | handler->address_callback(card, NULL, tcode, |
777 | destination, source, | 867 | destination, source, |
778 | p->generation, p->speed, | 868 | p->generation, offset, |
779 | offset, request->data, | 869 | request->data, |
780 | request->length, | 870 | request->length, |
781 | handler->callback_data); | 871 | handler->callback_data); |
782 | } | 872 | } |
@@ -793,7 +883,12 @@ void fw_core_handle_request(struct fw_card *card, struct fw_packet *p) | |||
793 | if (p->ack != ACK_PENDING && p->ack != ACK_COMPLETE) | 883 | if (p->ack != ACK_PENDING && p->ack != ACK_COMPLETE) |
794 | return; | 884 | return; |
795 | 885 | ||
796 | request = allocate_request(p); | 886 | if (TCODE_IS_LINK_INTERNAL(HEADER_GET_TCODE(p->header[0]))) { |
887 | fw_cdev_handle_phy_packet(card, p); | ||
888 | return; | ||
889 | } | ||
890 | |||
891 | request = allocate_request(card, p); | ||
797 | if (request == NULL) { | 892 | if (request == NULL) { |
798 | /* FIXME: send statically allocated busy packet. */ | 893 | /* FIXME: send statically allocated busy packet. */ |
799 | return; | 894 | return; |
@@ -816,19 +911,18 @@ void fw_core_handle_response(struct fw_card *card, struct fw_packet *p) | |||
816 | unsigned long flags; | 911 | unsigned long flags; |
817 | u32 *data; | 912 | u32 *data; |
818 | size_t data_length; | 913 | size_t data_length; |
819 | int tcode, tlabel, destination, source, rcode; | 914 | int tcode, tlabel, source, rcode; |
820 | 915 | ||
821 | tcode = HEADER_GET_TCODE(p->header[0]); | 916 | tcode = HEADER_GET_TCODE(p->header[0]); |
822 | tlabel = HEADER_GET_TLABEL(p->header[0]); | 917 | tlabel = HEADER_GET_TLABEL(p->header[0]); |
823 | destination = HEADER_GET_DESTINATION(p->header[0]); | 918 | source = HEADER_GET_SOURCE(p->header[1]); |
824 | source = HEADER_GET_SOURCE(p->header[1]); | 919 | rcode = HEADER_GET_RCODE(p->header[1]); |
825 | rcode = HEADER_GET_RCODE(p->header[1]); | ||
826 | 920 | ||
827 | spin_lock_irqsave(&card->lock, flags); | 921 | spin_lock_irqsave(&card->lock, flags); |
828 | list_for_each_entry(t, &card->transaction_list, link) { | 922 | list_for_each_entry(t, &card->transaction_list, link) { |
829 | if (t->node_id == source && t->tlabel == tlabel) { | 923 | if (t->node_id == source && t->tlabel == tlabel) { |
830 | list_del(&t->link); | 924 | list_del_init(&t->link); |
831 | card->tlabel_mask &= ~(1 << t->tlabel); | 925 | card->tlabel_mask &= ~(1ULL << t->tlabel); |
832 | break; | 926 | break; |
833 | } | 927 | } |
834 | } | 928 | } |
@@ -869,6 +963,8 @@ void fw_core_handle_response(struct fw_card *card, struct fw_packet *p) | |||
869 | break; | 963 | break; |
870 | } | 964 | } |
871 | 965 | ||
966 | del_timer_sync(&t->split_timeout_timer); | ||
967 | |||
872 | /* | 968 | /* |
873 | * The response handler may be executed while the request handler | 969 | * The response handler may be executed while the request handler |
874 | * is still pending. Cancel the request handler. | 970 | * is still pending. Cancel the request handler. |
@@ -885,8 +981,8 @@ static const struct fw_address_region topology_map_region = | |||
885 | 981 | ||
886 | static void handle_topology_map(struct fw_card *card, struct fw_request *request, | 982 | static void handle_topology_map(struct fw_card *card, struct fw_request *request, |
887 | int tcode, int destination, int source, int generation, | 983 | int tcode, int destination, int source, int generation, |
888 | int speed, unsigned long long offset, | 984 | unsigned long long offset, void *payload, size_t length, |
889 | void *payload, size_t length, void *callback_data) | 985 | void *callback_data) |
890 | { | 986 | { |
891 | int start; | 987 | int start; |
892 | 988 | ||
@@ -915,19 +1011,97 @@ static const struct fw_address_region registers_region = | |||
915 | { .start = CSR_REGISTER_BASE, | 1011 | { .start = CSR_REGISTER_BASE, |
916 | .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM, }; | 1012 | .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM, }; |
917 | 1013 | ||
1014 | static void update_split_timeout(struct fw_card *card) | ||
1015 | { | ||
1016 | unsigned int cycles; | ||
1017 | |||
1018 | cycles = card->split_timeout_hi * 8000 + (card->split_timeout_lo >> 19); | ||
1019 | |||
1020 | cycles = max(cycles, 800u); /* minimum as per the spec */ | ||
1021 | cycles = min(cycles, 3u * 8000u); /* maximum OHCI timeout */ | ||
1022 | |||
1023 | card->split_timeout_cycles = cycles; | ||
1024 | card->split_timeout_jiffies = DIV_ROUND_UP(cycles * HZ, 8000); | ||
1025 | } | ||
1026 | |||
918 | static void handle_registers(struct fw_card *card, struct fw_request *request, | 1027 | static void handle_registers(struct fw_card *card, struct fw_request *request, |
919 | int tcode, int destination, int source, int generation, | 1028 | int tcode, int destination, int source, int generation, |
920 | int speed, unsigned long long offset, | 1029 | unsigned long long offset, void *payload, size_t length, |
921 | void *payload, size_t length, void *callback_data) | 1030 | void *callback_data) |
922 | { | 1031 | { |
923 | int reg = offset & ~CSR_REGISTER_BASE; | 1032 | int reg = offset & ~CSR_REGISTER_BASE; |
924 | __be32 *data = payload; | 1033 | __be32 *data = payload; |
925 | int rcode = RCODE_COMPLETE; | 1034 | int rcode = RCODE_COMPLETE; |
1035 | unsigned long flags; | ||
926 | 1036 | ||
927 | switch (reg) { | 1037 | switch (reg) { |
1038 | case CSR_PRIORITY_BUDGET: | ||
1039 | if (!card->priority_budget_implemented) { | ||
1040 | rcode = RCODE_ADDRESS_ERROR; | ||
1041 | break; | ||
1042 | } | ||
1043 | /* else fall through */ | ||
1044 | |||
1045 | case CSR_NODE_IDS: | ||
1046 | /* | ||
1047 | * per IEEE 1394-2008 8.3.22.3, not IEEE 1394.1-2004 3.2.8 | ||
1048 | * and 9.6, but interoperable with IEEE 1394.1-2004 bridges | ||
1049 | */ | ||
1050 | /* fall through */ | ||
1051 | |||
1052 | case CSR_STATE_CLEAR: | ||
1053 | case CSR_STATE_SET: | ||
928 | case CSR_CYCLE_TIME: | 1054 | case CSR_CYCLE_TIME: |
929 | if (TCODE_IS_READ_REQUEST(tcode) && length == 4) | 1055 | case CSR_BUS_TIME: |
930 | *data = cpu_to_be32(card->driver->get_cycle_time(card)); | 1056 | case CSR_BUSY_TIMEOUT: |
1057 | if (tcode == TCODE_READ_QUADLET_REQUEST) | ||
1058 | *data = cpu_to_be32(card->driver->read_csr(card, reg)); | ||
1059 | else if (tcode == TCODE_WRITE_QUADLET_REQUEST) | ||
1060 | card->driver->write_csr(card, reg, be32_to_cpu(*data)); | ||
1061 | else | ||
1062 | rcode = RCODE_TYPE_ERROR; | ||
1063 | break; | ||
1064 | |||
1065 | case CSR_RESET_START: | ||
1066 | if (tcode == TCODE_WRITE_QUADLET_REQUEST) | ||
1067 | card->driver->write_csr(card, CSR_STATE_CLEAR, | ||
1068 | CSR_STATE_BIT_ABDICATE); | ||
1069 | else | ||
1070 | rcode = RCODE_TYPE_ERROR; | ||
1071 | break; | ||
1072 | |||
1073 | case CSR_SPLIT_TIMEOUT_HI: | ||
1074 | if (tcode == TCODE_READ_QUADLET_REQUEST) { | ||
1075 | *data = cpu_to_be32(card->split_timeout_hi); | ||
1076 | } else if (tcode == TCODE_WRITE_QUADLET_REQUEST) { | ||
1077 | spin_lock_irqsave(&card->lock, flags); | ||
1078 | card->split_timeout_hi = be32_to_cpu(*data) & 7; | ||
1079 | update_split_timeout(card); | ||
1080 | spin_unlock_irqrestore(&card->lock, flags); | ||
1081 | } else { | ||
1082 | rcode = RCODE_TYPE_ERROR; | ||
1083 | } | ||
1084 | break; | ||
1085 | |||
1086 | case CSR_SPLIT_TIMEOUT_LO: | ||
1087 | if (tcode == TCODE_READ_QUADLET_REQUEST) { | ||
1088 | *data = cpu_to_be32(card->split_timeout_lo); | ||
1089 | } else if (tcode == TCODE_WRITE_QUADLET_REQUEST) { | ||
1090 | spin_lock_irqsave(&card->lock, flags); | ||
1091 | card->split_timeout_lo = | ||
1092 | be32_to_cpu(*data) & 0xfff80000; | ||
1093 | update_split_timeout(card); | ||
1094 | spin_unlock_irqrestore(&card->lock, flags); | ||
1095 | } else { | ||
1096 | rcode = RCODE_TYPE_ERROR; | ||
1097 | } | ||
1098 | break; | ||
1099 | |||
1100 | case CSR_MAINT_UTILITY: | ||
1101 | if (tcode == TCODE_READ_QUADLET_REQUEST) | ||
1102 | *data = card->maint_utility_register; | ||
1103 | else if (tcode == TCODE_WRITE_QUADLET_REQUEST) | ||
1104 | card->maint_utility_register = *data; | ||
931 | else | 1105 | else |
932 | rcode = RCODE_TYPE_ERROR; | 1106 | rcode = RCODE_TYPE_ERROR; |
933 | break; | 1107 | break; |
@@ -957,12 +1131,6 @@ static void handle_registers(struct fw_card *card, struct fw_request *request, | |||
957 | BUG(); | 1131 | BUG(); |
958 | break; | 1132 | break; |
959 | 1133 | ||
960 | case CSR_BUSY_TIMEOUT: | ||
961 | /* FIXME: Implement this. */ | ||
962 | |||
963 | case CSR_BUS_TIME: | ||
964 | /* Useless without initialization by the bus manager. */ | ||
965 | |||
966 | default: | 1134 | default: |
967 | rcode = RCODE_ADDRESS_ERROR; | 1135 | rcode = RCODE_ADDRESS_ERROR; |
968 | break; | 1136 | break; |
diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index fb0321300cce..e6239f971be6 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h | |||
@@ -27,12 +27,20 @@ struct fw_packet; | |||
27 | #define PHY_LINK_ACTIVE 0x80 | 27 | #define PHY_LINK_ACTIVE 0x80 |
28 | #define PHY_CONTENDER 0x40 | 28 | #define PHY_CONTENDER 0x40 |
29 | #define PHY_BUS_RESET 0x40 | 29 | #define PHY_BUS_RESET 0x40 |
30 | #define PHY_EXTENDED_REGISTERS 0xe0 | ||
30 | #define PHY_BUS_SHORT_RESET 0x40 | 31 | #define PHY_BUS_SHORT_RESET 0x40 |
32 | #define PHY_INT_STATUS_BITS 0x3c | ||
33 | #define PHY_ENABLE_ACCEL 0x02 | ||
34 | #define PHY_ENABLE_MULTI 0x01 | ||
35 | #define PHY_PAGE_SELECT 0xe0 | ||
31 | 36 | ||
32 | #define BANDWIDTH_AVAILABLE_INITIAL 4915 | 37 | #define BANDWIDTH_AVAILABLE_INITIAL 4915 |
33 | #define BROADCAST_CHANNEL_INITIAL (1 << 31 | 31) | 38 | #define BROADCAST_CHANNEL_INITIAL (1 << 31 | 31) |
34 | #define BROADCAST_CHANNEL_VALID (1 << 30) | 39 | #define BROADCAST_CHANNEL_VALID (1 << 30) |
35 | 40 | ||
41 | #define CSR_STATE_BIT_CMSTR (1 << 8) | ||
42 | #define CSR_STATE_BIT_ABDICATE (1 << 10) | ||
43 | |||
36 | struct fw_card_driver { | 44 | struct fw_card_driver { |
37 | /* | 45 | /* |
38 | * Enable the given card with the given initial config rom. | 46 | * Enable the given card with the given initial config rom. |
@@ -43,6 +51,7 @@ struct fw_card_driver { | |||
43 | int (*enable)(struct fw_card *card, | 51 | int (*enable)(struct fw_card *card, |
44 | const __be32 *config_rom, size_t length); | 52 | const __be32 *config_rom, size_t length); |
45 | 53 | ||
54 | int (*read_phy_reg)(struct fw_card *card, int address); | ||
46 | int (*update_phy_reg)(struct fw_card *card, int address, | 55 | int (*update_phy_reg)(struct fw_card *card, int address, |
47 | int clear_bits, int set_bits); | 56 | int clear_bits, int set_bits); |
48 | 57 | ||
@@ -70,7 +79,8 @@ struct fw_card_driver { | |||
70 | int (*enable_phys_dma)(struct fw_card *card, | 79 | int (*enable_phys_dma)(struct fw_card *card, |
71 | int node_id, int generation); | 80 | int node_id, int generation); |
72 | 81 | ||
73 | u32 (*get_cycle_time)(struct fw_card *card); | 82 | u32 (*read_csr)(struct fw_card *card, int csr_offset); |
83 | void (*write_csr)(struct fw_card *card, int csr_offset, u32 value); | ||
74 | 84 | ||
75 | struct fw_iso_context * | 85 | struct fw_iso_context * |
76 | (*allocate_iso_context)(struct fw_card *card, | 86 | (*allocate_iso_context)(struct fw_card *card, |
@@ -80,6 +90,8 @@ struct fw_card_driver { | |||
80 | int (*start_iso)(struct fw_iso_context *ctx, | 90 | int (*start_iso)(struct fw_iso_context *ctx, |
81 | s32 cycle, u32 sync, u32 tags); | 91 | s32 cycle, u32 sync, u32 tags); |
82 | 92 | ||
93 | int (*set_iso_channels)(struct fw_iso_context *ctx, u64 *channels); | ||
94 | |||
83 | int (*queue_iso)(struct fw_iso_context *ctx, | 95 | int (*queue_iso)(struct fw_iso_context *ctx, |
84 | struct fw_iso_packet *packet, | 96 | struct fw_iso_packet *packet, |
85 | struct fw_iso_buffer *buffer, | 97 | struct fw_iso_buffer *buffer, |
@@ -93,8 +105,8 @@ void fw_card_initialize(struct fw_card *card, | |||
93 | int fw_card_add(struct fw_card *card, | 105 | int fw_card_add(struct fw_card *card, |
94 | u32 max_receive, u32 link_speed, u64 guid); | 106 | u32 max_receive, u32 link_speed, u64 guid); |
95 | void fw_core_remove_card(struct fw_card *card); | 107 | void fw_core_remove_card(struct fw_card *card); |
96 | int fw_core_initiate_bus_reset(struct fw_card *card, int short_reset); | ||
97 | int fw_compute_block_crc(__be32 *block); | 108 | int fw_compute_block_crc(__be32 *block); |
109 | void fw_schedule_bus_reset(struct fw_card *card, bool delayed, bool short_reset); | ||
98 | void fw_schedule_bm_work(struct fw_card *card, unsigned long delay); | 110 | void fw_schedule_bm_work(struct fw_card *card, unsigned long delay); |
99 | 111 | ||
100 | static inline struct fw_card *fw_card_get(struct fw_card *card) | 112 | static inline struct fw_card *fw_card_get(struct fw_card *card) |
@@ -118,6 +130,7 @@ extern const struct file_operations fw_device_ops; | |||
118 | 130 | ||
119 | void fw_device_cdev_update(struct fw_device *device); | 131 | void fw_device_cdev_update(struct fw_device *device); |
120 | void fw_device_cdev_remove(struct fw_device *device); | 132 | void fw_device_cdev_remove(struct fw_device *device); |
133 | void fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p); | ||
121 | 134 | ||
122 | 135 | ||
123 | /* -device */ | 136 | /* -device */ |
@@ -187,7 +200,7 @@ static inline void fw_node_put(struct fw_node *node) | |||
187 | } | 200 | } |
188 | 201 | ||
189 | void fw_core_handle_bus_reset(struct fw_card *card, int node_id, | 202 | void fw_core_handle_bus_reset(struct fw_card *card, int node_id, |
190 | int generation, int self_id_count, u32 *self_ids); | 203 | int generation, int self_id_count, u32 *self_ids, bool bm_abdicate); |
191 | void fw_destroy_nodes(struct fw_card *card); | 204 | void fw_destroy_nodes(struct fw_card *card); |
192 | 205 | ||
193 | /* | 206 | /* |
@@ -204,6 +217,7 @@ static inline bool is_next_generation(int new_generation, int old_generation) | |||
204 | 217 | ||
205 | #define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4) | 218 | #define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4) |
206 | #define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0) | 219 | #define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0) |
220 | #define TCODE_IS_LINK_INTERNAL(tcode) ((tcode) == 0xe) | ||
207 | #define TCODE_IS_REQUEST(tcode) (((tcode) & 2) == 0) | 221 | #define TCODE_IS_REQUEST(tcode) (((tcode) & 2) == 0) |
208 | #define TCODE_IS_RESPONSE(tcode) (((tcode) & 2) != 0) | 222 | #define TCODE_IS_RESPONSE(tcode) (((tcode) & 2) != 0) |
209 | #define TCODE_HAS_REQUEST_DATA(tcode) (((tcode) & 12) != 4) | 223 | #define TCODE_HAS_REQUEST_DATA(tcode) (((tcode) & 12) != 4) |
@@ -213,10 +227,18 @@ static inline bool is_next_generation(int new_generation, int old_generation) | |||
213 | 227 | ||
214 | void fw_core_handle_request(struct fw_card *card, struct fw_packet *request); | 228 | void fw_core_handle_request(struct fw_card *card, struct fw_packet *request); |
215 | void fw_core_handle_response(struct fw_card *card, struct fw_packet *packet); | 229 | void fw_core_handle_response(struct fw_card *card, struct fw_packet *packet); |
230 | int fw_get_response_length(struct fw_request *request); | ||
216 | void fw_fill_response(struct fw_packet *response, u32 *request_header, | 231 | void fw_fill_response(struct fw_packet *response, u32 *request_header, |
217 | int rcode, void *payload, size_t length); | 232 | int rcode, void *payload, size_t length); |
218 | void fw_flush_transactions(struct fw_card *card); | 233 | |
234 | #define FW_PHY_CONFIG_NO_NODE_ID -1 | ||
235 | #define FW_PHY_CONFIG_CURRENT_GAP_COUNT -1 | ||
219 | void fw_send_phy_config(struct fw_card *card, | 236 | void fw_send_phy_config(struct fw_card *card, |
220 | int node_id, int generation, int gap_count); | 237 | int node_id, int generation, int gap_count); |
221 | 238 | ||
239 | static inline bool is_ping_packet(u32 *data) | ||
240 | { | ||
241 | return (data[0] & 0xc0ffffff) == 0 && ~data[0] == data[1]; | ||
242 | } | ||
243 | |||
222 | #endif /* _FIREWIRE_CORE_H */ | 244 | #endif /* _FIREWIRE_CORE_H */ |
diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c index 7142eeec8074..da17d409a244 100644 --- a/drivers/firewire/net.c +++ b/drivers/firewire/net.c | |||
@@ -806,8 +806,8 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len, | |||
806 | 806 | ||
807 | static void fwnet_receive_packet(struct fw_card *card, struct fw_request *r, | 807 | static void fwnet_receive_packet(struct fw_card *card, struct fw_request *r, |
808 | int tcode, int destination, int source, int generation, | 808 | int tcode, int destination, int source, int generation, |
809 | int speed, unsigned long long offset, void *payload, | 809 | unsigned long long offset, void *payload, size_t length, |
810 | size_t length, void *callback_data) | 810 | void *callback_data) |
811 | { | 811 | { |
812 | struct fwnet_device *dev = callback_data; | 812 | struct fwnet_device *dev = callback_data; |
813 | int rcode; | 813 | int rcode; |
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 94b16e0340ae..7f03540cabe8 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c | |||
@@ -18,6 +18,7 @@ | |||
18 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <linux/bug.h> | ||
21 | #include <linux/compiler.h> | 22 | #include <linux/compiler.h> |
22 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
23 | #include <linux/device.h> | 24 | #include <linux/device.h> |
@@ -32,11 +33,13 @@ | |||
32 | #include <linux/mm.h> | 33 | #include <linux/mm.h> |
33 | #include <linux/module.h> | 34 | #include <linux/module.h> |
34 | #include <linux/moduleparam.h> | 35 | #include <linux/moduleparam.h> |
36 | #include <linux/mutex.h> | ||
35 | #include <linux/pci.h> | 37 | #include <linux/pci.h> |
36 | #include <linux/pci_ids.h> | 38 | #include <linux/pci_ids.h> |
37 | #include <linux/slab.h> | 39 | #include <linux/slab.h> |
38 | #include <linux/spinlock.h> | 40 | #include <linux/spinlock.h> |
39 | #include <linux/string.h> | 41 | #include <linux/string.h> |
42 | #include <linux/time.h> | ||
40 | 43 | ||
41 | #include <asm/byteorder.h> | 44 | #include <asm/byteorder.h> |
42 | #include <asm/page.h> | 45 | #include <asm/page.h> |
@@ -170,6 +173,10 @@ struct fw_ohci { | |||
170 | int generation; | 173 | int generation; |
171 | int request_generation; /* for timestamping incoming requests */ | 174 | int request_generation; /* for timestamping incoming requests */ |
172 | unsigned quirks; | 175 | unsigned quirks; |
176 | unsigned int pri_req_max; | ||
177 | u32 bus_time; | ||
178 | bool is_root; | ||
179 | bool csr_state_setclear_abdicate; | ||
173 | 180 | ||
174 | /* | 181 | /* |
175 | * Spinlock for accessing fw_ohci data. Never call out of | 182 | * Spinlock for accessing fw_ohci data. Never call out of |
@@ -177,16 +184,20 @@ struct fw_ohci { | |||
177 | */ | 184 | */ |
178 | spinlock_t lock; | 185 | spinlock_t lock; |
179 | 186 | ||
187 | struct mutex phy_reg_mutex; | ||
188 | |||
180 | struct ar_context ar_request_ctx; | 189 | struct ar_context ar_request_ctx; |
181 | struct ar_context ar_response_ctx; | 190 | struct ar_context ar_response_ctx; |
182 | struct context at_request_ctx; | 191 | struct context at_request_ctx; |
183 | struct context at_response_ctx; | 192 | struct context at_response_ctx; |
184 | 193 | ||
185 | u32 it_context_mask; | 194 | u32 it_context_mask; /* unoccupied IT contexts */ |
186 | struct iso_context *it_context_list; | 195 | struct iso_context *it_context_list; |
187 | u64 ir_context_channels; | 196 | u64 ir_context_channels; /* unoccupied channels */ |
188 | u32 ir_context_mask; | 197 | u32 ir_context_mask; /* unoccupied IR contexts */ |
189 | struct iso_context *ir_context_list; | 198 | struct iso_context *ir_context_list; |
199 | u64 mc_channels; /* channels in use by the multichannel IR context */ | ||
200 | bool mc_allocated; | ||
190 | 201 | ||
191 | __be32 *config_rom; | 202 | __be32 *config_rom; |
192 | dma_addr_t config_rom_bus; | 203 | dma_addr_t config_rom_bus; |
@@ -231,20 +242,25 @@ static inline struct fw_ohci *fw_ohci(struct fw_card *card) | |||
231 | 242 | ||
232 | static char ohci_driver_name[] = KBUILD_MODNAME; | 243 | static char ohci_driver_name[] = KBUILD_MODNAME; |
233 | 244 | ||
245 | #define PCI_DEVICE_ID_JMICRON_JMB38X_FW 0x2380 | ||
234 | #define PCI_DEVICE_ID_TI_TSB12LV22 0x8009 | 246 | #define PCI_DEVICE_ID_TI_TSB12LV22 0x8009 |
235 | 247 | ||
236 | #define QUIRK_CYCLE_TIMER 1 | 248 | #define QUIRK_CYCLE_TIMER 1 |
237 | #define QUIRK_RESET_PACKET 2 | 249 | #define QUIRK_RESET_PACKET 2 |
238 | #define QUIRK_BE_HEADERS 4 | 250 | #define QUIRK_BE_HEADERS 4 |
251 | #define QUIRK_NO_1394A 8 | ||
252 | #define QUIRK_NO_MSI 16 | ||
239 | 253 | ||
240 | /* In case of multiple matches in ohci_quirks[], only the first one is used. */ | 254 | /* In case of multiple matches in ohci_quirks[], only the first one is used. */ |
241 | static const struct { | 255 | static const struct { |
242 | unsigned short vendor, device, flags; | 256 | unsigned short vendor, device, flags; |
243 | } ohci_quirks[] = { | 257 | } ohci_quirks[] = { |
244 | {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV22, QUIRK_CYCLE_TIMER | | 258 | {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV22, QUIRK_CYCLE_TIMER | |
245 | QUIRK_RESET_PACKET}, | 259 | QUIRK_RESET_PACKET | |
260 | QUIRK_NO_1394A}, | ||
246 | {PCI_VENDOR_ID_TI, PCI_ANY_ID, QUIRK_RESET_PACKET}, | 261 | {PCI_VENDOR_ID_TI, PCI_ANY_ID, QUIRK_RESET_PACKET}, |
247 | {PCI_VENDOR_ID_AL, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, | 262 | {PCI_VENDOR_ID_AL, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, |
263 | {PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB38X_FW, QUIRK_NO_MSI}, | ||
248 | {PCI_VENDOR_ID_NEC, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, | 264 | {PCI_VENDOR_ID_NEC, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, |
249 | {PCI_VENDOR_ID_VIA, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, | 265 | {PCI_VENDOR_ID_VIA, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, |
250 | {PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_FW, QUIRK_BE_HEADERS}, | 266 | {PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_FW, QUIRK_BE_HEADERS}, |
@@ -257,15 +273,17 @@ MODULE_PARM_DESC(quirks, "Chip quirks (default = 0" | |||
257 | ", nonatomic cycle timer = " __stringify(QUIRK_CYCLE_TIMER) | 273 | ", nonatomic cycle timer = " __stringify(QUIRK_CYCLE_TIMER) |
258 | ", reset packet generation = " __stringify(QUIRK_RESET_PACKET) | 274 | ", reset packet generation = " __stringify(QUIRK_RESET_PACKET) |
259 | ", AR/selfID endianess = " __stringify(QUIRK_BE_HEADERS) | 275 | ", AR/selfID endianess = " __stringify(QUIRK_BE_HEADERS) |
276 | ", no 1394a enhancements = " __stringify(QUIRK_NO_1394A) | ||
277 | ", disable MSI = " __stringify(QUIRK_NO_MSI) | ||
260 | ")"); | 278 | ")"); |
261 | 279 | ||
262 | #ifdef CONFIG_FIREWIRE_OHCI_DEBUG | ||
263 | |||
264 | #define OHCI_PARAM_DEBUG_AT_AR 1 | 280 | #define OHCI_PARAM_DEBUG_AT_AR 1 |
265 | #define OHCI_PARAM_DEBUG_SELFIDS 2 | 281 | #define OHCI_PARAM_DEBUG_SELFIDS 2 |
266 | #define OHCI_PARAM_DEBUG_IRQS 4 | 282 | #define OHCI_PARAM_DEBUG_IRQS 4 |
267 | #define OHCI_PARAM_DEBUG_BUSRESETS 8 /* only effective before chip init */ | 283 | #define OHCI_PARAM_DEBUG_BUSRESETS 8 /* only effective before chip init */ |
268 | 284 | ||
285 | #ifdef CONFIG_FIREWIRE_OHCI_DEBUG | ||
286 | |||
269 | static int param_debug; | 287 | static int param_debug; |
270 | module_param_named(debug, param_debug, int, 0644); | 288 | module_param_named(debug, param_debug, int, 0644); |
271 | MODULE_PARM_DESC(debug, "Verbose logging (default = 0" | 289 | MODULE_PARM_DESC(debug, "Verbose logging (default = 0" |
@@ -285,7 +303,7 @@ static void log_irqs(u32 evt) | |||
285 | !(evt & OHCI1394_busReset)) | 303 | !(evt & OHCI1394_busReset)) |
286 | return; | 304 | return; |
287 | 305 | ||
288 | fw_notify("IRQ %08x%s%s%s%s%s%s%s%s%s%s%s%s%s\n", evt, | 306 | fw_notify("IRQ %08x%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", evt, |
289 | evt & OHCI1394_selfIDComplete ? " selfID" : "", | 307 | evt & OHCI1394_selfIDComplete ? " selfID" : "", |
290 | evt & OHCI1394_RQPkt ? " AR_req" : "", | 308 | evt & OHCI1394_RQPkt ? " AR_req" : "", |
291 | evt & OHCI1394_RSPkt ? " AR_resp" : "", | 309 | evt & OHCI1394_RSPkt ? " AR_resp" : "", |
@@ -295,6 +313,7 @@ static void log_irqs(u32 evt) | |||
295 | evt & OHCI1394_isochTx ? " IT" : "", | 313 | evt & OHCI1394_isochTx ? " IT" : "", |
296 | evt & OHCI1394_postedWriteErr ? " postedWriteErr" : "", | 314 | evt & OHCI1394_postedWriteErr ? " postedWriteErr" : "", |
297 | evt & OHCI1394_cycleTooLong ? " cycleTooLong" : "", | 315 | evt & OHCI1394_cycleTooLong ? " cycleTooLong" : "", |
316 | evt & OHCI1394_cycle64Seconds ? " cycle64Seconds" : "", | ||
298 | evt & OHCI1394_cycleInconsistent ? " cycleInconsistent" : "", | 317 | evt & OHCI1394_cycleInconsistent ? " cycleInconsistent" : "", |
299 | evt & OHCI1394_regAccessFail ? " regAccessFail" : "", | 318 | evt & OHCI1394_regAccessFail ? " regAccessFail" : "", |
300 | evt & OHCI1394_busReset ? " busReset" : "", | 319 | evt & OHCI1394_busReset ? " busReset" : "", |
@@ -302,7 +321,8 @@ static void log_irqs(u32 evt) | |||
302 | OHCI1394_RSPkt | OHCI1394_reqTxComplete | | 321 | OHCI1394_RSPkt | OHCI1394_reqTxComplete | |
303 | OHCI1394_respTxComplete | OHCI1394_isochRx | | 322 | OHCI1394_respTxComplete | OHCI1394_isochRx | |
304 | OHCI1394_isochTx | OHCI1394_postedWriteErr | | 323 | OHCI1394_isochTx | OHCI1394_postedWriteErr | |
305 | OHCI1394_cycleTooLong | OHCI1394_cycleInconsistent | | 324 | OHCI1394_cycleTooLong | OHCI1394_cycle64Seconds | |
325 | OHCI1394_cycleInconsistent | | ||
306 | OHCI1394_regAccessFail | OHCI1394_busReset) | 326 | OHCI1394_regAccessFail | OHCI1394_busReset) |
307 | ? " ?" : ""); | 327 | ? " ?" : ""); |
308 | } | 328 | } |
@@ -438,9 +458,10 @@ static void log_ar_at_event(char dir, int speed, u32 *header, int evt) | |||
438 | 458 | ||
439 | #else | 459 | #else |
440 | 460 | ||
441 | #define log_irqs(evt) | 461 | #define param_debug 0 |
442 | #define log_selfids(node_id, generation, self_id_count, sid) | 462 | static inline void log_irqs(u32 evt) {} |
443 | #define log_ar_at_event(dir, speed, header, evt) | 463 | static inline void log_selfids(int node_id, int generation, int self_id_count, u32 *s) {} |
464 | static inline void log_ar_at_event(char dir, int speed, u32 *header, int evt) {} | ||
444 | 465 | ||
445 | #endif /* CONFIG_FIREWIRE_OHCI_DEBUG */ | 466 | #endif /* CONFIG_FIREWIRE_OHCI_DEBUG */ |
446 | 467 | ||
@@ -460,27 +481,99 @@ static inline void flush_writes(const struct fw_ohci *ohci) | |||
460 | reg_read(ohci, OHCI1394_Version); | 481 | reg_read(ohci, OHCI1394_Version); |
461 | } | 482 | } |
462 | 483 | ||
463 | static int ohci_update_phy_reg(struct fw_card *card, int addr, | 484 | static int read_phy_reg(struct fw_ohci *ohci, int addr) |
464 | int clear_bits, int set_bits) | ||
465 | { | 485 | { |
466 | struct fw_ohci *ohci = fw_ohci(card); | 486 | u32 val; |
467 | u32 val, old; | 487 | int i; |
468 | 488 | ||
469 | reg_write(ohci, OHCI1394_PhyControl, OHCI1394_PhyControl_Read(addr)); | 489 | reg_write(ohci, OHCI1394_PhyControl, OHCI1394_PhyControl_Read(addr)); |
470 | flush_writes(ohci); | 490 | for (i = 0; i < 3 + 100; i++) { |
471 | msleep(2); | 491 | val = reg_read(ohci, OHCI1394_PhyControl); |
472 | val = reg_read(ohci, OHCI1394_PhyControl); | 492 | if (val & OHCI1394_PhyControl_ReadDone) |
473 | if ((val & OHCI1394_PhyControl_ReadDone) == 0) { | 493 | return OHCI1394_PhyControl_ReadData(val); |
474 | fw_error("failed to set phy reg bits.\n"); | 494 | |
475 | return -EBUSY; | 495 | /* |
496 | * Try a few times without waiting. Sleeping is necessary | ||
497 | * only when the link/PHY interface is busy. | ||
498 | */ | ||
499 | if (i >= 3) | ||
500 | msleep(1); | ||
476 | } | 501 | } |
502 | fw_error("failed to read phy reg\n"); | ||
503 | |||
504 | return -EBUSY; | ||
505 | } | ||
506 | |||
507 | static int write_phy_reg(const struct fw_ohci *ohci, int addr, u32 val) | ||
508 | { | ||
509 | int i; | ||
477 | 510 | ||
478 | old = OHCI1394_PhyControl_ReadData(val); | ||
479 | old = (old & ~clear_bits) | set_bits; | ||
480 | reg_write(ohci, OHCI1394_PhyControl, | 511 | reg_write(ohci, OHCI1394_PhyControl, |
481 | OHCI1394_PhyControl_Write(addr, old)); | 512 | OHCI1394_PhyControl_Write(addr, val)); |
513 | for (i = 0; i < 3 + 100; i++) { | ||
514 | val = reg_read(ohci, OHCI1394_PhyControl); | ||
515 | if (!(val & OHCI1394_PhyControl_WritePending)) | ||
516 | return 0; | ||
482 | 517 | ||
483 | return 0; | 518 | if (i >= 3) |
519 | msleep(1); | ||
520 | } | ||
521 | fw_error("failed to write phy reg\n"); | ||
522 | |||
523 | return -EBUSY; | ||
524 | } | ||
525 | |||
526 | static int update_phy_reg(struct fw_ohci *ohci, int addr, | ||
527 | int clear_bits, int set_bits) | ||
528 | { | ||
529 | int ret = read_phy_reg(ohci, addr); | ||
530 | if (ret < 0) | ||
531 | return ret; | ||
532 | |||
533 | /* | ||
534 | * The interrupt status bits are cleared by writing a one bit. | ||
535 | * Avoid clearing them unless explicitly requested in set_bits. | ||
536 | */ | ||
537 | if (addr == 5) | ||
538 | clear_bits |= PHY_INT_STATUS_BITS; | ||
539 | |||
540 | return write_phy_reg(ohci, addr, (ret & ~clear_bits) | set_bits); | ||
541 | } | ||
542 | |||
543 | static int read_paged_phy_reg(struct fw_ohci *ohci, int page, int addr) | ||
544 | { | ||
545 | int ret; | ||
546 | |||
547 | ret = update_phy_reg(ohci, 7, PHY_PAGE_SELECT, page << 5); | ||
548 | if (ret < 0) | ||
549 | return ret; | ||
550 | |||
551 | return read_phy_reg(ohci, addr); | ||
552 | } | ||
553 | |||
554 | static int ohci_read_phy_reg(struct fw_card *card, int addr) | ||
555 | { | ||
556 | struct fw_ohci *ohci = fw_ohci(card); | ||
557 | int ret; | ||
558 | |||
559 | mutex_lock(&ohci->phy_reg_mutex); | ||
560 | ret = read_phy_reg(ohci, addr); | ||
561 | mutex_unlock(&ohci->phy_reg_mutex); | ||
562 | |||
563 | return ret; | ||
564 | } | ||
565 | |||
566 | static int ohci_update_phy_reg(struct fw_card *card, int addr, | ||
567 | int clear_bits, int set_bits) | ||
568 | { | ||
569 | struct fw_ohci *ohci = fw_ohci(card); | ||
570 | int ret; | ||
571 | |||
572 | mutex_lock(&ohci->phy_reg_mutex); | ||
573 | ret = update_phy_reg(ohci, addr, clear_bits, set_bits); | ||
574 | mutex_unlock(&ohci->phy_reg_mutex); | ||
575 | |||
576 | return ret; | ||
484 | } | 577 | } |
485 | 578 | ||
486 | static int ar_context_add_page(struct ar_context *ctx) | 579 | static int ar_context_add_page(struct ar_context *ctx) |
@@ -505,6 +598,7 @@ static int ar_context_add_page(struct ar_context *ctx) | |||
505 | ab->descriptor.res_count = cpu_to_le16(PAGE_SIZE - offset); | 598 | ab->descriptor.res_count = cpu_to_le16(PAGE_SIZE - offset); |
506 | ab->descriptor.branch_address = 0; | 599 | ab->descriptor.branch_address = 0; |
507 | 600 | ||
601 | wmb(); /* finish init of new descriptors before branch_address update */ | ||
508 | ctx->last_buffer->descriptor.branch_address = cpu_to_le32(ab_bus | 1); | 602 | ctx->last_buffer->descriptor.branch_address = cpu_to_le32(ab_bus | 1); |
509 | ctx->last_buffer->next = ab; | 603 | ctx->last_buffer->next = ab; |
510 | ctx->last_buffer = ab; | 604 | ctx->last_buffer = ab; |
@@ -892,6 +986,8 @@ static void context_append(struct context *ctx, | |||
892 | d_bus = desc->buffer_bus + (d - desc->buffer) * sizeof(*d); | 986 | d_bus = desc->buffer_bus + (d - desc->buffer) * sizeof(*d); |
893 | 987 | ||
894 | desc->used += (z + extra) * sizeof(*d); | 988 | desc->used += (z + extra) * sizeof(*d); |
989 | |||
990 | wmb(); /* finish init of new descriptors before branch_address update */ | ||
895 | ctx->prev->branch_address = cpu_to_le32(d_bus | z); | 991 | ctx->prev->branch_address = cpu_to_le32(d_bus | z); |
896 | ctx->prev = find_branch_descriptor(d, z); | 992 | ctx->prev = find_branch_descriptor(d, z); |
897 | 993 | ||
@@ -978,6 +1074,9 @@ static int at_context_queue_packet(struct context *ctx, | |||
978 | header[1] = cpu_to_le32(packet->header[0]); | 1074 | header[1] = cpu_to_le32(packet->header[0]); |
979 | header[2] = cpu_to_le32(packet->header[1]); | 1075 | header[2] = cpu_to_le32(packet->header[1]); |
980 | d[0].req_count = cpu_to_le16(12); | 1076 | d[0].req_count = cpu_to_le16(12); |
1077 | |||
1078 | if (is_ping_packet(packet->header)) | ||
1079 | d[0].control |= cpu_to_le16(DESCRIPTOR_PING); | ||
981 | break; | 1080 | break; |
982 | 1081 | ||
983 | case 4: | 1082 | case 4: |
@@ -1263,6 +1362,78 @@ static void at_context_transmit(struct context *ctx, struct fw_packet *packet) | |||
1263 | 1362 | ||
1264 | } | 1363 | } |
1265 | 1364 | ||
1365 | static u32 cycle_timer_ticks(u32 cycle_timer) | ||
1366 | { | ||
1367 | u32 ticks; | ||
1368 | |||
1369 | ticks = cycle_timer & 0xfff; | ||
1370 | ticks += 3072 * ((cycle_timer >> 12) & 0x1fff); | ||
1371 | ticks += (3072 * 8000) * (cycle_timer >> 25); | ||
1372 | |||
1373 | return ticks; | ||
1374 | } | ||
1375 | |||
1376 | /* | ||
1377 | * Some controllers exhibit one or more of the following bugs when updating the | ||
1378 | * iso cycle timer register: | ||
1379 | * - When the lowest six bits are wrapping around to zero, a read that happens | ||
1380 | * at the same time will return garbage in the lowest ten bits. | ||
1381 | * - When the cycleOffset field wraps around to zero, the cycleCount field is | ||
1382 | * not incremented for about 60 ns. | ||
1383 | * - Occasionally, the entire register reads zero. | ||
1384 | * | ||
1385 | * To catch these, we read the register three times and ensure that the | ||
1386 | * difference between each two consecutive reads is approximately the same, i.e. | ||
1387 | * less than twice the other. Furthermore, any negative difference indicates an | ||
1388 | * error. (A PCI read should take at least 20 ticks of the 24.576 MHz timer to | ||
1389 | * execute, so we have enough precision to compute the ratio of the differences.) | ||
1390 | */ | ||
1391 | static u32 get_cycle_time(struct fw_ohci *ohci) | ||
1392 | { | ||
1393 | u32 c0, c1, c2; | ||
1394 | u32 t0, t1, t2; | ||
1395 | s32 diff01, diff12; | ||
1396 | int i; | ||
1397 | |||
1398 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1399 | |||
1400 | if (ohci->quirks & QUIRK_CYCLE_TIMER) { | ||
1401 | i = 0; | ||
1402 | c1 = c2; | ||
1403 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1404 | do { | ||
1405 | c0 = c1; | ||
1406 | c1 = c2; | ||
1407 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | ||
1408 | t0 = cycle_timer_ticks(c0); | ||
1409 | t1 = cycle_timer_ticks(c1); | ||
1410 | t2 = cycle_timer_ticks(c2); | ||
1411 | diff01 = t1 - t0; | ||
1412 | diff12 = t2 - t1; | ||
1413 | } while ((diff01 <= 0 || diff12 <= 0 || | ||
1414 | diff01 / diff12 >= 2 || diff12 / diff01 >= 2) | ||
1415 | && i++ < 20); | ||
1416 | } | ||
1417 | |||
1418 | return c2; | ||
1419 | } | ||
1420 | |||
1421 | /* | ||
1422 | * This function has to be called at least every 64 seconds. The bus_time | ||
1423 | * field stores not only the upper 25 bits of the BUS_TIME register but also | ||
1424 | * the most significant bit of the cycle timer in bit 6 so that we can detect | ||
1425 | * changes in this bit. | ||
1426 | */ | ||
1427 | static u32 update_bus_time(struct fw_ohci *ohci) | ||
1428 | { | ||
1429 | u32 cycle_time_seconds = get_cycle_time(ohci) >> 25; | ||
1430 | |||
1431 | if ((ohci->bus_time & 0x40) != (cycle_time_seconds & 0x40)) | ||
1432 | ohci->bus_time += 0x40; | ||
1433 | |||
1434 | return ohci->bus_time | cycle_time_seconds; | ||
1435 | } | ||
1436 | |||
1266 | static void bus_reset_tasklet(unsigned long data) | 1437 | static void bus_reset_tasklet(unsigned long data) |
1267 | { | 1438 | { |
1268 | struct fw_ohci *ohci = (struct fw_ohci *)data; | 1439 | struct fw_ohci *ohci = (struct fw_ohci *)data; |
@@ -1271,6 +1442,7 @@ static void bus_reset_tasklet(unsigned long data) | |||
1271 | unsigned long flags; | 1442 | unsigned long flags; |
1272 | void *free_rom = NULL; | 1443 | void *free_rom = NULL; |
1273 | dma_addr_t free_rom_bus = 0; | 1444 | dma_addr_t free_rom_bus = 0; |
1445 | bool is_new_root; | ||
1274 | 1446 | ||
1275 | reg = reg_read(ohci, OHCI1394_NodeID); | 1447 | reg = reg_read(ohci, OHCI1394_NodeID); |
1276 | if (!(reg & OHCI1394_NodeID_idValid)) { | 1448 | if (!(reg & OHCI1394_NodeID_idValid)) { |
@@ -1284,6 +1456,12 @@ static void bus_reset_tasklet(unsigned long data) | |||
1284 | ohci->node_id = reg & (OHCI1394_NodeID_busNumber | | 1456 | ohci->node_id = reg & (OHCI1394_NodeID_busNumber | |
1285 | OHCI1394_NodeID_nodeNumber); | 1457 | OHCI1394_NodeID_nodeNumber); |
1286 | 1458 | ||
1459 | is_new_root = (reg & OHCI1394_NodeID_root) != 0; | ||
1460 | if (!(ohci->is_root && is_new_root)) | ||
1461 | reg_write(ohci, OHCI1394_LinkControlSet, | ||
1462 | OHCI1394_LinkControl_cycleMaster); | ||
1463 | ohci->is_root = is_new_root; | ||
1464 | |||
1287 | reg = reg_read(ohci, OHCI1394_SelfIDCount); | 1465 | reg = reg_read(ohci, OHCI1394_SelfIDCount); |
1288 | if (reg & OHCI1394_SelfIDCount_selfIDError) { | 1466 | if (reg & OHCI1394_SelfIDCount_selfIDError) { |
1289 | fw_notify("inconsistent self IDs\n"); | 1467 | fw_notify("inconsistent self IDs\n"); |
@@ -1351,7 +1529,7 @@ static void bus_reset_tasklet(unsigned long data) | |||
1351 | * was set up before this reset, the old one is now no longer | 1529 | * was set up before this reset, the old one is now no longer |
1352 | * in use and we can free it. Update the config rom pointers | 1530 | * in use and we can free it. Update the config rom pointers |
1353 | * to point to the current config rom and clear the | 1531 | * to point to the current config rom and clear the |
1354 | * next_config_rom pointer so a new udpate can take place. | 1532 | * next_config_rom pointer so a new update can take place. |
1355 | */ | 1533 | */ |
1356 | 1534 | ||
1357 | if (ohci->next_config_rom != NULL) { | 1535 | if (ohci->next_config_rom != NULL) { |
@@ -1391,7 +1569,9 @@ static void bus_reset_tasklet(unsigned long data) | |||
1391 | self_id_count, ohci->self_id_buffer); | 1569 | self_id_count, ohci->self_id_buffer); |
1392 | 1570 | ||
1393 | fw_core_handle_bus_reset(&ohci->card, ohci->node_id, generation, | 1571 | fw_core_handle_bus_reset(&ohci->card, ohci->node_id, generation, |
1394 | self_id_count, ohci->self_id_buffer); | 1572 | self_id_count, ohci->self_id_buffer, |
1573 | ohci->csr_state_setclear_abdicate); | ||
1574 | ohci->csr_state_setclear_abdicate = false; | ||
1395 | } | 1575 | } |
1396 | 1576 | ||
1397 | static irqreturn_t irq_handler(int irq, void *data) | 1577 | static irqreturn_t irq_handler(int irq, void *data) |
@@ -1467,6 +1647,12 @@ static irqreturn_t irq_handler(int irq, void *data) | |||
1467 | fw_notify("isochronous cycle inconsistent\n"); | 1647 | fw_notify("isochronous cycle inconsistent\n"); |
1468 | } | 1648 | } |
1469 | 1649 | ||
1650 | if (event & OHCI1394_cycle64Seconds) { | ||
1651 | spin_lock(&ohci->lock); | ||
1652 | update_bus_time(ohci); | ||
1653 | spin_unlock(&ohci->lock); | ||
1654 | } | ||
1655 | |||
1470 | return IRQ_HANDLED; | 1656 | return IRQ_HANDLED; |
1471 | } | 1657 | } |
1472 | 1658 | ||
@@ -1495,13 +1681,64 @@ static void copy_config_rom(__be32 *dest, const __be32 *src, size_t length) | |||
1495 | memset(&dest[length], 0, CONFIG_ROM_SIZE - size); | 1681 | memset(&dest[length], 0, CONFIG_ROM_SIZE - size); |
1496 | } | 1682 | } |
1497 | 1683 | ||
1684 | static int configure_1394a_enhancements(struct fw_ohci *ohci) | ||
1685 | { | ||
1686 | bool enable_1394a; | ||
1687 | int ret, clear, set, offset; | ||
1688 | |||
1689 | /* Check if the driver should configure link and PHY. */ | ||
1690 | if (!(reg_read(ohci, OHCI1394_HCControlSet) & | ||
1691 | OHCI1394_HCControl_programPhyEnable)) | ||
1692 | return 0; | ||
1693 | |||
1694 | /* Paranoia: check whether the PHY supports 1394a, too. */ | ||
1695 | enable_1394a = false; | ||
1696 | ret = read_phy_reg(ohci, 2); | ||
1697 | if (ret < 0) | ||
1698 | return ret; | ||
1699 | if ((ret & PHY_EXTENDED_REGISTERS) == PHY_EXTENDED_REGISTERS) { | ||
1700 | ret = read_paged_phy_reg(ohci, 1, 8); | ||
1701 | if (ret < 0) | ||
1702 | return ret; | ||
1703 | if (ret >= 1) | ||
1704 | enable_1394a = true; | ||
1705 | } | ||
1706 | |||
1707 | if (ohci->quirks & QUIRK_NO_1394A) | ||
1708 | enable_1394a = false; | ||
1709 | |||
1710 | /* Configure PHY and link consistently. */ | ||
1711 | if (enable_1394a) { | ||
1712 | clear = 0; | ||
1713 | set = PHY_ENABLE_ACCEL | PHY_ENABLE_MULTI; | ||
1714 | } else { | ||
1715 | clear = PHY_ENABLE_ACCEL | PHY_ENABLE_MULTI; | ||
1716 | set = 0; | ||
1717 | } | ||
1718 | ret = update_phy_reg(ohci, 5, clear, set); | ||
1719 | if (ret < 0) | ||
1720 | return ret; | ||
1721 | |||
1722 | if (enable_1394a) | ||
1723 | offset = OHCI1394_HCControlSet; | ||
1724 | else | ||
1725 | offset = OHCI1394_HCControlClear; | ||
1726 | reg_write(ohci, offset, OHCI1394_HCControl_aPhyEnhanceEnable); | ||
1727 | |||
1728 | /* Clean up: configuration has been taken care of. */ | ||
1729 | reg_write(ohci, OHCI1394_HCControlClear, | ||
1730 | OHCI1394_HCControl_programPhyEnable); | ||
1731 | |||
1732 | return 0; | ||
1733 | } | ||
1734 | |||
1498 | static int ohci_enable(struct fw_card *card, | 1735 | static int ohci_enable(struct fw_card *card, |
1499 | const __be32 *config_rom, size_t length) | 1736 | const __be32 *config_rom, size_t length) |
1500 | { | 1737 | { |
1501 | struct fw_ohci *ohci = fw_ohci(card); | 1738 | struct fw_ohci *ohci = fw_ohci(card); |
1502 | struct pci_dev *dev = to_pci_dev(card->device); | 1739 | struct pci_dev *dev = to_pci_dev(card->device); |
1503 | u32 lps; | 1740 | u32 lps, seconds, version, irqs; |
1504 | int i; | 1741 | int i, ret; |
1505 | 1742 | ||
1506 | if (software_reset(ohci)) { | 1743 | if (software_reset(ohci)) { |
1507 | fw_error("Failed to reset ohci card.\n"); | 1744 | fw_error("Failed to reset ohci card.\n"); |
@@ -1536,17 +1773,34 @@ static int ohci_enable(struct fw_card *card, | |||
1536 | OHCI1394_HCControl_noByteSwapData); | 1773 | OHCI1394_HCControl_noByteSwapData); |
1537 | 1774 | ||
1538 | reg_write(ohci, OHCI1394_SelfIDBuffer, ohci->self_id_bus); | 1775 | reg_write(ohci, OHCI1394_SelfIDBuffer, ohci->self_id_bus); |
1539 | reg_write(ohci, OHCI1394_LinkControlClear, | ||
1540 | OHCI1394_LinkControl_rcvPhyPkt); | ||
1541 | reg_write(ohci, OHCI1394_LinkControlSet, | 1776 | reg_write(ohci, OHCI1394_LinkControlSet, |
1542 | OHCI1394_LinkControl_rcvSelfID | | 1777 | OHCI1394_LinkControl_rcvSelfID | |
1778 | OHCI1394_LinkControl_rcvPhyPkt | | ||
1543 | OHCI1394_LinkControl_cycleTimerEnable | | 1779 | OHCI1394_LinkControl_cycleTimerEnable | |
1544 | OHCI1394_LinkControl_cycleMaster); | 1780 | OHCI1394_LinkControl_cycleMaster); |
1545 | 1781 | ||
1546 | reg_write(ohci, OHCI1394_ATRetries, | 1782 | reg_write(ohci, OHCI1394_ATRetries, |
1547 | OHCI1394_MAX_AT_REQ_RETRIES | | 1783 | OHCI1394_MAX_AT_REQ_RETRIES | |
1548 | (OHCI1394_MAX_AT_RESP_RETRIES << 4) | | 1784 | (OHCI1394_MAX_AT_RESP_RETRIES << 4) | |
1549 | (OHCI1394_MAX_PHYS_RESP_RETRIES << 8)); | 1785 | (OHCI1394_MAX_PHYS_RESP_RETRIES << 8) | |
1786 | (200 << 16)); | ||
1787 | |||
1788 | seconds = lower_32_bits(get_seconds()); | ||
1789 | reg_write(ohci, OHCI1394_IsochronousCycleTimer, seconds << 25); | ||
1790 | ohci->bus_time = seconds & ~0x3f; | ||
1791 | |||
1792 | version = reg_read(ohci, OHCI1394_Version) & 0x00ff00ff; | ||
1793 | if (version >= OHCI_VERSION_1_1) { | ||
1794 | reg_write(ohci, OHCI1394_InitialChannelsAvailableHi, | ||
1795 | 0xfffffffe); | ||
1796 | card->broadcast_channel_auto_allocated = true; | ||
1797 | } | ||
1798 | |||
1799 | /* Get implemented bits of the priority arbitration request counter. */ | ||
1800 | reg_write(ohci, OHCI1394_FairnessControl, 0x3f); | ||
1801 | ohci->pri_req_max = reg_read(ohci, OHCI1394_FairnessControl) & 0x3f; | ||
1802 | reg_write(ohci, OHCI1394_FairnessControl, 0); | ||
1803 | card->priority_budget_implemented = ohci->pri_req_max != 0; | ||
1550 | 1804 | ||
1551 | ar_context_run(&ohci->ar_request_ctx); | 1805 | ar_context_run(&ohci->ar_request_ctx); |
1552 | ar_context_run(&ohci->ar_response_ctx); | 1806 | ar_context_run(&ohci->ar_response_ctx); |
@@ -1554,21 +1808,15 @@ static int ohci_enable(struct fw_card *card, | |||
1554 | reg_write(ohci, OHCI1394_PhyUpperBound, 0x00010000); | 1808 | reg_write(ohci, OHCI1394_PhyUpperBound, 0x00010000); |
1555 | reg_write(ohci, OHCI1394_IntEventClear, ~0); | 1809 | reg_write(ohci, OHCI1394_IntEventClear, ~0); |
1556 | reg_write(ohci, OHCI1394_IntMaskClear, ~0); | 1810 | reg_write(ohci, OHCI1394_IntMaskClear, ~0); |
1557 | reg_write(ohci, OHCI1394_IntMaskSet, | 1811 | |
1558 | OHCI1394_selfIDComplete | | 1812 | ret = configure_1394a_enhancements(ohci); |
1559 | OHCI1394_RQPkt | OHCI1394_RSPkt | | 1813 | if (ret < 0) |
1560 | OHCI1394_reqTxComplete | OHCI1394_respTxComplete | | 1814 | return ret; |
1561 | OHCI1394_isochRx | OHCI1394_isochTx | | ||
1562 | OHCI1394_postedWriteErr | OHCI1394_cycleTooLong | | ||
1563 | OHCI1394_cycleInconsistent | OHCI1394_regAccessFail | | ||
1564 | OHCI1394_masterIntEnable); | ||
1565 | if (param_debug & OHCI_PARAM_DEBUG_BUSRESETS) | ||
1566 | reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset); | ||
1567 | 1815 | ||
1568 | /* Activate link_on bit and contender bit in our self ID packets.*/ | 1816 | /* Activate link_on bit and contender bit in our self ID packets.*/ |
1569 | if (ohci_update_phy_reg(card, 4, 0, | 1817 | ret = ohci_update_phy_reg(card, 4, 0, PHY_LINK_ACTIVE | PHY_CONTENDER); |
1570 | PHY_LINK_ACTIVE | PHY_CONTENDER) < 0) | 1818 | if (ret < 0) |
1571 | return -EIO; | 1819 | return ret; |
1572 | 1820 | ||
1573 | /* | 1821 | /* |
1574 | * When the link is not yet enabled, the atomic config rom | 1822 | * When the link is not yet enabled, the atomic config rom |
@@ -1616,26 +1864,38 @@ static int ohci_enable(struct fw_card *card, | |||
1616 | 1864 | ||
1617 | reg_write(ohci, OHCI1394_AsReqFilterHiSet, 0x80000000); | 1865 | reg_write(ohci, OHCI1394_AsReqFilterHiSet, 0x80000000); |
1618 | 1866 | ||
1867 | if (!(ohci->quirks & QUIRK_NO_MSI)) | ||
1868 | pci_enable_msi(dev); | ||
1619 | if (request_irq(dev->irq, irq_handler, | 1869 | if (request_irq(dev->irq, irq_handler, |
1620 | IRQF_SHARED, ohci_driver_name, ohci)) { | 1870 | pci_dev_msi_enabled(dev) ? 0 : IRQF_SHARED, |
1621 | fw_error("Failed to allocate shared interrupt %d.\n", | 1871 | ohci_driver_name, ohci)) { |
1622 | dev->irq); | 1872 | fw_error("Failed to allocate interrupt %d.\n", dev->irq); |
1873 | pci_disable_msi(dev); | ||
1623 | dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, | 1874 | dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, |
1624 | ohci->config_rom, ohci->config_rom_bus); | 1875 | ohci->config_rom, ohci->config_rom_bus); |
1625 | return -EIO; | 1876 | return -EIO; |
1626 | } | 1877 | } |
1627 | 1878 | ||
1879 | irqs = OHCI1394_reqTxComplete | OHCI1394_respTxComplete | | ||
1880 | OHCI1394_RQPkt | OHCI1394_RSPkt | | ||
1881 | OHCI1394_isochTx | OHCI1394_isochRx | | ||
1882 | OHCI1394_postedWriteErr | | ||
1883 | OHCI1394_selfIDComplete | | ||
1884 | OHCI1394_regAccessFail | | ||
1885 | OHCI1394_cycle64Seconds | | ||
1886 | OHCI1394_cycleInconsistent | OHCI1394_cycleTooLong | | ||
1887 | OHCI1394_masterIntEnable; | ||
1888 | if (param_debug & OHCI_PARAM_DEBUG_BUSRESETS) | ||
1889 | irqs |= OHCI1394_busReset; | ||
1890 | reg_write(ohci, OHCI1394_IntMaskSet, irqs); | ||
1891 | |||
1628 | reg_write(ohci, OHCI1394_HCControlSet, | 1892 | reg_write(ohci, OHCI1394_HCControlSet, |
1629 | OHCI1394_HCControl_linkEnable | | 1893 | OHCI1394_HCControl_linkEnable | |
1630 | OHCI1394_HCControl_BIBimageValid); | 1894 | OHCI1394_HCControl_BIBimageValid); |
1631 | flush_writes(ohci); | 1895 | flush_writes(ohci); |
1632 | 1896 | ||
1633 | /* | 1897 | /* We are ready to go, reset bus to finish initialization. */ |
1634 | * We are ready to go, initiate bus reset to finish the | 1898 | fw_schedule_bus_reset(&ohci->card, false, true); |
1635 | * initialization. | ||
1636 | */ | ||
1637 | |||
1638 | fw_core_initiate_bus_reset(&ohci->card, 1); | ||
1639 | 1899 | ||
1640 | return 0; | 1900 | return 0; |
1641 | } | 1901 | } |
@@ -1710,7 +1970,7 @@ static int ohci_set_config_rom(struct fw_card *card, | |||
1710 | * takes effect. | 1970 | * takes effect. |
1711 | */ | 1971 | */ |
1712 | if (ret == 0) | 1972 | if (ret == 0) |
1713 | fw_core_initiate_bus_reset(&ohci->card, 1); | 1973 | fw_schedule_bus_reset(&ohci->card, true, true); |
1714 | else | 1974 | else |
1715 | dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, | 1975 | dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, |
1716 | next_config_rom, next_config_rom_bus); | 1976 | next_config_rom, next_config_rom_bus); |
@@ -1800,61 +2060,117 @@ static int ohci_enable_phys_dma(struct fw_card *card, | |||
1800 | #endif /* CONFIG_FIREWIRE_OHCI_REMOTE_DMA */ | 2060 | #endif /* CONFIG_FIREWIRE_OHCI_REMOTE_DMA */ |
1801 | } | 2061 | } |
1802 | 2062 | ||
1803 | static u32 cycle_timer_ticks(u32 cycle_timer) | 2063 | static u32 ohci_read_csr(struct fw_card *card, int csr_offset) |
1804 | { | 2064 | { |
1805 | u32 ticks; | 2065 | struct fw_ohci *ohci = fw_ohci(card); |
2066 | unsigned long flags; | ||
2067 | u32 value; | ||
2068 | |||
2069 | switch (csr_offset) { | ||
2070 | case CSR_STATE_CLEAR: | ||
2071 | case CSR_STATE_SET: | ||
2072 | if (ohci->is_root && | ||
2073 | (reg_read(ohci, OHCI1394_LinkControlSet) & | ||
2074 | OHCI1394_LinkControl_cycleMaster)) | ||
2075 | value = CSR_STATE_BIT_CMSTR; | ||
2076 | else | ||
2077 | value = 0; | ||
2078 | if (ohci->csr_state_setclear_abdicate) | ||
2079 | value |= CSR_STATE_BIT_ABDICATE; | ||
1806 | 2080 | ||
1807 | ticks = cycle_timer & 0xfff; | 2081 | return value; |
1808 | ticks += 3072 * ((cycle_timer >> 12) & 0x1fff); | ||
1809 | ticks += (3072 * 8000) * (cycle_timer >> 25); | ||
1810 | 2082 | ||
1811 | return ticks; | 2083 | case CSR_NODE_IDS: |
2084 | return reg_read(ohci, OHCI1394_NodeID) << 16; | ||
2085 | |||
2086 | case CSR_CYCLE_TIME: | ||
2087 | return get_cycle_time(ohci); | ||
2088 | |||
2089 | case CSR_BUS_TIME: | ||
2090 | /* | ||
2091 | * We might be called just after the cycle timer has wrapped | ||
2092 | * around but just before the cycle64Seconds handler, so we | ||
2093 | * better check here, too, if the bus time needs to be updated. | ||
2094 | */ | ||
2095 | spin_lock_irqsave(&ohci->lock, flags); | ||
2096 | value = update_bus_time(ohci); | ||
2097 | spin_unlock_irqrestore(&ohci->lock, flags); | ||
2098 | return value; | ||
2099 | |||
2100 | case CSR_BUSY_TIMEOUT: | ||
2101 | value = reg_read(ohci, OHCI1394_ATRetries); | ||
2102 | return (value >> 4) & 0x0ffff00f; | ||
2103 | |||
2104 | case CSR_PRIORITY_BUDGET: | ||
2105 | return (reg_read(ohci, OHCI1394_FairnessControl) & 0x3f) | | ||
2106 | (ohci->pri_req_max << 8); | ||
2107 | |||
2108 | default: | ||
2109 | WARN_ON(1); | ||
2110 | return 0; | ||
2111 | } | ||
1812 | } | 2112 | } |
1813 | 2113 | ||
1814 | /* | 2114 | static void ohci_write_csr(struct fw_card *card, int csr_offset, u32 value) |
1815 | * Some controllers exhibit one or more of the following bugs when updating the | ||
1816 | * iso cycle timer register: | ||
1817 | * - When the lowest six bits are wrapping around to zero, a read that happens | ||
1818 | * at the same time will return garbage in the lowest ten bits. | ||
1819 | * - When the cycleOffset field wraps around to zero, the cycleCount field is | ||
1820 | * not incremented for about 60 ns. | ||
1821 | * - Occasionally, the entire register reads zero. | ||
1822 | * | ||
1823 | * To catch these, we read the register three times and ensure that the | ||
1824 | * difference between each two consecutive reads is approximately the same, i.e. | ||
1825 | * less than twice the other. Furthermore, any negative difference indicates an | ||
1826 | * error. (A PCI read should take at least 20 ticks of the 24.576 MHz timer to | ||
1827 | * execute, so we have enough precision to compute the ratio of the differences.) | ||
1828 | */ | ||
1829 | static u32 ohci_get_cycle_time(struct fw_card *card) | ||
1830 | { | 2115 | { |
1831 | struct fw_ohci *ohci = fw_ohci(card); | 2116 | struct fw_ohci *ohci = fw_ohci(card); |
1832 | u32 c0, c1, c2; | 2117 | unsigned long flags; |
1833 | u32 t0, t1, t2; | ||
1834 | s32 diff01, diff12; | ||
1835 | int i; | ||
1836 | 2118 | ||
1837 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | 2119 | switch (csr_offset) { |
2120 | case CSR_STATE_CLEAR: | ||
2121 | if ((value & CSR_STATE_BIT_CMSTR) && ohci->is_root) { | ||
2122 | reg_write(ohci, OHCI1394_LinkControlClear, | ||
2123 | OHCI1394_LinkControl_cycleMaster); | ||
2124 | flush_writes(ohci); | ||
2125 | } | ||
2126 | if (value & CSR_STATE_BIT_ABDICATE) | ||
2127 | ohci->csr_state_setclear_abdicate = false; | ||
2128 | break; | ||
1838 | 2129 | ||
1839 | if (ohci->quirks & QUIRK_CYCLE_TIMER) { | 2130 | case CSR_STATE_SET: |
1840 | i = 0; | 2131 | if ((value & CSR_STATE_BIT_CMSTR) && ohci->is_root) { |
1841 | c1 = c2; | 2132 | reg_write(ohci, OHCI1394_LinkControlSet, |
1842 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | 2133 | OHCI1394_LinkControl_cycleMaster); |
1843 | do { | 2134 | flush_writes(ohci); |
1844 | c0 = c1; | 2135 | } |
1845 | c1 = c2; | 2136 | if (value & CSR_STATE_BIT_ABDICATE) |
1846 | c2 = reg_read(ohci, OHCI1394_IsochronousCycleTimer); | 2137 | ohci->csr_state_setclear_abdicate = true; |
1847 | t0 = cycle_timer_ticks(c0); | 2138 | break; |
1848 | t1 = cycle_timer_ticks(c1); | ||
1849 | t2 = cycle_timer_ticks(c2); | ||
1850 | diff01 = t1 - t0; | ||
1851 | diff12 = t2 - t1; | ||
1852 | } while ((diff01 <= 0 || diff12 <= 0 || | ||
1853 | diff01 / diff12 >= 2 || diff12 / diff01 >= 2) | ||
1854 | && i++ < 20); | ||
1855 | } | ||
1856 | 2139 | ||
1857 | return c2; | 2140 | case CSR_NODE_IDS: |
2141 | reg_write(ohci, OHCI1394_NodeID, value >> 16); | ||
2142 | flush_writes(ohci); | ||
2143 | break; | ||
2144 | |||
2145 | case CSR_CYCLE_TIME: | ||
2146 | reg_write(ohci, OHCI1394_IsochronousCycleTimer, value); | ||
2147 | reg_write(ohci, OHCI1394_IntEventSet, | ||
2148 | OHCI1394_cycleInconsistent); | ||
2149 | flush_writes(ohci); | ||
2150 | break; | ||
2151 | |||
2152 | case CSR_BUS_TIME: | ||
2153 | spin_lock_irqsave(&ohci->lock, flags); | ||
2154 | ohci->bus_time = (ohci->bus_time & 0x7f) | (value & ~0x7f); | ||
2155 | spin_unlock_irqrestore(&ohci->lock, flags); | ||
2156 | break; | ||
2157 | |||
2158 | case CSR_BUSY_TIMEOUT: | ||
2159 | value = (value & 0xf) | ((value & 0xf) << 4) | | ||
2160 | ((value & 0xf) << 8) | ((value & 0x0ffff000) << 4); | ||
2161 | reg_write(ohci, OHCI1394_ATRetries, value); | ||
2162 | flush_writes(ohci); | ||
2163 | break; | ||
2164 | |||
2165 | case CSR_PRIORITY_BUDGET: | ||
2166 | reg_write(ohci, OHCI1394_FairnessControl, value & 0x3f); | ||
2167 | flush_writes(ohci); | ||
2168 | break; | ||
2169 | |||
2170 | default: | ||
2171 | WARN_ON(1); | ||
2172 | break; | ||
2173 | } | ||
1858 | } | 2174 | } |
1859 | 2175 | ||
1860 | static void copy_iso_headers(struct iso_context *ctx, void *p) | 2176 | static void copy_iso_headers(struct iso_context *ctx, void *p) |
@@ -1889,10 +2205,9 @@ static int handle_ir_packet_per_buffer(struct context *context, | |||
1889 | __le32 *ir_header; | 2205 | __le32 *ir_header; |
1890 | void *p; | 2206 | void *p; |
1891 | 2207 | ||
1892 | for (pd = d; pd <= last; pd++) { | 2208 | for (pd = d; pd <= last; pd++) |
1893 | if (pd->transfer_status) | 2209 | if (pd->transfer_status) |
1894 | break; | 2210 | break; |
1895 | } | ||
1896 | if (pd > last) | 2211 | if (pd > last) |
1897 | /* Descriptor(s) not done yet, stop iteration */ | 2212 | /* Descriptor(s) not done yet, stop iteration */ |
1898 | return 0; | 2213 | return 0; |
@@ -1902,16 +2217,38 @@ static int handle_ir_packet_per_buffer(struct context *context, | |||
1902 | 2217 | ||
1903 | if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) { | 2218 | if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) { |
1904 | ir_header = (__le32 *) p; | 2219 | ir_header = (__le32 *) p; |
1905 | ctx->base.callback(&ctx->base, | 2220 | ctx->base.callback.sc(&ctx->base, |
1906 | le32_to_cpu(ir_header[0]) & 0xffff, | 2221 | le32_to_cpu(ir_header[0]) & 0xffff, |
1907 | ctx->header_length, ctx->header, | 2222 | ctx->header_length, ctx->header, |
1908 | ctx->base.callback_data); | 2223 | ctx->base.callback_data); |
1909 | ctx->header_length = 0; | 2224 | ctx->header_length = 0; |
1910 | } | 2225 | } |
1911 | 2226 | ||
1912 | return 1; | 2227 | return 1; |
1913 | } | 2228 | } |
1914 | 2229 | ||
2230 | /* d == last because each descriptor block is only a single descriptor. */ | ||
2231 | static int handle_ir_buffer_fill(struct context *context, | ||
2232 | struct descriptor *d, | ||
2233 | struct descriptor *last) | ||
2234 | { | ||
2235 | struct iso_context *ctx = | ||
2236 | container_of(context, struct iso_context, context); | ||
2237 | |||
2238 | if (!last->transfer_status) | ||
2239 | /* Descriptor(s) not done yet, stop iteration */ | ||
2240 | return 0; | ||
2241 | |||
2242 | if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) | ||
2243 | ctx->base.callback.mc(&ctx->base, | ||
2244 | le32_to_cpu(last->data_address) + | ||
2245 | le16_to_cpu(last->req_count) - | ||
2246 | le16_to_cpu(last->res_count), | ||
2247 | ctx->base.callback_data); | ||
2248 | |||
2249 | return 1; | ||
2250 | } | ||
2251 | |||
1915 | static int handle_it_packet(struct context *context, | 2252 | static int handle_it_packet(struct context *context, |
1916 | struct descriptor *d, | 2253 | struct descriptor *d, |
1917 | struct descriptor *last) | 2254 | struct descriptor *last) |
@@ -1937,71 +2274,118 @@ static int handle_it_packet(struct context *context, | |||
1937 | ctx->header_length += 4; | 2274 | ctx->header_length += 4; |
1938 | } | 2275 | } |
1939 | if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) { | 2276 | if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) { |
1940 | ctx->base.callback(&ctx->base, le16_to_cpu(last->res_count), | 2277 | ctx->base.callback.sc(&ctx->base, le16_to_cpu(last->res_count), |
1941 | ctx->header_length, ctx->header, | 2278 | ctx->header_length, ctx->header, |
1942 | ctx->base.callback_data); | 2279 | ctx->base.callback_data); |
1943 | ctx->header_length = 0; | 2280 | ctx->header_length = 0; |
1944 | } | 2281 | } |
1945 | return 1; | 2282 | return 1; |
1946 | } | 2283 | } |
1947 | 2284 | ||
2285 | static void set_multichannel_mask(struct fw_ohci *ohci, u64 channels) | ||
2286 | { | ||
2287 | u32 hi = channels >> 32, lo = channels; | ||
2288 | |||
2289 | reg_write(ohci, OHCI1394_IRMultiChanMaskHiClear, ~hi); | ||
2290 | reg_write(ohci, OHCI1394_IRMultiChanMaskLoClear, ~lo); | ||
2291 | reg_write(ohci, OHCI1394_IRMultiChanMaskHiSet, hi); | ||
2292 | reg_write(ohci, OHCI1394_IRMultiChanMaskLoSet, lo); | ||
2293 | mmiowb(); | ||
2294 | ohci->mc_channels = channels; | ||
2295 | } | ||
2296 | |||
1948 | static struct fw_iso_context *ohci_allocate_iso_context(struct fw_card *card, | 2297 | static struct fw_iso_context *ohci_allocate_iso_context(struct fw_card *card, |
1949 | int type, int channel, size_t header_size) | 2298 | int type, int channel, size_t header_size) |
1950 | { | 2299 | { |
1951 | struct fw_ohci *ohci = fw_ohci(card); | 2300 | struct fw_ohci *ohci = fw_ohci(card); |
1952 | struct iso_context *ctx, *list; | 2301 | struct iso_context *uninitialized_var(ctx); |
1953 | descriptor_callback_t callback; | 2302 | descriptor_callback_t uninitialized_var(callback); |
1954 | u64 *channels, dont_care = ~0ULL; | 2303 | u64 *uninitialized_var(channels); |
1955 | u32 *mask, regs; | 2304 | u32 *uninitialized_var(mask), uninitialized_var(regs); |
1956 | unsigned long flags; | 2305 | unsigned long flags; |
1957 | int index, ret = -ENOMEM; | 2306 | int index, ret = -EBUSY; |
1958 | 2307 | ||
1959 | if (type == FW_ISO_CONTEXT_TRANSMIT) { | 2308 | spin_lock_irqsave(&ohci->lock, flags); |
1960 | channels = &dont_care; | 2309 | |
1961 | mask = &ohci->it_context_mask; | 2310 | switch (type) { |
1962 | list = ohci->it_context_list; | 2311 | case FW_ISO_CONTEXT_TRANSMIT: |
2312 | mask = &ohci->it_context_mask; | ||
1963 | callback = handle_it_packet; | 2313 | callback = handle_it_packet; |
1964 | } else { | 2314 | index = ffs(*mask) - 1; |
2315 | if (index >= 0) { | ||
2316 | *mask &= ~(1 << index); | ||
2317 | regs = OHCI1394_IsoXmitContextBase(index); | ||
2318 | ctx = &ohci->it_context_list[index]; | ||
2319 | } | ||
2320 | break; | ||
2321 | |||
2322 | case FW_ISO_CONTEXT_RECEIVE: | ||
1965 | channels = &ohci->ir_context_channels; | 2323 | channels = &ohci->ir_context_channels; |
1966 | mask = &ohci->ir_context_mask; | 2324 | mask = &ohci->ir_context_mask; |
1967 | list = ohci->ir_context_list; | ||
1968 | callback = handle_ir_packet_per_buffer; | 2325 | callback = handle_ir_packet_per_buffer; |
1969 | } | 2326 | index = *channels & 1ULL << channel ? ffs(*mask) - 1 : -1; |
2327 | if (index >= 0) { | ||
2328 | *channels &= ~(1ULL << channel); | ||
2329 | *mask &= ~(1 << index); | ||
2330 | regs = OHCI1394_IsoRcvContextBase(index); | ||
2331 | ctx = &ohci->ir_context_list[index]; | ||
2332 | } | ||
2333 | break; | ||
1970 | 2334 | ||
1971 | spin_lock_irqsave(&ohci->lock, flags); | 2335 | case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: |
1972 | index = *channels & 1ULL << channel ? ffs(*mask) - 1 : -1; | 2336 | mask = &ohci->ir_context_mask; |
1973 | if (index >= 0) { | 2337 | callback = handle_ir_buffer_fill; |
1974 | *channels &= ~(1ULL << channel); | 2338 | index = !ohci->mc_allocated ? ffs(*mask) - 1 : -1; |
1975 | *mask &= ~(1 << index); | 2339 | if (index >= 0) { |
2340 | ohci->mc_allocated = true; | ||
2341 | *mask &= ~(1 << index); | ||
2342 | regs = OHCI1394_IsoRcvContextBase(index); | ||
2343 | ctx = &ohci->ir_context_list[index]; | ||
2344 | } | ||
2345 | break; | ||
2346 | |||
2347 | default: | ||
2348 | index = -1; | ||
2349 | ret = -ENOSYS; | ||
1976 | } | 2350 | } |
2351 | |||
1977 | spin_unlock_irqrestore(&ohci->lock, flags); | 2352 | spin_unlock_irqrestore(&ohci->lock, flags); |
1978 | 2353 | ||
1979 | if (index < 0) | 2354 | if (index < 0) |
1980 | return ERR_PTR(-EBUSY); | 2355 | return ERR_PTR(ret); |
1981 | 2356 | ||
1982 | if (type == FW_ISO_CONTEXT_TRANSMIT) | ||
1983 | regs = OHCI1394_IsoXmitContextBase(index); | ||
1984 | else | ||
1985 | regs = OHCI1394_IsoRcvContextBase(index); | ||
1986 | |||
1987 | ctx = &list[index]; | ||
1988 | memset(ctx, 0, sizeof(*ctx)); | 2357 | memset(ctx, 0, sizeof(*ctx)); |
1989 | ctx->header_length = 0; | 2358 | ctx->header_length = 0; |
1990 | ctx->header = (void *) __get_free_page(GFP_KERNEL); | 2359 | ctx->header = (void *) __get_free_page(GFP_KERNEL); |
1991 | if (ctx->header == NULL) | 2360 | if (ctx->header == NULL) { |
2361 | ret = -ENOMEM; | ||
1992 | goto out; | 2362 | goto out; |
1993 | 2363 | } | |
1994 | ret = context_init(&ctx->context, ohci, regs, callback); | 2364 | ret = context_init(&ctx->context, ohci, regs, callback); |
1995 | if (ret < 0) | 2365 | if (ret < 0) |
1996 | goto out_with_header; | 2366 | goto out_with_header; |
1997 | 2367 | ||
2368 | if (type == FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL) | ||
2369 | set_multichannel_mask(ohci, 0); | ||
2370 | |||
1998 | return &ctx->base; | 2371 | return &ctx->base; |
1999 | 2372 | ||
2000 | out_with_header: | 2373 | out_with_header: |
2001 | free_page((unsigned long)ctx->header); | 2374 | free_page((unsigned long)ctx->header); |
2002 | out: | 2375 | out: |
2003 | spin_lock_irqsave(&ohci->lock, flags); | 2376 | spin_lock_irqsave(&ohci->lock, flags); |
2377 | |||
2378 | switch (type) { | ||
2379 | case FW_ISO_CONTEXT_RECEIVE: | ||
2380 | *channels |= 1ULL << channel; | ||
2381 | break; | ||
2382 | |||
2383 | case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: | ||
2384 | ohci->mc_allocated = false; | ||
2385 | break; | ||
2386 | } | ||
2004 | *mask |= 1 << index; | 2387 | *mask |= 1 << index; |
2388 | |||
2005 | spin_unlock_irqrestore(&ohci->lock, flags); | 2389 | spin_unlock_irqrestore(&ohci->lock, flags); |
2006 | 2390 | ||
2007 | return ERR_PTR(ret); | 2391 | return ERR_PTR(ret); |
@@ -2012,10 +2396,11 @@ static int ohci_start_iso(struct fw_iso_context *base, | |||
2012 | { | 2396 | { |
2013 | struct iso_context *ctx = container_of(base, struct iso_context, base); | 2397 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
2014 | struct fw_ohci *ohci = ctx->context.ohci; | 2398 | struct fw_ohci *ohci = ctx->context.ohci; |
2015 | u32 control, match; | 2399 | u32 control = IR_CONTEXT_ISOCH_HEADER, match; |
2016 | int index; | 2400 | int index; |
2017 | 2401 | ||
2018 | if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) { | 2402 | switch (ctx->base.type) { |
2403 | case FW_ISO_CONTEXT_TRANSMIT: | ||
2019 | index = ctx - ohci->it_context_list; | 2404 | index = ctx - ohci->it_context_list; |
2020 | match = 0; | 2405 | match = 0; |
2021 | if (cycle >= 0) | 2406 | if (cycle >= 0) |
@@ -2025,9 +2410,13 @@ static int ohci_start_iso(struct fw_iso_context *base, | |||
2025 | reg_write(ohci, OHCI1394_IsoXmitIntEventClear, 1 << index); | 2410 | reg_write(ohci, OHCI1394_IsoXmitIntEventClear, 1 << index); |
2026 | reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, 1 << index); | 2411 | reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, 1 << index); |
2027 | context_run(&ctx->context, match); | 2412 | context_run(&ctx->context, match); |
2028 | } else { | 2413 | break; |
2414 | |||
2415 | case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: | ||
2416 | control |= IR_CONTEXT_BUFFER_FILL|IR_CONTEXT_MULTI_CHANNEL_MODE; | ||
2417 | /* fall through */ | ||
2418 | case FW_ISO_CONTEXT_RECEIVE: | ||
2029 | index = ctx - ohci->ir_context_list; | 2419 | index = ctx - ohci->ir_context_list; |
2030 | control = IR_CONTEXT_ISOCH_HEADER; | ||
2031 | match = (tags << 28) | (sync << 8) | ctx->base.channel; | 2420 | match = (tags << 28) | (sync << 8) | ctx->base.channel; |
2032 | if (cycle >= 0) { | 2421 | if (cycle >= 0) { |
2033 | match |= (cycle & 0x07fff) << 12; | 2422 | match |= (cycle & 0x07fff) << 12; |
@@ -2038,6 +2427,7 @@ static int ohci_start_iso(struct fw_iso_context *base, | |||
2038 | reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, 1 << index); | 2427 | reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, 1 << index); |
2039 | reg_write(ohci, CONTEXT_MATCH(ctx->context.regs), match); | 2428 | reg_write(ohci, CONTEXT_MATCH(ctx->context.regs), match); |
2040 | context_run(&ctx->context, control); | 2429 | context_run(&ctx->context, control); |
2430 | break; | ||
2041 | } | 2431 | } |
2042 | 2432 | ||
2043 | return 0; | 2433 | return 0; |
@@ -2049,12 +2439,17 @@ static int ohci_stop_iso(struct fw_iso_context *base) | |||
2049 | struct iso_context *ctx = container_of(base, struct iso_context, base); | 2439 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
2050 | int index; | 2440 | int index; |
2051 | 2441 | ||
2052 | if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) { | 2442 | switch (ctx->base.type) { |
2443 | case FW_ISO_CONTEXT_TRANSMIT: | ||
2053 | index = ctx - ohci->it_context_list; | 2444 | index = ctx - ohci->it_context_list; |
2054 | reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, 1 << index); | 2445 | reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, 1 << index); |
2055 | } else { | 2446 | break; |
2447 | |||
2448 | case FW_ISO_CONTEXT_RECEIVE: | ||
2449 | case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: | ||
2056 | index = ctx - ohci->ir_context_list; | 2450 | index = ctx - ohci->ir_context_list; |
2057 | reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, 1 << index); | 2451 | reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, 1 << index); |
2452 | break; | ||
2058 | } | 2453 | } |
2059 | flush_writes(ohci); | 2454 | flush_writes(ohci); |
2060 | context_stop(&ctx->context); | 2455 | context_stop(&ctx->context); |
@@ -2075,24 +2470,65 @@ static void ohci_free_iso_context(struct fw_iso_context *base) | |||
2075 | 2470 | ||
2076 | spin_lock_irqsave(&ohci->lock, flags); | 2471 | spin_lock_irqsave(&ohci->lock, flags); |
2077 | 2472 | ||
2078 | if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) { | 2473 | switch (base->type) { |
2474 | case FW_ISO_CONTEXT_TRANSMIT: | ||
2079 | index = ctx - ohci->it_context_list; | 2475 | index = ctx - ohci->it_context_list; |
2080 | ohci->it_context_mask |= 1 << index; | 2476 | ohci->it_context_mask |= 1 << index; |
2081 | } else { | 2477 | break; |
2478 | |||
2479 | case FW_ISO_CONTEXT_RECEIVE: | ||
2082 | index = ctx - ohci->ir_context_list; | 2480 | index = ctx - ohci->ir_context_list; |
2083 | ohci->ir_context_mask |= 1 << index; | 2481 | ohci->ir_context_mask |= 1 << index; |
2084 | ohci->ir_context_channels |= 1ULL << base->channel; | 2482 | ohci->ir_context_channels |= 1ULL << base->channel; |
2483 | break; | ||
2484 | |||
2485 | case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: | ||
2486 | index = ctx - ohci->ir_context_list; | ||
2487 | ohci->ir_context_mask |= 1 << index; | ||
2488 | ohci->ir_context_channels |= ohci->mc_channels; | ||
2489 | ohci->mc_channels = 0; | ||
2490 | ohci->mc_allocated = false; | ||
2491 | break; | ||
2085 | } | 2492 | } |
2086 | 2493 | ||
2087 | spin_unlock_irqrestore(&ohci->lock, flags); | 2494 | spin_unlock_irqrestore(&ohci->lock, flags); |
2088 | } | 2495 | } |
2089 | 2496 | ||
2090 | static int ohci_queue_iso_transmit(struct fw_iso_context *base, | 2497 | static int ohci_set_iso_channels(struct fw_iso_context *base, u64 *channels) |
2091 | struct fw_iso_packet *packet, | 2498 | { |
2092 | struct fw_iso_buffer *buffer, | 2499 | struct fw_ohci *ohci = fw_ohci(base->card); |
2093 | unsigned long payload) | 2500 | unsigned long flags; |
2501 | int ret; | ||
2502 | |||
2503 | switch (base->type) { | ||
2504 | case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: | ||
2505 | |||
2506 | spin_lock_irqsave(&ohci->lock, flags); | ||
2507 | |||
2508 | /* Don't allow multichannel to grab other contexts' channels. */ | ||
2509 | if (~ohci->ir_context_channels & ~ohci->mc_channels & *channels) { | ||
2510 | *channels = ohci->ir_context_channels; | ||
2511 | ret = -EBUSY; | ||
2512 | } else { | ||
2513 | set_multichannel_mask(ohci, *channels); | ||
2514 | ret = 0; | ||
2515 | } | ||
2516 | |||
2517 | spin_unlock_irqrestore(&ohci->lock, flags); | ||
2518 | |||
2519 | break; | ||
2520 | default: | ||
2521 | ret = -EINVAL; | ||
2522 | } | ||
2523 | |||
2524 | return ret; | ||
2525 | } | ||
2526 | |||
2527 | static int queue_iso_transmit(struct iso_context *ctx, | ||
2528 | struct fw_iso_packet *packet, | ||
2529 | struct fw_iso_buffer *buffer, | ||
2530 | unsigned long payload) | ||
2094 | { | 2531 | { |
2095 | struct iso_context *ctx = container_of(base, struct iso_context, base); | ||
2096 | struct descriptor *d, *last, *pd; | 2532 | struct descriptor *d, *last, *pd; |
2097 | struct fw_iso_packet *p; | 2533 | struct fw_iso_packet *p; |
2098 | __le32 *header; | 2534 | __le32 *header; |
@@ -2188,14 +2624,12 @@ static int ohci_queue_iso_transmit(struct fw_iso_context *base, | |||
2188 | return 0; | 2624 | return 0; |
2189 | } | 2625 | } |
2190 | 2626 | ||
2191 | static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base, | 2627 | static int queue_iso_packet_per_buffer(struct iso_context *ctx, |
2192 | struct fw_iso_packet *packet, | 2628 | struct fw_iso_packet *packet, |
2193 | struct fw_iso_buffer *buffer, | 2629 | struct fw_iso_buffer *buffer, |
2194 | unsigned long payload) | 2630 | unsigned long payload) |
2195 | { | 2631 | { |
2196 | struct iso_context *ctx = container_of(base, struct iso_context, base); | ||
2197 | struct descriptor *d, *pd; | 2632 | struct descriptor *d, *pd; |
2198 | struct fw_iso_packet *p = packet; | ||
2199 | dma_addr_t d_bus, page_bus; | 2633 | dma_addr_t d_bus, page_bus; |
2200 | u32 z, header_z, rest; | 2634 | u32 z, header_z, rest; |
2201 | int i, j, length; | 2635 | int i, j, length; |
@@ -2205,14 +2639,14 @@ static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base, | |||
2205 | * The OHCI controller puts the isochronous header and trailer in the | 2639 | * The OHCI controller puts the isochronous header and trailer in the |
2206 | * buffer, so we need at least 8 bytes. | 2640 | * buffer, so we need at least 8 bytes. |
2207 | */ | 2641 | */ |
2208 | packet_count = p->header_length / ctx->base.header_size; | 2642 | packet_count = packet->header_length / ctx->base.header_size; |
2209 | header_size = max(ctx->base.header_size, (size_t)8); | 2643 | header_size = max(ctx->base.header_size, (size_t)8); |
2210 | 2644 | ||
2211 | /* Get header size in number of descriptors. */ | 2645 | /* Get header size in number of descriptors. */ |
2212 | header_z = DIV_ROUND_UP(header_size, sizeof(*d)); | 2646 | header_z = DIV_ROUND_UP(header_size, sizeof(*d)); |
2213 | page = payload >> PAGE_SHIFT; | 2647 | page = payload >> PAGE_SHIFT; |
2214 | offset = payload & ~PAGE_MASK; | 2648 | offset = payload & ~PAGE_MASK; |
2215 | payload_per_buffer = p->payload_length / packet_count; | 2649 | payload_per_buffer = packet->payload_length / packet_count; |
2216 | 2650 | ||
2217 | for (i = 0; i < packet_count; i++) { | 2651 | for (i = 0; i < packet_count; i++) { |
2218 | /* d points to the header descriptor */ | 2652 | /* d points to the header descriptor */ |
@@ -2224,7 +2658,7 @@ static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base, | |||
2224 | 2658 | ||
2225 | d->control = cpu_to_le16(DESCRIPTOR_STATUS | | 2659 | d->control = cpu_to_le16(DESCRIPTOR_STATUS | |
2226 | DESCRIPTOR_INPUT_MORE); | 2660 | DESCRIPTOR_INPUT_MORE); |
2227 | if (p->skip && i == 0) | 2661 | if (packet->skip && i == 0) |
2228 | d->control |= cpu_to_le16(DESCRIPTOR_WAIT); | 2662 | d->control |= cpu_to_le16(DESCRIPTOR_WAIT); |
2229 | d->req_count = cpu_to_le16(header_size); | 2663 | d->req_count = cpu_to_le16(header_size); |
2230 | d->res_count = d->req_count; | 2664 | d->res_count = d->req_count; |
@@ -2257,7 +2691,7 @@ static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base, | |||
2257 | pd->control = cpu_to_le16(DESCRIPTOR_STATUS | | 2691 | pd->control = cpu_to_le16(DESCRIPTOR_STATUS | |
2258 | DESCRIPTOR_INPUT_LAST | | 2692 | DESCRIPTOR_INPUT_LAST | |
2259 | DESCRIPTOR_BRANCH_ALWAYS); | 2693 | DESCRIPTOR_BRANCH_ALWAYS); |
2260 | if (p->interrupt && i == packet_count - 1) | 2694 | if (packet->interrupt && i == packet_count - 1) |
2261 | pd->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS); | 2695 | pd->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS); |
2262 | 2696 | ||
2263 | context_append(&ctx->context, d, z, header_z); | 2697 | context_append(&ctx->context, d, z, header_z); |
@@ -2266,6 +2700,58 @@ static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base, | |||
2266 | return 0; | 2700 | return 0; |
2267 | } | 2701 | } |
2268 | 2702 | ||
2703 | static int queue_iso_buffer_fill(struct iso_context *ctx, | ||
2704 | struct fw_iso_packet *packet, | ||
2705 | struct fw_iso_buffer *buffer, | ||
2706 | unsigned long payload) | ||
2707 | { | ||
2708 | struct descriptor *d; | ||
2709 | dma_addr_t d_bus, page_bus; | ||
2710 | int page, offset, rest, z, i, length; | ||
2711 | |||
2712 | page = payload >> PAGE_SHIFT; | ||
2713 | offset = payload & ~PAGE_MASK; | ||
2714 | rest = packet->payload_length; | ||
2715 | |||
2716 | /* We need one descriptor for each page in the buffer. */ | ||
2717 | z = DIV_ROUND_UP(offset + rest, PAGE_SIZE); | ||
2718 | |||
2719 | if (WARN_ON(offset & 3 || rest & 3 || page + z > buffer->page_count)) | ||
2720 | return -EFAULT; | ||
2721 | |||
2722 | for (i = 0; i < z; i++) { | ||
2723 | d = context_get_descriptors(&ctx->context, 1, &d_bus); | ||
2724 | if (d == NULL) | ||
2725 | return -ENOMEM; | ||
2726 | |||
2727 | d->control = cpu_to_le16(DESCRIPTOR_INPUT_MORE | | ||
2728 | DESCRIPTOR_BRANCH_ALWAYS); | ||
2729 | if (packet->skip && i == 0) | ||
2730 | d->control |= cpu_to_le16(DESCRIPTOR_WAIT); | ||
2731 | if (packet->interrupt && i == z - 1) | ||
2732 | d->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS); | ||
2733 | |||
2734 | if (offset + rest < PAGE_SIZE) | ||
2735 | length = rest; | ||
2736 | else | ||
2737 | length = PAGE_SIZE - offset; | ||
2738 | d->req_count = cpu_to_le16(length); | ||
2739 | d->res_count = d->req_count; | ||
2740 | d->transfer_status = 0; | ||
2741 | |||
2742 | page_bus = page_private(buffer->pages[page]); | ||
2743 | d->data_address = cpu_to_le32(page_bus + offset); | ||
2744 | |||
2745 | rest -= length; | ||
2746 | offset = 0; | ||
2747 | page++; | ||
2748 | |||
2749 | context_append(&ctx->context, d, 1, 0); | ||
2750 | } | ||
2751 | |||
2752 | return 0; | ||
2753 | } | ||
2754 | |||
2269 | static int ohci_queue_iso(struct fw_iso_context *base, | 2755 | static int ohci_queue_iso(struct fw_iso_context *base, |
2270 | struct fw_iso_packet *packet, | 2756 | struct fw_iso_packet *packet, |
2271 | struct fw_iso_buffer *buffer, | 2757 | struct fw_iso_buffer *buffer, |
@@ -2273,14 +2759,20 @@ static int ohci_queue_iso(struct fw_iso_context *base, | |||
2273 | { | 2759 | { |
2274 | struct iso_context *ctx = container_of(base, struct iso_context, base); | 2760 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
2275 | unsigned long flags; | 2761 | unsigned long flags; |
2276 | int ret; | 2762 | int ret = -ENOSYS; |
2277 | 2763 | ||
2278 | spin_lock_irqsave(&ctx->context.ohci->lock, flags); | 2764 | spin_lock_irqsave(&ctx->context.ohci->lock, flags); |
2279 | if (base->type == FW_ISO_CONTEXT_TRANSMIT) | 2765 | switch (base->type) { |
2280 | ret = ohci_queue_iso_transmit(base, packet, buffer, payload); | 2766 | case FW_ISO_CONTEXT_TRANSMIT: |
2281 | else | 2767 | ret = queue_iso_transmit(ctx, packet, buffer, payload); |
2282 | ret = ohci_queue_iso_receive_packet_per_buffer(base, packet, | 2768 | break; |
2283 | buffer, payload); | 2769 | case FW_ISO_CONTEXT_RECEIVE: |
2770 | ret = queue_iso_packet_per_buffer(ctx, packet, buffer, payload); | ||
2771 | break; | ||
2772 | case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: | ||
2773 | ret = queue_iso_buffer_fill(ctx, packet, buffer, payload); | ||
2774 | break; | ||
2775 | } | ||
2284 | spin_unlock_irqrestore(&ctx->context.ohci->lock, flags); | 2776 | spin_unlock_irqrestore(&ctx->context.ohci->lock, flags); |
2285 | 2777 | ||
2286 | return ret; | 2778 | return ret; |
@@ -2288,23 +2780,26 @@ static int ohci_queue_iso(struct fw_iso_context *base, | |||
2288 | 2780 | ||
2289 | static const struct fw_card_driver ohci_driver = { | 2781 | static const struct fw_card_driver ohci_driver = { |
2290 | .enable = ohci_enable, | 2782 | .enable = ohci_enable, |
2783 | .read_phy_reg = ohci_read_phy_reg, | ||
2291 | .update_phy_reg = ohci_update_phy_reg, | 2784 | .update_phy_reg = ohci_update_phy_reg, |
2292 | .set_config_rom = ohci_set_config_rom, | 2785 | .set_config_rom = ohci_set_config_rom, |
2293 | .send_request = ohci_send_request, | 2786 | .send_request = ohci_send_request, |
2294 | .send_response = ohci_send_response, | 2787 | .send_response = ohci_send_response, |
2295 | .cancel_packet = ohci_cancel_packet, | 2788 | .cancel_packet = ohci_cancel_packet, |
2296 | .enable_phys_dma = ohci_enable_phys_dma, | 2789 | .enable_phys_dma = ohci_enable_phys_dma, |
2297 | .get_cycle_time = ohci_get_cycle_time, | 2790 | .read_csr = ohci_read_csr, |
2791 | .write_csr = ohci_write_csr, | ||
2298 | 2792 | ||
2299 | .allocate_iso_context = ohci_allocate_iso_context, | 2793 | .allocate_iso_context = ohci_allocate_iso_context, |
2300 | .free_iso_context = ohci_free_iso_context, | 2794 | .free_iso_context = ohci_free_iso_context, |
2795 | .set_iso_channels = ohci_set_iso_channels, | ||
2301 | .queue_iso = ohci_queue_iso, | 2796 | .queue_iso = ohci_queue_iso, |
2302 | .start_iso = ohci_start_iso, | 2797 | .start_iso = ohci_start_iso, |
2303 | .stop_iso = ohci_stop_iso, | 2798 | .stop_iso = ohci_stop_iso, |
2304 | }; | 2799 | }; |
2305 | 2800 | ||
2306 | #ifdef CONFIG_PPC_PMAC | 2801 | #ifdef CONFIG_PPC_PMAC |
2307 | static void ohci_pmac_on(struct pci_dev *dev) | 2802 | static void pmac_ohci_on(struct pci_dev *dev) |
2308 | { | 2803 | { |
2309 | if (machine_is(powermac)) { | 2804 | if (machine_is(powermac)) { |
2310 | struct device_node *ofn = pci_device_to_OF_node(dev); | 2805 | struct device_node *ofn = pci_device_to_OF_node(dev); |
@@ -2316,7 +2811,7 @@ static void ohci_pmac_on(struct pci_dev *dev) | |||
2316 | } | 2811 | } |
2317 | } | 2812 | } |
2318 | 2813 | ||
2319 | static void ohci_pmac_off(struct pci_dev *dev) | 2814 | static void pmac_ohci_off(struct pci_dev *dev) |
2320 | { | 2815 | { |
2321 | if (machine_is(powermac)) { | 2816 | if (machine_is(powermac)) { |
2322 | struct device_node *ofn = pci_device_to_OF_node(dev); | 2817 | struct device_node *ofn = pci_device_to_OF_node(dev); |
@@ -2328,15 +2823,15 @@ static void ohci_pmac_off(struct pci_dev *dev) | |||
2328 | } | 2823 | } |
2329 | } | 2824 | } |
2330 | #else | 2825 | #else |
2331 | #define ohci_pmac_on(dev) | 2826 | static inline void pmac_ohci_on(struct pci_dev *dev) {} |
2332 | #define ohci_pmac_off(dev) | 2827 | static inline void pmac_ohci_off(struct pci_dev *dev) {} |
2333 | #endif /* CONFIG_PPC_PMAC */ | 2828 | #endif /* CONFIG_PPC_PMAC */ |
2334 | 2829 | ||
2335 | static int __devinit pci_probe(struct pci_dev *dev, | 2830 | static int __devinit pci_probe(struct pci_dev *dev, |
2336 | const struct pci_device_id *ent) | 2831 | const struct pci_device_id *ent) |
2337 | { | 2832 | { |
2338 | struct fw_ohci *ohci; | 2833 | struct fw_ohci *ohci; |
2339 | u32 bus_options, max_receive, link_speed, version; | 2834 | u32 bus_options, max_receive, link_speed, version, link_enh; |
2340 | u64 guid; | 2835 | u64 guid; |
2341 | int i, err, n_ir, n_it; | 2836 | int i, err, n_ir, n_it; |
2342 | size_t size; | 2837 | size_t size; |
@@ -2349,7 +2844,7 @@ static int __devinit pci_probe(struct pci_dev *dev, | |||
2349 | 2844 | ||
2350 | fw_card_initialize(&ohci->card, &ohci_driver, &dev->dev); | 2845 | fw_card_initialize(&ohci->card, &ohci_driver, &dev->dev); |
2351 | 2846 | ||
2352 | ohci_pmac_on(dev); | 2847 | pmac_ohci_on(dev); |
2353 | 2848 | ||
2354 | err = pci_enable_device(dev); | 2849 | err = pci_enable_device(dev); |
2355 | if (err) { | 2850 | if (err) { |
@@ -2362,6 +2857,7 @@ static int __devinit pci_probe(struct pci_dev *dev, | |||
2362 | pci_set_drvdata(dev, ohci); | 2857 | pci_set_drvdata(dev, ohci); |
2363 | 2858 | ||
2364 | spin_lock_init(&ohci->lock); | 2859 | spin_lock_init(&ohci->lock); |
2860 | mutex_init(&ohci->phy_reg_mutex); | ||
2365 | 2861 | ||
2366 | tasklet_init(&ohci->bus_reset_tasklet, | 2862 | tasklet_init(&ohci->bus_reset_tasklet, |
2367 | bus_reset_tasklet, (unsigned long)ohci); | 2863 | bus_reset_tasklet, (unsigned long)ohci); |
@@ -2389,6 +2885,23 @@ static int __devinit pci_probe(struct pci_dev *dev, | |||
2389 | if (param_quirks) | 2885 | if (param_quirks) |
2390 | ohci->quirks = param_quirks; | 2886 | ohci->quirks = param_quirks; |
2391 | 2887 | ||
2888 | /* TI OHCI-Lynx and compatible: set recommended configuration bits. */ | ||
2889 | if (dev->vendor == PCI_VENDOR_ID_TI) { | ||
2890 | pci_read_config_dword(dev, PCI_CFG_TI_LinkEnh, &link_enh); | ||
2891 | |||
2892 | /* adjust latency of ATx FIFO: use 1.7 KB threshold */ | ||
2893 | link_enh &= ~TI_LinkEnh_atx_thresh_mask; | ||
2894 | link_enh |= TI_LinkEnh_atx_thresh_1_7K; | ||
2895 | |||
2896 | /* use priority arbitration for asynchronous responses */ | ||
2897 | link_enh |= TI_LinkEnh_enab_unfair; | ||
2898 | |||
2899 | /* required for aPhyEnhanceEnable to work */ | ||
2900 | link_enh |= TI_LinkEnh_enab_accel; | ||
2901 | |||
2902 | pci_write_config_dword(dev, PCI_CFG_TI_LinkEnh, link_enh); | ||
2903 | } | ||
2904 | |||
2392 | ar_context_init(&ohci->ar_request_ctx, ohci, | 2905 | ar_context_init(&ohci->ar_request_ctx, ohci, |
2393 | OHCI1394_AsReqRcvContextControlSet); | 2906 | OHCI1394_AsReqRcvContextControlSet); |
2394 | 2907 | ||
@@ -2466,7 +2979,7 @@ static int __devinit pci_probe(struct pci_dev *dev, | |||
2466 | pci_disable_device(dev); | 2979 | pci_disable_device(dev); |
2467 | fail_free: | 2980 | fail_free: |
2468 | kfree(&ohci->card); | 2981 | kfree(&ohci->card); |
2469 | ohci_pmac_off(dev); | 2982 | pmac_ohci_off(dev); |
2470 | fail: | 2983 | fail: |
2471 | if (err == -ENOMEM) | 2984 | if (err == -ENOMEM) |
2472 | fw_error("Out of memory\n"); | 2985 | fw_error("Out of memory\n"); |
@@ -2505,11 +3018,12 @@ static void pci_remove(struct pci_dev *dev) | |||
2505 | context_release(&ohci->at_response_ctx); | 3018 | context_release(&ohci->at_response_ctx); |
2506 | kfree(ohci->it_context_list); | 3019 | kfree(ohci->it_context_list); |
2507 | kfree(ohci->ir_context_list); | 3020 | kfree(ohci->ir_context_list); |
3021 | pci_disable_msi(dev); | ||
2508 | pci_iounmap(dev, ohci->registers); | 3022 | pci_iounmap(dev, ohci->registers); |
2509 | pci_release_region(dev, 0); | 3023 | pci_release_region(dev, 0); |
2510 | pci_disable_device(dev); | 3024 | pci_disable_device(dev); |
2511 | kfree(&ohci->card); | 3025 | kfree(&ohci->card); |
2512 | ohci_pmac_off(dev); | 3026 | pmac_ohci_off(dev); |
2513 | 3027 | ||
2514 | fw_notify("Removed fw-ohci device.\n"); | 3028 | fw_notify("Removed fw-ohci device.\n"); |
2515 | } | 3029 | } |
@@ -2522,6 +3036,7 @@ static int pci_suspend(struct pci_dev *dev, pm_message_t state) | |||
2522 | 3036 | ||
2523 | software_reset(ohci); | 3037 | software_reset(ohci); |
2524 | free_irq(dev->irq, ohci); | 3038 | free_irq(dev->irq, ohci); |
3039 | pci_disable_msi(dev); | ||
2525 | err = pci_save_state(dev); | 3040 | err = pci_save_state(dev); |
2526 | if (err) { | 3041 | if (err) { |
2527 | fw_error("pci_save_state failed\n"); | 3042 | fw_error("pci_save_state failed\n"); |
@@ -2530,7 +3045,7 @@ static int pci_suspend(struct pci_dev *dev, pm_message_t state) | |||
2530 | err = pci_set_power_state(dev, pci_choose_state(dev, state)); | 3045 | err = pci_set_power_state(dev, pci_choose_state(dev, state)); |
2531 | if (err) | 3046 | if (err) |
2532 | fw_error("pci_set_power_state failed with %d\n", err); | 3047 | fw_error("pci_set_power_state failed with %d\n", err); |
2533 | ohci_pmac_off(dev); | 3048 | pmac_ohci_off(dev); |
2534 | 3049 | ||
2535 | return 0; | 3050 | return 0; |
2536 | } | 3051 | } |
@@ -2540,7 +3055,7 @@ static int pci_resume(struct pci_dev *dev) | |||
2540 | struct fw_ohci *ohci = pci_get_drvdata(dev); | 3055 | struct fw_ohci *ohci = pci_get_drvdata(dev); |
2541 | int err; | 3056 | int err; |
2542 | 3057 | ||
2543 | ohci_pmac_on(dev); | 3058 | pmac_ohci_on(dev); |
2544 | pci_set_power_state(dev, PCI_D0); | 3059 | pci_set_power_state(dev, PCI_D0); |
2545 | pci_restore_state(dev); | 3060 | pci_restore_state(dev); |
2546 | err = pci_enable_device(dev); | 3061 | err = pci_enable_device(dev); |
diff --git a/drivers/firewire/ohci.h b/drivers/firewire/ohci.h index ba492d85c516..0e6c5a466908 100644 --- a/drivers/firewire/ohci.h +++ b/drivers/firewire/ohci.h | |||
@@ -60,6 +60,7 @@ | |||
60 | #define OHCI1394_LinkControl_cycleSource (1 << 22) | 60 | #define OHCI1394_LinkControl_cycleSource (1 << 22) |
61 | #define OHCI1394_NodeID 0x0E8 | 61 | #define OHCI1394_NodeID 0x0E8 |
62 | #define OHCI1394_NodeID_idValid 0x80000000 | 62 | #define OHCI1394_NodeID_idValid 0x80000000 |
63 | #define OHCI1394_NodeID_root 0x40000000 | ||
63 | #define OHCI1394_NodeID_nodeNumber 0x0000003f | 64 | #define OHCI1394_NodeID_nodeNumber 0x0000003f |
64 | #define OHCI1394_NodeID_busNumber 0x0000ffc0 | 65 | #define OHCI1394_NodeID_busNumber 0x0000ffc0 |
65 | #define OHCI1394_PhyControl 0x0EC | 66 | #define OHCI1394_PhyControl 0x0EC |
@@ -67,7 +68,7 @@ | |||
67 | #define OHCI1394_PhyControl_ReadDone 0x80000000 | 68 | #define OHCI1394_PhyControl_ReadDone 0x80000000 |
68 | #define OHCI1394_PhyControl_ReadData(r) (((r) & 0x00ff0000) >> 16) | 69 | #define OHCI1394_PhyControl_ReadData(r) (((r) & 0x00ff0000) >> 16) |
69 | #define OHCI1394_PhyControl_Write(addr, data) (((addr) << 8) | (data) | 0x00004000) | 70 | #define OHCI1394_PhyControl_Write(addr, data) (((addr) << 8) | (data) | 0x00004000) |
70 | #define OHCI1394_PhyControl_WriteDone 0x00004000 | 71 | #define OHCI1394_PhyControl_WritePending 0x00004000 |
71 | #define OHCI1394_IsochronousCycleTimer 0x0F0 | 72 | #define OHCI1394_IsochronousCycleTimer 0x0F0 |
72 | #define OHCI1394_AsReqFilterHiSet 0x100 | 73 | #define OHCI1394_AsReqFilterHiSet 0x100 |
73 | #define OHCI1394_AsReqFilterHiClear 0x104 | 74 | #define OHCI1394_AsReqFilterHiClear 0x104 |
@@ -154,4 +155,12 @@ | |||
154 | 155 | ||
155 | #define OHCI1394_phy_tcode 0xe | 156 | #define OHCI1394_phy_tcode 0xe |
156 | 157 | ||
158 | /* TI extensions */ | ||
159 | |||
160 | #define PCI_CFG_TI_LinkEnh 0xf4 | ||
161 | #define TI_LinkEnh_enab_accel 0x00000002 | ||
162 | #define TI_LinkEnh_enab_unfair 0x00000080 | ||
163 | #define TI_LinkEnh_atx_thresh_mask 0x00003000 | ||
164 | #define TI_LinkEnh_atx_thresh_1_7K 0x00001000 | ||
165 | |||
157 | #endif /* _FIREWIRE_OHCI_H */ | 166 | #endif /* _FIREWIRE_OHCI_H */ |
diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c index ca264f2fdf0c..9f76171717e5 100644 --- a/drivers/firewire/sbp2.c +++ b/drivers/firewire/sbp2.c | |||
@@ -410,8 +410,7 @@ static void free_orb(struct kref *kref) | |||
410 | 410 | ||
411 | static void sbp2_status_write(struct fw_card *card, struct fw_request *request, | 411 | static void sbp2_status_write(struct fw_card *card, struct fw_request *request, |
412 | int tcode, int destination, int source, | 412 | int tcode, int destination, int source, |
413 | int generation, int speed, | 413 | int generation, unsigned long long offset, |
414 | unsigned long long offset, | ||
415 | void *payload, size_t length, void *callback_data) | 414 | void *payload, size_t length, void *callback_data) |
416 | { | 415 | { |
417 | struct sbp2_logical_unit *lu = callback_data; | 416 | struct sbp2_logical_unit *lu = callback_data; |
@@ -508,8 +507,7 @@ static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu, | |||
508 | 507 | ||
509 | fw_send_request(device->card, &orb->t, TCODE_WRITE_BLOCK_REQUEST, | 508 | fw_send_request(device->card, &orb->t, TCODE_WRITE_BLOCK_REQUEST, |
510 | node_id, generation, device->max_speed, offset, | 509 | node_id, generation, device->max_speed, offset, |
511 | &orb->pointer, sizeof(orb->pointer), | 510 | &orb->pointer, 8, complete_transaction, orb); |
512 | complete_transaction, orb); | ||
513 | } | 511 | } |
514 | 512 | ||
515 | static int sbp2_cancel_orbs(struct sbp2_logical_unit *lu) | 513 | static int sbp2_cancel_orbs(struct sbp2_logical_unit *lu) |
@@ -654,7 +652,7 @@ static void sbp2_agent_reset(struct sbp2_logical_unit *lu) | |||
654 | fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, | 652 | fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, |
655 | lu->tgt->node_id, lu->generation, device->max_speed, | 653 | lu->tgt->node_id, lu->generation, device->max_speed, |
656 | lu->command_block_agent_address + SBP2_AGENT_RESET, | 654 | lu->command_block_agent_address + SBP2_AGENT_RESET, |
657 | &d, sizeof(d)); | 655 | &d, 4); |
658 | } | 656 | } |
659 | 657 | ||
660 | static void complete_agent_reset_write_no_wait(struct fw_card *card, | 658 | static void complete_agent_reset_write_no_wait(struct fw_card *card, |
@@ -676,7 +674,7 @@ static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu) | |||
676 | fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST, | 674 | fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST, |
677 | lu->tgt->node_id, lu->generation, device->max_speed, | 675 | lu->tgt->node_id, lu->generation, device->max_speed, |
678 | lu->command_block_agent_address + SBP2_AGENT_RESET, | 676 | lu->command_block_agent_address + SBP2_AGENT_RESET, |
679 | &d, sizeof(d), complete_agent_reset_write_no_wait, t); | 677 | &d, 4, complete_agent_reset_write_no_wait, t); |
680 | } | 678 | } |
681 | 679 | ||
682 | static inline void sbp2_allow_block(struct sbp2_logical_unit *lu) | 680 | static inline void sbp2_allow_block(struct sbp2_logical_unit *lu) |
@@ -866,8 +864,7 @@ static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu) | |||
866 | 864 | ||
867 | fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, | 865 | fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, |
868 | lu->tgt->node_id, lu->generation, device->max_speed, | 866 | lu->tgt->node_id, lu->generation, device->max_speed, |
869 | CSR_REGISTER_BASE + CSR_BUSY_TIMEOUT, | 867 | CSR_REGISTER_BASE + CSR_BUSY_TIMEOUT, &d, 4); |
870 | &d, sizeof(d)); | ||
871 | } | 868 | } |
872 | 869 | ||
873 | static void sbp2_reconnect(struct work_struct *work); | 870 | static void sbp2_reconnect(struct work_struct *work); |