diff options
author | David S. Miller <davem@davemloft.net> | 2008-03-18 03:37:55 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-03-18 03:37:55 -0400 |
commit | 577f99c1d08cf9cbdafd4e858dd13ff04d855090 (patch) | |
tree | 0f726bbda9b18d311d4c95198bbd96cb7ac01db0 /drivers/firewire/fw-ohci.c | |
parent | 26c0f03f6b77c513cb7bc37b73a06819bdbb791b (diff) | |
parent | 2f633928cbba8a5858bb39b11e7219a41b0fbef5 (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
Conflicts:
drivers/net/wireless/rt2x00/rt2x00dev.c
net/8021q/vlan_dev.c
Diffstat (limited to 'drivers/firewire/fw-ohci.c')
-rw-r--r-- | drivers/firewire/fw-ohci.c | 108 |
1 files changed, 81 insertions, 27 deletions
diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c index 7ebad3c14cb8..996d61f0d460 100644 --- a/drivers/firewire/fw-ohci.c +++ b/drivers/firewire/fw-ohci.c | |||
@@ -33,6 +33,10 @@ | |||
33 | #include <asm/page.h> | 33 | #include <asm/page.h> |
34 | #include <asm/system.h> | 34 | #include <asm/system.h> |
35 | 35 | ||
36 | #ifdef CONFIG_PPC_PMAC | ||
37 | #include <asm/pmac_feature.h> | ||
38 | #endif | ||
39 | |||
36 | #include "fw-ohci.h" | 40 | #include "fw-ohci.h" |
37 | #include "fw-transaction.h" | 41 | #include "fw-transaction.h" |
38 | 42 | ||
@@ -175,6 +179,7 @@ struct fw_ohci { | |||
175 | int generation; | 179 | int generation; |
176 | int request_generation; | 180 | int request_generation; |
177 | u32 bus_seconds; | 181 | u32 bus_seconds; |
182 | bool old_uninorth; | ||
178 | 183 | ||
179 | /* | 184 | /* |
180 | * Spinlock for accessing fw_ohci data. Never call out of | 185 | * Spinlock for accessing fw_ohci data. Never call out of |
@@ -276,19 +281,13 @@ static int ar_context_add_page(struct ar_context *ctx) | |||
276 | { | 281 | { |
277 | struct device *dev = ctx->ohci->card.device; | 282 | struct device *dev = ctx->ohci->card.device; |
278 | struct ar_buffer *ab; | 283 | struct ar_buffer *ab; |
279 | dma_addr_t ab_bus; | 284 | dma_addr_t uninitialized_var(ab_bus); |
280 | size_t offset; | 285 | size_t offset; |
281 | 286 | ||
282 | ab = (struct ar_buffer *) __get_free_page(GFP_ATOMIC); | 287 | ab = dma_alloc_coherent(dev, PAGE_SIZE, &ab_bus, GFP_ATOMIC); |
283 | if (ab == NULL) | 288 | if (ab == NULL) |
284 | return -ENOMEM; | 289 | return -ENOMEM; |
285 | 290 | ||
286 | ab_bus = dma_map_single(dev, ab, PAGE_SIZE, DMA_BIDIRECTIONAL); | ||
287 | if (dma_mapping_error(ab_bus)) { | ||
288 | free_page((unsigned long) ab); | ||
289 | return -ENOMEM; | ||
290 | } | ||
291 | |||
292 | memset(&ab->descriptor, 0, sizeof(ab->descriptor)); | 291 | memset(&ab->descriptor, 0, sizeof(ab->descriptor)); |
293 | ab->descriptor.control = cpu_to_le16(DESCRIPTOR_INPUT_MORE | | 292 | ab->descriptor.control = cpu_to_le16(DESCRIPTOR_INPUT_MORE | |
294 | DESCRIPTOR_STATUS | | 293 | DESCRIPTOR_STATUS | |
@@ -299,8 +298,6 @@ static int ar_context_add_page(struct ar_context *ctx) | |||
299 | ab->descriptor.res_count = cpu_to_le16(PAGE_SIZE - offset); | 298 | ab->descriptor.res_count = cpu_to_le16(PAGE_SIZE - offset); |
300 | ab->descriptor.branch_address = 0; | 299 | ab->descriptor.branch_address = 0; |
301 | 300 | ||
302 | dma_sync_single_for_device(dev, ab_bus, PAGE_SIZE, DMA_BIDIRECTIONAL); | ||
303 | |||
304 | ctx->last_buffer->descriptor.branch_address = cpu_to_le32(ab_bus | 1); | 301 | ctx->last_buffer->descriptor.branch_address = cpu_to_le32(ab_bus | 1); |
305 | ctx->last_buffer->next = ab; | 302 | ctx->last_buffer->next = ab; |
306 | ctx->last_buffer = ab; | 303 | ctx->last_buffer = ab; |
@@ -311,15 +308,22 @@ static int ar_context_add_page(struct ar_context *ctx) | |||
311 | return 0; | 308 | return 0; |
312 | } | 309 | } |
313 | 310 | ||
311 | #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) | ||
312 | #define cond_le32_to_cpu(v) \ | ||
313 | (ohci->old_uninorth ? (__force __u32)(v) : le32_to_cpu(v)) | ||
314 | #else | ||
315 | #define cond_le32_to_cpu(v) le32_to_cpu(v) | ||
316 | #endif | ||
317 | |||
314 | static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer) | 318 | static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer) |
315 | { | 319 | { |
316 | struct fw_ohci *ohci = ctx->ohci; | 320 | struct fw_ohci *ohci = ctx->ohci; |
317 | struct fw_packet p; | 321 | struct fw_packet p; |
318 | u32 status, length, tcode; | 322 | u32 status, length, tcode; |
319 | 323 | ||
320 | p.header[0] = le32_to_cpu(buffer[0]); | 324 | p.header[0] = cond_le32_to_cpu(buffer[0]); |
321 | p.header[1] = le32_to_cpu(buffer[1]); | 325 | p.header[1] = cond_le32_to_cpu(buffer[1]); |
322 | p.header[2] = le32_to_cpu(buffer[2]); | 326 | p.header[2] = cond_le32_to_cpu(buffer[2]); |
323 | 327 | ||
324 | tcode = (p.header[0] >> 4) & 0x0f; | 328 | tcode = (p.header[0] >> 4) & 0x0f; |
325 | switch (tcode) { | 329 | switch (tcode) { |
@@ -331,7 +335,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer) | |||
331 | break; | 335 | break; |
332 | 336 | ||
333 | case TCODE_READ_BLOCK_REQUEST : | 337 | case TCODE_READ_BLOCK_REQUEST : |
334 | p.header[3] = le32_to_cpu(buffer[3]); | 338 | p.header[3] = cond_le32_to_cpu(buffer[3]); |
335 | p.header_length = 16; | 339 | p.header_length = 16; |
336 | p.payload_length = 0; | 340 | p.payload_length = 0; |
337 | break; | 341 | break; |
@@ -340,7 +344,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer) | |||
340 | case TCODE_READ_BLOCK_RESPONSE: | 344 | case TCODE_READ_BLOCK_RESPONSE: |
341 | case TCODE_LOCK_REQUEST: | 345 | case TCODE_LOCK_REQUEST: |
342 | case TCODE_LOCK_RESPONSE: | 346 | case TCODE_LOCK_RESPONSE: |
343 | p.header[3] = le32_to_cpu(buffer[3]); | 347 | p.header[3] = cond_le32_to_cpu(buffer[3]); |
344 | p.header_length = 16; | 348 | p.header_length = 16; |
345 | p.payload_length = p.header[3] >> 16; | 349 | p.payload_length = p.header[3] >> 16; |
346 | break; | 350 | break; |
@@ -357,7 +361,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer) | |||
357 | 361 | ||
358 | /* FIXME: What to do about evt_* errors? */ | 362 | /* FIXME: What to do about evt_* errors? */ |
359 | length = (p.header_length + p.payload_length + 3) / 4; | 363 | length = (p.header_length + p.payload_length + 3) / 4; |
360 | status = le32_to_cpu(buffer[length]); | 364 | status = cond_le32_to_cpu(buffer[length]); |
361 | 365 | ||
362 | p.ack = ((status >> 16) & 0x1f) - 16; | 366 | p.ack = ((status >> 16) & 0x1f) - 16; |
363 | p.speed = (status >> 21) & 0x7; | 367 | p.speed = (status >> 21) & 0x7; |
@@ -375,7 +379,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer) | |||
375 | */ | 379 | */ |
376 | 380 | ||
377 | if (p.ack + 16 == 0x09) | 381 | if (p.ack + 16 == 0x09) |
378 | ohci->request_generation = (buffer[2] >> 16) & 0xff; | 382 | ohci->request_generation = (p.header[2] >> 16) & 0xff; |
379 | else if (ctx == &ohci->ar_request_ctx) | 383 | else if (ctx == &ohci->ar_request_ctx) |
380 | fw_core_handle_request(&ohci->card, &p); | 384 | fw_core_handle_request(&ohci->card, &p); |
381 | else | 385 | else |
@@ -397,6 +401,7 @@ static void ar_context_tasklet(unsigned long data) | |||
397 | 401 | ||
398 | if (d->res_count == 0) { | 402 | if (d->res_count == 0) { |
399 | size_t size, rest, offset; | 403 | size_t size, rest, offset; |
404 | dma_addr_t buffer_bus; | ||
400 | 405 | ||
401 | /* | 406 | /* |
402 | * This descriptor is finished and we may have a | 407 | * This descriptor is finished and we may have a |
@@ -405,9 +410,7 @@ static void ar_context_tasklet(unsigned long data) | |||
405 | */ | 410 | */ |
406 | 411 | ||
407 | offset = offsetof(struct ar_buffer, data); | 412 | offset = offsetof(struct ar_buffer, data); |
408 | dma_unmap_single(ohci->card.device, | 413 | buffer_bus = le32_to_cpu(ab->descriptor.data_address) - offset; |
409 | le32_to_cpu(ab->descriptor.data_address) - offset, | ||
410 | PAGE_SIZE, DMA_BIDIRECTIONAL); | ||
411 | 414 | ||
412 | buffer = ab; | 415 | buffer = ab; |
413 | ab = ab->next; | 416 | ab = ab->next; |
@@ -423,7 +426,8 @@ static void ar_context_tasklet(unsigned long data) | |||
423 | while (buffer < end) | 426 | while (buffer < end) |
424 | buffer = handle_ar_packet(ctx, buffer); | 427 | buffer = handle_ar_packet(ctx, buffer); |
425 | 428 | ||
426 | free_page((unsigned long)buffer); | 429 | dma_free_coherent(ohci->card.device, PAGE_SIZE, |
430 | buffer, buffer_bus); | ||
427 | ar_context_add_page(ctx); | 431 | ar_context_add_page(ctx); |
428 | } else { | 432 | } else { |
429 | buffer = ctx->pointer; | 433 | buffer = ctx->pointer; |
@@ -532,7 +536,7 @@ static int | |||
532 | context_add_buffer(struct context *ctx) | 536 | context_add_buffer(struct context *ctx) |
533 | { | 537 | { |
534 | struct descriptor_buffer *desc; | 538 | struct descriptor_buffer *desc; |
535 | dma_addr_t bus_addr; | 539 | dma_addr_t uninitialized_var(bus_addr); |
536 | int offset; | 540 | int offset; |
537 | 541 | ||
538 | /* | 542 | /* |
@@ -1022,13 +1026,14 @@ static void bus_reset_tasklet(unsigned long data) | |||
1022 | */ | 1026 | */ |
1023 | 1027 | ||
1024 | self_id_count = (reg_read(ohci, OHCI1394_SelfIDCount) >> 3) & 0x3ff; | 1028 | self_id_count = (reg_read(ohci, OHCI1394_SelfIDCount) >> 3) & 0x3ff; |
1025 | generation = (le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff; | 1029 | generation = (cond_le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff; |
1026 | rmb(); | 1030 | rmb(); |
1027 | 1031 | ||
1028 | for (i = 1, j = 0; j < self_id_count; i += 2, j++) { | 1032 | for (i = 1, j = 0; j < self_id_count; i += 2, j++) { |
1029 | if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1]) | 1033 | if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1]) |
1030 | fw_error("inconsistent self IDs\n"); | 1034 | fw_error("inconsistent self IDs\n"); |
1031 | ohci->self_id_buffer[j] = le32_to_cpu(ohci->self_id_cpu[i]); | 1035 | ohci->self_id_buffer[j] = |
1036 | cond_le32_to_cpu(ohci->self_id_cpu[i]); | ||
1032 | } | 1037 | } |
1033 | rmb(); | 1038 | rmb(); |
1034 | 1039 | ||
@@ -1316,7 +1321,7 @@ ohci_set_config_rom(struct fw_card *card, u32 *config_rom, size_t length) | |||
1316 | unsigned long flags; | 1321 | unsigned long flags; |
1317 | int retval = -EBUSY; | 1322 | int retval = -EBUSY; |
1318 | __be32 *next_config_rom; | 1323 | __be32 *next_config_rom; |
1319 | dma_addr_t next_config_rom_bus; | 1324 | dma_addr_t uninitialized_var(next_config_rom_bus); |
1320 | 1325 | ||
1321 | ohci = fw_ohci(card); | 1326 | ohci = fw_ohci(card); |
1322 | 1327 | ||
@@ -1487,7 +1492,7 @@ static int handle_ir_dualbuffer_packet(struct context *context, | |||
1487 | void *p, *end; | 1492 | void *p, *end; |
1488 | int i; | 1493 | int i; |
1489 | 1494 | ||
1490 | if (db->first_res_count > 0 && db->second_res_count > 0) { | 1495 | if (db->first_res_count != 0 && db->second_res_count != 0) { |
1491 | if (ctx->excess_bytes <= le16_to_cpu(db->second_req_count)) { | 1496 | if (ctx->excess_bytes <= le16_to_cpu(db->second_req_count)) { |
1492 | /* This descriptor isn't done yet, stop iteration. */ | 1497 | /* This descriptor isn't done yet, stop iteration. */ |
1493 | return 0; | 1498 | return 0; |
@@ -1513,7 +1518,7 @@ static int handle_ir_dualbuffer_packet(struct context *context, | |||
1513 | memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4); | 1518 | memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4); |
1514 | i += ctx->base.header_size; | 1519 | i += ctx->base.header_size; |
1515 | ctx->excess_bytes += | 1520 | ctx->excess_bytes += |
1516 | (le32_to_cpu(*(u32 *)(p + 4)) >> 16) & 0xffff; | 1521 | (le32_to_cpu(*(__le32 *)(p + 4)) >> 16) & 0xffff; |
1517 | p += ctx->base.header_size + 4; | 1522 | p += ctx->base.header_size + 4; |
1518 | } | 1523 | } |
1519 | ctx->header_length = i; | 1524 | ctx->header_length = i; |
@@ -2048,6 +2053,18 @@ pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) | |||
2048 | int err; | 2053 | int err; |
2049 | size_t size; | 2054 | size_t size; |
2050 | 2055 | ||
2056 | #ifdef CONFIG_PPC_PMAC | ||
2057 | /* Necessary on some machines if fw-ohci was loaded/ unloaded before */ | ||
2058 | if (machine_is(powermac)) { | ||
2059 | struct device_node *ofn = pci_device_to_OF_node(dev); | ||
2060 | |||
2061 | if (ofn) { | ||
2062 | pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, ofn, 0, 1); | ||
2063 | pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 1); | ||
2064 | } | ||
2065 | } | ||
2066 | #endif /* CONFIG_PPC_PMAC */ | ||
2067 | |||
2051 | ohci = kzalloc(sizeof(*ohci), GFP_KERNEL); | 2068 | ohci = kzalloc(sizeof(*ohci), GFP_KERNEL); |
2052 | if (ohci == NULL) { | 2069 | if (ohci == NULL) { |
2053 | fw_error("Could not malloc fw_ohci data.\n"); | 2070 | fw_error("Could not malloc fw_ohci data.\n"); |
@@ -2066,6 +2083,10 @@ pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) | |||
2066 | pci_write_config_dword(dev, OHCI1394_PCI_HCI_Control, 0); | 2083 | pci_write_config_dword(dev, OHCI1394_PCI_HCI_Control, 0); |
2067 | pci_set_drvdata(dev, ohci); | 2084 | pci_set_drvdata(dev, ohci); |
2068 | 2085 | ||
2086 | #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) | ||
2087 | ohci->old_uninorth = dev->vendor == PCI_VENDOR_ID_APPLE && | ||
2088 | dev->device == PCI_DEVICE_ID_APPLE_UNI_N_FW; | ||
2089 | #endif | ||
2069 | spin_lock_init(&ohci->lock); | 2090 | spin_lock_init(&ohci->lock); |
2070 | 2091 | ||
2071 | tasklet_init(&ohci->bus_reset_tasklet, | 2092 | tasklet_init(&ohci->bus_reset_tasklet, |
@@ -2182,6 +2203,19 @@ static void pci_remove(struct pci_dev *dev) | |||
2182 | pci_disable_device(dev); | 2203 | pci_disable_device(dev); |
2183 | fw_card_put(&ohci->card); | 2204 | fw_card_put(&ohci->card); |
2184 | 2205 | ||
2206 | #ifdef CONFIG_PPC_PMAC | ||
2207 | /* On UniNorth, power down the cable and turn off the chip clock | ||
2208 | * to save power on laptops */ | ||
2209 | if (machine_is(powermac)) { | ||
2210 | struct device_node *ofn = pci_device_to_OF_node(dev); | ||
2211 | |||
2212 | if (ofn) { | ||
2213 | pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 0); | ||
2214 | pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, ofn, 0, 0); | ||
2215 | } | ||
2216 | } | ||
2217 | #endif /* CONFIG_PPC_PMAC */ | ||
2218 | |||
2185 | fw_notify("Removed fw-ohci device.\n"); | 2219 | fw_notify("Removed fw-ohci device.\n"); |
2186 | } | 2220 | } |
2187 | 2221 | ||
@@ -2202,6 +2236,16 @@ static int pci_suspend(struct pci_dev *pdev, pm_message_t state) | |||
2202 | if (err) | 2236 | if (err) |
2203 | fw_error("pci_set_power_state failed with %d\n", err); | 2237 | fw_error("pci_set_power_state failed with %d\n", err); |
2204 | 2238 | ||
2239 | /* PowerMac suspend code comes last */ | ||
2240 | #ifdef CONFIG_PPC_PMAC | ||
2241 | if (machine_is(powermac)) { | ||
2242 | struct device_node *ofn = pci_device_to_OF_node(pdev); | ||
2243 | |||
2244 | if (ofn) | ||
2245 | pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 0); | ||
2246 | } | ||
2247 | #endif /* CONFIG_PPC_PMAC */ | ||
2248 | |||
2205 | return 0; | 2249 | return 0; |
2206 | } | 2250 | } |
2207 | 2251 | ||
@@ -2210,6 +2254,16 @@ static int pci_resume(struct pci_dev *pdev) | |||
2210 | struct fw_ohci *ohci = pci_get_drvdata(pdev); | 2254 | struct fw_ohci *ohci = pci_get_drvdata(pdev); |
2211 | int err; | 2255 | int err; |
2212 | 2256 | ||
2257 | /* PowerMac resume code comes first */ | ||
2258 | #ifdef CONFIG_PPC_PMAC | ||
2259 | if (machine_is(powermac)) { | ||
2260 | struct device_node *ofn = pci_device_to_OF_node(pdev); | ||
2261 | |||
2262 | if (ofn) | ||
2263 | pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 1); | ||
2264 | } | ||
2265 | #endif /* CONFIG_PPC_PMAC */ | ||
2266 | |||
2213 | pci_set_power_state(pdev, PCI_D0); | 2267 | pci_set_power_state(pdev, PCI_D0); |
2214 | pci_restore_state(pdev); | 2268 | pci_restore_state(pdev); |
2215 | err = pci_enable_device(pdev); | 2269 | err = pci_enable_device(pdev); |