diff options
Diffstat (limited to 'drivers')
272 files changed, 21725 insertions, 3536 deletions
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c index 95650f83ce2e..bc46de3d967f 100644 --- a/drivers/acpi/pci_bind.c +++ b/drivers/acpi/pci_bind.c | |||
@@ -116,9 +116,6 @@ int acpi_pci_bind(struct acpi_device *device) | |||
116 | struct acpi_pci_data *pdata; | 116 | struct acpi_pci_data *pdata; |
117 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 117 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
118 | acpi_handle handle; | 118 | acpi_handle handle; |
119 | struct pci_dev *dev; | ||
120 | struct pci_bus *bus; | ||
121 | |||
122 | 119 | ||
123 | if (!device || !device->parent) | 120 | if (!device || !device->parent) |
124 | return -EINVAL; | 121 | return -EINVAL; |
@@ -176,20 +173,9 @@ int acpi_pci_bind(struct acpi_device *device) | |||
176 | * Locate matching device in PCI namespace. If it doesn't exist | 173 | * Locate matching device in PCI namespace. If it doesn't exist |
177 | * this typically means that the device isn't currently inserted | 174 | * this typically means that the device isn't currently inserted |
178 | * (e.g. docking station, port replicator, etc.). | 175 | * (e.g. docking station, port replicator, etc.). |
179 | * We cannot simply search the global pci device list, since | ||
180 | * PCI devices are added to the global pci list when the root | ||
181 | * bridge start ops are run, which may not have happened yet. | ||
182 | */ | 176 | */ |
183 | bus = pci_find_bus(data->id.segment, data->id.bus); | 177 | data->dev = pci_get_slot(pdata->bus, |
184 | if (bus) { | 178 | PCI_DEVFN(data->id.device, data->id.function)); |
185 | list_for_each_entry(dev, &bus->devices, bus_list) { | ||
186 | if (dev->devfn == PCI_DEVFN(data->id.device, | ||
187 | data->id.function)) { | ||
188 | data->dev = dev; | ||
189 | break; | ||
190 | } | ||
191 | } | ||
192 | } | ||
193 | if (!data->dev) { | 179 | if (!data->dev) { |
194 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 180 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
195 | "Device %04x:%02x:%02x.%d not present in PCI namespace\n", | 181 | "Device %04x:%02x:%02x.%d not present in PCI namespace\n", |
@@ -259,9 +245,10 @@ int acpi_pci_bind(struct acpi_device *device) | |||
259 | 245 | ||
260 | end: | 246 | end: |
261 | kfree(buffer.pointer); | 247 | kfree(buffer.pointer); |
262 | if (result) | 248 | if (result) { |
249 | pci_dev_put(data->dev); | ||
263 | kfree(data); | 250 | kfree(data); |
264 | 251 | } | |
265 | return result; | 252 | return result; |
266 | } | 253 | } |
267 | 254 | ||
@@ -303,6 +290,7 @@ static int acpi_pci_unbind(struct acpi_device *device) | |||
303 | if (data->dev->subordinate) { | 290 | if (data->dev->subordinate) { |
304 | acpi_pci_irq_del_prt(data->id.segment, data->bus->number); | 291 | acpi_pci_irq_del_prt(data->id.segment, data->bus->number); |
305 | } | 292 | } |
293 | pci_dev_put(data->dev); | ||
306 | kfree(data); | 294 | kfree(data); |
307 | 295 | ||
308 | end: | 296 | end: |
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c index 51b9f8280f88..2faa9e2ac893 100644 --- a/drivers/acpi/pci_irq.c +++ b/drivers/acpi/pci_irq.c | |||
@@ -401,7 +401,8 @@ int acpi_pci_irq_enable(struct pci_dev *dev) | |||
401 | /* Interrupt Line values above 0xF are forbidden */ | 401 | /* Interrupt Line values above 0xF are forbidden */ |
402 | if (dev->irq > 0 && (dev->irq <= 0xF)) { | 402 | if (dev->irq > 0 && (dev->irq <= 0xF)) { |
403 | printk(" - using IRQ %d\n", dev->irq); | 403 | printk(" - using IRQ %d\n", dev->irq); |
404 | acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE, | 404 | acpi_register_gsi(&dev->dev, dev->irq, |
405 | ACPI_LEVEL_SENSITIVE, | ||
405 | ACPI_ACTIVE_LOW); | 406 | ACPI_ACTIVE_LOW); |
406 | return 0; | 407 | return 0; |
407 | } else { | 408 | } else { |
@@ -410,7 +411,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev) | |||
410 | } | 411 | } |
411 | } | 412 | } |
412 | 413 | ||
413 | rc = acpi_register_gsi(gsi, triggering, polarity); | 414 | rc = acpi_register_gsi(&dev->dev, gsi, triggering, polarity); |
414 | if (rc < 0) { | 415 | if (rc < 0) { |
415 | dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n", | 416 | dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n", |
416 | pin_name(pin)); | 417 | pin_name(pin)); |
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c index 45ad3288c5ff..23f0fb84f1c1 100644 --- a/drivers/acpi/processor_core.c +++ b/drivers/acpi/processor_core.c | |||
@@ -844,7 +844,7 @@ static int acpi_processor_add(struct acpi_device *device) | |||
844 | if (!pr) | 844 | if (!pr) |
845 | return -ENOMEM; | 845 | return -ENOMEM; |
846 | 846 | ||
847 | if (!alloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) { | 847 | if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) { |
848 | kfree(pr); | 848 | kfree(pr); |
849 | return -ENOMEM; | 849 | return -ENOMEM; |
850 | } | 850 | } |
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 72069ba5f1ed..10a2d913635a 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c | |||
@@ -148,6 +148,9 @@ static void acpi_timer_check_state(int state, struct acpi_processor *pr, | |||
148 | if (cpu_has(&cpu_data(pr->id), X86_FEATURE_ARAT)) | 148 | if (cpu_has(&cpu_data(pr->id), X86_FEATURE_ARAT)) |
149 | return; | 149 | return; |
150 | 150 | ||
151 | if (boot_cpu_has(X86_FEATURE_AMDC1E)) | ||
152 | type = ACPI_STATE_C1; | ||
153 | |||
151 | /* | 154 | /* |
152 | * Check, if one of the previous states already marked the lapic | 155 | * Check, if one of the previous states already marked the lapic |
153 | * unstable | 156 | * unstable |
@@ -611,6 +614,7 @@ static int acpi_processor_power_verify(struct acpi_processor *pr) | |||
611 | switch (cx->type) { | 614 | switch (cx->type) { |
612 | case ACPI_STATE_C1: | 615 | case ACPI_STATE_C1: |
613 | cx->valid = 1; | 616 | cx->valid = 1; |
617 | acpi_timer_check_state(i, pr, cx); | ||
614 | break; | 618 | break; |
615 | 619 | ||
616 | case ACPI_STATE_C2: | 620 | case ACPI_STATE_C2: |
@@ -830,11 +834,12 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev, | |||
830 | 834 | ||
831 | /* Do not access any ACPI IO ports in suspend path */ | 835 | /* Do not access any ACPI IO ports in suspend path */ |
832 | if (acpi_idle_suspend) { | 836 | if (acpi_idle_suspend) { |
833 | acpi_safe_halt(); | ||
834 | local_irq_enable(); | 837 | local_irq_enable(); |
838 | cpu_relax(); | ||
835 | return 0; | 839 | return 0; |
836 | } | 840 | } |
837 | 841 | ||
842 | acpi_state_timer_broadcast(pr, cx, 1); | ||
838 | kt1 = ktime_get_real(); | 843 | kt1 = ktime_get_real(); |
839 | acpi_idle_do_entry(cx); | 844 | acpi_idle_do_entry(cx); |
840 | kt2 = ktime_get_real(); | 845 | kt2 = ktime_get_real(); |
@@ -842,6 +847,7 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev, | |||
842 | 847 | ||
843 | local_irq_enable(); | 848 | local_irq_enable(); |
844 | cx->usage++; | 849 | cx->usage++; |
850 | acpi_state_timer_broadcast(pr, cx, 0); | ||
845 | 851 | ||
846 | return idle_time; | 852 | return idle_time; |
847 | } | 853 | } |
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c index cafb41000f6b..60e543d3234e 100644 --- a/drivers/acpi/processor_perflib.c +++ b/drivers/acpi/processor_perflib.c | |||
@@ -309,9 +309,15 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr) | |||
309 | (u32) px->bus_master_latency, | 309 | (u32) px->bus_master_latency, |
310 | (u32) px->control, (u32) px->status)); | 310 | (u32) px->control, (u32) px->status)); |
311 | 311 | ||
312 | if (!px->core_frequency) { | 312 | /* |
313 | printk(KERN_ERR PREFIX | 313 | * Check that ACPI's u64 MHz will be valid as u32 KHz in cpufreq |
314 | "Invalid _PSS data: freq is zero\n"); | 314 | */ |
315 | if (!px->core_frequency || | ||
316 | ((u32)(px->core_frequency * 1000) != | ||
317 | (px->core_frequency * 1000))) { | ||
318 | printk(KERN_ERR FW_BUG PREFIX | ||
319 | "Invalid BIOS _PSS frequency: 0x%llx MHz\n", | ||
320 | px->core_frequency); | ||
315 | result = -EFAULT; | 321 | result = -EFAULT; |
316 | kfree(pr->performance->states); | 322 | kfree(pr->performance->states); |
317 | goto end; | 323 | goto end; |
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c index 7f16f5f8e7d3..227543789ba9 100644 --- a/drivers/acpi/processor_throttling.c +++ b/drivers/acpi/processor_throttling.c | |||
@@ -840,7 +840,7 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) | |||
840 | state = acpi_get_throttling_state(pr, value); | 840 | state = acpi_get_throttling_state(pr, value); |
841 | if (state == -1) { | 841 | if (state == -1) { |
842 | ACPI_WARNING((AE_INFO, | 842 | ACPI_WARNING((AE_INFO, |
843 | "Invalid throttling state, reset\n")); | 843 | "Invalid throttling state, reset")); |
844 | state = 0; | 844 | state = 0; |
845 | ret = acpi_processor_set_throttling(pr, state); | 845 | ret = acpi_processor_set_throttling(pr, state); |
846 | if (ret) | 846 | if (ret) |
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index 810cca90ca7f..1bdfb37377e3 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c | |||
@@ -570,6 +570,22 @@ static struct dmi_system_id video_dmi_table[] __initdata = { | |||
570 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5710Z"), | 570 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5710Z"), |
571 | }, | 571 | }, |
572 | }, | 572 | }, |
573 | { | ||
574 | .callback = video_set_bqc_offset, | ||
575 | .ident = "eMachines E510", | ||
576 | .matches = { | ||
577 | DMI_MATCH(DMI_BOARD_VENDOR, "EMACHINES"), | ||
578 | DMI_MATCH(DMI_PRODUCT_NAME, "eMachines E510"), | ||
579 | }, | ||
580 | }, | ||
581 | { | ||
582 | .callback = video_set_bqc_offset, | ||
583 | .ident = "Acer Aspire 5315", | ||
584 | .matches = { | ||
585 | DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), | ||
586 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5315"), | ||
587 | }, | ||
588 | }, | ||
573 | {} | 589 | {} |
574 | }; | 590 | }; |
575 | 591 | ||
@@ -2334,7 +2350,7 @@ static int __init acpi_video_init(void) | |||
2334 | return acpi_video_register(); | 2350 | return acpi_video_register(); |
2335 | } | 2351 | } |
2336 | 2352 | ||
2337 | void __exit acpi_video_exit(void) | 2353 | void acpi_video_exit(void) |
2338 | { | 2354 | { |
2339 | 2355 | ||
2340 | acpi_bus_unregister_driver(&acpi_video_bus); | 2356 | acpi_bus_unregister_driver(&acpi_video_bus); |
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 08186ecbaf8d..6b91c26a4635 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c | |||
@@ -220,6 +220,7 @@ enum { | |||
220 | AHCI_HFLAG_NO_HOTPLUG = (1 << 7), /* ignore PxSERR.DIAG.N */ | 220 | AHCI_HFLAG_NO_HOTPLUG = (1 << 7), /* ignore PxSERR.DIAG.N */ |
221 | AHCI_HFLAG_SECT255 = (1 << 8), /* max 255 sectors */ | 221 | AHCI_HFLAG_SECT255 = (1 << 8), /* max 255 sectors */ |
222 | AHCI_HFLAG_YES_NCQ = (1 << 9), /* force NCQ cap on */ | 222 | AHCI_HFLAG_YES_NCQ = (1 << 9), /* force NCQ cap on */ |
223 | AHCI_HFLAG_NO_SUSPEND = (1 << 10), /* don't suspend */ | ||
223 | 224 | ||
224 | /* ap->flags bits */ | 225 | /* ap->flags bits */ |
225 | 226 | ||
@@ -2316,9 +2317,17 @@ static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg) | |||
2316 | static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg) | 2317 | static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg) |
2317 | { | 2318 | { |
2318 | struct ata_host *host = dev_get_drvdata(&pdev->dev); | 2319 | struct ata_host *host = dev_get_drvdata(&pdev->dev); |
2320 | struct ahci_host_priv *hpriv = host->private_data; | ||
2319 | void __iomem *mmio = host->iomap[AHCI_PCI_BAR]; | 2321 | void __iomem *mmio = host->iomap[AHCI_PCI_BAR]; |
2320 | u32 ctl; | 2322 | u32 ctl; |
2321 | 2323 | ||
2324 | if (mesg.event & PM_EVENT_SUSPEND && | ||
2325 | hpriv->flags & AHCI_HFLAG_NO_SUSPEND) { | ||
2326 | dev_printk(KERN_ERR, &pdev->dev, | ||
2327 | "BIOS update required for suspend/resume\n"); | ||
2328 | return -EIO; | ||
2329 | } | ||
2330 | |||
2322 | if (mesg.event & PM_EVENT_SLEEP) { | 2331 | if (mesg.event & PM_EVENT_SLEEP) { |
2323 | /* AHCI spec rev1.1 section 8.3.3: | 2332 | /* AHCI spec rev1.1 section 8.3.3: |
2324 | * Software must disable interrupts prior to requesting a | 2333 | * Software must disable interrupts prior to requesting a |
@@ -2610,6 +2619,63 @@ static bool ahci_broken_system_poweroff(struct pci_dev *pdev) | |||
2610 | return false; | 2619 | return false; |
2611 | } | 2620 | } |
2612 | 2621 | ||
2622 | static bool ahci_broken_suspend(struct pci_dev *pdev) | ||
2623 | { | ||
2624 | static const struct dmi_system_id sysids[] = { | ||
2625 | /* | ||
2626 | * On HP dv[4-6] and HDX18 with earlier BIOSen, link | ||
2627 | * to the harddisk doesn't become online after | ||
2628 | * resuming from STR. Warn and fail suspend. | ||
2629 | */ | ||
2630 | { | ||
2631 | .ident = "dv4", | ||
2632 | .matches = { | ||
2633 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), | ||
2634 | DMI_MATCH(DMI_PRODUCT_NAME, | ||
2635 | "HP Pavilion dv4 Notebook PC"), | ||
2636 | }, | ||
2637 | .driver_data = "F.30", /* cutoff BIOS version */ | ||
2638 | }, | ||
2639 | { | ||
2640 | .ident = "dv5", | ||
2641 | .matches = { | ||
2642 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), | ||
2643 | DMI_MATCH(DMI_PRODUCT_NAME, | ||
2644 | "HP Pavilion dv5 Notebook PC"), | ||
2645 | }, | ||
2646 | .driver_data = "F.16", /* cutoff BIOS version */ | ||
2647 | }, | ||
2648 | { | ||
2649 | .ident = "dv6", | ||
2650 | .matches = { | ||
2651 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), | ||
2652 | DMI_MATCH(DMI_PRODUCT_NAME, | ||
2653 | "HP Pavilion dv6 Notebook PC"), | ||
2654 | }, | ||
2655 | .driver_data = "F.21", /* cutoff BIOS version */ | ||
2656 | }, | ||
2657 | { | ||
2658 | .ident = "HDX18", | ||
2659 | .matches = { | ||
2660 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), | ||
2661 | DMI_MATCH(DMI_PRODUCT_NAME, | ||
2662 | "HP HDX18 Notebook PC"), | ||
2663 | }, | ||
2664 | .driver_data = "F.23", /* cutoff BIOS version */ | ||
2665 | }, | ||
2666 | { } /* terminate list */ | ||
2667 | }; | ||
2668 | const struct dmi_system_id *dmi = dmi_first_match(sysids); | ||
2669 | const char *ver; | ||
2670 | |||
2671 | if (!dmi || pdev->bus->number || pdev->devfn != PCI_DEVFN(0x1f, 2)) | ||
2672 | return false; | ||
2673 | |||
2674 | ver = dmi_get_system_info(DMI_BIOS_VERSION); | ||
2675 | |||
2676 | return !ver || strcmp(ver, dmi->driver_data) < 0; | ||
2677 | } | ||
2678 | |||
2613 | static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | 2679 | static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
2614 | { | 2680 | { |
2615 | static int printed_version; | 2681 | static int printed_version; |
@@ -2715,6 +2781,12 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
2715 | "quirky BIOS, skipping spindown on poweroff\n"); | 2781 | "quirky BIOS, skipping spindown on poweroff\n"); |
2716 | } | 2782 | } |
2717 | 2783 | ||
2784 | if (ahci_broken_suspend(pdev)) { | ||
2785 | hpriv->flags |= AHCI_HFLAG_NO_SUSPEND; | ||
2786 | dev_printk(KERN_WARNING, &pdev->dev, | ||
2787 | "BIOS update required for suspend/resume\n"); | ||
2788 | } | ||
2789 | |||
2718 | /* CAP.NP sometimes indicate the index of the last enabled | 2790 | /* CAP.NP sometimes indicate the index of the last enabled |
2719 | * port, at other times, that of the last possible port, so | 2791 | * port, at other times, that of the last possible port, so |
2720 | * determining the maximum port number requires looking at | 2792 | * determining the maximum port number requires looking at |
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c index d51a17c0f59b..1aeb7082b0c4 100644 --- a/drivers/ata/ata_piix.c +++ b/drivers/ata/ata_piix.c | |||
@@ -1455,6 +1455,15 @@ static bool piix_broken_system_poweroff(struct pci_dev *pdev) | |||
1455 | /* PCI slot number of the controller */ | 1455 | /* PCI slot number of the controller */ |
1456 | .driver_data = (void *)0x1FUL, | 1456 | .driver_data = (void *)0x1FUL, |
1457 | }, | 1457 | }, |
1458 | { | ||
1459 | .ident = "HP Compaq nc6000", | ||
1460 | .matches = { | ||
1461 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), | ||
1462 | DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nc6000"), | ||
1463 | }, | ||
1464 | /* PCI slot number of the controller */ | ||
1465 | .driver_data = (void *)0x1FUL, | ||
1466 | }, | ||
1458 | 1467 | ||
1459 | { } /* terminate list */ | 1468 | { } /* terminate list */ |
1460 | }; | 1469 | }; |
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c index 751b7ea4816c..fc9c5d6d7d80 100644 --- a/drivers/ata/pata_ali.c +++ b/drivers/ata/pata_ali.c | |||
@@ -497,14 +497,16 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id) | |||
497 | }; | 497 | }; |
498 | /* Revision 0x20 added DMA */ | 498 | /* Revision 0x20 added DMA */ |
499 | static const struct ata_port_info info_20 = { | 499 | static const struct ata_port_info info_20 = { |
500 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48, | 500 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48 | |
501 | ATA_FLAG_IGN_SIMPLEX, | ||
501 | .pio_mask = ATA_PIO4, | 502 | .pio_mask = ATA_PIO4, |
502 | .mwdma_mask = ATA_MWDMA2, | 503 | .mwdma_mask = ATA_MWDMA2, |
503 | .port_ops = &ali_20_port_ops | 504 | .port_ops = &ali_20_port_ops |
504 | }; | 505 | }; |
505 | /* Revision 0x20 with support logic added UDMA */ | 506 | /* Revision 0x20 with support logic added UDMA */ |
506 | static const struct ata_port_info info_20_udma = { | 507 | static const struct ata_port_info info_20_udma = { |
507 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48, | 508 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48 | |
509 | ATA_FLAG_IGN_SIMPLEX, | ||
508 | .pio_mask = ATA_PIO4, | 510 | .pio_mask = ATA_PIO4, |
509 | .mwdma_mask = ATA_MWDMA2, | 511 | .mwdma_mask = ATA_MWDMA2, |
510 | .udma_mask = ATA_UDMA2, | 512 | .udma_mask = ATA_UDMA2, |
@@ -512,7 +514,8 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id) | |||
512 | }; | 514 | }; |
513 | /* Revision 0xC2 adds UDMA66 */ | 515 | /* Revision 0xC2 adds UDMA66 */ |
514 | static const struct ata_port_info info_c2 = { | 516 | static const struct ata_port_info info_c2 = { |
515 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48, | 517 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48 | |
518 | ATA_FLAG_IGN_SIMPLEX, | ||
516 | .pio_mask = ATA_PIO4, | 519 | .pio_mask = ATA_PIO4, |
517 | .mwdma_mask = ATA_MWDMA2, | 520 | .mwdma_mask = ATA_MWDMA2, |
518 | .udma_mask = ATA_UDMA4, | 521 | .udma_mask = ATA_UDMA4, |
@@ -520,7 +523,8 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id) | |||
520 | }; | 523 | }; |
521 | /* Revision 0xC3 is UDMA66 for now */ | 524 | /* Revision 0xC3 is UDMA66 for now */ |
522 | static const struct ata_port_info info_c3 = { | 525 | static const struct ata_port_info info_c3 = { |
523 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48, | 526 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48 | |
527 | ATA_FLAG_IGN_SIMPLEX, | ||
524 | .pio_mask = ATA_PIO4, | 528 | .pio_mask = ATA_PIO4, |
525 | .mwdma_mask = ATA_MWDMA2, | 529 | .mwdma_mask = ATA_MWDMA2, |
526 | .udma_mask = ATA_UDMA4, | 530 | .udma_mask = ATA_UDMA4, |
@@ -528,7 +532,8 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id) | |||
528 | }; | 532 | }; |
529 | /* Revision 0xC4 is UDMA100 */ | 533 | /* Revision 0xC4 is UDMA100 */ |
530 | static const struct ata_port_info info_c4 = { | 534 | static const struct ata_port_info info_c4 = { |
531 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48, | 535 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48 | |
536 | ATA_FLAG_IGN_SIMPLEX, | ||
532 | .pio_mask = ATA_PIO4, | 537 | .pio_mask = ATA_PIO4, |
533 | .mwdma_mask = ATA_MWDMA2, | 538 | .mwdma_mask = ATA_MWDMA2, |
534 | .udma_mask = ATA_UDMA5, | 539 | .udma_mask = ATA_UDMA5, |
@@ -536,7 +541,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id) | |||
536 | }; | 541 | }; |
537 | /* Revision 0xC5 is UDMA133 with LBA48 DMA */ | 542 | /* Revision 0xC5 is UDMA133 with LBA48 DMA */ |
538 | static const struct ata_port_info info_c5 = { | 543 | static const struct ata_port_info info_c5 = { |
539 | .flags = ATA_FLAG_SLAVE_POSS, | 544 | .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_IGN_SIMPLEX, |
540 | .pio_mask = ATA_PIO4, | 545 | .pio_mask = ATA_PIO4, |
541 | .mwdma_mask = ATA_MWDMA2, | 546 | .mwdma_mask = ATA_MWDMA2, |
542 | .udma_mask = ATA_UDMA6, | 547 | .udma_mask = ATA_UDMA6, |
diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c index 2085e0a3a05a..2a6412f5d117 100644 --- a/drivers/ata/pata_efar.c +++ b/drivers/ata/pata_efar.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <linux/ata.h> | 22 | #include <linux/ata.h> |
23 | 23 | ||
24 | #define DRV_NAME "pata_efar" | 24 | #define DRV_NAME "pata_efar" |
25 | #define DRV_VERSION "0.4.4" | 25 | #define DRV_VERSION "0.4.5" |
26 | 26 | ||
27 | /** | 27 | /** |
28 | * efar_pre_reset - Enable bits | 28 | * efar_pre_reset - Enable bits |
@@ -98,18 +98,17 @@ static void efar_set_piomode (struct ata_port *ap, struct ata_device *adev) | |||
98 | { 2, 1 }, | 98 | { 2, 1 }, |
99 | { 2, 3 }, }; | 99 | { 2, 3 }, }; |
100 | 100 | ||
101 | if (pio > 2) | 101 | if (pio > 1) |
102 | control |= 1; /* TIME1 enable */ | 102 | control |= 1; /* TIME */ |
103 | if (ata_pio_need_iordy(adev)) /* PIO 3/4 require IORDY */ | 103 | if (ata_pio_need_iordy(adev)) /* PIO 3/4 require IORDY */ |
104 | control |= 2; /* IE enable */ | 104 | control |= 2; /* IE */ |
105 | /* Intel specifies that the PPE functionality is for disk only */ | 105 | /* Intel specifies that the prefetch/posting is for disk only */ |
106 | if (adev->class == ATA_DEV_ATA) | 106 | if (adev->class == ATA_DEV_ATA) |
107 | control |= 4; /* PPE enable */ | 107 | control |= 4; /* PPE */ |
108 | 108 | ||
109 | pci_read_config_word(dev, idetm_port, &idetm_data); | 109 | pci_read_config_word(dev, idetm_port, &idetm_data); |
110 | 110 | ||
111 | /* Enable PPE, IE and TIME as appropriate */ | 111 | /* Set PPE, IE, and TIME as appropriate */ |
112 | |||
113 | if (adev->devno == 0) { | 112 | if (adev->devno == 0) { |
114 | idetm_data &= 0xCCF0; | 113 | idetm_data &= 0xCCF0; |
115 | idetm_data |= control; | 114 | idetm_data |= control; |
@@ -129,7 +128,7 @@ static void efar_set_piomode (struct ata_port *ap, struct ata_device *adev) | |||
129 | pci_write_config_byte(dev, 0x44, slave_data); | 128 | pci_write_config_byte(dev, 0x44, slave_data); |
130 | } | 129 | } |
131 | 130 | ||
132 | idetm_data |= 0x4000; /* Ensure SITRE is enabled */ | 131 | idetm_data |= 0x4000; /* Ensure SITRE is set */ |
133 | pci_write_config_word(dev, idetm_port, idetm_data); | 132 | pci_write_config_word(dev, idetm_port, idetm_data); |
134 | } | 133 | } |
135 | 134 | ||
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c index f72c6c5b820f..6932e56d179c 100644 --- a/drivers/ata/pata_legacy.c +++ b/drivers/ata/pata_legacy.c | |||
@@ -48,6 +48,7 @@ | |||
48 | * | 48 | * |
49 | */ | 49 | */ |
50 | 50 | ||
51 | #include <linux/async.h> | ||
51 | #include <linux/kernel.h> | 52 | #include <linux/kernel.h> |
52 | #include <linux/module.h> | 53 | #include <linux/module.h> |
53 | #include <linux/pci.h> | 54 | #include <linux/pci.h> |
@@ -1028,6 +1029,7 @@ static __init int legacy_init_one(struct legacy_probe *probe) | |||
1028 | &legacy_sht); | 1029 | &legacy_sht); |
1029 | if (ret) | 1030 | if (ret) |
1030 | goto fail; | 1031 | goto fail; |
1032 | async_synchronize_full(); | ||
1031 | ld->platform_dev = pdev; | 1033 | ld->platform_dev = pdev; |
1032 | 1034 | ||
1033 | /* Nothing found means we drop the port as its probably not there */ | 1035 | /* Nothing found means we drop the port as its probably not there */ |
diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c index bdb236957cb9..f0d52f72f5bb 100644 --- a/drivers/ata/pata_netcell.c +++ b/drivers/ata/pata_netcell.c | |||
@@ -20,13 +20,24 @@ | |||
20 | 20 | ||
21 | /* No PIO or DMA methods needed for this device */ | 21 | /* No PIO or DMA methods needed for this device */ |
22 | 22 | ||
23 | static unsigned int netcell_read_id(struct ata_device *adev, | ||
24 | struct ata_taskfile *tf, u16 *id) | ||
25 | { | ||
26 | unsigned int err_mask = ata_do_dev_read_id(adev, tf, id); | ||
27 | /* Firmware forgets to mark words 85-87 valid */ | ||
28 | if (err_mask == 0) | ||
29 | id[ATA_ID_CSF_DEFAULT] |= 0x4000; | ||
30 | return err_mask; | ||
31 | } | ||
32 | |||
23 | static struct scsi_host_template netcell_sht = { | 33 | static struct scsi_host_template netcell_sht = { |
24 | ATA_BMDMA_SHT(DRV_NAME), | 34 | ATA_BMDMA_SHT(DRV_NAME), |
25 | }; | 35 | }; |
26 | 36 | ||
27 | static struct ata_port_operations netcell_ops = { | 37 | static struct ata_port_operations netcell_ops = { |
28 | .inherits = &ata_bmdma_port_ops, | 38 | .inherits = &ata_bmdma_port_ops, |
29 | .cable_detect = ata_cable_80wire, | 39 | .cable_detect = ata_cable_80wire, |
40 | .read_id = netcell_read_id, | ||
30 | }; | 41 | }; |
31 | 42 | ||
32 | 43 | ||
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index dc030f1f00f1..c6599618523e 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -700,8 +700,10 @@ int bus_add_driver(struct device_driver *drv) | |||
700 | } | 700 | } |
701 | 701 | ||
702 | kobject_uevent(&priv->kobj, KOBJ_ADD); | 702 | kobject_uevent(&priv->kobj, KOBJ_ADD); |
703 | return error; | 703 | return 0; |
704 | out_unregister: | 704 | out_unregister: |
705 | kfree(drv->p); | ||
706 | drv->p = NULL; | ||
705 | kobject_put(&priv->kobj); | 707 | kobject_put(&priv->kobj); |
706 | out_put_bus: | 708 | out_put_bus: |
707 | bus_put(bus); | 709 | bus_put(bus); |
diff --git a/drivers/base/core.c b/drivers/base/core.c index 4aa527b8a913..1977d4beb89e 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -879,7 +879,7 @@ int device_add(struct device *dev) | |||
879 | } | 879 | } |
880 | 880 | ||
881 | if (!dev_name(dev)) | 881 | if (!dev_name(dev)) |
882 | goto done; | 882 | goto name_error; |
883 | 883 | ||
884 | pr_debug("device: '%s': %s\n", dev_name(dev), __func__); | 884 | pr_debug("device: '%s': %s\n", dev_name(dev), __func__); |
885 | 885 | ||
@@ -978,6 +978,9 @@ done: | |||
978 | cleanup_device_parent(dev); | 978 | cleanup_device_parent(dev); |
979 | if (parent) | 979 | if (parent) |
980 | put_device(parent); | 980 | put_device(parent); |
981 | name_error: | ||
982 | kfree(dev->p); | ||
983 | dev->p = NULL; | ||
981 | goto done; | 984 | goto done; |
982 | } | 985 | } |
983 | 986 | ||
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index c51f11bb29ae..8ae0f63602e0 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c | |||
@@ -257,6 +257,10 @@ EXPORT_SYMBOL_GPL(driver_register); | |||
257 | */ | 257 | */ |
258 | void driver_unregister(struct device_driver *drv) | 258 | void driver_unregister(struct device_driver *drv) |
259 | { | 259 | { |
260 | if (!drv || !drv->p) { | ||
261 | WARN(1, "Unexpected driver unregister!\n"); | ||
262 | return; | ||
263 | } | ||
260 | driver_remove_groups(drv, drv->groups); | 264 | driver_remove_groups(drv, drv->groups); |
261 | bus_remove_driver(drv); | 265 | bus_remove_driver(drv); |
262 | } | 266 | } |
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 69b4ddb7de3b..3e4bc699bc0f 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
@@ -357,6 +357,7 @@ static void dpm_power_up(pm_message_t state) | |||
357 | { | 357 | { |
358 | struct device *dev; | 358 | struct device *dev; |
359 | 359 | ||
360 | mutex_lock(&dpm_list_mtx); | ||
360 | list_for_each_entry(dev, &dpm_list, power.entry) | 361 | list_for_each_entry(dev, &dpm_list, power.entry) |
361 | if (dev->power.status > DPM_OFF) { | 362 | if (dev->power.status > DPM_OFF) { |
362 | int error; | 363 | int error; |
@@ -366,6 +367,7 @@ static void dpm_power_up(pm_message_t state) | |||
366 | if (error) | 367 | if (error) |
367 | pm_dev_err(dev, state, " early", error); | 368 | pm_dev_err(dev, state, " early", error); |
368 | } | 369 | } |
370 | mutex_unlock(&dpm_list_mtx); | ||
369 | } | 371 | } |
370 | 372 | ||
371 | /** | 373 | /** |
@@ -614,6 +616,7 @@ int device_power_down(pm_message_t state) | |||
614 | int error = 0; | 616 | int error = 0; |
615 | 617 | ||
616 | suspend_device_irqs(); | 618 | suspend_device_irqs(); |
619 | mutex_lock(&dpm_list_mtx); | ||
617 | list_for_each_entry_reverse(dev, &dpm_list, power.entry) { | 620 | list_for_each_entry_reverse(dev, &dpm_list, power.entry) { |
618 | error = suspend_device_noirq(dev, state); | 621 | error = suspend_device_noirq(dev, state); |
619 | if (error) { | 622 | if (error) { |
@@ -622,6 +625,7 @@ int device_power_down(pm_message_t state) | |||
622 | } | 625 | } |
623 | dev->power.status = DPM_OFF_IRQ; | 626 | dev->power.status = DPM_OFF_IRQ; |
624 | } | 627 | } |
628 | mutex_unlock(&dpm_list_mtx); | ||
625 | if (error) | 629 | if (error) |
626 | device_power_up(resume_event(state)); | 630 | device_power_up(resume_event(state)); |
627 | return error; | 631 | return error; |
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index af761dc434f6..4895f0e05322 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c | |||
@@ -277,8 +277,8 @@ static int hci_uart_tty_open(struct tty_struct *tty) | |||
277 | /* FIXME: why is this needed. Note don't use ldisc_ref here as the | 277 | /* FIXME: why is this needed. Note don't use ldisc_ref here as the |
278 | open path is before the ldisc is referencable */ | 278 | open path is before the ldisc is referencable */ |
279 | 279 | ||
280 | if (tty->ldisc.ops->flush_buffer) | 280 | if (tty->ldisc->ops->flush_buffer) |
281 | tty->ldisc.ops->flush_buffer(tty); | 281 | tty->ldisc->ops->flush_buffer(tty); |
282 | tty_driver_flush_buffer(tty); | 282 | tty_driver_flush_buffer(tty); |
283 | 283 | ||
284 | return 0; | 284 | return 0; |
@@ -463,7 +463,6 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file, | |||
463 | clear_bit(HCI_UART_PROTO_SET, &hu->flags); | 463 | clear_bit(HCI_UART_PROTO_SET, &hu->flags); |
464 | return err; | 464 | return err; |
465 | } | 465 | } |
466 | tty->low_latency = 1; | ||
467 | } else | 466 | } else |
468 | return -EBUSY; | 467 | return -EBUSY; |
469 | break; | 468 | break; |
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 735bbe2be51a..02ecfd5fa61c 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig | |||
@@ -97,6 +97,19 @@ config DEVKMEM | |||
97 | kind of kernel debugging operations. | 97 | kind of kernel debugging operations. |
98 | When in doubt, say "N". | 98 | When in doubt, say "N". |
99 | 99 | ||
100 | config BFIN_JTAG_COMM | ||
101 | tristate "Blackfin JTAG Communication" | ||
102 | depends on BLACKFIN | ||
103 | help | ||
104 | Add support for emulating a TTY device over the Blackfin JTAG. | ||
105 | |||
106 | To compile this driver as a module, choose M here: the | ||
107 | module will be called bfin_jtag_comm. | ||
108 | |||
109 | config BFIN_JTAG_COMM_CONSOLE | ||
110 | bool "Console on Blackfin JTAG" | ||
111 | depends on BFIN_JTAG_COMM=y | ||
112 | |||
100 | config SERIAL_NONSTANDARD | 113 | config SERIAL_NONSTANDARD |
101 | bool "Non-standard serial port support" | 114 | bool "Non-standard serial port support" |
102 | depends on HAS_IOMEM | 115 | depends on HAS_IOMEM |
diff --git a/drivers/char/Makefile b/drivers/char/Makefile index 9caf5b5ad1c0..189efcff08ce 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile | |||
@@ -13,6 +13,7 @@ obj-$(CONFIG_LEGACY_PTYS) += pty.o | |||
13 | obj-$(CONFIG_UNIX98_PTYS) += pty.o | 13 | obj-$(CONFIG_UNIX98_PTYS) += pty.o |
14 | obj-y += misc.o | 14 | obj-y += misc.o |
15 | obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o | 15 | obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o |
16 | obj-$(CONFIG_BFIN_JTAG_COMM) += bfin_jtag_comm.o | ||
16 | obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o | 17 | obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o |
17 | obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o | 18 | obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o |
18 | obj-$(CONFIG_AUDIT) += tty_audit.o | 19 | obj-$(CONFIG_AUDIT) += tty_audit.o |
diff --git a/drivers/char/bfin_jtag_comm.c b/drivers/char/bfin_jtag_comm.c new file mode 100644 index 000000000000..44c113d56045 --- /dev/null +++ b/drivers/char/bfin_jtag_comm.c | |||
@@ -0,0 +1,365 @@ | |||
1 | /* | ||
2 | * TTY over Blackfin JTAG Communication | ||
3 | * | ||
4 | * Copyright 2008-2009 Analog Devices Inc. | ||
5 | * | ||
6 | * Enter bugs at http://blackfin.uclinux.org/ | ||
7 | * | ||
8 | * Licensed under the GPL-2 or later. | ||
9 | */ | ||
10 | |||
11 | #include <linux/circ_buf.h> | ||
12 | #include <linux/console.h> | ||
13 | #include <linux/delay.h> | ||
14 | #include <linux/err.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/kthread.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/mutex.h> | ||
19 | #include <linux/sched.h> | ||
20 | #include <linux/tty.h> | ||
21 | #include <linux/tty_driver.h> | ||
22 | #include <linux/tty_flip.h> | ||
23 | #include <asm/atomic.h> | ||
24 | |||
25 | /* See the Debug/Emulation chapter in the HRM */ | ||
26 | #define EMUDOF 0x00000001 /* EMUDAT_OUT full & valid */ | ||
27 | #define EMUDIF 0x00000002 /* EMUDAT_IN full & valid */ | ||
28 | #define EMUDOOVF 0x00000004 /* EMUDAT_OUT overflow */ | ||
29 | #define EMUDIOVF 0x00000008 /* EMUDAT_IN overflow */ | ||
30 | |||
31 | #define DRV_NAME "bfin-jtag-comm" | ||
32 | #define DEV_NAME "ttyBFJC" | ||
33 | |||
34 | #define pr_init(fmt, args...) ({ static const __initdata char __fmt[] = fmt; printk(__fmt, ## args); }) | ||
35 | #define debug(fmt, args...) pr_debug(DRV_NAME ": " fmt, ## args) | ||
36 | |||
37 | static inline uint32_t bfin_write_emudat(uint32_t emudat) | ||
38 | { | ||
39 | __asm__ __volatile__("emudat = %0;" : : "d"(emudat)); | ||
40 | return emudat; | ||
41 | } | ||
42 | |||
43 | static inline uint32_t bfin_read_emudat(void) | ||
44 | { | ||
45 | uint32_t emudat; | ||
46 | __asm__ __volatile__("%0 = emudat;" : "=d"(emudat)); | ||
47 | return emudat; | ||
48 | } | ||
49 | |||
50 | static inline uint32_t bfin_write_emudat_chars(char a, char b, char c, char d) | ||
51 | { | ||
52 | return bfin_write_emudat((a << 0) | (b << 8) | (c << 16) | (d << 24)); | ||
53 | } | ||
54 | |||
55 | #define CIRC_SIZE 2048 /* see comment in tty_io.c:do_tty_write() */ | ||
56 | #define CIRC_MASK (CIRC_SIZE - 1) | ||
57 | #define circ_empty(circ) ((circ)->head == (circ)->tail) | ||
58 | #define circ_free(circ) CIRC_SPACE((circ)->head, (circ)->tail, CIRC_SIZE) | ||
59 | #define circ_cnt(circ) CIRC_CNT((circ)->head, (circ)->tail, CIRC_SIZE) | ||
60 | #define circ_byte(circ, idx) ((circ)->buf[(idx) & CIRC_MASK]) | ||
61 | |||
62 | static struct tty_driver *bfin_jc_driver; | ||
63 | static struct task_struct *bfin_jc_kthread; | ||
64 | static struct tty_struct * volatile bfin_jc_tty; | ||
65 | static unsigned long bfin_jc_count; | ||
66 | static DEFINE_MUTEX(bfin_jc_tty_mutex); | ||
67 | static volatile struct circ_buf bfin_jc_write_buf; | ||
68 | |||
69 | static int | ||
70 | bfin_jc_emudat_manager(void *arg) | ||
71 | { | ||
72 | uint32_t inbound_len = 0, outbound_len = 0; | ||
73 | |||
74 | while (!kthread_should_stop()) { | ||
75 | /* no one left to give data to, so sleep */ | ||
76 | if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) { | ||
77 | debug("waiting for readers\n"); | ||
78 | __set_current_state(TASK_UNINTERRUPTIBLE); | ||
79 | schedule(); | ||
80 | __set_current_state(TASK_RUNNING); | ||
81 | } | ||
82 | |||
83 | /* no data available, so just chill */ | ||
84 | if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) { | ||
85 | debug("waiting for data (in_len = %i) (circ: %i %i)\n", | ||
86 | inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head); | ||
87 | if (inbound_len) | ||
88 | schedule(); | ||
89 | else | ||
90 | schedule_timeout_interruptible(HZ); | ||
91 | continue; | ||
92 | } | ||
93 | |||
94 | /* if incoming data is ready, eat it */ | ||
95 | if (bfin_read_DBGSTAT() & EMUDIF) { | ||
96 | struct tty_struct *tty; | ||
97 | mutex_lock(&bfin_jc_tty_mutex); | ||
98 | tty = (struct tty_struct *)bfin_jc_tty; | ||
99 | if (tty != NULL) { | ||
100 | uint32_t emudat = bfin_read_emudat(); | ||
101 | if (inbound_len == 0) { | ||
102 | debug("incoming length: 0x%08x\n", emudat); | ||
103 | inbound_len = emudat; | ||
104 | } else { | ||
105 | size_t num_chars = (4 <= inbound_len ? 4 : inbound_len); | ||
106 | debug(" incoming data: 0x%08x (pushing %zu)\n", emudat, num_chars); | ||
107 | inbound_len -= num_chars; | ||
108 | tty_insert_flip_string(tty, (unsigned char *)&emudat, num_chars); | ||
109 | tty_flip_buffer_push(tty); | ||
110 | } | ||
111 | } | ||
112 | mutex_unlock(&bfin_jc_tty_mutex); | ||
113 | } | ||
114 | |||
115 | /* if outgoing data is ready, post it */ | ||
116 | if (!(bfin_read_DBGSTAT() & EMUDOF) && !circ_empty(&bfin_jc_write_buf)) { | ||
117 | if (outbound_len == 0) { | ||
118 | outbound_len = circ_cnt(&bfin_jc_write_buf); | ||
119 | bfin_write_emudat(outbound_len); | ||
120 | debug("outgoing length: 0x%08x\n", outbound_len); | ||
121 | } else { | ||
122 | struct tty_struct *tty; | ||
123 | int tail = bfin_jc_write_buf.tail; | ||
124 | size_t ate = (4 <= outbound_len ? 4 : outbound_len); | ||
125 | uint32_t emudat = | ||
126 | bfin_write_emudat_chars( | ||
127 | circ_byte(&bfin_jc_write_buf, tail + 0), | ||
128 | circ_byte(&bfin_jc_write_buf, tail + 1), | ||
129 | circ_byte(&bfin_jc_write_buf, tail + 2), | ||
130 | circ_byte(&bfin_jc_write_buf, tail + 3) | ||
131 | ); | ||
132 | bfin_jc_write_buf.tail += ate; | ||
133 | outbound_len -= ate; | ||
134 | mutex_lock(&bfin_jc_tty_mutex); | ||
135 | tty = (struct tty_struct *)bfin_jc_tty; | ||
136 | if (tty) | ||
137 | tty_wakeup(tty); | ||
138 | mutex_unlock(&bfin_jc_tty_mutex); | ||
139 | debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate); | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | |||
144 | __set_current_state(TASK_RUNNING); | ||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | static int | ||
149 | bfin_jc_open(struct tty_struct *tty, struct file *filp) | ||
150 | { | ||
151 | mutex_lock(&bfin_jc_tty_mutex); | ||
152 | debug("open %lu\n", bfin_jc_count); | ||
153 | ++bfin_jc_count; | ||
154 | bfin_jc_tty = tty; | ||
155 | wake_up_process(bfin_jc_kthread); | ||
156 | mutex_unlock(&bfin_jc_tty_mutex); | ||
157 | return 0; | ||
158 | } | ||
159 | |||
160 | static void | ||
161 | bfin_jc_close(struct tty_struct *tty, struct file *filp) | ||
162 | { | ||
163 | mutex_lock(&bfin_jc_tty_mutex); | ||
164 | debug("close %lu\n", bfin_jc_count); | ||
165 | if (--bfin_jc_count == 0) | ||
166 | bfin_jc_tty = NULL; | ||
167 | wake_up_process(bfin_jc_kthread); | ||
168 | mutex_unlock(&bfin_jc_tty_mutex); | ||
169 | } | ||
170 | |||
171 | /* XXX: we dont handle the put_char() case where we must handle count = 1 */ | ||
172 | static int | ||
173 | bfin_jc_circ_write(const unsigned char *buf, int count) | ||
174 | { | ||
175 | int i; | ||
176 | count = min(count, circ_free(&bfin_jc_write_buf)); | ||
177 | debug("going to write chunk of %i bytes\n", count); | ||
178 | for (i = 0; i < count; ++i) | ||
179 | circ_byte(&bfin_jc_write_buf, bfin_jc_write_buf.head + i) = buf[i]; | ||
180 | bfin_jc_write_buf.head += i; | ||
181 | return i; | ||
182 | } | ||
183 | |||
184 | #ifndef CONFIG_BFIN_JTAG_COMM_CONSOLE | ||
185 | # define acquire_console_sem() | ||
186 | # define release_console_sem() | ||
187 | #endif | ||
188 | static int | ||
189 | bfin_jc_write(struct tty_struct *tty, const unsigned char *buf, int count) | ||
190 | { | ||
191 | int i; | ||
192 | acquire_console_sem(); | ||
193 | i = bfin_jc_circ_write(buf, count); | ||
194 | release_console_sem(); | ||
195 | wake_up_process(bfin_jc_kthread); | ||
196 | return i; | ||
197 | } | ||
198 | |||
199 | static void | ||
200 | bfin_jc_flush_chars(struct tty_struct *tty) | ||
201 | { | ||
202 | wake_up_process(bfin_jc_kthread); | ||
203 | } | ||
204 | |||
205 | static int | ||
206 | bfin_jc_write_room(struct tty_struct *tty) | ||
207 | { | ||
208 | return circ_free(&bfin_jc_write_buf); | ||
209 | } | ||
210 | |||
211 | static int | ||
212 | bfin_jc_chars_in_buffer(struct tty_struct *tty) | ||
213 | { | ||
214 | return circ_cnt(&bfin_jc_write_buf); | ||
215 | } | ||
216 | |||
217 | static void | ||
218 | bfin_jc_wait_until_sent(struct tty_struct *tty, int timeout) | ||
219 | { | ||
220 | unsigned long expire = jiffies + timeout; | ||
221 | while (!circ_empty(&bfin_jc_write_buf)) { | ||
222 | if (signal_pending(current)) | ||
223 | break; | ||
224 | if (time_after(jiffies, expire)) | ||
225 | break; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | static struct tty_operations bfin_jc_ops = { | ||
230 | .open = bfin_jc_open, | ||
231 | .close = bfin_jc_close, | ||
232 | .write = bfin_jc_write, | ||
233 | /*.put_char = bfin_jc_put_char,*/ | ||
234 | .flush_chars = bfin_jc_flush_chars, | ||
235 | .write_room = bfin_jc_write_room, | ||
236 | .chars_in_buffer = bfin_jc_chars_in_buffer, | ||
237 | .wait_until_sent = bfin_jc_wait_until_sent, | ||
238 | }; | ||
239 | |||
240 | static int __init bfin_jc_init(void) | ||
241 | { | ||
242 | int ret; | ||
243 | |||
244 | bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME); | ||
245 | if (IS_ERR(bfin_jc_kthread)) | ||
246 | return PTR_ERR(bfin_jc_kthread); | ||
247 | |||
248 | ret = -ENOMEM; | ||
249 | |||
250 | bfin_jc_write_buf.head = bfin_jc_write_buf.tail = 0; | ||
251 | bfin_jc_write_buf.buf = kmalloc(CIRC_SIZE, GFP_KERNEL); | ||
252 | if (!bfin_jc_write_buf.buf) | ||
253 | goto err; | ||
254 | |||
255 | bfin_jc_driver = alloc_tty_driver(1); | ||
256 | if (!bfin_jc_driver) | ||
257 | goto err; | ||
258 | |||
259 | bfin_jc_driver->owner = THIS_MODULE; | ||
260 | bfin_jc_driver->driver_name = DRV_NAME; | ||
261 | bfin_jc_driver->name = DEV_NAME; | ||
262 | bfin_jc_driver->type = TTY_DRIVER_TYPE_SERIAL; | ||
263 | bfin_jc_driver->subtype = SERIAL_TYPE_NORMAL; | ||
264 | bfin_jc_driver->init_termios = tty_std_termios; | ||
265 | tty_set_operations(bfin_jc_driver, &bfin_jc_ops); | ||
266 | |||
267 | ret = tty_register_driver(bfin_jc_driver); | ||
268 | if (ret) | ||
269 | goto err; | ||
270 | |||
271 | pr_init(KERN_INFO DRV_NAME ": initialized\n"); | ||
272 | |||
273 | return 0; | ||
274 | |||
275 | err: | ||
276 | put_tty_driver(bfin_jc_driver); | ||
277 | kfree(bfin_jc_write_buf.buf); | ||
278 | kthread_stop(bfin_jc_kthread); | ||
279 | return ret; | ||
280 | } | ||
281 | module_init(bfin_jc_init); | ||
282 | |||
283 | static void __exit bfin_jc_exit(void) | ||
284 | { | ||
285 | kthread_stop(bfin_jc_kthread); | ||
286 | kfree(bfin_jc_write_buf.buf); | ||
287 | tty_unregister_driver(bfin_jc_driver); | ||
288 | put_tty_driver(bfin_jc_driver); | ||
289 | } | ||
290 | module_exit(bfin_jc_exit); | ||
291 | |||
292 | #if defined(CONFIG_BFIN_JTAG_COMM_CONSOLE) || defined(CONFIG_EARLY_PRINTK) | ||
293 | static void | ||
294 | bfin_jc_straight_buffer_write(const char *buf, unsigned count) | ||
295 | { | ||
296 | unsigned ate = 0; | ||
297 | while (bfin_read_DBGSTAT() & EMUDOF) | ||
298 | continue; | ||
299 | bfin_write_emudat(count); | ||
300 | while (ate < count) { | ||
301 | while (bfin_read_DBGSTAT() & EMUDOF) | ||
302 | continue; | ||
303 | bfin_write_emudat_chars(buf[ate], buf[ate+1], buf[ate+2], buf[ate+3]); | ||
304 | ate += 4; | ||
305 | } | ||
306 | } | ||
307 | #endif | ||
308 | |||
309 | #ifdef CONFIG_BFIN_JTAG_COMM_CONSOLE | ||
310 | static void | ||
311 | bfin_jc_console_write(struct console *co, const char *buf, unsigned count) | ||
312 | { | ||
313 | if (bfin_jc_kthread == NULL) | ||
314 | bfin_jc_straight_buffer_write(buf, count); | ||
315 | else | ||
316 | bfin_jc_circ_write(buf, count); | ||
317 | } | ||
318 | |||
319 | static struct tty_driver * | ||
320 | bfin_jc_console_device(struct console *co, int *index) | ||
321 | { | ||
322 | *index = co->index; | ||
323 | return bfin_jc_driver; | ||
324 | } | ||
325 | |||
326 | static struct console bfin_jc_console = { | ||
327 | .name = DEV_NAME, | ||
328 | .write = bfin_jc_console_write, | ||
329 | .device = bfin_jc_console_device, | ||
330 | .flags = CON_ANYTIME | CON_PRINTBUFFER, | ||
331 | .index = -1, | ||
332 | }; | ||
333 | |||
334 | static int __init bfin_jc_console_init(void) | ||
335 | { | ||
336 | register_console(&bfin_jc_console); | ||
337 | return 0; | ||
338 | } | ||
339 | console_initcall(bfin_jc_console_init); | ||
340 | #endif | ||
341 | |||
342 | #ifdef CONFIG_EARLY_PRINTK | ||
343 | static void __init | ||
344 | bfin_jc_early_write(struct console *co, const char *buf, unsigned int count) | ||
345 | { | ||
346 | bfin_jc_straight_buffer_write(buf, count); | ||
347 | } | ||
348 | |||
349 | static struct __initdata console bfin_jc_early_console = { | ||
350 | .name = "early_BFJC", | ||
351 | .write = bfin_jc_early_write, | ||
352 | .flags = CON_ANYTIME | CON_PRINTBUFFER, | ||
353 | .index = -1, | ||
354 | }; | ||
355 | |||
356 | struct console * __init | ||
357 | bfin_jc_early_init(unsigned int port, unsigned int cflag) | ||
358 | { | ||
359 | return &bfin_jc_early_console; | ||
360 | } | ||
361 | #endif | ||
362 | |||
363 | MODULE_AUTHOR("Mike Frysinger <vapier@gentoo.org>"); | ||
364 | MODULE_DESCRIPTION("TTY over Blackfin JTAG Communication"); | ||
365 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c index 1fdb9f657d8f..f3366d3f06cf 100644 --- a/drivers/char/cyclades.c +++ b/drivers/char/cyclades.c | |||
@@ -604,7 +604,6 @@ | |||
604 | 604 | ||
605 | #define NR_PORTS 256 | 605 | #define NR_PORTS 256 |
606 | 606 | ||
607 | #define ZE_V1_NPORTS 64 | ||
608 | #define ZO_V1 0 | 607 | #define ZO_V1 0 |
609 | #define ZO_V2 1 | 608 | #define ZO_V2 1 |
610 | #define ZE_V1 2 | 609 | #define ZE_V1 2 |
@@ -663,18 +662,6 @@ | |||
663 | static void cy_throttle(struct tty_struct *tty); | 662 | static void cy_throttle(struct tty_struct *tty); |
664 | static void cy_send_xchar(struct tty_struct *tty, char ch); | 663 | static void cy_send_xchar(struct tty_struct *tty, char ch); |
665 | 664 | ||
666 | #define IS_CYC_Z(card) ((card).num_chips == (unsigned int)-1) | ||
667 | |||
668 | #define Z_FPGA_CHECK(card) \ | ||
669 | ((readl(&((struct RUNTIME_9060 __iomem *) \ | ||
670 | ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0) | ||
671 | |||
672 | #define ISZLOADED(card) (((ZO_V1 == readl(&((struct RUNTIME_9060 __iomem *) \ | ||
673 | ((card).ctl_addr))->mail_box_0)) || \ | ||
674 | Z_FPGA_CHECK(card)) && \ | ||
675 | (ZFIRM_ID == readl(&((struct FIRM_ID __iomem *) \ | ||
676 | ((card).base_addr+ID_ADDRESS))->signature))) | ||
677 | |||
678 | #ifndef SERIAL_XMIT_SIZE | 665 | #ifndef SERIAL_XMIT_SIZE |
679 | #define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096)) | 666 | #define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096)) |
680 | #endif | 667 | #endif |
@@ -687,8 +674,6 @@ static void cy_send_xchar(struct tty_struct *tty, char ch); | |||
687 | #define DRIVER_VERSION 0x02010203 | 674 | #define DRIVER_VERSION 0x02010203 |
688 | #define RAM_SIZE 0x80000 | 675 | #define RAM_SIZE 0x80000 |
689 | 676 | ||
690 | #define Z_FPGA_LOADED(X) ((readl(&(X)->init_ctrl) & (1<<17)) != 0) | ||
691 | |||
692 | enum zblock_type { | 677 | enum zblock_type { |
693 | ZBLOCK_PRG = 0, | 678 | ZBLOCK_PRG = 0, |
694 | ZBLOCK_FPGA = 1 | 679 | ZBLOCK_FPGA = 1 |
@@ -883,6 +868,29 @@ static void cyz_rx_restart(unsigned long); | |||
883 | static struct timer_list cyz_rx_full_timer[NR_PORTS]; | 868 | static struct timer_list cyz_rx_full_timer[NR_PORTS]; |
884 | #endif /* CONFIG_CYZ_INTR */ | 869 | #endif /* CONFIG_CYZ_INTR */ |
885 | 870 | ||
871 | static inline bool cy_is_Z(struct cyclades_card *card) | ||
872 | { | ||
873 | return card->num_chips == (unsigned int)-1; | ||
874 | } | ||
875 | |||
876 | static inline bool __cyz_fpga_loaded(struct RUNTIME_9060 __iomem *ctl_addr) | ||
877 | { | ||
878 | return readl(&ctl_addr->init_ctrl) & (1 << 17); | ||
879 | } | ||
880 | |||
881 | static inline bool cyz_fpga_loaded(struct cyclades_card *card) | ||
882 | { | ||
883 | return __cyz_fpga_loaded(card->ctl_addr.p9060); | ||
884 | } | ||
885 | |||
886 | static inline bool cyz_is_loaded(struct cyclades_card *card) | ||
887 | { | ||
888 | struct FIRM_ID __iomem *fw_id = card->base_addr + ID_ADDRESS; | ||
889 | |||
890 | return (card->hw_ver == ZO_V1 || cyz_fpga_loaded(card)) && | ||
891 | readl(&fw_id->signature) == ZFIRM_ID; | ||
892 | } | ||
893 | |||
886 | static inline int serial_paranoia_check(struct cyclades_port *info, | 894 | static inline int serial_paranoia_check(struct cyclades_port *info, |
887 | char *name, const char *routine) | 895 | char *name, const char *routine) |
888 | { | 896 | { |
@@ -1395,19 +1403,15 @@ cyz_fetch_msg(struct cyclades_card *cinfo, | |||
1395 | unsigned long loc_doorbell; | 1403 | unsigned long loc_doorbell; |
1396 | 1404 | ||
1397 | firm_id = cinfo->base_addr + ID_ADDRESS; | 1405 | firm_id = cinfo->base_addr + ID_ADDRESS; |
1398 | if (!ISZLOADED(*cinfo)) | ||
1399 | return -1; | ||
1400 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 1406 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
1401 | board_ctrl = &zfw_ctrl->board_ctrl; | 1407 | board_ctrl = &zfw_ctrl->board_ctrl; |
1402 | 1408 | ||
1403 | loc_doorbell = readl(&((struct RUNTIME_9060 __iomem *) | 1409 | loc_doorbell = readl(&cinfo->ctl_addr.p9060->loc_doorbell); |
1404 | (cinfo->ctl_addr))->loc_doorbell); | ||
1405 | if (loc_doorbell) { | 1410 | if (loc_doorbell) { |
1406 | *cmd = (char)(0xff & loc_doorbell); | 1411 | *cmd = (char)(0xff & loc_doorbell); |
1407 | *channel = readl(&board_ctrl->fwcmd_channel); | 1412 | *channel = readl(&board_ctrl->fwcmd_channel); |
1408 | *param = (__u32) readl(&board_ctrl->fwcmd_param); | 1413 | *param = (__u32) readl(&board_ctrl->fwcmd_param); |
1409 | cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))-> | 1414 | cy_writel(&cinfo->ctl_addr.p9060->loc_doorbell, 0xffffffff); |
1410 | loc_doorbell, 0xffffffff); | ||
1411 | return 1; | 1415 | return 1; |
1412 | } | 1416 | } |
1413 | return 0; | 1417 | return 0; |
@@ -1424,15 +1428,14 @@ cyz_issue_cmd(struct cyclades_card *cinfo, | |||
1424 | unsigned int index; | 1428 | unsigned int index; |
1425 | 1429 | ||
1426 | firm_id = cinfo->base_addr + ID_ADDRESS; | 1430 | firm_id = cinfo->base_addr + ID_ADDRESS; |
1427 | if (!ISZLOADED(*cinfo)) | 1431 | if (!cyz_is_loaded(cinfo)) |
1428 | return -1; | 1432 | return -1; |
1429 | 1433 | ||
1430 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 1434 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
1431 | board_ctrl = &zfw_ctrl->board_ctrl; | 1435 | board_ctrl = &zfw_ctrl->board_ctrl; |
1432 | 1436 | ||
1433 | index = 0; | 1437 | index = 0; |
1434 | pci_doorbell = | 1438 | pci_doorbell = &cinfo->ctl_addr.p9060->pci_doorbell; |
1435 | &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell; | ||
1436 | while ((readl(pci_doorbell) & 0xff) != 0) { | 1439 | while ((readl(pci_doorbell) & 0xff) != 0) { |
1437 | if (index++ == 1000) | 1440 | if (index++ == 1000) |
1438 | return (int)(readl(pci_doorbell) & 0xff); | 1441 | return (int)(readl(pci_doorbell) & 0xff); |
@@ -1624,10 +1627,8 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo) | |||
1624 | static struct BOARD_CTRL __iomem *board_ctrl; | 1627 | static struct BOARD_CTRL __iomem *board_ctrl; |
1625 | static struct CH_CTRL __iomem *ch_ctrl; | 1628 | static struct CH_CTRL __iomem *ch_ctrl; |
1626 | static struct BUF_CTRL __iomem *buf_ctrl; | 1629 | static struct BUF_CTRL __iomem *buf_ctrl; |
1627 | __u32 channel; | 1630 | __u32 channel, param, fw_ver; |
1628 | __u8 cmd; | 1631 | __u8 cmd; |
1629 | __u32 param; | ||
1630 | __u32 hw_ver, fw_ver; | ||
1631 | int special_count; | 1632 | int special_count; |
1632 | int delta_count; | 1633 | int delta_count; |
1633 | 1634 | ||
@@ -1635,8 +1636,6 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo) | |||
1635 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 1636 | zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
1636 | board_ctrl = &zfw_ctrl->board_ctrl; | 1637 | board_ctrl = &zfw_ctrl->board_ctrl; |
1637 | fw_ver = readl(&board_ctrl->fw_version); | 1638 | fw_ver = readl(&board_ctrl->fw_version); |
1638 | hw_ver = readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))-> | ||
1639 | mail_box_0); | ||
1640 | 1639 | ||
1641 | while (cyz_fetch_msg(cinfo, &channel, &cmd, ¶m) == 1) { | 1640 | while (cyz_fetch_msg(cinfo, &channel, &cmd, ¶m) == 1) { |
1642 | special_count = 0; | 1641 | special_count = 0; |
@@ -1737,15 +1736,7 @@ static irqreturn_t cyz_interrupt(int irq, void *dev_id) | |||
1737 | { | 1736 | { |
1738 | struct cyclades_card *cinfo = dev_id; | 1737 | struct cyclades_card *cinfo = dev_id; |
1739 | 1738 | ||
1740 | if (unlikely(cinfo == NULL)) { | 1739 | if (unlikely(!cyz_is_loaded(cinfo))) { |
1741 | #ifdef CY_DEBUG_INTERRUPTS | ||
1742 | printk(KERN_DEBUG "cyz_interrupt: spurious interrupt %d\n", | ||
1743 | irq); | ||
1744 | #endif | ||
1745 | return IRQ_NONE; /* spurious interrupt */ | ||
1746 | } | ||
1747 | |||
1748 | if (unlikely(!ISZLOADED(*cinfo))) { | ||
1749 | #ifdef CY_DEBUG_INTERRUPTS | 1740 | #ifdef CY_DEBUG_INTERRUPTS |
1750 | printk(KERN_DEBUG "cyz_interrupt: board not yet loaded " | 1741 | printk(KERN_DEBUG "cyz_interrupt: board not yet loaded " |
1751 | "(IRQ%d).\n", irq); | 1742 | "(IRQ%d).\n", irq); |
@@ -1785,7 +1776,6 @@ static void cyz_poll(unsigned long arg) | |||
1785 | struct tty_struct *tty; | 1776 | struct tty_struct *tty; |
1786 | struct FIRM_ID __iomem *firm_id; | 1777 | struct FIRM_ID __iomem *firm_id; |
1787 | struct ZFW_CTRL __iomem *zfw_ctrl; | 1778 | struct ZFW_CTRL __iomem *zfw_ctrl; |
1788 | struct BOARD_CTRL __iomem *board_ctrl; | ||
1789 | struct BUF_CTRL __iomem *buf_ctrl; | 1779 | struct BUF_CTRL __iomem *buf_ctrl; |
1790 | unsigned long expires = jiffies + HZ; | 1780 | unsigned long expires = jiffies + HZ; |
1791 | unsigned int port, card; | 1781 | unsigned int port, card; |
@@ -1793,19 +1783,17 @@ static void cyz_poll(unsigned long arg) | |||
1793 | for (card = 0; card < NR_CARDS; card++) { | 1783 | for (card = 0; card < NR_CARDS; card++) { |
1794 | cinfo = &cy_card[card]; | 1784 | cinfo = &cy_card[card]; |
1795 | 1785 | ||
1796 | if (!IS_CYC_Z(*cinfo)) | 1786 | if (!cy_is_Z(cinfo)) |
1797 | continue; | 1787 | continue; |
1798 | if (!ISZLOADED(*cinfo)) | 1788 | if (!cyz_is_loaded(cinfo)) |
1799 | continue; | 1789 | continue; |
1800 | 1790 | ||
1801 | firm_id = cinfo->base_addr + ID_ADDRESS; | 1791 | firm_id = cinfo->base_addr + ID_ADDRESS; |
1802 | zfw_ctrl = cinfo->base_addr + | 1792 | zfw_ctrl = cinfo->base_addr + |
1803 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 1793 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
1804 | board_ctrl = &(zfw_ctrl->board_ctrl); | ||
1805 | 1794 | ||
1806 | /* Skip first polling cycle to avoid racing conditions with the FW */ | 1795 | /* Skip first polling cycle to avoid racing conditions with the FW */ |
1807 | if (!cinfo->intr_enabled) { | 1796 | if (!cinfo->intr_enabled) { |
1808 | cinfo->nports = (int)readl(&board_ctrl->n_channel); | ||
1809 | cinfo->intr_enabled = 1; | 1797 | cinfo->intr_enabled = 1; |
1810 | continue; | 1798 | continue; |
1811 | } | 1799 | } |
@@ -1874,7 +1862,7 @@ static int startup(struct cyclades_port *info) | |||
1874 | 1862 | ||
1875 | set_line_char(info); | 1863 | set_line_char(info); |
1876 | 1864 | ||
1877 | if (!IS_CYC_Z(*card)) { | 1865 | if (!cy_is_Z(card)) { |
1878 | chip = channel >> 2; | 1866 | chip = channel >> 2; |
1879 | channel &= 0x03; | 1867 | channel &= 0x03; |
1880 | index = card->bus_index; | 1868 | index = card->bus_index; |
@@ -1931,7 +1919,7 @@ static int startup(struct cyclades_port *info) | |||
1931 | base_addr = card->base_addr; | 1919 | base_addr = card->base_addr; |
1932 | 1920 | ||
1933 | firm_id = base_addr + ID_ADDRESS; | 1921 | firm_id = base_addr + ID_ADDRESS; |
1934 | if (!ISZLOADED(*card)) | 1922 | if (!cyz_is_loaded(card)) |
1935 | return -ENODEV; | 1923 | return -ENODEV; |
1936 | 1924 | ||
1937 | zfw_ctrl = card->base_addr + | 1925 | zfw_ctrl = card->base_addr + |
@@ -2026,7 +2014,7 @@ static void start_xmit(struct cyclades_port *info) | |||
2026 | 2014 | ||
2027 | card = info->card; | 2015 | card = info->card; |
2028 | channel = info->line - card->first_line; | 2016 | channel = info->line - card->first_line; |
2029 | if (!IS_CYC_Z(*card)) { | 2017 | if (!cy_is_Z(card)) { |
2030 | chip = channel >> 2; | 2018 | chip = channel >> 2; |
2031 | channel &= 0x03; | 2019 | channel &= 0x03; |
2032 | index = card->bus_index; | 2020 | index = card->bus_index; |
@@ -2070,7 +2058,7 @@ static void shutdown(struct cyclades_port *info) | |||
2070 | 2058 | ||
2071 | card = info->card; | 2059 | card = info->card; |
2072 | channel = info->line - card->first_line; | 2060 | channel = info->line - card->first_line; |
2073 | if (!IS_CYC_Z(*card)) { | 2061 | if (!cy_is_Z(card)) { |
2074 | chip = channel >> 2; | 2062 | chip = channel >> 2; |
2075 | channel &= 0x03; | 2063 | channel &= 0x03; |
2076 | index = card->bus_index; | 2064 | index = card->bus_index; |
@@ -2126,7 +2114,7 @@ static void shutdown(struct cyclades_port *info) | |||
2126 | #endif | 2114 | #endif |
2127 | 2115 | ||
2128 | firm_id = base_addr + ID_ADDRESS; | 2116 | firm_id = base_addr + ID_ADDRESS; |
2129 | if (!ISZLOADED(*card)) | 2117 | if (!cyz_is_loaded(card)) |
2130 | return; | 2118 | return; |
2131 | 2119 | ||
2132 | zfw_ctrl = card->base_addr + | 2120 | zfw_ctrl = card->base_addr + |
@@ -2233,7 +2221,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp, | |||
2233 | #endif | 2221 | #endif |
2234 | info->port.blocked_open++; | 2222 | info->port.blocked_open++; |
2235 | 2223 | ||
2236 | if (!IS_CYC_Z(*cinfo)) { | 2224 | if (!cy_is_Z(cinfo)) { |
2237 | chip = channel >> 2; | 2225 | chip = channel >> 2; |
2238 | channel &= 0x03; | 2226 | channel &= 0x03; |
2239 | index = cinfo->bus_index; | 2227 | index = cinfo->bus_index; |
@@ -2296,7 +2284,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp, | |||
2296 | 2284 | ||
2297 | base_addr = cinfo->base_addr; | 2285 | base_addr = cinfo->base_addr; |
2298 | firm_id = base_addr + ID_ADDRESS; | 2286 | firm_id = base_addr + ID_ADDRESS; |
2299 | if (!ISZLOADED(*cinfo)) { | 2287 | if (!cyz_is_loaded(cinfo)) { |
2300 | __set_current_state(TASK_RUNNING); | 2288 | __set_current_state(TASK_RUNNING); |
2301 | remove_wait_queue(&info->port.open_wait, &wait); | 2289 | remove_wait_queue(&info->port.open_wait, &wait); |
2302 | return -EINVAL; | 2290 | return -EINVAL; |
@@ -2397,16 +2385,14 @@ static int cy_open(struct tty_struct *tty, struct file *filp) | |||
2397 | treat it as absent from the system. This | 2385 | treat it as absent from the system. This |
2398 | will make the user pay attention. | 2386 | will make the user pay attention. |
2399 | */ | 2387 | */ |
2400 | if (IS_CYC_Z(*info->card)) { | 2388 | if (cy_is_Z(info->card)) { |
2401 | struct cyclades_card *cinfo = info->card; | 2389 | struct cyclades_card *cinfo = info->card; |
2402 | struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS; | 2390 | struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS; |
2403 | 2391 | ||
2404 | if (!ISZLOADED(*cinfo)) { | 2392 | if (!cyz_is_loaded(cinfo)) { |
2405 | if (((ZE_V1 == readl(&((struct RUNTIME_9060 __iomem *) | 2393 | if (cinfo->hw_ver == ZE_V1 && cyz_fpga_loaded(cinfo) && |
2406 | (cinfo->ctl_addr))->mail_box_0)) && | 2394 | readl(&firm_id->signature) == |
2407 | Z_FPGA_CHECK(*cinfo)) && | 2395 | ZFIRM_HLT) { |
2408 | (ZFIRM_HLT == readl( | ||
2409 | &firm_id->signature))) { | ||
2410 | printk(KERN_ERR "cyc:Cyclades-Z Error: you " | 2396 | printk(KERN_ERR "cyc:Cyclades-Z Error: you " |
2411 | "need an external power supply for " | 2397 | "need an external power supply for " |
2412 | "this number of ports.\nFirmware " | 2398 | "this number of ports.\nFirmware " |
@@ -2423,18 +2409,13 @@ static int cy_open(struct tty_struct *tty, struct file *filp) | |||
2423 | interrupts should be enabled as soon as the first open | 2409 | interrupts should be enabled as soon as the first open |
2424 | happens to one of its ports. */ | 2410 | happens to one of its ports. */ |
2425 | if (!cinfo->intr_enabled) { | 2411 | if (!cinfo->intr_enabled) { |
2426 | struct ZFW_CTRL __iomem *zfw_ctrl; | 2412 | u16 intr; |
2427 | struct BOARD_CTRL __iomem *board_ctrl; | ||
2428 | |||
2429 | zfw_ctrl = cinfo->base_addr + | ||
2430 | (readl(&firm_id->zfwctrl_addr) & | ||
2431 | 0xfffff); | ||
2432 | |||
2433 | board_ctrl = &zfw_ctrl->board_ctrl; | ||
2434 | 2413 | ||
2435 | /* Enable interrupts on the PLX chip */ | 2414 | /* Enable interrupts on the PLX chip */ |
2436 | cy_writew(cinfo->ctl_addr + 0x68, | 2415 | intr = readw(&cinfo->ctl_addr.p9060-> |
2437 | readw(cinfo->ctl_addr + 0x68) | 0x0900); | 2416 | intr_ctrl_stat) | 0x0900; |
2417 | cy_writew(&cinfo->ctl_addr.p9060-> | ||
2418 | intr_ctrl_stat, intr); | ||
2438 | /* Enable interrupts on the FW */ | 2419 | /* Enable interrupts on the FW */ |
2439 | retval = cyz_issue_cmd(cinfo, 0, | 2420 | retval = cyz_issue_cmd(cinfo, 0, |
2440 | C_CM_IRQ_ENBL, 0L); | 2421 | C_CM_IRQ_ENBL, 0L); |
@@ -2442,8 +2423,6 @@ static int cy_open(struct tty_struct *tty, struct file *filp) | |||
2442 | printk(KERN_ERR "cyc:IRQ enable retval " | 2423 | printk(KERN_ERR "cyc:IRQ enable retval " |
2443 | "was %x\n", retval); | 2424 | "was %x\n", retval); |
2444 | } | 2425 | } |
2445 | cinfo->nports = | ||
2446 | (int)readl(&board_ctrl->n_channel); | ||
2447 | cinfo->intr_enabled = 1; | 2426 | cinfo->intr_enabled = 1; |
2448 | } | 2427 | } |
2449 | } | 2428 | } |
@@ -2556,7 +2535,7 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout) | |||
2556 | #endif | 2535 | #endif |
2557 | card = info->card; | 2536 | card = info->card; |
2558 | channel = (info->line) - (card->first_line); | 2537 | channel = (info->line) - (card->first_line); |
2559 | if (!IS_CYC_Z(*card)) { | 2538 | if (!cy_is_Z(card)) { |
2560 | chip = channel >> 2; | 2539 | chip = channel >> 2; |
2561 | channel &= 0x03; | 2540 | channel &= 0x03; |
2562 | index = card->bus_index; | 2541 | index = card->bus_index; |
@@ -2601,7 +2580,7 @@ static void cy_flush_buffer(struct tty_struct *tty) | |||
2601 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; | 2580 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; |
2602 | spin_unlock_irqrestore(&card->card_lock, flags); | 2581 | spin_unlock_irqrestore(&card->card_lock, flags); |
2603 | 2582 | ||
2604 | if (IS_CYC_Z(*card)) { /* If it is a Z card, flush the on-board | 2583 | if (cy_is_Z(card)) { /* If it is a Z card, flush the on-board |
2605 | buffers as well */ | 2584 | buffers as well */ |
2606 | spin_lock_irqsave(&card->card_lock, flags); | 2585 | spin_lock_irqsave(&card->card_lock, flags); |
2607 | retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L); | 2586 | retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L); |
@@ -2682,7 +2661,7 @@ static void cy_close(struct tty_struct *tty, struct file *filp) | |||
2682 | 2661 | ||
2683 | spin_lock_irqsave(&card->card_lock, flags); | 2662 | spin_lock_irqsave(&card->card_lock, flags); |
2684 | 2663 | ||
2685 | if (!IS_CYC_Z(*card)) { | 2664 | if (!cy_is_Z(card)) { |
2686 | int channel = info->line - card->first_line; | 2665 | int channel = info->line - card->first_line; |
2687 | int index = card->bus_index; | 2666 | int index = card->bus_index; |
2688 | void __iomem *base_addr = card->base_addr + | 2667 | void __iomem *base_addr = card->base_addr + |
@@ -2902,7 +2881,7 @@ static int cy_chars_in_buffer(struct tty_struct *tty) | |||
2902 | channel = (info->line) - (card->first_line); | 2881 | channel = (info->line) - (card->first_line); |
2903 | 2882 | ||
2904 | #ifdef Z_EXT_CHARS_IN_BUFFER | 2883 | #ifdef Z_EXT_CHARS_IN_BUFFER |
2905 | if (!IS_CYC_Z(cy_card[card])) { | 2884 | if (!cy_is_Z(card)) { |
2906 | #endif /* Z_EXT_CHARS_IN_BUFFER */ | 2885 | #endif /* Z_EXT_CHARS_IN_BUFFER */ |
2907 | #ifdef CY_DEBUG_IO | 2886 | #ifdef CY_DEBUG_IO |
2908 | printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n", | 2887 | printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n", |
@@ -2984,7 +2963,6 @@ static void set_line_char(struct cyclades_port *info) | |||
2984 | void __iomem *base_addr; | 2963 | void __iomem *base_addr; |
2985 | int chip, channel, index; | 2964 | int chip, channel, index; |
2986 | unsigned cflag, iflag; | 2965 | unsigned cflag, iflag; |
2987 | unsigned short chip_number; | ||
2988 | int baud, baud_rate = 0; | 2966 | int baud, baud_rate = 0; |
2989 | int i; | 2967 | int i; |
2990 | 2968 | ||
@@ -3013,9 +2991,8 @@ static void set_line_char(struct cyclades_port *info) | |||
3013 | 2991 | ||
3014 | card = info->card; | 2992 | card = info->card; |
3015 | channel = info->line - card->first_line; | 2993 | channel = info->line - card->first_line; |
3016 | chip_number = channel / 4; | ||
3017 | 2994 | ||
3018 | if (!IS_CYC_Z(*card)) { | 2995 | if (!cy_is_Z(card)) { |
3019 | 2996 | ||
3020 | index = card->bus_index; | 2997 | index = card->bus_index; |
3021 | 2998 | ||
@@ -3233,21 +3210,17 @@ static void set_line_char(struct cyclades_port *info) | |||
3233 | } else { | 3210 | } else { |
3234 | struct FIRM_ID __iomem *firm_id; | 3211 | struct FIRM_ID __iomem *firm_id; |
3235 | struct ZFW_CTRL __iomem *zfw_ctrl; | 3212 | struct ZFW_CTRL __iomem *zfw_ctrl; |
3236 | struct BOARD_CTRL __iomem *board_ctrl; | ||
3237 | struct CH_CTRL __iomem *ch_ctrl; | 3213 | struct CH_CTRL __iomem *ch_ctrl; |
3238 | struct BUF_CTRL __iomem *buf_ctrl; | ||
3239 | __u32 sw_flow; | 3214 | __u32 sw_flow; |
3240 | int retval; | 3215 | int retval; |
3241 | 3216 | ||
3242 | firm_id = card->base_addr + ID_ADDRESS; | 3217 | firm_id = card->base_addr + ID_ADDRESS; |
3243 | if (!ISZLOADED(*card)) | 3218 | if (!cyz_is_loaded(card)) |
3244 | return; | 3219 | return; |
3245 | 3220 | ||
3246 | zfw_ctrl = card->base_addr + | 3221 | zfw_ctrl = card->base_addr + |
3247 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 3222 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
3248 | board_ctrl = &zfw_ctrl->board_ctrl; | ||
3249 | ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); | 3223 | ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); |
3250 | buf_ctrl = &zfw_ctrl->buf_ctrl[channel]; | ||
3251 | 3224 | ||
3252 | /* baud rate */ | 3225 | /* baud rate */ |
3253 | baud = tty_get_baud_rate(info->port.tty); | 3226 | baud = tty_get_baud_rate(info->port.tty); |
@@ -3457,7 +3430,7 @@ static int get_lsr_info(struct cyclades_port *info, unsigned int __user *value) | |||
3457 | 3430 | ||
3458 | card = info->card; | 3431 | card = info->card; |
3459 | channel = (info->line) - (card->first_line); | 3432 | channel = (info->line) - (card->first_line); |
3460 | if (!IS_CYC_Z(*card)) { | 3433 | if (!cy_is_Z(card)) { |
3461 | chip = channel >> 2; | 3434 | chip = channel >> 2; |
3462 | channel &= 0x03; | 3435 | channel &= 0x03; |
3463 | index = card->bus_index; | 3436 | index = card->bus_index; |
@@ -3497,7 +3470,7 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file) | |||
3497 | 3470 | ||
3498 | card = info->card; | 3471 | card = info->card; |
3499 | channel = info->line - card->first_line; | 3472 | channel = info->line - card->first_line; |
3500 | if (!IS_CYC_Z(*card)) { | 3473 | if (!cy_is_Z(card)) { |
3501 | chip = channel >> 2; | 3474 | chip = channel >> 2; |
3502 | channel &= 0x03; | 3475 | channel &= 0x03; |
3503 | index = card->bus_index; | 3476 | index = card->bus_index; |
@@ -3523,7 +3496,7 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file) | |||
3523 | } else { | 3496 | } else { |
3524 | base_addr = card->base_addr; | 3497 | base_addr = card->base_addr; |
3525 | firm_id = card->base_addr + ID_ADDRESS; | 3498 | firm_id = card->base_addr + ID_ADDRESS; |
3526 | if (ISZLOADED(*card)) { | 3499 | if (cyz_is_loaded(card)) { |
3527 | zfw_ctrl = card->base_addr + | 3500 | zfw_ctrl = card->base_addr + |
3528 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 3501 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
3529 | board_ctrl = &zfw_ctrl->board_ctrl; | 3502 | board_ctrl = &zfw_ctrl->board_ctrl; |
@@ -3566,7 +3539,7 @@ cy_tiocmset(struct tty_struct *tty, struct file *file, | |||
3566 | 3539 | ||
3567 | card = info->card; | 3540 | card = info->card; |
3568 | channel = (info->line) - (card->first_line); | 3541 | channel = (info->line) - (card->first_line); |
3569 | if (!IS_CYC_Z(*card)) { | 3542 | if (!cy_is_Z(card)) { |
3570 | chip = channel >> 2; | 3543 | chip = channel >> 2; |
3571 | channel &= 0x03; | 3544 | channel &= 0x03; |
3572 | index = card->bus_index; | 3545 | index = card->bus_index; |
@@ -3641,7 +3614,7 @@ cy_tiocmset(struct tty_struct *tty, struct file *file, | |||
3641 | base_addr = card->base_addr; | 3614 | base_addr = card->base_addr; |
3642 | 3615 | ||
3643 | firm_id = card->base_addr + ID_ADDRESS; | 3616 | firm_id = card->base_addr + ID_ADDRESS; |
3644 | if (ISZLOADED(*card)) { | 3617 | if (cyz_is_loaded(card)) { |
3645 | zfw_ctrl = card->base_addr + | 3618 | zfw_ctrl = card->base_addr + |
3646 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); | 3619 | (readl(&firm_id->zfwctrl_addr) & 0xfffff); |
3647 | board_ctrl = &zfw_ctrl->board_ctrl; | 3620 | board_ctrl = &zfw_ctrl->board_ctrl; |
@@ -3713,7 +3686,7 @@ static int cy_break(struct tty_struct *tty, int break_state) | |||
3713 | card = info->card; | 3686 | card = info->card; |
3714 | 3687 | ||
3715 | spin_lock_irqsave(&card->card_lock, flags); | 3688 | spin_lock_irqsave(&card->card_lock, flags); |
3716 | if (!IS_CYC_Z(*card)) { | 3689 | if (!cy_is_Z(card)) { |
3717 | /* Let the transmit ISR take care of this (since it | 3690 | /* Let the transmit ISR take care of this (since it |
3718 | requires stuffing characters into the output stream). | 3691 | requires stuffing characters into the output stream). |
3719 | */ | 3692 | */ |
@@ -3782,7 +3755,7 @@ static int set_threshold(struct cyclades_port *info, unsigned long value) | |||
3782 | 3755 | ||
3783 | card = info->card; | 3756 | card = info->card; |
3784 | channel = info->line - card->first_line; | 3757 | channel = info->line - card->first_line; |
3785 | if (!IS_CYC_Z(*card)) { | 3758 | if (!cy_is_Z(card)) { |
3786 | chip = channel >> 2; | 3759 | chip = channel >> 2; |
3787 | channel &= 0x03; | 3760 | channel &= 0x03; |
3788 | index = card->bus_index; | 3761 | index = card->bus_index; |
@@ -3810,7 +3783,7 @@ static int get_threshold(struct cyclades_port *info, | |||
3810 | 3783 | ||
3811 | card = info->card; | 3784 | card = info->card; |
3812 | channel = info->line - card->first_line; | 3785 | channel = info->line - card->first_line; |
3813 | if (!IS_CYC_Z(*card)) { | 3786 | if (!cy_is_Z(card)) { |
3814 | chip = channel >> 2; | 3787 | chip = channel >> 2; |
3815 | channel &= 0x03; | 3788 | channel &= 0x03; |
3816 | index = card->bus_index; | 3789 | index = card->bus_index; |
@@ -3844,7 +3817,7 @@ static int set_timeout(struct cyclades_port *info, unsigned long value) | |||
3844 | 3817 | ||
3845 | card = info->card; | 3818 | card = info->card; |
3846 | channel = info->line - card->first_line; | 3819 | channel = info->line - card->first_line; |
3847 | if (!IS_CYC_Z(*card)) { | 3820 | if (!cy_is_Z(card)) { |
3848 | chip = channel >> 2; | 3821 | chip = channel >> 2; |
3849 | channel &= 0x03; | 3822 | channel &= 0x03; |
3850 | index = card->bus_index; | 3823 | index = card->bus_index; |
@@ -3867,7 +3840,7 @@ static int get_timeout(struct cyclades_port *info, | |||
3867 | 3840 | ||
3868 | card = info->card; | 3841 | card = info->card; |
3869 | channel = info->line - card->first_line; | 3842 | channel = info->line - card->first_line; |
3870 | if (!IS_CYC_Z(*card)) { | 3843 | if (!cy_is_Z(card)) { |
3871 | chip = channel >> 2; | 3844 | chip = channel >> 2; |
3872 | channel &= 0x03; | 3845 | channel &= 0x03; |
3873 | index = card->bus_index; | 3846 | index = card->bus_index; |
@@ -4121,7 +4094,7 @@ static void cy_send_xchar(struct tty_struct *tty, char ch) | |||
4121 | card = info->card; | 4094 | card = info->card; |
4122 | channel = info->line - card->first_line; | 4095 | channel = info->line - card->first_line; |
4123 | 4096 | ||
4124 | if (IS_CYC_Z(*card)) { | 4097 | if (cy_is_Z(card)) { |
4125 | if (ch == STOP_CHAR(tty)) | 4098 | if (ch == STOP_CHAR(tty)) |
4126 | cyz_issue_cmd(card, channel, C_CM_SENDXOFF, 0L); | 4099 | cyz_issue_cmd(card, channel, C_CM_SENDXOFF, 0L); |
4127 | else if (ch == START_CHAR(tty)) | 4100 | else if (ch == START_CHAR(tty)) |
@@ -4154,7 +4127,7 @@ static void cy_throttle(struct tty_struct *tty) | |||
4154 | card = info->card; | 4127 | card = info->card; |
4155 | 4128 | ||
4156 | if (I_IXOFF(tty)) { | 4129 | if (I_IXOFF(tty)) { |
4157 | if (!IS_CYC_Z(*card)) | 4130 | if (!cy_is_Z(card)) |
4158 | cy_send_xchar(tty, STOP_CHAR(tty)); | 4131 | cy_send_xchar(tty, STOP_CHAR(tty)); |
4159 | else | 4132 | else |
4160 | info->throttle = 1; | 4133 | info->throttle = 1; |
@@ -4162,7 +4135,7 @@ static void cy_throttle(struct tty_struct *tty) | |||
4162 | 4135 | ||
4163 | if (tty->termios->c_cflag & CRTSCTS) { | 4136 | if (tty->termios->c_cflag & CRTSCTS) { |
4164 | channel = info->line - card->first_line; | 4137 | channel = info->line - card->first_line; |
4165 | if (!IS_CYC_Z(*card)) { | 4138 | if (!cy_is_Z(card)) { |
4166 | chip = channel >> 2; | 4139 | chip = channel >> 2; |
4167 | channel &= 0x03; | 4140 | channel &= 0x03; |
4168 | index = card->bus_index; | 4141 | index = card->bus_index; |
@@ -4219,7 +4192,7 @@ static void cy_unthrottle(struct tty_struct *tty) | |||
4219 | if (tty->termios->c_cflag & CRTSCTS) { | 4192 | if (tty->termios->c_cflag & CRTSCTS) { |
4220 | card = info->card; | 4193 | card = info->card; |
4221 | channel = info->line - card->first_line; | 4194 | channel = info->line - card->first_line; |
4222 | if (!IS_CYC_Z(*card)) { | 4195 | if (!cy_is_Z(card)) { |
4223 | chip = channel >> 2; | 4196 | chip = channel >> 2; |
4224 | channel &= 0x03; | 4197 | channel &= 0x03; |
4225 | index = card->bus_index; | 4198 | index = card->bus_index; |
@@ -4263,7 +4236,7 @@ static void cy_stop(struct tty_struct *tty) | |||
4263 | 4236 | ||
4264 | cinfo = info->card; | 4237 | cinfo = info->card; |
4265 | channel = info->line - cinfo->first_line; | 4238 | channel = info->line - cinfo->first_line; |
4266 | if (!IS_CYC_Z(*cinfo)) { | 4239 | if (!cy_is_Z(cinfo)) { |
4267 | index = cinfo->bus_index; | 4240 | index = cinfo->bus_index; |
4268 | chip = channel >> 2; | 4241 | chip = channel >> 2; |
4269 | channel &= 0x03; | 4242 | channel &= 0x03; |
@@ -4296,7 +4269,7 @@ static void cy_start(struct tty_struct *tty) | |||
4296 | cinfo = info->card; | 4269 | cinfo = info->card; |
4297 | channel = info->line - cinfo->first_line; | 4270 | channel = info->line - cinfo->first_line; |
4298 | index = cinfo->bus_index; | 4271 | index = cinfo->bus_index; |
4299 | if (!IS_CYC_Z(*cinfo)) { | 4272 | if (!cy_is_Z(cinfo)) { |
4300 | chip = channel >> 2; | 4273 | chip = channel >> 2; |
4301 | channel &= 0x03; | 4274 | channel &= 0x03; |
4302 | base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index); | 4275 | base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index); |
@@ -4347,33 +4320,20 @@ static void cy_hangup(struct tty_struct *tty) | |||
4347 | static int __devinit cy_init_card(struct cyclades_card *cinfo) | 4320 | static int __devinit cy_init_card(struct cyclades_card *cinfo) |
4348 | { | 4321 | { |
4349 | struct cyclades_port *info; | 4322 | struct cyclades_port *info; |
4350 | u32 uninitialized_var(mailbox); | 4323 | unsigned int port; |
4351 | unsigned int nports, port; | ||
4352 | unsigned short chip_number; | 4324 | unsigned short chip_number; |
4353 | int uninitialized_var(index); | ||
4354 | 4325 | ||
4355 | spin_lock_init(&cinfo->card_lock); | 4326 | spin_lock_init(&cinfo->card_lock); |
4327 | cinfo->intr_enabled = 0; | ||
4356 | 4328 | ||
4357 | if (IS_CYC_Z(*cinfo)) { /* Cyclades-Z */ | 4329 | cinfo->ports = kcalloc(cinfo->nports, sizeof(*cinfo->ports), |
4358 | mailbox = readl(&((struct RUNTIME_9060 __iomem *) | 4330 | GFP_KERNEL); |
4359 | cinfo->ctl_addr)->mail_box_0); | ||
4360 | nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8; | ||
4361 | cinfo->intr_enabled = 0; | ||
4362 | cinfo->nports = 0; /* Will be correctly set later, after | ||
4363 | Z FW is loaded */ | ||
4364 | } else { | ||
4365 | index = cinfo->bus_index; | ||
4366 | nports = cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips; | ||
4367 | } | ||
4368 | |||
4369 | cinfo->ports = kzalloc(sizeof(*cinfo->ports) * nports, GFP_KERNEL); | ||
4370 | if (cinfo->ports == NULL) { | 4331 | if (cinfo->ports == NULL) { |
4371 | printk(KERN_ERR "Cyclades: cannot allocate ports\n"); | 4332 | printk(KERN_ERR "Cyclades: cannot allocate ports\n"); |
4372 | cinfo->nports = 0; | ||
4373 | return -ENOMEM; | 4333 | return -ENOMEM; |
4374 | } | 4334 | } |
4375 | 4335 | ||
4376 | for (port = cinfo->first_line; port < cinfo->first_line + nports; | 4336 | for (port = cinfo->first_line; port < cinfo->first_line + cinfo->nports; |
4377 | port++) { | 4337 | port++) { |
4378 | info = &cinfo->ports[port - cinfo->first_line]; | 4338 | info = &cinfo->ports[port - cinfo->first_line]; |
4379 | tty_port_init(&info->port); | 4339 | tty_port_init(&info->port); |
@@ -4387,9 +4347,9 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo) | |||
4387 | init_completion(&info->shutdown_wait); | 4347 | init_completion(&info->shutdown_wait); |
4388 | init_waitqueue_head(&info->delta_msr_wait); | 4348 | init_waitqueue_head(&info->delta_msr_wait); |
4389 | 4349 | ||
4390 | if (IS_CYC_Z(*cinfo)) { | 4350 | if (cy_is_Z(cinfo)) { |
4391 | info->type = PORT_STARTECH; | 4351 | info->type = PORT_STARTECH; |
4392 | if (mailbox == ZO_V1) | 4352 | if (cinfo->hw_ver == ZO_V1) |
4393 | info->xmit_fifo_size = CYZ_FIFO_SIZE; | 4353 | info->xmit_fifo_size = CYZ_FIFO_SIZE; |
4394 | else | 4354 | else |
4395 | info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE; | 4355 | info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE; |
@@ -4398,6 +4358,7 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo) | |||
4398 | cyz_rx_restart, (unsigned long)info); | 4358 | cyz_rx_restart, (unsigned long)info); |
4399 | #endif | 4359 | #endif |
4400 | } else { | 4360 | } else { |
4361 | int index = cinfo->bus_index; | ||
4401 | info->type = PORT_CIRRUS; | 4362 | info->type = PORT_CIRRUS; |
4402 | info->xmit_fifo_size = CyMAX_CHAR_FIFO; | 4363 | info->xmit_fifo_size = CyMAX_CHAR_FIFO; |
4403 | info->cor1 = CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS; | 4364 | info->cor1 = CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS; |
@@ -4430,7 +4391,7 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo) | |||
4430 | } | 4391 | } |
4431 | 4392 | ||
4432 | #ifndef CONFIG_CYZ_INTR | 4393 | #ifndef CONFIG_CYZ_INTR |
4433 | if (IS_CYC_Z(*cinfo) && !timer_pending(&cyz_timerlist)) { | 4394 | if (cy_is_Z(cinfo) && !timer_pending(&cyz_timerlist)) { |
4434 | mod_timer(&cyz_timerlist, jiffies + 1); | 4395 | mod_timer(&cyz_timerlist, jiffies + 1); |
4435 | #ifdef CY_PCI_DEBUG | 4396 | #ifdef CY_PCI_DEBUG |
4436 | printk(KERN_DEBUG "Cyclades-Z polling initialized\n"); | 4397 | printk(KERN_DEBUG "Cyclades-Z polling initialized\n"); |
@@ -4621,11 +4582,12 @@ static int __init cy_detect_isa(void) | |||
4621 | 4582 | ||
4622 | /* set cy_card */ | 4583 | /* set cy_card */ |
4623 | cy_card[j].base_addr = cy_isa_address; | 4584 | cy_card[j].base_addr = cy_isa_address; |
4624 | cy_card[j].ctl_addr = NULL; | 4585 | cy_card[j].ctl_addr.p9050 = NULL; |
4625 | cy_card[j].irq = (int)cy_isa_irq; | 4586 | cy_card[j].irq = (int)cy_isa_irq; |
4626 | cy_card[j].bus_index = 0; | 4587 | cy_card[j].bus_index = 0; |
4627 | cy_card[j].first_line = cy_next_channel; | 4588 | cy_card[j].first_line = cy_next_channel; |
4628 | cy_card[j].num_chips = cy_isa_nchan / 4; | 4589 | cy_card[j].num_chips = cy_isa_nchan / CyPORTS_PER_CHIP; |
4590 | cy_card[j].nports = cy_isa_nchan; | ||
4629 | if (cy_init_card(&cy_card[j])) { | 4591 | if (cy_init_card(&cy_card[j])) { |
4630 | cy_card[j].base_addr = NULL; | 4592 | cy_card[j].base_addr = NULL; |
4631 | free_irq(cy_isa_irq, &cy_card[j]); | 4593 | free_irq(cy_isa_irq, &cy_card[j]); |
@@ -4781,7 +4743,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4781 | struct CUSTOM_REG __iomem *cust = base_addr; | 4743 | struct CUSTOM_REG __iomem *cust = base_addr; |
4782 | struct ZFW_CTRL __iomem *pt_zfwctrl; | 4744 | struct ZFW_CTRL __iomem *pt_zfwctrl; |
4783 | void __iomem *tmp; | 4745 | void __iomem *tmp; |
4784 | u32 mailbox, status; | 4746 | u32 mailbox, status, nchan; |
4785 | unsigned int i; | 4747 | unsigned int i; |
4786 | int retval; | 4748 | int retval; |
4787 | 4749 | ||
@@ -4793,7 +4755,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4793 | 4755 | ||
4794 | /* Check whether the firmware is already loaded and running. If | 4756 | /* Check whether the firmware is already loaded and running. If |
4795 | positive, skip this board */ | 4757 | positive, skip this board */ |
4796 | if (Z_FPGA_LOADED(ctl_addr) && readl(&fid->signature) == ZFIRM_ID) { | 4758 | if (__cyz_fpga_loaded(ctl_addr) && readl(&fid->signature) == ZFIRM_ID) { |
4797 | u32 cntval = readl(base_addr + 0x190); | 4759 | u32 cntval = readl(base_addr + 0x190); |
4798 | 4760 | ||
4799 | udelay(100); | 4761 | udelay(100); |
@@ -4812,7 +4774,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4812 | 4774 | ||
4813 | mailbox = readl(&ctl_addr->mail_box_0); | 4775 | mailbox = readl(&ctl_addr->mail_box_0); |
4814 | 4776 | ||
4815 | if (mailbox == 0 || Z_FPGA_LOADED(ctl_addr)) { | 4777 | if (mailbox == 0 || __cyz_fpga_loaded(ctl_addr)) { |
4816 | /* stops CPU and set window to beginning of RAM */ | 4778 | /* stops CPU and set window to beginning of RAM */ |
4817 | cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); | 4779 | cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); |
4818 | cy_writel(&cust->cpu_stop, 0); | 4780 | cy_writel(&cust->cpu_stop, 0); |
@@ -4828,7 +4790,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4828 | base_addr); | 4790 | base_addr); |
4829 | if (retval) | 4791 | if (retval) |
4830 | goto err_rel; | 4792 | goto err_rel; |
4831 | if (!Z_FPGA_LOADED(ctl_addr)) { | 4793 | if (!__cyz_fpga_loaded(ctl_addr)) { |
4832 | dev_err(&pdev->dev, "fw upload successful, but fw is " | 4794 | dev_err(&pdev->dev, "fw upload successful, but fw is " |
4833 | "not loaded\n"); | 4795 | "not loaded\n"); |
4834 | goto err_rel; | 4796 | goto err_rel; |
@@ -4887,7 +4849,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4887 | "system before loading the new FW to the " | 4849 | "system before loading the new FW to the " |
4888 | "Cyclades-Z.\n"); | 4850 | "Cyclades-Z.\n"); |
4889 | 4851 | ||
4890 | if (Z_FPGA_LOADED(ctl_addr)) | 4852 | if (__cyz_fpga_loaded(ctl_addr)) |
4891 | plx_init(pdev, irq, ctl_addr); | 4853 | plx_init(pdev, irq, ctl_addr); |
4892 | 4854 | ||
4893 | retval = -EIO; | 4855 | retval = -EIO; |
@@ -4902,16 +4864,16 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4902 | base_addr + ID_ADDRESS, readl(&fid->zfwctrl_addr), | 4864 | base_addr + ID_ADDRESS, readl(&fid->zfwctrl_addr), |
4903 | base_addr + readl(&fid->zfwctrl_addr)); | 4865 | base_addr + readl(&fid->zfwctrl_addr)); |
4904 | 4866 | ||
4867 | nchan = readl(&pt_zfwctrl->board_ctrl.n_channel); | ||
4905 | dev_info(&pdev->dev, "Cyclades-Z FW loaded: version = %x, ports = %u\n", | 4868 | dev_info(&pdev->dev, "Cyclades-Z FW loaded: version = %x, ports = %u\n", |
4906 | readl(&pt_zfwctrl->board_ctrl.fw_version), | 4869 | readl(&pt_zfwctrl->board_ctrl.fw_version), nchan); |
4907 | readl(&pt_zfwctrl->board_ctrl.n_channel)); | ||
4908 | 4870 | ||
4909 | if (readl(&pt_zfwctrl->board_ctrl.n_channel) == 0) { | 4871 | if (nchan == 0) { |
4910 | dev_warn(&pdev->dev, "no Cyclades-Z ports were found. Please " | 4872 | dev_warn(&pdev->dev, "no Cyclades-Z ports were found. Please " |
4911 | "check the connection between the Z host card and the " | 4873 | "check the connection between the Z host card and the " |
4912 | "serial expanders.\n"); | 4874 | "serial expanders.\n"); |
4913 | 4875 | ||
4914 | if (Z_FPGA_LOADED(ctl_addr)) | 4876 | if (__cyz_fpga_loaded(ctl_addr)) |
4915 | plx_init(pdev, irq, ctl_addr); | 4877 | plx_init(pdev, irq, ctl_addr); |
4916 | 4878 | ||
4917 | dev_info(&pdev->dev, "Null number of ports detected. Board " | 4879 | dev_info(&pdev->dev, "Null number of ports detected. Board " |
@@ -4932,9 +4894,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, | |||
4932 | cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) | | 4894 | cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) | |
4933 | 0x00030800UL); | 4895 | 0x00030800UL); |
4934 | 4896 | ||
4935 | plx_init(pdev, irq, ctl_addr); | 4897 | return nchan; |
4936 | |||
4937 | return 0; | ||
4938 | err_rel: | 4898 | err_rel: |
4939 | release_firmware(fw); | 4899 | release_firmware(fw); |
4940 | err: | 4900 | err: |
@@ -4946,7 +4906,7 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
4946 | { | 4906 | { |
4947 | void __iomem *addr0 = NULL, *addr2 = NULL; | 4907 | void __iomem *addr0 = NULL, *addr2 = NULL; |
4948 | char *card_name = NULL; | 4908 | char *card_name = NULL; |
4949 | u32 mailbox; | 4909 | u32 uninitialized_var(mailbox); |
4950 | unsigned int device_id, nchan = 0, card_no, i; | 4910 | unsigned int device_id, nchan = 0, card_no, i; |
4951 | unsigned char plx_ver; | 4911 | unsigned char plx_ver; |
4952 | int retval, irq; | 4912 | int retval, irq; |
@@ -5023,11 +4983,12 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5023 | } | 4983 | } |
5024 | 4984 | ||
5025 | /* Disable interrupts on the PLX before resetting it */ | 4985 | /* Disable interrupts on the PLX before resetting it */ |
5026 | cy_writew(addr0 + 0x68, readw(addr0 + 0x68) & ~0x0900); | 4986 | cy_writew(&ctl_addr->intr_ctrl_stat, |
4987 | readw(&ctl_addr->intr_ctrl_stat) & ~0x0900); | ||
5027 | 4988 | ||
5028 | plx_init(pdev, irq, addr0); | 4989 | plx_init(pdev, irq, addr0); |
5029 | 4990 | ||
5030 | mailbox = (u32)readl(&ctl_addr->mail_box_0); | 4991 | mailbox = readl(&ctl_addr->mail_box_0); |
5031 | 4992 | ||
5032 | addr2 = ioremap_nocache(pci_resource_start(pdev, 2), | 4993 | addr2 = ioremap_nocache(pci_resource_start(pdev, 2), |
5033 | mailbox == ZE_V1 ? CyPCI_Ze_win : CyPCI_Zwin); | 4994 | mailbox == ZE_V1 ? CyPCI_Ze_win : CyPCI_Zwin); |
@@ -5038,12 +4999,8 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5038 | 4999 | ||
5039 | if (mailbox == ZE_V1) { | 5000 | if (mailbox == ZE_V1) { |
5040 | card_name = "Cyclades-Ze"; | 5001 | card_name = "Cyclades-Ze"; |
5041 | |||
5042 | readl(&ctl_addr->mail_box_0); | ||
5043 | nchan = ZE_V1_NPORTS; | ||
5044 | } else { | 5002 | } else { |
5045 | card_name = "Cyclades-8Zo"; | 5003 | card_name = "Cyclades-8Zo"; |
5046 | |||
5047 | #ifdef CY_PCI_DEBUG | 5004 | #ifdef CY_PCI_DEBUG |
5048 | if (mailbox == ZO_V1) { | 5005 | if (mailbox == ZO_V1) { |
5049 | cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); | 5006 | cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); |
@@ -5065,15 +5022,12 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5065 | */ | 5022 | */ |
5066 | if ((mailbox == ZO_V1) || (mailbox == ZO_V2)) | 5023 | if ((mailbox == ZO_V1) || (mailbox == ZO_V2)) |
5067 | cy_writel(addr2 + ID_ADDRESS, 0L); | 5024 | cy_writel(addr2 + ID_ADDRESS, 0L); |
5068 | |||
5069 | retval = cyz_load_fw(pdev, addr2, addr0, irq); | ||
5070 | if (retval) | ||
5071 | goto err_unmap; | ||
5072 | /* This must be a Cyclades-8Zo/PCI. The extendable | ||
5073 | version will have a different device_id and will | ||
5074 | be allocated its maximum number of ports. */ | ||
5075 | nchan = 8; | ||
5076 | } | 5025 | } |
5026 | |||
5027 | retval = cyz_load_fw(pdev, addr2, addr0, irq); | ||
5028 | if (retval <= 0) | ||
5029 | goto err_unmap; | ||
5030 | nchan = retval; | ||
5077 | } | 5031 | } |
5078 | 5032 | ||
5079 | if ((cy_next_channel + nchan) > NR_PORTS) { | 5033 | if ((cy_next_channel + nchan) > NR_PORTS) { |
@@ -5103,8 +5057,10 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5103 | dev_err(&pdev->dev, "could not allocate IRQ\n"); | 5057 | dev_err(&pdev->dev, "could not allocate IRQ\n"); |
5104 | goto err_unmap; | 5058 | goto err_unmap; |
5105 | } | 5059 | } |
5106 | cy_card[card_no].num_chips = nchan / 4; | 5060 | cy_card[card_no].num_chips = nchan / CyPORTS_PER_CHIP; |
5107 | } else { | 5061 | } else { |
5062 | cy_card[card_no].hw_ver = mailbox; | ||
5063 | cy_card[card_no].num_chips = (unsigned int)-1; | ||
5108 | #ifdef CONFIG_CYZ_INTR | 5064 | #ifdef CONFIG_CYZ_INTR |
5109 | /* allocate IRQ only if board has an IRQ */ | 5065 | /* allocate IRQ only if board has an IRQ */ |
5110 | if (irq != 0 && irq != 255) { | 5066 | if (irq != 0 && irq != 255) { |
@@ -5117,15 +5073,15 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5117 | } | 5073 | } |
5118 | } | 5074 | } |
5119 | #endif /* CONFIG_CYZ_INTR */ | 5075 | #endif /* CONFIG_CYZ_INTR */ |
5120 | cy_card[card_no].num_chips = (unsigned int)-1; | ||
5121 | } | 5076 | } |
5122 | 5077 | ||
5123 | /* set cy_card */ | 5078 | /* set cy_card */ |
5124 | cy_card[card_no].base_addr = addr2; | 5079 | cy_card[card_no].base_addr = addr2; |
5125 | cy_card[card_no].ctl_addr = addr0; | 5080 | cy_card[card_no].ctl_addr.p9050 = addr0; |
5126 | cy_card[card_no].irq = irq; | 5081 | cy_card[card_no].irq = irq; |
5127 | cy_card[card_no].bus_index = 1; | 5082 | cy_card[card_no].bus_index = 1; |
5128 | cy_card[card_no].first_line = cy_next_channel; | 5083 | cy_card[card_no].first_line = cy_next_channel; |
5084 | cy_card[card_no].nports = nchan; | ||
5129 | retval = cy_init_card(&cy_card[card_no]); | 5085 | retval = cy_init_card(&cy_card[card_no]); |
5130 | if (retval) | 5086 | if (retval) |
5131 | goto err_null; | 5087 | goto err_null; |
@@ -5138,17 +5094,20 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, | |||
5138 | plx_ver = readb(addr2 + CyPLX_VER) & 0x0f; | 5094 | plx_ver = readb(addr2 + CyPLX_VER) & 0x0f; |
5139 | switch (plx_ver) { | 5095 | switch (plx_ver) { |
5140 | case PLX_9050: | 5096 | case PLX_9050: |
5141 | |||
5142 | cy_writeb(addr0 + 0x4c, 0x43); | 5097 | cy_writeb(addr0 + 0x4c, 0x43); |
5143 | break; | 5098 | break; |
5144 | 5099 | ||
5145 | case PLX_9060: | 5100 | case PLX_9060: |
5146 | case PLX_9080: | 5101 | case PLX_9080: |
5147 | default: /* Old boards, use PLX_9060 */ | 5102 | default: /* Old boards, use PLX_9060 */ |
5148 | plx_init(pdev, irq, addr0); | 5103 | { |
5149 | cy_writew(addr0 + 0x68, readw(addr0 + 0x68) | 0x0900); | 5104 | struct RUNTIME_9060 __iomem *ctl_addr = addr0; |
5105 | plx_init(pdev, irq, ctl_addr); | ||
5106 | cy_writew(&ctl_addr->intr_ctrl_stat, | ||
5107 | readw(&ctl_addr->intr_ctrl_stat) | 0x0900); | ||
5150 | break; | 5108 | break; |
5151 | } | 5109 | } |
5110 | } | ||
5152 | } | 5111 | } |
5153 | 5112 | ||
5154 | dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from " | 5113 | dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from " |
@@ -5179,22 +5138,23 @@ static void __devexit cy_pci_remove(struct pci_dev *pdev) | |||
5179 | unsigned int i; | 5138 | unsigned int i; |
5180 | 5139 | ||
5181 | /* non-Z with old PLX */ | 5140 | /* non-Z with old PLX */ |
5182 | if (!IS_CYC_Z(*cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) == | 5141 | if (!cy_is_Z(cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) == |
5183 | PLX_9050) | 5142 | PLX_9050) |
5184 | cy_writeb(cinfo->ctl_addr + 0x4c, 0); | 5143 | cy_writeb(cinfo->ctl_addr.p9050 + 0x4c, 0); |
5185 | else | 5144 | else |
5186 | #ifndef CONFIG_CYZ_INTR | 5145 | #ifndef CONFIG_CYZ_INTR |
5187 | if (!IS_CYC_Z(*cinfo)) | 5146 | if (!cy_is_Z(cinfo)) |
5188 | #endif | 5147 | #endif |
5189 | cy_writew(cinfo->ctl_addr + 0x68, | 5148 | cy_writew(&cinfo->ctl_addr.p9060->intr_ctrl_stat, |
5190 | readw(cinfo->ctl_addr + 0x68) & ~0x0900); | 5149 | readw(&cinfo->ctl_addr.p9060->intr_ctrl_stat) & |
5150 | ~0x0900); | ||
5191 | 5151 | ||
5192 | iounmap(cinfo->base_addr); | 5152 | iounmap(cinfo->base_addr); |
5193 | if (cinfo->ctl_addr) | 5153 | if (cinfo->ctl_addr.p9050) |
5194 | iounmap(cinfo->ctl_addr); | 5154 | iounmap(cinfo->ctl_addr.p9050); |
5195 | if (cinfo->irq | 5155 | if (cinfo->irq |
5196 | #ifndef CONFIG_CYZ_INTR | 5156 | #ifndef CONFIG_CYZ_INTR |
5197 | && !IS_CYC_Z(*cinfo) | 5157 | && !cy_is_Z(cinfo) |
5198 | #endif /* CONFIG_CYZ_INTR */ | 5158 | #endif /* CONFIG_CYZ_INTR */ |
5199 | ) | 5159 | ) |
5200 | free_irq(cinfo->irq, cinfo); | 5160 | free_irq(cinfo->irq, cinfo); |
@@ -5240,7 +5200,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v) | |||
5240 | (cur_jifs - info->idle_stats.recv_idle)/ | 5200 | (cur_jifs - info->idle_stats.recv_idle)/ |
5241 | HZ, info->idle_stats.overruns, | 5201 | HZ, info->idle_stats.overruns, |
5242 | /* FIXME: double check locking */ | 5202 | /* FIXME: double check locking */ |
5243 | (long)info->port.tty->ldisc.ops->num); | 5203 | (long)info->port.tty->ldisc->ops->num); |
5244 | else | 5204 | else |
5245 | seq_printf(m, "%3d %8lu %10lu %8lu " | 5205 | seq_printf(m, "%3d %8lu %10lu %8lu " |
5246 | "%10lu %8lu %9lu %6ld\n", | 5206 | "%10lu %8lu %9lu %6ld\n", |
@@ -5386,11 +5346,11 @@ static void __exit cy_cleanup_module(void) | |||
5386 | /* clear interrupt */ | 5346 | /* clear interrupt */ |
5387 | cy_writeb(card->base_addr + Cy_ClrIntr, 0); | 5347 | cy_writeb(card->base_addr + Cy_ClrIntr, 0); |
5388 | iounmap(card->base_addr); | 5348 | iounmap(card->base_addr); |
5389 | if (card->ctl_addr) | 5349 | if (card->ctl_addr.p9050) |
5390 | iounmap(card->ctl_addr); | 5350 | iounmap(card->ctl_addr.p9050); |
5391 | if (card->irq | 5351 | if (card->irq |
5392 | #ifndef CONFIG_CYZ_INTR | 5352 | #ifndef CONFIG_CYZ_INTR |
5393 | && !IS_CYC_Z(*card) | 5353 | && !cy_is_Z(card) |
5394 | #endif /* CONFIG_CYZ_INTR */ | 5354 | #endif /* CONFIG_CYZ_INTR */ |
5395 | ) | 5355 | ) |
5396 | free_irq(card->irq, card); | 5356 | free_irq(card->irq, card); |
diff --git a/drivers/char/epca.c b/drivers/char/epca.c index af7c13ca9493..abef1f7d84fe 100644 --- a/drivers/char/epca.c +++ b/drivers/char/epca.c | |||
@@ -745,7 +745,7 @@ static int epca_carrier_raised(struct tty_port *port) | |||
745 | return 0; | 745 | return 0; |
746 | } | 746 | } |
747 | 747 | ||
748 | static void epca_raise_dtr_rts(struct tty_port *port) | 748 | static void epca_dtr_rts(struct tty_port *port, int onoff) |
749 | { | 749 | { |
750 | } | 750 | } |
751 | 751 | ||
@@ -925,7 +925,7 @@ static const struct tty_operations pc_ops = { | |||
925 | 925 | ||
926 | static const struct tty_port_operations epca_port_ops = { | 926 | static const struct tty_port_operations epca_port_ops = { |
927 | .carrier_raised = epca_carrier_raised, | 927 | .carrier_raised = epca_carrier_raised, |
928 | .raise_dtr_rts = epca_raise_dtr_rts, | 928 | .dtr_rts = epca_dtr_rts, |
929 | }; | 929 | }; |
930 | 930 | ||
931 | static int info_open(struct tty_struct *tty, struct file *filp) | 931 | static int info_open(struct tty_struct *tty, struct file *filp) |
@@ -1518,7 +1518,7 @@ static void doevent(int crd) | |||
1518 | if (event & MODEMCHG_IND) { | 1518 | if (event & MODEMCHG_IND) { |
1519 | /* A modem signal change has been indicated */ | 1519 | /* A modem signal change has been indicated */ |
1520 | ch->imodem = mstat; | 1520 | ch->imodem = mstat; |
1521 | if (test_bit(ASYNC_CHECK_CD, &ch->port.flags)) { | 1521 | if (test_bit(ASYNCB_CHECK_CD, &ch->port.flags)) { |
1522 | /* We are now receiving dcd */ | 1522 | /* We are now receiving dcd */ |
1523 | if (mstat & ch->dcd) | 1523 | if (mstat & ch->dcd) |
1524 | wake_up_interruptible(&ch->port.open_wait); | 1524 | wake_up_interruptible(&ch->port.open_wait); |
@@ -1765,9 +1765,9 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch) | |||
1765 | * that the driver will wait on carrier detect. | 1765 | * that the driver will wait on carrier detect. |
1766 | */ | 1766 | */ |
1767 | if (ts->c_cflag & CLOCAL) | 1767 | if (ts->c_cflag & CLOCAL) |
1768 | clear_bit(ASYNC_CHECK_CD, &ch->port.flags); | 1768 | clear_bit(ASYNCB_CHECK_CD, &ch->port.flags); |
1769 | else | 1769 | else |
1770 | set_bit(ASYNC_CHECK_CD, &ch->port.flags); | 1770 | set_bit(ASYNCB_CHECK_CD, &ch->port.flags); |
1771 | mval = ch->m_dtr | ch->m_rts; | 1771 | mval = ch->m_dtr | ch->m_rts; |
1772 | } /* End CBAUD not detected */ | 1772 | } /* End CBAUD not detected */ |
1773 | iflag = termios2digi_i(ch, ts->c_iflag); | 1773 | iflag = termios2digi_i(ch, ts->c_iflag); |
@@ -2114,8 +2114,8 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file, | |||
2114 | tty_wait_until_sent(tty, 0); | 2114 | tty_wait_until_sent(tty, 0); |
2115 | } else { | 2115 | } else { |
2116 | /* ldisc lock already held in ioctl */ | 2116 | /* ldisc lock already held in ioctl */ |
2117 | if (tty->ldisc.ops->flush_buffer) | 2117 | if (tty->ldisc->ops->flush_buffer) |
2118 | tty->ldisc.ops->flush_buffer(tty); | 2118 | tty->ldisc->ops->flush_buffer(tty); |
2119 | } | 2119 | } |
2120 | unlock_kernel(); | 2120 | unlock_kernel(); |
2121 | /* Fall Thru */ | 2121 | /* Fall Thru */ |
@@ -2244,7 +2244,8 @@ static void do_softint(struct work_struct *work) | |||
2244 | if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { | 2244 | if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { |
2245 | tty_hangup(tty); | 2245 | tty_hangup(tty); |
2246 | wake_up_interruptible(&ch->port.open_wait); | 2246 | wake_up_interruptible(&ch->port.open_wait); |
2247 | clear_bit(ASYNC_NORMAL_ACTIVE, &ch->port.flags); | 2247 | clear_bit(ASYNCB_NORMAL_ACTIVE, |
2248 | &ch->port.flags); | ||
2248 | } | 2249 | } |
2249 | } | 2250 | } |
2250 | tty_kref_put(tty); | 2251 | tty_kref_put(tty); |
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c index 340ba4f9dc54..4a9f3492b921 100644 --- a/drivers/char/hpet.c +++ b/drivers/char/hpet.c | |||
@@ -224,7 +224,7 @@ static void hpet_timer_set_irq(struct hpet_dev *devp) | |||
224 | break; | 224 | break; |
225 | } | 225 | } |
226 | 226 | ||
227 | gsi = acpi_register_gsi(irq, ACPI_LEVEL_SENSITIVE, | 227 | gsi = acpi_register_gsi(NULL, irq, ACPI_LEVEL_SENSITIVE, |
228 | ACPI_ACTIVE_LOW); | 228 | ACPI_ACTIVE_LOW); |
229 | if (gsi > 0) | 229 | if (gsi > 0) |
230 | break; | 230 | break; |
@@ -939,7 +939,7 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data) | |||
939 | irqp = &res->data.extended_irq; | 939 | irqp = &res->data.extended_irq; |
940 | 940 | ||
941 | for (i = 0; i < irqp->interrupt_count; i++) { | 941 | for (i = 0; i < irqp->interrupt_count; i++) { |
942 | irq = acpi_register_gsi(irqp->interrupts[i], | 942 | irq = acpi_register_gsi(NULL, irqp->interrupts[i], |
943 | irqp->triggering, irqp->polarity); | 943 | irqp->triggering, irqp->polarity); |
944 | if (irq < 0) | 944 | if (irq < 0) |
945 | return AE_ERROR; | 945 | return AE_ERROR; |
diff --git a/drivers/char/ip2/i2lib.c b/drivers/char/ip2/i2lib.c index 0061e18aff60..0d10b89218ed 100644 --- a/drivers/char/ip2/i2lib.c +++ b/drivers/char/ip2/i2lib.c | |||
@@ -868,11 +868,11 @@ i2Input(i2ChanStrPtr pCh) | |||
868 | amountToMove = count; | 868 | amountToMove = count; |
869 | } | 869 | } |
870 | // Move the first block | 870 | // Move the first block |
871 | pCh->pTTY->ldisc.ops->receive_buf( pCh->pTTY, | 871 | pCh->pTTY->ldisc->ops->receive_buf( pCh->pTTY, |
872 | &(pCh->Ibuf[stripIndex]), NULL, amountToMove ); | 872 | &(pCh->Ibuf[stripIndex]), NULL, amountToMove ); |
873 | // If we needed to wrap, do the second data move | 873 | // If we needed to wrap, do the second data move |
874 | if (count > amountToMove) { | 874 | if (count > amountToMove) { |
875 | pCh->pTTY->ldisc.ops->receive_buf( pCh->pTTY, | 875 | pCh->pTTY->ldisc->ops->receive_buf( pCh->pTTY, |
876 | pCh->Ibuf, NULL, count - amountToMove ); | 876 | pCh->Ibuf, NULL, count - amountToMove ); |
877 | } | 877 | } |
878 | // Bump and wrap the stripIndex all at once by the amount of data read. This | 878 | // Bump and wrap the stripIndex all at once by the amount of data read. This |
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c index afd9247cf082..517271c762e6 100644 --- a/drivers/char/ip2/ip2main.c +++ b/drivers/char/ip2/ip2main.c | |||
@@ -1315,8 +1315,8 @@ static inline void isig(int sig, struct tty_struct *tty, int flush) | |||
1315 | if (tty->pgrp) | 1315 | if (tty->pgrp) |
1316 | kill_pgrp(tty->pgrp, sig, 1); | 1316 | kill_pgrp(tty->pgrp, sig, 1); |
1317 | if (flush || !L_NOFLSH(tty)) { | 1317 | if (flush || !L_NOFLSH(tty)) { |
1318 | if ( tty->ldisc.ops->flush_buffer ) | 1318 | if ( tty->ldisc->ops->flush_buffer ) |
1319 | tty->ldisc.ops->flush_buffer(tty); | 1319 | tty->ldisc->ops->flush_buffer(tty); |
1320 | i2InputFlush( tty->driver_data ); | 1320 | i2InputFlush( tty->driver_data ); |
1321 | } | 1321 | } |
1322 | } | 1322 | } |
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c index a59eac584d16..4d745a89504f 100644 --- a/drivers/char/isicom.c +++ b/drivers/char/isicom.c | |||
@@ -329,7 +329,7 @@ static inline void drop_rts(struct isi_port *port) | |||
329 | 329 | ||
330 | /* card->lock MUST NOT be held */ | 330 | /* card->lock MUST NOT be held */ |
331 | 331 | ||
332 | static void isicom_raise_dtr_rts(struct tty_port *port) | 332 | static void isicom_dtr_rts(struct tty_port *port, int on) |
333 | { | 333 | { |
334 | struct isi_port *ip = container_of(port, struct isi_port, port); | 334 | struct isi_port *ip = container_of(port, struct isi_port, port); |
335 | struct isi_board *card = ip->card; | 335 | struct isi_board *card = ip->card; |
@@ -339,10 +339,17 @@ static void isicom_raise_dtr_rts(struct tty_port *port) | |||
339 | if (!lock_card(card)) | 339 | if (!lock_card(card)) |
340 | return; | 340 | return; |
341 | 341 | ||
342 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); | 342 | if (on) { |
343 | outw(0x0f04, base); | 343 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
344 | InterruptTheCard(base); | 344 | outw(0x0f04, base); |
345 | ip->status |= (ISI_DTR | ISI_RTS); | 345 | InterruptTheCard(base); |
346 | ip->status |= (ISI_DTR | ISI_RTS); | ||
347 | } else { | ||
348 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); | ||
349 | outw(0x0C04, base); | ||
350 | InterruptTheCard(base); | ||
351 | ip->status &= ~(ISI_DTR | ISI_RTS); | ||
352 | } | ||
346 | unlock_card(card); | 353 | unlock_card(card); |
347 | } | 354 | } |
348 | 355 | ||
@@ -1339,7 +1346,7 @@ static const struct tty_operations isicom_ops = { | |||
1339 | 1346 | ||
1340 | static const struct tty_port_operations isicom_port_ops = { | 1347 | static const struct tty_port_operations isicom_port_ops = { |
1341 | .carrier_raised = isicom_carrier_raised, | 1348 | .carrier_raised = isicom_carrier_raised, |
1342 | .raise_dtr_rts = isicom_raise_dtr_rts, | 1349 | .dtr_rts = isicom_dtr_rts, |
1343 | }; | 1350 | }; |
1344 | 1351 | ||
1345 | static int __devinit reset_card(struct pci_dev *pdev, | 1352 | static int __devinit reset_card(struct pci_dev *pdev, |
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c index fff19f7e29d2..e18800c400b1 100644 --- a/drivers/char/istallion.c +++ b/drivers/char/istallion.c | |||
@@ -1140,14 +1140,14 @@ static int stli_carrier_raised(struct tty_port *port) | |||
1140 | return (portp->sigs & TIOCM_CD) ? 1 : 0; | 1140 | return (portp->sigs & TIOCM_CD) ? 1 : 0; |
1141 | } | 1141 | } |
1142 | 1142 | ||
1143 | static void stli_raise_dtr_rts(struct tty_port *port) | 1143 | static void stli_dtr_rts(struct tty_port *port, int on) |
1144 | { | 1144 | { |
1145 | struct stliport *portp = container_of(port, struct stliport, port); | 1145 | struct stliport *portp = container_of(port, struct stliport, port); |
1146 | struct stlibrd *brdp = stli_brds[portp->brdnr]; | 1146 | struct stlibrd *brdp = stli_brds[portp->brdnr]; |
1147 | stli_mkasysigs(&portp->asig, 1, 1); | 1147 | stli_mkasysigs(&portp->asig, on, on); |
1148 | if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, | 1148 | if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, |
1149 | sizeof(asysigs_t), 0) < 0) | 1149 | sizeof(asysigs_t), 0) < 0) |
1150 | printk(KERN_WARNING "istallion: dtr raise failed.\n"); | 1150 | printk(KERN_WARNING "istallion: dtr set failed.\n"); |
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | 1153 | ||
@@ -4417,7 +4417,7 @@ static const struct tty_operations stli_ops = { | |||
4417 | 4417 | ||
4418 | static const struct tty_port_operations stli_port_ops = { | 4418 | static const struct tty_port_operations stli_port_ops = { |
4419 | .carrier_raised = stli_carrier_raised, | 4419 | .carrier_raised = stli_carrier_raised, |
4420 | .raise_dtr_rts = stli_raise_dtr_rts, | 4420 | .dtr_rts = stli_dtr_rts, |
4421 | }; | 4421 | }; |
4422 | 4422 | ||
4423 | /*****************************************************************************/ | 4423 | /*****************************************************************************/ |
diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 8f05c38c2f06..f96d0bef855e 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c | |||
@@ -694,6 +694,8 @@ static ssize_t read_zero(struct file * file, char __user * buf, | |||
694 | written += chunk - unwritten; | 694 | written += chunk - unwritten; |
695 | if (unwritten) | 695 | if (unwritten) |
696 | break; | 696 | break; |
697 | if (signal_pending(current)) | ||
698 | return written ? written : -ERESTARTSYS; | ||
697 | buf += chunk; | 699 | buf += chunk; |
698 | count -= chunk; | 700 | count -= chunk; |
699 | cond_resched(); | 701 | cond_resched(); |
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c index 4a4cab73d0be..65b6ff2442c6 100644 --- a/drivers/char/moxa.c +++ b/drivers/char/moxa.c | |||
@@ -1184,6 +1184,11 @@ static int moxa_open(struct tty_struct *tty, struct file *filp) | |||
1184 | return -ENODEV; | 1184 | return -ENODEV; |
1185 | } | 1185 | } |
1186 | 1186 | ||
1187 | if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) { | ||
1188 | mutex_unlock(&moxa_openlock); | ||
1189 | return -ENODEV; | ||
1190 | } | ||
1191 | |||
1187 | ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; | 1192 | ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; |
1188 | ch->port.count++; | 1193 | ch->port.count++; |
1189 | tty->driver_data = ch; | 1194 | tty->driver_data = ch; |
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index a420e8d437dd..9533f43a30bb 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c | |||
@@ -547,14 +547,18 @@ static int mxser_carrier_raised(struct tty_port *port) | |||
547 | return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0; | 547 | return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0; |
548 | } | 548 | } |
549 | 549 | ||
550 | static void mxser_raise_dtr_rts(struct tty_port *port) | 550 | static void mxser_dtr_rts(struct tty_port *port, int on) |
551 | { | 551 | { |
552 | struct mxser_port *mp = container_of(port, struct mxser_port, port); | 552 | struct mxser_port *mp = container_of(port, struct mxser_port, port); |
553 | unsigned long flags; | 553 | unsigned long flags; |
554 | 554 | ||
555 | spin_lock_irqsave(&mp->slock, flags); | 555 | spin_lock_irqsave(&mp->slock, flags); |
556 | outb(inb(mp->ioaddr + UART_MCR) | | 556 | if (on) |
557 | UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR); | 557 | outb(inb(mp->ioaddr + UART_MCR) | |
558 | UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR); | ||
559 | else | ||
560 | outb(inb(mp->ioaddr + UART_MCR)&~(UART_MCR_DTR | UART_MCR_RTS), | ||
561 | mp->ioaddr + UART_MCR); | ||
558 | spin_unlock_irqrestore(&mp->slock, flags); | 562 | spin_unlock_irqrestore(&mp->slock, flags); |
559 | } | 563 | } |
560 | 564 | ||
@@ -2356,7 +2360,7 @@ static const struct tty_operations mxser_ops = { | |||
2356 | 2360 | ||
2357 | struct tty_port_operations mxser_port_ops = { | 2361 | struct tty_port_operations mxser_port_ops = { |
2358 | .carrier_raised = mxser_carrier_raised, | 2362 | .carrier_raised = mxser_carrier_raised, |
2359 | .raise_dtr_rts = mxser_raise_dtr_rts, | 2363 | .dtr_rts = mxser_dtr_rts, |
2360 | }; | 2364 | }; |
2361 | 2365 | ||
2362 | /* | 2366 | /* |
@@ -2711,7 +2715,7 @@ static int __init mxser_module_init(void) | |||
2711 | continue; | 2715 | continue; |
2712 | 2716 | ||
2713 | brd = &mxser_boards[m]; | 2717 | brd = &mxser_boards[m]; |
2714 | retval = mxser_get_ISA_conf(!ioaddr[b], brd); | 2718 | retval = mxser_get_ISA_conf(ioaddr[b], brd); |
2715 | if (retval <= 0) { | 2719 | if (retval <= 0) { |
2716 | brd->info = NULL; | 2720 | brd->info = NULL; |
2717 | continue; | 2721 | continue; |
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c index bacb3e2872ae..461ece591a5b 100644 --- a/drivers/char/n_hdlc.c +++ b/drivers/char/n_hdlc.c | |||
@@ -342,8 +342,8 @@ static int n_hdlc_tty_open (struct tty_struct *tty) | |||
342 | #endif | 342 | #endif |
343 | 343 | ||
344 | /* Flush any pending characters in the driver and discipline. */ | 344 | /* Flush any pending characters in the driver and discipline. */ |
345 | if (tty->ldisc.ops->flush_buffer) | 345 | if (tty->ldisc->ops->flush_buffer) |
346 | tty->ldisc.ops->flush_buffer(tty); | 346 | tty->ldisc->ops->flush_buffer(tty); |
347 | 347 | ||
348 | tty_driver_flush_buffer(tty); | 348 | tty_driver_flush_buffer(tty); |
349 | 349 | ||
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c index f6f0e4ec2b51..94a5d5020abc 100644 --- a/drivers/char/n_tty.c +++ b/drivers/char/n_tty.c | |||
@@ -73,24 +73,6 @@ | |||
73 | #define ECHO_OP_SET_CANON_COL 0x81 | 73 | #define ECHO_OP_SET_CANON_COL 0x81 |
74 | #define ECHO_OP_ERASE_TAB 0x82 | 74 | #define ECHO_OP_ERASE_TAB 0x82 |
75 | 75 | ||
76 | static inline unsigned char *alloc_buf(void) | ||
77 | { | ||
78 | gfp_t prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; | ||
79 | |||
80 | if (PAGE_SIZE != N_TTY_BUF_SIZE) | ||
81 | return kmalloc(N_TTY_BUF_SIZE, prio); | ||
82 | else | ||
83 | return (unsigned char *)__get_free_page(prio); | ||
84 | } | ||
85 | |||
86 | static inline void free_buf(unsigned char *buf) | ||
87 | { | ||
88 | if (PAGE_SIZE != N_TTY_BUF_SIZE) | ||
89 | kfree(buf); | ||
90 | else | ||
91 | free_page((unsigned long) buf); | ||
92 | } | ||
93 | |||
94 | static inline int tty_put_user(struct tty_struct *tty, unsigned char x, | 76 | static inline int tty_put_user(struct tty_struct *tty, unsigned char x, |
95 | unsigned char __user *ptr) | 77 | unsigned char __user *ptr) |
96 | { | 78 | { |
@@ -1558,11 +1540,11 @@ static void n_tty_close(struct tty_struct *tty) | |||
1558 | { | 1540 | { |
1559 | n_tty_flush_buffer(tty); | 1541 | n_tty_flush_buffer(tty); |
1560 | if (tty->read_buf) { | 1542 | if (tty->read_buf) { |
1561 | free_buf(tty->read_buf); | 1543 | kfree(tty->read_buf); |
1562 | tty->read_buf = NULL; | 1544 | tty->read_buf = NULL; |
1563 | } | 1545 | } |
1564 | if (tty->echo_buf) { | 1546 | if (tty->echo_buf) { |
1565 | free_buf(tty->echo_buf); | 1547 | kfree(tty->echo_buf); |
1566 | tty->echo_buf = NULL; | 1548 | tty->echo_buf = NULL; |
1567 | } | 1549 | } |
1568 | } | 1550 | } |
@@ -1584,17 +1566,16 @@ static int n_tty_open(struct tty_struct *tty) | |||
1584 | 1566 | ||
1585 | /* These are ugly. Currently a malloc failure here can panic */ | 1567 | /* These are ugly. Currently a malloc failure here can panic */ |
1586 | if (!tty->read_buf) { | 1568 | if (!tty->read_buf) { |
1587 | tty->read_buf = alloc_buf(); | 1569 | tty->read_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL); |
1588 | if (!tty->read_buf) | 1570 | if (!tty->read_buf) |
1589 | return -ENOMEM; | 1571 | return -ENOMEM; |
1590 | } | 1572 | } |
1591 | if (!tty->echo_buf) { | 1573 | if (!tty->echo_buf) { |
1592 | tty->echo_buf = alloc_buf(); | 1574 | tty->echo_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL); |
1575 | |||
1593 | if (!tty->echo_buf) | 1576 | if (!tty->echo_buf) |
1594 | return -ENOMEM; | 1577 | return -ENOMEM; |
1595 | } | 1578 | } |
1596 | memset(tty->read_buf, 0, N_TTY_BUF_SIZE); | ||
1597 | memset(tty->echo_buf, 0, N_TTY_BUF_SIZE); | ||
1598 | reset_buffer_flags(tty); | 1579 | reset_buffer_flags(tty); |
1599 | tty->column = 0; | 1580 | tty->column = 0; |
1600 | n_tty_set_termios(tty, NULL); | 1581 | n_tty_set_termios(tty, NULL); |
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 19d79fc54461..77b364889224 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c | |||
@@ -383,7 +383,7 @@ static void async_mode(MGSLPC_INFO *info); | |||
383 | static void tx_timeout(unsigned long context); | 383 | static void tx_timeout(unsigned long context); |
384 | 384 | ||
385 | static int carrier_raised(struct tty_port *port); | 385 | static int carrier_raised(struct tty_port *port); |
386 | static void raise_dtr_rts(struct tty_port *port); | 386 | static void dtr_rts(struct tty_port *port, int onoff); |
387 | 387 | ||
388 | #if SYNCLINK_GENERIC_HDLC | 388 | #if SYNCLINK_GENERIC_HDLC |
389 | #define dev_to_port(D) (dev_to_hdlc(D)->priv) | 389 | #define dev_to_port(D) (dev_to_hdlc(D)->priv) |
@@ -513,7 +513,7 @@ static void ldisc_receive_buf(struct tty_struct *tty, | |||
513 | 513 | ||
514 | static const struct tty_port_operations mgslpc_port_ops = { | 514 | static const struct tty_port_operations mgslpc_port_ops = { |
515 | .carrier_raised = carrier_raised, | 515 | .carrier_raised = carrier_raised, |
516 | .raise_dtr_rts = raise_dtr_rts | 516 | .dtr_rts = dtr_rts |
517 | }; | 517 | }; |
518 | 518 | ||
519 | static int mgslpc_probe(struct pcmcia_device *link) | 519 | static int mgslpc_probe(struct pcmcia_device *link) |
@@ -2528,13 +2528,16 @@ static int carrier_raised(struct tty_port *port) | |||
2528 | return 0; | 2528 | return 0; |
2529 | } | 2529 | } |
2530 | 2530 | ||
2531 | static void raise_dtr_rts(struct tty_port *port) | 2531 | static void dtr_rts(struct tty_port *port, int onoff) |
2532 | { | 2532 | { |
2533 | MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port); | 2533 | MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port); |
2534 | unsigned long flags; | 2534 | unsigned long flags; |
2535 | 2535 | ||
2536 | spin_lock_irqsave(&info->lock,flags); | 2536 | spin_lock_irqsave(&info->lock,flags); |
2537 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | 2537 | if (onoff) |
2538 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | ||
2539 | else | ||
2540 | info->serial_signals &= ~SerialSignal_RTS + SerialSignal_DTR; | ||
2538 | set_signals(info); | 2541 | set_signals(info); |
2539 | spin_unlock_irqrestore(&info->lock,flags); | 2542 | spin_unlock_irqrestore(&info->lock,flags); |
2540 | } | 2543 | } |
diff --git a/drivers/char/pty.c b/drivers/char/pty.c index 31038a0052a2..5acd29e6e043 100644 --- a/drivers/char/pty.c +++ b/drivers/char/pty.c | |||
@@ -30,7 +30,6 @@ | |||
30 | 30 | ||
31 | #include <asm/system.h> | 31 | #include <asm/system.h> |
32 | 32 | ||
33 | /* These are global because they are accessed in tty_io.c */ | ||
34 | #ifdef CONFIG_UNIX98_PTYS | 33 | #ifdef CONFIG_UNIX98_PTYS |
35 | static struct tty_driver *ptm_driver; | 34 | static struct tty_driver *ptm_driver; |
36 | static struct tty_driver *pts_driver; | 35 | static struct tty_driver *pts_driver; |
@@ -111,7 +110,7 @@ static int pty_write(struct tty_struct *tty, const unsigned char *buf, | |||
111 | c = to->receive_room; | 110 | c = to->receive_room; |
112 | if (c > count) | 111 | if (c > count) |
113 | c = count; | 112 | c = count; |
114 | to->ldisc.ops->receive_buf(to, buf, NULL, c); | 113 | to->ldisc->ops->receive_buf(to, buf, NULL, c); |
115 | 114 | ||
116 | return c; | 115 | return c; |
117 | } | 116 | } |
@@ -149,11 +148,11 @@ static int pty_chars_in_buffer(struct tty_struct *tty) | |||
149 | int count; | 148 | int count; |
150 | 149 | ||
151 | /* We should get the line discipline lock for "tty->link" */ | 150 | /* We should get the line discipline lock for "tty->link" */ |
152 | if (!to || !to->ldisc.ops->chars_in_buffer) | 151 | if (!to || !to->ldisc->ops->chars_in_buffer) |
153 | return 0; | 152 | return 0; |
154 | 153 | ||
155 | /* The ldisc must report 0 if no characters available to be read */ | 154 | /* The ldisc must report 0 if no characters available to be read */ |
156 | count = to->ldisc.ops->chars_in_buffer(to); | 155 | count = to->ldisc->ops->chars_in_buffer(to); |
157 | 156 | ||
158 | if (tty->driver->subtype == PTY_TYPE_SLAVE) | 157 | if (tty->driver->subtype == PTY_TYPE_SLAVE) |
159 | return count; | 158 | return count; |
@@ -187,8 +186,8 @@ static void pty_flush_buffer(struct tty_struct *tty) | |||
187 | if (!to) | 186 | if (!to) |
188 | return; | 187 | return; |
189 | 188 | ||
190 | if (to->ldisc.ops->flush_buffer) | 189 | if (to->ldisc->ops->flush_buffer) |
191 | to->ldisc.ops->flush_buffer(to); | 190 | to->ldisc->ops->flush_buffer(to); |
192 | 191 | ||
193 | if (to->packet) { | 192 | if (to->packet) { |
194 | spin_lock_irqsave(&tty->ctrl_lock, flags); | 193 | spin_lock_irqsave(&tty->ctrl_lock, flags); |
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c index f59fc5cea067..63d5b628477a 100644 --- a/drivers/char/rocket.c +++ b/drivers/char/rocket.c | |||
@@ -872,11 +872,16 @@ static int carrier_raised(struct tty_port *port) | |||
872 | return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0; | 872 | return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0; |
873 | } | 873 | } |
874 | 874 | ||
875 | static void raise_dtr_rts(struct tty_port *port) | 875 | static void dtr_rts(struct tty_port *port, int on) |
876 | { | 876 | { |
877 | struct r_port *info = container_of(port, struct r_port, port); | 877 | struct r_port *info = container_of(port, struct r_port, port); |
878 | sSetDTR(&info->channel); | 878 | if (on) { |
879 | sSetRTS(&info->channel); | 879 | sSetDTR(&info->channel); |
880 | sSetRTS(&info->channel); | ||
881 | } else { | ||
882 | sClrDTR(&info->channel); | ||
883 | sClrRTS(&info->channel); | ||
884 | } | ||
880 | } | 885 | } |
881 | 886 | ||
882 | /* | 887 | /* |
@@ -934,7 +939,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) | |||
934 | /* | 939 | /* |
935 | * Info->count is now 1; so it's safe to sleep now. | 940 | * Info->count is now 1; so it's safe to sleep now. |
936 | */ | 941 | */ |
937 | if (!test_bit(ASYNC_INITIALIZED, &port->flags)) { | 942 | if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { |
938 | cp = &info->channel; | 943 | cp = &info->channel; |
939 | sSetRxTrigger(cp, TRIG_1); | 944 | sSetRxTrigger(cp, TRIG_1); |
940 | if (sGetChanStatus(cp) & CD_ACT) | 945 | if (sGetChanStatus(cp) & CD_ACT) |
@@ -958,7 +963,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) | |||
958 | sEnRxFIFO(cp); | 963 | sEnRxFIFO(cp); |
959 | sEnTransmit(cp); | 964 | sEnTransmit(cp); |
960 | 965 | ||
961 | set_bit(ASYNC_INITIALIZED, &info->port.flags); | 966 | set_bit(ASYNCB_INITIALIZED, &info->port.flags); |
962 | 967 | ||
963 | /* | 968 | /* |
964 | * Set up the tty->alt_speed kludge | 969 | * Set up the tty->alt_speed kludge |
@@ -1641,7 +1646,7 @@ static int rp_write(struct tty_struct *tty, | |||
1641 | /* Write remaining data into the port's xmit_buf */ | 1646 | /* Write remaining data into the port's xmit_buf */ |
1642 | while (1) { | 1647 | while (1) { |
1643 | /* Hung up ? */ | 1648 | /* Hung up ? */ |
1644 | if (!test_bit(ASYNC_NORMAL_ACTIVE, &info->port.flags)) | 1649 | if (!test_bit(ASYNCB_NORMAL_ACTIVE, &info->port.flags)) |
1645 | goto end; | 1650 | goto end; |
1646 | c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1); | 1651 | c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1); |
1647 | c = min(c, XMIT_BUF_SIZE - info->xmit_head); | 1652 | c = min(c, XMIT_BUF_SIZE - info->xmit_head); |
@@ -2250,7 +2255,7 @@ static const struct tty_operations rocket_ops = { | |||
2250 | 2255 | ||
2251 | static const struct tty_port_operations rocket_port_ops = { | 2256 | static const struct tty_port_operations rocket_port_ops = { |
2252 | .carrier_raised = carrier_raised, | 2257 | .carrier_raised = carrier_raised, |
2253 | .raise_dtr_rts = raise_dtr_rts, | 2258 | .dtr_rts = dtr_rts, |
2254 | }; | 2259 | }; |
2255 | 2260 | ||
2256 | /* | 2261 | /* |
diff --git a/drivers/char/selection.c b/drivers/char/selection.c index cb8ca5698963..f97b9e848064 100644 --- a/drivers/char/selection.c +++ b/drivers/char/selection.c | |||
@@ -327,7 +327,7 @@ int paste_selection(struct tty_struct *tty) | |||
327 | } | 327 | } |
328 | count = sel_buffer_lth - pasted; | 328 | count = sel_buffer_lth - pasted; |
329 | count = min(count, tty->receive_room); | 329 | count = min(count, tty->receive_room); |
330 | tty->ldisc.ops->receive_buf(tty, sel_buffer + pasted, | 330 | tty->ldisc->ops->receive_buf(tty, sel_buffer + pasted, |
331 | NULL, count); | 331 | NULL, count); |
332 | pasted += count; | 332 | pasted += count; |
333 | } | 333 | } |
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c index 2ad813a801dc..53e504f41b20 100644 --- a/drivers/char/stallion.c +++ b/drivers/char/stallion.c | |||
@@ -772,11 +772,11 @@ static int stl_carrier_raised(struct tty_port *port) | |||
772 | return (portp->sigs & TIOCM_CD) ? 1 : 0; | 772 | return (portp->sigs & TIOCM_CD) ? 1 : 0; |
773 | } | 773 | } |
774 | 774 | ||
775 | static void stl_raise_dtr_rts(struct tty_port *port) | 775 | static void stl_dtr_rts(struct tty_port *port, int on) |
776 | { | 776 | { |
777 | struct stlport *portp = container_of(port, struct stlport, port); | 777 | struct stlport *portp = container_of(port, struct stlport, port); |
778 | /* Takes brd_lock internally */ | 778 | /* Takes brd_lock internally */ |
779 | stl_setsignals(portp, 1, 1); | 779 | stl_setsignals(portp, on, on); |
780 | } | 780 | } |
781 | 781 | ||
782 | /*****************************************************************************/ | 782 | /*****************************************************************************/ |
@@ -2547,7 +2547,7 @@ static const struct tty_operations stl_ops = { | |||
2547 | 2547 | ||
2548 | static const struct tty_port_operations stl_port_ops = { | 2548 | static const struct tty_port_operations stl_port_ops = { |
2549 | .carrier_raised = stl_carrier_raised, | 2549 | .carrier_raised = stl_carrier_raised, |
2550 | .raise_dtr_rts = stl_raise_dtr_rts, | 2550 | .dtr_rts = stl_dtr_rts, |
2551 | }; | 2551 | }; |
2552 | 2552 | ||
2553 | /*****************************************************************************/ | 2553 | /*****************************************************************************/ |
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c index afd0b26ca056..afded3a2379c 100644 --- a/drivers/char/synclink.c +++ b/drivers/char/synclink.c | |||
@@ -3247,13 +3247,16 @@ static int carrier_raised(struct tty_port *port) | |||
3247 | return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; | 3247 | return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; |
3248 | } | 3248 | } |
3249 | 3249 | ||
3250 | static void raise_dtr_rts(struct tty_port *port) | 3250 | static void dtr_rts(struct tty_port *port, int on) |
3251 | { | 3251 | { |
3252 | struct mgsl_struct *info = container_of(port, struct mgsl_struct, port); | 3252 | struct mgsl_struct *info = container_of(port, struct mgsl_struct, port); |
3253 | unsigned long flags; | 3253 | unsigned long flags; |
3254 | 3254 | ||
3255 | spin_lock_irqsave(&info->irq_spinlock,flags); | 3255 | spin_lock_irqsave(&info->irq_spinlock,flags); |
3256 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | 3256 | if (on) |
3257 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | ||
3258 | else | ||
3259 | info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR); | ||
3257 | usc_set_serial_signals(info); | 3260 | usc_set_serial_signals(info); |
3258 | spin_unlock_irqrestore(&info->irq_spinlock,flags); | 3261 | spin_unlock_irqrestore(&info->irq_spinlock,flags); |
3259 | } | 3262 | } |
@@ -4258,7 +4261,7 @@ static void mgsl_add_device( struct mgsl_struct *info ) | |||
4258 | 4261 | ||
4259 | static const struct tty_port_operations mgsl_port_ops = { | 4262 | static const struct tty_port_operations mgsl_port_ops = { |
4260 | .carrier_raised = carrier_raised, | 4263 | .carrier_raised = carrier_raised, |
4261 | .raise_dtr_rts = raise_dtr_rts, | 4264 | .dtr_rts = dtr_rts, |
4262 | }; | 4265 | }; |
4263 | 4266 | ||
4264 | 4267 | ||
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c index 5e256494686a..1386625fc4ca 100644 --- a/drivers/char/synclink_gt.c +++ b/drivers/char/synclink_gt.c | |||
@@ -214,6 +214,7 @@ struct slgt_desc | |||
214 | #define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b)) | 214 | #define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b)) |
215 | #define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b)) | 215 | #define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b)) |
216 | #define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0)) | 216 | #define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0)) |
217 | #define set_desc_status(a, b) (a).status = cpu_to_le16((unsigned short)(b)) | ||
217 | #define desc_count(a) (le16_to_cpu((a).count)) | 218 | #define desc_count(a) (le16_to_cpu((a).count)) |
218 | #define desc_status(a) (le16_to_cpu((a).status)) | 219 | #define desc_status(a) (le16_to_cpu((a).status)) |
219 | #define desc_complete(a) (le16_to_cpu((a).status) & BIT15) | 220 | #define desc_complete(a) (le16_to_cpu((a).status) & BIT15) |
@@ -297,6 +298,7 @@ struct slgt_info { | |||
297 | u32 max_frame_size; /* as set by device config */ | 298 | u32 max_frame_size; /* as set by device config */ |
298 | 299 | ||
299 | unsigned int rbuf_fill_level; | 300 | unsigned int rbuf_fill_level; |
301 | unsigned int rx_pio; | ||
300 | unsigned int if_mode; | 302 | unsigned int if_mode; |
301 | unsigned int base_clock; | 303 | unsigned int base_clock; |
302 | 304 | ||
@@ -331,6 +333,8 @@ struct slgt_info { | |||
331 | struct slgt_desc *rbufs; | 333 | struct slgt_desc *rbufs; |
332 | unsigned int rbuf_current; | 334 | unsigned int rbuf_current; |
333 | unsigned int rbuf_index; | 335 | unsigned int rbuf_index; |
336 | unsigned int rbuf_fill_index; | ||
337 | unsigned short rbuf_fill_count; | ||
334 | 338 | ||
335 | unsigned int tbuf_count; | 339 | unsigned int tbuf_count; |
336 | struct slgt_desc *tbufs; | 340 | struct slgt_desc *tbufs; |
@@ -2110,6 +2114,40 @@ static void ri_change(struct slgt_info *info, unsigned short status) | |||
2110 | info->pending_bh |= BH_STATUS; | 2114 | info->pending_bh |= BH_STATUS; |
2111 | } | 2115 | } |
2112 | 2116 | ||
2117 | static void isr_rxdata(struct slgt_info *info) | ||
2118 | { | ||
2119 | unsigned int count = info->rbuf_fill_count; | ||
2120 | unsigned int i = info->rbuf_fill_index; | ||
2121 | unsigned short reg; | ||
2122 | |||
2123 | while (rd_reg16(info, SSR) & IRQ_RXDATA) { | ||
2124 | reg = rd_reg16(info, RDR); | ||
2125 | DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg)); | ||
2126 | if (desc_complete(info->rbufs[i])) { | ||
2127 | /* all buffers full */ | ||
2128 | rx_stop(info); | ||
2129 | info->rx_restart = 1; | ||
2130 | continue; | ||
2131 | } | ||
2132 | info->rbufs[i].buf[count++] = (unsigned char)reg; | ||
2133 | /* async mode saves status byte to buffer for each data byte */ | ||
2134 | if (info->params.mode == MGSL_MODE_ASYNC) | ||
2135 | info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8); | ||
2136 | if (count == info->rbuf_fill_level || (reg & BIT10)) { | ||
2137 | /* buffer full or end of frame */ | ||
2138 | set_desc_count(info->rbufs[i], count); | ||
2139 | set_desc_status(info->rbufs[i], BIT15 | (reg >> 8)); | ||
2140 | info->rbuf_fill_count = count = 0; | ||
2141 | if (++i == info->rbuf_count) | ||
2142 | i = 0; | ||
2143 | info->pending_bh |= BH_RECEIVE; | ||
2144 | } | ||
2145 | } | ||
2146 | |||
2147 | info->rbuf_fill_index = i; | ||
2148 | info->rbuf_fill_count = count; | ||
2149 | } | ||
2150 | |||
2113 | static void isr_serial(struct slgt_info *info) | 2151 | static void isr_serial(struct slgt_info *info) |
2114 | { | 2152 | { |
2115 | unsigned short status = rd_reg16(info, SSR); | 2153 | unsigned short status = rd_reg16(info, SSR); |
@@ -2125,6 +2163,8 @@ static void isr_serial(struct slgt_info *info) | |||
2125 | if (info->tx_count) | 2163 | if (info->tx_count) |
2126 | isr_txeom(info, status); | 2164 | isr_txeom(info, status); |
2127 | } | 2165 | } |
2166 | if (info->rx_pio && (status & IRQ_RXDATA)) | ||
2167 | isr_rxdata(info); | ||
2128 | if ((status & IRQ_RXBREAK) && (status & RXBREAK)) { | 2168 | if ((status & IRQ_RXBREAK) && (status & RXBREAK)) { |
2129 | info->icount.brk++; | 2169 | info->icount.brk++; |
2130 | /* process break detection if tty control allows */ | 2170 | /* process break detection if tty control allows */ |
@@ -2141,7 +2181,8 @@ static void isr_serial(struct slgt_info *info) | |||
2141 | } else { | 2181 | } else { |
2142 | if (status & (IRQ_TXIDLE + IRQ_TXUNDER)) | 2182 | if (status & (IRQ_TXIDLE + IRQ_TXUNDER)) |
2143 | isr_txeom(info, status); | 2183 | isr_txeom(info, status); |
2144 | 2184 | if (info->rx_pio && (status & IRQ_RXDATA)) | |
2185 | isr_rxdata(info); | ||
2145 | if (status & IRQ_RXIDLE) { | 2186 | if (status & IRQ_RXIDLE) { |
2146 | if (status & RXIDLE) | 2187 | if (status & RXIDLE) |
2147 | info->icount.rxidle++; | 2188 | info->icount.rxidle++; |
@@ -2642,6 +2683,10 @@ static int rx_enable(struct slgt_info *info, int enable) | |||
2642 | return -EINVAL; | 2683 | return -EINVAL; |
2643 | } | 2684 | } |
2644 | info->rbuf_fill_level = rbuf_fill_level; | 2685 | info->rbuf_fill_level = rbuf_fill_level; |
2686 | if (rbuf_fill_level < 128) | ||
2687 | info->rx_pio = 1; /* PIO mode */ | ||
2688 | else | ||
2689 | info->rx_pio = 0; /* DMA mode */ | ||
2645 | rx_stop(info); /* restart receiver to use new fill level */ | 2690 | rx_stop(info); /* restart receiver to use new fill level */ |
2646 | } | 2691 | } |
2647 | 2692 | ||
@@ -3099,13 +3144,16 @@ static int carrier_raised(struct tty_port *port) | |||
3099 | return (info->signals & SerialSignal_DCD) ? 1 : 0; | 3144 | return (info->signals & SerialSignal_DCD) ? 1 : 0; |
3100 | } | 3145 | } |
3101 | 3146 | ||
3102 | static void raise_dtr_rts(struct tty_port *port) | 3147 | static void dtr_rts(struct tty_port *port, int on) |
3103 | { | 3148 | { |
3104 | unsigned long flags; | 3149 | unsigned long flags; |
3105 | struct slgt_info *info = container_of(port, struct slgt_info, port); | 3150 | struct slgt_info *info = container_of(port, struct slgt_info, port); |
3106 | 3151 | ||
3107 | spin_lock_irqsave(&info->lock,flags); | 3152 | spin_lock_irqsave(&info->lock,flags); |
3108 | info->signals |= SerialSignal_RTS + SerialSignal_DTR; | 3153 | if (on) |
3154 | info->signals |= SerialSignal_RTS + SerialSignal_DTR; | ||
3155 | else | ||
3156 | info->signals &= ~(SerialSignal_RTS + SerialSignal_DTR); | ||
3109 | set_signals(info); | 3157 | set_signals(info); |
3110 | spin_unlock_irqrestore(&info->lock,flags); | 3158 | spin_unlock_irqrestore(&info->lock,flags); |
3111 | } | 3159 | } |
@@ -3419,7 +3467,7 @@ static void add_device(struct slgt_info *info) | |||
3419 | 3467 | ||
3420 | static const struct tty_port_operations slgt_port_ops = { | 3468 | static const struct tty_port_operations slgt_port_ops = { |
3421 | .carrier_raised = carrier_raised, | 3469 | .carrier_raised = carrier_raised, |
3422 | .raise_dtr_rts = raise_dtr_rts, | 3470 | .dtr_rts = dtr_rts, |
3423 | }; | 3471 | }; |
3424 | 3472 | ||
3425 | /* | 3473 | /* |
@@ -3841,15 +3889,27 @@ static void rx_start(struct slgt_info *info) | |||
3841 | rdma_reset(info); | 3889 | rdma_reset(info); |
3842 | reset_rbufs(info); | 3890 | reset_rbufs(info); |
3843 | 3891 | ||
3844 | /* set 1st descriptor address */ | 3892 | if (info->rx_pio) { |
3845 | wr_reg32(info, RDDAR, info->rbufs[0].pdesc); | 3893 | /* rx request when rx FIFO not empty */ |
3846 | 3894 | wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14)); | |
3847 | if (info->params.mode != MGSL_MODE_ASYNC) { | 3895 | slgt_irq_on(info, IRQ_RXDATA); |
3848 | /* enable rx DMA and DMA interrupt */ | 3896 | if (info->params.mode == MGSL_MODE_ASYNC) { |
3849 | wr_reg32(info, RDCSR, (BIT2 + BIT0)); | 3897 | /* enable saving of rx status */ |
3898 | wr_reg32(info, RDCSR, BIT6); | ||
3899 | } | ||
3850 | } else { | 3900 | } else { |
3851 | /* enable saving of rx status, rx DMA and DMA interrupt */ | 3901 | /* rx request when rx FIFO half full */ |
3852 | wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); | 3902 | wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14)); |
3903 | /* set 1st descriptor address */ | ||
3904 | wr_reg32(info, RDDAR, info->rbufs[0].pdesc); | ||
3905 | |||
3906 | if (info->params.mode != MGSL_MODE_ASYNC) { | ||
3907 | /* enable rx DMA and DMA interrupt */ | ||
3908 | wr_reg32(info, RDCSR, (BIT2 + BIT0)); | ||
3909 | } else { | ||
3910 | /* enable saving of rx status, rx DMA and DMA interrupt */ | ||
3911 | wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); | ||
3912 | } | ||
3853 | } | 3913 | } |
3854 | 3914 | ||
3855 | slgt_irq_on(info, IRQ_RXOVER); | 3915 | slgt_irq_on(info, IRQ_RXOVER); |
@@ -4467,6 +4527,8 @@ static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last | |||
4467 | static void reset_rbufs(struct slgt_info *info) | 4527 | static void reset_rbufs(struct slgt_info *info) |
4468 | { | 4528 | { |
4469 | free_rbufs(info, 0, info->rbuf_count - 1); | 4529 | free_rbufs(info, 0, info->rbuf_count - 1); |
4530 | info->rbuf_fill_index = 0; | ||
4531 | info->rbuf_fill_count = 0; | ||
4470 | } | 4532 | } |
4471 | 4533 | ||
4472 | /* | 4534 | /* |
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c index 26de60efe4b2..6f727e3c53ad 100644 --- a/drivers/char/synclinkmp.c +++ b/drivers/char/synclinkmp.c | |||
@@ -3277,13 +3277,16 @@ static int carrier_raised(struct tty_port *port) | |||
3277 | return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; | 3277 | return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; |
3278 | } | 3278 | } |
3279 | 3279 | ||
3280 | static void raise_dtr_rts(struct tty_port *port) | 3280 | static void dtr_rts(struct tty_port *port, int on) |
3281 | { | 3281 | { |
3282 | SLMP_INFO *info = container_of(port, SLMP_INFO, port); | 3282 | SLMP_INFO *info = container_of(port, SLMP_INFO, port); |
3283 | unsigned long flags; | 3283 | unsigned long flags; |
3284 | 3284 | ||
3285 | spin_lock_irqsave(&info->lock,flags); | 3285 | spin_lock_irqsave(&info->lock,flags); |
3286 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | 3286 | if (on) |
3287 | info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; | ||
3288 | else | ||
3289 | info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR); | ||
3287 | set_signals(info); | 3290 | set_signals(info); |
3288 | spin_unlock_irqrestore(&info->lock,flags); | 3291 | spin_unlock_irqrestore(&info->lock,flags); |
3289 | } | 3292 | } |
@@ -3746,7 +3749,7 @@ static void add_device(SLMP_INFO *info) | |||
3746 | 3749 | ||
3747 | static const struct tty_port_operations port_ops = { | 3750 | static const struct tty_port_operations port_ops = { |
3748 | .carrier_raised = carrier_raised, | 3751 | .carrier_raised = carrier_raised, |
3749 | .raise_dtr_rts = raise_dtr_rts, | 3752 | .dtr_rts = dtr_rts, |
3750 | }; | 3753 | }; |
3751 | 3754 | ||
3752 | /* Allocate and initialize a device instance structure | 3755 | /* Allocate and initialize a device instance structure |
diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c index 55ba6f142883..ac16fbec72d0 100644 --- a/drivers/char/tty_audit.c +++ b/drivers/char/tty_audit.c | |||
@@ -29,10 +29,7 @@ static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor, | |||
29 | buf = kmalloc(sizeof(*buf), GFP_KERNEL); | 29 | buf = kmalloc(sizeof(*buf), GFP_KERNEL); |
30 | if (!buf) | 30 | if (!buf) |
31 | goto err; | 31 | goto err; |
32 | if (PAGE_SIZE != N_TTY_BUF_SIZE) | 32 | buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL); |
33 | buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL); | ||
34 | else | ||
35 | buf->data = (unsigned char *)__get_free_page(GFP_KERNEL); | ||
36 | if (!buf->data) | 33 | if (!buf->data) |
37 | goto err_buf; | 34 | goto err_buf; |
38 | atomic_set(&buf->count, 1); | 35 | atomic_set(&buf->count, 1); |
@@ -52,10 +49,7 @@ err: | |||
52 | static void tty_audit_buf_free(struct tty_audit_buf *buf) | 49 | static void tty_audit_buf_free(struct tty_audit_buf *buf) |
53 | { | 50 | { |
54 | WARN_ON(buf->valid != 0); | 51 | WARN_ON(buf->valid != 0); |
55 | if (PAGE_SIZE != N_TTY_BUF_SIZE) | 52 | kfree(buf->data); |
56 | kfree(buf->data); | ||
57 | else | ||
58 | free_page((unsigned long)buf->data); | ||
59 | kfree(buf); | 53 | kfree(buf); |
60 | } | 54 | } |
61 | 55 | ||
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 66b99a2049e3..939e198d7670 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
@@ -295,7 +295,7 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line) | |||
295 | struct tty_driver *p, *res = NULL; | 295 | struct tty_driver *p, *res = NULL; |
296 | int tty_line = 0; | 296 | int tty_line = 0; |
297 | int len; | 297 | int len; |
298 | char *str; | 298 | char *str, *stp; |
299 | 299 | ||
300 | for (str = name; *str; str++) | 300 | for (str = name; *str; str++) |
301 | if ((*str >= '0' && *str <= '9') || *str == ',') | 301 | if ((*str >= '0' && *str <= '9') || *str == ',') |
@@ -311,13 +311,14 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line) | |||
311 | list_for_each_entry(p, &tty_drivers, tty_drivers) { | 311 | list_for_each_entry(p, &tty_drivers, tty_drivers) { |
312 | if (strncmp(name, p->name, len) != 0) | 312 | if (strncmp(name, p->name, len) != 0) |
313 | continue; | 313 | continue; |
314 | if (*str == ',') | 314 | stp = str; |
315 | str++; | 315 | if (*stp == ',') |
316 | if (*str == '\0') | 316 | stp++; |
317 | str = NULL; | 317 | if (*stp == '\0') |
318 | stp = NULL; | ||
318 | 319 | ||
319 | if (tty_line >= 0 && tty_line <= p->num && p->ops && | 320 | if (tty_line >= 0 && tty_line <= p->num && p->ops && |
320 | p->ops->poll_init && !p->ops->poll_init(p, tty_line, str)) { | 321 | p->ops->poll_init && !p->ops->poll_init(p, tty_line, stp)) { |
321 | res = tty_driver_kref_get(p); | 322 | res = tty_driver_kref_get(p); |
322 | *line = tty_line; | 323 | *line = tty_line; |
323 | break; | 324 | break; |
@@ -470,43 +471,6 @@ void tty_wakeup(struct tty_struct *tty) | |||
470 | EXPORT_SYMBOL_GPL(tty_wakeup); | 471 | EXPORT_SYMBOL_GPL(tty_wakeup); |
471 | 472 | ||
472 | /** | 473 | /** |
473 | * tty_ldisc_flush - flush line discipline queue | ||
474 | * @tty: tty | ||
475 | * | ||
476 | * Flush the line discipline queue (if any) for this tty. If there | ||
477 | * is no line discipline active this is a no-op. | ||
478 | */ | ||
479 | |||
480 | void tty_ldisc_flush(struct tty_struct *tty) | ||
481 | { | ||
482 | struct tty_ldisc *ld = tty_ldisc_ref(tty); | ||
483 | if (ld) { | ||
484 | if (ld->ops->flush_buffer) | ||
485 | ld->ops->flush_buffer(tty); | ||
486 | tty_ldisc_deref(ld); | ||
487 | } | ||
488 | tty_buffer_flush(tty); | ||
489 | } | ||
490 | |||
491 | EXPORT_SYMBOL_GPL(tty_ldisc_flush); | ||
492 | |||
493 | /** | ||
494 | * tty_reset_termios - reset terminal state | ||
495 | * @tty: tty to reset | ||
496 | * | ||
497 | * Restore a terminal to the driver default state | ||
498 | */ | ||
499 | |||
500 | static void tty_reset_termios(struct tty_struct *tty) | ||
501 | { | ||
502 | mutex_lock(&tty->termios_mutex); | ||
503 | *tty->termios = tty->driver->init_termios; | ||
504 | tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios); | ||
505 | tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios); | ||
506 | mutex_unlock(&tty->termios_mutex); | ||
507 | } | ||
508 | |||
509 | /** | ||
510 | * do_tty_hangup - actual handler for hangup events | 474 | * do_tty_hangup - actual handler for hangup events |
511 | * @work: tty device | 475 | * @work: tty device |
512 | * | 476 | * |
@@ -535,7 +499,6 @@ static void do_tty_hangup(struct work_struct *work) | |||
535 | struct file *cons_filp = NULL; | 499 | struct file *cons_filp = NULL; |
536 | struct file *filp, *f = NULL; | 500 | struct file *filp, *f = NULL; |
537 | struct task_struct *p; | 501 | struct task_struct *p; |
538 | struct tty_ldisc *ld; | ||
539 | int closecount = 0, n; | 502 | int closecount = 0, n; |
540 | unsigned long flags; | 503 | unsigned long flags; |
541 | int refs = 0; | 504 | int refs = 0; |
@@ -566,40 +529,8 @@ static void do_tty_hangup(struct work_struct *work) | |||
566 | filp->f_op = &hung_up_tty_fops; | 529 | filp->f_op = &hung_up_tty_fops; |
567 | } | 530 | } |
568 | file_list_unlock(); | 531 | file_list_unlock(); |
569 | /* | ||
570 | * FIXME! What are the locking issues here? This may me overdoing | ||
571 | * things... This question is especially important now that we've | ||
572 | * removed the irqlock. | ||
573 | */ | ||
574 | ld = tty_ldisc_ref(tty); | ||
575 | if (ld != NULL) { | ||
576 | /* We may have no line discipline at this point */ | ||
577 | if (ld->ops->flush_buffer) | ||
578 | ld->ops->flush_buffer(tty); | ||
579 | tty_driver_flush_buffer(tty); | ||
580 | if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && | ||
581 | ld->ops->write_wakeup) | ||
582 | ld->ops->write_wakeup(tty); | ||
583 | if (ld->ops->hangup) | ||
584 | ld->ops->hangup(tty); | ||
585 | } | ||
586 | /* | ||
587 | * FIXME: Once we trust the LDISC code better we can wait here for | ||
588 | * ldisc completion and fix the driver call race | ||
589 | */ | ||
590 | wake_up_interruptible_poll(&tty->write_wait, POLLOUT); | ||
591 | wake_up_interruptible_poll(&tty->read_wait, POLLIN); | ||
592 | /* | ||
593 | * Shutdown the current line discipline, and reset it to | ||
594 | * N_TTY. | ||
595 | */ | ||
596 | if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) | ||
597 | tty_reset_termios(tty); | ||
598 | /* Defer ldisc switch */ | ||
599 | /* tty_deferred_ldisc_switch(N_TTY); | ||
600 | 532 | ||
601 | This should get done automatically when the port closes and | 533 | tty_ldisc_hangup(tty); |
602 | tty_release is called */ | ||
603 | 534 | ||
604 | read_lock(&tasklist_lock); | 535 | read_lock(&tasklist_lock); |
605 | if (tty->session) { | 536 | if (tty->session) { |
@@ -628,12 +559,15 @@ static void do_tty_hangup(struct work_struct *work) | |||
628 | read_unlock(&tasklist_lock); | 559 | read_unlock(&tasklist_lock); |
629 | 560 | ||
630 | spin_lock_irqsave(&tty->ctrl_lock, flags); | 561 | spin_lock_irqsave(&tty->ctrl_lock, flags); |
631 | tty->flags = 0; | 562 | clear_bit(TTY_THROTTLED, &tty->flags); |
563 | clear_bit(TTY_PUSH, &tty->flags); | ||
564 | clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); | ||
632 | put_pid(tty->session); | 565 | put_pid(tty->session); |
633 | put_pid(tty->pgrp); | 566 | put_pid(tty->pgrp); |
634 | tty->session = NULL; | 567 | tty->session = NULL; |
635 | tty->pgrp = NULL; | 568 | tty->pgrp = NULL; |
636 | tty->ctrl_status = 0; | 569 | tty->ctrl_status = 0; |
570 | set_bit(TTY_HUPPED, &tty->flags); | ||
637 | spin_unlock_irqrestore(&tty->ctrl_lock, flags); | 571 | spin_unlock_irqrestore(&tty->ctrl_lock, flags); |
638 | 572 | ||
639 | /* Account for the p->signal references we killed */ | 573 | /* Account for the p->signal references we killed */ |
@@ -659,10 +593,7 @@ static void do_tty_hangup(struct work_struct *work) | |||
659 | * can't yet guarantee all that. | 593 | * can't yet guarantee all that. |
660 | */ | 594 | */ |
661 | set_bit(TTY_HUPPED, &tty->flags); | 595 | set_bit(TTY_HUPPED, &tty->flags); |
662 | if (ld) { | 596 | tty_ldisc_enable(tty); |
663 | tty_ldisc_enable(tty); | ||
664 | tty_ldisc_deref(ld); | ||
665 | } | ||
666 | unlock_kernel(); | 597 | unlock_kernel(); |
667 | if (f) | 598 | if (f) |
668 | fput(f); | 599 | fput(f); |
@@ -2480,6 +2411,24 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int | |||
2480 | return tty->ops->tiocmset(tty, file, set, clear); | 2411 | return tty->ops->tiocmset(tty, file, set, clear); |
2481 | } | 2412 | } |
2482 | 2413 | ||
2414 | struct tty_struct *tty_pair_get_tty(struct tty_struct *tty) | ||
2415 | { | ||
2416 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && | ||
2417 | tty->driver->subtype == PTY_TYPE_MASTER) | ||
2418 | tty = tty->link; | ||
2419 | return tty; | ||
2420 | } | ||
2421 | EXPORT_SYMBOL(tty_pair_get_tty); | ||
2422 | |||
2423 | struct tty_struct *tty_pair_get_pty(struct tty_struct *tty) | ||
2424 | { | ||
2425 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && | ||
2426 | tty->driver->subtype == PTY_TYPE_MASTER) | ||
2427 | return tty; | ||
2428 | return tty->link; | ||
2429 | } | ||
2430 | EXPORT_SYMBOL(tty_pair_get_pty); | ||
2431 | |||
2483 | /* | 2432 | /* |
2484 | * Split this up, as gcc can choke on it otherwise.. | 2433 | * Split this up, as gcc can choke on it otherwise.. |
2485 | */ | 2434 | */ |
@@ -2495,11 +2444,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
2495 | if (tty_paranoia_check(tty, inode, "tty_ioctl")) | 2444 | if (tty_paranoia_check(tty, inode, "tty_ioctl")) |
2496 | return -EINVAL; | 2445 | return -EINVAL; |
2497 | 2446 | ||
2498 | real_tty = tty; | 2447 | real_tty = tty_pair_get_tty(tty); |
2499 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && | ||
2500 | tty->driver->subtype == PTY_TYPE_MASTER) | ||
2501 | real_tty = tty->link; | ||
2502 | |||
2503 | 2448 | ||
2504 | /* | 2449 | /* |
2505 | * Factor out some common prep work | 2450 | * Factor out some common prep work |
@@ -2555,7 +2500,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
2555 | case TIOCGSID: | 2500 | case TIOCGSID: |
2556 | return tiocgsid(tty, real_tty, p); | 2501 | return tiocgsid(tty, real_tty, p); |
2557 | case TIOCGETD: | 2502 | case TIOCGETD: |
2558 | return put_user(tty->ldisc.ops->num, (int __user *)p); | 2503 | return put_user(tty->ldisc->ops->num, (int __user *)p); |
2559 | case TIOCSETD: | 2504 | case TIOCSETD: |
2560 | return tiocsetd(tty, p); | 2505 | return tiocsetd(tty, p); |
2561 | /* | 2506 | /* |
@@ -2770,6 +2715,7 @@ void initialize_tty_struct(struct tty_struct *tty, | |||
2770 | tty->buf.head = tty->buf.tail = NULL; | 2715 | tty->buf.head = tty->buf.tail = NULL; |
2771 | tty_buffer_init(tty); | 2716 | tty_buffer_init(tty); |
2772 | mutex_init(&tty->termios_mutex); | 2717 | mutex_init(&tty->termios_mutex); |
2718 | mutex_init(&tty->ldisc_mutex); | ||
2773 | init_waitqueue_head(&tty->write_wait); | 2719 | init_waitqueue_head(&tty->write_wait); |
2774 | init_waitqueue_head(&tty->read_wait); | 2720 | init_waitqueue_head(&tty->read_wait); |
2775 | INIT_WORK(&tty->hangup_work, do_tty_hangup); | 2721 | INIT_WORK(&tty->hangup_work, do_tty_hangup); |
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c index 6f4c7d0a53bf..8116bb1c8f80 100644 --- a/drivers/char/tty_ioctl.c +++ b/drivers/char/tty_ioctl.c | |||
@@ -97,14 +97,19 @@ EXPORT_SYMBOL(tty_driver_flush_buffer); | |||
97 | * @tty: terminal | 97 | * @tty: terminal |
98 | * | 98 | * |
99 | * Indicate that a tty should stop transmitting data down the stack. | 99 | * Indicate that a tty should stop transmitting data down the stack. |
100 | * Takes the termios mutex to protect against parallel throttle/unthrottle | ||
101 | * and also to ensure the driver can consistently reference its own | ||
102 | * termios data at this point when implementing software flow control. | ||
100 | */ | 103 | */ |
101 | 104 | ||
102 | void tty_throttle(struct tty_struct *tty) | 105 | void tty_throttle(struct tty_struct *tty) |
103 | { | 106 | { |
107 | mutex_lock(&tty->termios_mutex); | ||
104 | /* check TTY_THROTTLED first so it indicates our state */ | 108 | /* check TTY_THROTTLED first so it indicates our state */ |
105 | if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && | 109 | if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && |
106 | tty->ops->throttle) | 110 | tty->ops->throttle) |
107 | tty->ops->throttle(tty); | 111 | tty->ops->throttle(tty); |
112 | mutex_unlock(&tty->termios_mutex); | ||
108 | } | 113 | } |
109 | EXPORT_SYMBOL(tty_throttle); | 114 | EXPORT_SYMBOL(tty_throttle); |
110 | 115 | ||
@@ -113,13 +118,21 @@ EXPORT_SYMBOL(tty_throttle); | |||
113 | * @tty: terminal | 118 | * @tty: terminal |
114 | * | 119 | * |
115 | * Indicate that a tty may continue transmitting data down the stack. | 120 | * Indicate that a tty may continue transmitting data down the stack. |
121 | * Takes the termios mutex to protect against parallel throttle/unthrottle | ||
122 | * and also to ensure the driver can consistently reference its own | ||
123 | * termios data at this point when implementing software flow control. | ||
124 | * | ||
125 | * Drivers should however remember that the stack can issue a throttle, | ||
126 | * then change flow control method, then unthrottle. | ||
116 | */ | 127 | */ |
117 | 128 | ||
118 | void tty_unthrottle(struct tty_struct *tty) | 129 | void tty_unthrottle(struct tty_struct *tty) |
119 | { | 130 | { |
131 | mutex_lock(&tty->termios_mutex); | ||
120 | if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && | 132 | if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && |
121 | tty->ops->unthrottle) | 133 | tty->ops->unthrottle) |
122 | tty->ops->unthrottle(tty); | 134 | tty->ops->unthrottle(tty); |
135 | mutex_unlock(&tty->termios_mutex); | ||
123 | } | 136 | } |
124 | EXPORT_SYMBOL(tty_unthrottle); | 137 | EXPORT_SYMBOL(tty_unthrottle); |
125 | 138 | ||
@@ -613,9 +626,25 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt) | |||
613 | return 0; | 626 | return 0; |
614 | } | 627 | } |
615 | 628 | ||
629 | static void copy_termios(struct tty_struct *tty, struct ktermios *kterm) | ||
630 | { | ||
631 | mutex_lock(&tty->termios_mutex); | ||
632 | memcpy(kterm, tty->termios, sizeof(struct ktermios)); | ||
633 | mutex_unlock(&tty->termios_mutex); | ||
634 | } | ||
635 | |||
636 | static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm) | ||
637 | { | ||
638 | mutex_lock(&tty->termios_mutex); | ||
639 | memcpy(kterm, tty->termios_locked, sizeof(struct ktermios)); | ||
640 | mutex_unlock(&tty->termios_mutex); | ||
641 | } | ||
642 | |||
616 | static int get_termio(struct tty_struct *tty, struct termio __user *termio) | 643 | static int get_termio(struct tty_struct *tty, struct termio __user *termio) |
617 | { | 644 | { |
618 | if (kernel_termios_to_user_termio(termio, tty->termios)) | 645 | struct ktermios kterm; |
646 | copy_termios(tty, &kterm); | ||
647 | if (kernel_termios_to_user_termio(termio, &kterm)) | ||
619 | return -EFAULT; | 648 | return -EFAULT; |
620 | return 0; | 649 | return 0; |
621 | } | 650 | } |
@@ -917,6 +946,8 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
917 | struct tty_struct *real_tty; | 946 | struct tty_struct *real_tty; |
918 | void __user *p = (void __user *)arg; | 947 | void __user *p = (void __user *)arg; |
919 | int ret = 0; | 948 | int ret = 0; |
949 | struct ktermios kterm; | ||
950 | struct termiox ktermx; | ||
920 | 951 | ||
921 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && | 952 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && |
922 | tty->driver->subtype == PTY_TYPE_MASTER) | 953 | tty->driver->subtype == PTY_TYPE_MASTER) |
@@ -952,23 +983,20 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
952 | return set_termios(real_tty, p, TERMIOS_OLD); | 983 | return set_termios(real_tty, p, TERMIOS_OLD); |
953 | #ifndef TCGETS2 | 984 | #ifndef TCGETS2 |
954 | case TCGETS: | 985 | case TCGETS: |
955 | mutex_lock(&real_tty->termios_mutex); | 986 | copy_termios(real_tty, &kterm); |
956 | if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios)) | 987 | if (kernel_termios_to_user_termios((struct termios __user *)arg, &kterm)) |
957 | ret = -EFAULT; | 988 | ret = -EFAULT; |
958 | mutex_unlock(&real_tty->termios_mutex); | ||
959 | return ret; | 989 | return ret; |
960 | #else | 990 | #else |
961 | case TCGETS: | 991 | case TCGETS: |
962 | mutex_lock(&real_tty->termios_mutex); | 992 | copy_termios(real_tty, &kterm); |
963 | if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios)) | 993 | if (kernel_termios_to_user_termios_1((struct termios __user *)arg, &kterm)) |
964 | ret = -EFAULT; | 994 | ret = -EFAULT; |
965 | mutex_unlock(&real_tty->termios_mutex); | ||
966 | return ret; | 995 | return ret; |
967 | case TCGETS2: | 996 | case TCGETS2: |
968 | mutex_lock(&real_tty->termios_mutex); | 997 | copy_termios(real_tty, &kterm); |
969 | if (kernel_termios_to_user_termios((struct termios2 __user *)arg, real_tty->termios)) | 998 | if (kernel_termios_to_user_termios((struct termios2 __user *)arg, &kterm)) |
970 | ret = -EFAULT; | 999 | ret = -EFAULT; |
971 | mutex_unlock(&real_tty->termios_mutex); | ||
972 | return ret; | 1000 | return ret; |
973 | case TCSETSF2: | 1001 | case TCSETSF2: |
974 | return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT); | 1002 | return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT); |
@@ -987,34 +1015,36 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
987 | return set_termios(real_tty, p, TERMIOS_TERMIO); | 1015 | return set_termios(real_tty, p, TERMIOS_TERMIO); |
988 | #ifndef TCGETS2 | 1016 | #ifndef TCGETS2 |
989 | case TIOCGLCKTRMIOS: | 1017 | case TIOCGLCKTRMIOS: |
990 | mutex_lock(&real_tty->termios_mutex); | 1018 | copy_termios_locked(real_tty, &kterm); |
991 | if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios_locked)) | 1019 | if (kernel_termios_to_user_termios((struct termios __user *)arg, &kterm)) |
992 | ret = -EFAULT; | 1020 | ret = -EFAULT; |
993 | mutex_unlock(&real_tty->termios_mutex); | ||
994 | return ret; | 1021 | return ret; |
995 | case TIOCSLCKTRMIOS: | 1022 | case TIOCSLCKTRMIOS: |
996 | if (!capable(CAP_SYS_ADMIN)) | 1023 | if (!capable(CAP_SYS_ADMIN)) |
997 | return -EPERM; | 1024 | return -EPERM; |
998 | mutex_lock(&real_tty->termios_mutex); | 1025 | copy_termios_locked(real_tty, &kterm); |
999 | if (user_termios_to_kernel_termios(real_tty->termios_locked, | 1026 | if (user_termios_to_kernel_termios(&kterm, |
1000 | (struct termios __user *) arg)) | 1027 | (struct termios __user *) arg)) |
1001 | ret = -EFAULT; | 1028 | return -EFAULT; |
1029 | mutex_lock(&real_tty->termios_mutex); | ||
1030 | memcpy(real_tty->termios_locked, &kterm, sizeof(struct ktermios)); | ||
1002 | mutex_unlock(&real_tty->termios_mutex); | 1031 | mutex_unlock(&real_tty->termios_mutex); |
1003 | return ret; | 1032 | return 0; |
1004 | #else | 1033 | #else |
1005 | case TIOCGLCKTRMIOS: | 1034 | case TIOCGLCKTRMIOS: |
1006 | mutex_lock(&real_tty->termios_mutex); | 1035 | copy_termios_locked(real_tty, &kterm); |
1007 | if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios_locked)) | 1036 | if (kernel_termios_to_user_termios_1((struct termios __user *)arg, &kterm)) |
1008 | ret = -EFAULT; | 1037 | ret = -EFAULT; |
1009 | mutex_unlock(&real_tty->termios_mutex); | ||
1010 | return ret; | 1038 | return ret; |
1011 | case TIOCSLCKTRMIOS: | 1039 | case TIOCSLCKTRMIOS: |
1012 | if (!capable(CAP_SYS_ADMIN)) | 1040 | if (!capable(CAP_SYS_ADMIN)) |
1013 | ret = -EPERM; | 1041 | return -EPERM; |
1014 | mutex_lock(&real_tty->termios_mutex); | 1042 | copy_termios_locked(real_tty, &kterm); |
1015 | if (user_termios_to_kernel_termios_1(real_tty->termios_locked, | 1043 | if (user_termios_to_kernel_termios_1(&kterm, |
1016 | (struct termios __user *) arg)) | 1044 | (struct termios __user *) arg)) |
1017 | ret = -EFAULT; | 1045 | return -EFAULT; |
1046 | mutex_lock(&real_tty->termios_mutex); | ||
1047 | memcpy(real_tty->termios_locked, &kterm, sizeof(struct ktermios)); | ||
1018 | mutex_unlock(&real_tty->termios_mutex); | 1048 | mutex_unlock(&real_tty->termios_mutex); |
1019 | return ret; | 1049 | return ret; |
1020 | #endif | 1050 | #endif |
@@ -1023,9 +1053,10 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
1023 | if (real_tty->termiox == NULL) | 1053 | if (real_tty->termiox == NULL) |
1024 | return -EINVAL; | 1054 | return -EINVAL; |
1025 | mutex_lock(&real_tty->termios_mutex); | 1055 | mutex_lock(&real_tty->termios_mutex); |
1026 | if (copy_to_user(p, real_tty->termiox, sizeof(struct termiox))) | 1056 | memcpy(&ktermx, real_tty->termiox, sizeof(struct termiox)); |
1027 | ret = -EFAULT; | ||
1028 | mutex_unlock(&real_tty->termios_mutex); | 1057 | mutex_unlock(&real_tty->termios_mutex); |
1058 | if (copy_to_user(p, &ktermx, sizeof(struct termiox))) | ||
1059 | ret = -EFAULT; | ||
1029 | return ret; | 1060 | return ret; |
1030 | case TCSETX: | 1061 | case TCSETX: |
1031 | return set_termiox(real_tty, p, 0); | 1062 | return set_termiox(real_tty, p, 0); |
@@ -1035,10 +1066,9 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
1035 | return set_termiox(real_tty, p, TERMIOS_FLUSH); | 1066 | return set_termiox(real_tty, p, TERMIOS_FLUSH); |
1036 | #endif | 1067 | #endif |
1037 | case TIOCGSOFTCAR: | 1068 | case TIOCGSOFTCAR: |
1038 | mutex_lock(&real_tty->termios_mutex); | 1069 | copy_termios(real_tty, &kterm); |
1039 | ret = put_user(C_CLOCAL(real_tty) ? 1 : 0, | 1070 | ret = put_user((kterm.c_cflag & CLOCAL) ? 1 : 0, |
1040 | (int __user *)arg); | 1071 | (int __user *)arg); |
1041 | mutex_unlock(&real_tty->termios_mutex); | ||
1042 | return ret; | 1072 | return ret; |
1043 | case TIOCSSOFTCAR: | 1073 | case TIOCSSOFTCAR: |
1044 | if (get_user(arg, (unsigned int __user *) arg)) | 1074 | if (get_user(arg, (unsigned int __user *) arg)) |
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c index f78f5b0127a8..39c8f86dedd4 100644 --- a/drivers/char/tty_ldisc.c +++ b/drivers/char/tty_ldisc.c | |||
@@ -115,19 +115,22 @@ EXPORT_SYMBOL(tty_unregister_ldisc); | |||
115 | /** | 115 | /** |
116 | * tty_ldisc_try_get - try and reference an ldisc | 116 | * tty_ldisc_try_get - try and reference an ldisc |
117 | * @disc: ldisc number | 117 | * @disc: ldisc number |
118 | * @ld: tty ldisc structure to complete | ||
119 | * | 118 | * |
120 | * Attempt to open and lock a line discipline into place. Return | 119 | * Attempt to open and lock a line discipline into place. Return |
121 | * the line discipline refcounted and assigned in ld. On an error | 120 | * the line discipline refcounted or an error. |
122 | * report the error code back | ||
123 | */ | 121 | */ |
124 | 122 | ||
125 | static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld) | 123 | static struct tty_ldisc *tty_ldisc_try_get(int disc) |
126 | { | 124 | { |
127 | unsigned long flags; | 125 | unsigned long flags; |
126 | struct tty_ldisc *ld; | ||
128 | struct tty_ldisc_ops *ldops; | 127 | struct tty_ldisc_ops *ldops; |
129 | int err = -EINVAL; | 128 | int err = -EINVAL; |
130 | 129 | ||
130 | ld = kmalloc(sizeof(struct tty_ldisc), GFP_KERNEL); | ||
131 | if (ld == NULL) | ||
132 | return ERR_PTR(-ENOMEM); | ||
133 | |||
131 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 134 | spin_lock_irqsave(&tty_ldisc_lock, flags); |
132 | ld->ops = NULL; | 135 | ld->ops = NULL; |
133 | ldops = tty_ldiscs[disc]; | 136 | ldops = tty_ldiscs[disc]; |
@@ -140,17 +143,19 @@ static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld) | |||
140 | /* lock it */ | 143 | /* lock it */ |
141 | ldops->refcount++; | 144 | ldops->refcount++; |
142 | ld->ops = ldops; | 145 | ld->ops = ldops; |
146 | ld->refcount = 0; | ||
143 | err = 0; | 147 | err = 0; |
144 | } | 148 | } |
145 | } | 149 | } |
146 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 150 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
147 | return err; | 151 | if (err) |
152 | return ERR_PTR(err); | ||
153 | return ld; | ||
148 | } | 154 | } |
149 | 155 | ||
150 | /** | 156 | /** |
151 | * tty_ldisc_get - take a reference to an ldisc | 157 | * tty_ldisc_get - take a reference to an ldisc |
152 | * @disc: ldisc number | 158 | * @disc: ldisc number |
153 | * @ld: tty line discipline structure to use | ||
154 | * | 159 | * |
155 | * Takes a reference to a line discipline. Deals with refcounts and | 160 | * Takes a reference to a line discipline. Deals with refcounts and |
156 | * module locking counts. Returns NULL if the discipline is not available. | 161 | * module locking counts. Returns NULL if the discipline is not available. |
@@ -161,52 +166,54 @@ static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld) | |||
161 | * takes tty_ldisc_lock to guard against ldisc races | 166 | * takes tty_ldisc_lock to guard against ldisc races |
162 | */ | 167 | */ |
163 | 168 | ||
164 | static int tty_ldisc_get(int disc, struct tty_ldisc *ld) | 169 | static struct tty_ldisc *tty_ldisc_get(int disc) |
165 | { | 170 | { |
166 | int err; | 171 | struct tty_ldisc *ld; |
167 | 172 | ||
168 | if (disc < N_TTY || disc >= NR_LDISCS) | 173 | if (disc < N_TTY || disc >= NR_LDISCS) |
169 | return -EINVAL; | 174 | return ERR_PTR(-EINVAL); |
170 | err = tty_ldisc_try_get(disc, ld); | 175 | ld = tty_ldisc_try_get(disc); |
171 | if (err < 0) { | 176 | if (IS_ERR(ld)) { |
172 | request_module("tty-ldisc-%d", disc); | 177 | request_module("tty-ldisc-%d", disc); |
173 | err = tty_ldisc_try_get(disc, ld); | 178 | ld = tty_ldisc_try_get(disc); |
174 | } | 179 | } |
175 | return err; | 180 | return ld; |
176 | } | 181 | } |
177 | 182 | ||
178 | /** | 183 | /** |
179 | * tty_ldisc_put - drop ldisc reference | 184 | * tty_ldisc_put - drop ldisc reference |
180 | * @disc: ldisc number | 185 | * @ld: ldisc |
181 | * | 186 | * |
182 | * Drop a reference to a line discipline. Manage refcounts and | 187 | * Drop a reference to a line discipline. Manage refcounts and |
183 | * module usage counts | 188 | * module usage counts. Free the ldisc once the recount hits zero. |
184 | * | 189 | * |
185 | * Locking: | 190 | * Locking: |
186 | * takes tty_ldisc_lock to guard against ldisc races | 191 | * takes tty_ldisc_lock to guard against ldisc races |
187 | */ | 192 | */ |
188 | 193 | ||
189 | static void tty_ldisc_put(struct tty_ldisc_ops *ld) | 194 | static void tty_ldisc_put(struct tty_ldisc *ld) |
190 | { | 195 | { |
191 | unsigned long flags; | 196 | unsigned long flags; |
192 | int disc = ld->num; | 197 | int disc = ld->ops->num; |
198 | struct tty_ldisc_ops *ldo; | ||
193 | 199 | ||
194 | BUG_ON(disc < N_TTY || disc >= NR_LDISCS); | 200 | BUG_ON(disc < N_TTY || disc >= NR_LDISCS); |
195 | 201 | ||
196 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 202 | spin_lock_irqsave(&tty_ldisc_lock, flags); |
197 | ld = tty_ldiscs[disc]; | 203 | ldo = tty_ldiscs[disc]; |
198 | BUG_ON(ld->refcount == 0); | 204 | BUG_ON(ldo->refcount == 0); |
199 | ld->refcount--; | 205 | ldo->refcount--; |
200 | module_put(ld->owner); | 206 | module_put(ldo->owner); |
201 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 207 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
208 | kfree(ld); | ||
202 | } | 209 | } |
203 | 210 | ||
204 | static void * tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos) | 211 | static void *tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos) |
205 | { | 212 | { |
206 | return (*pos < NR_LDISCS) ? pos : NULL; | 213 | return (*pos < NR_LDISCS) ? pos : NULL; |
207 | } | 214 | } |
208 | 215 | ||
209 | static void * tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos) | 216 | static void *tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos) |
210 | { | 217 | { |
211 | (*pos)++; | 218 | (*pos)++; |
212 | return (*pos < NR_LDISCS) ? pos : NULL; | 219 | return (*pos < NR_LDISCS) ? pos : NULL; |
@@ -219,12 +226,13 @@ static void tty_ldiscs_seq_stop(struct seq_file *m, void *v) | |||
219 | static int tty_ldiscs_seq_show(struct seq_file *m, void *v) | 226 | static int tty_ldiscs_seq_show(struct seq_file *m, void *v) |
220 | { | 227 | { |
221 | int i = *(loff_t *)v; | 228 | int i = *(loff_t *)v; |
222 | struct tty_ldisc ld; | 229 | struct tty_ldisc *ld; |
223 | 230 | ||
224 | if (tty_ldisc_get(i, &ld) < 0) | 231 | ld = tty_ldisc_try_get(i); |
232 | if (IS_ERR(ld)) | ||
225 | return 0; | 233 | return 0; |
226 | seq_printf(m, "%-10s %2d\n", ld.ops->name ? ld.ops->name : "???", i); | 234 | seq_printf(m, "%-10s %2d\n", ld->ops->name ? ld->ops->name : "???", i); |
227 | tty_ldisc_put(ld.ops); | 235 | tty_ldisc_put(ld); |
228 | return 0; | 236 | return 0; |
229 | } | 237 | } |
230 | 238 | ||
@@ -263,8 +271,7 @@ const struct file_operations tty_ldiscs_proc_fops = { | |||
263 | 271 | ||
264 | static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) | 272 | static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) |
265 | { | 273 | { |
266 | ld->refcount = 0; | 274 | tty->ldisc = ld; |
267 | tty->ldisc = *ld; | ||
268 | } | 275 | } |
269 | 276 | ||
270 | /** | 277 | /** |
@@ -286,7 +293,7 @@ static int tty_ldisc_try(struct tty_struct *tty) | |||
286 | int ret = 0; | 293 | int ret = 0; |
287 | 294 | ||
288 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 295 | spin_lock_irqsave(&tty_ldisc_lock, flags); |
289 | ld = &tty->ldisc; | 296 | ld = tty->ldisc; |
290 | if (test_bit(TTY_LDISC, &tty->flags)) { | 297 | if (test_bit(TTY_LDISC, &tty->flags)) { |
291 | ld->refcount++; | 298 | ld->refcount++; |
292 | ret = 1; | 299 | ret = 1; |
@@ -315,10 +322,9 @@ struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) | |||
315 | { | 322 | { |
316 | /* wait_event is a macro */ | 323 | /* wait_event is a macro */ |
317 | wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); | 324 | wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); |
318 | WARN_ON(tty->ldisc.refcount == 0); | 325 | WARN_ON(tty->ldisc->refcount == 0); |
319 | return &tty->ldisc; | 326 | return tty->ldisc; |
320 | } | 327 | } |
321 | |||
322 | EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); | 328 | EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); |
323 | 329 | ||
324 | /** | 330 | /** |
@@ -335,10 +341,9 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); | |||
335 | struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) | 341 | struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) |
336 | { | 342 | { |
337 | if (tty_ldisc_try(tty)) | 343 | if (tty_ldisc_try(tty)) |
338 | return &tty->ldisc; | 344 | return tty->ldisc; |
339 | return NULL; | 345 | return NULL; |
340 | } | 346 | } |
341 | |||
342 | EXPORT_SYMBOL_GPL(tty_ldisc_ref); | 347 | EXPORT_SYMBOL_GPL(tty_ldisc_ref); |
343 | 348 | ||
344 | /** | 349 | /** |
@@ -366,7 +371,6 @@ void tty_ldisc_deref(struct tty_ldisc *ld) | |||
366 | wake_up(&tty_ldisc_wait); | 371 | wake_up(&tty_ldisc_wait); |
367 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 372 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
368 | } | 373 | } |
369 | |||
370 | EXPORT_SYMBOL_GPL(tty_ldisc_deref); | 374 | EXPORT_SYMBOL_GPL(tty_ldisc_deref); |
371 | 375 | ||
372 | /** | 376 | /** |
@@ -389,6 +393,26 @@ void tty_ldisc_enable(struct tty_struct *tty) | |||
389 | } | 393 | } |
390 | 394 | ||
391 | /** | 395 | /** |
396 | * tty_ldisc_flush - flush line discipline queue | ||
397 | * @tty: tty | ||
398 | * | ||
399 | * Flush the line discipline queue (if any) for this tty. If there | ||
400 | * is no line discipline active this is a no-op. | ||
401 | */ | ||
402 | |||
403 | void tty_ldisc_flush(struct tty_struct *tty) | ||
404 | { | ||
405 | struct tty_ldisc *ld = tty_ldisc_ref(tty); | ||
406 | if (ld) { | ||
407 | if (ld->ops->flush_buffer) | ||
408 | ld->ops->flush_buffer(tty); | ||
409 | tty_ldisc_deref(ld); | ||
410 | } | ||
411 | tty_buffer_flush(tty); | ||
412 | } | ||
413 | EXPORT_SYMBOL_GPL(tty_ldisc_flush); | ||
414 | |||
415 | /** | ||
392 | * tty_set_termios_ldisc - set ldisc field | 416 | * tty_set_termios_ldisc - set ldisc field |
393 | * @tty: tty structure | 417 | * @tty: tty structure |
394 | * @num: line discipline number | 418 | * @num: line discipline number |
@@ -407,6 +431,39 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num) | |||
407 | mutex_unlock(&tty->termios_mutex); | 431 | mutex_unlock(&tty->termios_mutex); |
408 | } | 432 | } |
409 | 433 | ||
434 | /** | ||
435 | * tty_ldisc_open - open a line discipline | ||
436 | * @tty: tty we are opening the ldisc on | ||
437 | * @ld: discipline to open | ||
438 | * | ||
439 | * A helper opening method. Also a convenient debugging and check | ||
440 | * point. | ||
441 | */ | ||
442 | |||
443 | static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld) | ||
444 | { | ||
445 | WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags)); | ||
446 | if (ld->ops->open) | ||
447 | return ld->ops->open(tty); | ||
448 | return 0; | ||
449 | } | ||
450 | |||
451 | /** | ||
452 | * tty_ldisc_close - close a line discipline | ||
453 | * @tty: tty we are opening the ldisc on | ||
454 | * @ld: discipline to close | ||
455 | * | ||
456 | * A helper close method. Also a convenient debugging and check | ||
457 | * point. | ||
458 | */ | ||
459 | |||
460 | static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld) | ||
461 | { | ||
462 | WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags)); | ||
463 | clear_bit(TTY_LDISC_OPEN, &tty->flags); | ||
464 | if (ld->ops->close) | ||
465 | ld->ops->close(tty); | ||
466 | } | ||
410 | 467 | ||
411 | /** | 468 | /** |
412 | * tty_ldisc_restore - helper for tty ldisc change | 469 | * tty_ldisc_restore - helper for tty ldisc change |
@@ -420,66 +477,136 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num) | |||
420 | static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old) | 477 | static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old) |
421 | { | 478 | { |
422 | char buf[64]; | 479 | char buf[64]; |
423 | struct tty_ldisc new_ldisc; | 480 | struct tty_ldisc *new_ldisc; |
481 | int r; | ||
424 | 482 | ||
425 | /* There is an outstanding reference here so this is safe */ | 483 | /* There is an outstanding reference here so this is safe */ |
426 | tty_ldisc_get(old->ops->num, old); | 484 | old = tty_ldisc_get(old->ops->num); |
485 | WARN_ON(IS_ERR(old)); | ||
427 | tty_ldisc_assign(tty, old); | 486 | tty_ldisc_assign(tty, old); |
428 | tty_set_termios_ldisc(tty, old->ops->num); | 487 | tty_set_termios_ldisc(tty, old->ops->num); |
429 | if (old->ops->open && (old->ops->open(tty) < 0)) { | 488 | if (tty_ldisc_open(tty, old) < 0) { |
430 | tty_ldisc_put(old->ops); | 489 | tty_ldisc_put(old); |
431 | /* This driver is always present */ | 490 | /* This driver is always present */ |
432 | if (tty_ldisc_get(N_TTY, &new_ldisc) < 0) | 491 | new_ldisc = tty_ldisc_get(N_TTY); |
492 | if (IS_ERR(new_ldisc)) | ||
433 | panic("n_tty: get"); | 493 | panic("n_tty: get"); |
434 | tty_ldisc_assign(tty, &new_ldisc); | 494 | tty_ldisc_assign(tty, new_ldisc); |
435 | tty_set_termios_ldisc(tty, N_TTY); | 495 | tty_set_termios_ldisc(tty, N_TTY); |
436 | if (new_ldisc.ops->open) { | 496 | r = tty_ldisc_open(tty, new_ldisc); |
437 | int r = new_ldisc.ops->open(tty); | 497 | if (r < 0) |
438 | if (r < 0) | 498 | panic("Couldn't open N_TTY ldisc for " |
439 | panic("Couldn't open N_TTY ldisc for " | 499 | "%s --- error %d.", |
440 | "%s --- error %d.", | 500 | tty_name(tty, buf), r); |
441 | tty_name(tty, buf), r); | ||
442 | } | ||
443 | } | 501 | } |
444 | } | 502 | } |
445 | 503 | ||
446 | /** | 504 | /** |
505 | * tty_ldisc_halt - shut down the line discipline | ||
506 | * @tty: tty device | ||
507 | * | ||
508 | * Shut down the line discipline and work queue for this tty device. | ||
509 | * The TTY_LDISC flag being cleared ensures no further references can | ||
510 | * be obtained while the delayed work queue halt ensures that no more | ||
511 | * data is fed to the ldisc. | ||
512 | * | ||
513 | * In order to wait for any existing references to complete see | ||
514 | * tty_ldisc_wait_idle. | ||
515 | */ | ||
516 | |||
517 | static int tty_ldisc_halt(struct tty_struct *tty) | ||
518 | { | ||
519 | clear_bit(TTY_LDISC, &tty->flags); | ||
520 | return cancel_delayed_work(&tty->buf.work); | ||
521 | } | ||
522 | |||
523 | /** | ||
524 | * tty_ldisc_wait_idle - wait for the ldisc to become idle | ||
525 | * @tty: tty to wait for | ||
526 | * | ||
527 | * Wait for the line discipline to become idle. The discipline must | ||
528 | * have been halted for this to guarantee it remains idle. | ||
529 | * | ||
530 | * tty_ldisc_lock protects the ref counts currently. | ||
531 | */ | ||
532 | |||
533 | static int tty_ldisc_wait_idle(struct tty_struct *tty) | ||
534 | { | ||
535 | unsigned long flags; | ||
536 | spin_lock_irqsave(&tty_ldisc_lock, flags); | ||
537 | while (tty->ldisc->refcount) { | ||
538 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
539 | if (wait_event_timeout(tty_ldisc_wait, | ||
540 | tty->ldisc->refcount == 0, 5 * HZ) == 0) | ||
541 | return -EBUSY; | ||
542 | spin_lock_irqsave(&tty_ldisc_lock, flags); | ||
543 | } | ||
544 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
545 | return 0; | ||
546 | } | ||
547 | |||
548 | /** | ||
447 | * tty_set_ldisc - set line discipline | 549 | * tty_set_ldisc - set line discipline |
448 | * @tty: the terminal to set | 550 | * @tty: the terminal to set |
449 | * @ldisc: the line discipline | 551 | * @ldisc: the line discipline |
450 | * | 552 | * |
451 | * Set the discipline of a tty line. Must be called from a process | 553 | * Set the discipline of a tty line. Must be called from a process |
452 | * context. | 554 | * context. The ldisc change logic has to protect itself against any |
555 | * overlapping ldisc change (including on the other end of pty pairs), | ||
556 | * the close of one side of a tty/pty pair, and eventually hangup. | ||
453 | * | 557 | * |
454 | * Locking: takes tty_ldisc_lock. | 558 | * Locking: takes tty_ldisc_lock, termios_mutex |
455 | * called functions take termios_mutex | ||
456 | */ | 559 | */ |
457 | 560 | ||
458 | int tty_set_ldisc(struct tty_struct *tty, int ldisc) | 561 | int tty_set_ldisc(struct tty_struct *tty, int ldisc) |
459 | { | 562 | { |
460 | int retval; | 563 | int retval; |
461 | struct tty_ldisc o_ldisc, new_ldisc; | 564 | struct tty_ldisc *o_ldisc, *new_ldisc; |
462 | int work; | 565 | int work, o_work = 0; |
463 | unsigned long flags; | ||
464 | struct tty_struct *o_tty; | 566 | struct tty_struct *o_tty; |
465 | 567 | ||
466 | restart: | 568 | new_ldisc = tty_ldisc_get(ldisc); |
467 | /* This is a bit ugly for now but means we can break the 'ldisc | 569 | if (IS_ERR(new_ldisc)) |
468 | is part of the tty struct' assumption later */ | 570 | return PTR_ERR(new_ldisc); |
469 | retval = tty_ldisc_get(ldisc, &new_ldisc); | 571 | |
470 | if (retval) | 572 | /* |
471 | return retval; | 573 | * We need to look at the tty locking here for pty/tty pairs |
574 | * when both sides try to change in parallel. | ||
575 | */ | ||
576 | |||
577 | o_tty = tty->link; /* o_tty is the pty side or NULL */ | ||
578 | |||
579 | |||
580 | /* | ||
581 | * Check the no-op case | ||
582 | */ | ||
583 | |||
584 | if (tty->ldisc->ops->num == ldisc) { | ||
585 | tty_ldisc_put(new_ldisc); | ||
586 | return 0; | ||
587 | } | ||
472 | 588 | ||
473 | /* | 589 | /* |
474 | * Problem: What do we do if this blocks ? | 590 | * Problem: What do we do if this blocks ? |
591 | * We could deadlock here | ||
475 | */ | 592 | */ |
476 | 593 | ||
477 | tty_wait_until_sent(tty, 0); | 594 | tty_wait_until_sent(tty, 0); |
478 | 595 | ||
479 | if (tty->ldisc.ops->num == ldisc) { | 596 | mutex_lock(&tty->ldisc_mutex); |
480 | tty_ldisc_put(new_ldisc.ops); | 597 | |
481 | return 0; | 598 | /* |
599 | * We could be midstream of another ldisc change which has | ||
600 | * dropped the lock during processing. If so we need to wait. | ||
601 | */ | ||
602 | |||
603 | while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { | ||
604 | mutex_unlock(&tty->ldisc_mutex); | ||
605 | wait_event(tty_ldisc_wait, | ||
606 | test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); | ||
607 | mutex_lock(&tty->ldisc_mutex); | ||
482 | } | 608 | } |
609 | set_bit(TTY_LDISC_CHANGING, &tty->flags); | ||
483 | 610 | ||
484 | /* | 611 | /* |
485 | * No more input please, we are switching. The new ldisc | 612 | * No more input please, we are switching. The new ldisc |
@@ -489,8 +616,6 @@ restart: | |||
489 | tty->receive_room = 0; | 616 | tty->receive_room = 0; |
490 | 617 | ||
491 | o_ldisc = tty->ldisc; | 618 | o_ldisc = tty->ldisc; |
492 | o_tty = tty->link; | ||
493 | |||
494 | /* | 619 | /* |
495 | * Make sure we don't change while someone holds a | 620 | * Make sure we don't change while someone holds a |
496 | * reference to the line discipline. The TTY_LDISC bit | 621 | * reference to the line discipline. The TTY_LDISC bit |
@@ -501,108 +626,181 @@ restart: | |||
501 | * with a userspace app continually trying to use the tty in | 626 | * with a userspace app continually trying to use the tty in |
502 | * parallel to the change and re-referencing the tty. | 627 | * parallel to the change and re-referencing the tty. |
503 | */ | 628 | */ |
504 | clear_bit(TTY_LDISC, &tty->flags); | ||
505 | if (o_tty) | ||
506 | clear_bit(TTY_LDISC, &o_tty->flags); | ||
507 | 629 | ||
508 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 630 | work = tty_ldisc_halt(tty); |
509 | if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) { | ||
510 | if (tty->ldisc.refcount) { | ||
511 | /* Free the new ldisc we grabbed. Must drop the lock | ||
512 | first. */ | ||
513 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
514 | tty_ldisc_put(o_ldisc.ops); | ||
515 | /* | ||
516 | * There are several reasons we may be busy, including | ||
517 | * random momentary I/O traffic. We must therefore | ||
518 | * retry. We could distinguish between blocking ops | ||
519 | * and retries if we made tty_ldisc_wait() smarter. | ||
520 | * That is up for discussion. | ||
521 | */ | ||
522 | if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0) | ||
523 | return -ERESTARTSYS; | ||
524 | goto restart; | ||
525 | } | ||
526 | if (o_tty && o_tty->ldisc.refcount) { | ||
527 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
528 | tty_ldisc_put(o_tty->ldisc.ops); | ||
529 | if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0) | ||
530 | return -ERESTARTSYS; | ||
531 | goto restart; | ||
532 | } | ||
533 | } | ||
534 | /* | ||
535 | * If the TTY_LDISC bit is set, then we are racing against | ||
536 | * another ldisc change | ||
537 | */ | ||
538 | if (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { | ||
539 | struct tty_ldisc *ld; | ||
540 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
541 | tty_ldisc_put(new_ldisc.ops); | ||
542 | ld = tty_ldisc_ref_wait(tty); | ||
543 | tty_ldisc_deref(ld); | ||
544 | goto restart; | ||
545 | } | ||
546 | /* | ||
547 | * This flag is used to avoid two parallel ldisc changes. Once | ||
548 | * open and close are fine grained locked this may work better | ||
549 | * as a mutex shared with the open/close/hup paths | ||
550 | */ | ||
551 | set_bit(TTY_LDISC_CHANGING, &tty->flags); | ||
552 | if (o_tty) | 631 | if (o_tty) |
553 | set_bit(TTY_LDISC_CHANGING, &o_tty->flags); | 632 | o_work = tty_ldisc_halt(o_tty); |
554 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
555 | |||
556 | /* | ||
557 | * From this point on we know nobody has an ldisc | ||
558 | * usage reference, nor can they obtain one until | ||
559 | * we say so later on. | ||
560 | */ | ||
561 | 633 | ||
562 | work = cancel_delayed_work(&tty->buf.work); | ||
563 | /* | 634 | /* |
564 | * Wait for ->hangup_work and ->buf.work handlers to terminate | 635 | * Wait for ->hangup_work and ->buf.work handlers to terminate. |
565 | * MUST NOT hold locks here. | 636 | * We must drop the mutex here in case a hangup is also in process. |
566 | */ | 637 | */ |
638 | |||
639 | mutex_unlock(&tty->ldisc_mutex); | ||
640 | |||
567 | flush_scheduled_work(); | 641 | flush_scheduled_work(); |
642 | |||
643 | /* Let any existing reference holders finish */ | ||
644 | retval = tty_ldisc_wait_idle(tty); | ||
645 | if (retval < 0) { | ||
646 | clear_bit(TTY_LDISC_CHANGING, &tty->flags); | ||
647 | tty_ldisc_put(new_ldisc); | ||
648 | return retval; | ||
649 | } | ||
650 | |||
651 | mutex_lock(&tty->ldisc_mutex); | ||
652 | if (test_bit(TTY_HUPPED, &tty->flags)) { | ||
653 | /* We were raced by the hangup method. It will have stomped | ||
654 | the ldisc data and closed the ldisc down */ | ||
655 | clear_bit(TTY_LDISC_CHANGING, &tty->flags); | ||
656 | mutex_unlock(&tty->ldisc_mutex); | ||
657 | tty_ldisc_put(new_ldisc); | ||
658 | return -EIO; | ||
659 | } | ||
660 | |||
568 | /* Shutdown the current discipline. */ | 661 | /* Shutdown the current discipline. */ |
569 | if (o_ldisc.ops->close) | 662 | tty_ldisc_close(tty, o_ldisc); |
570 | (o_ldisc.ops->close)(tty); | ||
571 | 663 | ||
572 | /* Now set up the new line discipline. */ | 664 | /* Now set up the new line discipline. */ |
573 | tty_ldisc_assign(tty, &new_ldisc); | 665 | tty_ldisc_assign(tty, new_ldisc); |
574 | tty_set_termios_ldisc(tty, ldisc); | 666 | tty_set_termios_ldisc(tty, ldisc); |
575 | if (new_ldisc.ops->open) | 667 | |
576 | retval = (new_ldisc.ops->open)(tty); | 668 | retval = tty_ldisc_open(tty, new_ldisc); |
577 | if (retval < 0) { | 669 | if (retval < 0) { |
578 | tty_ldisc_put(new_ldisc.ops); | 670 | /* Back to the old one or N_TTY if we can't */ |
579 | tty_ldisc_restore(tty, &o_ldisc); | 671 | tty_ldisc_put(new_ldisc); |
672 | tty_ldisc_restore(tty, o_ldisc); | ||
580 | } | 673 | } |
674 | |||
581 | /* At this point we hold a reference to the new ldisc and a | 675 | /* At this point we hold a reference to the new ldisc and a |
582 | a reference to the old ldisc. If we ended up flipping back | 676 | a reference to the old ldisc. If we ended up flipping back |
583 | to the existing ldisc we have two references to it */ | 677 | to the existing ldisc we have two references to it */ |
584 | 678 | ||
585 | if (tty->ldisc.ops->num != o_ldisc.ops->num && tty->ops->set_ldisc) | 679 | if (tty->ldisc->ops->num != o_ldisc->ops->num && tty->ops->set_ldisc) |
586 | tty->ops->set_ldisc(tty); | 680 | tty->ops->set_ldisc(tty); |
587 | 681 | ||
588 | tty_ldisc_put(o_ldisc.ops); | 682 | tty_ldisc_put(o_ldisc); |
589 | 683 | ||
590 | /* | 684 | /* |
591 | * Allow ldisc referencing to occur as soon as the driver | 685 | * Allow ldisc referencing to occur again |
592 | * ldisc callback completes. | ||
593 | */ | 686 | */ |
594 | 687 | ||
595 | tty_ldisc_enable(tty); | 688 | tty_ldisc_enable(tty); |
596 | if (o_tty) | 689 | if (o_tty) |
597 | tty_ldisc_enable(o_tty); | 690 | tty_ldisc_enable(o_tty); |
598 | 691 | ||
599 | /* Restart it in case no characters kick it off. Safe if | 692 | /* Restart the work queue in case no characters kick it off. Safe if |
600 | already running */ | 693 | already running */ |
601 | if (work) | 694 | if (work) |
602 | schedule_delayed_work(&tty->buf.work, 1); | 695 | schedule_delayed_work(&tty->buf.work, 1); |
696 | if (o_work) | ||
697 | schedule_delayed_work(&o_tty->buf.work, 1); | ||
698 | mutex_unlock(&tty->ldisc_mutex); | ||
603 | return retval; | 699 | return retval; |
604 | } | 700 | } |
605 | 701 | ||
702 | /** | ||
703 | * tty_reset_termios - reset terminal state | ||
704 | * @tty: tty to reset | ||
705 | * | ||
706 | * Restore a terminal to the driver default state. | ||
707 | */ | ||
708 | |||
709 | static void tty_reset_termios(struct tty_struct *tty) | ||
710 | { | ||
711 | mutex_lock(&tty->termios_mutex); | ||
712 | *tty->termios = tty->driver->init_termios; | ||
713 | tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios); | ||
714 | tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios); | ||
715 | mutex_unlock(&tty->termios_mutex); | ||
716 | } | ||
717 | |||
718 | |||
719 | /** | ||
720 | * tty_ldisc_reinit - reinitialise the tty ldisc | ||
721 | * @tty: tty to reinit | ||
722 | * | ||
723 | * Switch the tty back to N_TTY line discipline and leave the | ||
724 | * ldisc state closed | ||
725 | */ | ||
726 | |||
727 | static void tty_ldisc_reinit(struct tty_struct *tty) | ||
728 | { | ||
729 | struct tty_ldisc *ld; | ||
730 | |||
731 | tty_ldisc_close(tty, tty->ldisc); | ||
732 | tty_ldisc_put(tty->ldisc); | ||
733 | tty->ldisc = NULL; | ||
734 | /* | ||
735 | * Switch the line discipline back | ||
736 | */ | ||
737 | ld = tty_ldisc_get(N_TTY); | ||
738 | BUG_ON(IS_ERR(ld)); | ||
739 | tty_ldisc_assign(tty, ld); | ||
740 | tty_set_termios_ldisc(tty, N_TTY); | ||
741 | } | ||
742 | |||
743 | /** | ||
744 | * tty_ldisc_hangup - hangup ldisc reset | ||
745 | * @tty: tty being hung up | ||
746 | * | ||
747 | * Some tty devices reset their termios when they receive a hangup | ||
748 | * event. In that situation we must also switch back to N_TTY properly | ||
749 | * before we reset the termios data. | ||
750 | * | ||
751 | * Locking: We can take the ldisc mutex as the rest of the code is | ||
752 | * careful to allow for this. | ||
753 | * | ||
754 | * In the pty pair case this occurs in the close() path of the | ||
755 | * tty itself so we must be careful about locking rules. | ||
756 | */ | ||
757 | |||
758 | void tty_ldisc_hangup(struct tty_struct *tty) | ||
759 | { | ||
760 | struct tty_ldisc *ld; | ||
761 | |||
762 | /* | ||
763 | * FIXME! What are the locking issues here? This may me overdoing | ||
764 | * things... This question is especially important now that we've | ||
765 | * removed the irqlock. | ||
766 | */ | ||
767 | ld = tty_ldisc_ref(tty); | ||
768 | if (ld != NULL) { | ||
769 | /* We may have no line discipline at this point */ | ||
770 | if (ld->ops->flush_buffer) | ||
771 | ld->ops->flush_buffer(tty); | ||
772 | tty_driver_flush_buffer(tty); | ||
773 | if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && | ||
774 | ld->ops->write_wakeup) | ||
775 | ld->ops->write_wakeup(tty); | ||
776 | if (ld->ops->hangup) | ||
777 | ld->ops->hangup(tty); | ||
778 | tty_ldisc_deref(ld); | ||
779 | } | ||
780 | /* | ||
781 | * FIXME: Once we trust the LDISC code better we can wait here for | ||
782 | * ldisc completion and fix the driver call race | ||
783 | */ | ||
784 | wake_up_interruptible_poll(&tty->write_wait, POLLOUT); | ||
785 | wake_up_interruptible_poll(&tty->read_wait, POLLIN); | ||
786 | /* | ||
787 | * Shutdown the current line discipline, and reset it to | ||
788 | * N_TTY. | ||
789 | */ | ||
790 | if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) { | ||
791 | /* Avoid racing set_ldisc */ | ||
792 | mutex_lock(&tty->ldisc_mutex); | ||
793 | /* Switch back to N_TTY */ | ||
794 | tty_ldisc_reinit(tty); | ||
795 | /* At this point we have a closed ldisc and we want to | ||
796 | reopen it. We could defer this to the next open but | ||
797 | it means auditing a lot of other paths so this is a FIXME */ | ||
798 | WARN_ON(tty_ldisc_open(tty, tty->ldisc)); | ||
799 | tty_ldisc_enable(tty); | ||
800 | mutex_unlock(&tty->ldisc_mutex); | ||
801 | tty_reset_termios(tty); | ||
802 | } | ||
803 | } | ||
606 | 804 | ||
607 | /** | 805 | /** |
608 | * tty_ldisc_setup - open line discipline | 806 | * tty_ldisc_setup - open line discipline |
@@ -610,24 +808,23 @@ restart: | |||
610 | * @o_tty: pair tty for pty/tty pairs | 808 | * @o_tty: pair tty for pty/tty pairs |
611 | * | 809 | * |
612 | * Called during the initial open of a tty/pty pair in order to set up the | 810 | * Called during the initial open of a tty/pty pair in order to set up the |
613 | * line discplines and bind them to the tty. | 811 | * line disciplines and bind them to the tty. This has no locking issues |
812 | * as the device isn't yet active. | ||
614 | */ | 813 | */ |
615 | 814 | ||
616 | int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) | 815 | int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) |
617 | { | 816 | { |
618 | struct tty_ldisc *ld = &tty->ldisc; | 817 | struct tty_ldisc *ld = tty->ldisc; |
619 | int retval; | 818 | int retval; |
620 | 819 | ||
621 | if (ld->ops->open) { | 820 | retval = tty_ldisc_open(tty, ld); |
622 | retval = (ld->ops->open)(tty); | 821 | if (retval) |
623 | if (retval) | 822 | return retval; |
624 | return retval; | 823 | |
625 | } | 824 | if (o_tty) { |
626 | if (o_tty && o_tty->ldisc.ops->open) { | 825 | retval = tty_ldisc_open(o_tty, o_tty->ldisc); |
627 | retval = (o_tty->ldisc.ops->open)(o_tty); | ||
628 | if (retval) { | 826 | if (retval) { |
629 | if (ld->ops->close) | 827 | tty_ldisc_close(tty, ld); |
630 | (ld->ops->close)(tty); | ||
631 | return retval; | 828 | return retval; |
632 | } | 829 | } |
633 | tty_ldisc_enable(o_tty); | 830 | tty_ldisc_enable(o_tty); |
@@ -635,32 +832,25 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) | |||
635 | tty_ldisc_enable(tty); | 832 | tty_ldisc_enable(tty); |
636 | return 0; | 833 | return 0; |
637 | } | 834 | } |
638 | |||
639 | /** | 835 | /** |
640 | * tty_ldisc_release - release line discipline | 836 | * tty_ldisc_release - release line discipline |
641 | * @tty: tty being shut down | 837 | * @tty: tty being shut down |
642 | * @o_tty: pair tty for pty/tty pairs | 838 | * @o_tty: pair tty for pty/tty pairs |
643 | * | 839 | * |
644 | * Called during the final close of a tty/pty pair in order to shut down the | 840 | * Called during the final close of a tty/pty pair in order to shut down |
645 | * line discpline layer. | 841 | * the line discpline layer. On exit the ldisc assigned is N_TTY and the |
842 | * ldisc has not been opened. | ||
646 | */ | 843 | */ |
647 | 844 | ||
648 | void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) | 845 | void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) |
649 | { | 846 | { |
650 | unsigned long flags; | ||
651 | struct tty_ldisc ld; | ||
652 | /* | 847 | /* |
653 | * Prevent flush_to_ldisc() from rescheduling the work for later. Then | 848 | * Prevent flush_to_ldisc() from rescheduling the work for later. Then |
654 | * kill any delayed work. As this is the final close it does not | 849 | * kill any delayed work. As this is the final close it does not |
655 | * race with the set_ldisc code path. | 850 | * race with the set_ldisc code path. |
656 | */ | 851 | */ |
657 | clear_bit(TTY_LDISC, &tty->flags); | ||
658 | cancel_delayed_work(&tty->buf.work); | ||
659 | |||
660 | /* | ||
661 | * Wait for ->hangup_work and ->buf.work handlers to terminate | ||
662 | */ | ||
663 | 852 | ||
853 | tty_ldisc_halt(tty); | ||
664 | flush_scheduled_work(); | 854 | flush_scheduled_work(); |
665 | 855 | ||
666 | /* | 856 | /* |
@@ -668,38 +858,19 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) | |||
668 | * side waiters as the file is closing so user count on the file | 858 | * side waiters as the file is closing so user count on the file |
669 | * side is zero. | 859 | * side is zero. |
670 | */ | 860 | */ |
671 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 861 | |
672 | while (tty->ldisc.refcount) { | 862 | tty_ldisc_wait_idle(tty); |
673 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 863 | |
674 | wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0); | ||
675 | spin_lock_irqsave(&tty_ldisc_lock, flags); | ||
676 | } | ||
677 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | ||
678 | /* | 864 | /* |
679 | * Shutdown the current line discipline, and reset it to N_TTY. | 865 | * Shutdown the current line discipline, and reset it to N_TTY. |
680 | * | 866 | * |
681 | * FIXME: this MUST get fixed for the new reflocking | 867 | * FIXME: this MUST get fixed for the new reflocking |
682 | */ | 868 | */ |
683 | if (tty->ldisc.ops->close) | ||
684 | (tty->ldisc.ops->close)(tty); | ||
685 | tty_ldisc_put(tty->ldisc.ops); | ||
686 | 869 | ||
687 | /* | 870 | tty_ldisc_reinit(tty); |
688 | * Switch the line discipline back | 871 | /* This will need doing differently if we need to lock */ |
689 | */ | 872 | if (o_tty) |
690 | WARN_ON(tty_ldisc_get(N_TTY, &ld)); | 873 | tty_ldisc_release(o_tty, NULL); |
691 | tty_ldisc_assign(tty, &ld); | ||
692 | tty_set_termios_ldisc(tty, N_TTY); | ||
693 | if (o_tty) { | ||
694 | /* FIXME: could o_tty be in setldisc here ? */ | ||
695 | clear_bit(TTY_LDISC, &o_tty->flags); | ||
696 | if (o_tty->ldisc.ops->close) | ||
697 | (o_tty->ldisc.ops->close)(o_tty); | ||
698 | tty_ldisc_put(o_tty->ldisc.ops); | ||
699 | WARN_ON(tty_ldisc_get(N_TTY, &ld)); | ||
700 | tty_ldisc_assign(o_tty, &ld); | ||
701 | tty_set_termios_ldisc(o_tty, N_TTY); | ||
702 | } | ||
703 | } | 874 | } |
704 | 875 | ||
705 | /** | 876 | /** |
@@ -712,10 +883,10 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) | |||
712 | 883 | ||
713 | void tty_ldisc_init(struct tty_struct *tty) | 884 | void tty_ldisc_init(struct tty_struct *tty) |
714 | { | 885 | { |
715 | struct tty_ldisc ld; | 886 | struct tty_ldisc *ld = tty_ldisc_get(N_TTY); |
716 | if (tty_ldisc_get(N_TTY, &ld) < 0) | 887 | if (IS_ERR(ld)) |
717 | panic("n_tty: init_tty"); | 888 | panic("n_tty: init_tty"); |
718 | tty_ldisc_assign(tty, &ld); | 889 | tty_ldisc_assign(tty, ld); |
719 | } | 890 | } |
720 | 891 | ||
721 | void tty_ldisc_begin(void) | 892 | void tty_ldisc_begin(void) |
diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c index 9b8004c72686..62dadfc95e34 100644 --- a/drivers/char/tty_port.c +++ b/drivers/char/tty_port.c | |||
@@ -137,7 +137,7 @@ int tty_port_carrier_raised(struct tty_port *port) | |||
137 | EXPORT_SYMBOL(tty_port_carrier_raised); | 137 | EXPORT_SYMBOL(tty_port_carrier_raised); |
138 | 138 | ||
139 | /** | 139 | /** |
140 | * tty_port_raise_dtr_rts - Riase DTR/RTS | 140 | * tty_port_raise_dtr_rts - Raise DTR/RTS |
141 | * @port: tty port | 141 | * @port: tty port |
142 | * | 142 | * |
143 | * Wrapper for the DTR/RTS raise logic. For the moment this is used | 143 | * Wrapper for the DTR/RTS raise logic. For the moment this is used |
@@ -147,12 +147,28 @@ EXPORT_SYMBOL(tty_port_carrier_raised); | |||
147 | 147 | ||
148 | void tty_port_raise_dtr_rts(struct tty_port *port) | 148 | void tty_port_raise_dtr_rts(struct tty_port *port) |
149 | { | 149 | { |
150 | if (port->ops->raise_dtr_rts) | 150 | if (port->ops->dtr_rts) |
151 | port->ops->raise_dtr_rts(port); | 151 | port->ops->dtr_rts(port, 1); |
152 | } | 152 | } |
153 | EXPORT_SYMBOL(tty_port_raise_dtr_rts); | 153 | EXPORT_SYMBOL(tty_port_raise_dtr_rts); |
154 | 154 | ||
155 | /** | 155 | /** |
156 | * tty_port_lower_dtr_rts - Lower DTR/RTS | ||
157 | * @port: tty port | ||
158 | * | ||
159 | * Wrapper for the DTR/RTS raise logic. For the moment this is used | ||
160 | * to hide some internal details. This will eventually become entirely | ||
161 | * internal to the tty port. | ||
162 | */ | ||
163 | |||
164 | void tty_port_lower_dtr_rts(struct tty_port *port) | ||
165 | { | ||
166 | if (port->ops->dtr_rts) | ||
167 | port->ops->dtr_rts(port, 0); | ||
168 | } | ||
169 | EXPORT_SYMBOL(tty_port_lower_dtr_rts); | ||
170 | |||
171 | /** | ||
156 | * tty_port_block_til_ready - Waiting logic for tty open | 172 | * tty_port_block_til_ready - Waiting logic for tty open |
157 | * @port: the tty port being opened | 173 | * @port: the tty port being opened |
158 | * @tty: the tty device being bound | 174 | * @tty: the tty device being bound |
@@ -167,7 +183,7 @@ EXPORT_SYMBOL(tty_port_raise_dtr_rts); | |||
167 | * - port flags and counts | 183 | * - port flags and counts |
168 | * | 184 | * |
169 | * The passed tty_port must implement the carrier_raised method if it can | 185 | * The passed tty_port must implement the carrier_raised method if it can |
170 | * do carrier detect and the raise_dtr_rts method if it supports software | 186 | * do carrier detect and the dtr_rts method if it supports software |
171 | * management of these lines. Note that the dtr/rts raise is done each | 187 | * management of these lines. Note that the dtr/rts raise is done each |
172 | * iteration as a hangup may have previously dropped them while we wait. | 188 | * iteration as a hangup may have previously dropped them while we wait. |
173 | */ | 189 | */ |
@@ -182,7 +198,8 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
182 | 198 | ||
183 | /* block if port is in the process of being closed */ | 199 | /* block if port is in the process of being closed */ |
184 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { | 200 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { |
185 | interruptible_sleep_on(&port->close_wait); | 201 | wait_event_interruptible(port->close_wait, |
202 | !(port->flags & ASYNC_CLOSING)); | ||
186 | if (port->flags & ASYNC_HUP_NOTIFY) | 203 | if (port->flags & ASYNC_HUP_NOTIFY) |
187 | return -EAGAIN; | 204 | return -EAGAIN; |
188 | else | 205 | else |
@@ -205,7 +222,6 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
205 | before the next open may complete */ | 222 | before the next open may complete */ |
206 | 223 | ||
207 | retval = 0; | 224 | retval = 0; |
208 | add_wait_queue(&port->open_wait, &wait); | ||
209 | 225 | ||
210 | /* The port lock protects the port counts */ | 226 | /* The port lock protects the port counts */ |
211 | spin_lock_irqsave(&port->lock, flags); | 227 | spin_lock_irqsave(&port->lock, flags); |
@@ -219,7 +235,7 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
219 | if (tty->termios->c_cflag & CBAUD) | 235 | if (tty->termios->c_cflag & CBAUD) |
220 | tty_port_raise_dtr_rts(port); | 236 | tty_port_raise_dtr_rts(port); |
221 | 237 | ||
222 | set_current_state(TASK_INTERRUPTIBLE); | 238 | prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); |
223 | /* Check for a hangup or uninitialised port. Return accordingly */ | 239 | /* Check for a hangup or uninitialised port. Return accordingly */ |
224 | if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { | 240 | if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { |
225 | if (port->flags & ASYNC_HUP_NOTIFY) | 241 | if (port->flags & ASYNC_HUP_NOTIFY) |
@@ -240,8 +256,7 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
240 | } | 256 | } |
241 | schedule(); | 257 | schedule(); |
242 | } | 258 | } |
243 | set_current_state(TASK_RUNNING); | 259 | finish_wait(&port->open_wait, &wait); |
244 | remove_wait_queue(&port->open_wait, &wait); | ||
245 | 260 | ||
246 | /* Update counts. A parallel hangup will have set count to zero and | 261 | /* Update counts. A parallel hangup will have set count to zero and |
247 | we must not mess that up further */ | 262 | we must not mess that up further */ |
@@ -292,6 +307,17 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f | |||
292 | if (port->flags & ASYNC_INITIALIZED && | 307 | if (port->flags & ASYNC_INITIALIZED && |
293 | port->closing_wait != ASYNC_CLOSING_WAIT_NONE) | 308 | port->closing_wait != ASYNC_CLOSING_WAIT_NONE) |
294 | tty_wait_until_sent(tty, port->closing_wait); | 309 | tty_wait_until_sent(tty, port->closing_wait); |
310 | if (port->drain_delay) { | ||
311 | unsigned int bps = tty_get_baud_rate(tty); | ||
312 | long timeout; | ||
313 | |||
314 | if (bps > 1200) | ||
315 | timeout = max_t(long, (HZ * 10 * port->drain_delay) / bps, | ||
316 | HZ / 10); | ||
317 | else | ||
318 | timeout = 2 * HZ; | ||
319 | schedule_timeout_interruptible(timeout); | ||
320 | } | ||
295 | return 1; | 321 | return 1; |
296 | } | 322 | } |
297 | EXPORT_SYMBOL(tty_port_close_start); | 323 | EXPORT_SYMBOL(tty_port_close_start); |
@@ -302,6 +328,9 @@ void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) | |||
302 | 328 | ||
303 | tty_ldisc_flush(tty); | 329 | tty_ldisc_flush(tty); |
304 | 330 | ||
331 | if (tty->termios->c_cflag & HUPCL) | ||
332 | tty_port_lower_dtr_rts(port); | ||
333 | |||
305 | spin_lock_irqsave(&port->lock, flags); | 334 | spin_lock_irqsave(&port->lock, flags); |
306 | tty->closing = 0; | 335 | tty->closing = 0; |
307 | 336 | ||
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index 1efb2879a94f..eef216f7f61d 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile | |||
@@ -3,3 +3,5 @@ obj-$(CONFIG_X86_CYCLONE_TIMER) += cyclone.o | |||
3 | obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o | 3 | obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o |
4 | obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o | 4 | obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o |
5 | obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o | 5 | obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o |
6 | obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o | ||
7 | obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o | ||
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index 1c92c39a53aa..cf56a2af5fe1 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c | |||
@@ -18,7 +18,6 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/init.h> | 20 | #include <linux/init.h> |
21 | #include <linux/bootmem.h> | ||
22 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
23 | #include <linux/spinlock.h> | 22 | #include <linux/spinlock.h> |
24 | #include <linux/interrupt.h> | 23 | #include <linux/interrupt.h> |
@@ -29,7 +28,7 @@ | |||
29 | #include <linux/err.h> | 28 | #include <linux/err.h> |
30 | #include <linux/clocksource.h> | 29 | #include <linux/clocksource.h> |
31 | #include <linux/clockchips.h> | 30 | #include <linux/clockchips.h> |
32 | #include <linux/sh_cmt.h> | 31 | #include <linux/sh_timer.h> |
33 | 32 | ||
34 | struct sh_cmt_priv { | 33 | struct sh_cmt_priv { |
35 | void __iomem *mapbase; | 34 | void __iomem *mapbase; |
@@ -47,6 +46,7 @@ struct sh_cmt_priv { | |||
47 | unsigned long rate; | 46 | unsigned long rate; |
48 | spinlock_t lock; | 47 | spinlock_t lock; |
49 | struct clock_event_device ced; | 48 | struct clock_event_device ced; |
49 | struct clocksource cs; | ||
50 | unsigned long total_cycles; | 50 | unsigned long total_cycles; |
51 | }; | 51 | }; |
52 | 52 | ||
@@ -59,7 +59,7 @@ static DEFINE_SPINLOCK(sh_cmt_lock); | |||
59 | 59 | ||
60 | static inline unsigned long sh_cmt_read(struct sh_cmt_priv *p, int reg_nr) | 60 | static inline unsigned long sh_cmt_read(struct sh_cmt_priv *p, int reg_nr) |
61 | { | 61 | { |
62 | struct sh_cmt_config *cfg = p->pdev->dev.platform_data; | 62 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; |
63 | void __iomem *base = p->mapbase; | 63 | void __iomem *base = p->mapbase; |
64 | unsigned long offs; | 64 | unsigned long offs; |
65 | 65 | ||
@@ -83,7 +83,7 @@ static inline unsigned long sh_cmt_read(struct sh_cmt_priv *p, int reg_nr) | |||
83 | static inline void sh_cmt_write(struct sh_cmt_priv *p, int reg_nr, | 83 | static inline void sh_cmt_write(struct sh_cmt_priv *p, int reg_nr, |
84 | unsigned long value) | 84 | unsigned long value) |
85 | { | 85 | { |
86 | struct sh_cmt_config *cfg = p->pdev->dev.platform_data; | 86 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; |
87 | void __iomem *base = p->mapbase; | 87 | void __iomem *base = p->mapbase; |
88 | unsigned long offs; | 88 | unsigned long offs; |
89 | 89 | ||
@@ -110,23 +110,28 @@ static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p, | |||
110 | int *has_wrapped) | 110 | int *has_wrapped) |
111 | { | 111 | { |
112 | unsigned long v1, v2, v3; | 112 | unsigned long v1, v2, v3; |
113 | int o1, o2; | ||
114 | |||
115 | o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit; | ||
113 | 116 | ||
114 | /* Make sure the timer value is stable. Stolen from acpi_pm.c */ | 117 | /* Make sure the timer value is stable. Stolen from acpi_pm.c */ |
115 | do { | 118 | do { |
119 | o2 = o1; | ||
116 | v1 = sh_cmt_read(p, CMCNT); | 120 | v1 = sh_cmt_read(p, CMCNT); |
117 | v2 = sh_cmt_read(p, CMCNT); | 121 | v2 = sh_cmt_read(p, CMCNT); |
118 | v3 = sh_cmt_read(p, CMCNT); | 122 | v3 = sh_cmt_read(p, CMCNT); |
119 | } while (unlikely((v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1) | 123 | o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit; |
120 | || (v3 > v1 && v3 < v2))); | 124 | } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3) |
125 | || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2))); | ||
121 | 126 | ||
122 | *has_wrapped = sh_cmt_read(p, CMCSR) & p->overflow_bit; | 127 | *has_wrapped = o1; |
123 | return v2; | 128 | return v2; |
124 | } | 129 | } |
125 | 130 | ||
126 | 131 | ||
127 | static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start) | 132 | static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start) |
128 | { | 133 | { |
129 | struct sh_cmt_config *cfg = p->pdev->dev.platform_data; | 134 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; |
130 | unsigned long flags, value; | 135 | unsigned long flags, value; |
131 | 136 | ||
132 | /* start stop register shared by multiple timer channels */ | 137 | /* start stop register shared by multiple timer channels */ |
@@ -144,7 +149,7 @@ static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start) | |||
144 | 149 | ||
145 | static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate) | 150 | static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate) |
146 | { | 151 | { |
147 | struct sh_cmt_config *cfg = p->pdev->dev.platform_data; | 152 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; |
148 | int ret; | 153 | int ret; |
149 | 154 | ||
150 | /* enable clock */ | 155 | /* enable clock */ |
@@ -153,16 +158,18 @@ static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate) | |||
153 | pr_err("sh_cmt: cannot enable clock \"%s\"\n", cfg->clk); | 158 | pr_err("sh_cmt: cannot enable clock \"%s\"\n", cfg->clk); |
154 | return ret; | 159 | return ret; |
155 | } | 160 | } |
156 | *rate = clk_get_rate(p->clk) / 8; | ||
157 | 161 | ||
158 | /* make sure channel is disabled */ | 162 | /* make sure channel is disabled */ |
159 | sh_cmt_start_stop_ch(p, 0); | 163 | sh_cmt_start_stop_ch(p, 0); |
160 | 164 | ||
161 | /* configure channel, periodic mode and maximum timeout */ | 165 | /* configure channel, periodic mode and maximum timeout */ |
162 | if (p->width == 16) | 166 | if (p->width == 16) { |
163 | sh_cmt_write(p, CMCSR, 0); | 167 | *rate = clk_get_rate(p->clk) / 512; |
164 | else | 168 | sh_cmt_write(p, CMCSR, 0x43); |
169 | } else { | ||
170 | *rate = clk_get_rate(p->clk) / 8; | ||
165 | sh_cmt_write(p, CMCSR, 0x01a4); | 171 | sh_cmt_write(p, CMCSR, 0x01a4); |
172 | } | ||
166 | 173 | ||
167 | sh_cmt_write(p, CMCOR, 0xffffffff); | 174 | sh_cmt_write(p, CMCOR, 0xffffffff); |
168 | sh_cmt_write(p, CMCNT, 0); | 175 | sh_cmt_write(p, CMCNT, 0); |
@@ -376,6 +383,68 @@ static void sh_cmt_stop(struct sh_cmt_priv *p, unsigned long flag) | |||
376 | spin_unlock_irqrestore(&p->lock, flags); | 383 | spin_unlock_irqrestore(&p->lock, flags); |
377 | } | 384 | } |
378 | 385 | ||
386 | static struct sh_cmt_priv *cs_to_sh_cmt(struct clocksource *cs) | ||
387 | { | ||
388 | return container_of(cs, struct sh_cmt_priv, cs); | ||
389 | } | ||
390 | |||
391 | static cycle_t sh_cmt_clocksource_read(struct clocksource *cs) | ||
392 | { | ||
393 | struct sh_cmt_priv *p = cs_to_sh_cmt(cs); | ||
394 | unsigned long flags, raw; | ||
395 | unsigned long value; | ||
396 | int has_wrapped; | ||
397 | |||
398 | spin_lock_irqsave(&p->lock, flags); | ||
399 | value = p->total_cycles; | ||
400 | raw = sh_cmt_get_counter(p, &has_wrapped); | ||
401 | |||
402 | if (unlikely(has_wrapped)) | ||
403 | raw += p->match_value; | ||
404 | spin_unlock_irqrestore(&p->lock, flags); | ||
405 | |||
406 | return value + raw; | ||
407 | } | ||
408 | |||
409 | static int sh_cmt_clocksource_enable(struct clocksource *cs) | ||
410 | { | ||
411 | struct sh_cmt_priv *p = cs_to_sh_cmt(cs); | ||
412 | int ret; | ||
413 | |||
414 | p->total_cycles = 0; | ||
415 | |||
416 | ret = sh_cmt_start(p, FLAG_CLOCKSOURCE); | ||
417 | if (ret) | ||
418 | return ret; | ||
419 | |||
420 | /* TODO: calculate good shift from rate and counter bit width */ | ||
421 | cs->shift = 0; | ||
422 | cs->mult = clocksource_hz2mult(p->rate, cs->shift); | ||
423 | return 0; | ||
424 | } | ||
425 | |||
426 | static void sh_cmt_clocksource_disable(struct clocksource *cs) | ||
427 | { | ||
428 | sh_cmt_stop(cs_to_sh_cmt(cs), FLAG_CLOCKSOURCE); | ||
429 | } | ||
430 | |||
431 | static int sh_cmt_register_clocksource(struct sh_cmt_priv *p, | ||
432 | char *name, unsigned long rating) | ||
433 | { | ||
434 | struct clocksource *cs = &p->cs; | ||
435 | |||
436 | cs->name = name; | ||
437 | cs->rating = rating; | ||
438 | cs->read = sh_cmt_clocksource_read; | ||
439 | cs->enable = sh_cmt_clocksource_enable; | ||
440 | cs->disable = sh_cmt_clocksource_disable; | ||
441 | cs->mask = CLOCKSOURCE_MASK(sizeof(unsigned long) * 8); | ||
442 | cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; | ||
443 | pr_info("sh_cmt: %s used as clock source\n", cs->name); | ||
444 | clocksource_register(cs); | ||
445 | return 0; | ||
446 | } | ||
447 | |||
379 | static struct sh_cmt_priv *ced_to_sh_cmt(struct clock_event_device *ced) | 448 | static struct sh_cmt_priv *ced_to_sh_cmt(struct clock_event_device *ced) |
380 | { | 449 | { |
381 | return container_of(ced, struct sh_cmt_priv, ced); | 450 | return container_of(ced, struct sh_cmt_priv, ced); |
@@ -468,9 +537,9 @@ static void sh_cmt_register_clockevent(struct sh_cmt_priv *p, | |||
468 | clockevents_register_device(ced); | 537 | clockevents_register_device(ced); |
469 | } | 538 | } |
470 | 539 | ||
471 | int sh_cmt_register(struct sh_cmt_priv *p, char *name, | 540 | static int sh_cmt_register(struct sh_cmt_priv *p, char *name, |
472 | unsigned long clockevent_rating, | 541 | unsigned long clockevent_rating, |
473 | unsigned long clocksource_rating) | 542 | unsigned long clocksource_rating) |
474 | { | 543 | { |
475 | if (p->width == (sizeof(p->max_match_value) * 8)) | 544 | if (p->width == (sizeof(p->max_match_value) * 8)) |
476 | p->max_match_value = ~0; | 545 | p->max_match_value = ~0; |
@@ -483,12 +552,15 @@ int sh_cmt_register(struct sh_cmt_priv *p, char *name, | |||
483 | if (clockevent_rating) | 552 | if (clockevent_rating) |
484 | sh_cmt_register_clockevent(p, name, clockevent_rating); | 553 | sh_cmt_register_clockevent(p, name, clockevent_rating); |
485 | 554 | ||
555 | if (clocksource_rating) | ||
556 | sh_cmt_register_clocksource(p, name, clocksource_rating); | ||
557 | |||
486 | return 0; | 558 | return 0; |
487 | } | 559 | } |
488 | 560 | ||
489 | static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) | 561 | static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) |
490 | { | 562 | { |
491 | struct sh_cmt_config *cfg = pdev->dev.platform_data; | 563 | struct sh_timer_config *cfg = pdev->dev.platform_data; |
492 | struct resource *res; | 564 | struct resource *res; |
493 | int irq, ret; | 565 | int irq, ret; |
494 | ret = -ENXIO; | 566 | ret = -ENXIO; |
@@ -545,7 +617,7 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) | |||
545 | if (resource_size(res) == 6) { | 617 | if (resource_size(res) == 6) { |
546 | p->width = 16; | 618 | p->width = 16; |
547 | p->overflow_bit = 0x80; | 619 | p->overflow_bit = 0x80; |
548 | p->clear_bits = ~0xc0; | 620 | p->clear_bits = ~0x80; |
549 | } else { | 621 | } else { |
550 | p->width = 32; | 622 | p->width = 32; |
551 | p->overflow_bit = 0x8000; | 623 | p->overflow_bit = 0x8000; |
@@ -566,8 +638,14 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) | |||
566 | static int __devinit sh_cmt_probe(struct platform_device *pdev) | 638 | static int __devinit sh_cmt_probe(struct platform_device *pdev) |
567 | { | 639 | { |
568 | struct sh_cmt_priv *p = platform_get_drvdata(pdev); | 640 | struct sh_cmt_priv *p = platform_get_drvdata(pdev); |
641 | struct sh_timer_config *cfg = pdev->dev.platform_data; | ||
569 | int ret; | 642 | int ret; |
570 | 643 | ||
644 | if (p) { | ||
645 | pr_info("sh_cmt: %s kept as earlytimer\n", cfg->name); | ||
646 | return 0; | ||
647 | } | ||
648 | |||
571 | p = kmalloc(sizeof(*p), GFP_KERNEL); | 649 | p = kmalloc(sizeof(*p), GFP_KERNEL); |
572 | if (p == NULL) { | 650 | if (p == NULL) { |
573 | dev_err(&pdev->dev, "failed to allocate driver data\n"); | 651 | dev_err(&pdev->dev, "failed to allocate driver data\n"); |
@@ -577,7 +655,6 @@ static int __devinit sh_cmt_probe(struct platform_device *pdev) | |||
577 | ret = sh_cmt_setup(p, pdev); | 655 | ret = sh_cmt_setup(p, pdev); |
578 | if (ret) { | 656 | if (ret) { |
579 | kfree(p); | 657 | kfree(p); |
580 | |||
581 | platform_set_drvdata(pdev, NULL); | 658 | platform_set_drvdata(pdev, NULL); |
582 | } | 659 | } |
583 | return ret; | 660 | return ret; |
@@ -606,6 +683,7 @@ static void __exit sh_cmt_exit(void) | |||
606 | platform_driver_unregister(&sh_cmt_device_driver); | 683 | platform_driver_unregister(&sh_cmt_device_driver); |
607 | } | 684 | } |
608 | 685 | ||
686 | early_platform_init("earlytimer", &sh_cmt_device_driver); | ||
609 | module_init(sh_cmt_init); | 687 | module_init(sh_cmt_init); |
610 | module_exit(sh_cmt_exit); | 688 | module_exit(sh_cmt_exit); |
611 | 689 | ||
diff --git a/drivers/clocksource/sh_mtu2.c b/drivers/clocksource/sh_mtu2.c new file mode 100644 index 000000000000..d1ae75454d10 --- /dev/null +++ b/drivers/clocksource/sh_mtu2.c | |||
@@ -0,0 +1,357 @@ | |||
1 | /* | ||
2 | * SuperH Timer Support - MTU2 | ||
3 | * | ||
4 | * Copyright (C) 2009 Magnus Damm | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/init.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/spinlock.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/ioport.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/io.h> | ||
27 | #include <linux/clk.h> | ||
28 | #include <linux/irq.h> | ||
29 | #include <linux/err.h> | ||
30 | #include <linux/clockchips.h> | ||
31 | #include <linux/sh_timer.h> | ||
32 | |||
33 | struct sh_mtu2_priv { | ||
34 | void __iomem *mapbase; | ||
35 | struct clk *clk; | ||
36 | struct irqaction irqaction; | ||
37 | struct platform_device *pdev; | ||
38 | unsigned long rate; | ||
39 | unsigned long periodic; | ||
40 | struct clock_event_device ced; | ||
41 | }; | ||
42 | |||
43 | static DEFINE_SPINLOCK(sh_mtu2_lock); | ||
44 | |||
45 | #define TSTR -1 /* shared register */ | ||
46 | #define TCR 0 /* channel register */ | ||
47 | #define TMDR 1 /* channel register */ | ||
48 | #define TIOR 2 /* channel register */ | ||
49 | #define TIER 3 /* channel register */ | ||
50 | #define TSR 4 /* channel register */ | ||
51 | #define TCNT 5 /* channel register */ | ||
52 | #define TGR 6 /* channel register */ | ||
53 | |||
54 | static unsigned long mtu2_reg_offs[] = { | ||
55 | [TCR] = 0, | ||
56 | [TMDR] = 1, | ||
57 | [TIOR] = 2, | ||
58 | [TIER] = 4, | ||
59 | [TSR] = 5, | ||
60 | [TCNT] = 6, | ||
61 | [TGR] = 8, | ||
62 | }; | ||
63 | |||
64 | static inline unsigned long sh_mtu2_read(struct sh_mtu2_priv *p, int reg_nr) | ||
65 | { | ||
66 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; | ||
67 | void __iomem *base = p->mapbase; | ||
68 | unsigned long offs; | ||
69 | |||
70 | if (reg_nr == TSTR) | ||
71 | return ioread8(base + cfg->channel_offset); | ||
72 | |||
73 | offs = mtu2_reg_offs[reg_nr]; | ||
74 | |||
75 | if ((reg_nr == TCNT) || (reg_nr == TGR)) | ||
76 | return ioread16(base + offs); | ||
77 | else | ||
78 | return ioread8(base + offs); | ||
79 | } | ||
80 | |||
81 | static inline void sh_mtu2_write(struct sh_mtu2_priv *p, int reg_nr, | ||
82 | unsigned long value) | ||
83 | { | ||
84 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; | ||
85 | void __iomem *base = p->mapbase; | ||
86 | unsigned long offs; | ||
87 | |||
88 | if (reg_nr == TSTR) { | ||
89 | iowrite8(value, base + cfg->channel_offset); | ||
90 | return; | ||
91 | } | ||
92 | |||
93 | offs = mtu2_reg_offs[reg_nr]; | ||
94 | |||
95 | if ((reg_nr == TCNT) || (reg_nr == TGR)) | ||
96 | iowrite16(value, base + offs); | ||
97 | else | ||
98 | iowrite8(value, base + offs); | ||
99 | } | ||
100 | |||
101 | static void sh_mtu2_start_stop_ch(struct sh_mtu2_priv *p, int start) | ||
102 | { | ||
103 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; | ||
104 | unsigned long flags, value; | ||
105 | |||
106 | /* start stop register shared by multiple timer channels */ | ||
107 | spin_lock_irqsave(&sh_mtu2_lock, flags); | ||
108 | value = sh_mtu2_read(p, TSTR); | ||
109 | |||
110 | if (start) | ||
111 | value |= 1 << cfg->timer_bit; | ||
112 | else | ||
113 | value &= ~(1 << cfg->timer_bit); | ||
114 | |||
115 | sh_mtu2_write(p, TSTR, value); | ||
116 | spin_unlock_irqrestore(&sh_mtu2_lock, flags); | ||
117 | } | ||
118 | |||
119 | static int sh_mtu2_enable(struct sh_mtu2_priv *p) | ||
120 | { | ||
121 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; | ||
122 | int ret; | ||
123 | |||
124 | /* enable clock */ | ||
125 | ret = clk_enable(p->clk); | ||
126 | if (ret) { | ||
127 | pr_err("sh_mtu2: cannot enable clock \"%s\"\n", cfg->clk); | ||
128 | return ret; | ||
129 | } | ||
130 | |||
131 | /* make sure channel is disabled */ | ||
132 | sh_mtu2_start_stop_ch(p, 0); | ||
133 | |||
134 | p->rate = clk_get_rate(p->clk) / 64; | ||
135 | p->periodic = (p->rate + HZ/2) / HZ; | ||
136 | |||
137 | /* "Periodic Counter Operation" */ | ||
138 | sh_mtu2_write(p, TCR, 0x23); /* TGRA clear, divide clock by 64 */ | ||
139 | sh_mtu2_write(p, TIOR, 0); | ||
140 | sh_mtu2_write(p, TGR, p->periodic); | ||
141 | sh_mtu2_write(p, TCNT, 0); | ||
142 | sh_mtu2_write(p, TMDR, 0); | ||
143 | sh_mtu2_write(p, TIER, 0x01); | ||
144 | |||
145 | /* enable channel */ | ||
146 | sh_mtu2_start_stop_ch(p, 1); | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | static void sh_mtu2_disable(struct sh_mtu2_priv *p) | ||
152 | { | ||
153 | /* disable channel */ | ||
154 | sh_mtu2_start_stop_ch(p, 0); | ||
155 | |||
156 | /* stop clock */ | ||
157 | clk_disable(p->clk); | ||
158 | } | ||
159 | |||
160 | static irqreturn_t sh_mtu2_interrupt(int irq, void *dev_id) | ||
161 | { | ||
162 | struct sh_mtu2_priv *p = dev_id; | ||
163 | |||
164 | /* acknowledge interrupt */ | ||
165 | sh_mtu2_read(p, TSR); | ||
166 | sh_mtu2_write(p, TSR, 0xfe); | ||
167 | |||
168 | /* notify clockevent layer */ | ||
169 | p->ced.event_handler(&p->ced); | ||
170 | return IRQ_HANDLED; | ||
171 | } | ||
172 | |||
173 | static struct sh_mtu2_priv *ced_to_sh_mtu2(struct clock_event_device *ced) | ||
174 | { | ||
175 | return container_of(ced, struct sh_mtu2_priv, ced); | ||
176 | } | ||
177 | |||
178 | static void sh_mtu2_clock_event_mode(enum clock_event_mode mode, | ||
179 | struct clock_event_device *ced) | ||
180 | { | ||
181 | struct sh_mtu2_priv *p = ced_to_sh_mtu2(ced); | ||
182 | int disabled = 0; | ||
183 | |||
184 | /* deal with old setting first */ | ||
185 | switch (ced->mode) { | ||
186 | case CLOCK_EVT_MODE_PERIODIC: | ||
187 | sh_mtu2_disable(p); | ||
188 | disabled = 1; | ||
189 | break; | ||
190 | default: | ||
191 | break; | ||
192 | } | ||
193 | |||
194 | switch (mode) { | ||
195 | case CLOCK_EVT_MODE_PERIODIC: | ||
196 | pr_info("sh_mtu2: %s used for periodic clock events\n", | ||
197 | ced->name); | ||
198 | sh_mtu2_enable(p); | ||
199 | break; | ||
200 | case CLOCK_EVT_MODE_UNUSED: | ||
201 | if (!disabled) | ||
202 | sh_mtu2_disable(p); | ||
203 | break; | ||
204 | case CLOCK_EVT_MODE_SHUTDOWN: | ||
205 | default: | ||
206 | break; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | static void sh_mtu2_register_clockevent(struct sh_mtu2_priv *p, | ||
211 | char *name, unsigned long rating) | ||
212 | { | ||
213 | struct clock_event_device *ced = &p->ced; | ||
214 | int ret; | ||
215 | |||
216 | memset(ced, 0, sizeof(*ced)); | ||
217 | |||
218 | ced->name = name; | ||
219 | ced->features = CLOCK_EVT_FEAT_PERIODIC; | ||
220 | ced->rating = rating; | ||
221 | ced->cpumask = cpumask_of(0); | ||
222 | ced->set_mode = sh_mtu2_clock_event_mode; | ||
223 | |||
224 | ret = setup_irq(p->irqaction.irq, &p->irqaction); | ||
225 | if (ret) { | ||
226 | pr_err("sh_mtu2: failed to request irq %d\n", | ||
227 | p->irqaction.irq); | ||
228 | return; | ||
229 | } | ||
230 | |||
231 | pr_info("sh_mtu2: %s used for clock events\n", ced->name); | ||
232 | clockevents_register_device(ced); | ||
233 | } | ||
234 | |||
235 | static int sh_mtu2_register(struct sh_mtu2_priv *p, char *name, | ||
236 | unsigned long clockevent_rating) | ||
237 | { | ||
238 | if (clockevent_rating) | ||
239 | sh_mtu2_register_clockevent(p, name, clockevent_rating); | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static int sh_mtu2_setup(struct sh_mtu2_priv *p, struct platform_device *pdev) | ||
245 | { | ||
246 | struct sh_timer_config *cfg = pdev->dev.platform_data; | ||
247 | struct resource *res; | ||
248 | int irq, ret; | ||
249 | ret = -ENXIO; | ||
250 | |||
251 | memset(p, 0, sizeof(*p)); | ||
252 | p->pdev = pdev; | ||
253 | |||
254 | if (!cfg) { | ||
255 | dev_err(&p->pdev->dev, "missing platform data\n"); | ||
256 | goto err0; | ||
257 | } | ||
258 | |||
259 | platform_set_drvdata(pdev, p); | ||
260 | |||
261 | res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0); | ||
262 | if (!res) { | ||
263 | dev_err(&p->pdev->dev, "failed to get I/O memory\n"); | ||
264 | goto err0; | ||
265 | } | ||
266 | |||
267 | irq = platform_get_irq(p->pdev, 0); | ||
268 | if (irq < 0) { | ||
269 | dev_err(&p->pdev->dev, "failed to get irq\n"); | ||
270 | goto err0; | ||
271 | } | ||
272 | |||
273 | /* map memory, let mapbase point to our channel */ | ||
274 | p->mapbase = ioremap_nocache(res->start, resource_size(res)); | ||
275 | if (p->mapbase == NULL) { | ||
276 | pr_err("sh_mtu2: failed to remap I/O memory\n"); | ||
277 | goto err0; | ||
278 | } | ||
279 | |||
280 | /* setup data for setup_irq() (too early for request_irq()) */ | ||
281 | p->irqaction.name = cfg->name; | ||
282 | p->irqaction.handler = sh_mtu2_interrupt; | ||
283 | p->irqaction.dev_id = p; | ||
284 | p->irqaction.irq = irq; | ||
285 | p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL; | ||
286 | p->irqaction.mask = CPU_MASK_NONE; | ||
287 | |||
288 | /* get hold of clock */ | ||
289 | p->clk = clk_get(&p->pdev->dev, cfg->clk); | ||
290 | if (IS_ERR(p->clk)) { | ||
291 | pr_err("sh_mtu2: cannot get clock \"%s\"\n", cfg->clk); | ||
292 | ret = PTR_ERR(p->clk); | ||
293 | goto err1; | ||
294 | } | ||
295 | |||
296 | return sh_mtu2_register(p, cfg->name, cfg->clockevent_rating); | ||
297 | err1: | ||
298 | iounmap(p->mapbase); | ||
299 | err0: | ||
300 | return ret; | ||
301 | } | ||
302 | |||
303 | static int __devinit sh_mtu2_probe(struct platform_device *pdev) | ||
304 | { | ||
305 | struct sh_mtu2_priv *p = platform_get_drvdata(pdev); | ||
306 | struct sh_timer_config *cfg = pdev->dev.platform_data; | ||
307 | int ret; | ||
308 | |||
309 | if (p) { | ||
310 | pr_info("sh_mtu2: %s kept as earlytimer\n", cfg->name); | ||
311 | return 0; | ||
312 | } | ||
313 | |||
314 | p = kmalloc(sizeof(*p), GFP_KERNEL); | ||
315 | if (p == NULL) { | ||
316 | dev_err(&pdev->dev, "failed to allocate driver data\n"); | ||
317 | return -ENOMEM; | ||
318 | } | ||
319 | |||
320 | ret = sh_mtu2_setup(p, pdev); | ||
321 | if (ret) { | ||
322 | kfree(p); | ||
323 | platform_set_drvdata(pdev, NULL); | ||
324 | } | ||
325 | return ret; | ||
326 | } | ||
327 | |||
328 | static int __devexit sh_mtu2_remove(struct platform_device *pdev) | ||
329 | { | ||
330 | return -EBUSY; /* cannot unregister clockevent */ | ||
331 | } | ||
332 | |||
333 | static struct platform_driver sh_mtu2_device_driver = { | ||
334 | .probe = sh_mtu2_probe, | ||
335 | .remove = __devexit_p(sh_mtu2_remove), | ||
336 | .driver = { | ||
337 | .name = "sh_mtu2", | ||
338 | } | ||
339 | }; | ||
340 | |||
341 | static int __init sh_mtu2_init(void) | ||
342 | { | ||
343 | return platform_driver_register(&sh_mtu2_device_driver); | ||
344 | } | ||
345 | |||
346 | static void __exit sh_mtu2_exit(void) | ||
347 | { | ||
348 | platform_driver_unregister(&sh_mtu2_device_driver); | ||
349 | } | ||
350 | |||
351 | early_platform_init("earlytimer", &sh_mtu2_device_driver); | ||
352 | module_init(sh_mtu2_init); | ||
353 | module_exit(sh_mtu2_exit); | ||
354 | |||
355 | MODULE_AUTHOR("Magnus Damm"); | ||
356 | MODULE_DESCRIPTION("SuperH MTU2 Timer Driver"); | ||
357 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c new file mode 100644 index 000000000000..d6ea4398bf62 --- /dev/null +++ b/drivers/clocksource/sh_tmu.c | |||
@@ -0,0 +1,461 @@ | |||
1 | /* | ||
2 | * SuperH Timer Support - TMU | ||
3 | * | ||
4 | * Copyright (C) 2009 Magnus Damm | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/init.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/spinlock.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/ioport.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/io.h> | ||
27 | #include <linux/clk.h> | ||
28 | #include <linux/irq.h> | ||
29 | #include <linux/err.h> | ||
30 | #include <linux/clocksource.h> | ||
31 | #include <linux/clockchips.h> | ||
32 | #include <linux/sh_timer.h> | ||
33 | |||
34 | struct sh_tmu_priv { | ||
35 | void __iomem *mapbase; | ||
36 | struct clk *clk; | ||
37 | struct irqaction irqaction; | ||
38 | struct platform_device *pdev; | ||
39 | unsigned long rate; | ||
40 | unsigned long periodic; | ||
41 | struct clock_event_device ced; | ||
42 | struct clocksource cs; | ||
43 | }; | ||
44 | |||
45 | static DEFINE_SPINLOCK(sh_tmu_lock); | ||
46 | |||
47 | #define TSTR -1 /* shared register */ | ||
48 | #define TCOR 0 /* channel register */ | ||
49 | #define TCNT 1 /* channel register */ | ||
50 | #define TCR 2 /* channel register */ | ||
51 | |||
52 | static inline unsigned long sh_tmu_read(struct sh_tmu_priv *p, int reg_nr) | ||
53 | { | ||
54 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; | ||
55 | void __iomem *base = p->mapbase; | ||
56 | unsigned long offs; | ||
57 | |||
58 | if (reg_nr == TSTR) | ||
59 | return ioread8(base - cfg->channel_offset); | ||
60 | |||
61 | offs = reg_nr << 2; | ||
62 | |||
63 | if (reg_nr == TCR) | ||
64 | return ioread16(base + offs); | ||
65 | else | ||
66 | return ioread32(base + offs); | ||
67 | } | ||
68 | |||
69 | static inline void sh_tmu_write(struct sh_tmu_priv *p, int reg_nr, | ||
70 | unsigned long value) | ||
71 | { | ||
72 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; | ||
73 | void __iomem *base = p->mapbase; | ||
74 | unsigned long offs; | ||
75 | |||
76 | if (reg_nr == TSTR) { | ||
77 | iowrite8(value, base - cfg->channel_offset); | ||
78 | return; | ||
79 | } | ||
80 | |||
81 | offs = reg_nr << 2; | ||
82 | |||
83 | if (reg_nr == TCR) | ||
84 | iowrite16(value, base + offs); | ||
85 | else | ||
86 | iowrite32(value, base + offs); | ||
87 | } | ||
88 | |||
89 | static void sh_tmu_start_stop_ch(struct sh_tmu_priv *p, int start) | ||
90 | { | ||
91 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; | ||
92 | unsigned long flags, value; | ||
93 | |||
94 | /* start stop register shared by multiple timer channels */ | ||
95 | spin_lock_irqsave(&sh_tmu_lock, flags); | ||
96 | value = sh_tmu_read(p, TSTR); | ||
97 | |||
98 | if (start) | ||
99 | value |= 1 << cfg->timer_bit; | ||
100 | else | ||
101 | value &= ~(1 << cfg->timer_bit); | ||
102 | |||
103 | sh_tmu_write(p, TSTR, value); | ||
104 | spin_unlock_irqrestore(&sh_tmu_lock, flags); | ||
105 | } | ||
106 | |||
107 | static int sh_tmu_enable(struct sh_tmu_priv *p) | ||
108 | { | ||
109 | struct sh_timer_config *cfg = p->pdev->dev.platform_data; | ||
110 | int ret; | ||
111 | |||
112 | /* enable clock */ | ||
113 | ret = clk_enable(p->clk); | ||
114 | if (ret) { | ||
115 | pr_err("sh_tmu: cannot enable clock \"%s\"\n", cfg->clk); | ||
116 | return ret; | ||
117 | } | ||
118 | |||
119 | /* make sure channel is disabled */ | ||
120 | sh_tmu_start_stop_ch(p, 0); | ||
121 | |||
122 | /* maximum timeout */ | ||
123 | sh_tmu_write(p, TCOR, 0xffffffff); | ||
124 | sh_tmu_write(p, TCNT, 0xffffffff); | ||
125 | |||
126 | /* configure channel to parent clock / 4, irq off */ | ||
127 | p->rate = clk_get_rate(p->clk) / 4; | ||
128 | sh_tmu_write(p, TCR, 0x0000); | ||
129 | |||
130 | /* enable channel */ | ||
131 | sh_tmu_start_stop_ch(p, 1); | ||
132 | |||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | static void sh_tmu_disable(struct sh_tmu_priv *p) | ||
137 | { | ||
138 | /* disable channel */ | ||
139 | sh_tmu_start_stop_ch(p, 0); | ||
140 | |||
141 | /* stop clock */ | ||
142 | clk_disable(p->clk); | ||
143 | } | ||
144 | |||
145 | static void sh_tmu_set_next(struct sh_tmu_priv *p, unsigned long delta, | ||
146 | int periodic) | ||
147 | { | ||
148 | /* stop timer */ | ||
149 | sh_tmu_start_stop_ch(p, 0); | ||
150 | |||
151 | /* acknowledge interrupt */ | ||
152 | sh_tmu_read(p, TCR); | ||
153 | |||
154 | /* enable interrupt */ | ||
155 | sh_tmu_write(p, TCR, 0x0020); | ||
156 | |||
157 | /* reload delta value in case of periodic timer */ | ||
158 | if (periodic) | ||
159 | sh_tmu_write(p, TCOR, delta); | ||
160 | else | ||
161 | sh_tmu_write(p, TCOR, 0); | ||
162 | |||
163 | sh_tmu_write(p, TCNT, delta); | ||
164 | |||
165 | /* start timer */ | ||
166 | sh_tmu_start_stop_ch(p, 1); | ||
167 | } | ||
168 | |||
169 | static irqreturn_t sh_tmu_interrupt(int irq, void *dev_id) | ||
170 | { | ||
171 | struct sh_tmu_priv *p = dev_id; | ||
172 | |||
173 | /* disable or acknowledge interrupt */ | ||
174 | if (p->ced.mode == CLOCK_EVT_MODE_ONESHOT) | ||
175 | sh_tmu_write(p, TCR, 0x0000); | ||
176 | else | ||
177 | sh_tmu_write(p, TCR, 0x0020); | ||
178 | |||
179 | /* notify clockevent layer */ | ||
180 | p->ced.event_handler(&p->ced); | ||
181 | return IRQ_HANDLED; | ||
182 | } | ||
183 | |||
184 | static struct sh_tmu_priv *cs_to_sh_tmu(struct clocksource *cs) | ||
185 | { | ||
186 | return container_of(cs, struct sh_tmu_priv, cs); | ||
187 | } | ||
188 | |||
189 | static cycle_t sh_tmu_clocksource_read(struct clocksource *cs) | ||
190 | { | ||
191 | struct sh_tmu_priv *p = cs_to_sh_tmu(cs); | ||
192 | |||
193 | return sh_tmu_read(p, TCNT) ^ 0xffffffff; | ||
194 | } | ||
195 | |||
196 | static int sh_tmu_clocksource_enable(struct clocksource *cs) | ||
197 | { | ||
198 | struct sh_tmu_priv *p = cs_to_sh_tmu(cs); | ||
199 | int ret; | ||
200 | |||
201 | ret = sh_tmu_enable(p); | ||
202 | if (ret) | ||
203 | return ret; | ||
204 | |||
205 | /* TODO: calculate good shift from rate and counter bit width */ | ||
206 | cs->shift = 10; | ||
207 | cs->mult = clocksource_hz2mult(p->rate, cs->shift); | ||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | static void sh_tmu_clocksource_disable(struct clocksource *cs) | ||
212 | { | ||
213 | sh_tmu_disable(cs_to_sh_tmu(cs)); | ||
214 | } | ||
215 | |||
216 | static int sh_tmu_register_clocksource(struct sh_tmu_priv *p, | ||
217 | char *name, unsigned long rating) | ||
218 | { | ||
219 | struct clocksource *cs = &p->cs; | ||
220 | |||
221 | cs->name = name; | ||
222 | cs->rating = rating; | ||
223 | cs->read = sh_tmu_clocksource_read; | ||
224 | cs->enable = sh_tmu_clocksource_enable; | ||
225 | cs->disable = sh_tmu_clocksource_disable; | ||
226 | cs->mask = CLOCKSOURCE_MASK(32); | ||
227 | cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; | ||
228 | pr_info("sh_tmu: %s used as clock source\n", cs->name); | ||
229 | clocksource_register(cs); | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | static struct sh_tmu_priv *ced_to_sh_tmu(struct clock_event_device *ced) | ||
234 | { | ||
235 | return container_of(ced, struct sh_tmu_priv, ced); | ||
236 | } | ||
237 | |||
238 | static void sh_tmu_clock_event_start(struct sh_tmu_priv *p, int periodic) | ||
239 | { | ||
240 | struct clock_event_device *ced = &p->ced; | ||
241 | |||
242 | sh_tmu_enable(p); | ||
243 | |||
244 | /* TODO: calculate good shift from rate and counter bit width */ | ||
245 | |||
246 | ced->shift = 32; | ||
247 | ced->mult = div_sc(p->rate, NSEC_PER_SEC, ced->shift); | ||
248 | ced->max_delta_ns = clockevent_delta2ns(0xffffffff, ced); | ||
249 | ced->min_delta_ns = 5000; | ||
250 | |||
251 | if (periodic) { | ||
252 | p->periodic = (p->rate + HZ/2) / HZ; | ||
253 | sh_tmu_set_next(p, p->periodic, 1); | ||
254 | } | ||
255 | } | ||
256 | |||
257 | static void sh_tmu_clock_event_mode(enum clock_event_mode mode, | ||
258 | struct clock_event_device *ced) | ||
259 | { | ||
260 | struct sh_tmu_priv *p = ced_to_sh_tmu(ced); | ||
261 | int disabled = 0; | ||
262 | |||
263 | /* deal with old setting first */ | ||
264 | switch (ced->mode) { | ||
265 | case CLOCK_EVT_MODE_PERIODIC: | ||
266 | case CLOCK_EVT_MODE_ONESHOT: | ||
267 | sh_tmu_disable(p); | ||
268 | disabled = 1; | ||
269 | break; | ||
270 | default: | ||
271 | break; | ||
272 | } | ||
273 | |||
274 | switch (mode) { | ||
275 | case CLOCK_EVT_MODE_PERIODIC: | ||
276 | pr_info("sh_tmu: %s used for periodic clock events\n", | ||
277 | ced->name); | ||
278 | sh_tmu_clock_event_start(p, 1); | ||
279 | break; | ||
280 | case CLOCK_EVT_MODE_ONESHOT: | ||
281 | pr_info("sh_tmu: %s used for oneshot clock events\n", | ||
282 | ced->name); | ||
283 | sh_tmu_clock_event_start(p, 0); | ||
284 | break; | ||
285 | case CLOCK_EVT_MODE_UNUSED: | ||
286 | if (!disabled) | ||
287 | sh_tmu_disable(p); | ||
288 | break; | ||
289 | case CLOCK_EVT_MODE_SHUTDOWN: | ||
290 | default: | ||
291 | break; | ||
292 | } | ||
293 | } | ||
294 | |||
295 | static int sh_tmu_clock_event_next(unsigned long delta, | ||
296 | struct clock_event_device *ced) | ||
297 | { | ||
298 | struct sh_tmu_priv *p = ced_to_sh_tmu(ced); | ||
299 | |||
300 | BUG_ON(ced->mode != CLOCK_EVT_MODE_ONESHOT); | ||
301 | |||
302 | /* program new delta value */ | ||
303 | sh_tmu_set_next(p, delta, 0); | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | static void sh_tmu_register_clockevent(struct sh_tmu_priv *p, | ||
308 | char *name, unsigned long rating) | ||
309 | { | ||
310 | struct clock_event_device *ced = &p->ced; | ||
311 | int ret; | ||
312 | |||
313 | memset(ced, 0, sizeof(*ced)); | ||
314 | |||
315 | ced->name = name; | ||
316 | ced->features = CLOCK_EVT_FEAT_PERIODIC; | ||
317 | ced->features |= CLOCK_EVT_FEAT_ONESHOT; | ||
318 | ced->rating = rating; | ||
319 | ced->cpumask = cpumask_of(0); | ||
320 | ced->set_next_event = sh_tmu_clock_event_next; | ||
321 | ced->set_mode = sh_tmu_clock_event_mode; | ||
322 | |||
323 | ret = setup_irq(p->irqaction.irq, &p->irqaction); | ||
324 | if (ret) { | ||
325 | pr_err("sh_tmu: failed to request irq %d\n", | ||
326 | p->irqaction.irq); | ||
327 | return; | ||
328 | } | ||
329 | |||
330 | pr_info("sh_tmu: %s used for clock events\n", ced->name); | ||
331 | clockevents_register_device(ced); | ||
332 | } | ||
333 | |||
334 | static int sh_tmu_register(struct sh_tmu_priv *p, char *name, | ||
335 | unsigned long clockevent_rating, | ||
336 | unsigned long clocksource_rating) | ||
337 | { | ||
338 | if (clockevent_rating) | ||
339 | sh_tmu_register_clockevent(p, name, clockevent_rating); | ||
340 | else if (clocksource_rating) | ||
341 | sh_tmu_register_clocksource(p, name, clocksource_rating); | ||
342 | |||
343 | return 0; | ||
344 | } | ||
345 | |||
346 | static int sh_tmu_setup(struct sh_tmu_priv *p, struct platform_device *pdev) | ||
347 | { | ||
348 | struct sh_timer_config *cfg = pdev->dev.platform_data; | ||
349 | struct resource *res; | ||
350 | int irq, ret; | ||
351 | ret = -ENXIO; | ||
352 | |||
353 | memset(p, 0, sizeof(*p)); | ||
354 | p->pdev = pdev; | ||
355 | |||
356 | if (!cfg) { | ||
357 | dev_err(&p->pdev->dev, "missing platform data\n"); | ||
358 | goto err0; | ||
359 | } | ||
360 | |||
361 | platform_set_drvdata(pdev, p); | ||
362 | |||
363 | res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0); | ||
364 | if (!res) { | ||
365 | dev_err(&p->pdev->dev, "failed to get I/O memory\n"); | ||
366 | goto err0; | ||
367 | } | ||
368 | |||
369 | irq = platform_get_irq(p->pdev, 0); | ||
370 | if (irq < 0) { | ||
371 | dev_err(&p->pdev->dev, "failed to get irq\n"); | ||
372 | goto err0; | ||
373 | } | ||
374 | |||
375 | /* map memory, let mapbase point to our channel */ | ||
376 | p->mapbase = ioremap_nocache(res->start, resource_size(res)); | ||
377 | if (p->mapbase == NULL) { | ||
378 | pr_err("sh_tmu: failed to remap I/O memory\n"); | ||
379 | goto err0; | ||
380 | } | ||
381 | |||
382 | /* setup data for setup_irq() (too early for request_irq()) */ | ||
383 | p->irqaction.name = cfg->name; | ||
384 | p->irqaction.handler = sh_tmu_interrupt; | ||
385 | p->irqaction.dev_id = p; | ||
386 | p->irqaction.irq = irq; | ||
387 | p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL; | ||
388 | p->irqaction.mask = CPU_MASK_NONE; | ||
389 | |||
390 | /* get hold of clock */ | ||
391 | p->clk = clk_get(&p->pdev->dev, cfg->clk); | ||
392 | if (IS_ERR(p->clk)) { | ||
393 | pr_err("sh_tmu: cannot get clock \"%s\"\n", cfg->clk); | ||
394 | ret = PTR_ERR(p->clk); | ||
395 | goto err1; | ||
396 | } | ||
397 | |||
398 | return sh_tmu_register(p, cfg->name, | ||
399 | cfg->clockevent_rating, | ||
400 | cfg->clocksource_rating); | ||
401 | err1: | ||
402 | iounmap(p->mapbase); | ||
403 | err0: | ||
404 | return ret; | ||
405 | } | ||
406 | |||
407 | static int __devinit sh_tmu_probe(struct platform_device *pdev) | ||
408 | { | ||
409 | struct sh_tmu_priv *p = platform_get_drvdata(pdev); | ||
410 | struct sh_timer_config *cfg = pdev->dev.platform_data; | ||
411 | int ret; | ||
412 | |||
413 | if (p) { | ||
414 | pr_info("sh_tmu: %s kept as earlytimer\n", cfg->name); | ||
415 | return 0; | ||
416 | } | ||
417 | |||
418 | p = kmalloc(sizeof(*p), GFP_KERNEL); | ||
419 | if (p == NULL) { | ||
420 | dev_err(&pdev->dev, "failed to allocate driver data\n"); | ||
421 | return -ENOMEM; | ||
422 | } | ||
423 | |||
424 | ret = sh_tmu_setup(p, pdev); | ||
425 | if (ret) { | ||
426 | kfree(p); | ||
427 | platform_set_drvdata(pdev, NULL); | ||
428 | } | ||
429 | return ret; | ||
430 | } | ||
431 | |||
432 | static int __devexit sh_tmu_remove(struct platform_device *pdev) | ||
433 | { | ||
434 | return -EBUSY; /* cannot unregister clockevent and clocksource */ | ||
435 | } | ||
436 | |||
437 | static struct platform_driver sh_tmu_device_driver = { | ||
438 | .probe = sh_tmu_probe, | ||
439 | .remove = __devexit_p(sh_tmu_remove), | ||
440 | .driver = { | ||
441 | .name = "sh_tmu", | ||
442 | } | ||
443 | }; | ||
444 | |||
445 | static int __init sh_tmu_init(void) | ||
446 | { | ||
447 | return platform_driver_register(&sh_tmu_device_driver); | ||
448 | } | ||
449 | |||
450 | static void __exit sh_tmu_exit(void) | ||
451 | { | ||
452 | platform_driver_unregister(&sh_tmu_device_driver); | ||
453 | } | ||
454 | |||
455 | early_platform_init("earlytimer", &sh_tmu_device_driver); | ||
456 | module_init(sh_tmu_init); | ||
457 | module_exit(sh_tmu_exit); | ||
458 | |||
459 | MODULE_AUTHOR("Magnus Damm"); | ||
460 | MODULE_DESCRIPTION("SuperH TMU Timer Driver"); | ||
461 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index d270e8eb3e67..6e2ec0b18948 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -808,7 +808,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) | |||
808 | ret = -ENOMEM; | 808 | ret = -ENOMEM; |
809 | goto nomem_out; | 809 | goto nomem_out; |
810 | } | 810 | } |
811 | if (!alloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) { | 811 | if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) { |
812 | free_cpumask_var(policy->cpus); | 812 | free_cpumask_var(policy->cpus); |
813 | kfree(policy); | 813 | kfree(policy); |
814 | ret = -ENOMEM; | 814 | ret = -ENOMEM; |
@@ -1070,11 +1070,11 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) | |||
1070 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1070 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1071 | #endif | 1071 | #endif |
1072 | 1072 | ||
1073 | unlock_policy_rwsem_write(cpu); | ||
1074 | |||
1073 | if (cpufreq_driver->target) | 1075 | if (cpufreq_driver->target) |
1074 | __cpufreq_governor(data, CPUFREQ_GOV_STOP); | 1076 | __cpufreq_governor(data, CPUFREQ_GOV_STOP); |
1075 | 1077 | ||
1076 | unlock_policy_rwsem_write(cpu); | ||
1077 | |||
1078 | kobject_put(&data->kobj); | 1078 | kobject_put(&data->kobj); |
1079 | 1079 | ||
1080 | /* we need to make sure that the underlying kobj is actually | 1080 | /* we need to make sure that the underlying kobj is actually |
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c index 2ecd95e4ab1a..7a74d175287b 100644 --- a/drivers/cpufreq/cpufreq_conservative.c +++ b/drivers/cpufreq/cpufreq_conservative.c | |||
@@ -91,6 +91,9 @@ static unsigned int dbs_enable; /* number of CPUs using this policy */ | |||
91 | * (like __cpufreq_driver_target()) is being called with dbs_mutex taken, then | 91 | * (like __cpufreq_driver_target()) is being called with dbs_mutex taken, then |
92 | * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock | 92 | * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock |
93 | * is recursive for the same process. -Venki | 93 | * is recursive for the same process. -Venki |
94 | * DEADLOCK ALERT! (2) : do_dbs_timer() must not take the dbs_mutex, because it | ||
95 | * would deadlock with cancel_delayed_work_sync(), which is needed for proper | ||
96 | * raceless workqueue teardown. | ||
94 | */ | 97 | */ |
95 | static DEFINE_MUTEX(dbs_mutex); | 98 | static DEFINE_MUTEX(dbs_mutex); |
96 | 99 | ||
@@ -542,7 +545,7 @@ static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info) | |||
542 | static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info) | 545 | static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info) |
543 | { | 546 | { |
544 | dbs_info->enable = 0; | 547 | dbs_info->enable = 0; |
545 | cancel_delayed_work(&dbs_info->work); | 548 | cancel_delayed_work_sync(&dbs_info->work); |
546 | } | 549 | } |
547 | 550 | ||
548 | static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | 551 | static int cpufreq_governor_dbs(struct cpufreq_policy *policy, |
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c index 338f428a15b7..e741c339df76 100644 --- a/drivers/cpufreq/cpufreq_ondemand.c +++ b/drivers/cpufreq/cpufreq_ondemand.c | |||
@@ -98,6 +98,9 @@ static unsigned int dbs_enable; /* number of CPUs using this policy */ | |||
98 | * (like __cpufreq_driver_target()) is being called with dbs_mutex taken, then | 98 | * (like __cpufreq_driver_target()) is being called with dbs_mutex taken, then |
99 | * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock | 99 | * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock |
100 | * is recursive for the same process. -Venki | 100 | * is recursive for the same process. -Venki |
101 | * DEADLOCK ALERT! (2) : do_dbs_timer() must not take the dbs_mutex, because it | ||
102 | * would deadlock with cancel_delayed_work_sync(), which is needed for proper | ||
103 | * raceless workqueue teardown. | ||
101 | */ | 104 | */ |
102 | static DEFINE_MUTEX(dbs_mutex); | 105 | static DEFINE_MUTEX(dbs_mutex); |
103 | 106 | ||
@@ -562,7 +565,7 @@ static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info) | |||
562 | static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info) | 565 | static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info) |
563 | { | 566 | { |
564 | dbs_info->enable = 0; | 567 | dbs_info->enable = 0; |
565 | cancel_delayed_work(&dbs_info->work); | 568 | cancel_delayed_work_sync(&dbs_info->work); |
566 | } | 569 | } |
567 | 570 | ||
568 | static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | 571 | static int cpufreq_governor_dbs(struct cpufreq_policy *policy, |
diff --git a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c index da8a8ed9e411..f18d1bde0439 100644 --- a/drivers/dma/fsldma.c +++ b/drivers/dma/fsldma.c | |||
@@ -179,9 +179,14 @@ static void dma_halt(struct fsl_dma_chan *fsl_chan) | |||
179 | static void set_ld_eol(struct fsl_dma_chan *fsl_chan, | 179 | static void set_ld_eol(struct fsl_dma_chan *fsl_chan, |
180 | struct fsl_desc_sw *desc) | 180 | struct fsl_desc_sw *desc) |
181 | { | 181 | { |
182 | u64 snoop_bits; | ||
183 | |||
184 | snoop_bits = ((fsl_chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_83XX) | ||
185 | ? FSL_DMA_SNEN : 0; | ||
186 | |||
182 | desc->hw.next_ln_addr = CPU_TO_DMA(fsl_chan, | 187 | desc->hw.next_ln_addr = CPU_TO_DMA(fsl_chan, |
183 | DMA_TO_CPU(fsl_chan, desc->hw.next_ln_addr, 64) | FSL_DMA_EOL, | 188 | DMA_TO_CPU(fsl_chan, desc->hw.next_ln_addr, 64) | FSL_DMA_EOL |
184 | 64); | 189 | | snoop_bits, 64); |
185 | } | 190 | } |
186 | 191 | ||
187 | static void append_ld_queue(struct fsl_dma_chan *fsl_chan, | 192 | static void append_ld_queue(struct fsl_dma_chan *fsl_chan, |
@@ -313,8 +318,8 @@ static void fsl_chan_toggle_ext_start(struct fsl_dma_chan *fsl_chan, int enable) | |||
313 | 318 | ||
314 | static dma_cookie_t fsl_dma_tx_submit(struct dma_async_tx_descriptor *tx) | 319 | static dma_cookie_t fsl_dma_tx_submit(struct dma_async_tx_descriptor *tx) |
315 | { | 320 | { |
316 | struct fsl_desc_sw *desc = tx_to_fsl_desc(tx); | ||
317 | struct fsl_dma_chan *fsl_chan = to_fsl_chan(tx->chan); | 321 | struct fsl_dma_chan *fsl_chan = to_fsl_chan(tx->chan); |
322 | struct fsl_desc_sw *desc; | ||
318 | unsigned long flags; | 323 | unsigned long flags; |
319 | dma_cookie_t cookie; | 324 | dma_cookie_t cookie; |
320 | 325 | ||
@@ -322,14 +327,17 @@ static dma_cookie_t fsl_dma_tx_submit(struct dma_async_tx_descriptor *tx) | |||
322 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); | 327 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); |
323 | 328 | ||
324 | cookie = fsl_chan->common.cookie; | 329 | cookie = fsl_chan->common.cookie; |
325 | cookie++; | 330 | list_for_each_entry(desc, &tx->tx_list, node) { |
326 | if (cookie < 0) | 331 | cookie++; |
327 | cookie = 1; | 332 | if (cookie < 0) |
328 | desc->async_tx.cookie = cookie; | 333 | cookie = 1; |
329 | fsl_chan->common.cookie = desc->async_tx.cookie; | ||
330 | 334 | ||
331 | append_ld_queue(fsl_chan, desc); | 335 | desc->async_tx.cookie = cookie; |
332 | list_splice_init(&desc->async_tx.tx_list, fsl_chan->ld_queue.prev); | 336 | } |
337 | |||
338 | fsl_chan->common.cookie = cookie; | ||
339 | append_ld_queue(fsl_chan, tx_to_fsl_desc(tx)); | ||
340 | list_splice_init(&tx->tx_list, fsl_chan->ld_queue.prev); | ||
333 | 341 | ||
334 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | 342 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); |
335 | 343 | ||
@@ -454,8 +462,8 @@ static struct dma_async_tx_descriptor *fsl_dma_prep_memcpy( | |||
454 | { | 462 | { |
455 | struct fsl_dma_chan *fsl_chan; | 463 | struct fsl_dma_chan *fsl_chan; |
456 | struct fsl_desc_sw *first = NULL, *prev = NULL, *new; | 464 | struct fsl_desc_sw *first = NULL, *prev = NULL, *new; |
465 | struct list_head *list; | ||
457 | size_t copy; | 466 | size_t copy; |
458 | LIST_HEAD(link_chain); | ||
459 | 467 | ||
460 | if (!chan) | 468 | if (!chan) |
461 | return NULL; | 469 | return NULL; |
@@ -472,7 +480,7 @@ static struct dma_async_tx_descriptor *fsl_dma_prep_memcpy( | |||
472 | if (!new) { | 480 | if (!new) { |
473 | dev_err(fsl_chan->dev, | 481 | dev_err(fsl_chan->dev, |
474 | "No free memory for link descriptor\n"); | 482 | "No free memory for link descriptor\n"); |
475 | return NULL; | 483 | goto fail; |
476 | } | 484 | } |
477 | #ifdef FSL_DMA_LD_DEBUG | 485 | #ifdef FSL_DMA_LD_DEBUG |
478 | dev_dbg(fsl_chan->dev, "new link desc alloc %p\n", new); | 486 | dev_dbg(fsl_chan->dev, "new link desc alloc %p\n", new); |
@@ -507,7 +515,19 @@ static struct dma_async_tx_descriptor *fsl_dma_prep_memcpy( | |||
507 | /* Set End-of-link to the last link descriptor of new list*/ | 515 | /* Set End-of-link to the last link descriptor of new list*/ |
508 | set_ld_eol(fsl_chan, new); | 516 | set_ld_eol(fsl_chan, new); |
509 | 517 | ||
510 | return first ? &first->async_tx : NULL; | 518 | return &first->async_tx; |
519 | |||
520 | fail: | ||
521 | if (!first) | ||
522 | return NULL; | ||
523 | |||
524 | list = &first->async_tx.tx_list; | ||
525 | list_for_each_entry_safe_reverse(new, prev, list, node) { | ||
526 | list_del(&new->node); | ||
527 | dma_pool_free(fsl_chan->desc_pool, new, new->async_tx.phys); | ||
528 | } | ||
529 | |||
530 | return NULL; | ||
511 | } | 531 | } |
512 | 532 | ||
513 | /** | 533 | /** |
@@ -598,15 +618,16 @@ static void fsl_chan_xfer_ld_queue(struct fsl_dma_chan *fsl_chan) | |||
598 | dma_addr_t next_dest_addr; | 618 | dma_addr_t next_dest_addr; |
599 | unsigned long flags; | 619 | unsigned long flags; |
600 | 620 | ||
621 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); | ||
622 | |||
601 | if (!dma_is_idle(fsl_chan)) | 623 | if (!dma_is_idle(fsl_chan)) |
602 | return; | 624 | goto out_unlock; |
603 | 625 | ||
604 | dma_halt(fsl_chan); | 626 | dma_halt(fsl_chan); |
605 | 627 | ||
606 | /* If there are some link descriptors | 628 | /* If there are some link descriptors |
607 | * not transfered in queue. We need to start it. | 629 | * not transfered in queue. We need to start it. |
608 | */ | 630 | */ |
609 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); | ||
610 | 631 | ||
611 | /* Find the first un-transfer desciptor */ | 632 | /* Find the first un-transfer desciptor */ |
612 | for (ld_node = fsl_chan->ld_queue.next; | 633 | for (ld_node = fsl_chan->ld_queue.next; |
@@ -617,19 +638,20 @@ static void fsl_chan_xfer_ld_queue(struct fsl_dma_chan *fsl_chan) | |||
617 | fsl_chan->common.cookie) == DMA_SUCCESS); | 638 | fsl_chan->common.cookie) == DMA_SUCCESS); |
618 | ld_node = ld_node->next); | 639 | ld_node = ld_node->next); |
619 | 640 | ||
620 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | ||
621 | |||
622 | if (ld_node != &fsl_chan->ld_queue) { | 641 | if (ld_node != &fsl_chan->ld_queue) { |
623 | /* Get the ld start address from ld_queue */ | 642 | /* Get the ld start address from ld_queue */ |
624 | next_dest_addr = to_fsl_desc(ld_node)->async_tx.phys; | 643 | next_dest_addr = to_fsl_desc(ld_node)->async_tx.phys; |
625 | dev_dbg(fsl_chan->dev, "xfer LDs staring from %p\n", | 644 | dev_dbg(fsl_chan->dev, "xfer LDs staring from 0x%llx\n", |
626 | (void *)next_dest_addr); | 645 | (unsigned long long)next_dest_addr); |
627 | set_cdar(fsl_chan, next_dest_addr); | 646 | set_cdar(fsl_chan, next_dest_addr); |
628 | dma_start(fsl_chan); | 647 | dma_start(fsl_chan); |
629 | } else { | 648 | } else { |
630 | set_cdar(fsl_chan, 0); | 649 | set_cdar(fsl_chan, 0); |
631 | set_ndar(fsl_chan, 0); | 650 | set_ndar(fsl_chan, 0); |
632 | } | 651 | } |
652 | |||
653 | out_unlock: | ||
654 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | ||
633 | } | 655 | } |
634 | 656 | ||
635 | /** | 657 | /** |
@@ -734,8 +756,9 @@ static irqreturn_t fsl_dma_chan_do_interrupt(int irq, void *data) | |||
734 | */ | 756 | */ |
735 | if (stat & FSL_DMA_SR_EOSI) { | 757 | if (stat & FSL_DMA_SR_EOSI) { |
736 | dev_dbg(fsl_chan->dev, "event: End-of-segments INT\n"); | 758 | dev_dbg(fsl_chan->dev, "event: End-of-segments INT\n"); |
737 | dev_dbg(fsl_chan->dev, "event: clndar %p, nlndar %p\n", | 759 | dev_dbg(fsl_chan->dev, "event: clndar 0x%llx, nlndar 0x%llx\n", |
738 | (void *)get_cdar(fsl_chan), (void *)get_ndar(fsl_chan)); | 760 | (unsigned long long)get_cdar(fsl_chan), |
761 | (unsigned long long)get_ndar(fsl_chan)); | ||
739 | stat &= ~FSL_DMA_SR_EOSI; | 762 | stat &= ~FSL_DMA_SR_EOSI; |
740 | update_cookie = 1; | 763 | update_cookie = 1; |
741 | } | 764 | } |
@@ -830,7 +853,7 @@ static int __devinit fsl_dma_chan_probe(struct fsl_dma_device *fdev, | |||
830 | new_fsl_chan->reg.end - new_fsl_chan->reg.start + 1); | 853 | new_fsl_chan->reg.end - new_fsl_chan->reg.start + 1); |
831 | 854 | ||
832 | new_fsl_chan->id = ((new_fsl_chan->reg.start - 0x100) & 0xfff) >> 7; | 855 | new_fsl_chan->id = ((new_fsl_chan->reg.start - 0x100) & 0xfff) >> 7; |
833 | if (new_fsl_chan->id > FSL_DMA_MAX_CHANS_PER_DEVICE) { | 856 | if (new_fsl_chan->id >= FSL_DMA_MAX_CHANS_PER_DEVICE) { |
834 | dev_err(fdev->dev, "There is no %d channel!\n", | 857 | dev_err(fdev->dev, "There is no %d channel!\n", |
835 | new_fsl_chan->id); | 858 | new_fsl_chan->id); |
836 | err = -EINVAL; | 859 | err = -EINVAL; |
@@ -925,8 +948,8 @@ static int __devinit of_fsl_dma_probe(struct of_device *dev, | |||
925 | } | 948 | } |
926 | 949 | ||
927 | dev_info(&dev->dev, "Probe the Freescale DMA driver for %s " | 950 | dev_info(&dev->dev, "Probe the Freescale DMA driver for %s " |
928 | "controller at %p...\n", | 951 | "controller at 0x%llx...\n", |
929 | match->compatible, (void *)fdev->reg.start); | 952 | match->compatible, (unsigned long long)fdev->reg.start); |
930 | fdev->reg_base = ioremap(fdev->reg.start, fdev->reg.end | 953 | fdev->reg_base = ioremap(fdev->reg.start, fdev->reg.end |
931 | - fdev->reg.start + 1); | 954 | - fdev->reg.start + 1); |
932 | 955 | ||
diff --git a/drivers/dma/ioat_dma.c b/drivers/dma/ioat_dma.c index 1955ee8d6d20..a600fc0f7962 100644 --- a/drivers/dma/ioat_dma.c +++ b/drivers/dma/ioat_dma.c | |||
@@ -173,7 +173,7 @@ static int ioat_dma_enumerate_channels(struct ioatdma_device *device) | |||
173 | xfercap = (xfercap_scale == 0 ? -1 : (1UL << xfercap_scale)); | 173 | xfercap = (xfercap_scale == 0 ? -1 : (1UL << xfercap_scale)); |
174 | 174 | ||
175 | #ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL | 175 | #ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL |
176 | if (i7300_idle_platform_probe(NULL, NULL) == 0) { | 176 | if (i7300_idle_platform_probe(NULL, NULL, 1) == 0) { |
177 | device->common.chancnt--; | 177 | device->common.chancnt--; |
178 | } | 178 | } |
179 | #endif | 179 | #endif |
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig index e5f5c5a8ba6c..ab4f3592a11c 100644 --- a/drivers/edac/Kconfig +++ b/drivers/edac/Kconfig | |||
@@ -49,7 +49,6 @@ config EDAC_DEBUG_VERBOSE | |||
49 | 49 | ||
50 | config EDAC_MM_EDAC | 50 | config EDAC_MM_EDAC |
51 | tristate "Main Memory EDAC (Error Detection And Correction) reporting" | 51 | tristate "Main Memory EDAC (Error Detection And Correction) reporting" |
52 | default y | ||
53 | help | 52 | help |
54 | Some systems are able to detect and correct errors in main | 53 | Some systems are able to detect and correct errors in main |
55 | memory. EDAC can report statistics on memory error | 54 | memory. EDAC can report statistics on memory error |
@@ -58,6 +57,31 @@ config EDAC_MM_EDAC | |||
58 | occurred so that a particular failing memory module can be | 57 | occurred so that a particular failing memory module can be |
59 | replaced. If unsure, select 'Y'. | 58 | replaced. If unsure, select 'Y'. |
60 | 59 | ||
60 | config EDAC_AMD64 | ||
61 | tristate "AMD64 (Opteron, Athlon64) K8, F10h, F11h" | ||
62 | depends on EDAC_MM_EDAC && K8_NB && X86_64 && PCI | ||
63 | help | ||
64 | Support for error detection and correction on the AMD 64 | ||
65 | Families of Memory Controllers (K8, F10h and F11h) | ||
66 | |||
67 | config EDAC_AMD64_ERROR_INJECTION | ||
68 | bool "Sysfs Error Injection facilities" | ||
69 | depends on EDAC_AMD64 | ||
70 | help | ||
71 | Recent Opterons (Family 10h and later) provide for Memory Error | ||
72 | Injection into the ECC detection circuits. The amd64_edac module | ||
73 | allows the operator/user to inject Uncorrectable and Correctable | ||
74 | errors into DRAM. | ||
75 | |||
76 | When enabled, in each of the respective memory controller directories | ||
77 | (/sys/devices/system/edac/mc/mcX), there are 3 input files: | ||
78 | |||
79 | - inject_section (0..3, 16-byte section of 64-byte cacheline), | ||
80 | - inject_word (0..8, 16-bit word of 16-byte section), | ||
81 | - inject_ecc_vector (hex ecc vector: select bits of inject word) | ||
82 | |||
83 | In addition, there are two control files, inject_read and inject_write, | ||
84 | which trigger the DRAM ECC Read and Write respectively. | ||
61 | 85 | ||
62 | config EDAC_AMD76X | 86 | config EDAC_AMD76X |
63 | tristate "AMD 76x (760, 762, 768)" | 87 | tristate "AMD 76x (760, 762, 768)" |
@@ -192,16 +216,20 @@ config EDAC_PPC4XX | |||
192 | 216 | ||
193 | config EDAC_AMD8131 | 217 | config EDAC_AMD8131 |
194 | tristate "AMD8131 HyperTransport PCI-X Tunnel" | 218 | tristate "AMD8131 HyperTransport PCI-X Tunnel" |
195 | depends on EDAC_MM_EDAC && PCI | 219 | depends on EDAC_MM_EDAC && PCI && PPC_MAPLE |
196 | help | 220 | help |
197 | Support for error detection and correction on the | 221 | Support for error detection and correction on the |
198 | AMD8131 HyperTransport PCI-X Tunnel chip. | 222 | AMD8131 HyperTransport PCI-X Tunnel chip. |
223 | Note, add more Kconfig dependency if it's adopted | ||
224 | on some machine other than Maple. | ||
199 | 225 | ||
200 | config EDAC_AMD8111 | 226 | config EDAC_AMD8111 |
201 | tristate "AMD8111 HyperTransport I/O Hub" | 227 | tristate "AMD8111 HyperTransport I/O Hub" |
202 | depends on EDAC_MM_EDAC && PCI | 228 | depends on EDAC_MM_EDAC && PCI && PPC_MAPLE |
203 | help | 229 | help |
204 | Support for error detection and correction on the | 230 | Support for error detection and correction on the |
205 | AMD8111 HyperTransport I/O Hub chip. | 231 | AMD8111 HyperTransport I/O Hub chip. |
232 | Note, add more Kconfig dependency if it's adopted | ||
233 | on some machine other than Maple. | ||
206 | 234 | ||
207 | endif # EDAC | 235 | endif # EDAC |
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile index a5fdcf02f591..633dc5604ee3 100644 --- a/drivers/edac/Makefile +++ b/drivers/edac/Makefile | |||
@@ -30,8 +30,17 @@ obj-$(CONFIG_EDAC_I3000) += i3000_edac.o | |||
30 | obj-$(CONFIG_EDAC_X38) += x38_edac.o | 30 | obj-$(CONFIG_EDAC_X38) += x38_edac.o |
31 | obj-$(CONFIG_EDAC_I82860) += i82860_edac.o | 31 | obj-$(CONFIG_EDAC_I82860) += i82860_edac.o |
32 | obj-$(CONFIG_EDAC_R82600) += r82600_edac.o | 32 | obj-$(CONFIG_EDAC_R82600) += r82600_edac.o |
33 | |||
34 | amd64_edac_mod-y := amd64_edac_err_types.o amd64_edac.o | ||
35 | amd64_edac_mod-$(CONFIG_EDAC_DEBUG) += amd64_edac_dbg.o | ||
36 | amd64_edac_mod-$(CONFIG_EDAC_AMD64_ERROR_INJECTION) += amd64_edac_inj.o | ||
37 | |||
38 | obj-$(CONFIG_EDAC_AMD64) += amd64_edac_mod.o | ||
39 | |||
33 | obj-$(CONFIG_EDAC_PASEMI) += pasemi_edac.o | 40 | obj-$(CONFIG_EDAC_PASEMI) += pasemi_edac.o |
34 | obj-$(CONFIG_EDAC_MPC85XX) += mpc85xx_edac.o | 41 | obj-$(CONFIG_EDAC_MPC85XX) += mpc85xx_edac.o |
35 | obj-$(CONFIG_EDAC_MV64X60) += mv64x60_edac.o | 42 | obj-$(CONFIG_EDAC_MV64X60) += mv64x60_edac.o |
36 | obj-$(CONFIG_EDAC_CELL) += cell_edac.o | 43 | obj-$(CONFIG_EDAC_CELL) += cell_edac.o |
37 | obj-$(CONFIG_EDAC_PPC4XX) += ppc4xx_edac.o | 44 | obj-$(CONFIG_EDAC_PPC4XX) += ppc4xx_edac.o |
45 | obj-$(CONFIG_EDAC_AMD8111) += amd8111_edac.o | ||
46 | obj-$(CONFIG_EDAC_AMD8131) += amd8131_edac.o | ||
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c new file mode 100644 index 000000000000..c36bf40568cf --- /dev/null +++ b/drivers/edac/amd64_edac.c | |||
@@ -0,0 +1,3354 @@ | |||
1 | #include "amd64_edac.h" | ||
2 | #include <asm/k8.h> | ||
3 | |||
4 | static struct edac_pci_ctl_info *amd64_ctl_pci; | ||
5 | |||
6 | static int report_gart_errors; | ||
7 | module_param(report_gart_errors, int, 0644); | ||
8 | |||
9 | /* | ||
10 | * Set by command line parameter. If BIOS has enabled the ECC, this override is | ||
11 | * cleared to prevent re-enabling the hardware by this driver. | ||
12 | */ | ||
13 | static int ecc_enable_override; | ||
14 | module_param(ecc_enable_override, int, 0644); | ||
15 | |||
16 | /* Lookup table for all possible MC control instances */ | ||
17 | struct amd64_pvt; | ||
18 | static struct mem_ctl_info *mci_lookup[MAX_NUMNODES]; | ||
19 | static struct amd64_pvt *pvt_lookup[MAX_NUMNODES]; | ||
20 | |||
21 | /* | ||
22 | * Memory scrubber control interface. For K8, memory scrubbing is handled by | ||
23 | * hardware and can involve L2 cache, dcache as well as the main memory. With | ||
24 | * F10, this is extended to L3 cache scrubbing on CPU models sporting that | ||
25 | * functionality. | ||
26 | * | ||
27 | * This causes the "units" for the scrubbing speed to vary from 64 byte blocks | ||
28 | * (dram) over to cache lines. This is nasty, so we will use bandwidth in | ||
29 | * bytes/sec for the setting. | ||
30 | * | ||
31 | * Currently, we only do dram scrubbing. If the scrubbing is done in software on | ||
32 | * other archs, we might not have access to the caches directly. | ||
33 | */ | ||
34 | |||
35 | /* | ||
36 | * scan the scrub rate mapping table for a close or matching bandwidth value to | ||
37 | * issue. If requested is too big, then use last maximum value found. | ||
38 | */ | ||
39 | static int amd64_search_set_scrub_rate(struct pci_dev *ctl, u32 new_bw, | ||
40 | u32 min_scrubrate) | ||
41 | { | ||
42 | u32 scrubval; | ||
43 | int i; | ||
44 | |||
45 | /* | ||
46 | * map the configured rate (new_bw) to a value specific to the AMD64 | ||
47 | * memory controller and apply to register. Search for the first | ||
48 | * bandwidth entry that is greater or equal than the setting requested | ||
49 | * and program that. If at last entry, turn off DRAM scrubbing. | ||
50 | */ | ||
51 | for (i = 0; i < ARRAY_SIZE(scrubrates); i++) { | ||
52 | /* | ||
53 | * skip scrub rates which aren't recommended | ||
54 | * (see F10 BKDG, F3x58) | ||
55 | */ | ||
56 | if (scrubrates[i].scrubval < min_scrubrate) | ||
57 | continue; | ||
58 | |||
59 | if (scrubrates[i].bandwidth <= new_bw) | ||
60 | break; | ||
61 | |||
62 | /* | ||
63 | * if no suitable bandwidth found, turn off DRAM scrubbing | ||
64 | * entirely by falling back to the last element in the | ||
65 | * scrubrates array. | ||
66 | */ | ||
67 | } | ||
68 | |||
69 | scrubval = scrubrates[i].scrubval; | ||
70 | if (scrubval) | ||
71 | edac_printk(KERN_DEBUG, EDAC_MC, | ||
72 | "Setting scrub rate bandwidth: %u\n", | ||
73 | scrubrates[i].bandwidth); | ||
74 | else | ||
75 | edac_printk(KERN_DEBUG, EDAC_MC, "Turning scrubbing off.\n"); | ||
76 | |||
77 | pci_write_bits32(ctl, K8_SCRCTRL, scrubval, 0x001F); | ||
78 | |||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | static int amd64_set_scrub_rate(struct mem_ctl_info *mci, u32 *bandwidth) | ||
83 | { | ||
84 | struct amd64_pvt *pvt = mci->pvt_info; | ||
85 | u32 min_scrubrate = 0x0; | ||
86 | |||
87 | switch (boot_cpu_data.x86) { | ||
88 | case 0xf: | ||
89 | min_scrubrate = K8_MIN_SCRUB_RATE_BITS; | ||
90 | break; | ||
91 | case 0x10: | ||
92 | min_scrubrate = F10_MIN_SCRUB_RATE_BITS; | ||
93 | break; | ||
94 | case 0x11: | ||
95 | min_scrubrate = F11_MIN_SCRUB_RATE_BITS; | ||
96 | break; | ||
97 | |||
98 | default: | ||
99 | amd64_printk(KERN_ERR, "Unsupported family!\n"); | ||
100 | break; | ||
101 | } | ||
102 | return amd64_search_set_scrub_rate(pvt->misc_f3_ctl, *bandwidth, | ||
103 | min_scrubrate); | ||
104 | } | ||
105 | |||
106 | static int amd64_get_scrub_rate(struct mem_ctl_info *mci, u32 *bw) | ||
107 | { | ||
108 | struct amd64_pvt *pvt = mci->pvt_info; | ||
109 | u32 scrubval = 0; | ||
110 | int status = -1, i, ret = 0; | ||
111 | |||
112 | ret = pci_read_config_dword(pvt->misc_f3_ctl, K8_SCRCTRL, &scrubval); | ||
113 | if (ret) | ||
114 | debugf0("Reading K8_SCRCTRL failed\n"); | ||
115 | |||
116 | scrubval = scrubval & 0x001F; | ||
117 | |||
118 | edac_printk(KERN_DEBUG, EDAC_MC, | ||
119 | "pci-read, sdram scrub control value: %d \n", scrubval); | ||
120 | |||
121 | for (i = 0; ARRAY_SIZE(scrubrates); i++) { | ||
122 | if (scrubrates[i].scrubval == scrubval) { | ||
123 | *bw = scrubrates[i].bandwidth; | ||
124 | status = 0; | ||
125 | break; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | return status; | ||
130 | } | ||
131 | |||
132 | /* Map from a CSROW entry to the mask entry that operates on it */ | ||
133 | static inline u32 amd64_map_to_dcs_mask(struct amd64_pvt *pvt, int csrow) | ||
134 | { | ||
135 | return csrow >> (pvt->num_dcsm >> 3); | ||
136 | } | ||
137 | |||
138 | /* return the 'base' address the i'th CS entry of the 'dct' DRAM controller */ | ||
139 | static u32 amd64_get_dct_base(struct amd64_pvt *pvt, int dct, int csrow) | ||
140 | { | ||
141 | if (dct == 0) | ||
142 | return pvt->dcsb0[csrow]; | ||
143 | else | ||
144 | return pvt->dcsb1[csrow]; | ||
145 | } | ||
146 | |||
147 | /* | ||
148 | * Return the 'mask' address the i'th CS entry. This function is needed because | ||
149 | * there number of DCSM registers on Rev E and prior vs Rev F and later is | ||
150 | * different. | ||
151 | */ | ||
152 | static u32 amd64_get_dct_mask(struct amd64_pvt *pvt, int dct, int csrow) | ||
153 | { | ||
154 | if (dct == 0) | ||
155 | return pvt->dcsm0[amd64_map_to_dcs_mask(pvt, csrow)]; | ||
156 | else | ||
157 | return pvt->dcsm1[amd64_map_to_dcs_mask(pvt, csrow)]; | ||
158 | } | ||
159 | |||
160 | |||
161 | /* | ||
162 | * In *base and *limit, pass back the full 40-bit base and limit physical | ||
163 | * addresses for the node given by node_id. This information is obtained from | ||
164 | * DRAM Base (section 3.4.4.1) and DRAM Limit (section 3.4.4.2) registers. The | ||
165 | * base and limit addresses are of type SysAddr, as defined at the start of | ||
166 | * section 3.4.4 (p. 70). They are the lowest and highest physical addresses | ||
167 | * in the address range they represent. | ||
168 | */ | ||
169 | static void amd64_get_base_and_limit(struct amd64_pvt *pvt, int node_id, | ||
170 | u64 *base, u64 *limit) | ||
171 | { | ||
172 | *base = pvt->dram_base[node_id]; | ||
173 | *limit = pvt->dram_limit[node_id]; | ||
174 | } | ||
175 | |||
176 | /* | ||
177 | * Return 1 if the SysAddr given by sys_addr matches the base/limit associated | ||
178 | * with node_id | ||
179 | */ | ||
180 | static int amd64_base_limit_match(struct amd64_pvt *pvt, | ||
181 | u64 sys_addr, int node_id) | ||
182 | { | ||
183 | u64 base, limit, addr; | ||
184 | |||
185 | amd64_get_base_and_limit(pvt, node_id, &base, &limit); | ||
186 | |||
187 | /* The K8 treats this as a 40-bit value. However, bits 63-40 will be | ||
188 | * all ones if the most significant implemented address bit is 1. | ||
189 | * Here we discard bits 63-40. See section 3.4.2 of AMD publication | ||
190 | * 24592: AMD x86-64 Architecture Programmer's Manual Volume 1 | ||
191 | * Application Programming. | ||
192 | */ | ||
193 | addr = sys_addr & 0x000000ffffffffffull; | ||
194 | |||
195 | return (addr >= base) && (addr <= limit); | ||
196 | } | ||
197 | |||
198 | /* | ||
199 | * Attempt to map a SysAddr to a node. On success, return a pointer to the | ||
200 | * mem_ctl_info structure for the node that the SysAddr maps to. | ||
201 | * | ||
202 | * On failure, return NULL. | ||
203 | */ | ||
204 | static struct mem_ctl_info *find_mc_by_sys_addr(struct mem_ctl_info *mci, | ||
205 | u64 sys_addr) | ||
206 | { | ||
207 | struct amd64_pvt *pvt; | ||
208 | int node_id; | ||
209 | u32 intlv_en, bits; | ||
210 | |||
211 | /* | ||
212 | * Here we use the DRAM Base (section 3.4.4.1) and DRAM Limit (section | ||
213 | * 3.4.4.2) registers to map the SysAddr to a node ID. | ||
214 | */ | ||
215 | pvt = mci->pvt_info; | ||
216 | |||
217 | /* | ||
218 | * The value of this field should be the same for all DRAM Base | ||
219 | * registers. Therefore we arbitrarily choose to read it from the | ||
220 | * register for node 0. | ||
221 | */ | ||
222 | intlv_en = pvt->dram_IntlvEn[0]; | ||
223 | |||
224 | if (intlv_en == 0) { | ||
225 | for (node_id = 0; ; ) { | ||
226 | if (amd64_base_limit_match(pvt, sys_addr, node_id)) | ||
227 | break; | ||
228 | |||
229 | if (++node_id >= DRAM_REG_COUNT) | ||
230 | goto err_no_match; | ||
231 | } | ||
232 | goto found; | ||
233 | } | ||
234 | |||
235 | if (unlikely((intlv_en != (0x01 << 8)) && | ||
236 | (intlv_en != (0x03 << 8)) && | ||
237 | (intlv_en != (0x07 << 8)))) { | ||
238 | amd64_printk(KERN_WARNING, "junk value of 0x%x extracted from " | ||
239 | "IntlvEn field of DRAM Base Register for node 0: " | ||
240 | "This probably indicates a BIOS bug.\n", intlv_en); | ||
241 | return NULL; | ||
242 | } | ||
243 | |||
244 | bits = (((u32) sys_addr) >> 12) & intlv_en; | ||
245 | |||
246 | for (node_id = 0; ; ) { | ||
247 | if ((pvt->dram_limit[node_id] & intlv_en) == bits) | ||
248 | break; /* intlv_sel field matches */ | ||
249 | |||
250 | if (++node_id >= DRAM_REG_COUNT) | ||
251 | goto err_no_match; | ||
252 | } | ||
253 | |||
254 | /* sanity test for sys_addr */ | ||
255 | if (unlikely(!amd64_base_limit_match(pvt, sys_addr, node_id))) { | ||
256 | amd64_printk(KERN_WARNING, | ||
257 | "%s(): sys_addr 0x%lx falls outside base/limit " | ||
258 | "address range for node %d with node interleaving " | ||
259 | "enabled.\n", __func__, (unsigned long)sys_addr, | ||
260 | node_id); | ||
261 | return NULL; | ||
262 | } | ||
263 | |||
264 | found: | ||
265 | return edac_mc_find(node_id); | ||
266 | |||
267 | err_no_match: | ||
268 | debugf2("sys_addr 0x%lx doesn't match any node\n", | ||
269 | (unsigned long)sys_addr); | ||
270 | |||
271 | return NULL; | ||
272 | } | ||
273 | |||
274 | /* | ||
275 | * Extract the DRAM CS base address from selected csrow register. | ||
276 | */ | ||
277 | static u64 base_from_dct_base(struct amd64_pvt *pvt, int csrow) | ||
278 | { | ||
279 | return ((u64) (amd64_get_dct_base(pvt, 0, csrow) & pvt->dcsb_base)) << | ||
280 | pvt->dcs_shift; | ||
281 | } | ||
282 | |||
283 | /* | ||
284 | * Extract the mask from the dcsb0[csrow] entry in a CPU revision-specific way. | ||
285 | */ | ||
286 | static u64 mask_from_dct_mask(struct amd64_pvt *pvt, int csrow) | ||
287 | { | ||
288 | u64 dcsm_bits, other_bits; | ||
289 | u64 mask; | ||
290 | |||
291 | /* Extract bits from DRAM CS Mask. */ | ||
292 | dcsm_bits = amd64_get_dct_mask(pvt, 0, csrow) & pvt->dcsm_mask; | ||
293 | |||
294 | other_bits = pvt->dcsm_mask; | ||
295 | other_bits = ~(other_bits << pvt->dcs_shift); | ||
296 | |||
297 | /* | ||
298 | * The extracted bits from DCSM belong in the spaces represented by | ||
299 | * the cleared bits in other_bits. | ||
300 | */ | ||
301 | mask = (dcsm_bits << pvt->dcs_shift) | other_bits; | ||
302 | |||
303 | return mask; | ||
304 | } | ||
305 | |||
306 | /* | ||
307 | * @input_addr is an InputAddr associated with the node given by mci. Return the | ||
308 | * csrow that input_addr maps to, or -1 on failure (no csrow claims input_addr). | ||
309 | */ | ||
310 | static int input_addr_to_csrow(struct mem_ctl_info *mci, u64 input_addr) | ||
311 | { | ||
312 | struct amd64_pvt *pvt; | ||
313 | int csrow; | ||
314 | u64 base, mask; | ||
315 | |||
316 | pvt = mci->pvt_info; | ||
317 | |||
318 | /* | ||
319 | * Here we use the DRAM CS Base and DRAM CS Mask registers. For each CS | ||
320 | * base/mask register pair, test the condition shown near the start of | ||
321 | * section 3.5.4 (p. 84, BKDG #26094, K8, revA-E). | ||
322 | */ | ||
323 | for (csrow = 0; csrow < CHIPSELECT_COUNT; csrow++) { | ||
324 | |||
325 | /* This DRAM chip select is disabled on this node */ | ||
326 | if ((pvt->dcsb0[csrow] & K8_DCSB_CS_ENABLE) == 0) | ||
327 | continue; | ||
328 | |||
329 | base = base_from_dct_base(pvt, csrow); | ||
330 | mask = ~mask_from_dct_mask(pvt, csrow); | ||
331 | |||
332 | if ((input_addr & mask) == (base & mask)) { | ||
333 | debugf2("InputAddr 0x%lx matches csrow %d (node %d)\n", | ||
334 | (unsigned long)input_addr, csrow, | ||
335 | pvt->mc_node_id); | ||
336 | |||
337 | return csrow; | ||
338 | } | ||
339 | } | ||
340 | |||
341 | debugf2("no matching csrow for InputAddr 0x%lx (MC node %d)\n", | ||
342 | (unsigned long)input_addr, pvt->mc_node_id); | ||
343 | |||
344 | return -1; | ||
345 | } | ||
346 | |||
347 | /* | ||
348 | * Return the base value defined by the DRAM Base register for the node | ||
349 | * represented by mci. This function returns the full 40-bit value despite the | ||
350 | * fact that the register only stores bits 39-24 of the value. See section | ||
351 | * 3.4.4.1 (BKDG #26094, K8, revA-E) | ||
352 | */ | ||
353 | static inline u64 get_dram_base(struct mem_ctl_info *mci) | ||
354 | { | ||
355 | struct amd64_pvt *pvt = mci->pvt_info; | ||
356 | |||
357 | return pvt->dram_base[pvt->mc_node_id]; | ||
358 | } | ||
359 | |||
360 | /* | ||
361 | * Obtain info from the DRAM Hole Address Register (section 3.4.8, pub #26094) | ||
362 | * for the node represented by mci. Info is passed back in *hole_base, | ||
363 | * *hole_offset, and *hole_size. Function returns 0 if info is valid or 1 if | ||
364 | * info is invalid. Info may be invalid for either of the following reasons: | ||
365 | * | ||
366 | * - The revision of the node is not E or greater. In this case, the DRAM Hole | ||
367 | * Address Register does not exist. | ||
368 | * | ||
369 | * - The DramHoleValid bit is cleared in the DRAM Hole Address Register, | ||
370 | * indicating that its contents are not valid. | ||
371 | * | ||
372 | * The values passed back in *hole_base, *hole_offset, and *hole_size are | ||
373 | * complete 32-bit values despite the fact that the bitfields in the DHAR | ||
374 | * only represent bits 31-24 of the base and offset values. | ||
375 | */ | ||
376 | int amd64_get_dram_hole_info(struct mem_ctl_info *mci, u64 *hole_base, | ||
377 | u64 *hole_offset, u64 *hole_size) | ||
378 | { | ||
379 | struct amd64_pvt *pvt = mci->pvt_info; | ||
380 | u64 base; | ||
381 | |||
382 | /* only revE and later have the DRAM Hole Address Register */ | ||
383 | if (boot_cpu_data.x86 == 0xf && pvt->ext_model < OPTERON_CPU_REV_E) { | ||
384 | debugf1(" revision %d for node %d does not support DHAR\n", | ||
385 | pvt->ext_model, pvt->mc_node_id); | ||
386 | return 1; | ||
387 | } | ||
388 | |||
389 | /* only valid for Fam10h */ | ||
390 | if (boot_cpu_data.x86 == 0x10 && | ||
391 | (pvt->dhar & F10_DRAM_MEM_HOIST_VALID) == 0) { | ||
392 | debugf1(" Dram Memory Hoisting is DISABLED on this system\n"); | ||
393 | return 1; | ||
394 | } | ||
395 | |||
396 | if ((pvt->dhar & DHAR_VALID) == 0) { | ||
397 | debugf1(" Dram Memory Hoisting is DISABLED on this node %d\n", | ||
398 | pvt->mc_node_id); | ||
399 | return 1; | ||
400 | } | ||
401 | |||
402 | /* This node has Memory Hoisting */ | ||
403 | |||
404 | /* +------------------+--------------------+--------------------+----- | ||
405 | * | memory | DRAM hole | relocated | | ||
406 | * | [0, (x - 1)] | [x, 0xffffffff] | addresses from | | ||
407 | * | | | DRAM hole | | ||
408 | * | | | [0x100000000, | | ||
409 | * | | | (0x100000000+ | | ||
410 | * | | | (0xffffffff-x))] | | ||
411 | * +------------------+--------------------+--------------------+----- | ||
412 | * | ||
413 | * Above is a diagram of physical memory showing the DRAM hole and the | ||
414 | * relocated addresses from the DRAM hole. As shown, the DRAM hole | ||
415 | * starts at address x (the base address) and extends through address | ||
416 | * 0xffffffff. The DRAM Hole Address Register (DHAR) relocates the | ||
417 | * addresses in the hole so that they start at 0x100000000. | ||
418 | */ | ||
419 | |||
420 | base = dhar_base(pvt->dhar); | ||
421 | |||
422 | *hole_base = base; | ||
423 | *hole_size = (0x1ull << 32) - base; | ||
424 | |||
425 | if (boot_cpu_data.x86 > 0xf) | ||
426 | *hole_offset = f10_dhar_offset(pvt->dhar); | ||
427 | else | ||
428 | *hole_offset = k8_dhar_offset(pvt->dhar); | ||
429 | |||
430 | debugf1(" DHAR info for node %d base 0x%lx offset 0x%lx size 0x%lx\n", | ||
431 | pvt->mc_node_id, (unsigned long)*hole_base, | ||
432 | (unsigned long)*hole_offset, (unsigned long)*hole_size); | ||
433 | |||
434 | return 0; | ||
435 | } | ||
436 | EXPORT_SYMBOL_GPL(amd64_get_dram_hole_info); | ||
437 | |||
438 | /* | ||
439 | * Return the DramAddr that the SysAddr given by @sys_addr maps to. It is | ||
440 | * assumed that sys_addr maps to the node given by mci. | ||
441 | * | ||
442 | * The first part of section 3.4.4 (p. 70) shows how the DRAM Base (section | ||
443 | * 3.4.4.1) and DRAM Limit (section 3.4.4.2) registers are used to translate a | ||
444 | * SysAddr to a DramAddr. If the DRAM Hole Address Register (DHAR) is enabled, | ||
445 | * then it is also involved in translating a SysAddr to a DramAddr. Sections | ||
446 | * 3.4.8 and 3.5.8.2 describe the DHAR and how it is used for memory hoisting. | ||
447 | * These parts of the documentation are unclear. I interpret them as follows: | ||
448 | * | ||
449 | * When node n receives a SysAddr, it processes the SysAddr as follows: | ||
450 | * | ||
451 | * 1. It extracts the DRAMBase and DRAMLimit values from the DRAM Base and DRAM | ||
452 | * Limit registers for node n. If the SysAddr is not within the range | ||
453 | * specified by the base and limit values, then node n ignores the Sysaddr | ||
454 | * (since it does not map to node n). Otherwise continue to step 2 below. | ||
455 | * | ||
456 | * 2. If the DramHoleValid bit of the DHAR for node n is clear, the DHAR is | ||
457 | * disabled so skip to step 3 below. Otherwise see if the SysAddr is within | ||
458 | * the range of relocated addresses (starting at 0x100000000) from the DRAM | ||
459 | * hole. If not, skip to step 3 below. Else get the value of the | ||
460 | * DramHoleOffset field from the DHAR. To obtain the DramAddr, subtract the | ||
461 | * offset defined by this value from the SysAddr. | ||
462 | * | ||
463 | * 3. Obtain the base address for node n from the DRAMBase field of the DRAM | ||
464 | * Base register for node n. To obtain the DramAddr, subtract the base | ||
465 | * address from the SysAddr, as shown near the start of section 3.4.4 (p.70). | ||
466 | */ | ||
467 | static u64 sys_addr_to_dram_addr(struct mem_ctl_info *mci, u64 sys_addr) | ||
468 | { | ||
469 | u64 dram_base, hole_base, hole_offset, hole_size, dram_addr; | ||
470 | int ret = 0; | ||
471 | |||
472 | dram_base = get_dram_base(mci); | ||
473 | |||
474 | ret = amd64_get_dram_hole_info(mci, &hole_base, &hole_offset, | ||
475 | &hole_size); | ||
476 | if (!ret) { | ||
477 | if ((sys_addr >= (1ull << 32)) && | ||
478 | (sys_addr < ((1ull << 32) + hole_size))) { | ||
479 | /* use DHAR to translate SysAddr to DramAddr */ | ||
480 | dram_addr = sys_addr - hole_offset; | ||
481 | |||
482 | debugf2("using DHAR to translate SysAddr 0x%lx to " | ||
483 | "DramAddr 0x%lx\n", | ||
484 | (unsigned long)sys_addr, | ||
485 | (unsigned long)dram_addr); | ||
486 | |||
487 | return dram_addr; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | /* | ||
492 | * Translate the SysAddr to a DramAddr as shown near the start of | ||
493 | * section 3.4.4 (p. 70). Although sys_addr is a 64-bit value, the k8 | ||
494 | * only deals with 40-bit values. Therefore we discard bits 63-40 of | ||
495 | * sys_addr below. If bit 39 of sys_addr is 1 then the bits we | ||
496 | * discard are all 1s. Otherwise the bits we discard are all 0s. See | ||
497 | * section 3.4.2 of AMD publication 24592: AMD x86-64 Architecture | ||
498 | * Programmer's Manual Volume 1 Application Programming. | ||
499 | */ | ||
500 | dram_addr = (sys_addr & 0xffffffffffull) - dram_base; | ||
501 | |||
502 | debugf2("using DRAM Base register to translate SysAddr 0x%lx to " | ||
503 | "DramAddr 0x%lx\n", (unsigned long)sys_addr, | ||
504 | (unsigned long)dram_addr); | ||
505 | return dram_addr; | ||
506 | } | ||
507 | |||
508 | /* | ||
509 | * @intlv_en is the value of the IntlvEn field from a DRAM Base register | ||
510 | * (section 3.4.4.1). Return the number of bits from a SysAddr that are used | ||
511 | * for node interleaving. | ||
512 | */ | ||
513 | static int num_node_interleave_bits(unsigned intlv_en) | ||
514 | { | ||
515 | static const int intlv_shift_table[] = { 0, 1, 0, 2, 0, 0, 0, 3 }; | ||
516 | int n; | ||
517 | |||
518 | BUG_ON(intlv_en > 7); | ||
519 | n = intlv_shift_table[intlv_en]; | ||
520 | return n; | ||
521 | } | ||
522 | |||
523 | /* Translate the DramAddr given by @dram_addr to an InputAddr. */ | ||
524 | static u64 dram_addr_to_input_addr(struct mem_ctl_info *mci, u64 dram_addr) | ||
525 | { | ||
526 | struct amd64_pvt *pvt; | ||
527 | int intlv_shift; | ||
528 | u64 input_addr; | ||
529 | |||
530 | pvt = mci->pvt_info; | ||
531 | |||
532 | /* | ||
533 | * See the start of section 3.4.4 (p. 70, BKDG #26094, K8, revA-E) | ||
534 | * concerning translating a DramAddr to an InputAddr. | ||
535 | */ | ||
536 | intlv_shift = num_node_interleave_bits(pvt->dram_IntlvEn[0]); | ||
537 | input_addr = ((dram_addr >> intlv_shift) & 0xffffff000ull) + | ||
538 | (dram_addr & 0xfff); | ||
539 | |||
540 | debugf2(" Intlv Shift=%d DramAddr=0x%lx maps to InputAddr=0x%lx\n", | ||
541 | intlv_shift, (unsigned long)dram_addr, | ||
542 | (unsigned long)input_addr); | ||
543 | |||
544 | return input_addr; | ||
545 | } | ||
546 | |||
547 | /* | ||
548 | * Translate the SysAddr represented by @sys_addr to an InputAddr. It is | ||
549 | * assumed that @sys_addr maps to the node given by mci. | ||
550 | */ | ||
551 | static u64 sys_addr_to_input_addr(struct mem_ctl_info *mci, u64 sys_addr) | ||
552 | { | ||
553 | u64 input_addr; | ||
554 | |||
555 | input_addr = | ||
556 | dram_addr_to_input_addr(mci, sys_addr_to_dram_addr(mci, sys_addr)); | ||
557 | |||
558 | debugf2("SysAdddr 0x%lx translates to InputAddr 0x%lx\n", | ||
559 | (unsigned long)sys_addr, (unsigned long)input_addr); | ||
560 | |||
561 | return input_addr; | ||
562 | } | ||
563 | |||
564 | |||
565 | /* | ||
566 | * @input_addr is an InputAddr associated with the node represented by mci. | ||
567 | * Translate @input_addr to a DramAddr and return the result. | ||
568 | */ | ||
569 | static u64 input_addr_to_dram_addr(struct mem_ctl_info *mci, u64 input_addr) | ||
570 | { | ||
571 | struct amd64_pvt *pvt; | ||
572 | int node_id, intlv_shift; | ||
573 | u64 bits, dram_addr; | ||
574 | u32 intlv_sel; | ||
575 | |||
576 | /* | ||
577 | * Near the start of section 3.4.4 (p. 70, BKDG #26094, K8, revA-E) | ||
578 | * shows how to translate a DramAddr to an InputAddr. Here we reverse | ||
579 | * this procedure. When translating from a DramAddr to an InputAddr, the | ||
580 | * bits used for node interleaving are discarded. Here we recover these | ||
581 | * bits from the IntlvSel field of the DRAM Limit register (section | ||
582 | * 3.4.4.2) for the node that input_addr is associated with. | ||
583 | */ | ||
584 | pvt = mci->pvt_info; | ||
585 | node_id = pvt->mc_node_id; | ||
586 | BUG_ON((node_id < 0) || (node_id > 7)); | ||
587 | |||
588 | intlv_shift = num_node_interleave_bits(pvt->dram_IntlvEn[0]); | ||
589 | |||
590 | if (intlv_shift == 0) { | ||
591 | debugf1(" InputAddr 0x%lx translates to DramAddr of " | ||
592 | "same value\n", (unsigned long)input_addr); | ||
593 | |||
594 | return input_addr; | ||
595 | } | ||
596 | |||
597 | bits = ((input_addr & 0xffffff000ull) << intlv_shift) + | ||
598 | (input_addr & 0xfff); | ||
599 | |||
600 | intlv_sel = pvt->dram_IntlvSel[node_id] & ((1 << intlv_shift) - 1); | ||
601 | dram_addr = bits + (intlv_sel << 12); | ||
602 | |||
603 | debugf1("InputAddr 0x%lx translates to DramAddr 0x%lx " | ||
604 | "(%d node interleave bits)\n", (unsigned long)input_addr, | ||
605 | (unsigned long)dram_addr, intlv_shift); | ||
606 | |||
607 | return dram_addr; | ||
608 | } | ||
609 | |||
610 | /* | ||
611 | * @dram_addr is a DramAddr that maps to the node represented by mci. Convert | ||
612 | * @dram_addr to a SysAddr. | ||
613 | */ | ||
614 | static u64 dram_addr_to_sys_addr(struct mem_ctl_info *mci, u64 dram_addr) | ||
615 | { | ||
616 | struct amd64_pvt *pvt = mci->pvt_info; | ||
617 | u64 hole_base, hole_offset, hole_size, base, limit, sys_addr; | ||
618 | int ret = 0; | ||
619 | |||
620 | ret = amd64_get_dram_hole_info(mci, &hole_base, &hole_offset, | ||
621 | &hole_size); | ||
622 | if (!ret) { | ||
623 | if ((dram_addr >= hole_base) && | ||
624 | (dram_addr < (hole_base + hole_size))) { | ||
625 | sys_addr = dram_addr + hole_offset; | ||
626 | |||
627 | debugf1("using DHAR to translate DramAddr 0x%lx to " | ||
628 | "SysAddr 0x%lx\n", (unsigned long)dram_addr, | ||
629 | (unsigned long)sys_addr); | ||
630 | |||
631 | return sys_addr; | ||
632 | } | ||
633 | } | ||
634 | |||
635 | amd64_get_base_and_limit(pvt, pvt->mc_node_id, &base, &limit); | ||
636 | sys_addr = dram_addr + base; | ||
637 | |||
638 | /* | ||
639 | * The sys_addr we have computed up to this point is a 40-bit value | ||
640 | * because the k8 deals with 40-bit values. However, the value we are | ||
641 | * supposed to return is a full 64-bit physical address. The AMD | ||
642 | * x86-64 architecture specifies that the most significant implemented | ||
643 | * address bit through bit 63 of a physical address must be either all | ||
644 | * 0s or all 1s. Therefore we sign-extend the 40-bit sys_addr to a | ||
645 | * 64-bit value below. See section 3.4.2 of AMD publication 24592: | ||
646 | * AMD x86-64 Architecture Programmer's Manual Volume 1 Application | ||
647 | * Programming. | ||
648 | */ | ||
649 | sys_addr |= ~((sys_addr & (1ull << 39)) - 1); | ||
650 | |||
651 | debugf1(" Node %d, DramAddr 0x%lx to SysAddr 0x%lx\n", | ||
652 | pvt->mc_node_id, (unsigned long)dram_addr, | ||
653 | (unsigned long)sys_addr); | ||
654 | |||
655 | return sys_addr; | ||
656 | } | ||
657 | |||
658 | /* | ||
659 | * @input_addr is an InputAddr associated with the node given by mci. Translate | ||
660 | * @input_addr to a SysAddr. | ||
661 | */ | ||
662 | static inline u64 input_addr_to_sys_addr(struct mem_ctl_info *mci, | ||
663 | u64 input_addr) | ||
664 | { | ||
665 | return dram_addr_to_sys_addr(mci, | ||
666 | input_addr_to_dram_addr(mci, input_addr)); | ||
667 | } | ||
668 | |||
669 | /* | ||
670 | * Find the minimum and maximum InputAddr values that map to the given @csrow. | ||
671 | * Pass back these values in *input_addr_min and *input_addr_max. | ||
672 | */ | ||
673 | static void find_csrow_limits(struct mem_ctl_info *mci, int csrow, | ||
674 | u64 *input_addr_min, u64 *input_addr_max) | ||
675 | { | ||
676 | struct amd64_pvt *pvt; | ||
677 | u64 base, mask; | ||
678 | |||
679 | pvt = mci->pvt_info; | ||
680 | BUG_ON((csrow < 0) || (csrow >= CHIPSELECT_COUNT)); | ||
681 | |||
682 | base = base_from_dct_base(pvt, csrow); | ||
683 | mask = mask_from_dct_mask(pvt, csrow); | ||
684 | |||
685 | *input_addr_min = base & ~mask; | ||
686 | *input_addr_max = base | mask | pvt->dcs_mask_notused; | ||
687 | } | ||
688 | |||
689 | /* | ||
690 | * Extract error address from MCA NB Address Low (section 3.6.4.5) and MCA NB | ||
691 | * Address High (section 3.6.4.6) register values and return the result. Address | ||
692 | * is located in the info structure (nbeah and nbeal), the encoding is device | ||
693 | * specific. | ||
694 | */ | ||
695 | static u64 extract_error_address(struct mem_ctl_info *mci, | ||
696 | struct amd64_error_info_regs *info) | ||
697 | { | ||
698 | struct amd64_pvt *pvt = mci->pvt_info; | ||
699 | |||
700 | return pvt->ops->get_error_address(mci, info); | ||
701 | } | ||
702 | |||
703 | |||
704 | /* Map the Error address to a PAGE and PAGE OFFSET. */ | ||
705 | static inline void error_address_to_page_and_offset(u64 error_address, | ||
706 | u32 *page, u32 *offset) | ||
707 | { | ||
708 | *page = (u32) (error_address >> PAGE_SHIFT); | ||
709 | *offset = ((u32) error_address) & ~PAGE_MASK; | ||
710 | } | ||
711 | |||
712 | /* | ||
713 | * @sys_addr is an error address (a SysAddr) extracted from the MCA NB Address | ||
714 | * Low (section 3.6.4.5) and MCA NB Address High (section 3.6.4.6) registers | ||
715 | * of a node that detected an ECC memory error. mci represents the node that | ||
716 | * the error address maps to (possibly different from the node that detected | ||
717 | * the error). Return the number of the csrow that sys_addr maps to, or -1 on | ||
718 | * error. | ||
719 | */ | ||
720 | static int sys_addr_to_csrow(struct mem_ctl_info *mci, u64 sys_addr) | ||
721 | { | ||
722 | int csrow; | ||
723 | |||
724 | csrow = input_addr_to_csrow(mci, sys_addr_to_input_addr(mci, sys_addr)); | ||
725 | |||
726 | if (csrow == -1) | ||
727 | amd64_mc_printk(mci, KERN_ERR, | ||
728 | "Failed to translate InputAddr to csrow for " | ||
729 | "address 0x%lx\n", (unsigned long)sys_addr); | ||
730 | return csrow; | ||
731 | } | ||
732 | |||
733 | static int get_channel_from_ecc_syndrome(unsigned short syndrome); | ||
734 | |||
735 | static void amd64_cpu_display_info(struct amd64_pvt *pvt) | ||
736 | { | ||
737 | if (boot_cpu_data.x86 == 0x11) | ||
738 | edac_printk(KERN_DEBUG, EDAC_MC, "F11h CPU detected\n"); | ||
739 | else if (boot_cpu_data.x86 == 0x10) | ||
740 | edac_printk(KERN_DEBUG, EDAC_MC, "F10h CPU detected\n"); | ||
741 | else if (boot_cpu_data.x86 == 0xf) | ||
742 | edac_printk(KERN_DEBUG, EDAC_MC, "%s detected\n", | ||
743 | (pvt->ext_model >= OPTERON_CPU_REV_F) ? | ||
744 | "Rev F or later" : "Rev E or earlier"); | ||
745 | else | ||
746 | /* we'll hardly ever ever get here */ | ||
747 | edac_printk(KERN_ERR, EDAC_MC, "Unknown cpu!\n"); | ||
748 | } | ||
749 | |||
750 | /* | ||
751 | * Determine if the DIMMs have ECC enabled. ECC is enabled ONLY if all the DIMMs | ||
752 | * are ECC capable. | ||
753 | */ | ||
754 | static enum edac_type amd64_determine_edac_cap(struct amd64_pvt *pvt) | ||
755 | { | ||
756 | int bit; | ||
757 | enum dev_type edac_cap = EDAC_NONE; | ||
758 | |||
759 | bit = (boot_cpu_data.x86 > 0xf || pvt->ext_model >= OPTERON_CPU_REV_F) | ||
760 | ? 19 | ||
761 | : 17; | ||
762 | |||
763 | if (pvt->dclr0 >> BIT(bit)) | ||
764 | edac_cap = EDAC_FLAG_SECDED; | ||
765 | |||
766 | return edac_cap; | ||
767 | } | ||
768 | |||
769 | |||
770 | static void f10_debug_display_dimm_sizes(int ctrl, struct amd64_pvt *pvt, | ||
771 | int ganged); | ||
772 | |||
773 | /* Display and decode various NB registers for debug purposes. */ | ||
774 | static void amd64_dump_misc_regs(struct amd64_pvt *pvt) | ||
775 | { | ||
776 | int ganged; | ||
777 | |||
778 | debugf1(" nbcap:0x%8.08x DctDualCap=%s DualNode=%s 8-Node=%s\n", | ||
779 | pvt->nbcap, | ||
780 | (pvt->nbcap & K8_NBCAP_DCT_DUAL) ? "True" : "False", | ||
781 | (pvt->nbcap & K8_NBCAP_DUAL_NODE) ? "True" : "False", | ||
782 | (pvt->nbcap & K8_NBCAP_8_NODE) ? "True" : "False"); | ||
783 | debugf1(" ECC Capable=%s ChipKill Capable=%s\n", | ||
784 | (pvt->nbcap & K8_NBCAP_SECDED) ? "True" : "False", | ||
785 | (pvt->nbcap & K8_NBCAP_CHIPKILL) ? "True" : "False"); | ||
786 | debugf1(" DramCfg0-low=0x%08x DIMM-ECC=%s Parity=%s Width=%s\n", | ||
787 | pvt->dclr0, | ||
788 | (pvt->dclr0 & BIT(19)) ? "Enabled" : "Disabled", | ||
789 | (pvt->dclr0 & BIT(8)) ? "Enabled" : "Disabled", | ||
790 | (pvt->dclr0 & BIT(11)) ? "128b" : "64b"); | ||
791 | debugf1(" DIMM x4 Present: L0=%s L1=%s L2=%s L3=%s DIMM Type=%s\n", | ||
792 | (pvt->dclr0 & BIT(12)) ? "Y" : "N", | ||
793 | (pvt->dclr0 & BIT(13)) ? "Y" : "N", | ||
794 | (pvt->dclr0 & BIT(14)) ? "Y" : "N", | ||
795 | (pvt->dclr0 & BIT(15)) ? "Y" : "N", | ||
796 | (pvt->dclr0 & BIT(16)) ? "UN-Buffered" : "Buffered"); | ||
797 | |||
798 | |||
799 | debugf1(" online-spare: 0x%8.08x\n", pvt->online_spare); | ||
800 | |||
801 | if (boot_cpu_data.x86 == 0xf) { | ||
802 | debugf1(" dhar: 0x%8.08x Base=0x%08x Offset=0x%08x\n", | ||
803 | pvt->dhar, dhar_base(pvt->dhar), | ||
804 | k8_dhar_offset(pvt->dhar)); | ||
805 | debugf1(" DramHoleValid=%s\n", | ||
806 | (pvt->dhar & DHAR_VALID) ? "True" : "False"); | ||
807 | |||
808 | debugf1(" dbam-dkt: 0x%8.08x\n", pvt->dbam0); | ||
809 | |||
810 | /* everything below this point is Fam10h and above */ | ||
811 | return; | ||
812 | |||
813 | } else { | ||
814 | debugf1(" dhar: 0x%8.08x Base=0x%08x Offset=0x%08x\n", | ||
815 | pvt->dhar, dhar_base(pvt->dhar), | ||
816 | f10_dhar_offset(pvt->dhar)); | ||
817 | debugf1(" DramMemHoistValid=%s DramHoleValid=%s\n", | ||
818 | (pvt->dhar & F10_DRAM_MEM_HOIST_VALID) ? | ||
819 | "True" : "False", | ||
820 | (pvt->dhar & DHAR_VALID) ? | ||
821 | "True" : "False"); | ||
822 | } | ||
823 | |||
824 | /* Only if NOT ganged does dcl1 have valid info */ | ||
825 | if (!dct_ganging_enabled(pvt)) { | ||
826 | debugf1(" DramCfg1-low=0x%08x DIMM-ECC=%s Parity=%s " | ||
827 | "Width=%s\n", pvt->dclr1, | ||
828 | (pvt->dclr1 & BIT(19)) ? "Enabled" : "Disabled", | ||
829 | (pvt->dclr1 & BIT(8)) ? "Enabled" : "Disabled", | ||
830 | (pvt->dclr1 & BIT(11)) ? "128b" : "64b"); | ||
831 | debugf1(" DIMM x4 Present: L0=%s L1=%s L2=%s L3=%s " | ||
832 | "DIMM Type=%s\n", | ||
833 | (pvt->dclr1 & BIT(12)) ? "Y" : "N", | ||
834 | (pvt->dclr1 & BIT(13)) ? "Y" : "N", | ||
835 | (pvt->dclr1 & BIT(14)) ? "Y" : "N", | ||
836 | (pvt->dclr1 & BIT(15)) ? "Y" : "N", | ||
837 | (pvt->dclr1 & BIT(16)) ? "UN-Buffered" : "Buffered"); | ||
838 | } | ||
839 | |||
840 | /* | ||
841 | * Determine if ganged and then dump memory sizes for first controller, | ||
842 | * and if NOT ganged dump info for 2nd controller. | ||
843 | */ | ||
844 | ganged = dct_ganging_enabled(pvt); | ||
845 | |||
846 | f10_debug_display_dimm_sizes(0, pvt, ganged); | ||
847 | |||
848 | if (!ganged) | ||
849 | f10_debug_display_dimm_sizes(1, pvt, ganged); | ||
850 | } | ||
851 | |||
852 | /* Read in both of DBAM registers */ | ||
853 | static void amd64_read_dbam_reg(struct amd64_pvt *pvt) | ||
854 | { | ||
855 | int err = 0; | ||
856 | unsigned int reg; | ||
857 | |||
858 | reg = DBAM0; | ||
859 | err = pci_read_config_dword(pvt->dram_f2_ctl, reg, &pvt->dbam0); | ||
860 | if (err) | ||
861 | goto err_reg; | ||
862 | |||
863 | if (boot_cpu_data.x86 >= 0x10) { | ||
864 | reg = DBAM1; | ||
865 | err = pci_read_config_dword(pvt->dram_f2_ctl, reg, &pvt->dbam1); | ||
866 | |||
867 | if (err) | ||
868 | goto err_reg; | ||
869 | } | ||
870 | |||
871 | err_reg: | ||
872 | debugf0("Error reading F2x%03x.\n", reg); | ||
873 | } | ||
874 | |||
875 | /* | ||
876 | * NOTE: CPU Revision Dependent code: Rev E and Rev F | ||
877 | * | ||
878 | * Set the DCSB and DCSM mask values depending on the CPU revision value. Also | ||
879 | * set the shift factor for the DCSB and DCSM values. | ||
880 | * | ||
881 | * ->dcs_mask_notused, RevE: | ||
882 | * | ||
883 | * To find the max InputAddr for the csrow, start with the base address and set | ||
884 | * all bits that are "don't care" bits in the test at the start of section | ||
885 | * 3.5.4 (p. 84). | ||
886 | * | ||
887 | * The "don't care" bits are all set bits in the mask and all bits in the gaps | ||
888 | * between bit ranges [35:25] and [19:13]. The value REV_E_DCS_NOTUSED_BITS | ||
889 | * represents bits [24:20] and [12:0], which are all bits in the above-mentioned | ||
890 | * gaps. | ||
891 | * | ||
892 | * ->dcs_mask_notused, RevF and later: | ||
893 | * | ||
894 | * To find the max InputAddr for the csrow, start with the base address and set | ||
895 | * all bits that are "don't care" bits in the test at the start of NPT section | ||
896 | * 4.5.4 (p. 87). | ||
897 | * | ||
898 | * The "don't care" bits are all set bits in the mask and all bits in the gaps | ||
899 | * between bit ranges [36:27] and [21:13]. | ||
900 | * | ||
901 | * The value REV_F_F1Xh_DCS_NOTUSED_BITS represents bits [26:22] and [12:0], | ||
902 | * which are all bits in the above-mentioned gaps. | ||
903 | */ | ||
904 | static void amd64_set_dct_base_and_mask(struct amd64_pvt *pvt) | ||
905 | { | ||
906 | if (pvt->ext_model >= OPTERON_CPU_REV_F) { | ||
907 | pvt->dcsb_base = REV_F_F1Xh_DCSB_BASE_BITS; | ||
908 | pvt->dcsm_mask = REV_F_F1Xh_DCSM_MASK_BITS; | ||
909 | pvt->dcs_mask_notused = REV_F_F1Xh_DCS_NOTUSED_BITS; | ||
910 | pvt->dcs_shift = REV_F_F1Xh_DCS_SHIFT; | ||
911 | |||
912 | switch (boot_cpu_data.x86) { | ||
913 | case 0xf: | ||
914 | pvt->num_dcsm = REV_F_DCSM_COUNT; | ||
915 | break; | ||
916 | |||
917 | case 0x10: | ||
918 | pvt->num_dcsm = F10_DCSM_COUNT; | ||
919 | break; | ||
920 | |||
921 | case 0x11: | ||
922 | pvt->num_dcsm = F11_DCSM_COUNT; | ||
923 | break; | ||
924 | |||
925 | default: | ||
926 | amd64_printk(KERN_ERR, "Unsupported family!\n"); | ||
927 | break; | ||
928 | } | ||
929 | } else { | ||
930 | pvt->dcsb_base = REV_E_DCSB_BASE_BITS; | ||
931 | pvt->dcsm_mask = REV_E_DCSM_MASK_BITS; | ||
932 | pvt->dcs_mask_notused = REV_E_DCS_NOTUSED_BITS; | ||
933 | pvt->dcs_shift = REV_E_DCS_SHIFT; | ||
934 | pvt->num_dcsm = REV_E_DCSM_COUNT; | ||
935 | } | ||
936 | } | ||
937 | |||
938 | /* | ||
939 | * Function 2 Offset F10_DCSB0; read in the DCS Base and DCS Mask hw registers | ||
940 | */ | ||
941 | static void amd64_read_dct_base_mask(struct amd64_pvt *pvt) | ||
942 | { | ||
943 | int cs, reg, err = 0; | ||
944 | |||
945 | amd64_set_dct_base_and_mask(pvt); | ||
946 | |||
947 | for (cs = 0; cs < CHIPSELECT_COUNT; cs++) { | ||
948 | reg = K8_DCSB0 + (cs * 4); | ||
949 | err = pci_read_config_dword(pvt->dram_f2_ctl, reg, | ||
950 | &pvt->dcsb0[cs]); | ||
951 | if (unlikely(err)) | ||
952 | debugf0("Reading K8_DCSB0[%d] failed\n", cs); | ||
953 | else | ||
954 | debugf0(" DCSB0[%d]=0x%08x reg: F2x%x\n", | ||
955 | cs, pvt->dcsb0[cs], reg); | ||
956 | |||
957 | /* If DCT are NOT ganged, then read in DCT1's base */ | ||
958 | if (boot_cpu_data.x86 >= 0x10 && !dct_ganging_enabled(pvt)) { | ||
959 | reg = F10_DCSB1 + (cs * 4); | ||
960 | err = pci_read_config_dword(pvt->dram_f2_ctl, reg, | ||
961 | &pvt->dcsb1[cs]); | ||
962 | if (unlikely(err)) | ||
963 | debugf0("Reading F10_DCSB1[%d] failed\n", cs); | ||
964 | else | ||
965 | debugf0(" DCSB1[%d]=0x%08x reg: F2x%x\n", | ||
966 | cs, pvt->dcsb1[cs], reg); | ||
967 | } else { | ||
968 | pvt->dcsb1[cs] = 0; | ||
969 | } | ||
970 | } | ||
971 | |||
972 | for (cs = 0; cs < pvt->num_dcsm; cs++) { | ||
973 | reg = K8_DCSB0 + (cs * 4); | ||
974 | err = pci_read_config_dword(pvt->dram_f2_ctl, reg, | ||
975 | &pvt->dcsm0[cs]); | ||
976 | if (unlikely(err)) | ||
977 | debugf0("Reading K8_DCSM0 failed\n"); | ||
978 | else | ||
979 | debugf0(" DCSM0[%d]=0x%08x reg: F2x%x\n", | ||
980 | cs, pvt->dcsm0[cs], reg); | ||
981 | |||
982 | /* If DCT are NOT ganged, then read in DCT1's mask */ | ||
983 | if (boot_cpu_data.x86 >= 0x10 && !dct_ganging_enabled(pvt)) { | ||
984 | reg = F10_DCSM1 + (cs * 4); | ||
985 | err = pci_read_config_dword(pvt->dram_f2_ctl, reg, | ||
986 | &pvt->dcsm1[cs]); | ||
987 | if (unlikely(err)) | ||
988 | debugf0("Reading F10_DCSM1[%d] failed\n", cs); | ||
989 | else | ||
990 | debugf0(" DCSM1[%d]=0x%08x reg: F2x%x\n", | ||
991 | cs, pvt->dcsm1[cs], reg); | ||
992 | } else | ||
993 | pvt->dcsm1[cs] = 0; | ||
994 | } | ||
995 | } | ||
996 | |||
997 | static enum mem_type amd64_determine_memory_type(struct amd64_pvt *pvt) | ||
998 | { | ||
999 | enum mem_type type; | ||
1000 | |||
1001 | if (boot_cpu_data.x86 >= 0x10 || pvt->ext_model >= OPTERON_CPU_REV_F) { | ||
1002 | /* Rev F and later */ | ||
1003 | type = (pvt->dclr0 & BIT(16)) ? MEM_DDR2 : MEM_RDDR2; | ||
1004 | } else { | ||
1005 | /* Rev E and earlier */ | ||
1006 | type = (pvt->dclr0 & BIT(18)) ? MEM_DDR : MEM_RDDR; | ||
1007 | } | ||
1008 | |||
1009 | debugf1(" Memory type is: %s\n", | ||
1010 | (type == MEM_DDR2) ? "MEM_DDR2" : | ||
1011 | (type == MEM_RDDR2) ? "MEM_RDDR2" : | ||
1012 | (type == MEM_DDR) ? "MEM_DDR" : "MEM_RDDR"); | ||
1013 | |||
1014 | return type; | ||
1015 | } | ||
1016 | |||
1017 | /* | ||
1018 | * Read the DRAM Configuration Low register. It differs between CG, D & E revs | ||
1019 | * and the later RevF memory controllers (DDR vs DDR2) | ||
1020 | * | ||
1021 | * Return: | ||
1022 | * number of memory channels in operation | ||
1023 | * Pass back: | ||
1024 | * contents of the DCL0_LOW register | ||
1025 | */ | ||
1026 | static int k8_early_channel_count(struct amd64_pvt *pvt) | ||
1027 | { | ||
1028 | int flag, err = 0; | ||
1029 | |||
1030 | err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCLR_0, &pvt->dclr0); | ||
1031 | if (err) | ||
1032 | return err; | ||
1033 | |||
1034 | if ((boot_cpu_data.x86_model >> 4) >= OPTERON_CPU_REV_F) { | ||
1035 | /* RevF (NPT) and later */ | ||
1036 | flag = pvt->dclr0 & F10_WIDTH_128; | ||
1037 | } else { | ||
1038 | /* RevE and earlier */ | ||
1039 | flag = pvt->dclr0 & REVE_WIDTH_128; | ||
1040 | } | ||
1041 | |||
1042 | /* not used */ | ||
1043 | pvt->dclr1 = 0; | ||
1044 | |||
1045 | return (flag) ? 2 : 1; | ||
1046 | } | ||
1047 | |||
1048 | /* extract the ERROR ADDRESS for the K8 CPUs */ | ||
1049 | static u64 k8_get_error_address(struct mem_ctl_info *mci, | ||
1050 | struct amd64_error_info_regs *info) | ||
1051 | { | ||
1052 | return (((u64) (info->nbeah & 0xff)) << 32) + | ||
1053 | (info->nbeal & ~0x03); | ||
1054 | } | ||
1055 | |||
1056 | /* | ||
1057 | * Read the Base and Limit registers for K8 based Memory controllers; extract | ||
1058 | * fields from the 'raw' reg into separate data fields | ||
1059 | * | ||
1060 | * Isolates: BASE, LIMIT, IntlvEn, IntlvSel, RW_EN | ||
1061 | */ | ||
1062 | static void k8_read_dram_base_limit(struct amd64_pvt *pvt, int dram) | ||
1063 | { | ||
1064 | u32 low; | ||
1065 | u32 off = dram << 3; /* 8 bytes between DRAM entries */ | ||
1066 | int err; | ||
1067 | |||
1068 | err = pci_read_config_dword(pvt->addr_f1_ctl, | ||
1069 | K8_DRAM_BASE_LOW + off, &low); | ||
1070 | if (err) | ||
1071 | debugf0("Reading K8_DRAM_BASE_LOW failed\n"); | ||
1072 | |||
1073 | /* Extract parts into separate data entries */ | ||
1074 | pvt->dram_base[dram] = ((u64) low & 0xFFFF0000) << 8; | ||
1075 | pvt->dram_IntlvEn[dram] = (low >> 8) & 0x7; | ||
1076 | pvt->dram_rw_en[dram] = (low & 0x3); | ||
1077 | |||
1078 | err = pci_read_config_dword(pvt->addr_f1_ctl, | ||
1079 | K8_DRAM_LIMIT_LOW + off, &low); | ||
1080 | if (err) | ||
1081 | debugf0("Reading K8_DRAM_LIMIT_LOW failed\n"); | ||
1082 | |||
1083 | /* | ||
1084 | * Extract parts into separate data entries. Limit is the HIGHEST memory | ||
1085 | * location of the region, so lower 24 bits need to be all ones | ||
1086 | */ | ||
1087 | pvt->dram_limit[dram] = (((u64) low & 0xFFFF0000) << 8) | 0x00FFFFFF; | ||
1088 | pvt->dram_IntlvSel[dram] = (low >> 8) & 0x7; | ||
1089 | pvt->dram_DstNode[dram] = (low & 0x7); | ||
1090 | } | ||
1091 | |||
1092 | static void k8_map_sysaddr_to_csrow(struct mem_ctl_info *mci, | ||
1093 | struct amd64_error_info_regs *info, | ||
1094 | u64 SystemAddress) | ||
1095 | { | ||
1096 | struct mem_ctl_info *src_mci; | ||
1097 | unsigned short syndrome; | ||
1098 | int channel, csrow; | ||
1099 | u32 page, offset; | ||
1100 | |||
1101 | /* Extract the syndrome parts and form a 16-bit syndrome */ | ||
1102 | syndrome = EXTRACT_HIGH_SYNDROME(info->nbsl) << 8; | ||
1103 | syndrome |= EXTRACT_LOW_SYNDROME(info->nbsh); | ||
1104 | |||
1105 | /* CHIPKILL enabled */ | ||
1106 | if (info->nbcfg & K8_NBCFG_CHIPKILL) { | ||
1107 | channel = get_channel_from_ecc_syndrome(syndrome); | ||
1108 | if (channel < 0) { | ||
1109 | /* | ||
1110 | * Syndrome didn't map, so we don't know which of the | ||
1111 | * 2 DIMMs is in error. So we need to ID 'both' of them | ||
1112 | * as suspect. | ||
1113 | */ | ||
1114 | amd64_mc_printk(mci, KERN_WARNING, | ||
1115 | "unknown syndrome 0x%x - possible error " | ||
1116 | "reporting race\n", syndrome); | ||
1117 | edac_mc_handle_ce_no_info(mci, EDAC_MOD_STR); | ||
1118 | return; | ||
1119 | } | ||
1120 | } else { | ||
1121 | /* | ||
1122 | * non-chipkill ecc mode | ||
1123 | * | ||
1124 | * The k8 documentation is unclear about how to determine the | ||
1125 | * channel number when using non-chipkill memory. This method | ||
1126 | * was obtained from email communication with someone at AMD. | ||
1127 | * (Wish the email was placed in this comment - norsk) | ||
1128 | */ | ||
1129 | channel = ((SystemAddress & BIT(3)) != 0); | ||
1130 | } | ||
1131 | |||
1132 | /* | ||
1133 | * Find out which node the error address belongs to. This may be | ||
1134 | * different from the node that detected the error. | ||
1135 | */ | ||
1136 | src_mci = find_mc_by_sys_addr(mci, SystemAddress); | ||
1137 | if (src_mci) { | ||
1138 | amd64_mc_printk(mci, KERN_ERR, | ||
1139 | "failed to map error address 0x%lx to a node\n", | ||
1140 | (unsigned long)SystemAddress); | ||
1141 | edac_mc_handle_ce_no_info(mci, EDAC_MOD_STR); | ||
1142 | return; | ||
1143 | } | ||
1144 | |||
1145 | /* Now map the SystemAddress to a CSROW */ | ||
1146 | csrow = sys_addr_to_csrow(src_mci, SystemAddress); | ||
1147 | if (csrow < 0) { | ||
1148 | edac_mc_handle_ce_no_info(src_mci, EDAC_MOD_STR); | ||
1149 | } else { | ||
1150 | error_address_to_page_and_offset(SystemAddress, &page, &offset); | ||
1151 | |||
1152 | edac_mc_handle_ce(src_mci, page, offset, syndrome, csrow, | ||
1153 | channel, EDAC_MOD_STR); | ||
1154 | } | ||
1155 | } | ||
1156 | |||
1157 | /* | ||
1158 | * determrine the number of PAGES in for this DIMM's size based on its DRAM | ||
1159 | * Address Mapping. | ||
1160 | * | ||
1161 | * First step is to calc the number of bits to shift a value of 1 left to | ||
1162 | * indicate show many pages. Start with the DBAM value as the starting bits, | ||
1163 | * then proceed to adjust those shift bits, based on CPU rev and the table. | ||
1164 | * See BKDG on the DBAM | ||
1165 | */ | ||
1166 | static int k8_dbam_map_to_pages(struct amd64_pvt *pvt, int dram_map) | ||
1167 | { | ||
1168 | int nr_pages; | ||
1169 | |||
1170 | if (pvt->ext_model >= OPTERON_CPU_REV_F) { | ||
1171 | nr_pages = 1 << (revf_quad_ddr2_shift[dram_map] - PAGE_SHIFT); | ||
1172 | } else { | ||
1173 | /* | ||
1174 | * RevE and less section; this line is tricky. It collapses the | ||
1175 | * table used by RevD and later to one that matches revisions CG | ||
1176 | * and earlier. | ||
1177 | */ | ||
1178 | dram_map -= (pvt->ext_model >= OPTERON_CPU_REV_D) ? | ||
1179 | (dram_map > 8 ? 4 : (dram_map > 5 ? | ||
1180 | 3 : (dram_map > 2 ? 1 : 0))) : 0; | ||
1181 | |||
1182 | /* 25 shift is 32MiB minimum DIMM size in RevE and prior */ | ||
1183 | nr_pages = 1 << (dram_map + 25 - PAGE_SHIFT); | ||
1184 | } | ||
1185 | |||
1186 | return nr_pages; | ||
1187 | } | ||
1188 | |||
1189 | /* | ||
1190 | * Get the number of DCT channels in use. | ||
1191 | * | ||
1192 | * Return: | ||
1193 | * number of Memory Channels in operation | ||
1194 | * Pass back: | ||
1195 | * contents of the DCL0_LOW register | ||
1196 | */ | ||
1197 | static int f10_early_channel_count(struct amd64_pvt *pvt) | ||
1198 | { | ||
1199 | int err = 0, channels = 0; | ||
1200 | u32 dbam; | ||
1201 | |||
1202 | err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCLR_0, &pvt->dclr0); | ||
1203 | if (err) | ||
1204 | goto err_reg; | ||
1205 | |||
1206 | err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCLR_1, &pvt->dclr1); | ||
1207 | if (err) | ||
1208 | goto err_reg; | ||
1209 | |||
1210 | /* If we are in 128 bit mode, then we are using 2 channels */ | ||
1211 | if (pvt->dclr0 & F10_WIDTH_128) { | ||
1212 | debugf0("Data WIDTH is 128 bits - 2 channels\n"); | ||
1213 | channels = 2; | ||
1214 | return channels; | ||
1215 | } | ||
1216 | |||
1217 | /* | ||
1218 | * Need to check if in UN-ganged mode: In such, there are 2 channels, | ||
1219 | * but they are NOT in 128 bit mode and thus the above 'dcl0' status bit | ||
1220 | * will be OFF. | ||
1221 | * | ||
1222 | * Need to check DCT0[0] and DCT1[0] to see if only one of them has | ||
1223 | * their CSEnable bit on. If so, then SINGLE DIMM case. | ||
1224 | */ | ||
1225 | debugf0("Data WIDTH is NOT 128 bits - need more decoding\n"); | ||
1226 | |||
1227 | /* | ||
1228 | * Check DRAM Bank Address Mapping values for each DIMM to see if there | ||
1229 | * is more than just one DIMM present in unganged mode. Need to check | ||
1230 | * both controllers since DIMMs can be placed in either one. | ||
1231 | */ | ||
1232 | channels = 0; | ||
1233 | err = pci_read_config_dword(pvt->dram_f2_ctl, DBAM0, &dbam); | ||
1234 | if (err) | ||
1235 | goto err_reg; | ||
1236 | |||
1237 | if (DBAM_DIMM(0, dbam) > 0) | ||
1238 | channels++; | ||
1239 | if (DBAM_DIMM(1, dbam) > 0) | ||
1240 | channels++; | ||
1241 | if (DBAM_DIMM(2, dbam) > 0) | ||
1242 | channels++; | ||
1243 | if (DBAM_DIMM(3, dbam) > 0) | ||
1244 | channels++; | ||
1245 | |||
1246 | /* If more than 2 DIMMs are present, then we have 2 channels */ | ||
1247 | if (channels > 2) | ||
1248 | channels = 2; | ||
1249 | else if (channels == 0) { | ||
1250 | /* No DIMMs on DCT0, so look at DCT1 */ | ||
1251 | err = pci_read_config_dword(pvt->dram_f2_ctl, DBAM1, &dbam); | ||
1252 | if (err) | ||
1253 | goto err_reg; | ||
1254 | |||
1255 | if (DBAM_DIMM(0, dbam) > 0) | ||
1256 | channels++; | ||
1257 | if (DBAM_DIMM(1, dbam) > 0) | ||
1258 | channels++; | ||
1259 | if (DBAM_DIMM(2, dbam) > 0) | ||
1260 | channels++; | ||
1261 | if (DBAM_DIMM(3, dbam) > 0) | ||
1262 | channels++; | ||
1263 | |||
1264 | if (channels > 2) | ||
1265 | channels = 2; | ||
1266 | } | ||
1267 | |||
1268 | /* If we found ALL 0 values, then assume just ONE DIMM-ONE Channel */ | ||
1269 | if (channels == 0) | ||
1270 | channels = 1; | ||
1271 | |||
1272 | debugf0("DIMM count= %d\n", channels); | ||
1273 | |||
1274 | return channels; | ||
1275 | |||
1276 | err_reg: | ||
1277 | return -1; | ||
1278 | |||
1279 | } | ||
1280 | |||
1281 | static int f10_dbam_map_to_pages(struct amd64_pvt *pvt, int dram_map) | ||
1282 | { | ||
1283 | return 1 << (revf_quad_ddr2_shift[dram_map] - PAGE_SHIFT); | ||
1284 | } | ||
1285 | |||
1286 | /* Enable extended configuration access via 0xCF8 feature */ | ||
1287 | static void amd64_setup(struct amd64_pvt *pvt) | ||
1288 | { | ||
1289 | u32 reg; | ||
1290 | |||
1291 | pci_read_config_dword(pvt->misc_f3_ctl, F10_NB_CFG_HIGH, ®); | ||
1292 | |||
1293 | pvt->flags.cf8_extcfg = !!(reg & F10_NB_CFG_LOW_ENABLE_EXT_CFG); | ||
1294 | reg |= F10_NB_CFG_LOW_ENABLE_EXT_CFG; | ||
1295 | pci_write_config_dword(pvt->misc_f3_ctl, F10_NB_CFG_HIGH, reg); | ||
1296 | } | ||
1297 | |||
1298 | /* Restore the extended configuration access via 0xCF8 feature */ | ||
1299 | static void amd64_teardown(struct amd64_pvt *pvt) | ||
1300 | { | ||
1301 | u32 reg; | ||
1302 | |||
1303 | pci_read_config_dword(pvt->misc_f3_ctl, F10_NB_CFG_HIGH, ®); | ||
1304 | |||
1305 | reg &= ~F10_NB_CFG_LOW_ENABLE_EXT_CFG; | ||
1306 | if (pvt->flags.cf8_extcfg) | ||
1307 | reg |= F10_NB_CFG_LOW_ENABLE_EXT_CFG; | ||
1308 | pci_write_config_dword(pvt->misc_f3_ctl, F10_NB_CFG_HIGH, reg); | ||
1309 | } | ||
1310 | |||
1311 | static u64 f10_get_error_address(struct mem_ctl_info *mci, | ||
1312 | struct amd64_error_info_regs *info) | ||
1313 | { | ||
1314 | return (((u64) (info->nbeah & 0xffff)) << 32) + | ||
1315 | (info->nbeal & ~0x01); | ||
1316 | } | ||
1317 | |||
1318 | /* | ||
1319 | * Read the Base and Limit registers for F10 based Memory controllers. Extract | ||
1320 | * fields from the 'raw' reg into separate data fields. | ||
1321 | * | ||
1322 | * Isolates: BASE, LIMIT, IntlvEn, IntlvSel, RW_EN. | ||
1323 | */ | ||
1324 | static void f10_read_dram_base_limit(struct amd64_pvt *pvt, int dram) | ||
1325 | { | ||
1326 | u32 high_offset, low_offset, high_base, low_base, high_limit, low_limit; | ||
1327 | |||
1328 | low_offset = K8_DRAM_BASE_LOW + (dram << 3); | ||
1329 | high_offset = F10_DRAM_BASE_HIGH + (dram << 3); | ||
1330 | |||
1331 | /* read the 'raw' DRAM BASE Address register */ | ||
1332 | pci_read_config_dword(pvt->addr_f1_ctl, low_offset, &low_base); | ||
1333 | |||
1334 | /* Read from the ECS data register */ | ||
1335 | pci_read_config_dword(pvt->addr_f1_ctl, high_offset, &high_base); | ||
1336 | |||
1337 | /* Extract parts into separate data entries */ | ||
1338 | pvt->dram_rw_en[dram] = (low_base & 0x3); | ||
1339 | |||
1340 | if (pvt->dram_rw_en[dram] == 0) | ||
1341 | return; | ||
1342 | |||
1343 | pvt->dram_IntlvEn[dram] = (low_base >> 8) & 0x7; | ||
1344 | |||
1345 | pvt->dram_base[dram] = (((((u64) high_base & 0x000000FF) << 32) | | ||
1346 | ((u64) low_base & 0xFFFF0000))) << 8; | ||
1347 | |||
1348 | low_offset = K8_DRAM_LIMIT_LOW + (dram << 3); | ||
1349 | high_offset = F10_DRAM_LIMIT_HIGH + (dram << 3); | ||
1350 | |||
1351 | /* read the 'raw' LIMIT registers */ | ||
1352 | pci_read_config_dword(pvt->addr_f1_ctl, low_offset, &low_limit); | ||
1353 | |||
1354 | /* Read from the ECS data register for the HIGH portion */ | ||
1355 | pci_read_config_dword(pvt->addr_f1_ctl, high_offset, &high_limit); | ||
1356 | |||
1357 | debugf0(" HW Regs: BASE=0x%08x-%08x LIMIT= 0x%08x-%08x\n", | ||
1358 | high_base, low_base, high_limit, low_limit); | ||
1359 | |||
1360 | pvt->dram_DstNode[dram] = (low_limit & 0x7); | ||
1361 | pvt->dram_IntlvSel[dram] = (low_limit >> 8) & 0x7; | ||
1362 | |||
1363 | /* | ||
1364 | * Extract address values and form a LIMIT address. Limit is the HIGHEST | ||
1365 | * memory location of the region, so low 24 bits need to be all ones. | ||
1366 | */ | ||
1367 | low_limit |= 0x0000FFFF; | ||
1368 | pvt->dram_limit[dram] = | ||
1369 | ((((u64) high_limit << 32) + (u64) low_limit) << 8) | (0xFF); | ||
1370 | } | ||
1371 | |||
1372 | static void f10_read_dram_ctl_register(struct amd64_pvt *pvt) | ||
1373 | { | ||
1374 | int err = 0; | ||
1375 | |||
1376 | err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCTL_SEL_LOW, | ||
1377 | &pvt->dram_ctl_select_low); | ||
1378 | if (err) { | ||
1379 | debugf0("Reading F10_DCTL_SEL_LOW failed\n"); | ||
1380 | } else { | ||
1381 | debugf0("DRAM_DCTL_SEL_LOW=0x%x DctSelBaseAddr=0x%x\n", | ||
1382 | pvt->dram_ctl_select_low, dct_sel_baseaddr(pvt)); | ||
1383 | |||
1384 | debugf0(" DRAM DCTs are=%s DRAM Is=%s DRAM-Ctl-" | ||
1385 | "sel-hi-range=%s\n", | ||
1386 | (dct_ganging_enabled(pvt) ? "GANGED" : "NOT GANGED"), | ||
1387 | (dct_dram_enabled(pvt) ? "Enabled" : "Disabled"), | ||
1388 | (dct_high_range_enabled(pvt) ? "Enabled" : "Disabled")); | ||
1389 | |||
1390 | debugf0(" DctDatIntLv=%s MemCleared=%s DctSelIntLvAddr=0x%x\n", | ||
1391 | (dct_data_intlv_enabled(pvt) ? "Enabled" : "Disabled"), | ||
1392 | (dct_memory_cleared(pvt) ? "True " : "False "), | ||
1393 | dct_sel_interleave_addr(pvt)); | ||
1394 | } | ||
1395 | |||
1396 | err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCTL_SEL_HIGH, | ||
1397 | &pvt->dram_ctl_select_high); | ||
1398 | if (err) | ||
1399 | debugf0("Reading F10_DCTL_SEL_HIGH failed\n"); | ||
1400 | } | ||
1401 | |||
1402 | /* | ||
1403 | * determine channel based on the interleaving mode: F10h BKDG, 2.8.9 Memory | ||
1404 | * Interleaving Modes. | ||
1405 | */ | ||
1406 | static u32 f10_determine_channel(struct amd64_pvt *pvt, u64 sys_addr, | ||
1407 | int hi_range_sel, u32 intlv_en) | ||
1408 | { | ||
1409 | u32 cs, temp, dct_sel_high = (pvt->dram_ctl_select_low >> 1) & 1; | ||
1410 | |||
1411 | if (dct_ganging_enabled(pvt)) | ||
1412 | cs = 0; | ||
1413 | else if (hi_range_sel) | ||
1414 | cs = dct_sel_high; | ||
1415 | else if (dct_interleave_enabled(pvt)) { | ||
1416 | /* | ||
1417 | * see F2x110[DctSelIntLvAddr] - channel interleave mode | ||
1418 | */ | ||
1419 | if (dct_sel_interleave_addr(pvt) == 0) | ||
1420 | cs = sys_addr >> 6 & 1; | ||
1421 | else if ((dct_sel_interleave_addr(pvt) >> 1) & 1) { | ||
1422 | temp = hweight_long((u32) ((sys_addr >> 16) & 0x1F)) % 2; | ||
1423 | |||
1424 | if (dct_sel_interleave_addr(pvt) & 1) | ||
1425 | cs = (sys_addr >> 9 & 1) ^ temp; | ||
1426 | else | ||
1427 | cs = (sys_addr >> 6 & 1) ^ temp; | ||
1428 | } else if (intlv_en & 4) | ||
1429 | cs = sys_addr >> 15 & 1; | ||
1430 | else if (intlv_en & 2) | ||
1431 | cs = sys_addr >> 14 & 1; | ||
1432 | else if (intlv_en & 1) | ||
1433 | cs = sys_addr >> 13 & 1; | ||
1434 | else | ||
1435 | cs = sys_addr >> 12 & 1; | ||
1436 | } else if (dct_high_range_enabled(pvt) && !dct_ganging_enabled(pvt)) | ||
1437 | cs = ~dct_sel_high & 1; | ||
1438 | else | ||
1439 | cs = 0; | ||
1440 | |||
1441 | return cs; | ||
1442 | } | ||
1443 | |||
1444 | static inline u32 f10_map_intlv_en_to_shift(u32 intlv_en) | ||
1445 | { | ||
1446 | if (intlv_en == 1) | ||
1447 | return 1; | ||
1448 | else if (intlv_en == 3) | ||
1449 | return 2; | ||
1450 | else if (intlv_en == 7) | ||
1451 | return 3; | ||
1452 | |||
1453 | return 0; | ||
1454 | } | ||
1455 | |||
1456 | /* See F10h BKDG, 2.8.10.2 DctSelBaseOffset Programming */ | ||
1457 | static inline u64 f10_get_base_addr_offset(u64 sys_addr, int hi_range_sel, | ||
1458 | u32 dct_sel_base_addr, | ||
1459 | u64 dct_sel_base_off, | ||
1460 | u32 hole_valid, u32 hole_off, | ||
1461 | u64 dram_base) | ||
1462 | { | ||
1463 | u64 chan_off; | ||
1464 | |||
1465 | if (hi_range_sel) { | ||
1466 | if (!(dct_sel_base_addr & 0xFFFFF800) && | ||
1467 | hole_valid && (sys_addr >= 0x100000000ULL)) | ||
1468 | chan_off = hole_off << 16; | ||
1469 | else | ||
1470 | chan_off = dct_sel_base_off; | ||
1471 | } else { | ||
1472 | if (hole_valid && (sys_addr >= 0x100000000ULL)) | ||
1473 | chan_off = hole_off << 16; | ||
1474 | else | ||
1475 | chan_off = dram_base & 0xFFFFF8000000ULL; | ||
1476 | } | ||
1477 | |||
1478 | return (sys_addr & 0x0000FFFFFFFFFFC0ULL) - | ||
1479 | (chan_off & 0x0000FFFFFF800000ULL); | ||
1480 | } | ||
1481 | |||
1482 | /* Hack for the time being - Can we get this from BIOS?? */ | ||
1483 | #define CH0SPARE_RANK 0 | ||
1484 | #define CH1SPARE_RANK 1 | ||
1485 | |||
1486 | /* | ||
1487 | * checks if the csrow passed in is marked as SPARED, if so returns the new | ||
1488 | * spare row | ||
1489 | */ | ||
1490 | static inline int f10_process_possible_spare(int csrow, | ||
1491 | u32 cs, struct amd64_pvt *pvt) | ||
1492 | { | ||
1493 | u32 swap_done; | ||
1494 | u32 bad_dram_cs; | ||
1495 | |||
1496 | /* Depending on channel, isolate respective SPARING info */ | ||
1497 | if (cs) { | ||
1498 | swap_done = F10_ONLINE_SPARE_SWAPDONE1(pvt->online_spare); | ||
1499 | bad_dram_cs = F10_ONLINE_SPARE_BADDRAM_CS1(pvt->online_spare); | ||
1500 | if (swap_done && (csrow == bad_dram_cs)) | ||
1501 | csrow = CH1SPARE_RANK; | ||
1502 | } else { | ||
1503 | swap_done = F10_ONLINE_SPARE_SWAPDONE0(pvt->online_spare); | ||
1504 | bad_dram_cs = F10_ONLINE_SPARE_BADDRAM_CS0(pvt->online_spare); | ||
1505 | if (swap_done && (csrow == bad_dram_cs)) | ||
1506 | csrow = CH0SPARE_RANK; | ||
1507 | } | ||
1508 | return csrow; | ||
1509 | } | ||
1510 | |||
1511 | /* | ||
1512 | * Iterate over the DRAM DCT "base" and "mask" registers looking for a | ||
1513 | * SystemAddr match on the specified 'ChannelSelect' and 'NodeID' | ||
1514 | * | ||
1515 | * Return: | ||
1516 | * -EINVAL: NOT FOUND | ||
1517 | * 0..csrow = Chip-Select Row | ||
1518 | */ | ||
1519 | static int f10_lookup_addr_in_dct(u32 in_addr, u32 nid, u32 cs) | ||
1520 | { | ||
1521 | struct mem_ctl_info *mci; | ||
1522 | struct amd64_pvt *pvt; | ||
1523 | u32 cs_base, cs_mask; | ||
1524 | int cs_found = -EINVAL; | ||
1525 | int csrow; | ||
1526 | |||
1527 | mci = mci_lookup[nid]; | ||
1528 | if (!mci) | ||
1529 | return cs_found; | ||
1530 | |||
1531 | pvt = mci->pvt_info; | ||
1532 | |||
1533 | debugf1("InputAddr=0x%x channelselect=%d\n", in_addr, cs); | ||
1534 | |||
1535 | for (csrow = 0; csrow < CHIPSELECT_COUNT; csrow++) { | ||
1536 | |||
1537 | cs_base = amd64_get_dct_base(pvt, cs, csrow); | ||
1538 | if (!(cs_base & K8_DCSB_CS_ENABLE)) | ||
1539 | continue; | ||
1540 | |||
1541 | /* | ||
1542 | * We have an ENABLED CSROW, Isolate just the MASK bits of the | ||
1543 | * target: [28:19] and [13:5], which map to [36:27] and [21:13] | ||
1544 | * of the actual address. | ||
1545 | */ | ||
1546 | cs_base &= REV_F_F1Xh_DCSB_BASE_BITS; | ||
1547 | |||
1548 | /* | ||
1549 | * Get the DCT Mask, and ENABLE the reserved bits: [18:16] and | ||
1550 | * [4:0] to become ON. Then mask off bits [28:0] ([36:8]) | ||
1551 | */ | ||
1552 | cs_mask = amd64_get_dct_mask(pvt, cs, csrow); | ||
1553 | |||
1554 | debugf1(" CSROW=%d CSBase=0x%x RAW CSMask=0x%x\n", | ||
1555 | csrow, cs_base, cs_mask); | ||
1556 | |||
1557 | cs_mask = (cs_mask | 0x0007C01F) & 0x1FFFFFFF; | ||
1558 | |||
1559 | debugf1(" Final CSMask=0x%x\n", cs_mask); | ||
1560 | debugf1(" (InputAddr & ~CSMask)=0x%x " | ||
1561 | "(CSBase & ~CSMask)=0x%x\n", | ||
1562 | (in_addr & ~cs_mask), (cs_base & ~cs_mask)); | ||
1563 | |||
1564 | if ((in_addr & ~cs_mask) == (cs_base & ~cs_mask)) { | ||
1565 | cs_found = f10_process_possible_spare(csrow, cs, pvt); | ||
1566 | |||
1567 | debugf1(" MATCH csrow=%d\n", cs_found); | ||
1568 | break; | ||
1569 | } | ||
1570 | } | ||
1571 | return cs_found; | ||
1572 | } | ||
1573 | |||
1574 | /* For a given @dram_range, check if @sys_addr falls within it. */ | ||
1575 | static int f10_match_to_this_node(struct amd64_pvt *pvt, int dram_range, | ||
1576 | u64 sys_addr, int *nid, int *chan_sel) | ||
1577 | { | ||
1578 | int node_id, cs_found = -EINVAL, high_range = 0; | ||
1579 | u32 intlv_en, intlv_sel, intlv_shift, hole_off; | ||
1580 | u32 hole_valid, tmp, dct_sel_base, channel; | ||
1581 | u64 dram_base, chan_addr, dct_sel_base_off; | ||
1582 | |||
1583 | dram_base = pvt->dram_base[dram_range]; | ||
1584 | intlv_en = pvt->dram_IntlvEn[dram_range]; | ||
1585 | |||
1586 | node_id = pvt->dram_DstNode[dram_range]; | ||
1587 | intlv_sel = pvt->dram_IntlvSel[dram_range]; | ||
1588 | |||
1589 | debugf1("(dram=%d) Base=0x%llx SystemAddr= 0x%llx Limit=0x%llx\n", | ||
1590 | dram_range, dram_base, sys_addr, pvt->dram_limit[dram_range]); | ||
1591 | |||
1592 | /* | ||
1593 | * This assumes that one node's DHAR is the same as all the other | ||
1594 | * nodes' DHAR. | ||
1595 | */ | ||
1596 | hole_off = (pvt->dhar & 0x0000FF80); | ||
1597 | hole_valid = (pvt->dhar & 0x1); | ||
1598 | dct_sel_base_off = (pvt->dram_ctl_select_high & 0xFFFFFC00) << 16; | ||
1599 | |||
1600 | debugf1(" HoleOffset=0x%x HoleValid=0x%x IntlvSel=0x%x\n", | ||
1601 | hole_off, hole_valid, intlv_sel); | ||
1602 | |||
1603 | if (intlv_en || | ||
1604 | (intlv_sel != ((sys_addr >> 12) & intlv_en))) | ||
1605 | return -EINVAL; | ||
1606 | |||
1607 | dct_sel_base = dct_sel_baseaddr(pvt); | ||
1608 | |||
1609 | /* | ||
1610 | * check whether addresses >= DctSelBaseAddr[47:27] are to be used to | ||
1611 | * select between DCT0 and DCT1. | ||
1612 | */ | ||
1613 | if (dct_high_range_enabled(pvt) && | ||
1614 | !dct_ganging_enabled(pvt) && | ||
1615 | ((sys_addr >> 27) >= (dct_sel_base >> 11))) | ||
1616 | high_range = 1; | ||
1617 | |||
1618 | channel = f10_determine_channel(pvt, sys_addr, high_range, intlv_en); | ||
1619 | |||
1620 | chan_addr = f10_get_base_addr_offset(sys_addr, high_range, dct_sel_base, | ||
1621 | dct_sel_base_off, hole_valid, | ||
1622 | hole_off, dram_base); | ||
1623 | |||
1624 | intlv_shift = f10_map_intlv_en_to_shift(intlv_en); | ||
1625 | |||
1626 | /* remove Node ID (in case of memory interleaving) */ | ||
1627 | tmp = chan_addr & 0xFC0; | ||
1628 | |||
1629 | chan_addr = ((chan_addr >> intlv_shift) & 0xFFFFFFFFF000ULL) | tmp; | ||
1630 | |||
1631 | /* remove channel interleave and hash */ | ||
1632 | if (dct_interleave_enabled(pvt) && | ||
1633 | !dct_high_range_enabled(pvt) && | ||
1634 | !dct_ganging_enabled(pvt)) { | ||
1635 | if (dct_sel_interleave_addr(pvt) != 1) | ||
1636 | chan_addr = (chan_addr >> 1) & 0xFFFFFFFFFFFFFFC0ULL; | ||
1637 | else { | ||
1638 | tmp = chan_addr & 0xFC0; | ||
1639 | chan_addr = ((chan_addr & 0xFFFFFFFFFFFFC000ULL) >> 1) | ||
1640 | | tmp; | ||
1641 | } | ||
1642 | } | ||
1643 | |||
1644 | debugf1(" (ChannelAddrLong=0x%llx) >> 8 becomes InputAddr=0x%x\n", | ||
1645 | chan_addr, (u32)(chan_addr >> 8)); | ||
1646 | |||
1647 | cs_found = f10_lookup_addr_in_dct(chan_addr >> 8, node_id, channel); | ||
1648 | |||
1649 | if (cs_found >= 0) { | ||
1650 | *nid = node_id; | ||
1651 | *chan_sel = channel; | ||
1652 | } | ||
1653 | return cs_found; | ||
1654 | } | ||
1655 | |||
1656 | static int f10_translate_sysaddr_to_cs(struct amd64_pvt *pvt, u64 sys_addr, | ||
1657 | int *node, int *chan_sel) | ||
1658 | { | ||
1659 | int dram_range, cs_found = -EINVAL; | ||
1660 | u64 dram_base, dram_limit; | ||
1661 | |||
1662 | for (dram_range = 0; dram_range < DRAM_REG_COUNT; dram_range++) { | ||
1663 | |||
1664 | if (!pvt->dram_rw_en[dram_range]) | ||
1665 | continue; | ||
1666 | |||
1667 | dram_base = pvt->dram_base[dram_range]; | ||
1668 | dram_limit = pvt->dram_limit[dram_range]; | ||
1669 | |||
1670 | if ((dram_base <= sys_addr) && (sys_addr <= dram_limit)) { | ||
1671 | |||
1672 | cs_found = f10_match_to_this_node(pvt, dram_range, | ||
1673 | sys_addr, node, | ||
1674 | chan_sel); | ||
1675 | if (cs_found >= 0) | ||
1676 | break; | ||
1677 | } | ||
1678 | } | ||
1679 | return cs_found; | ||
1680 | } | ||
1681 | |||
1682 | /* | ||
1683 | * This the F10h reference code from AMD to map a @sys_addr to NodeID, | ||
1684 | * CSROW, Channel. | ||
1685 | * | ||
1686 | * The @sys_addr is usually an error address received from the hardware. | ||
1687 | */ | ||
1688 | static void f10_map_sysaddr_to_csrow(struct mem_ctl_info *mci, | ||
1689 | struct amd64_error_info_regs *info, | ||
1690 | u64 sys_addr) | ||
1691 | { | ||
1692 | struct amd64_pvt *pvt = mci->pvt_info; | ||
1693 | u32 page, offset; | ||
1694 | unsigned short syndrome; | ||
1695 | int nid, csrow, chan = 0; | ||
1696 | |||
1697 | csrow = f10_translate_sysaddr_to_cs(pvt, sys_addr, &nid, &chan); | ||
1698 | |||
1699 | if (csrow >= 0) { | ||
1700 | error_address_to_page_and_offset(sys_addr, &page, &offset); | ||
1701 | |||
1702 | syndrome = EXTRACT_HIGH_SYNDROME(info->nbsl) << 8; | ||
1703 | syndrome |= EXTRACT_LOW_SYNDROME(info->nbsh); | ||
1704 | |||
1705 | /* | ||
1706 | * Is CHIPKILL on? If so, then we can attempt to use the | ||
1707 | * syndrome to isolate which channel the error was on. | ||
1708 | */ | ||
1709 | if (pvt->nbcfg & K8_NBCFG_CHIPKILL) | ||
1710 | chan = get_channel_from_ecc_syndrome(syndrome); | ||
1711 | |||
1712 | if (chan >= 0) { | ||
1713 | edac_mc_handle_ce(mci, page, offset, syndrome, | ||
1714 | csrow, chan, EDAC_MOD_STR); | ||
1715 | } else { | ||
1716 | /* | ||
1717 | * Channel unknown, report all channels on this | ||
1718 | * CSROW as failed. | ||
1719 | */ | ||
1720 | for (chan = 0; chan < mci->csrows[csrow].nr_channels; | ||
1721 | chan++) { | ||
1722 | edac_mc_handle_ce(mci, page, offset, | ||
1723 | syndrome, | ||
1724 | csrow, chan, | ||
1725 | EDAC_MOD_STR); | ||
1726 | } | ||
1727 | } | ||
1728 | |||
1729 | } else { | ||
1730 | edac_mc_handle_ce_no_info(mci, EDAC_MOD_STR); | ||
1731 | } | ||
1732 | } | ||
1733 | |||
1734 | /* | ||
1735 | * Input (@index) is the DBAM DIMM value (1 of 4) used as an index into a shift | ||
1736 | * table (revf_quad_ddr2_shift) which starts at 128MB DIMM size. Index of 0 | ||
1737 | * indicates an empty DIMM slot, as reported by Hardware on empty slots. | ||
1738 | * | ||
1739 | * Normalize to 128MB by subracting 27 bit shift. | ||
1740 | */ | ||
1741 | static int map_dbam_to_csrow_size(int index) | ||
1742 | { | ||
1743 | int mega_bytes = 0; | ||
1744 | |||
1745 | if (index > 0 && index <= DBAM_MAX_VALUE) | ||
1746 | mega_bytes = ((128 << (revf_quad_ddr2_shift[index]-27))); | ||
1747 | |||
1748 | return mega_bytes; | ||
1749 | } | ||
1750 | |||
1751 | /* | ||
1752 | * debug routine to display the memory sizes of a DIMM (ganged or not) and it | ||
1753 | * CSROWs as well | ||
1754 | */ | ||
1755 | static void f10_debug_display_dimm_sizes(int ctrl, struct amd64_pvt *pvt, | ||
1756 | int ganged) | ||
1757 | { | ||
1758 | int dimm, size0, size1; | ||
1759 | u32 dbam; | ||
1760 | u32 *dcsb; | ||
1761 | |||
1762 | debugf1(" dbam%d: 0x%8.08x CSROW is %s\n", ctrl, | ||
1763 | ctrl ? pvt->dbam1 : pvt->dbam0, | ||
1764 | ganged ? "GANGED - dbam1 not used" : "NON-GANGED"); | ||
1765 | |||
1766 | dbam = ctrl ? pvt->dbam1 : pvt->dbam0; | ||
1767 | dcsb = ctrl ? pvt->dcsb1 : pvt->dcsb0; | ||
1768 | |||
1769 | /* Dump memory sizes for DIMM and its CSROWs */ | ||
1770 | for (dimm = 0; dimm < 4; dimm++) { | ||
1771 | |||
1772 | size0 = 0; | ||
1773 | if (dcsb[dimm*2] & K8_DCSB_CS_ENABLE) | ||
1774 | size0 = map_dbam_to_csrow_size(DBAM_DIMM(dimm, dbam)); | ||
1775 | |||
1776 | size1 = 0; | ||
1777 | if (dcsb[dimm*2 + 1] & K8_DCSB_CS_ENABLE) | ||
1778 | size1 = map_dbam_to_csrow_size(DBAM_DIMM(dimm, dbam)); | ||
1779 | |||
1780 | debugf1(" CTRL-%d DIMM-%d=%5dMB CSROW-%d=%5dMB " | ||
1781 | "CSROW-%d=%5dMB\n", | ||
1782 | ctrl, | ||
1783 | dimm, | ||
1784 | size0 + size1, | ||
1785 | dimm * 2, | ||
1786 | size0, | ||
1787 | dimm * 2 + 1, | ||
1788 | size1); | ||
1789 | } | ||
1790 | } | ||
1791 | |||
1792 | /* | ||
1793 | * Very early hardware probe on pci_probe thread to determine if this module | ||
1794 | * supports the hardware. | ||
1795 | * | ||
1796 | * Return: | ||
1797 | * 0 for OK | ||
1798 | * 1 for error | ||
1799 | */ | ||
1800 | static int f10_probe_valid_hardware(struct amd64_pvt *pvt) | ||
1801 | { | ||
1802 | int ret = 0; | ||
1803 | |||
1804 | /* | ||
1805 | * If we are on a DDR3 machine, we don't know yet if | ||
1806 | * we support that properly at this time | ||
1807 | */ | ||
1808 | if ((pvt->dchr0 & F10_DCHR_Ddr3Mode) || | ||
1809 | (pvt->dchr1 & F10_DCHR_Ddr3Mode)) { | ||
1810 | |||
1811 | amd64_printk(KERN_WARNING, | ||
1812 | "%s() This machine is running with DDR3 memory. " | ||
1813 | "This is not currently supported. " | ||
1814 | "DCHR0=0x%x DCHR1=0x%x\n", | ||
1815 | __func__, pvt->dchr0, pvt->dchr1); | ||
1816 | |||
1817 | amd64_printk(KERN_WARNING, | ||
1818 | " Contact '%s' module MAINTAINER to help add" | ||
1819 | " support.\n", | ||
1820 | EDAC_MOD_STR); | ||
1821 | |||
1822 | ret = 1; | ||
1823 | |||
1824 | } | ||
1825 | return ret; | ||
1826 | } | ||
1827 | |||
1828 | /* | ||
1829 | * There currently are 3 types type of MC devices for AMD Athlon/Opterons | ||
1830 | * (as per PCI DEVICE_IDs): | ||
1831 | * | ||
1832 | * Family K8: That is the Athlon64 and Opteron CPUs. They all have the same PCI | ||
1833 | * DEVICE ID, even though there is differences between the different Revisions | ||
1834 | * (CG,D,E,F). | ||
1835 | * | ||
1836 | * Family F10h and F11h. | ||
1837 | * | ||
1838 | */ | ||
1839 | static struct amd64_family_type amd64_family_types[] = { | ||
1840 | [K8_CPUS] = { | ||
1841 | .ctl_name = "RevF", | ||
1842 | .addr_f1_ctl = PCI_DEVICE_ID_AMD_K8_NB_ADDRMAP, | ||
1843 | .misc_f3_ctl = PCI_DEVICE_ID_AMD_K8_NB_MISC, | ||
1844 | .ops = { | ||
1845 | .early_channel_count = k8_early_channel_count, | ||
1846 | .get_error_address = k8_get_error_address, | ||
1847 | .read_dram_base_limit = k8_read_dram_base_limit, | ||
1848 | .map_sysaddr_to_csrow = k8_map_sysaddr_to_csrow, | ||
1849 | .dbam_map_to_pages = k8_dbam_map_to_pages, | ||
1850 | } | ||
1851 | }, | ||
1852 | [F10_CPUS] = { | ||
1853 | .ctl_name = "Family 10h", | ||
1854 | .addr_f1_ctl = PCI_DEVICE_ID_AMD_10H_NB_MAP, | ||
1855 | .misc_f3_ctl = PCI_DEVICE_ID_AMD_10H_NB_MISC, | ||
1856 | .ops = { | ||
1857 | .probe_valid_hardware = f10_probe_valid_hardware, | ||
1858 | .early_channel_count = f10_early_channel_count, | ||
1859 | .get_error_address = f10_get_error_address, | ||
1860 | .read_dram_base_limit = f10_read_dram_base_limit, | ||
1861 | .read_dram_ctl_register = f10_read_dram_ctl_register, | ||
1862 | .map_sysaddr_to_csrow = f10_map_sysaddr_to_csrow, | ||
1863 | .dbam_map_to_pages = f10_dbam_map_to_pages, | ||
1864 | } | ||
1865 | }, | ||
1866 | [F11_CPUS] = { | ||
1867 | .ctl_name = "Family 11h", | ||
1868 | .addr_f1_ctl = PCI_DEVICE_ID_AMD_11H_NB_MAP, | ||
1869 | .misc_f3_ctl = PCI_DEVICE_ID_AMD_11H_NB_MISC, | ||
1870 | .ops = { | ||
1871 | .probe_valid_hardware = f10_probe_valid_hardware, | ||
1872 | .early_channel_count = f10_early_channel_count, | ||
1873 | .get_error_address = f10_get_error_address, | ||
1874 | .read_dram_base_limit = f10_read_dram_base_limit, | ||
1875 | .read_dram_ctl_register = f10_read_dram_ctl_register, | ||
1876 | .map_sysaddr_to_csrow = f10_map_sysaddr_to_csrow, | ||
1877 | .dbam_map_to_pages = f10_dbam_map_to_pages, | ||
1878 | } | ||
1879 | }, | ||
1880 | }; | ||
1881 | |||
1882 | static struct pci_dev *pci_get_related_function(unsigned int vendor, | ||
1883 | unsigned int device, | ||
1884 | struct pci_dev *related) | ||
1885 | { | ||
1886 | struct pci_dev *dev = NULL; | ||
1887 | |||
1888 | dev = pci_get_device(vendor, device, dev); | ||
1889 | while (dev) { | ||
1890 | if ((dev->bus->number == related->bus->number) && | ||
1891 | (PCI_SLOT(dev->devfn) == PCI_SLOT(related->devfn))) | ||
1892 | break; | ||
1893 | dev = pci_get_device(vendor, device, dev); | ||
1894 | } | ||
1895 | |||
1896 | return dev; | ||
1897 | } | ||
1898 | |||
1899 | /* | ||
1900 | * syndrome mapping table for ECC ChipKill devices | ||
1901 | * | ||
1902 | * The comment in each row is the token (nibble) number that is in error. | ||
1903 | * The least significant nibble of the syndrome is the mask for the bits | ||
1904 | * that are in error (need to be toggled) for the particular nibble. | ||
1905 | * | ||
1906 | * Each row contains 16 entries. | ||
1907 | * The first entry (0th) is the channel number for that row of syndromes. | ||
1908 | * The remaining 15 entries are the syndromes for the respective Error | ||
1909 | * bit mask index. | ||
1910 | * | ||
1911 | * 1st index entry is 0x0001 mask, indicating that the rightmost bit is the | ||
1912 | * bit in error. | ||
1913 | * The 2nd index entry is 0x0010 that the second bit is damaged. | ||
1914 | * The 3rd index entry is 0x0011 indicating that the rightmost 2 bits | ||
1915 | * are damaged. | ||
1916 | * Thus so on until index 15, 0x1111, whose entry has the syndrome | ||
1917 | * indicating that all 4 bits are damaged. | ||
1918 | * | ||
1919 | * A search is performed on this table looking for a given syndrome. | ||
1920 | * | ||
1921 | * See the AMD documentation for ECC syndromes. This ECC table is valid | ||
1922 | * across all the versions of the AMD64 processors. | ||
1923 | * | ||
1924 | * A fast lookup is to use the LAST four bits of the 16-bit syndrome as a | ||
1925 | * COLUMN index, then search all ROWS of that column, looking for a match | ||
1926 | * with the input syndrome. The ROW value will be the token number. | ||
1927 | * | ||
1928 | * The 0'th entry on that row, can be returned as the CHANNEL (0 or 1) of this | ||
1929 | * error. | ||
1930 | */ | ||
1931 | #define NUMBER_ECC_ROWS 36 | ||
1932 | static const unsigned short ecc_chipkill_syndromes[NUMBER_ECC_ROWS][16] = { | ||
1933 | /* Channel 0 syndromes */ | ||
1934 | {/*0*/ 0, 0xe821, 0x7c32, 0x9413, 0xbb44, 0x5365, 0xc776, 0x2f57, | ||
1935 | 0xdd88, 0x35a9, 0xa1ba, 0x499b, 0x66cc, 0x8eed, 0x1afe, 0xf2df }, | ||
1936 | {/*1*/ 0, 0x5d31, 0xa612, 0xfb23, 0x9584, 0xc8b5, 0x3396, 0x6ea7, | ||
1937 | 0xeac8, 0xb7f9, 0x4cda, 0x11eb, 0x7f4c, 0x227d, 0xd95e, 0x846f }, | ||
1938 | {/*2*/ 0, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, | ||
1939 | 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f }, | ||
1940 | {/*3*/ 0, 0x2021, 0x3032, 0x1013, 0x4044, 0x6065, 0x7076, 0x5057, | ||
1941 | 0x8088, 0xa0a9, 0xb0ba, 0x909b, 0xc0cc, 0xe0ed, 0xf0fe, 0xd0df }, | ||
1942 | {/*4*/ 0, 0x5041, 0xa082, 0xf0c3, 0x9054, 0xc015, 0x30d6, 0x6097, | ||
1943 | 0xe0a8, 0xb0e9, 0x402a, 0x106b, 0x70fc, 0x20bd, 0xd07e, 0x803f }, | ||
1944 | {/*5*/ 0, 0xbe21, 0xd732, 0x6913, 0x2144, 0x9f65, 0xf676, 0x4857, | ||
1945 | 0x3288, 0x8ca9, 0xe5ba, 0x5b9b, 0x13cc, 0xaded, 0xc4fe, 0x7adf }, | ||
1946 | {/*6*/ 0, 0x4951, 0x8ea2, 0xc7f3, 0x5394, 0x1ac5, 0xdd36, 0x9467, | ||
1947 | 0xa1e8, 0xe8b9, 0x2f4a, 0x661b, 0xf27c, 0xbb2d, 0x7cde, 0x358f }, | ||
1948 | {/*7*/ 0, 0x74e1, 0x9872, 0xec93, 0xd6b4, 0xa255, 0x4ec6, 0x3a27, | ||
1949 | 0x6bd8, 0x1f39, 0xf3aa, 0x874b, 0xbd6c, 0xc98d, 0x251e, 0x51ff }, | ||
1950 | {/*8*/ 0, 0x15c1, 0x2a42, 0x3f83, 0xcef4, 0xdb35, 0xe4b6, 0xf177, | ||
1951 | 0x4758, 0x5299, 0x6d1a, 0x78db, 0x89ac, 0x9c6d, 0xa3ee, 0xb62f }, | ||
1952 | {/*9*/ 0, 0x3d01, 0x1602, 0x2b03, 0x8504, 0xb805, 0x9306, 0xae07, | ||
1953 | 0xca08, 0xf709, 0xdc0a, 0xe10b, 0x4f0c, 0x720d, 0x590e, 0x640f }, | ||
1954 | {/*a*/ 0, 0x9801, 0xec02, 0x7403, 0x6b04, 0xf305, 0x8706, 0x1f07, | ||
1955 | 0xbd08, 0x2509, 0x510a, 0xc90b, 0xd60c, 0x4e0d, 0x3a0e, 0xa20f }, | ||
1956 | {/*b*/ 0, 0xd131, 0x6212, 0xb323, 0x3884, 0xe9b5, 0x5a96, 0x8ba7, | ||
1957 | 0x1cc8, 0xcdf9, 0x7eda, 0xafeb, 0x244c, 0xf57d, 0x465e, 0x976f }, | ||
1958 | {/*c*/ 0, 0xe1d1, 0x7262, 0x93b3, 0xb834, 0x59e5, 0xca56, 0x2b87, | ||
1959 | 0xdc18, 0x3dc9, 0xae7a, 0x4fab, 0x542c, 0x85fd, 0x164e, 0xf79f }, | ||
1960 | {/*d*/ 0, 0x6051, 0xb0a2, 0xd0f3, 0x1094, 0x70c5, 0xa036, 0xc067, | ||
1961 | 0x20e8, 0x40b9, 0x904a, 0x601b, 0x307c, 0x502d, 0x80de, 0xe08f }, | ||
1962 | {/*e*/ 0, 0xa4c1, 0xf842, 0x5c83, 0xe6f4, 0x4235, 0x1eb6, 0xba77, | ||
1963 | 0x7b58, 0xdf99, 0x831a, 0x27db, 0x9dac, 0x396d, 0x65ee, 0xc12f }, | ||
1964 | {/*f*/ 0, 0x11c1, 0x2242, 0x3383, 0xc8f4, 0xd935, 0xeab6, 0xfb77, | ||
1965 | 0x4c58, 0x5d99, 0x6e1a, 0x7fdb, 0x84ac, 0x956d, 0xa6ee, 0xb72f }, | ||
1966 | |||
1967 | /* Channel 1 syndromes */ | ||
1968 | {/*10*/ 1, 0x45d1, 0x8a62, 0xcfb3, 0x5e34, 0x1be5, 0xd456, 0x9187, | ||
1969 | 0xa718, 0xe2c9, 0x2d7a, 0x68ab, 0xf92c, 0xbcfd, 0x734e, 0x369f }, | ||
1970 | {/*11*/ 1, 0x63e1, 0xb172, 0xd293, 0x14b4, 0x7755, 0xa5c6, 0xc627, | ||
1971 | 0x28d8, 0x4b39, 0x99aa, 0xfa4b, 0x3c6c, 0x5f8d, 0x8d1e, 0xeeff }, | ||
1972 | {/*12*/ 1, 0xb741, 0xd982, 0x6ec3, 0x2254, 0x9515, 0xfbd6, 0x4c97, | ||
1973 | 0x33a8, 0x84e9, 0xea2a, 0x5d6b, 0x11fc, 0xa6bd, 0xc87e, 0x7f3f }, | ||
1974 | {/*13*/ 1, 0xdd41, 0x6682, 0xbbc3, 0x3554, 0xe815, 0x53d6, 0xce97, | ||
1975 | 0x1aa8, 0xc7e9, 0x7c2a, 0xa1fb, 0x2ffc, 0xf2bd, 0x497e, 0x943f }, | ||
1976 | {/*14*/ 1, 0x2bd1, 0x3d62, 0x16b3, 0x4f34, 0x64e5, 0x7256, 0x5987, | ||
1977 | 0x8518, 0xaec9, 0xb87a, 0x93ab, 0xca2c, 0xe1fd, 0xf74e, 0xdc9f }, | ||
1978 | {/*15*/ 1, 0x83c1, 0xc142, 0x4283, 0xa4f4, 0x2735, 0x65b6, 0xe677, | ||
1979 | 0xf858, 0x7b99, 0x391a, 0xbadb, 0x5cac, 0xdf6d, 0x9dee, 0x1e2f }, | ||
1980 | {/*16*/ 1, 0x8fd1, 0xc562, 0x4ab3, 0xa934, 0x26e5, 0x6c56, 0xe387, | ||
1981 | 0xfe18, 0x71c9, 0x3b7a, 0xb4ab, 0x572c, 0xd8fd, 0x924e, 0x1d9f }, | ||
1982 | {/*17*/ 1, 0x4791, 0x89e2, 0xce73, 0x5264, 0x15f5, 0xdb86, 0x9c17, | ||
1983 | 0xa3b8, 0xe429, 0x2a5a, 0x6dcb, 0xf1dc, 0xb64d, 0x783e, 0x3faf }, | ||
1984 | {/*18*/ 1, 0x5781, 0xa9c2, 0xfe43, 0x92a4, 0xc525, 0x3b66, 0x6ce7, | ||
1985 | 0xe3f8, 0xb479, 0x4a3a, 0x1dbb, 0x715c, 0x26dd, 0xd89e, 0x8f1f }, | ||
1986 | {/*19*/ 1, 0xbf41, 0xd582, 0x6ac3, 0x2954, 0x9615, 0xfcd6, 0x4397, | ||
1987 | 0x3ea8, 0x81e9, 0xeb2a, 0x546b, 0x17fc, 0xa8bd, 0xc27e, 0x7d3f }, | ||
1988 | {/*1a*/ 1, 0x9891, 0xe1e2, 0x7273, 0x6464, 0xf7f5, 0x8586, 0x1617, | ||
1989 | 0xb8b8, 0x2b29, 0x595a, 0xcacb, 0xdcdc, 0x4f4d, 0x3d3e, 0xaeaf }, | ||
1990 | {/*1b*/ 1, 0xcce1, 0x4472, 0x8893, 0xfdb4, 0x3f55, 0xb9c6, 0x7527, | ||
1991 | 0x56d8, 0x9a39, 0x12aa, 0xde4b, 0xab6c, 0x678d, 0xef1e, 0x23ff }, | ||
1992 | {/*1c*/ 1, 0xa761, 0xf9b2, 0x5ed3, 0xe214, 0x4575, 0x1ba6, 0xbcc7, | ||
1993 | 0x7328, 0xd449, 0x8a9a, 0x2dfb, 0x913c, 0x365d, 0x688e, 0xcfef }, | ||
1994 | {/*1d*/ 1, 0xff61, 0x55b2, 0xaad3, 0x7914, 0x8675, 0x2ca6, 0xd3c7, | ||
1995 | 0x9e28, 0x6149, 0xcb9a, 0x34fb, 0xe73c, 0x185d, 0xb28e, 0x4def }, | ||
1996 | {/*1e*/ 1, 0x5451, 0xa8a2, 0xfcf3, 0x9694, 0xc2c5, 0x3e36, 0x6a67, | ||
1997 | 0xebe8, 0xbfb9, 0x434a, 0x171b, 0x7d7c, 0x292d, 0xd5de, 0x818f }, | ||
1998 | {/*1f*/ 1, 0x6fc1, 0xb542, 0xda83, 0x19f4, 0x7635, 0xacb6, 0xc377, | ||
1999 | 0x2e58, 0x4199, 0x9b1a, 0xf4db, 0x37ac, 0x586d, 0x82ee, 0xed2f }, | ||
2000 | |||
2001 | /* ECC bits are also in the set of tokens and they too can go bad | ||
2002 | * first 2 cover channel 0, while the second 2 cover channel 1 | ||
2003 | */ | ||
2004 | {/*20*/ 0, 0xbe01, 0xd702, 0x6903, 0x2104, 0x9f05, 0xf606, 0x4807, | ||
2005 | 0x3208, 0x8c09, 0xe50a, 0x5b0b, 0x130c, 0xad0d, 0xc40e, 0x7a0f }, | ||
2006 | {/*21*/ 0, 0x4101, 0x8202, 0xc303, 0x5804, 0x1905, 0xda06, 0x9b07, | ||
2007 | 0xac08, 0xed09, 0x2e0a, 0x6f0b, 0x640c, 0xb50d, 0x760e, 0x370f }, | ||
2008 | {/*22*/ 1, 0xc441, 0x4882, 0x8cc3, 0xf654, 0x3215, 0xbed6, 0x7a97, | ||
2009 | 0x5ba8, 0x9fe9, 0x132a, 0xd76b, 0xadfc, 0x69bd, 0xe57e, 0x213f }, | ||
2010 | {/*23*/ 1, 0x7621, 0x9b32, 0xed13, 0xda44, 0xac65, 0x4176, 0x3757, | ||
2011 | 0x6f88, 0x19a9, 0xf4ba, 0x829b, 0xb5cc, 0xc3ed, 0x2efe, 0x58df } | ||
2012 | }; | ||
2013 | |||
2014 | /* | ||
2015 | * Given the syndrome argument, scan each of the channel tables for a syndrome | ||
2016 | * match. Depending on which table it is found, return the channel number. | ||
2017 | */ | ||
2018 | static int get_channel_from_ecc_syndrome(unsigned short syndrome) | ||
2019 | { | ||
2020 | int row; | ||
2021 | int column; | ||
2022 | |||
2023 | /* Determine column to scan */ | ||
2024 | column = syndrome & 0xF; | ||
2025 | |||
2026 | /* Scan all rows, looking for syndrome, or end of table */ | ||
2027 | for (row = 0; row < NUMBER_ECC_ROWS; row++) { | ||
2028 | if (ecc_chipkill_syndromes[row][column] == syndrome) | ||
2029 | return ecc_chipkill_syndromes[row][0]; | ||
2030 | } | ||
2031 | |||
2032 | debugf0("syndrome(%x) not found\n", syndrome); | ||
2033 | return -1; | ||
2034 | } | ||
2035 | |||
2036 | /* | ||
2037 | * Check for valid error in the NB Status High register. If so, proceed to read | ||
2038 | * NB Status Low, NB Address Low and NB Address High registers and store data | ||
2039 | * into error structure. | ||
2040 | * | ||
2041 | * Returns: | ||
2042 | * - 1: if hardware regs contains valid error info | ||
2043 | * - 0: if no valid error is indicated | ||
2044 | */ | ||
2045 | static int amd64_get_error_info_regs(struct mem_ctl_info *mci, | ||
2046 | struct amd64_error_info_regs *regs) | ||
2047 | { | ||
2048 | struct amd64_pvt *pvt; | ||
2049 | struct pci_dev *misc_f3_ctl; | ||
2050 | int err = 0; | ||
2051 | |||
2052 | pvt = mci->pvt_info; | ||
2053 | misc_f3_ctl = pvt->misc_f3_ctl; | ||
2054 | |||
2055 | err = pci_read_config_dword(misc_f3_ctl, K8_NBSH, ®s->nbsh); | ||
2056 | if (err) | ||
2057 | goto err_reg; | ||
2058 | |||
2059 | if (!(regs->nbsh & K8_NBSH_VALID_BIT)) | ||
2060 | return 0; | ||
2061 | |||
2062 | /* valid error, read remaining error information registers */ | ||
2063 | err = pci_read_config_dword(misc_f3_ctl, K8_NBSL, ®s->nbsl); | ||
2064 | if (err) | ||
2065 | goto err_reg; | ||
2066 | |||
2067 | err = pci_read_config_dword(misc_f3_ctl, K8_NBEAL, ®s->nbeal); | ||
2068 | if (err) | ||
2069 | goto err_reg; | ||
2070 | |||
2071 | err = pci_read_config_dword(misc_f3_ctl, K8_NBEAH, ®s->nbeah); | ||
2072 | if (err) | ||
2073 | goto err_reg; | ||
2074 | |||
2075 | err = pci_read_config_dword(misc_f3_ctl, K8_NBCFG, ®s->nbcfg); | ||
2076 | if (err) | ||
2077 | goto err_reg; | ||
2078 | |||
2079 | return 1; | ||
2080 | |||
2081 | err_reg: | ||
2082 | debugf0("Reading error info register failed\n"); | ||
2083 | return 0; | ||
2084 | } | ||
2085 | |||
2086 | /* | ||
2087 | * This function is called to retrieve the error data from hardware and store it | ||
2088 | * in the info structure. | ||
2089 | * | ||
2090 | * Returns: | ||
2091 | * - 1: if a valid error is found | ||
2092 | * - 0: if no error is found | ||
2093 | */ | ||
2094 | static int amd64_get_error_info(struct mem_ctl_info *mci, | ||
2095 | struct amd64_error_info_regs *info) | ||
2096 | { | ||
2097 | struct amd64_pvt *pvt; | ||
2098 | struct amd64_error_info_regs regs; | ||
2099 | |||
2100 | pvt = mci->pvt_info; | ||
2101 | |||
2102 | if (!amd64_get_error_info_regs(mci, info)) | ||
2103 | return 0; | ||
2104 | |||
2105 | /* | ||
2106 | * Here's the problem with the K8's EDAC reporting: There are four | ||
2107 | * registers which report pieces of error information. They are shared | ||
2108 | * between CEs and UEs. Furthermore, contrary to what is stated in the | ||
2109 | * BKDG, the overflow bit is never used! Every error always updates the | ||
2110 | * reporting registers. | ||
2111 | * | ||
2112 | * Can you see the race condition? All four error reporting registers | ||
2113 | * must be read before a new error updates them! There is no way to read | ||
2114 | * all four registers atomically. The best than can be done is to detect | ||
2115 | * that a race has occured and then report the error without any kind of | ||
2116 | * precision. | ||
2117 | * | ||
2118 | * What is still positive is that errors are still reported and thus | ||
2119 | * problems can still be detected - just not localized because the | ||
2120 | * syndrome and address are spread out across registers. | ||
2121 | * | ||
2122 | * Grrrrr!!!!! Here's hoping that AMD fixes this in some future K8 rev. | ||
2123 | * UEs and CEs should have separate register sets with proper overflow | ||
2124 | * bits that are used! At very least the problem can be fixed by | ||
2125 | * honoring the ErrValid bit in 'nbsh' and not updating registers - just | ||
2126 | * set the overflow bit - unless the current error is CE and the new | ||
2127 | * error is UE which would be the only situation for overwriting the | ||
2128 | * current values. | ||
2129 | */ | ||
2130 | |||
2131 | regs = *info; | ||
2132 | |||
2133 | /* Use info from the second read - most current */ | ||
2134 | if (unlikely(!amd64_get_error_info_regs(mci, info))) | ||
2135 | return 0; | ||
2136 | |||
2137 | /* clear the error bits in hardware */ | ||
2138 | pci_write_bits32(pvt->misc_f3_ctl, K8_NBSH, 0, K8_NBSH_VALID_BIT); | ||
2139 | |||
2140 | /* Check for the possible race condition */ | ||
2141 | if ((regs.nbsh != info->nbsh) || | ||
2142 | (regs.nbsl != info->nbsl) || | ||
2143 | (regs.nbeah != info->nbeah) || | ||
2144 | (regs.nbeal != info->nbeal)) { | ||
2145 | amd64_mc_printk(mci, KERN_WARNING, | ||
2146 | "hardware STATUS read access race condition " | ||
2147 | "detected!\n"); | ||
2148 | return 0; | ||
2149 | } | ||
2150 | return 1; | ||
2151 | } | ||
2152 | |||
2153 | static inline void amd64_decode_gart_tlb_error(struct mem_ctl_info *mci, | ||
2154 | struct amd64_error_info_regs *info) | ||
2155 | { | ||
2156 | u32 err_code; | ||
2157 | u32 ec_tt; /* error code transaction type (2b) */ | ||
2158 | u32 ec_ll; /* error code cache level (2b) */ | ||
2159 | |||
2160 | err_code = EXTRACT_ERROR_CODE(info->nbsl); | ||
2161 | ec_ll = EXTRACT_LL_CODE(err_code); | ||
2162 | ec_tt = EXTRACT_TT_CODE(err_code); | ||
2163 | |||
2164 | amd64_mc_printk(mci, KERN_ERR, | ||
2165 | "GART TLB event: transaction type(%s), " | ||
2166 | "cache level(%s)\n", tt_msgs[ec_tt], ll_msgs[ec_ll]); | ||
2167 | } | ||
2168 | |||
2169 | static inline void amd64_decode_mem_cache_error(struct mem_ctl_info *mci, | ||
2170 | struct amd64_error_info_regs *info) | ||
2171 | { | ||
2172 | u32 err_code; | ||
2173 | u32 ec_rrrr; /* error code memory transaction (4b) */ | ||
2174 | u32 ec_tt; /* error code transaction type (2b) */ | ||
2175 | u32 ec_ll; /* error code cache level (2b) */ | ||
2176 | |||
2177 | err_code = EXTRACT_ERROR_CODE(info->nbsl); | ||
2178 | ec_ll = EXTRACT_LL_CODE(err_code); | ||
2179 | ec_tt = EXTRACT_TT_CODE(err_code); | ||
2180 | ec_rrrr = EXTRACT_RRRR_CODE(err_code); | ||
2181 | |||
2182 | amd64_mc_printk(mci, KERN_ERR, | ||
2183 | "cache hierarchy error: memory transaction type(%s), " | ||
2184 | "transaction type(%s), cache level(%s)\n", | ||
2185 | rrrr_msgs[ec_rrrr], tt_msgs[ec_tt], ll_msgs[ec_ll]); | ||
2186 | } | ||
2187 | |||
2188 | |||
2189 | /* | ||
2190 | * Handle any Correctable Errors (CEs) that have occurred. Check for valid ERROR | ||
2191 | * ADDRESS and process. | ||
2192 | */ | ||
2193 | static void amd64_handle_ce(struct mem_ctl_info *mci, | ||
2194 | struct amd64_error_info_regs *info) | ||
2195 | { | ||
2196 | struct amd64_pvt *pvt = mci->pvt_info; | ||
2197 | u64 SystemAddress; | ||
2198 | |||
2199 | /* Ensure that the Error Address is VALID */ | ||
2200 | if ((info->nbsh & K8_NBSH_VALID_ERROR_ADDR) == 0) { | ||
2201 | amd64_mc_printk(mci, KERN_ERR, | ||
2202 | "HW has no ERROR_ADDRESS available\n"); | ||
2203 | edac_mc_handle_ce_no_info(mci, EDAC_MOD_STR); | ||
2204 | return; | ||
2205 | } | ||
2206 | |||
2207 | SystemAddress = extract_error_address(mci, info); | ||
2208 | |||
2209 | amd64_mc_printk(mci, KERN_ERR, | ||
2210 | "CE ERROR_ADDRESS= 0x%llx\n", SystemAddress); | ||
2211 | |||
2212 | pvt->ops->map_sysaddr_to_csrow(mci, info, SystemAddress); | ||
2213 | } | ||
2214 | |||
2215 | /* Handle any Un-correctable Errors (UEs) */ | ||
2216 | static void amd64_handle_ue(struct mem_ctl_info *mci, | ||
2217 | struct amd64_error_info_regs *info) | ||
2218 | { | ||
2219 | int csrow; | ||
2220 | u64 SystemAddress; | ||
2221 | u32 page, offset; | ||
2222 | struct mem_ctl_info *log_mci, *src_mci = NULL; | ||
2223 | |||
2224 | log_mci = mci; | ||
2225 | |||
2226 | if ((info->nbsh & K8_NBSH_VALID_ERROR_ADDR) == 0) { | ||
2227 | amd64_mc_printk(mci, KERN_CRIT, | ||
2228 | "HW has no ERROR_ADDRESS available\n"); | ||
2229 | edac_mc_handle_ue_no_info(log_mci, EDAC_MOD_STR); | ||
2230 | return; | ||
2231 | } | ||
2232 | |||
2233 | SystemAddress = extract_error_address(mci, info); | ||
2234 | |||
2235 | /* | ||
2236 | * Find out which node the error address belongs to. This may be | ||
2237 | * different from the node that detected the error. | ||
2238 | */ | ||
2239 | src_mci = find_mc_by_sys_addr(mci, SystemAddress); | ||
2240 | if (!src_mci) { | ||
2241 | amd64_mc_printk(mci, KERN_CRIT, | ||
2242 | "ERROR ADDRESS (0x%lx) value NOT mapped to a MC\n", | ||
2243 | (unsigned long)SystemAddress); | ||
2244 | edac_mc_handle_ue_no_info(log_mci, EDAC_MOD_STR); | ||
2245 | return; | ||
2246 | } | ||
2247 | |||
2248 | log_mci = src_mci; | ||
2249 | |||
2250 | csrow = sys_addr_to_csrow(log_mci, SystemAddress); | ||
2251 | if (csrow < 0) { | ||
2252 | amd64_mc_printk(mci, KERN_CRIT, | ||
2253 | "ERROR_ADDRESS (0x%lx) value NOT mapped to 'csrow'\n", | ||
2254 | (unsigned long)SystemAddress); | ||
2255 | edac_mc_handle_ue_no_info(log_mci, EDAC_MOD_STR); | ||
2256 | } else { | ||
2257 | error_address_to_page_and_offset(SystemAddress, &page, &offset); | ||
2258 | edac_mc_handle_ue(log_mci, page, offset, csrow, EDAC_MOD_STR); | ||
2259 | } | ||
2260 | } | ||
2261 | |||
2262 | static void amd64_decode_bus_error(struct mem_ctl_info *mci, | ||
2263 | struct amd64_error_info_regs *info) | ||
2264 | { | ||
2265 | u32 err_code, ext_ec; | ||
2266 | u32 ec_pp; /* error code participating processor (2p) */ | ||
2267 | u32 ec_to; /* error code timed out (1b) */ | ||
2268 | u32 ec_rrrr; /* error code memory transaction (4b) */ | ||
2269 | u32 ec_ii; /* error code memory or I/O (2b) */ | ||
2270 | u32 ec_ll; /* error code cache level (2b) */ | ||
2271 | |||
2272 | ext_ec = EXTRACT_EXT_ERROR_CODE(info->nbsl); | ||
2273 | err_code = EXTRACT_ERROR_CODE(info->nbsl); | ||
2274 | |||
2275 | ec_ll = EXTRACT_LL_CODE(err_code); | ||
2276 | ec_ii = EXTRACT_II_CODE(err_code); | ||
2277 | ec_rrrr = EXTRACT_RRRR_CODE(err_code); | ||
2278 | ec_to = EXTRACT_TO_CODE(err_code); | ||
2279 | ec_pp = EXTRACT_PP_CODE(err_code); | ||
2280 | |||
2281 | amd64_mc_printk(mci, KERN_ERR, | ||
2282 | "BUS ERROR:\n" | ||
2283 | " time-out(%s) mem or i/o(%s)\n" | ||
2284 | " participating processor(%s)\n" | ||
2285 | " memory transaction type(%s)\n" | ||
2286 | " cache level(%s) Error Found by: %s\n", | ||
2287 | to_msgs[ec_to], | ||
2288 | ii_msgs[ec_ii], | ||
2289 | pp_msgs[ec_pp], | ||
2290 | rrrr_msgs[ec_rrrr], | ||
2291 | ll_msgs[ec_ll], | ||
2292 | (info->nbsh & K8_NBSH_ERR_SCRUBER) ? | ||
2293 | "Scrubber" : "Normal Operation"); | ||
2294 | |||
2295 | /* If this was an 'observed' error, early out */ | ||
2296 | if (ec_pp == K8_NBSL_PP_OBS) | ||
2297 | return; /* We aren't the node involved */ | ||
2298 | |||
2299 | /* Parse out the extended error code for ECC events */ | ||
2300 | switch (ext_ec) { | ||
2301 | /* F10 changed to one Extended ECC error code */ | ||
2302 | case F10_NBSL_EXT_ERR_RES: /* Reserved field */ | ||
2303 | case F10_NBSL_EXT_ERR_ECC: /* F10 ECC ext err code */ | ||
2304 | break; | ||
2305 | |||
2306 | default: | ||
2307 | amd64_mc_printk(mci, KERN_ERR, "NOT ECC: no special error " | ||
2308 | "handling for this error\n"); | ||
2309 | return; | ||
2310 | } | ||
2311 | |||
2312 | if (info->nbsh & K8_NBSH_CECC) | ||
2313 | amd64_handle_ce(mci, info); | ||
2314 | else if (info->nbsh & K8_NBSH_UECC) | ||
2315 | amd64_handle_ue(mci, info); | ||
2316 | |||
2317 | /* | ||
2318 | * If main error is CE then overflow must be CE. If main error is UE | ||
2319 | * then overflow is unknown. We'll call the overflow a CE - if | ||
2320 | * panic_on_ue is set then we're already panic'ed and won't arrive | ||
2321 | * here. Else, then apparently someone doesn't think that UE's are | ||
2322 | * catastrophic. | ||
2323 | */ | ||
2324 | if (info->nbsh & K8_NBSH_OVERFLOW) | ||
2325 | edac_mc_handle_ce_no_info(mci, EDAC_MOD_STR | ||
2326 | "Error Overflow set"); | ||
2327 | } | ||
2328 | |||
2329 | int amd64_process_error_info(struct mem_ctl_info *mci, | ||
2330 | struct amd64_error_info_regs *info, | ||
2331 | int handle_errors) | ||
2332 | { | ||
2333 | struct amd64_pvt *pvt; | ||
2334 | struct amd64_error_info_regs *regs; | ||
2335 | u32 err_code, ext_ec; | ||
2336 | int gart_tlb_error = 0; | ||
2337 | |||
2338 | pvt = mci->pvt_info; | ||
2339 | |||
2340 | /* If caller doesn't want us to process the error, return */ | ||
2341 | if (!handle_errors) | ||
2342 | return 1; | ||
2343 | |||
2344 | regs = info; | ||
2345 | |||
2346 | debugf1("NorthBridge ERROR: mci(0x%p)\n", mci); | ||
2347 | debugf1(" MC node(%d) Error-Address(0x%.8x-%.8x)\n", | ||
2348 | pvt->mc_node_id, regs->nbeah, regs->nbeal); | ||
2349 | debugf1(" nbsh(0x%.8x) nbsl(0x%.8x)\n", | ||
2350 | regs->nbsh, regs->nbsl); | ||
2351 | debugf1(" Valid Error=%s Overflow=%s\n", | ||
2352 | (regs->nbsh & K8_NBSH_VALID_BIT) ? "True" : "False", | ||
2353 | (regs->nbsh & K8_NBSH_OVERFLOW) ? "True" : "False"); | ||
2354 | debugf1(" Err Uncorrected=%s MCA Error Reporting=%s\n", | ||
2355 | (regs->nbsh & K8_NBSH_UNCORRECTED_ERR) ? | ||
2356 | "True" : "False", | ||
2357 | (regs->nbsh & K8_NBSH_ERR_ENABLE) ? | ||
2358 | "True" : "False"); | ||
2359 | debugf1(" MiscErr Valid=%s ErrAddr Valid=%s PCC=%s\n", | ||
2360 | (regs->nbsh & K8_NBSH_MISC_ERR_VALID) ? | ||
2361 | "True" : "False", | ||
2362 | (regs->nbsh & K8_NBSH_VALID_ERROR_ADDR) ? | ||
2363 | "True" : "False", | ||
2364 | (regs->nbsh & K8_NBSH_PCC) ? | ||
2365 | "True" : "False"); | ||
2366 | debugf1(" CECC=%s UECC=%s Found by Scruber=%s\n", | ||
2367 | (regs->nbsh & K8_NBSH_CECC) ? | ||
2368 | "True" : "False", | ||
2369 | (regs->nbsh & K8_NBSH_UECC) ? | ||
2370 | "True" : "False", | ||
2371 | (regs->nbsh & K8_NBSH_ERR_SCRUBER) ? | ||
2372 | "True" : "False"); | ||
2373 | debugf1(" CORE0=%s CORE1=%s CORE2=%s CORE3=%s\n", | ||
2374 | (regs->nbsh & K8_NBSH_CORE0) ? "True" : "False", | ||
2375 | (regs->nbsh & K8_NBSH_CORE1) ? "True" : "False", | ||
2376 | (regs->nbsh & K8_NBSH_CORE2) ? "True" : "False", | ||
2377 | (regs->nbsh & K8_NBSH_CORE3) ? "True" : "False"); | ||
2378 | |||
2379 | |||
2380 | err_code = EXTRACT_ERROR_CODE(regs->nbsl); | ||
2381 | |||
2382 | /* Determine which error type: | ||
2383 | * 1) GART errors - non-fatal, developmental events | ||
2384 | * 2) MEMORY errors | ||
2385 | * 3) BUS errors | ||
2386 | * 4) Unknown error | ||
2387 | */ | ||
2388 | if (TEST_TLB_ERROR(err_code)) { | ||
2389 | /* | ||
2390 | * GART errors are intended to help graphics driver developers | ||
2391 | * to detect bad GART PTEs. It is recommended by AMD to disable | ||
2392 | * GART table walk error reporting by default[1] (currently | ||
2393 | * being disabled in mce_cpu_quirks()) and according to the | ||
2394 | * comment in mce_cpu_quirks(), such GART errors can be | ||
2395 | * incorrectly triggered. We may see these errors anyway and | ||
2396 | * unless requested by the user, they won't be reported. | ||
2397 | * | ||
2398 | * [1] section 13.10.1 on BIOS and Kernel Developers Guide for | ||
2399 | * AMD NPT family 0Fh processors | ||
2400 | */ | ||
2401 | if (report_gart_errors == 0) | ||
2402 | return 1; | ||
2403 | |||
2404 | /* | ||
2405 | * Only if GART error reporting is requested should we generate | ||
2406 | * any logs. | ||
2407 | */ | ||
2408 | gart_tlb_error = 1; | ||
2409 | |||
2410 | debugf1("GART TLB error\n"); | ||
2411 | amd64_decode_gart_tlb_error(mci, info); | ||
2412 | } else if (TEST_MEM_ERROR(err_code)) { | ||
2413 | debugf1("Memory/Cache error\n"); | ||
2414 | amd64_decode_mem_cache_error(mci, info); | ||
2415 | } else if (TEST_BUS_ERROR(err_code)) { | ||
2416 | debugf1("Bus (Link/DRAM) error\n"); | ||
2417 | amd64_decode_bus_error(mci, info); | ||
2418 | } else { | ||
2419 | /* shouldn't reach here! */ | ||
2420 | amd64_mc_printk(mci, KERN_WARNING, | ||
2421 | "%s(): unknown MCE error 0x%x\n", __func__, | ||
2422 | err_code); | ||
2423 | } | ||
2424 | |||
2425 | ext_ec = EXTRACT_EXT_ERROR_CODE(regs->nbsl); | ||
2426 | amd64_mc_printk(mci, KERN_ERR, | ||
2427 | "ExtErr=(0x%x) %s\n", ext_ec, ext_msgs[ext_ec]); | ||
2428 | |||
2429 | if (((ext_ec >= F10_NBSL_EXT_ERR_CRC && | ||
2430 | ext_ec <= F10_NBSL_EXT_ERR_TGT) || | ||
2431 | (ext_ec == F10_NBSL_EXT_ERR_RMW)) && | ||
2432 | EXTRACT_LDT_LINK(info->nbsh)) { | ||
2433 | |||
2434 | amd64_mc_printk(mci, KERN_ERR, | ||
2435 | "Error on hypertransport link: %s\n", | ||
2436 | htlink_msgs[ | ||
2437 | EXTRACT_LDT_LINK(info->nbsh)]); | ||
2438 | } | ||
2439 | |||
2440 | /* | ||
2441 | * Check the UE bit of the NB status high register, if set generate some | ||
2442 | * logs. If NOT a GART error, then process the event as a NO-INFO event. | ||
2443 | * If it was a GART error, skip that process. | ||
2444 | */ | ||
2445 | if (regs->nbsh & K8_NBSH_UNCORRECTED_ERR) { | ||
2446 | amd64_mc_printk(mci, KERN_CRIT, "uncorrected error\n"); | ||
2447 | if (!gart_tlb_error) | ||
2448 | edac_mc_handle_ue_no_info(mci, "UE bit is set\n"); | ||
2449 | } | ||
2450 | |||
2451 | if (regs->nbsh & K8_NBSH_PCC) | ||
2452 | amd64_mc_printk(mci, KERN_CRIT, | ||
2453 | "PCC (processor context corrupt) set\n"); | ||
2454 | |||
2455 | return 1; | ||
2456 | } | ||
2457 | EXPORT_SYMBOL_GPL(amd64_process_error_info); | ||
2458 | |||
2459 | /* | ||
2460 | * The main polling 'check' function, called FROM the edac core to perform the | ||
2461 | * error checking and if an error is encountered, error processing. | ||
2462 | */ | ||
2463 | static void amd64_check(struct mem_ctl_info *mci) | ||
2464 | { | ||
2465 | struct amd64_error_info_regs info; | ||
2466 | |||
2467 | if (amd64_get_error_info(mci, &info)) | ||
2468 | amd64_process_error_info(mci, &info, 1); | ||
2469 | } | ||
2470 | |||
2471 | /* | ||
2472 | * Input: | ||
2473 | * 1) struct amd64_pvt which contains pvt->dram_f2_ctl pointer | ||
2474 | * 2) AMD Family index value | ||
2475 | * | ||
2476 | * Ouput: | ||
2477 | * Upon return of 0, the following filled in: | ||
2478 | * | ||
2479 | * struct pvt->addr_f1_ctl | ||
2480 | * struct pvt->misc_f3_ctl | ||
2481 | * | ||
2482 | * Filled in with related device funcitions of 'dram_f2_ctl' | ||
2483 | * These devices are "reserved" via the pci_get_device() | ||
2484 | * | ||
2485 | * Upon return of 1 (error status): | ||
2486 | * | ||
2487 | * Nothing reserved | ||
2488 | */ | ||
2489 | static int amd64_reserve_mc_sibling_devices(struct amd64_pvt *pvt, int mc_idx) | ||
2490 | { | ||
2491 | const struct amd64_family_type *amd64_dev = &amd64_family_types[mc_idx]; | ||
2492 | |||
2493 | /* Reserve the ADDRESS MAP Device */ | ||
2494 | pvt->addr_f1_ctl = pci_get_related_function(pvt->dram_f2_ctl->vendor, | ||
2495 | amd64_dev->addr_f1_ctl, | ||
2496 | pvt->dram_f2_ctl); | ||
2497 | |||
2498 | if (!pvt->addr_f1_ctl) { | ||
2499 | amd64_printk(KERN_ERR, "error address map device not found: " | ||
2500 | "vendor %x device 0x%x (broken BIOS?)\n", | ||
2501 | PCI_VENDOR_ID_AMD, amd64_dev->addr_f1_ctl); | ||
2502 | return 1; | ||
2503 | } | ||
2504 | |||
2505 | /* Reserve the MISC Device */ | ||
2506 | pvt->misc_f3_ctl = pci_get_related_function(pvt->dram_f2_ctl->vendor, | ||
2507 | amd64_dev->misc_f3_ctl, | ||
2508 | pvt->dram_f2_ctl); | ||
2509 | |||
2510 | if (!pvt->misc_f3_ctl) { | ||
2511 | pci_dev_put(pvt->addr_f1_ctl); | ||
2512 | pvt->addr_f1_ctl = NULL; | ||
2513 | |||
2514 | amd64_printk(KERN_ERR, "error miscellaneous device not found: " | ||
2515 | "vendor %x device 0x%x (broken BIOS?)\n", | ||
2516 | PCI_VENDOR_ID_AMD, amd64_dev->misc_f3_ctl); | ||
2517 | return 1; | ||
2518 | } | ||
2519 | |||
2520 | debugf1(" Addr Map device PCI Bus ID:\t%s\n", | ||
2521 | pci_name(pvt->addr_f1_ctl)); | ||
2522 | debugf1(" DRAM MEM-CTL PCI Bus ID:\t%s\n", | ||
2523 | pci_name(pvt->dram_f2_ctl)); | ||
2524 | debugf1(" Misc device PCI Bus ID:\t%s\n", | ||
2525 | pci_name(pvt->misc_f3_ctl)); | ||
2526 | |||
2527 | return 0; | ||
2528 | } | ||
2529 | |||
2530 | static void amd64_free_mc_sibling_devices(struct amd64_pvt *pvt) | ||
2531 | { | ||
2532 | pci_dev_put(pvt->addr_f1_ctl); | ||
2533 | pci_dev_put(pvt->misc_f3_ctl); | ||
2534 | } | ||
2535 | |||
2536 | /* | ||
2537 | * Retrieve the hardware registers of the memory controller (this includes the | ||
2538 | * 'Address Map' and 'Misc' device regs) | ||
2539 | */ | ||
2540 | static void amd64_read_mc_registers(struct amd64_pvt *pvt) | ||
2541 | { | ||
2542 | u64 msr_val; | ||
2543 | int dram, err = 0; | ||
2544 | |||
2545 | /* | ||
2546 | * Retrieve TOP_MEM and TOP_MEM2; no masking off of reserved bits since | ||
2547 | * those are Read-As-Zero | ||
2548 | */ | ||
2549 | rdmsrl(MSR_K8_TOP_MEM1, msr_val); | ||
2550 | pvt->top_mem = msr_val >> 23; | ||
2551 | debugf0(" TOP_MEM=0x%08llx\n", pvt->top_mem); | ||
2552 | |||
2553 | /* check first whether TOP_MEM2 is enabled */ | ||
2554 | rdmsrl(MSR_K8_SYSCFG, msr_val); | ||
2555 | if (msr_val & (1U << 21)) { | ||
2556 | rdmsrl(MSR_K8_TOP_MEM2, msr_val); | ||
2557 | pvt->top_mem2 = msr_val >> 23; | ||
2558 | debugf0(" TOP_MEM2=0x%08llx\n", pvt->top_mem2); | ||
2559 | } else | ||
2560 | debugf0(" TOP_MEM2 disabled.\n"); | ||
2561 | |||
2562 | amd64_cpu_display_info(pvt); | ||
2563 | |||
2564 | err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCAP, &pvt->nbcap); | ||
2565 | if (err) | ||
2566 | goto err_reg; | ||
2567 | |||
2568 | if (pvt->ops->read_dram_ctl_register) | ||
2569 | pvt->ops->read_dram_ctl_register(pvt); | ||
2570 | |||
2571 | for (dram = 0; dram < DRAM_REG_COUNT; dram++) { | ||
2572 | /* | ||
2573 | * Call CPU specific READ function to get the DRAM Base and | ||
2574 | * Limit values from the DCT. | ||
2575 | */ | ||
2576 | pvt->ops->read_dram_base_limit(pvt, dram); | ||
2577 | |||
2578 | /* | ||
2579 | * Only print out debug info on rows with both R and W Enabled. | ||
2580 | * Normal processing, compiler should optimize this whole 'if' | ||
2581 | * debug output block away. | ||
2582 | */ | ||
2583 | if (pvt->dram_rw_en[dram] != 0) { | ||
2584 | debugf1(" DRAM_BASE[%d]: 0x%8.08x-%8.08x " | ||
2585 | "DRAM_LIMIT: 0x%8.08x-%8.08x\n", | ||
2586 | dram, | ||
2587 | (u32)(pvt->dram_base[dram] >> 32), | ||
2588 | (u32)(pvt->dram_base[dram] & 0xFFFFFFFF), | ||
2589 | (u32)(pvt->dram_limit[dram] >> 32), | ||
2590 | (u32)(pvt->dram_limit[dram] & 0xFFFFFFFF)); | ||
2591 | debugf1(" IntlvEn=%s %s %s " | ||
2592 | "IntlvSel=%d DstNode=%d\n", | ||
2593 | pvt->dram_IntlvEn[dram] ? | ||
2594 | "Enabled" : "Disabled", | ||
2595 | (pvt->dram_rw_en[dram] & 0x2) ? "W" : "!W", | ||
2596 | (pvt->dram_rw_en[dram] & 0x1) ? "R" : "!R", | ||
2597 | pvt->dram_IntlvSel[dram], | ||
2598 | pvt->dram_DstNode[dram]); | ||
2599 | } | ||
2600 | } | ||
2601 | |||
2602 | amd64_read_dct_base_mask(pvt); | ||
2603 | |||
2604 | err = pci_read_config_dword(pvt->addr_f1_ctl, K8_DHAR, &pvt->dhar); | ||
2605 | if (err) | ||
2606 | goto err_reg; | ||
2607 | |||
2608 | amd64_read_dbam_reg(pvt); | ||
2609 | |||
2610 | err = pci_read_config_dword(pvt->misc_f3_ctl, | ||
2611 | F10_ONLINE_SPARE, &pvt->online_spare); | ||
2612 | if (err) | ||
2613 | goto err_reg; | ||
2614 | |||
2615 | err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCLR_0, &pvt->dclr0); | ||
2616 | if (err) | ||
2617 | goto err_reg; | ||
2618 | |||
2619 | err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCHR_0, &pvt->dchr0); | ||
2620 | if (err) | ||
2621 | goto err_reg; | ||
2622 | |||
2623 | if (!dct_ganging_enabled(pvt)) { | ||
2624 | err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCLR_1, | ||
2625 | &pvt->dclr1); | ||
2626 | if (err) | ||
2627 | goto err_reg; | ||
2628 | |||
2629 | err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCHR_1, | ||
2630 | &pvt->dchr1); | ||
2631 | if (err) | ||
2632 | goto err_reg; | ||
2633 | } | ||
2634 | |||
2635 | amd64_dump_misc_regs(pvt); | ||
2636 | |||
2637 | err_reg: | ||
2638 | debugf0("Reading an MC register failed\n"); | ||
2639 | |||
2640 | } | ||
2641 | |||
2642 | /* | ||
2643 | * NOTE: CPU Revision Dependent code | ||
2644 | * | ||
2645 | * Input: | ||
2646 | * @csrow_nr ChipSelect Row Number (0..CHIPSELECT_COUNT-1) | ||
2647 | * k8 private pointer to --> | ||
2648 | * DRAM Bank Address mapping register | ||
2649 | * node_id | ||
2650 | * DCL register where dual_channel_active is | ||
2651 | * | ||
2652 | * The DBAM register consists of 4 sets of 4 bits each definitions: | ||
2653 | * | ||
2654 | * Bits: CSROWs | ||
2655 | * 0-3 CSROWs 0 and 1 | ||
2656 | * 4-7 CSROWs 2 and 3 | ||
2657 | * 8-11 CSROWs 4 and 5 | ||
2658 | * 12-15 CSROWs 6 and 7 | ||
2659 | * | ||
2660 | * Values range from: 0 to 15 | ||
2661 | * The meaning of the values depends on CPU revision and dual-channel state, | ||
2662 | * see relevant BKDG more info. | ||
2663 | * | ||
2664 | * The memory controller provides for total of only 8 CSROWs in its current | ||
2665 | * architecture. Each "pair" of CSROWs normally represents just one DIMM in | ||
2666 | * single channel or two (2) DIMMs in dual channel mode. | ||
2667 | * | ||
2668 | * The following code logic collapses the various tables for CSROW based on CPU | ||
2669 | * revision. | ||
2670 | * | ||
2671 | * Returns: | ||
2672 | * The number of PAGE_SIZE pages on the specified CSROW number it | ||
2673 | * encompasses | ||
2674 | * | ||
2675 | */ | ||
2676 | static u32 amd64_csrow_nr_pages(int csrow_nr, struct amd64_pvt *pvt) | ||
2677 | { | ||
2678 | u32 dram_map, nr_pages; | ||
2679 | |||
2680 | /* | ||
2681 | * The math on this doesn't look right on the surface because x/2*4 can | ||
2682 | * be simplified to x*2 but this expression makes use of the fact that | ||
2683 | * it is integral math where 1/2=0. This intermediate value becomes the | ||
2684 | * number of bits to shift the DBAM register to extract the proper CSROW | ||
2685 | * field. | ||
2686 | */ | ||
2687 | dram_map = (pvt->dbam0 >> ((csrow_nr / 2) * 4)) & 0xF; | ||
2688 | |||
2689 | nr_pages = pvt->ops->dbam_map_to_pages(pvt, dram_map); | ||
2690 | |||
2691 | /* | ||
2692 | * If dual channel then double the memory size of single channel. | ||
2693 | * Channel count is 1 or 2 | ||
2694 | */ | ||
2695 | nr_pages <<= (pvt->channel_count - 1); | ||
2696 | |||
2697 | debugf0(" (csrow=%d) DBAM map index= %d\n", csrow_nr, dram_map); | ||
2698 | debugf0(" nr_pages= %u channel-count = %d\n", | ||
2699 | nr_pages, pvt->channel_count); | ||
2700 | |||
2701 | return nr_pages; | ||
2702 | } | ||
2703 | |||
2704 | /* | ||
2705 | * Initialize the array of csrow attribute instances, based on the values | ||
2706 | * from pci config hardware registers. | ||
2707 | */ | ||
2708 | static int amd64_init_csrows(struct mem_ctl_info *mci) | ||
2709 | { | ||
2710 | struct csrow_info *csrow; | ||
2711 | struct amd64_pvt *pvt; | ||
2712 | u64 input_addr_min, input_addr_max, sys_addr; | ||
2713 | int i, err = 0, empty = 1; | ||
2714 | |||
2715 | pvt = mci->pvt_info; | ||
2716 | |||
2717 | err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCFG, &pvt->nbcfg); | ||
2718 | if (err) | ||
2719 | debugf0("Reading K8_NBCFG failed\n"); | ||
2720 | |||
2721 | debugf0("NBCFG= 0x%x CHIPKILL= %s DRAM ECC= %s\n", pvt->nbcfg, | ||
2722 | (pvt->nbcfg & K8_NBCFG_CHIPKILL) ? "Enabled" : "Disabled", | ||
2723 | (pvt->nbcfg & K8_NBCFG_ECC_ENABLE) ? "Enabled" : "Disabled" | ||
2724 | ); | ||
2725 | |||
2726 | for (i = 0; i < CHIPSELECT_COUNT; i++) { | ||
2727 | csrow = &mci->csrows[i]; | ||
2728 | |||
2729 | if ((pvt->dcsb0[i] & K8_DCSB_CS_ENABLE) == 0) { | ||
2730 | debugf1("----CSROW %d EMPTY for node %d\n", i, | ||
2731 | pvt->mc_node_id); | ||
2732 | continue; | ||
2733 | } | ||
2734 | |||
2735 | debugf1("----CSROW %d VALID for MC node %d\n", | ||
2736 | i, pvt->mc_node_id); | ||
2737 | |||
2738 | empty = 0; | ||
2739 | csrow->nr_pages = amd64_csrow_nr_pages(i, pvt); | ||
2740 | find_csrow_limits(mci, i, &input_addr_min, &input_addr_max); | ||
2741 | sys_addr = input_addr_to_sys_addr(mci, input_addr_min); | ||
2742 | csrow->first_page = (u32) (sys_addr >> PAGE_SHIFT); | ||
2743 | sys_addr = input_addr_to_sys_addr(mci, input_addr_max); | ||
2744 | csrow->last_page = (u32) (sys_addr >> PAGE_SHIFT); | ||
2745 | csrow->page_mask = ~mask_from_dct_mask(pvt, i); | ||
2746 | /* 8 bytes of resolution */ | ||
2747 | |||
2748 | csrow->mtype = amd64_determine_memory_type(pvt); | ||
2749 | |||
2750 | debugf1(" for MC node %d csrow %d:\n", pvt->mc_node_id, i); | ||
2751 | debugf1(" input_addr_min: 0x%lx input_addr_max: 0x%lx\n", | ||
2752 | (unsigned long)input_addr_min, | ||
2753 | (unsigned long)input_addr_max); | ||
2754 | debugf1(" sys_addr: 0x%lx page_mask: 0x%lx\n", | ||
2755 | (unsigned long)sys_addr, csrow->page_mask); | ||
2756 | debugf1(" nr_pages: %u first_page: 0x%lx " | ||
2757 | "last_page: 0x%lx\n", | ||
2758 | (unsigned)csrow->nr_pages, | ||
2759 | csrow->first_page, csrow->last_page); | ||
2760 | |||
2761 | /* | ||
2762 | * determine whether CHIPKILL or JUST ECC or NO ECC is operating | ||
2763 | */ | ||
2764 | if (pvt->nbcfg & K8_NBCFG_ECC_ENABLE) | ||
2765 | csrow->edac_mode = | ||
2766 | (pvt->nbcfg & K8_NBCFG_CHIPKILL) ? | ||
2767 | EDAC_S4ECD4ED : EDAC_SECDED; | ||
2768 | else | ||
2769 | csrow->edac_mode = EDAC_NONE; | ||
2770 | } | ||
2771 | |||
2772 | return empty; | ||
2773 | } | ||
2774 | |||
2775 | /* | ||
2776 | * Only if 'ecc_enable_override' is set AND BIOS had ECC disabled, do "we" | ||
2777 | * enable it. | ||
2778 | */ | ||
2779 | static void amd64_enable_ecc_error_reporting(struct mem_ctl_info *mci) | ||
2780 | { | ||
2781 | struct amd64_pvt *pvt = mci->pvt_info; | ||
2782 | const cpumask_t *cpumask = cpumask_of_node(pvt->mc_node_id); | ||
2783 | int cpu, idx = 0, err = 0; | ||
2784 | struct msr msrs[cpumask_weight(cpumask)]; | ||
2785 | u32 value; | ||
2786 | u32 mask = K8_NBCTL_CECCEn | K8_NBCTL_UECCEn; | ||
2787 | |||
2788 | if (!ecc_enable_override) | ||
2789 | return; | ||
2790 | |||
2791 | memset(msrs, 0, sizeof(msrs)); | ||
2792 | |||
2793 | amd64_printk(KERN_WARNING, | ||
2794 | "'ecc_enable_override' parameter is active, " | ||
2795 | "Enabling AMD ECC hardware now: CAUTION\n"); | ||
2796 | |||
2797 | err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCTL, &value); | ||
2798 | if (err) | ||
2799 | debugf0("Reading K8_NBCTL failed\n"); | ||
2800 | |||
2801 | /* turn on UECCn and CECCEn bits */ | ||
2802 | pvt->old_nbctl = value & mask; | ||
2803 | pvt->nbctl_mcgctl_saved = 1; | ||
2804 | |||
2805 | value |= mask; | ||
2806 | pci_write_config_dword(pvt->misc_f3_ctl, K8_NBCTL, value); | ||
2807 | |||
2808 | rdmsr_on_cpus(cpumask, K8_MSR_MCGCTL, msrs); | ||
2809 | |||
2810 | for_each_cpu(cpu, cpumask) { | ||
2811 | if (msrs[idx].l & K8_MSR_MCGCTL_NBE) | ||
2812 | set_bit(idx, &pvt->old_mcgctl); | ||
2813 | |||
2814 | msrs[idx].l |= K8_MSR_MCGCTL_NBE; | ||
2815 | idx++; | ||
2816 | } | ||
2817 | wrmsr_on_cpus(cpumask, K8_MSR_MCGCTL, msrs); | ||
2818 | |||
2819 | err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCFG, &value); | ||
2820 | if (err) | ||
2821 | debugf0("Reading K8_NBCFG failed\n"); | ||
2822 | |||
2823 | debugf0("NBCFG(1)= 0x%x CHIPKILL= %s ECC_ENABLE= %s\n", value, | ||
2824 | (value & K8_NBCFG_CHIPKILL) ? "Enabled" : "Disabled", | ||
2825 | (value & K8_NBCFG_ECC_ENABLE) ? "Enabled" : "Disabled"); | ||
2826 | |||
2827 | if (!(value & K8_NBCFG_ECC_ENABLE)) { | ||
2828 | amd64_printk(KERN_WARNING, | ||
2829 | "This node reports that DRAM ECC is " | ||
2830 | "currently Disabled; ENABLING now\n"); | ||
2831 | |||
2832 | /* Attempt to turn on DRAM ECC Enable */ | ||
2833 | value |= K8_NBCFG_ECC_ENABLE; | ||
2834 | pci_write_config_dword(pvt->misc_f3_ctl, K8_NBCFG, value); | ||
2835 | |||
2836 | err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCFG, &value); | ||
2837 | if (err) | ||
2838 | debugf0("Reading K8_NBCFG failed\n"); | ||
2839 | |||
2840 | if (!(value & K8_NBCFG_ECC_ENABLE)) { | ||
2841 | amd64_printk(KERN_WARNING, | ||
2842 | "Hardware rejects Enabling DRAM ECC checking\n" | ||
2843 | "Check memory DIMM configuration\n"); | ||
2844 | } else { | ||
2845 | amd64_printk(KERN_DEBUG, | ||
2846 | "Hardware accepted DRAM ECC Enable\n"); | ||
2847 | } | ||
2848 | } | ||
2849 | debugf0("NBCFG(2)= 0x%x CHIPKILL= %s ECC_ENABLE= %s\n", value, | ||
2850 | (value & K8_NBCFG_CHIPKILL) ? "Enabled" : "Disabled", | ||
2851 | (value & K8_NBCFG_ECC_ENABLE) ? "Enabled" : "Disabled"); | ||
2852 | |||
2853 | pvt->ctl_error_info.nbcfg = value; | ||
2854 | } | ||
2855 | |||
2856 | static void amd64_restore_ecc_error_reporting(struct amd64_pvt *pvt) | ||
2857 | { | ||
2858 | const cpumask_t *cpumask = cpumask_of_node(pvt->mc_node_id); | ||
2859 | int cpu, idx = 0, err = 0; | ||
2860 | struct msr msrs[cpumask_weight(cpumask)]; | ||
2861 | u32 value; | ||
2862 | u32 mask = K8_NBCTL_CECCEn | K8_NBCTL_UECCEn; | ||
2863 | |||
2864 | if (!pvt->nbctl_mcgctl_saved) | ||
2865 | return; | ||
2866 | |||
2867 | memset(msrs, 0, sizeof(msrs)); | ||
2868 | |||
2869 | err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCTL, &value); | ||
2870 | if (err) | ||
2871 | debugf0("Reading K8_NBCTL failed\n"); | ||
2872 | value &= ~mask; | ||
2873 | value |= pvt->old_nbctl; | ||
2874 | |||
2875 | /* restore the NB Enable MCGCTL bit */ | ||
2876 | pci_write_config_dword(pvt->misc_f3_ctl, K8_NBCTL, value); | ||
2877 | |||
2878 | rdmsr_on_cpus(cpumask, K8_MSR_MCGCTL, msrs); | ||
2879 | |||
2880 | for_each_cpu(cpu, cpumask) { | ||
2881 | msrs[idx].l &= ~K8_MSR_MCGCTL_NBE; | ||
2882 | msrs[idx].l |= | ||
2883 | test_bit(idx, &pvt->old_mcgctl) << K8_MSR_MCGCTL_NBE; | ||
2884 | idx++; | ||
2885 | } | ||
2886 | |||
2887 | wrmsr_on_cpus(cpumask, K8_MSR_MCGCTL, msrs); | ||
2888 | } | ||
2889 | |||
2890 | static void check_mcg_ctl(void *ret) | ||
2891 | { | ||
2892 | u64 msr_val = 0; | ||
2893 | u8 nbe; | ||
2894 | |||
2895 | rdmsrl(MSR_IA32_MCG_CTL, msr_val); | ||
2896 | nbe = msr_val & K8_MSR_MCGCTL_NBE; | ||
2897 | |||
2898 | debugf0("core: %u, MCG_CTL: 0x%llx, NB MSR is %s\n", | ||
2899 | raw_smp_processor_id(), msr_val, | ||
2900 | (nbe ? "enabled" : "disabled")); | ||
2901 | |||
2902 | if (!nbe) | ||
2903 | *(int *)ret = 0; | ||
2904 | } | ||
2905 | |||
2906 | /* check MCG_CTL on all the cpus on this node */ | ||
2907 | static int amd64_mcg_ctl_enabled_on_cpus(const cpumask_t *mask) | ||
2908 | { | ||
2909 | int ret = 1; | ||
2910 | preempt_disable(); | ||
2911 | smp_call_function_many(mask, check_mcg_ctl, &ret, 1); | ||
2912 | preempt_enable(); | ||
2913 | |||
2914 | return ret; | ||
2915 | } | ||
2916 | |||
2917 | /* | ||
2918 | * EDAC requires that the BIOS have ECC enabled before taking over the | ||
2919 | * processing of ECC errors. This is because the BIOS can properly initialize | ||
2920 | * the memory system completely. A command line option allows to force-enable | ||
2921 | * hardware ECC later in amd64_enable_ecc_error_reporting(). | ||
2922 | */ | ||
2923 | static int amd64_check_ecc_enabled(struct amd64_pvt *pvt) | ||
2924 | { | ||
2925 | u32 value; | ||
2926 | int err = 0, ret = 0; | ||
2927 | u8 ecc_enabled = 0; | ||
2928 | |||
2929 | err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCFG, &value); | ||
2930 | if (err) | ||
2931 | debugf0("Reading K8_NBCTL failed\n"); | ||
2932 | |||
2933 | ecc_enabled = !!(value & K8_NBCFG_ECC_ENABLE); | ||
2934 | |||
2935 | ret = amd64_mcg_ctl_enabled_on_cpus(cpumask_of_node(pvt->mc_node_id)); | ||
2936 | |||
2937 | debugf0("K8_NBCFG=0x%x, DRAM ECC is %s\n", value, | ||
2938 | (value & K8_NBCFG_ECC_ENABLE ? "enabled" : "disabled")); | ||
2939 | |||
2940 | if (!ecc_enabled || !ret) { | ||
2941 | if (!ecc_enabled) { | ||
2942 | amd64_printk(KERN_WARNING, "This node reports that " | ||
2943 | "Memory ECC is currently " | ||
2944 | "disabled.\n"); | ||
2945 | |||
2946 | amd64_printk(KERN_WARNING, "bit 0x%lx in register " | ||
2947 | "F3x%x of the MISC_CONTROL device (%s) " | ||
2948 | "should be enabled\n", K8_NBCFG_ECC_ENABLE, | ||
2949 | K8_NBCFG, pci_name(pvt->misc_f3_ctl)); | ||
2950 | } | ||
2951 | if (!ret) { | ||
2952 | amd64_printk(KERN_WARNING, "bit 0x%016lx in MSR 0x%08x " | ||
2953 | "of node %d should be enabled\n", | ||
2954 | K8_MSR_MCGCTL_NBE, MSR_IA32_MCG_CTL, | ||
2955 | pvt->mc_node_id); | ||
2956 | } | ||
2957 | if (!ecc_enable_override) { | ||
2958 | amd64_printk(KERN_WARNING, "WARNING: ECC is NOT " | ||
2959 | "currently enabled by the BIOS. Module " | ||
2960 | "will NOT be loaded.\n" | ||
2961 | " Either Enable ECC in the BIOS, " | ||
2962 | "or use the 'ecc_enable_override' " | ||
2963 | "parameter.\n" | ||
2964 | " Might be a BIOS bug, if BIOS says " | ||
2965 | "ECC is enabled\n" | ||
2966 | " Use of the override can cause " | ||
2967 | "unknown side effects.\n"); | ||
2968 | ret = -ENODEV; | ||
2969 | } | ||
2970 | } else { | ||
2971 | amd64_printk(KERN_INFO, | ||
2972 | "ECC is enabled by BIOS, Proceeding " | ||
2973 | "with EDAC module initialization\n"); | ||
2974 | |||
2975 | /* CLEAR the override, since BIOS controlled it */ | ||
2976 | ecc_enable_override = 0; | ||
2977 | } | ||
2978 | |||
2979 | return ret; | ||
2980 | } | ||
2981 | |||
2982 | struct mcidev_sysfs_attribute sysfs_attrs[ARRAY_SIZE(amd64_dbg_attrs) + | ||
2983 | ARRAY_SIZE(amd64_inj_attrs) + | ||
2984 | 1]; | ||
2985 | |||
2986 | struct mcidev_sysfs_attribute terminator = { .attr = { .name = NULL } }; | ||
2987 | |||
2988 | static void amd64_set_mc_sysfs_attributes(struct mem_ctl_info *mci) | ||
2989 | { | ||
2990 | unsigned int i = 0, j = 0; | ||
2991 | |||
2992 | for (; i < ARRAY_SIZE(amd64_dbg_attrs); i++) | ||
2993 | sysfs_attrs[i] = amd64_dbg_attrs[i]; | ||
2994 | |||
2995 | for (j = 0; j < ARRAY_SIZE(amd64_inj_attrs); j++, i++) | ||
2996 | sysfs_attrs[i] = amd64_inj_attrs[j]; | ||
2997 | |||
2998 | sysfs_attrs[i] = terminator; | ||
2999 | |||
3000 | mci->mc_driver_sysfs_attributes = sysfs_attrs; | ||
3001 | } | ||
3002 | |||
3003 | static void amd64_setup_mci_misc_attributes(struct mem_ctl_info *mci) | ||
3004 | { | ||
3005 | struct amd64_pvt *pvt = mci->pvt_info; | ||
3006 | |||
3007 | mci->mtype_cap = MEM_FLAG_DDR2 | MEM_FLAG_RDDR2; | ||
3008 | mci->edac_ctl_cap = EDAC_FLAG_NONE; | ||
3009 | mci->edac_cap = EDAC_FLAG_NONE; | ||
3010 | |||
3011 | if (pvt->nbcap & K8_NBCAP_SECDED) | ||
3012 | mci->edac_ctl_cap |= EDAC_FLAG_SECDED; | ||
3013 | |||
3014 | if (pvt->nbcap & K8_NBCAP_CHIPKILL) | ||
3015 | mci->edac_ctl_cap |= EDAC_FLAG_S4ECD4ED; | ||
3016 | |||
3017 | mci->edac_cap = amd64_determine_edac_cap(pvt); | ||
3018 | mci->mod_name = EDAC_MOD_STR; | ||
3019 | mci->mod_ver = EDAC_AMD64_VERSION; | ||
3020 | mci->ctl_name = get_amd_family_name(pvt->mc_type_index); | ||
3021 | mci->dev_name = pci_name(pvt->dram_f2_ctl); | ||
3022 | mci->ctl_page_to_phys = NULL; | ||
3023 | |||
3024 | /* IMPORTANT: Set the polling 'check' function in this module */ | ||
3025 | mci->edac_check = amd64_check; | ||
3026 | |||
3027 | /* memory scrubber interface */ | ||
3028 | mci->set_sdram_scrub_rate = amd64_set_scrub_rate; | ||
3029 | mci->get_sdram_scrub_rate = amd64_get_scrub_rate; | ||
3030 | } | ||
3031 | |||
3032 | /* | ||
3033 | * Init stuff for this DRAM Controller device. | ||
3034 | * | ||
3035 | * Due to a hardware feature on Fam10h CPUs, the Enable Extended Configuration | ||
3036 | * Space feature MUST be enabled on ALL Processors prior to actually reading | ||
3037 | * from the ECS registers. Since the loading of the module can occur on any | ||
3038 | * 'core', and cores don't 'see' all the other processors ECS data when the | ||
3039 | * others are NOT enabled. Our solution is to first enable ECS access in this | ||
3040 | * routine on all processors, gather some data in a amd64_pvt structure and | ||
3041 | * later come back in a finish-setup function to perform that final | ||
3042 | * initialization. See also amd64_init_2nd_stage() for that. | ||
3043 | */ | ||
3044 | static int amd64_probe_one_instance(struct pci_dev *dram_f2_ctl, | ||
3045 | int mc_type_index) | ||
3046 | { | ||
3047 | struct amd64_pvt *pvt = NULL; | ||
3048 | int err = 0, ret; | ||
3049 | |||
3050 | ret = -ENOMEM; | ||
3051 | pvt = kzalloc(sizeof(struct amd64_pvt), GFP_KERNEL); | ||
3052 | if (!pvt) | ||
3053 | goto err_exit; | ||
3054 | |||
3055 | pvt->mc_node_id = get_mc_node_id_from_pdev(dram_f2_ctl); | ||
3056 | |||
3057 | pvt->dram_f2_ctl = dram_f2_ctl; | ||
3058 | pvt->ext_model = boot_cpu_data.x86_model >> 4; | ||
3059 | pvt->mc_type_index = mc_type_index; | ||
3060 | pvt->ops = family_ops(mc_type_index); | ||
3061 | pvt->old_mcgctl = 0; | ||
3062 | |||
3063 | /* | ||
3064 | * We have the dram_f2_ctl device as an argument, now go reserve its | ||
3065 | * sibling devices from the PCI system. | ||
3066 | */ | ||
3067 | ret = -ENODEV; | ||
3068 | err = amd64_reserve_mc_sibling_devices(pvt, mc_type_index); | ||
3069 | if (err) | ||
3070 | goto err_free; | ||
3071 | |||
3072 | ret = -EINVAL; | ||
3073 | err = amd64_check_ecc_enabled(pvt); | ||
3074 | if (err) | ||
3075 | goto err_put; | ||
3076 | |||
3077 | /* | ||
3078 | * Key operation here: setup of HW prior to performing ops on it. Some | ||
3079 | * setup is required to access ECS data. After this is performed, the | ||
3080 | * 'teardown' function must be called upon error and normal exit paths. | ||
3081 | */ | ||
3082 | if (boot_cpu_data.x86 >= 0x10) | ||
3083 | amd64_setup(pvt); | ||
3084 | |||
3085 | /* | ||
3086 | * Save the pointer to the private data for use in 2nd initialization | ||
3087 | * stage | ||
3088 | */ | ||
3089 | pvt_lookup[pvt->mc_node_id] = pvt; | ||
3090 | |||
3091 | return 0; | ||
3092 | |||
3093 | err_put: | ||
3094 | amd64_free_mc_sibling_devices(pvt); | ||
3095 | |||
3096 | err_free: | ||
3097 | kfree(pvt); | ||
3098 | |||
3099 | err_exit: | ||
3100 | return ret; | ||
3101 | } | ||
3102 | |||
3103 | /* | ||
3104 | * This is the finishing stage of the init code. Needs to be performed after all | ||
3105 | * MCs' hardware have been prepped for accessing extended config space. | ||
3106 | */ | ||
3107 | static int amd64_init_2nd_stage(struct amd64_pvt *pvt) | ||
3108 | { | ||
3109 | int node_id = pvt->mc_node_id; | ||
3110 | struct mem_ctl_info *mci; | ||
3111 | int ret, err = 0; | ||
3112 | |||
3113 | amd64_read_mc_registers(pvt); | ||
3114 | |||
3115 | ret = -ENODEV; | ||
3116 | if (pvt->ops->probe_valid_hardware) { | ||
3117 | err = pvt->ops->probe_valid_hardware(pvt); | ||
3118 | if (err) | ||
3119 | goto err_exit; | ||
3120 | } | ||
3121 | |||
3122 | /* | ||
3123 | * We need to determine how many memory channels there are. Then use | ||
3124 | * that information for calculating the size of the dynamic instance | ||
3125 | * tables in the 'mci' structure | ||
3126 | */ | ||
3127 | pvt->channel_count = pvt->ops->early_channel_count(pvt); | ||
3128 | if (pvt->channel_count < 0) | ||
3129 | goto err_exit; | ||
3130 | |||
3131 | ret = -ENOMEM; | ||
3132 | mci = edac_mc_alloc(0, CHIPSELECT_COUNT, pvt->channel_count, node_id); | ||
3133 | if (!mci) | ||
3134 | goto err_exit; | ||
3135 | |||
3136 | mci->pvt_info = pvt; | ||
3137 | |||
3138 | mci->dev = &pvt->dram_f2_ctl->dev; | ||
3139 | amd64_setup_mci_misc_attributes(mci); | ||
3140 | |||
3141 | if (amd64_init_csrows(mci)) | ||
3142 | mci->edac_cap = EDAC_FLAG_NONE; | ||
3143 | |||
3144 | amd64_enable_ecc_error_reporting(mci); | ||
3145 | amd64_set_mc_sysfs_attributes(mci); | ||
3146 | |||
3147 | ret = -ENODEV; | ||
3148 | if (edac_mc_add_mc(mci)) { | ||
3149 | debugf1("failed edac_mc_add_mc()\n"); | ||
3150 | goto err_add_mc; | ||
3151 | } | ||
3152 | |||
3153 | mci_lookup[node_id] = mci; | ||
3154 | pvt_lookup[node_id] = NULL; | ||
3155 | return 0; | ||
3156 | |||
3157 | err_add_mc: | ||
3158 | edac_mc_free(mci); | ||
3159 | |||
3160 | err_exit: | ||
3161 | debugf0("failure to init 2nd stage: ret=%d\n", ret); | ||
3162 | |||
3163 | amd64_restore_ecc_error_reporting(pvt); | ||
3164 | |||
3165 | if (boot_cpu_data.x86 > 0xf) | ||
3166 | amd64_teardown(pvt); | ||
3167 | |||
3168 | amd64_free_mc_sibling_devices(pvt); | ||
3169 | |||
3170 | kfree(pvt_lookup[pvt->mc_node_id]); | ||
3171 | pvt_lookup[node_id] = NULL; | ||
3172 | |||
3173 | return ret; | ||
3174 | } | ||
3175 | |||
3176 | |||
3177 | static int __devinit amd64_init_one_instance(struct pci_dev *pdev, | ||
3178 | const struct pci_device_id *mc_type) | ||
3179 | { | ||
3180 | int ret = 0; | ||
3181 | |||
3182 | debugf0("(MC node=%d,mc_type='%s')\n", | ||
3183 | get_mc_node_id_from_pdev(pdev), | ||
3184 | get_amd_family_name(mc_type->driver_data)); | ||
3185 | |||
3186 | ret = pci_enable_device(pdev); | ||
3187 | if (ret < 0) | ||
3188 | ret = -EIO; | ||
3189 | else | ||
3190 | ret = amd64_probe_one_instance(pdev, mc_type->driver_data); | ||
3191 | |||
3192 | if (ret < 0) | ||
3193 | debugf0("ret=%d\n", ret); | ||
3194 | |||
3195 | return ret; | ||
3196 | } | ||
3197 | |||
3198 | static void __devexit amd64_remove_one_instance(struct pci_dev *pdev) | ||
3199 | { | ||
3200 | struct mem_ctl_info *mci; | ||
3201 | struct amd64_pvt *pvt; | ||
3202 | |||
3203 | /* Remove from EDAC CORE tracking list */ | ||
3204 | mci = edac_mc_del_mc(&pdev->dev); | ||
3205 | if (!mci) | ||
3206 | return; | ||
3207 | |||
3208 | pvt = mci->pvt_info; | ||
3209 | |||
3210 | amd64_restore_ecc_error_reporting(pvt); | ||
3211 | |||
3212 | if (boot_cpu_data.x86 > 0xf) | ||
3213 | amd64_teardown(pvt); | ||
3214 | |||
3215 | amd64_free_mc_sibling_devices(pvt); | ||
3216 | |||
3217 | kfree(pvt); | ||
3218 | mci->pvt_info = NULL; | ||
3219 | |||
3220 | mci_lookup[pvt->mc_node_id] = NULL; | ||
3221 | |||
3222 | /* Free the EDAC CORE resources */ | ||
3223 | edac_mc_free(mci); | ||
3224 | } | ||
3225 | |||
3226 | /* | ||
3227 | * This table is part of the interface for loading drivers for PCI devices. The | ||
3228 | * PCI core identifies what devices are on a system during boot, and then | ||
3229 | * inquiry this table to see if this driver is for a given device found. | ||
3230 | */ | ||
3231 | static const struct pci_device_id amd64_pci_table[] __devinitdata = { | ||
3232 | { | ||
3233 | .vendor = PCI_VENDOR_ID_AMD, | ||
3234 | .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL, | ||
3235 | .subvendor = PCI_ANY_ID, | ||
3236 | .subdevice = PCI_ANY_ID, | ||
3237 | .class = 0, | ||
3238 | .class_mask = 0, | ||
3239 | .driver_data = K8_CPUS | ||
3240 | }, | ||
3241 | { | ||
3242 | .vendor = PCI_VENDOR_ID_AMD, | ||
3243 | .device = PCI_DEVICE_ID_AMD_10H_NB_DRAM, | ||
3244 | .subvendor = PCI_ANY_ID, | ||
3245 | .subdevice = PCI_ANY_ID, | ||
3246 | .class = 0, | ||
3247 | .class_mask = 0, | ||
3248 | .driver_data = F10_CPUS | ||
3249 | }, | ||
3250 | { | ||
3251 | .vendor = PCI_VENDOR_ID_AMD, | ||
3252 | .device = PCI_DEVICE_ID_AMD_11H_NB_DRAM, | ||
3253 | .subvendor = PCI_ANY_ID, | ||
3254 | .subdevice = PCI_ANY_ID, | ||
3255 | .class = 0, | ||
3256 | .class_mask = 0, | ||
3257 | .driver_data = F11_CPUS | ||
3258 | }, | ||
3259 | {0, } | ||
3260 | }; | ||
3261 | MODULE_DEVICE_TABLE(pci, amd64_pci_table); | ||
3262 | |||
3263 | static struct pci_driver amd64_pci_driver = { | ||
3264 | .name = EDAC_MOD_STR, | ||
3265 | .probe = amd64_init_one_instance, | ||
3266 | .remove = __devexit_p(amd64_remove_one_instance), | ||
3267 | .id_table = amd64_pci_table, | ||
3268 | }; | ||
3269 | |||
3270 | static void amd64_setup_pci_device(void) | ||
3271 | { | ||
3272 | struct mem_ctl_info *mci; | ||
3273 | struct amd64_pvt *pvt; | ||
3274 | |||
3275 | if (amd64_ctl_pci) | ||
3276 | return; | ||
3277 | |||
3278 | mci = mci_lookup[0]; | ||
3279 | if (mci) { | ||
3280 | |||
3281 | pvt = mci->pvt_info; | ||
3282 | amd64_ctl_pci = | ||
3283 | edac_pci_create_generic_ctl(&pvt->dram_f2_ctl->dev, | ||
3284 | EDAC_MOD_STR); | ||
3285 | |||
3286 | if (!amd64_ctl_pci) { | ||
3287 | pr_warning("%s(): Unable to create PCI control\n", | ||
3288 | __func__); | ||
3289 | |||
3290 | pr_warning("%s(): PCI error report via EDAC not set\n", | ||
3291 | __func__); | ||
3292 | } | ||
3293 | } | ||
3294 | } | ||
3295 | |||
3296 | static int __init amd64_edac_init(void) | ||
3297 | { | ||
3298 | int nb, err = -ENODEV; | ||
3299 | |||
3300 | edac_printk(KERN_INFO, EDAC_MOD_STR, EDAC_AMD64_VERSION "\n"); | ||
3301 | |||
3302 | opstate_init(); | ||
3303 | |||
3304 | if (cache_k8_northbridges() < 0) | ||
3305 | goto err_exit; | ||
3306 | |||
3307 | err = pci_register_driver(&amd64_pci_driver); | ||
3308 | if (err) | ||
3309 | return err; | ||
3310 | |||
3311 | /* | ||
3312 | * At this point, the array 'pvt_lookup[]' contains pointers to alloc'd | ||
3313 | * amd64_pvt structs. These will be used in the 2nd stage init function | ||
3314 | * to finish initialization of the MC instances. | ||
3315 | */ | ||
3316 | for (nb = 0; nb < num_k8_northbridges; nb++) { | ||
3317 | if (!pvt_lookup[nb]) | ||
3318 | continue; | ||
3319 | |||
3320 | err = amd64_init_2nd_stage(pvt_lookup[nb]); | ||
3321 | if (err) | ||
3322 | goto err_exit; | ||
3323 | } | ||
3324 | |||
3325 | amd64_setup_pci_device(); | ||
3326 | |||
3327 | return 0; | ||
3328 | |||
3329 | err_exit: | ||
3330 | debugf0("'finish_setup' stage failed\n"); | ||
3331 | pci_unregister_driver(&amd64_pci_driver); | ||
3332 | |||
3333 | return err; | ||
3334 | } | ||
3335 | |||
3336 | static void __exit amd64_edac_exit(void) | ||
3337 | { | ||
3338 | if (amd64_ctl_pci) | ||
3339 | edac_pci_release_generic_ctl(amd64_ctl_pci); | ||
3340 | |||
3341 | pci_unregister_driver(&amd64_pci_driver); | ||
3342 | } | ||
3343 | |||
3344 | module_init(amd64_edac_init); | ||
3345 | module_exit(amd64_edac_exit); | ||
3346 | |||
3347 | MODULE_LICENSE("GPL"); | ||
3348 | MODULE_AUTHOR("SoftwareBitMaker: Doug Thompson, " | ||
3349 | "Dave Peterson, Thayne Harbaugh"); | ||
3350 | MODULE_DESCRIPTION("MC support for AMD64 memory controllers - " | ||
3351 | EDAC_AMD64_VERSION); | ||
3352 | |||
3353 | module_param(edac_op_state, int, 0444); | ||
3354 | MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); | ||
diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h new file mode 100644 index 000000000000..a159957e167b --- /dev/null +++ b/drivers/edac/amd64_edac.h | |||
@@ -0,0 +1,644 @@ | |||
1 | /* | ||
2 | * AMD64 class Memory Controller kernel module | ||
3 | * | ||
4 | * Copyright (c) 2009 SoftwareBitMaker. | ||
5 | * Copyright (c) 2009 Advanced Micro Devices, Inc. | ||
6 | * | ||
7 | * This file may be distributed under the terms of the | ||
8 | * GNU General Public License. | ||
9 | * | ||
10 | * Originally Written by Thayne Harbaugh | ||
11 | * | ||
12 | * Changes by Douglas "norsk" Thompson <dougthompson@xmission.com>: | ||
13 | * - K8 CPU Revision D and greater support | ||
14 | * | ||
15 | * Changes by Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com>: | ||
16 | * - Module largely rewritten, with new (and hopefully correct) | ||
17 | * code for dealing with node and chip select interleaving, | ||
18 | * various code cleanup, and bug fixes | ||
19 | * - Added support for memory hoisting using DRAM hole address | ||
20 | * register | ||
21 | * | ||
22 | * Changes by Douglas "norsk" Thompson <dougthompson@xmission.com>: | ||
23 | * -K8 Rev (1207) revision support added, required Revision | ||
24 | * specific mini-driver code to support Rev F as well as | ||
25 | * prior revisions | ||
26 | * | ||
27 | * Changes by Douglas "norsk" Thompson <dougthompson@xmission.com>: | ||
28 | * -Family 10h revision support added. New PCI Device IDs, | ||
29 | * indicating new changes. Actual registers modified | ||
30 | * were slight, less than the Rev E to Rev F transition | ||
31 | * but changing the PCI Device ID was the proper thing to | ||
32 | * do, as it provides for almost automactic family | ||
33 | * detection. The mods to Rev F required more family | ||
34 | * information detection. | ||
35 | * | ||
36 | * Changes/Fixes by Borislav Petkov <borislav.petkov@amd.com>: | ||
37 | * - misc fixes and code cleanups | ||
38 | * | ||
39 | * This module is based on the following documents | ||
40 | * (available from http://www.amd.com/): | ||
41 | * | ||
42 | * Title: BIOS and Kernel Developer's Guide for AMD Athlon 64 and AMD | ||
43 | * Opteron Processors | ||
44 | * AMD publication #: 26094 | ||
45 | *` Revision: 3.26 | ||
46 | * | ||
47 | * Title: BIOS and Kernel Developer's Guide for AMD NPT Family 0Fh | ||
48 | * Processors | ||
49 | * AMD publication #: 32559 | ||
50 | * Revision: 3.00 | ||
51 | * Issue Date: May 2006 | ||
52 | * | ||
53 | * Title: BIOS and Kernel Developer's Guide (BKDG) For AMD Family 10h | ||
54 | * Processors | ||
55 | * AMD publication #: 31116 | ||
56 | * Revision: 3.00 | ||
57 | * Issue Date: September 07, 2007 | ||
58 | * | ||
59 | * Sections in the first 2 documents are no longer in sync with each other. | ||
60 | * The Family 10h BKDG was totally re-written from scratch with a new | ||
61 | * presentation model. | ||
62 | * Therefore, comments that refer to a Document section might be off. | ||
63 | */ | ||
64 | |||
65 | #include <linux/module.h> | ||
66 | #include <linux/ctype.h> | ||
67 | #include <linux/init.h> | ||
68 | #include <linux/pci.h> | ||
69 | #include <linux/pci_ids.h> | ||
70 | #include <linux/slab.h> | ||
71 | #include <linux/mmzone.h> | ||
72 | #include <linux/edac.h> | ||
73 | #include <asm/msr.h> | ||
74 | #include "edac_core.h" | ||
75 | |||
76 | #define amd64_printk(level, fmt, arg...) \ | ||
77 | edac_printk(level, "amd64", fmt, ##arg) | ||
78 | |||
79 | #define amd64_mc_printk(mci, level, fmt, arg...) \ | ||
80 | edac_mc_chipset_printk(mci, level, "amd64", fmt, ##arg) | ||
81 | |||
82 | /* | ||
83 | * Throughout the comments in this code, the following terms are used: | ||
84 | * | ||
85 | * SysAddr, DramAddr, and InputAddr | ||
86 | * | ||
87 | * These terms come directly from the amd64 documentation | ||
88 | * (AMD publication #26094). They are defined as follows: | ||
89 | * | ||
90 | * SysAddr: | ||
91 | * This is a physical address generated by a CPU core or a device | ||
92 | * doing DMA. If generated by a CPU core, a SysAddr is the result of | ||
93 | * a virtual to physical address translation by the CPU core's address | ||
94 | * translation mechanism (MMU). | ||
95 | * | ||
96 | * DramAddr: | ||
97 | * A DramAddr is derived from a SysAddr by subtracting an offset that | ||
98 | * depends on which node the SysAddr maps to and whether the SysAddr | ||
99 | * is within a range affected by memory hoisting. The DRAM Base | ||
100 | * (section 3.4.4.1) and DRAM Limit (section 3.4.4.2) registers | ||
101 | * determine which node a SysAddr maps to. | ||
102 | * | ||
103 | * If the DRAM Hole Address Register (DHAR) is enabled and the SysAddr | ||
104 | * is within the range of addresses specified by this register, then | ||
105 | * a value x from the DHAR is subtracted from the SysAddr to produce a | ||
106 | * DramAddr. Here, x represents the base address for the node that | ||
107 | * the SysAddr maps to plus an offset due to memory hoisting. See | ||
108 | * section 3.4.8 and the comments in amd64_get_dram_hole_info() and | ||
109 | * sys_addr_to_dram_addr() below for more information. | ||
110 | * | ||
111 | * If the SysAddr is not affected by the DHAR then a value y is | ||
112 | * subtracted from the SysAddr to produce a DramAddr. Here, y is the | ||
113 | * base address for the node that the SysAddr maps to. See section | ||
114 | * 3.4.4 and the comments in sys_addr_to_dram_addr() below for more | ||
115 | * information. | ||
116 | * | ||
117 | * InputAddr: | ||
118 | * A DramAddr is translated to an InputAddr before being passed to the | ||
119 | * memory controller for the node that the DramAddr is associated | ||
120 | * with. The memory controller then maps the InputAddr to a csrow. | ||
121 | * If node interleaving is not in use, then the InputAddr has the same | ||
122 | * value as the DramAddr. Otherwise, the InputAddr is produced by | ||
123 | * discarding the bits used for node interleaving from the DramAddr. | ||
124 | * See section 3.4.4 for more information. | ||
125 | * | ||
126 | * The memory controller for a given node uses its DRAM CS Base and | ||
127 | * DRAM CS Mask registers to map an InputAddr to a csrow. See | ||
128 | * sections 3.5.4 and 3.5.5 for more information. | ||
129 | */ | ||
130 | |||
131 | #define EDAC_AMD64_VERSION " Ver: 3.2.0 " __DATE__ | ||
132 | #define EDAC_MOD_STR "amd64_edac" | ||
133 | |||
134 | /* Extended Model from CPUID, for CPU Revision numbers */ | ||
135 | #define OPTERON_CPU_LE_REV_C 0 | ||
136 | #define OPTERON_CPU_REV_D 1 | ||
137 | #define OPTERON_CPU_REV_E 2 | ||
138 | |||
139 | /* NPT processors have the following Extended Models */ | ||
140 | #define OPTERON_CPU_REV_F 4 | ||
141 | #define OPTERON_CPU_REV_FA 5 | ||
142 | |||
143 | /* Hardware limit on ChipSelect rows per MC and processors per system */ | ||
144 | #define CHIPSELECT_COUNT 8 | ||
145 | #define DRAM_REG_COUNT 8 | ||
146 | |||
147 | |||
148 | /* | ||
149 | * PCI-defined configuration space registers | ||
150 | */ | ||
151 | |||
152 | |||
153 | /* | ||
154 | * Function 1 - Address Map | ||
155 | */ | ||
156 | #define K8_DRAM_BASE_LOW 0x40 | ||
157 | #define K8_DRAM_LIMIT_LOW 0x44 | ||
158 | #define K8_DHAR 0xf0 | ||
159 | |||
160 | #define DHAR_VALID BIT(0) | ||
161 | #define F10_DRAM_MEM_HOIST_VALID BIT(1) | ||
162 | |||
163 | #define DHAR_BASE_MASK 0xff000000 | ||
164 | #define dhar_base(dhar) (dhar & DHAR_BASE_MASK) | ||
165 | |||
166 | #define K8_DHAR_OFFSET_MASK 0x0000ff00 | ||
167 | #define k8_dhar_offset(dhar) ((dhar & K8_DHAR_OFFSET_MASK) << 16) | ||
168 | |||
169 | #define F10_DHAR_OFFSET_MASK 0x0000ff80 | ||
170 | /* NOTE: Extra mask bit vs K8 */ | ||
171 | #define f10_dhar_offset(dhar) ((dhar & F10_DHAR_OFFSET_MASK) << 16) | ||
172 | |||
173 | |||
174 | /* F10 High BASE/LIMIT registers */ | ||
175 | #define F10_DRAM_BASE_HIGH 0x140 | ||
176 | #define F10_DRAM_LIMIT_HIGH 0x144 | ||
177 | |||
178 | |||
179 | /* | ||
180 | * Function 2 - DRAM controller | ||
181 | */ | ||
182 | #define K8_DCSB0 0x40 | ||
183 | #define F10_DCSB1 0x140 | ||
184 | |||
185 | #define K8_DCSB_CS_ENABLE BIT(0) | ||
186 | #define K8_DCSB_NPT_SPARE BIT(1) | ||
187 | #define K8_DCSB_NPT_TESTFAIL BIT(2) | ||
188 | |||
189 | /* | ||
190 | * REV E: select [31:21] and [15:9] from DCSB and the shift amount to form | ||
191 | * the address | ||
192 | */ | ||
193 | #define REV_E_DCSB_BASE_BITS (0xFFE0FE00ULL) | ||
194 | #define REV_E_DCS_SHIFT 4 | ||
195 | #define REV_E_DCSM_COUNT 8 | ||
196 | |||
197 | #define REV_F_F1Xh_DCSB_BASE_BITS (0x1FF83FE0ULL) | ||
198 | #define REV_F_F1Xh_DCS_SHIFT 8 | ||
199 | |||
200 | /* | ||
201 | * REV F and later: selects [28:19] and [13:5] from DCSB and the shift amount | ||
202 | * to form the address | ||
203 | */ | ||
204 | #define REV_F_DCSB_BASE_BITS (0x1FF83FE0ULL) | ||
205 | #define REV_F_DCS_SHIFT 8 | ||
206 | #define REV_F_DCSM_COUNT 4 | ||
207 | #define F10_DCSM_COUNT 4 | ||
208 | #define F11_DCSM_COUNT 2 | ||
209 | |||
210 | /* DRAM CS Mask Registers */ | ||
211 | #define K8_DCSM0 0x60 | ||
212 | #define F10_DCSM1 0x160 | ||
213 | |||
214 | /* REV E: select [29:21] and [15:9] from DCSM */ | ||
215 | #define REV_E_DCSM_MASK_BITS 0x3FE0FE00 | ||
216 | |||
217 | /* unused bits [24:20] and [12:0] */ | ||
218 | #define REV_E_DCS_NOTUSED_BITS 0x01F01FFF | ||
219 | |||
220 | /* REV F and later: select [28:19] and [13:5] from DCSM */ | ||
221 | #define REV_F_F1Xh_DCSM_MASK_BITS 0x1FF83FE0 | ||
222 | |||
223 | /* unused bits [26:22] and [12:0] */ | ||
224 | #define REV_F_F1Xh_DCS_NOTUSED_BITS 0x07C01FFF | ||
225 | |||
226 | #define DBAM0 0x80 | ||
227 | #define DBAM1 0x180 | ||
228 | |||
229 | /* Extract the DIMM 'type' on the i'th DIMM from the DBAM reg value passed */ | ||
230 | #define DBAM_DIMM(i, reg) ((((reg) >> (4*i))) & 0xF) | ||
231 | |||
232 | #define DBAM_MAX_VALUE 11 | ||
233 | |||
234 | |||
235 | #define F10_DCLR_0 0x90 | ||
236 | #define F10_DCLR_1 0x190 | ||
237 | #define REVE_WIDTH_128 BIT(16) | ||
238 | #define F10_WIDTH_128 BIT(11) | ||
239 | |||
240 | |||
241 | #define F10_DCHR_0 0x94 | ||
242 | #define F10_DCHR_1 0x194 | ||
243 | |||
244 | #define F10_DCHR_FOUR_RANK_DIMM BIT(18) | ||
245 | #define F10_DCHR_Ddr3Mode BIT(8) | ||
246 | #define F10_DCHR_MblMode BIT(6) | ||
247 | |||
248 | |||
249 | #define F10_DCTL_SEL_LOW 0x110 | ||
250 | |||
251 | #define dct_sel_baseaddr(pvt) \ | ||
252 | ((pvt->dram_ctl_select_low) & 0xFFFFF800) | ||
253 | |||
254 | #define dct_sel_interleave_addr(pvt) \ | ||
255 | (((pvt->dram_ctl_select_low) >> 6) & 0x3) | ||
256 | |||
257 | enum { | ||
258 | F10_DCTL_SEL_LOW_DctSelHiRngEn = BIT(0), | ||
259 | F10_DCTL_SEL_LOW_DctSelIntLvEn = BIT(2), | ||
260 | F10_DCTL_SEL_LOW_DctGangEn = BIT(4), | ||
261 | F10_DCTL_SEL_LOW_DctDatIntLv = BIT(5), | ||
262 | F10_DCTL_SEL_LOW_DramEnable = BIT(8), | ||
263 | F10_DCTL_SEL_LOW_MemCleared = BIT(10), | ||
264 | }; | ||
265 | |||
266 | #define dct_high_range_enabled(pvt) \ | ||
267 | (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_DctSelHiRngEn) | ||
268 | |||
269 | #define dct_interleave_enabled(pvt) \ | ||
270 | (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_DctSelIntLvEn) | ||
271 | |||
272 | #define dct_ganging_enabled(pvt) \ | ||
273 | (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_DctGangEn) | ||
274 | |||
275 | #define dct_data_intlv_enabled(pvt) \ | ||
276 | (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_DctDatIntLv) | ||
277 | |||
278 | #define dct_dram_enabled(pvt) \ | ||
279 | (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_DramEnable) | ||
280 | |||
281 | #define dct_memory_cleared(pvt) \ | ||
282 | (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_MemCleared) | ||
283 | |||
284 | |||
285 | #define F10_DCTL_SEL_HIGH 0x114 | ||
286 | |||
287 | |||
288 | /* | ||
289 | * Function 3 - Misc Control | ||
290 | */ | ||
291 | #define K8_NBCTL 0x40 | ||
292 | |||
293 | /* Correctable ECC error reporting enable */ | ||
294 | #define K8_NBCTL_CECCEn BIT(0) | ||
295 | |||
296 | /* UnCorrectable ECC error reporting enable */ | ||
297 | #define K8_NBCTL_UECCEn BIT(1) | ||
298 | |||
299 | #define K8_NBCFG 0x44 | ||
300 | #define K8_NBCFG_CHIPKILL BIT(23) | ||
301 | #define K8_NBCFG_ECC_ENABLE BIT(22) | ||
302 | |||
303 | #define K8_NBSL 0x48 | ||
304 | |||
305 | |||
306 | #define EXTRACT_HIGH_SYNDROME(x) (((x) >> 24) & 0xff) | ||
307 | #define EXTRACT_EXT_ERROR_CODE(x) (((x) >> 16) & 0x1f) | ||
308 | |||
309 | /* Family F10h: Normalized Extended Error Codes */ | ||
310 | #define F10_NBSL_EXT_ERR_RES 0x0 | ||
311 | #define F10_NBSL_EXT_ERR_CRC 0x1 | ||
312 | #define F10_NBSL_EXT_ERR_SYNC 0x2 | ||
313 | #define F10_NBSL_EXT_ERR_MST 0x3 | ||
314 | #define F10_NBSL_EXT_ERR_TGT 0x4 | ||
315 | #define F10_NBSL_EXT_ERR_GART 0x5 | ||
316 | #define F10_NBSL_EXT_ERR_RMW 0x6 | ||
317 | #define F10_NBSL_EXT_ERR_WDT 0x7 | ||
318 | #define F10_NBSL_EXT_ERR_ECC 0x8 | ||
319 | #define F10_NBSL_EXT_ERR_DEV 0x9 | ||
320 | #define F10_NBSL_EXT_ERR_LINK_DATA 0xA | ||
321 | |||
322 | /* Next two are overloaded values */ | ||
323 | #define F10_NBSL_EXT_ERR_LINK_PROTO 0xB | ||
324 | #define F10_NBSL_EXT_ERR_L3_PROTO 0xB | ||
325 | |||
326 | #define F10_NBSL_EXT_ERR_NB_ARRAY 0xC | ||
327 | #define F10_NBSL_EXT_ERR_DRAM_PARITY 0xD | ||
328 | #define F10_NBSL_EXT_ERR_LINK_RETRY 0xE | ||
329 | |||
330 | /* Next two are overloaded values */ | ||
331 | #define F10_NBSL_EXT_ERR_GART_WALK 0xF | ||
332 | #define F10_NBSL_EXT_ERR_DEV_WALK 0xF | ||
333 | |||
334 | /* 0x10 to 0x1B: Reserved */ | ||
335 | #define F10_NBSL_EXT_ERR_L3_DATA 0x1C | ||
336 | #define F10_NBSL_EXT_ERR_L3_TAG 0x1D | ||
337 | #define F10_NBSL_EXT_ERR_L3_LRU 0x1E | ||
338 | |||
339 | /* K8: Normalized Extended Error Codes */ | ||
340 | #define K8_NBSL_EXT_ERR_ECC 0x0 | ||
341 | #define K8_NBSL_EXT_ERR_CRC 0x1 | ||
342 | #define K8_NBSL_EXT_ERR_SYNC 0x2 | ||
343 | #define K8_NBSL_EXT_ERR_MST 0x3 | ||
344 | #define K8_NBSL_EXT_ERR_TGT 0x4 | ||
345 | #define K8_NBSL_EXT_ERR_GART 0x5 | ||
346 | #define K8_NBSL_EXT_ERR_RMW 0x6 | ||
347 | #define K8_NBSL_EXT_ERR_WDT 0x7 | ||
348 | #define K8_NBSL_EXT_ERR_CHIPKILL_ECC 0x8 | ||
349 | #define K8_NBSL_EXT_ERR_DRAM_PARITY 0xD | ||
350 | |||
351 | #define EXTRACT_ERROR_CODE(x) ((x) & 0xffff) | ||
352 | #define TEST_TLB_ERROR(x) (((x) & 0xFFF0) == 0x0010) | ||
353 | #define TEST_MEM_ERROR(x) (((x) & 0xFF00) == 0x0100) | ||
354 | #define TEST_BUS_ERROR(x) (((x) & 0xF800) == 0x0800) | ||
355 | #define EXTRACT_TT_CODE(x) (((x) >> 2) & 0x3) | ||
356 | #define EXTRACT_II_CODE(x) (((x) >> 2) & 0x3) | ||
357 | #define EXTRACT_LL_CODE(x) (((x) >> 0) & 0x3) | ||
358 | #define EXTRACT_RRRR_CODE(x) (((x) >> 4) & 0xf) | ||
359 | #define EXTRACT_TO_CODE(x) (((x) >> 8) & 0x1) | ||
360 | #define EXTRACT_PP_CODE(x) (((x) >> 9) & 0x3) | ||
361 | |||
362 | /* | ||
363 | * The following are for BUS type errors AFTER values have been normalized by | ||
364 | * shifting right | ||
365 | */ | ||
366 | #define K8_NBSL_PP_SRC 0x0 | ||
367 | #define K8_NBSL_PP_RES 0x1 | ||
368 | #define K8_NBSL_PP_OBS 0x2 | ||
369 | #define K8_NBSL_PP_GENERIC 0x3 | ||
370 | |||
371 | |||
372 | #define K8_NBSH 0x4C | ||
373 | |||
374 | #define K8_NBSH_VALID_BIT BIT(31) | ||
375 | #define K8_NBSH_OVERFLOW BIT(30) | ||
376 | #define K8_NBSH_UNCORRECTED_ERR BIT(29) | ||
377 | #define K8_NBSH_ERR_ENABLE BIT(28) | ||
378 | #define K8_NBSH_MISC_ERR_VALID BIT(27) | ||
379 | #define K8_NBSH_VALID_ERROR_ADDR BIT(26) | ||
380 | #define K8_NBSH_PCC BIT(25) | ||
381 | #define K8_NBSH_CECC BIT(14) | ||
382 | #define K8_NBSH_UECC BIT(13) | ||
383 | #define K8_NBSH_ERR_SCRUBER BIT(8) | ||
384 | #define K8_NBSH_CORE3 BIT(3) | ||
385 | #define K8_NBSH_CORE2 BIT(2) | ||
386 | #define K8_NBSH_CORE1 BIT(1) | ||
387 | #define K8_NBSH_CORE0 BIT(0) | ||
388 | |||
389 | #define EXTRACT_LDT_LINK(x) (((x) >> 4) & 0x7) | ||
390 | #define EXTRACT_ERR_CPU_MAP(x) ((x) & 0xF) | ||
391 | #define EXTRACT_LOW_SYNDROME(x) (((x) >> 15) & 0xff) | ||
392 | |||
393 | |||
394 | #define K8_NBEAL 0x50 | ||
395 | #define K8_NBEAH 0x54 | ||
396 | #define K8_SCRCTRL 0x58 | ||
397 | |||
398 | #define F10_NB_CFG_LOW 0x88 | ||
399 | #define F10_NB_CFG_LOW_ENABLE_EXT_CFG BIT(14) | ||
400 | |||
401 | #define F10_NB_CFG_HIGH 0x8C | ||
402 | |||
403 | #define F10_ONLINE_SPARE 0xB0 | ||
404 | #define F10_ONLINE_SPARE_SWAPDONE0(x) ((x) & BIT(1)) | ||
405 | #define F10_ONLINE_SPARE_SWAPDONE1(x) ((x) & BIT(3)) | ||
406 | #define F10_ONLINE_SPARE_BADDRAM_CS0(x) (((x) >> 4) & 0x00000007) | ||
407 | #define F10_ONLINE_SPARE_BADDRAM_CS1(x) (((x) >> 8) & 0x00000007) | ||
408 | |||
409 | #define F10_NB_ARRAY_ADDR 0xB8 | ||
410 | |||
411 | #define F10_NB_ARRAY_DRAM_ECC 0x80000000 | ||
412 | |||
413 | /* Bits [2:1] are used to select 16-byte section within a 64-byte cacheline */ | ||
414 | #define SET_NB_ARRAY_ADDRESS(section) (((section) & 0x3) << 1) | ||
415 | |||
416 | #define F10_NB_ARRAY_DATA 0xBC | ||
417 | |||
418 | #define SET_NB_DRAM_INJECTION_WRITE(word, bits) \ | ||
419 | (BIT(((word) & 0xF) + 20) | \ | ||
420 | BIT(17) | \ | ||
421 | ((bits) & 0xF)) | ||
422 | |||
423 | #define SET_NB_DRAM_INJECTION_READ(word, bits) \ | ||
424 | (BIT(((word) & 0xF) + 20) | \ | ||
425 | BIT(16) | \ | ||
426 | ((bits) & 0xF)) | ||
427 | |||
428 | #define K8_NBCAP 0xE8 | ||
429 | #define K8_NBCAP_CORES (BIT(12)|BIT(13)) | ||
430 | #define K8_NBCAP_CHIPKILL BIT(4) | ||
431 | #define K8_NBCAP_SECDED BIT(3) | ||
432 | #define K8_NBCAP_8_NODE BIT(2) | ||
433 | #define K8_NBCAP_DUAL_NODE BIT(1) | ||
434 | #define K8_NBCAP_DCT_DUAL BIT(0) | ||
435 | |||
436 | /* | ||
437 | * MSR Regs | ||
438 | */ | ||
439 | #define K8_MSR_MCGCTL 0x017b | ||
440 | #define K8_MSR_MCGCTL_NBE BIT(4) | ||
441 | |||
442 | #define K8_MSR_MC4CTL 0x0410 | ||
443 | #define K8_MSR_MC4STAT 0x0411 | ||
444 | #define K8_MSR_MC4ADDR 0x0412 | ||
445 | |||
446 | /* AMD sets the first MC device at device ID 0x18. */ | ||
447 | static inline int get_mc_node_id_from_pdev(struct pci_dev *pdev) | ||
448 | { | ||
449 | return PCI_SLOT(pdev->devfn) - 0x18; | ||
450 | } | ||
451 | |||
452 | enum amd64_chipset_families { | ||
453 | K8_CPUS = 0, | ||
454 | F10_CPUS, | ||
455 | F11_CPUS, | ||
456 | }; | ||
457 | |||
458 | /* | ||
459 | * Structure to hold: | ||
460 | * | ||
461 | * 1) dynamically read status and error address HW registers | ||
462 | * 2) sysfs entered values | ||
463 | * 3) MCE values | ||
464 | * | ||
465 | * Depends on entry into the modules | ||
466 | */ | ||
467 | struct amd64_error_info_regs { | ||
468 | u32 nbcfg; | ||
469 | u32 nbsh; | ||
470 | u32 nbsl; | ||
471 | u32 nbeah; | ||
472 | u32 nbeal; | ||
473 | }; | ||
474 | |||
475 | /* Error injection control structure */ | ||
476 | struct error_injection { | ||
477 | u32 section; | ||
478 | u32 word; | ||
479 | u32 bit_map; | ||
480 | }; | ||
481 | |||
482 | struct amd64_pvt { | ||
483 | /* pci_device handles which we utilize */ | ||
484 | struct pci_dev *addr_f1_ctl; | ||
485 | struct pci_dev *dram_f2_ctl; | ||
486 | struct pci_dev *misc_f3_ctl; | ||
487 | |||
488 | int mc_node_id; /* MC index of this MC node */ | ||
489 | int ext_model; /* extended model value of this node */ | ||
490 | |||
491 | struct low_ops *ops; /* pointer to per PCI Device ID func table */ | ||
492 | |||
493 | int channel_count; | ||
494 | |||
495 | /* Raw registers */ | ||
496 | u32 dclr0; /* DRAM Configuration Low DCT0 reg */ | ||
497 | u32 dclr1; /* DRAM Configuration Low DCT1 reg */ | ||
498 | u32 dchr0; /* DRAM Configuration High DCT0 reg */ | ||
499 | u32 dchr1; /* DRAM Configuration High DCT1 reg */ | ||
500 | u32 nbcap; /* North Bridge Capabilities */ | ||
501 | u32 nbcfg; /* F10 North Bridge Configuration */ | ||
502 | u32 ext_nbcfg; /* Extended F10 North Bridge Configuration */ | ||
503 | u32 dhar; /* DRAM Hoist reg */ | ||
504 | u32 dbam0; /* DRAM Base Address Mapping reg for DCT0 */ | ||
505 | u32 dbam1; /* DRAM Base Address Mapping reg for DCT1 */ | ||
506 | |||
507 | /* DRAM CS Base Address Registers F2x[1,0][5C:40] */ | ||
508 | u32 dcsb0[CHIPSELECT_COUNT]; | ||
509 | u32 dcsb1[CHIPSELECT_COUNT]; | ||
510 | |||
511 | /* DRAM CS Mask Registers F2x[1,0][6C:60] */ | ||
512 | u32 dcsm0[CHIPSELECT_COUNT]; | ||
513 | u32 dcsm1[CHIPSELECT_COUNT]; | ||
514 | |||
515 | /* | ||
516 | * Decoded parts of DRAM BASE and LIMIT Registers | ||
517 | * F1x[78,70,68,60,58,50,48,40] | ||
518 | */ | ||
519 | u64 dram_base[DRAM_REG_COUNT]; | ||
520 | u64 dram_limit[DRAM_REG_COUNT]; | ||
521 | u8 dram_IntlvSel[DRAM_REG_COUNT]; | ||
522 | u8 dram_IntlvEn[DRAM_REG_COUNT]; | ||
523 | u8 dram_DstNode[DRAM_REG_COUNT]; | ||
524 | u8 dram_rw_en[DRAM_REG_COUNT]; | ||
525 | |||
526 | /* | ||
527 | * The following fields are set at (load) run time, after CPU revision | ||
528 | * has been determined, since the dct_base and dct_mask registers vary | ||
529 | * based on revision | ||
530 | */ | ||
531 | u32 dcsb_base; /* DCSB base bits */ | ||
532 | u32 dcsm_mask; /* DCSM mask bits */ | ||
533 | u32 num_dcsm; /* Number of DCSM registers */ | ||
534 | u32 dcs_mask_notused; /* DCSM notused mask bits */ | ||
535 | u32 dcs_shift; /* DCSB and DCSM shift value */ | ||
536 | |||
537 | u64 top_mem; /* top of memory below 4GB */ | ||
538 | u64 top_mem2; /* top of memory above 4GB */ | ||
539 | |||
540 | u32 dram_ctl_select_low; /* DRAM Controller Select Low Reg */ | ||
541 | u32 dram_ctl_select_high; /* DRAM Controller Select High Reg */ | ||
542 | u32 online_spare; /* On-Line spare Reg */ | ||
543 | |||
544 | /* temp storage for when input is received from sysfs */ | ||
545 | struct amd64_error_info_regs ctl_error_info; | ||
546 | |||
547 | /* place to store error injection parameters prior to issue */ | ||
548 | struct error_injection injection; | ||
549 | |||
550 | /* Save old hw registers' values before we modified them */ | ||
551 | u32 nbctl_mcgctl_saved; /* When true, following 2 are valid */ | ||
552 | u32 old_nbctl; | ||
553 | unsigned long old_mcgctl; /* per core on this node */ | ||
554 | |||
555 | /* MC Type Index value: socket F vs Family 10h */ | ||
556 | u32 mc_type_index; | ||
557 | |||
558 | /* misc settings */ | ||
559 | struct flags { | ||
560 | unsigned long cf8_extcfg:1; | ||
561 | } flags; | ||
562 | }; | ||
563 | |||
564 | struct scrubrate { | ||
565 | u32 scrubval; /* bit pattern for scrub rate */ | ||
566 | u32 bandwidth; /* bandwidth consumed (bytes/sec) */ | ||
567 | }; | ||
568 | |||
569 | extern struct scrubrate scrubrates[23]; | ||
570 | extern u32 revf_quad_ddr2_shift[16]; | ||
571 | extern const char *tt_msgs[4]; | ||
572 | extern const char *ll_msgs[4]; | ||
573 | extern const char *rrrr_msgs[16]; | ||
574 | extern const char *to_msgs[2]; | ||
575 | extern const char *pp_msgs[4]; | ||
576 | extern const char *ii_msgs[4]; | ||
577 | extern const char *ext_msgs[32]; | ||
578 | extern const char *htlink_msgs[8]; | ||
579 | |||
580 | #ifdef CONFIG_EDAC_DEBUG | ||
581 | #define NUM_DBG_ATTRS 9 | ||
582 | #else | ||
583 | #define NUM_DBG_ATTRS 0 | ||
584 | #endif | ||
585 | |||
586 | #ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION | ||
587 | #define NUM_INJ_ATTRS 5 | ||
588 | #else | ||
589 | #define NUM_INJ_ATTRS 0 | ||
590 | #endif | ||
591 | |||
592 | extern struct mcidev_sysfs_attribute amd64_dbg_attrs[NUM_DBG_ATTRS], | ||
593 | amd64_inj_attrs[NUM_INJ_ATTRS]; | ||
594 | |||
595 | /* | ||
596 | * Each of the PCI Device IDs types have their own set of hardware accessor | ||
597 | * functions and per device encoding/decoding logic. | ||
598 | */ | ||
599 | struct low_ops { | ||
600 | int (*probe_valid_hardware)(struct amd64_pvt *pvt); | ||
601 | int (*early_channel_count)(struct amd64_pvt *pvt); | ||
602 | |||
603 | u64 (*get_error_address)(struct mem_ctl_info *mci, | ||
604 | struct amd64_error_info_regs *info); | ||
605 | void (*read_dram_base_limit)(struct amd64_pvt *pvt, int dram); | ||
606 | void (*read_dram_ctl_register)(struct amd64_pvt *pvt); | ||
607 | void (*map_sysaddr_to_csrow)(struct mem_ctl_info *mci, | ||
608 | struct amd64_error_info_regs *info, | ||
609 | u64 SystemAddr); | ||
610 | int (*dbam_map_to_pages)(struct amd64_pvt *pvt, int dram_map); | ||
611 | }; | ||
612 | |||
613 | struct amd64_family_type { | ||
614 | const char *ctl_name; | ||
615 | u16 addr_f1_ctl; | ||
616 | u16 misc_f3_ctl; | ||
617 | struct low_ops ops; | ||
618 | }; | ||
619 | |||
620 | static struct amd64_family_type amd64_family_types[]; | ||
621 | |||
622 | static inline const char *get_amd_family_name(int index) | ||
623 | { | ||
624 | return amd64_family_types[index].ctl_name; | ||
625 | } | ||
626 | |||
627 | static inline struct low_ops *family_ops(int index) | ||
628 | { | ||
629 | return &amd64_family_types[index].ops; | ||
630 | } | ||
631 | |||
632 | /* | ||
633 | * For future CPU versions, verify the following as new 'slow' rates appear and | ||
634 | * modify the necessary skip values for the supported CPU. | ||
635 | */ | ||
636 | #define K8_MIN_SCRUB_RATE_BITS 0x0 | ||
637 | #define F10_MIN_SCRUB_RATE_BITS 0x5 | ||
638 | #define F11_MIN_SCRUB_RATE_BITS 0x6 | ||
639 | |||
640 | int amd64_process_error_info(struct mem_ctl_info *mci, | ||
641 | struct amd64_error_info_regs *info, | ||
642 | int handle_errors); | ||
643 | int amd64_get_dram_hole_info(struct mem_ctl_info *mci, u64 *hole_base, | ||
644 | u64 *hole_offset, u64 *hole_size); | ||
diff --git a/drivers/edac/amd64_edac_dbg.c b/drivers/edac/amd64_edac_dbg.c new file mode 100644 index 000000000000..0a41b248a4ad --- /dev/null +++ b/drivers/edac/amd64_edac_dbg.c | |||
@@ -0,0 +1,255 @@ | |||
1 | #include "amd64_edac.h" | ||
2 | |||
3 | /* | ||
4 | * accept a hex value and store it into the virtual error register file, field: | ||
5 | * nbeal and nbeah. Assume virtual error values have already been set for: NBSL, | ||
6 | * NBSH and NBCFG. Then proceed to map the error values to a MC, CSROW and | ||
7 | * CHANNEL | ||
8 | */ | ||
9 | static ssize_t amd64_nbea_store(struct mem_ctl_info *mci, const char *data, | ||
10 | size_t count) | ||
11 | { | ||
12 | struct amd64_pvt *pvt = mci->pvt_info; | ||
13 | unsigned long long value; | ||
14 | int ret = 0; | ||
15 | |||
16 | ret = strict_strtoull(data, 16, &value); | ||
17 | if (ret != -EINVAL) { | ||
18 | debugf0("received NBEA= 0x%llx\n", value); | ||
19 | |||
20 | /* place the value into the virtual error packet */ | ||
21 | pvt->ctl_error_info.nbeal = (u32) value; | ||
22 | value >>= 32; | ||
23 | pvt->ctl_error_info.nbeah = (u32) value; | ||
24 | |||
25 | /* Process the Mapping request */ | ||
26 | /* TODO: Add race prevention */ | ||
27 | amd64_process_error_info(mci, &pvt->ctl_error_info, 1); | ||
28 | |||
29 | return count; | ||
30 | } | ||
31 | return ret; | ||
32 | } | ||
33 | |||
34 | /* display back what the last NBEA (MCA NB Address (MC4_ADDR)) was written */ | ||
35 | static ssize_t amd64_nbea_show(struct mem_ctl_info *mci, char *data) | ||
36 | { | ||
37 | struct amd64_pvt *pvt = mci->pvt_info; | ||
38 | u64 value; | ||
39 | |||
40 | value = pvt->ctl_error_info.nbeah; | ||
41 | value <<= 32; | ||
42 | value |= pvt->ctl_error_info.nbeal; | ||
43 | |||
44 | return sprintf(data, "%llx\n", value); | ||
45 | } | ||
46 | |||
47 | /* store the NBSL (MCA NB Status Low (MC4_STATUS)) value user desires */ | ||
48 | static ssize_t amd64_nbsl_store(struct mem_ctl_info *mci, const char *data, | ||
49 | size_t count) | ||
50 | { | ||
51 | struct amd64_pvt *pvt = mci->pvt_info; | ||
52 | unsigned long value; | ||
53 | int ret = 0; | ||
54 | |||
55 | ret = strict_strtoul(data, 16, &value); | ||
56 | if (ret != -EINVAL) { | ||
57 | debugf0("received NBSL= 0x%lx\n", value); | ||
58 | |||
59 | pvt->ctl_error_info.nbsl = (u32) value; | ||
60 | |||
61 | return count; | ||
62 | } | ||
63 | return ret; | ||
64 | } | ||
65 | |||
66 | /* display back what the last NBSL value written */ | ||
67 | static ssize_t amd64_nbsl_show(struct mem_ctl_info *mci, char *data) | ||
68 | { | ||
69 | struct amd64_pvt *pvt = mci->pvt_info; | ||
70 | u32 value; | ||
71 | |||
72 | value = pvt->ctl_error_info.nbsl; | ||
73 | |||
74 | return sprintf(data, "%x\n", value); | ||
75 | } | ||
76 | |||
77 | /* store the NBSH (MCA NB Status High) value user desires */ | ||
78 | static ssize_t amd64_nbsh_store(struct mem_ctl_info *mci, const char *data, | ||
79 | size_t count) | ||
80 | { | ||
81 | struct amd64_pvt *pvt = mci->pvt_info; | ||
82 | unsigned long value; | ||
83 | int ret = 0; | ||
84 | |||
85 | ret = strict_strtoul(data, 16, &value); | ||
86 | if (ret != -EINVAL) { | ||
87 | debugf0("received NBSH= 0x%lx\n", value); | ||
88 | |||
89 | pvt->ctl_error_info.nbsh = (u32) value; | ||
90 | |||
91 | return count; | ||
92 | } | ||
93 | return ret; | ||
94 | } | ||
95 | |||
96 | /* display back what the last NBSH value written */ | ||
97 | static ssize_t amd64_nbsh_show(struct mem_ctl_info *mci, char *data) | ||
98 | { | ||
99 | struct amd64_pvt *pvt = mci->pvt_info; | ||
100 | u32 value; | ||
101 | |||
102 | value = pvt->ctl_error_info.nbsh; | ||
103 | |||
104 | return sprintf(data, "%x\n", value); | ||
105 | } | ||
106 | |||
107 | /* accept and store the NBCFG (MCA NB Configuration) value user desires */ | ||
108 | static ssize_t amd64_nbcfg_store(struct mem_ctl_info *mci, | ||
109 | const char *data, size_t count) | ||
110 | { | ||
111 | struct amd64_pvt *pvt = mci->pvt_info; | ||
112 | unsigned long value; | ||
113 | int ret = 0; | ||
114 | |||
115 | ret = strict_strtoul(data, 16, &value); | ||
116 | if (ret != -EINVAL) { | ||
117 | debugf0("received NBCFG= 0x%lx\n", value); | ||
118 | |||
119 | pvt->ctl_error_info.nbcfg = (u32) value; | ||
120 | |||
121 | return count; | ||
122 | } | ||
123 | return ret; | ||
124 | } | ||
125 | |||
126 | /* various show routines for the controls of a MCI */ | ||
127 | static ssize_t amd64_nbcfg_show(struct mem_ctl_info *mci, char *data) | ||
128 | { | ||
129 | struct amd64_pvt *pvt = mci->pvt_info; | ||
130 | |||
131 | return sprintf(data, "%x\n", pvt->ctl_error_info.nbcfg); | ||
132 | } | ||
133 | |||
134 | |||
135 | static ssize_t amd64_dhar_show(struct mem_ctl_info *mci, char *data) | ||
136 | { | ||
137 | struct amd64_pvt *pvt = mci->pvt_info; | ||
138 | |||
139 | return sprintf(data, "%x\n", pvt->dhar); | ||
140 | } | ||
141 | |||
142 | |||
143 | static ssize_t amd64_dbam_show(struct mem_ctl_info *mci, char *data) | ||
144 | { | ||
145 | struct amd64_pvt *pvt = mci->pvt_info; | ||
146 | |||
147 | return sprintf(data, "%x\n", pvt->dbam0); | ||
148 | } | ||
149 | |||
150 | |||
151 | static ssize_t amd64_topmem_show(struct mem_ctl_info *mci, char *data) | ||
152 | { | ||
153 | struct amd64_pvt *pvt = mci->pvt_info; | ||
154 | |||
155 | return sprintf(data, "%llx\n", pvt->top_mem); | ||
156 | } | ||
157 | |||
158 | |||
159 | static ssize_t amd64_topmem2_show(struct mem_ctl_info *mci, char *data) | ||
160 | { | ||
161 | struct amd64_pvt *pvt = mci->pvt_info; | ||
162 | |||
163 | return sprintf(data, "%llx\n", pvt->top_mem2); | ||
164 | } | ||
165 | |||
166 | static ssize_t amd64_hole_show(struct mem_ctl_info *mci, char *data) | ||
167 | { | ||
168 | u64 hole_base = 0; | ||
169 | u64 hole_offset = 0; | ||
170 | u64 hole_size = 0; | ||
171 | |||
172 | amd64_get_dram_hole_info(mci, &hole_base, &hole_offset, &hole_size); | ||
173 | |||
174 | return sprintf(data, "%llx %llx %llx\n", hole_base, hole_offset, | ||
175 | hole_size); | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * update NUM_DBG_ATTRS in case you add new members | ||
180 | */ | ||
181 | struct mcidev_sysfs_attribute amd64_dbg_attrs[] = { | ||
182 | |||
183 | { | ||
184 | .attr = { | ||
185 | .name = "nbea_ctl", | ||
186 | .mode = (S_IRUGO | S_IWUSR) | ||
187 | }, | ||
188 | .show = amd64_nbea_show, | ||
189 | .store = amd64_nbea_store, | ||
190 | }, | ||
191 | { | ||
192 | .attr = { | ||
193 | .name = "nbsl_ctl", | ||
194 | .mode = (S_IRUGO | S_IWUSR) | ||
195 | }, | ||
196 | .show = amd64_nbsl_show, | ||
197 | .store = amd64_nbsl_store, | ||
198 | }, | ||
199 | { | ||
200 | .attr = { | ||
201 | .name = "nbsh_ctl", | ||
202 | .mode = (S_IRUGO | S_IWUSR) | ||
203 | }, | ||
204 | .show = amd64_nbsh_show, | ||
205 | .store = amd64_nbsh_store, | ||
206 | }, | ||
207 | { | ||
208 | .attr = { | ||
209 | .name = "nbcfg_ctl", | ||
210 | .mode = (S_IRUGO | S_IWUSR) | ||
211 | }, | ||
212 | .show = amd64_nbcfg_show, | ||
213 | .store = amd64_nbcfg_store, | ||
214 | }, | ||
215 | { | ||
216 | .attr = { | ||
217 | .name = "dhar", | ||
218 | .mode = (S_IRUGO) | ||
219 | }, | ||
220 | .show = amd64_dhar_show, | ||
221 | .store = NULL, | ||
222 | }, | ||
223 | { | ||
224 | .attr = { | ||
225 | .name = "dbam", | ||
226 | .mode = (S_IRUGO) | ||
227 | }, | ||
228 | .show = amd64_dbam_show, | ||
229 | .store = NULL, | ||
230 | }, | ||
231 | { | ||
232 | .attr = { | ||
233 | .name = "topmem", | ||
234 | .mode = (S_IRUGO) | ||
235 | }, | ||
236 | .show = amd64_topmem_show, | ||
237 | .store = NULL, | ||
238 | }, | ||
239 | { | ||
240 | .attr = { | ||
241 | .name = "topmem2", | ||
242 | .mode = (S_IRUGO) | ||
243 | }, | ||
244 | .show = amd64_topmem2_show, | ||
245 | .store = NULL, | ||
246 | }, | ||
247 | { | ||
248 | .attr = { | ||
249 | .name = "dram_hole", | ||
250 | .mode = (S_IRUGO) | ||
251 | }, | ||
252 | .show = amd64_hole_show, | ||
253 | .store = NULL, | ||
254 | }, | ||
255 | }; | ||
diff --git a/drivers/edac/amd64_edac_err_types.c b/drivers/edac/amd64_edac_err_types.c new file mode 100644 index 000000000000..f212ff12a9d8 --- /dev/null +++ b/drivers/edac/amd64_edac_err_types.c | |||
@@ -0,0 +1,161 @@ | |||
1 | #include "amd64_edac.h" | ||
2 | |||
3 | /* | ||
4 | * See F2x80 for K8 and F2x[1,0]80 for Fam10 and later. The table below is only | ||
5 | * for DDR2 DRAM mapping. | ||
6 | */ | ||
7 | u32 revf_quad_ddr2_shift[] = { | ||
8 | 0, /* 0000b NULL DIMM (128mb) */ | ||
9 | 28, /* 0001b 256mb */ | ||
10 | 29, /* 0010b 512mb */ | ||
11 | 29, /* 0011b 512mb */ | ||
12 | 29, /* 0100b 512mb */ | ||
13 | 30, /* 0101b 1gb */ | ||
14 | 30, /* 0110b 1gb */ | ||
15 | 31, /* 0111b 2gb */ | ||
16 | 31, /* 1000b 2gb */ | ||
17 | 32, /* 1001b 4gb */ | ||
18 | 32, /* 1010b 4gb */ | ||
19 | 33, /* 1011b 8gb */ | ||
20 | 0, /* 1100b future */ | ||
21 | 0, /* 1101b future */ | ||
22 | 0, /* 1110b future */ | ||
23 | 0 /* 1111b future */ | ||
24 | }; | ||
25 | |||
26 | /* | ||
27 | * Valid scrub rates for the K8 hardware memory scrubber. We map the scrubbing | ||
28 | * bandwidth to a valid bit pattern. The 'set' operation finds the 'matching- | ||
29 | * or higher value'. | ||
30 | * | ||
31 | *FIXME: Produce a better mapping/linearisation. | ||
32 | */ | ||
33 | |||
34 | struct scrubrate scrubrates[] = { | ||
35 | { 0x01, 1600000000UL}, | ||
36 | { 0x02, 800000000UL}, | ||
37 | { 0x03, 400000000UL}, | ||
38 | { 0x04, 200000000UL}, | ||
39 | { 0x05, 100000000UL}, | ||
40 | { 0x06, 50000000UL}, | ||
41 | { 0x07, 25000000UL}, | ||
42 | { 0x08, 12284069UL}, | ||
43 | { 0x09, 6274509UL}, | ||
44 | { 0x0A, 3121951UL}, | ||
45 | { 0x0B, 1560975UL}, | ||
46 | { 0x0C, 781440UL}, | ||
47 | { 0x0D, 390720UL}, | ||
48 | { 0x0E, 195300UL}, | ||
49 | { 0x0F, 97650UL}, | ||
50 | { 0x10, 48854UL}, | ||
51 | { 0x11, 24427UL}, | ||
52 | { 0x12, 12213UL}, | ||
53 | { 0x13, 6101UL}, | ||
54 | { 0x14, 3051UL}, | ||
55 | { 0x15, 1523UL}, | ||
56 | { 0x16, 761UL}, | ||
57 | { 0x00, 0UL}, /* scrubbing off */ | ||
58 | }; | ||
59 | |||
60 | /* | ||
61 | * string representation for the different MCA reported error types, see F3x48 | ||
62 | * or MSR0000_0411. | ||
63 | */ | ||
64 | const char *tt_msgs[] = { /* transaction type */ | ||
65 | "instruction", | ||
66 | "data", | ||
67 | "generic", | ||
68 | "reserved" | ||
69 | }; | ||
70 | |||
71 | const char *ll_msgs[] = { /* cache level */ | ||
72 | "L0", | ||
73 | "L1", | ||
74 | "L2", | ||
75 | "L3/generic" | ||
76 | }; | ||
77 | |||
78 | const char *rrrr_msgs[] = { | ||
79 | "generic", | ||
80 | "generic read", | ||
81 | "generic write", | ||
82 | "data read", | ||
83 | "data write", | ||
84 | "inst fetch", | ||
85 | "prefetch", | ||
86 | "evict", | ||
87 | "snoop", | ||
88 | "reserved RRRR= 9", | ||
89 | "reserved RRRR= 10", | ||
90 | "reserved RRRR= 11", | ||
91 | "reserved RRRR= 12", | ||
92 | "reserved RRRR= 13", | ||
93 | "reserved RRRR= 14", | ||
94 | "reserved RRRR= 15" | ||
95 | }; | ||
96 | |||
97 | const char *pp_msgs[] = { /* participating processor */ | ||
98 | "local node originated (SRC)", | ||
99 | "local node responded to request (RES)", | ||
100 | "local node observed as 3rd party (OBS)", | ||
101 | "generic" | ||
102 | }; | ||
103 | |||
104 | const char *to_msgs[] = { | ||
105 | "no timeout", | ||
106 | "timed out" | ||
107 | }; | ||
108 | |||
109 | const char *ii_msgs[] = { /* memory or i/o */ | ||
110 | "mem access", | ||
111 | "reserved", | ||
112 | "i/o access", | ||
113 | "generic" | ||
114 | }; | ||
115 | |||
116 | /* Map the 5 bits of Extended Error code to the string table. */ | ||
117 | const char *ext_msgs[] = { /* extended error */ | ||
118 | "K8 ECC error/F10 reserved", /* 0_0000b */ | ||
119 | "CRC error", /* 0_0001b */ | ||
120 | "sync error", /* 0_0010b */ | ||
121 | "mst abort", /* 0_0011b */ | ||
122 | "tgt abort", /* 0_0100b */ | ||
123 | "GART error", /* 0_0101b */ | ||
124 | "RMW error", /* 0_0110b */ | ||
125 | "Wdog timer error", /* 0_0111b */ | ||
126 | "F10-ECC/K8-Chipkill error", /* 0_1000b */ | ||
127 | "DEV Error", /* 0_1001b */ | ||
128 | "Link Data error", /* 0_1010b */ | ||
129 | "Link or L3 Protocol error", /* 0_1011b */ | ||
130 | "NB Array error", /* 0_1100b */ | ||
131 | "DRAM Parity error", /* 0_1101b */ | ||
132 | "Link Retry/GART Table Walk/DEV Table Walk error", /* 0_1110b */ | ||
133 | "Res 0x0ff error", /* 0_1111b */ | ||
134 | "Res 0x100 error", /* 1_0000b */ | ||
135 | "Res 0x101 error", /* 1_0001b */ | ||
136 | "Res 0x102 error", /* 1_0010b */ | ||
137 | "Res 0x103 error", /* 1_0011b */ | ||
138 | "Res 0x104 error", /* 1_0100b */ | ||
139 | "Res 0x105 error", /* 1_0101b */ | ||
140 | "Res 0x106 error", /* 1_0110b */ | ||
141 | "Res 0x107 error", /* 1_0111b */ | ||
142 | "Res 0x108 error", /* 1_1000b */ | ||
143 | "Res 0x109 error", /* 1_1001b */ | ||
144 | "Res 0x10A error", /* 1_1010b */ | ||
145 | "Res 0x10B error", /* 1_1011b */ | ||
146 | "L3 Cache Data error", /* 1_1100b */ | ||
147 | "L3 CacheTag error", /* 1_1101b */ | ||
148 | "L3 Cache LRU error", /* 1_1110b */ | ||
149 | "Res 0x1FF error" /* 1_1111b */ | ||
150 | }; | ||
151 | |||
152 | const char *htlink_msgs[] = { | ||
153 | "none", | ||
154 | "1", | ||
155 | "2", | ||
156 | "1 2", | ||
157 | "3", | ||
158 | "1 3", | ||
159 | "2 3", | ||
160 | "1 2 3" | ||
161 | }; | ||
diff --git a/drivers/edac/amd64_edac_inj.c b/drivers/edac/amd64_edac_inj.c new file mode 100644 index 000000000000..d3675b76b3a7 --- /dev/null +++ b/drivers/edac/amd64_edac_inj.c | |||
@@ -0,0 +1,185 @@ | |||
1 | #include "amd64_edac.h" | ||
2 | |||
3 | /* | ||
4 | * store error injection section value which refers to one of 4 16-byte sections | ||
5 | * within a 64-byte cacheline | ||
6 | * | ||
7 | * range: 0..3 | ||
8 | */ | ||
9 | static ssize_t amd64_inject_section_store(struct mem_ctl_info *mci, | ||
10 | const char *data, size_t count) | ||
11 | { | ||
12 | struct amd64_pvt *pvt = mci->pvt_info; | ||
13 | unsigned long value; | ||
14 | int ret = 0; | ||
15 | |||
16 | ret = strict_strtoul(data, 10, &value); | ||
17 | if (ret != -EINVAL) { | ||
18 | pvt->injection.section = (u32) value; | ||
19 | return count; | ||
20 | } | ||
21 | return ret; | ||
22 | } | ||
23 | |||
24 | /* | ||
25 | * store error injection word value which refers to one of 9 16-bit word of the | ||
26 | * 16-byte (128-bit + ECC bits) section | ||
27 | * | ||
28 | * range: 0..8 | ||
29 | */ | ||
30 | static ssize_t amd64_inject_word_store(struct mem_ctl_info *mci, | ||
31 | const char *data, size_t count) | ||
32 | { | ||
33 | struct amd64_pvt *pvt = mci->pvt_info; | ||
34 | unsigned long value; | ||
35 | int ret = 0; | ||
36 | |||
37 | ret = strict_strtoul(data, 10, &value); | ||
38 | if (ret != -EINVAL) { | ||
39 | |||
40 | value = (value <= 8) ? value : 0; | ||
41 | pvt->injection.word = (u32) value; | ||
42 | |||
43 | return count; | ||
44 | } | ||
45 | return ret; | ||
46 | } | ||
47 | |||
48 | /* | ||
49 | * store 16 bit error injection vector which enables injecting errors to the | ||
50 | * corresponding bit within the error injection word above. When used during a | ||
51 | * DRAM ECC read, it holds the contents of the of the DRAM ECC bits. | ||
52 | */ | ||
53 | static ssize_t amd64_inject_ecc_vector_store(struct mem_ctl_info *mci, | ||
54 | const char *data, size_t count) | ||
55 | { | ||
56 | struct amd64_pvt *pvt = mci->pvt_info; | ||
57 | unsigned long value; | ||
58 | int ret = 0; | ||
59 | |||
60 | ret = strict_strtoul(data, 16, &value); | ||
61 | if (ret != -EINVAL) { | ||
62 | |||
63 | pvt->injection.bit_map = (u32) value & 0xFFFF; | ||
64 | |||
65 | return count; | ||
66 | } | ||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | /* | ||
71 | * Do a DRAM ECC read. Assemble staged values in the pvt area, format into | ||
72 | * fields needed by the injection registers and read the NB Array Data Port. | ||
73 | */ | ||
74 | static ssize_t amd64_inject_read_store(struct mem_ctl_info *mci, | ||
75 | const char *data, size_t count) | ||
76 | { | ||
77 | struct amd64_pvt *pvt = mci->pvt_info; | ||
78 | unsigned long value; | ||
79 | u32 section, word_bits; | ||
80 | int ret = 0; | ||
81 | |||
82 | ret = strict_strtoul(data, 10, &value); | ||
83 | if (ret != -EINVAL) { | ||
84 | |||
85 | /* Form value to choose 16-byte section of cacheline */ | ||
86 | section = F10_NB_ARRAY_DRAM_ECC | | ||
87 | SET_NB_ARRAY_ADDRESS(pvt->injection.section); | ||
88 | pci_write_config_dword(pvt->misc_f3_ctl, | ||
89 | F10_NB_ARRAY_ADDR, section); | ||
90 | |||
91 | word_bits = SET_NB_DRAM_INJECTION_READ(pvt->injection.word, | ||
92 | pvt->injection.bit_map); | ||
93 | |||
94 | /* Issue 'word' and 'bit' along with the READ request */ | ||
95 | pci_write_config_dword(pvt->misc_f3_ctl, | ||
96 | F10_NB_ARRAY_DATA, word_bits); | ||
97 | |||
98 | debugf0("section=0x%x word_bits=0x%x\n", section, word_bits); | ||
99 | |||
100 | return count; | ||
101 | } | ||
102 | return ret; | ||
103 | } | ||
104 | |||
105 | /* | ||
106 | * Do a DRAM ECC write. Assemble staged values in the pvt area and format into | ||
107 | * fields needed by the injection registers. | ||
108 | */ | ||
109 | static ssize_t amd64_inject_write_store(struct mem_ctl_info *mci, | ||
110 | const char *data, size_t count) | ||
111 | { | ||
112 | struct amd64_pvt *pvt = mci->pvt_info; | ||
113 | unsigned long value; | ||
114 | u32 section, word_bits; | ||
115 | int ret = 0; | ||
116 | |||
117 | ret = strict_strtoul(data, 10, &value); | ||
118 | if (ret != -EINVAL) { | ||
119 | |||
120 | /* Form value to choose 16-byte section of cacheline */ | ||
121 | section = F10_NB_ARRAY_DRAM_ECC | | ||
122 | SET_NB_ARRAY_ADDRESS(pvt->injection.section); | ||
123 | pci_write_config_dword(pvt->misc_f3_ctl, | ||
124 | F10_NB_ARRAY_ADDR, section); | ||
125 | |||
126 | word_bits = SET_NB_DRAM_INJECTION_WRITE(pvt->injection.word, | ||
127 | pvt->injection.bit_map); | ||
128 | |||
129 | /* Issue 'word' and 'bit' along with the READ request */ | ||
130 | pci_write_config_dword(pvt->misc_f3_ctl, | ||
131 | F10_NB_ARRAY_DATA, word_bits); | ||
132 | |||
133 | debugf0("section=0x%x word_bits=0x%x\n", section, word_bits); | ||
134 | |||
135 | return count; | ||
136 | } | ||
137 | return ret; | ||
138 | } | ||
139 | |||
140 | /* | ||
141 | * update NUM_INJ_ATTRS in case you add new members | ||
142 | */ | ||
143 | struct mcidev_sysfs_attribute amd64_inj_attrs[] = { | ||
144 | |||
145 | { | ||
146 | .attr = { | ||
147 | .name = "inject_section", | ||
148 | .mode = (S_IRUGO | S_IWUSR) | ||
149 | }, | ||
150 | .show = NULL, | ||
151 | .store = amd64_inject_section_store, | ||
152 | }, | ||
153 | { | ||
154 | .attr = { | ||
155 | .name = "inject_word", | ||
156 | .mode = (S_IRUGO | S_IWUSR) | ||
157 | }, | ||
158 | .show = NULL, | ||
159 | .store = amd64_inject_word_store, | ||
160 | }, | ||
161 | { | ||
162 | .attr = { | ||
163 | .name = "inject_ecc_vector", | ||
164 | .mode = (S_IRUGO | S_IWUSR) | ||
165 | }, | ||
166 | .show = NULL, | ||
167 | .store = amd64_inject_ecc_vector_store, | ||
168 | }, | ||
169 | { | ||
170 | .attr = { | ||
171 | .name = "inject_write", | ||
172 | .mode = (S_IRUGO | S_IWUSR) | ||
173 | }, | ||
174 | .show = NULL, | ||
175 | .store = amd64_inject_write_store, | ||
176 | }, | ||
177 | { | ||
178 | .attr = { | ||
179 | .name = "inject_read", | ||
180 | .mode = (S_IRUGO | S_IWUSR) | ||
181 | }, | ||
182 | .show = NULL, | ||
183 | .store = amd64_inject_read_store, | ||
184 | }, | ||
185 | }; | ||
diff --git a/drivers/edac/amd8111_edac.c b/drivers/edac/amd8111_edac.c index 614692181120..2cb58ef743e0 100644 --- a/drivers/edac/amd8111_edac.c +++ b/drivers/edac/amd8111_edac.c | |||
@@ -389,7 +389,7 @@ static int amd8111_dev_probe(struct pci_dev *dev, | |||
389 | dev_info->edac_dev->dev = &dev_info->dev->dev; | 389 | dev_info->edac_dev->dev = &dev_info->dev->dev; |
390 | dev_info->edac_dev->mod_name = AMD8111_EDAC_MOD_STR; | 390 | dev_info->edac_dev->mod_name = AMD8111_EDAC_MOD_STR; |
391 | dev_info->edac_dev->ctl_name = dev_info->ctl_name; | 391 | dev_info->edac_dev->ctl_name = dev_info->ctl_name; |
392 | dev_info->edac_dev->dev_name = dev_info->dev->dev.bus_id; | 392 | dev_info->edac_dev->dev_name = dev_name(&dev_info->dev->dev); |
393 | 393 | ||
394 | if (edac_op_state == EDAC_OPSTATE_POLL) | 394 | if (edac_op_state == EDAC_OPSTATE_POLL) |
395 | dev_info->edac_dev->edac_check = dev_info->check; | 395 | dev_info->edac_dev->edac_check = dev_info->check; |
@@ -473,7 +473,7 @@ static int amd8111_pci_probe(struct pci_dev *dev, | |||
473 | pci_info->edac_dev->dev = &pci_info->dev->dev; | 473 | pci_info->edac_dev->dev = &pci_info->dev->dev; |
474 | pci_info->edac_dev->mod_name = AMD8111_EDAC_MOD_STR; | 474 | pci_info->edac_dev->mod_name = AMD8111_EDAC_MOD_STR; |
475 | pci_info->edac_dev->ctl_name = pci_info->ctl_name; | 475 | pci_info->edac_dev->ctl_name = pci_info->ctl_name; |
476 | pci_info->edac_dev->dev_name = pci_info->dev->dev.bus_id; | 476 | pci_info->edac_dev->dev_name = dev_name(&pci_info->dev->dev); |
477 | 477 | ||
478 | if (edac_op_state == EDAC_OPSTATE_POLL) | 478 | if (edac_op_state == EDAC_OPSTATE_POLL) |
479 | pci_info->edac_dev->edac_check = pci_info->check; | 479 | pci_info->edac_dev->edac_check = pci_info->check; |
diff --git a/drivers/edac/amd8131_edac.c b/drivers/edac/amd8131_edac.c index c083b31cac5a..b432d60c622a 100644 --- a/drivers/edac/amd8131_edac.c +++ b/drivers/edac/amd8131_edac.c | |||
@@ -287,7 +287,7 @@ static int amd8131_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
287 | dev_info->edac_dev->dev = &dev_info->dev->dev; | 287 | dev_info->edac_dev->dev = &dev_info->dev->dev; |
288 | dev_info->edac_dev->mod_name = AMD8131_EDAC_MOD_STR; | 288 | dev_info->edac_dev->mod_name = AMD8131_EDAC_MOD_STR; |
289 | dev_info->edac_dev->ctl_name = dev_info->ctl_name; | 289 | dev_info->edac_dev->ctl_name = dev_info->ctl_name; |
290 | dev_info->edac_dev->dev_name = dev_info->dev->dev.bus_id; | 290 | dev_info->edac_dev->dev_name = dev_name(&dev_info->dev->dev); |
291 | 291 | ||
292 | if (edac_op_state == EDAC_OPSTATE_POLL) | 292 | if (edac_op_state == EDAC_OPSTATE_POLL) |
293 | dev_info->edac_dev->edac_check = amd8131_chipset.check; | 293 | dev_info->edac_dev->edac_check = amd8131_chipset.check; |
diff --git a/drivers/edac/edac_core.h b/drivers/edac/edac_core.h index 6ad95c8d6363..48d3b1409834 100644 --- a/drivers/edac/edac_core.h +++ b/drivers/edac/edac_core.h | |||
@@ -76,10 +76,11 @@ | |||
76 | extern int edac_debug_level; | 76 | extern int edac_debug_level; |
77 | 77 | ||
78 | #ifndef CONFIG_EDAC_DEBUG_VERBOSE | 78 | #ifndef CONFIG_EDAC_DEBUG_VERBOSE |
79 | #define edac_debug_printk(level, fmt, arg...) \ | 79 | #define edac_debug_printk(level, fmt, arg...) \ |
80 | do { \ | 80 | do { \ |
81 | if (level <= edac_debug_level) \ | 81 | if (level <= edac_debug_level) \ |
82 | edac_printk(KERN_DEBUG, EDAC_DEBUG, fmt, ##arg); \ | 82 | edac_printk(KERN_DEBUG, EDAC_DEBUG, \ |
83 | "%s: " fmt, __func__, ##arg); \ | ||
83 | } while (0) | 84 | } while (0) |
84 | #else /* CONFIG_EDAC_DEBUG_VERBOSE */ | 85 | #else /* CONFIG_EDAC_DEBUG_VERBOSE */ |
85 | #define edac_debug_printk(level, fmt, arg...) \ | 86 | #define edac_debug_printk(level, fmt, arg...) \ |
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 4cd35d8fd799..f5d46e7199d4 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig | |||
@@ -67,12 +67,18 @@ config DRM_I830 | |||
67 | will load the correct one. | 67 | will load the correct one. |
68 | 68 | ||
69 | config DRM_I915 | 69 | config DRM_I915 |
70 | tristate "i915 driver" | ||
70 | select FB_CFB_FILLRECT | 71 | select FB_CFB_FILLRECT |
71 | select FB_CFB_COPYAREA | 72 | select FB_CFB_COPYAREA |
72 | select FB_CFB_IMAGEBLIT | 73 | select FB_CFB_IMAGEBLIT |
73 | select FB | 74 | select FB |
74 | select FRAMEBUFFER_CONSOLE if !EMBEDDED | 75 | select FRAMEBUFFER_CONSOLE if !EMBEDDED |
75 | tristate "i915 driver" | 76 | # i915 depends on ACPI_VIDEO when ACPI is enabled |
77 | # but for select to work, need to select ACPI_VIDEO's dependencies, ick | ||
78 | select VIDEO_OUTPUT_CONTROL if ACPI | ||
79 | select BACKLIGHT_CLASS_DEVICE if ACPI | ||
80 | select INPUT if ACPI | ||
81 | select ACPI_VIDEO if ACPI | ||
76 | help | 82 | help |
77 | Choose this option if you have a system that has Intel 830M, 845G, | 83 | Choose this option if you have a system that has Intel 830M, 845G, |
78 | 852GM, 855GM 865G or 915G integrated graphics. If M is selected, the | 84 | 852GM, 855GM 865G or 915G integrated graphics. If M is selected, the |
@@ -84,12 +90,6 @@ config DRM_I915 | |||
84 | config DRM_I915_KMS | 90 | config DRM_I915_KMS |
85 | bool "Enable modesetting on intel by default" | 91 | bool "Enable modesetting on intel by default" |
86 | depends on DRM_I915 | 92 | depends on DRM_I915 |
87 | # i915 KMS depends on ACPI_VIDEO when ACPI is enabled | ||
88 | # but for select to work, need to select ACPI_VIDEO's dependencies, ick | ||
89 | select VIDEO_OUTPUT_CONTROL if ACPI | ||
90 | select BACKLIGHT_CLASS_DEVICE if ACPI | ||
91 | select INPUT if ACPI | ||
92 | select ACPI_VIDEO if ACPI | ||
93 | help | 93 | help |
94 | Choose this option if you want kernel modesetting enabled by default, | 94 | Choose this option if you want kernel modesetting enabled by default, |
95 | and you have a new enough userspace to support this. Running old | 95 | and you have a new enough userspace to support this. Running old |
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 94a768871734..8fab7890a363 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c | |||
@@ -2294,7 +2294,12 @@ int drm_mode_connector_property_set_ioctl(struct drm_device *dev, | |||
2294 | } | 2294 | } |
2295 | } | 2295 | } |
2296 | 2296 | ||
2297 | if (connector->funcs->set_property) | 2297 | /* Do DPMS ourselves */ |
2298 | if (property == connector->dev->mode_config.dpms_property) { | ||
2299 | if (connector->funcs->dpms) | ||
2300 | (*connector->funcs->dpms)(connector, (int) out_resp->value); | ||
2301 | ret = 0; | ||
2302 | } else if (connector->funcs->set_property) | ||
2298 | ret = connector->funcs->set_property(connector, property, out_resp->value); | 2303 | ret = connector->funcs->set_property(connector, property, out_resp->value); |
2299 | 2304 | ||
2300 | /* store the property value if succesful */ | 2305 | /* store the property value if succesful */ |
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c index 45890447feec..a6f73f1e99d9 100644 --- a/drivers/gpu/drm/drm_crtc_helper.c +++ b/drivers/gpu/drm/drm_crtc_helper.c | |||
@@ -199,6 +199,29 @@ static void drm_helper_add_std_modes(struct drm_device *dev, | |||
199 | } | 199 | } |
200 | 200 | ||
201 | /** | 201 | /** |
202 | * drm_helper_encoder_in_use - check if a given encoder is in use | ||
203 | * @encoder: encoder to check | ||
204 | * | ||
205 | * LOCKING: | ||
206 | * Caller must hold mode config lock. | ||
207 | * | ||
208 | * Walk @encoders's DRM device's mode_config and see if it's in use. | ||
209 | * | ||
210 | * RETURNS: | ||
211 | * True if @encoder is part of the mode_config, false otherwise. | ||
212 | */ | ||
213 | bool drm_helper_encoder_in_use(struct drm_encoder *encoder) | ||
214 | { | ||
215 | struct drm_connector *connector; | ||
216 | struct drm_device *dev = encoder->dev; | ||
217 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) | ||
218 | if (connector->encoder == encoder) | ||
219 | return true; | ||
220 | return false; | ||
221 | } | ||
222 | EXPORT_SYMBOL(drm_helper_encoder_in_use); | ||
223 | |||
224 | /** | ||
202 | * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config | 225 | * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config |
203 | * @crtc: CRTC to check | 226 | * @crtc: CRTC to check |
204 | * | 227 | * |
@@ -216,7 +239,7 @@ bool drm_helper_crtc_in_use(struct drm_crtc *crtc) | |||
216 | struct drm_device *dev = crtc->dev; | 239 | struct drm_device *dev = crtc->dev; |
217 | /* FIXME: Locking around list access? */ | 240 | /* FIXME: Locking around list access? */ |
218 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) | 241 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
219 | if (encoder->crtc == crtc) | 242 | if (encoder->crtc == crtc && drm_helper_encoder_in_use(encoder)) |
220 | return true; | 243 | return true; |
221 | return false; | 244 | return false; |
222 | } | 245 | } |
@@ -240,7 +263,7 @@ void drm_helper_disable_unused_functions(struct drm_device *dev) | |||
240 | 263 | ||
241 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | 264 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
242 | encoder_funcs = encoder->helper_private; | 265 | encoder_funcs = encoder->helper_private; |
243 | if (!encoder->crtc) | 266 | if (!drm_helper_encoder_in_use(encoder)) |
244 | (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); | 267 | (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); |
245 | } | 268 | } |
246 | 269 | ||
@@ -935,6 +958,88 @@ bool drm_helper_initial_config(struct drm_device *dev) | |||
935 | } | 958 | } |
936 | EXPORT_SYMBOL(drm_helper_initial_config); | 959 | EXPORT_SYMBOL(drm_helper_initial_config); |
937 | 960 | ||
961 | static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder) | ||
962 | { | ||
963 | int dpms = DRM_MODE_DPMS_OFF; | ||
964 | struct drm_connector *connector; | ||
965 | struct drm_device *dev = encoder->dev; | ||
966 | |||
967 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) | ||
968 | if (connector->encoder == encoder) | ||
969 | if (connector->dpms < dpms) | ||
970 | dpms = connector->dpms; | ||
971 | return dpms; | ||
972 | } | ||
973 | |||
974 | static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc) | ||
975 | { | ||
976 | int dpms = DRM_MODE_DPMS_OFF; | ||
977 | struct drm_connector *connector; | ||
978 | struct drm_device *dev = crtc->dev; | ||
979 | |||
980 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) | ||
981 | if (connector->encoder && connector->encoder->crtc == crtc) | ||
982 | if (connector->dpms < dpms) | ||
983 | dpms = connector->dpms; | ||
984 | return dpms; | ||
985 | } | ||
986 | |||
987 | /** | ||
988 | * drm_helper_connector_dpms | ||
989 | * @connector affected connector | ||
990 | * @mode DPMS mode | ||
991 | * | ||
992 | * Calls the low-level connector DPMS function, then | ||
993 | * calls appropriate encoder and crtc DPMS functions as well | ||
994 | */ | ||
995 | void drm_helper_connector_dpms(struct drm_connector *connector, int mode) | ||
996 | { | ||
997 | struct drm_encoder *encoder = connector->encoder; | ||
998 | struct drm_crtc *crtc = encoder ? encoder->crtc : NULL; | ||
999 | int old_dpms; | ||
1000 | |||
1001 | if (mode == connector->dpms) | ||
1002 | return; | ||
1003 | |||
1004 | old_dpms = connector->dpms; | ||
1005 | connector->dpms = mode; | ||
1006 | |||
1007 | /* from off to on, do crtc then encoder */ | ||
1008 | if (mode < old_dpms) { | ||
1009 | if (crtc) { | ||
1010 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; | ||
1011 | if (crtc_funcs->dpms) | ||
1012 | (*crtc_funcs->dpms) (crtc, | ||
1013 | drm_helper_choose_crtc_dpms(crtc)); | ||
1014 | } | ||
1015 | if (encoder) { | ||
1016 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; | ||
1017 | if (encoder_funcs->dpms) | ||
1018 | (*encoder_funcs->dpms) (encoder, | ||
1019 | drm_helper_choose_encoder_dpms(encoder)); | ||
1020 | } | ||
1021 | } | ||
1022 | |||
1023 | /* from on to off, do encoder then crtc */ | ||
1024 | if (mode > old_dpms) { | ||
1025 | if (encoder) { | ||
1026 | struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; | ||
1027 | if (encoder_funcs->dpms) | ||
1028 | (*encoder_funcs->dpms) (encoder, | ||
1029 | drm_helper_choose_encoder_dpms(encoder)); | ||
1030 | } | ||
1031 | if (crtc) { | ||
1032 | struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; | ||
1033 | if (crtc_funcs->dpms) | ||
1034 | (*crtc_funcs->dpms) (crtc, | ||
1035 | drm_helper_choose_crtc_dpms(crtc)); | ||
1036 | } | ||
1037 | } | ||
1038 | |||
1039 | return; | ||
1040 | } | ||
1041 | EXPORT_SYMBOL(drm_helper_connector_dpms); | ||
1042 | |||
938 | /** | 1043 | /** |
939 | * drm_hotplug_stage_two | 1044 | * drm_hotplug_stage_two |
940 | * @dev DRM device | 1045 | * @dev DRM device |
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index ca9c61656714..6f6b26479d82 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c | |||
@@ -289,6 +289,11 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, | |||
289 | struct drm_display_mode *mode; | 289 | struct drm_display_mode *mode; |
290 | struct detailed_pixel_timing *pt = &timing->data.pixel_data; | 290 | struct detailed_pixel_timing *pt = &timing->data.pixel_data; |
291 | 291 | ||
292 | /* ignore tiny modes */ | ||
293 | if (((pt->hactive_hi << 8) | pt->hactive_lo) < 64 || | ||
294 | ((pt->vactive_hi << 8) | pt->hactive_lo) < 64) | ||
295 | return NULL; | ||
296 | |||
292 | if (pt->stereo) { | 297 | if (pt->stereo) { |
293 | printk(KERN_WARNING "stereo mode not supported\n"); | 298 | printk(KERN_WARNING "stereo mode not supported\n"); |
294 | return NULL; | 299 | return NULL; |
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index 93e677a481f5..fc8e5acd9d9a 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c | |||
@@ -196,6 +196,7 @@ int drm_irq_install(struct drm_device *dev) | |||
196 | { | 196 | { |
197 | int ret = 0; | 197 | int ret = 0; |
198 | unsigned long sh_flags = 0; | 198 | unsigned long sh_flags = 0; |
199 | char *irqname; | ||
199 | 200 | ||
200 | if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ)) | 201 | if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ)) |
201 | return -EINVAL; | 202 | return -EINVAL; |
@@ -227,8 +228,13 @@ int drm_irq_install(struct drm_device *dev) | |||
227 | if (drm_core_check_feature(dev, DRIVER_IRQ_SHARED)) | 228 | if (drm_core_check_feature(dev, DRIVER_IRQ_SHARED)) |
228 | sh_flags = IRQF_SHARED; | 229 | sh_flags = IRQF_SHARED; |
229 | 230 | ||
231 | if (dev->devname) | ||
232 | irqname = dev->devname; | ||
233 | else | ||
234 | irqname = dev->driver->name; | ||
235 | |||
230 | ret = request_irq(drm_dev_to_irq(dev), dev->driver->irq_handler, | 236 | ret = request_irq(drm_dev_to_irq(dev), dev->driver->irq_handler, |
231 | sh_flags, dev->devname, dev); | 237 | sh_flags, irqname, dev); |
232 | 238 | ||
233 | if (ret < 0) { | 239 | if (ret < 0) { |
234 | mutex_lock(&dev->struct_mutex); | 240 | mutex_lock(&dev->struct_mutex); |
diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c index 8f9372921f82..9987ab880835 100644 --- a/drivers/gpu/drm/drm_sysfs.c +++ b/drivers/gpu/drm/drm_sysfs.c | |||
@@ -147,7 +147,7 @@ static ssize_t status_show(struct device *device, | |||
147 | enum drm_connector_status status; | 147 | enum drm_connector_status status; |
148 | 148 | ||
149 | status = connector->funcs->detect(connector); | 149 | status = connector->funcs->detect(connector); |
150 | return snprintf(buf, PAGE_SIZE, "%s", | 150 | return snprintf(buf, PAGE_SIZE, "%s\n", |
151 | drm_get_connector_status_name(status)); | 151 | drm_get_connector_status_name(status)); |
152 | } | 152 | } |
153 | 153 | ||
@@ -166,7 +166,7 @@ static ssize_t dpms_show(struct device *device, | |||
166 | if (ret) | 166 | if (ret) |
167 | return 0; | 167 | return 0; |
168 | 168 | ||
169 | return snprintf(buf, PAGE_SIZE, "%s", | 169 | return snprintf(buf, PAGE_SIZE, "%s\n", |
170 | drm_get_dpms_name((int)dpms_status)); | 170 | drm_get_dpms_name((int)dpms_status)); |
171 | } | 171 | } |
172 | 172 | ||
@@ -176,7 +176,7 @@ static ssize_t enabled_show(struct device *device, | |||
176 | { | 176 | { |
177 | struct drm_connector *connector = to_drm_connector(device); | 177 | struct drm_connector *connector = to_drm_connector(device); |
178 | 178 | ||
179 | return snprintf(buf, PAGE_SIZE, connector->encoder ? "enabled" : | 179 | return snprintf(buf, PAGE_SIZE, "%s\n", connector->encoder ? "enabled" : |
180 | "disabled"); | 180 | "disabled"); |
181 | } | 181 | } |
182 | 182 | ||
@@ -317,6 +317,7 @@ static struct device_attribute connector_attrs_opt1[] = { | |||
317 | 317 | ||
318 | static struct bin_attribute edid_attr = { | 318 | static struct bin_attribute edid_attr = { |
319 | .attr.name = "edid", | 319 | .attr.name = "edid", |
320 | .attr.mode = 0444, | ||
320 | .size = 128, | 321 | .size = 128, |
321 | .read = edid_show, | 322 | .read = edid_show, |
322 | }; | 323 | }; |
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c index 53d544552625..0ccb63ee50ee 100644 --- a/drivers/gpu/drm/i915/i915_dma.c +++ b/drivers/gpu/drm/i915/i915_dma.c | |||
@@ -987,12 +987,6 @@ static int i915_load_modeset_init(struct drm_device *dev) | |||
987 | int fb_bar = IS_I9XX(dev) ? 2 : 0; | 987 | int fb_bar = IS_I9XX(dev) ? 2 : 0; |
988 | int ret = 0; | 988 | int ret = 0; |
989 | 989 | ||
990 | dev->devname = kstrdup(DRIVER_NAME, GFP_KERNEL); | ||
991 | if (!dev->devname) { | ||
992 | ret = -ENOMEM; | ||
993 | goto out; | ||
994 | } | ||
995 | |||
996 | dev->mode_config.fb_base = drm_get_resource_start(dev, fb_bar) & | 990 | dev->mode_config.fb_base = drm_get_resource_start(dev, fb_bar) & |
997 | 0xff000000; | 991 | 0xff000000; |
998 | 992 | ||
@@ -1006,7 +1000,7 @@ static int i915_load_modeset_init(struct drm_device *dev) | |||
1006 | 1000 | ||
1007 | ret = i915_probe_agp(dev, &agp_size, &prealloc_size); | 1001 | ret = i915_probe_agp(dev, &agp_size, &prealloc_size); |
1008 | if (ret) | 1002 | if (ret) |
1009 | goto kfree_devname; | 1003 | goto out; |
1010 | 1004 | ||
1011 | /* Basic memrange allocator for stolen space (aka vram) */ | 1005 | /* Basic memrange allocator for stolen space (aka vram) */ |
1012 | drm_mm_init(&dev_priv->vram, 0, prealloc_size); | 1006 | drm_mm_init(&dev_priv->vram, 0, prealloc_size); |
@@ -1024,7 +1018,7 @@ static int i915_load_modeset_init(struct drm_device *dev) | |||
1024 | 1018 | ||
1025 | ret = i915_gem_init_ringbuffer(dev); | 1019 | ret = i915_gem_init_ringbuffer(dev); |
1026 | if (ret) | 1020 | if (ret) |
1027 | goto kfree_devname; | 1021 | goto out; |
1028 | 1022 | ||
1029 | /* Allow hardware batchbuffers unless told otherwise. | 1023 | /* Allow hardware batchbuffers unless told otherwise. |
1030 | */ | 1024 | */ |
@@ -1056,8 +1050,6 @@ static int i915_load_modeset_init(struct drm_device *dev) | |||
1056 | 1050 | ||
1057 | destroy_ringbuffer: | 1051 | destroy_ringbuffer: |
1058 | i915_gem_cleanup_ringbuffer(dev); | 1052 | i915_gem_cleanup_ringbuffer(dev); |
1059 | kfree_devname: | ||
1060 | kfree(dev->devname); | ||
1061 | out: | 1053 | out: |
1062 | return ret; | 1054 | return ret; |
1063 | } | 1055 | } |
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 9b149fe824c3..c431fa54bbb5 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h | |||
@@ -180,7 +180,8 @@ typedef struct drm_i915_private { | |||
180 | int backlight_duty_cycle; /* restore backlight to this value */ | 180 | int backlight_duty_cycle; /* restore backlight to this value */ |
181 | bool panel_wants_dither; | 181 | bool panel_wants_dither; |
182 | struct drm_display_mode *panel_fixed_mode; | 182 | struct drm_display_mode *panel_fixed_mode; |
183 | struct drm_display_mode *vbt_mode; /* if any */ | 183 | struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */ |
184 | struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */ | ||
184 | 185 | ||
185 | /* Feature bits from the VBIOS */ | 186 | /* Feature bits from the VBIOS */ |
186 | unsigned int int_tv_support:1; | 187 | unsigned int int_tv_support:1; |
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index b189b49c7602..39f5c658ef5e 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c | |||
@@ -349,7 +349,7 @@ i915_gem_shmem_pread_slow(struct drm_device *dev, struct drm_gem_object *obj, | |||
349 | last_data_page = (data_ptr + args->size - 1) / PAGE_SIZE; | 349 | last_data_page = (data_ptr + args->size - 1) / PAGE_SIZE; |
350 | num_pages = last_data_page - first_data_page + 1; | 350 | num_pages = last_data_page - first_data_page + 1; |
351 | 351 | ||
352 | user_pages = kcalloc(num_pages, sizeof(struct page *), GFP_KERNEL); | 352 | user_pages = drm_calloc_large(num_pages, sizeof(struct page *)); |
353 | if (user_pages == NULL) | 353 | if (user_pages == NULL) |
354 | return -ENOMEM; | 354 | return -ENOMEM; |
355 | 355 | ||
@@ -429,7 +429,7 @@ fail_put_user_pages: | |||
429 | SetPageDirty(user_pages[i]); | 429 | SetPageDirty(user_pages[i]); |
430 | page_cache_release(user_pages[i]); | 430 | page_cache_release(user_pages[i]); |
431 | } | 431 | } |
432 | kfree(user_pages); | 432 | drm_free_large(user_pages); |
433 | 433 | ||
434 | return ret; | 434 | return ret; |
435 | } | 435 | } |
@@ -649,7 +649,7 @@ i915_gem_gtt_pwrite_slow(struct drm_device *dev, struct drm_gem_object *obj, | |||
649 | last_data_page = (data_ptr + args->size - 1) / PAGE_SIZE; | 649 | last_data_page = (data_ptr + args->size - 1) / PAGE_SIZE; |
650 | num_pages = last_data_page - first_data_page + 1; | 650 | num_pages = last_data_page - first_data_page + 1; |
651 | 651 | ||
652 | user_pages = kcalloc(num_pages, sizeof(struct page *), GFP_KERNEL); | 652 | user_pages = drm_calloc_large(num_pages, sizeof(struct page *)); |
653 | if (user_pages == NULL) | 653 | if (user_pages == NULL) |
654 | return -ENOMEM; | 654 | return -ENOMEM; |
655 | 655 | ||
@@ -719,7 +719,7 @@ out_unlock: | |||
719 | out_unpin_pages: | 719 | out_unpin_pages: |
720 | for (i = 0; i < pinned_pages; i++) | 720 | for (i = 0; i < pinned_pages; i++) |
721 | page_cache_release(user_pages[i]); | 721 | page_cache_release(user_pages[i]); |
722 | kfree(user_pages); | 722 | drm_free_large(user_pages); |
723 | 723 | ||
724 | return ret; | 724 | return ret; |
725 | } | 725 | } |
@@ -824,7 +824,7 @@ i915_gem_shmem_pwrite_slow(struct drm_device *dev, struct drm_gem_object *obj, | |||
824 | last_data_page = (data_ptr + args->size - 1) / PAGE_SIZE; | 824 | last_data_page = (data_ptr + args->size - 1) / PAGE_SIZE; |
825 | num_pages = last_data_page - first_data_page + 1; | 825 | num_pages = last_data_page - first_data_page + 1; |
826 | 826 | ||
827 | user_pages = kcalloc(num_pages, sizeof(struct page *), GFP_KERNEL); | 827 | user_pages = drm_calloc_large(num_pages, sizeof(struct page *)); |
828 | if (user_pages == NULL) | 828 | if (user_pages == NULL) |
829 | return -ENOMEM; | 829 | return -ENOMEM; |
830 | 830 | ||
@@ -902,7 +902,7 @@ fail_unlock: | |||
902 | fail_put_user_pages: | 902 | fail_put_user_pages: |
903 | for (i = 0; i < pinned_pages; i++) | 903 | for (i = 0; i < pinned_pages; i++) |
904 | page_cache_release(user_pages[i]); | 904 | page_cache_release(user_pages[i]); |
905 | kfree(user_pages); | 905 | drm_free_large(user_pages); |
906 | 906 | ||
907 | return ret; | 907 | return ret; |
908 | } | 908 | } |
@@ -1145,7 +1145,14 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
1145 | mutex_unlock(&dev->struct_mutex); | 1145 | mutex_unlock(&dev->struct_mutex); |
1146 | return VM_FAULT_SIGBUS; | 1146 | return VM_FAULT_SIGBUS; |
1147 | } | 1147 | } |
1148 | list_add(&obj_priv->list, &dev_priv->mm.inactive_list); | 1148 | |
1149 | ret = i915_gem_object_set_to_gtt_domain(obj, write); | ||
1150 | if (ret) { | ||
1151 | mutex_unlock(&dev->struct_mutex); | ||
1152 | return VM_FAULT_SIGBUS; | ||
1153 | } | ||
1154 | |||
1155 | list_add_tail(&obj_priv->list, &dev_priv->mm.inactive_list); | ||
1149 | } | 1156 | } |
1150 | 1157 | ||
1151 | /* Need a new fence register? */ | 1158 | /* Need a new fence register? */ |
@@ -1375,7 +1382,7 @@ i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data, | |||
1375 | mutex_unlock(&dev->struct_mutex); | 1382 | mutex_unlock(&dev->struct_mutex); |
1376 | return ret; | 1383 | return ret; |
1377 | } | 1384 | } |
1378 | list_add(&obj_priv->list, &dev_priv->mm.inactive_list); | 1385 | list_add_tail(&obj_priv->list, &dev_priv->mm.inactive_list); |
1379 | } | 1386 | } |
1380 | 1387 | ||
1381 | drm_gem_object_unreference(obj); | 1388 | drm_gem_object_unreference(obj); |
@@ -1408,9 +1415,7 @@ i915_gem_object_put_pages(struct drm_gem_object *obj) | |||
1408 | } | 1415 | } |
1409 | obj_priv->dirty = 0; | 1416 | obj_priv->dirty = 0; |
1410 | 1417 | ||
1411 | drm_free(obj_priv->pages, | 1418 | drm_free_large(obj_priv->pages); |
1412 | page_count * sizeof(struct page *), | ||
1413 | DRM_MEM_DRIVER); | ||
1414 | obj_priv->pages = NULL; | 1419 | obj_priv->pages = NULL; |
1415 | } | 1420 | } |
1416 | 1421 | ||
@@ -2024,8 +2029,7 @@ i915_gem_object_get_pages(struct drm_gem_object *obj) | |||
2024 | */ | 2029 | */ |
2025 | page_count = obj->size / PAGE_SIZE; | 2030 | page_count = obj->size / PAGE_SIZE; |
2026 | BUG_ON(obj_priv->pages != NULL); | 2031 | BUG_ON(obj_priv->pages != NULL); |
2027 | obj_priv->pages = drm_calloc(page_count, sizeof(struct page *), | 2032 | obj_priv->pages = drm_calloc_large(page_count, sizeof(struct page *)); |
2028 | DRM_MEM_DRIVER); | ||
2029 | if (obj_priv->pages == NULL) { | 2033 | if (obj_priv->pages == NULL) { |
2030 | DRM_ERROR("Faled to allocate page list\n"); | 2034 | DRM_ERROR("Faled to allocate page list\n"); |
2031 | obj_priv->pages_refcount--; | 2035 | obj_priv->pages_refcount--; |
@@ -2131,8 +2135,10 @@ static void i830_write_fence_reg(struct drm_i915_fence_reg *reg) | |||
2131 | return; | 2135 | return; |
2132 | } | 2136 | } |
2133 | 2137 | ||
2134 | pitch_val = (obj_priv->stride / 128) - 1; | 2138 | pitch_val = obj_priv->stride / 128; |
2135 | WARN_ON(pitch_val & ~0x0000000f); | 2139 | pitch_val = ffs(pitch_val) - 1; |
2140 | WARN_ON(pitch_val > I830_FENCE_MAX_PITCH_VAL); | ||
2141 | |||
2136 | val = obj_priv->gtt_offset; | 2142 | val = obj_priv->gtt_offset; |
2137 | if (obj_priv->tiling_mode == I915_TILING_Y) | 2143 | if (obj_priv->tiling_mode == I915_TILING_Y) |
2138 | val |= 1 << I830_FENCE_TILING_Y_SHIFT; | 2144 | val |= 1 << I830_FENCE_TILING_Y_SHIFT; |
@@ -2254,9 +2260,6 @@ try_again: | |||
2254 | goto try_again; | 2260 | goto try_again; |
2255 | } | 2261 | } |
2256 | 2262 | ||
2257 | BUG_ON(old_obj_priv->active || | ||
2258 | (reg->obj->write_domain & I915_GEM_GPU_DOMAINS)); | ||
2259 | |||
2260 | /* | 2263 | /* |
2261 | * Zap this virtual mapping so we can set up a fence again | 2264 | * Zap this virtual mapping so we can set up a fence again |
2262 | * for this object next time we need it. | 2265 | * for this object next time we need it. |
@@ -2424,6 +2427,16 @@ i915_gem_clflush_object(struct drm_gem_object *obj) | |||
2424 | if (obj_priv->pages == NULL) | 2427 | if (obj_priv->pages == NULL) |
2425 | return; | 2428 | return; |
2426 | 2429 | ||
2430 | /* XXX: The 865 in particular appears to be weird in how it handles | ||
2431 | * cache flushing. We haven't figured it out, but the | ||
2432 | * clflush+agp_chipset_flush doesn't appear to successfully get the | ||
2433 | * data visible to the PGU, while wbinvd + agp_chipset_flush does. | ||
2434 | */ | ||
2435 | if (IS_I865G(obj->dev)) { | ||
2436 | wbinvd(); | ||
2437 | return; | ||
2438 | } | ||
2439 | |||
2427 | drm_clflush_pages(obj_priv->pages, obj->size / PAGE_SIZE); | 2440 | drm_clflush_pages(obj_priv->pages, obj->size / PAGE_SIZE); |
2428 | } | 2441 | } |
2429 | 2442 | ||
@@ -3111,7 +3124,7 @@ i915_gem_get_relocs_from_user(struct drm_i915_gem_exec_object *exec_list, | |||
3111 | reloc_count += exec_list[i].relocation_count; | 3124 | reloc_count += exec_list[i].relocation_count; |
3112 | } | 3125 | } |
3113 | 3126 | ||
3114 | *relocs = drm_calloc(reloc_count, sizeof(**relocs), DRM_MEM_DRIVER); | 3127 | *relocs = drm_calloc_large(reloc_count, sizeof(**relocs)); |
3115 | if (*relocs == NULL) | 3128 | if (*relocs == NULL) |
3116 | return -ENOMEM; | 3129 | return -ENOMEM; |
3117 | 3130 | ||
@@ -3125,8 +3138,7 @@ i915_gem_get_relocs_from_user(struct drm_i915_gem_exec_object *exec_list, | |||
3125 | exec_list[i].relocation_count * | 3138 | exec_list[i].relocation_count * |
3126 | sizeof(**relocs)); | 3139 | sizeof(**relocs)); |
3127 | if (ret != 0) { | 3140 | if (ret != 0) { |
3128 | drm_free(*relocs, reloc_count * sizeof(**relocs), | 3141 | drm_free_large(*relocs); |
3129 | DRM_MEM_DRIVER); | ||
3130 | *relocs = NULL; | 3142 | *relocs = NULL; |
3131 | return -EFAULT; | 3143 | return -EFAULT; |
3132 | } | 3144 | } |
@@ -3165,7 +3177,7 @@ i915_gem_put_relocs_to_user(struct drm_i915_gem_exec_object *exec_list, | |||
3165 | } | 3177 | } |
3166 | 3178 | ||
3167 | err: | 3179 | err: |
3168 | drm_free(relocs, reloc_count * sizeof(*relocs), DRM_MEM_DRIVER); | 3180 | drm_free_large(relocs); |
3169 | 3181 | ||
3170 | return ret; | 3182 | return ret; |
3171 | } | 3183 | } |
@@ -3198,10 +3210,8 @@ i915_gem_execbuffer(struct drm_device *dev, void *data, | |||
3198 | return -EINVAL; | 3210 | return -EINVAL; |
3199 | } | 3211 | } |
3200 | /* Copy in the exec list from userland */ | 3212 | /* Copy in the exec list from userland */ |
3201 | exec_list = drm_calloc(sizeof(*exec_list), args->buffer_count, | 3213 | exec_list = drm_calloc_large(sizeof(*exec_list), args->buffer_count); |
3202 | DRM_MEM_DRIVER); | 3214 | object_list = drm_calloc_large(sizeof(*object_list), args->buffer_count); |
3203 | object_list = drm_calloc(sizeof(*object_list), args->buffer_count, | ||
3204 | DRM_MEM_DRIVER); | ||
3205 | if (exec_list == NULL || object_list == NULL) { | 3215 | if (exec_list == NULL || object_list == NULL) { |
3206 | DRM_ERROR("Failed to allocate exec or object list " | 3216 | DRM_ERROR("Failed to allocate exec or object list " |
3207 | "for %d buffers\n", | 3217 | "for %d buffers\n", |
@@ -3462,10 +3472,8 @@ err: | |||
3462 | } | 3472 | } |
3463 | 3473 | ||
3464 | pre_mutex_err: | 3474 | pre_mutex_err: |
3465 | drm_free(object_list, sizeof(*object_list) * args->buffer_count, | 3475 | drm_free_large(object_list); |
3466 | DRM_MEM_DRIVER); | 3476 | drm_free_large(exec_list); |
3467 | drm_free(exec_list, sizeof(*exec_list) * args->buffer_count, | ||
3468 | DRM_MEM_DRIVER); | ||
3469 | drm_free(cliprects, sizeof(*cliprects) * args->num_cliprects, | 3477 | drm_free(cliprects, sizeof(*cliprects) * args->num_cliprects, |
3470 | DRM_MEM_DRIVER); | 3478 | DRM_MEM_DRIVER); |
3471 | 3479 | ||
diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c index 52a059354e83..540dd336e6ec 100644 --- a/drivers/gpu/drm/i915/i915_gem_tiling.c +++ b/drivers/gpu/drm/i915/i915_gem_tiling.c | |||
@@ -213,7 +213,8 @@ i915_tiling_ok(struct drm_device *dev, int stride, int size, int tiling_mode) | |||
213 | if (tiling_mode == I915_TILING_NONE) | 213 | if (tiling_mode == I915_TILING_NONE) |
214 | return true; | 214 | return true; |
215 | 215 | ||
216 | if (tiling_mode == I915_TILING_Y && HAS_128_BYTE_Y_TILING(dev)) | 216 | if (!IS_I9XX(dev) || |
217 | (tiling_mode == I915_TILING_Y && HAS_128_BYTE_Y_TILING(dev))) | ||
217 | tile_width = 128; | 218 | tile_width = 128; |
218 | else | 219 | else |
219 | tile_width = 512; | 220 | tile_width = 512; |
@@ -225,11 +226,18 @@ i915_tiling_ok(struct drm_device *dev, int stride, int size, int tiling_mode) | |||
225 | if (stride / 128 > I965_FENCE_MAX_PITCH_VAL) | 226 | if (stride / 128 > I965_FENCE_MAX_PITCH_VAL) |
226 | return false; | 227 | return false; |
227 | } else if (IS_I9XX(dev)) { | 228 | } else if (IS_I9XX(dev)) { |
228 | if (stride / tile_width > I830_FENCE_MAX_PITCH_VAL || | 229 | uint32_t pitch_val = ffs(stride / tile_width) - 1; |
230 | |||
231 | /* XXX: For Y tiling, FENCE_MAX_PITCH_VAL is actually 6 (8KB) | ||
232 | * instead of 4 (2KB) on 945s. | ||
233 | */ | ||
234 | if (pitch_val > I915_FENCE_MAX_PITCH_VAL || | ||
229 | size > (I830_FENCE_MAX_SIZE_VAL << 20)) | 235 | size > (I830_FENCE_MAX_SIZE_VAL << 20)) |
230 | return false; | 236 | return false; |
231 | } else { | 237 | } else { |
232 | if (stride / 128 > I830_FENCE_MAX_PITCH_VAL || | 238 | uint32_t pitch_val = ffs(stride / tile_width) - 1; |
239 | |||
240 | if (pitch_val > I830_FENCE_MAX_PITCH_VAL || | ||
233 | size > (I830_FENCE_MAX_SIZE_VAL << 19)) | 241 | size > (I830_FENCE_MAX_SIZE_VAL << 19)) |
234 | return false; | 242 | return false; |
235 | } | 243 | } |
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h index 15da44cf21b1..375569d01d01 100644 --- a/drivers/gpu/drm/i915/i915_reg.h +++ b/drivers/gpu/drm/i915/i915_reg.h | |||
@@ -190,7 +190,8 @@ | |||
190 | #define I830_FENCE_SIZE_BITS(size) ((ffs((size) >> 19) - 1) << 8) | 190 | #define I830_FENCE_SIZE_BITS(size) ((ffs((size) >> 19) - 1) << 8) |
191 | #define I830_FENCE_PITCH_SHIFT 4 | 191 | #define I830_FENCE_PITCH_SHIFT 4 |
192 | #define I830_FENCE_REG_VALID (1<<0) | 192 | #define I830_FENCE_REG_VALID (1<<0) |
193 | #define I830_FENCE_MAX_PITCH_VAL 0x10 | 193 | #define I915_FENCE_MAX_PITCH_VAL 0x10 |
194 | #define I830_FENCE_MAX_PITCH_VAL 6 | ||
194 | #define I830_FENCE_MAX_SIZE_VAL (1<<8) | 195 | #define I830_FENCE_MAX_SIZE_VAL (1<<8) |
195 | 196 | ||
196 | #define I915_FENCE_START_MASK 0x0ff00000 | 197 | #define I915_FENCE_START_MASK 0x0ff00000 |
@@ -1410,9 +1411,25 @@ | |||
1410 | 1411 | ||
1411 | /* Cursor A & B regs */ | 1412 | /* Cursor A & B regs */ |
1412 | #define CURACNTR 0x70080 | 1413 | #define CURACNTR 0x70080 |
1414 | /* Old style CUR*CNTR flags (desktop 8xx) */ | ||
1415 | #define CURSOR_ENABLE 0x80000000 | ||
1416 | #define CURSOR_GAMMA_ENABLE 0x40000000 | ||
1417 | #define CURSOR_STRIDE_MASK 0x30000000 | ||
1418 | #define CURSOR_FORMAT_SHIFT 24 | ||
1419 | #define CURSOR_FORMAT_MASK (0x07 << CURSOR_FORMAT_SHIFT) | ||
1420 | #define CURSOR_FORMAT_2C (0x00 << CURSOR_FORMAT_SHIFT) | ||
1421 | #define CURSOR_FORMAT_3C (0x01 << CURSOR_FORMAT_SHIFT) | ||
1422 | #define CURSOR_FORMAT_4C (0x02 << CURSOR_FORMAT_SHIFT) | ||
1423 | #define CURSOR_FORMAT_ARGB (0x04 << CURSOR_FORMAT_SHIFT) | ||
1424 | #define CURSOR_FORMAT_XRGB (0x05 << CURSOR_FORMAT_SHIFT) | ||
1425 | /* New style CUR*CNTR flags */ | ||
1426 | #define CURSOR_MODE 0x27 | ||
1413 | #define CURSOR_MODE_DISABLE 0x00 | 1427 | #define CURSOR_MODE_DISABLE 0x00 |
1414 | #define CURSOR_MODE_64_32B_AX 0x07 | 1428 | #define CURSOR_MODE_64_32B_AX 0x07 |
1415 | #define CURSOR_MODE_64_ARGB_AX ((1 << 5) | CURSOR_MODE_64_32B_AX) | 1429 | #define CURSOR_MODE_64_ARGB_AX ((1 << 5) | CURSOR_MODE_64_32B_AX) |
1430 | #define MCURSOR_PIPE_SELECT (1 << 28) | ||
1431 | #define MCURSOR_PIPE_A 0x00 | ||
1432 | #define MCURSOR_PIPE_B (1 << 28) | ||
1416 | #define MCURSOR_GAMMA_ENABLE (1 << 26) | 1433 | #define MCURSOR_GAMMA_ENABLE (1 << 26) |
1417 | #define CURABASE 0x70084 | 1434 | #define CURABASE 0x70084 |
1418 | #define CURAPOS 0x70088 | 1435 | #define CURAPOS 0x70088 |
@@ -1420,6 +1437,7 @@ | |||
1420 | #define CURSOR_POS_SIGN 0x8000 | 1437 | #define CURSOR_POS_SIGN 0x8000 |
1421 | #define CURSOR_X_SHIFT 0 | 1438 | #define CURSOR_X_SHIFT 0 |
1422 | #define CURSOR_Y_SHIFT 16 | 1439 | #define CURSOR_Y_SHIFT 16 |
1440 | #define CURSIZE 0x700a0 | ||
1423 | #define CURBCNTR 0x700c0 | 1441 | #define CURBCNTR 0x700c0 |
1424 | #define CURBBASE 0x700c4 | 1442 | #define CURBBASE 0x700c4 |
1425 | #define CURBPOS 0x700c8 | 1443 | #define CURBPOS 0x700c8 |
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c index fc28e2bbd542..9d78cff33b24 100644 --- a/drivers/gpu/drm/i915/intel_bios.c +++ b/drivers/gpu/drm/i915/intel_bios.c | |||
@@ -57,9 +57,43 @@ find_section(struct bdb_header *bdb, int section_id) | |||
57 | return NULL; | 57 | return NULL; |
58 | } | 58 | } |
59 | 59 | ||
60 | /* Try to find panel data */ | ||
61 | static void | 60 | static void |
62 | parse_panel_data(struct drm_i915_private *dev_priv, struct bdb_header *bdb) | 61 | fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode, |
62 | struct lvds_dvo_timing *dvo_timing) | ||
63 | { | ||
64 | panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) | | ||
65 | dvo_timing->hactive_lo; | ||
66 | panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay + | ||
67 | ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo); | ||
68 | panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start + | ||
69 | dvo_timing->hsync_pulse_width; | ||
70 | panel_fixed_mode->htotal = panel_fixed_mode->hdisplay + | ||
71 | ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo); | ||
72 | |||
73 | panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) | | ||
74 | dvo_timing->vactive_lo; | ||
75 | panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay + | ||
76 | dvo_timing->vsync_off; | ||
77 | panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start + | ||
78 | dvo_timing->vsync_pulse_width; | ||
79 | panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay + | ||
80 | ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo); | ||
81 | panel_fixed_mode->clock = dvo_timing->clock * 10; | ||
82 | panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED; | ||
83 | |||
84 | /* Some VBTs have bogus h/vtotal values */ | ||
85 | if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal) | ||
86 | panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1; | ||
87 | if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal) | ||
88 | panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1; | ||
89 | |||
90 | drm_mode_set_name(panel_fixed_mode); | ||
91 | } | ||
92 | |||
93 | /* Try to find integrated panel data */ | ||
94 | static void | ||
95 | parse_lfp_panel_data(struct drm_i915_private *dev_priv, | ||
96 | struct bdb_header *bdb) | ||
63 | { | 97 | { |
64 | struct bdb_lvds_options *lvds_options; | 98 | struct bdb_lvds_options *lvds_options; |
65 | struct bdb_lvds_lfp_data *lvds_lfp_data; | 99 | struct bdb_lvds_lfp_data *lvds_lfp_data; |
@@ -91,38 +125,45 @@ parse_panel_data(struct drm_i915_private *dev_priv, struct bdb_header *bdb) | |||
91 | panel_fixed_mode = drm_calloc(1, sizeof(*panel_fixed_mode), | 125 | panel_fixed_mode = drm_calloc(1, sizeof(*panel_fixed_mode), |
92 | DRM_MEM_DRIVER); | 126 | DRM_MEM_DRIVER); |
93 | 127 | ||
94 | panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) | | 128 | fill_detail_timing_data(panel_fixed_mode, dvo_timing); |
95 | dvo_timing->hactive_lo; | ||
96 | panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay + | ||
97 | ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo); | ||
98 | panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start + | ||
99 | dvo_timing->hsync_pulse_width; | ||
100 | panel_fixed_mode->htotal = panel_fixed_mode->hdisplay + | ||
101 | ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo); | ||
102 | 129 | ||
103 | panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) | | 130 | dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode; |
104 | dvo_timing->vactive_lo; | ||
105 | panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay + | ||
106 | dvo_timing->vsync_off; | ||
107 | panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start + | ||
108 | dvo_timing->vsync_pulse_width; | ||
109 | panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay + | ||
110 | ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo); | ||
111 | panel_fixed_mode->clock = dvo_timing->clock * 10; | ||
112 | panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED; | ||
113 | 131 | ||
114 | /* Some VBTs have bogus h/vtotal values */ | 132 | DRM_DEBUG("Found panel mode in BIOS VBT tables:\n"); |
115 | if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal) | 133 | drm_mode_debug_printmodeline(panel_fixed_mode); |
116 | panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1; | ||
117 | if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal) | ||
118 | panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1; | ||
119 | 134 | ||
120 | drm_mode_set_name(panel_fixed_mode); | 135 | return; |
136 | } | ||
137 | |||
138 | /* Try to find sdvo panel data */ | ||
139 | static void | ||
140 | parse_sdvo_panel_data(struct drm_i915_private *dev_priv, | ||
141 | struct bdb_header *bdb) | ||
142 | { | ||
143 | struct bdb_sdvo_lvds_options *sdvo_lvds_options; | ||
144 | struct lvds_dvo_timing *dvo_timing; | ||
145 | struct drm_display_mode *panel_fixed_mode; | ||
121 | 146 | ||
122 | dev_priv->vbt_mode = panel_fixed_mode; | 147 | dev_priv->sdvo_lvds_vbt_mode = NULL; |
123 | 148 | ||
124 | DRM_DEBUG("Found panel mode in BIOS VBT tables:\n"); | 149 | sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS); |
125 | drm_mode_debug_printmodeline(panel_fixed_mode); | 150 | if (!sdvo_lvds_options) |
151 | return; | ||
152 | |||
153 | dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS); | ||
154 | if (!dvo_timing) | ||
155 | return; | ||
156 | |||
157 | panel_fixed_mode = drm_calloc(1, sizeof(*panel_fixed_mode), | ||
158 | DRM_MEM_DRIVER); | ||
159 | |||
160 | if (!panel_fixed_mode) | ||
161 | return; | ||
162 | |||
163 | fill_detail_timing_data(panel_fixed_mode, | ||
164 | dvo_timing + sdvo_lvds_options->panel_type); | ||
165 | |||
166 | dev_priv->sdvo_lvds_vbt_mode = panel_fixed_mode; | ||
126 | 167 | ||
127 | return; | 168 | return; |
128 | } | 169 | } |
@@ -199,7 +240,8 @@ intel_init_bios(struct drm_device *dev) | |||
199 | 240 | ||
200 | /* Grab useful general definitions */ | 241 | /* Grab useful general definitions */ |
201 | parse_general_features(dev_priv, bdb); | 242 | parse_general_features(dev_priv, bdb); |
202 | parse_panel_data(dev_priv, bdb); | 243 | parse_lfp_panel_data(dev_priv, bdb); |
244 | parse_sdvo_panel_data(dev_priv, bdb); | ||
203 | 245 | ||
204 | pci_unmap_rom(pdev, bios); | 246 | pci_unmap_rom(pdev, bios); |
205 | 247 | ||
diff --git a/drivers/gpu/drm/i915/intel_bios.h b/drivers/gpu/drm/i915/intel_bios.h index de621aad85b5..8ca2cde15804 100644 --- a/drivers/gpu/drm/i915/intel_bios.h +++ b/drivers/gpu/drm/i915/intel_bios.h | |||
@@ -279,6 +279,23 @@ struct vch_bdb_22 { | |||
279 | struct vch_panel_data panels[16]; | 279 | struct vch_panel_data panels[16]; |
280 | } __attribute__((packed)); | 280 | } __attribute__((packed)); |
281 | 281 | ||
282 | struct bdb_sdvo_lvds_options { | ||
283 | u8 panel_backlight; | ||
284 | u8 h40_set_panel_type; | ||
285 | u8 panel_type; | ||
286 | u8 ssc_clk_freq; | ||
287 | u16 als_low_trip; | ||
288 | u16 als_high_trip; | ||
289 | u8 sclalarcoeff_tab_row_num; | ||
290 | u8 sclalarcoeff_tab_row_size; | ||
291 | u8 coefficient[8]; | ||
292 | u8 panel_misc_bits_1; | ||
293 | u8 panel_misc_bits_2; | ||
294 | u8 panel_misc_bits_3; | ||
295 | u8 panel_misc_bits_4; | ||
296 | } __attribute__((packed)); | ||
297 | |||
298 | |||
282 | bool intel_init_bios(struct drm_device *dev); | 299 | bool intel_init_bios(struct drm_device *dev); |
283 | 300 | ||
284 | /* | 301 | /* |
diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c index 19148c3df637..79acc4f4c1f8 100644 --- a/drivers/gpu/drm/i915/intel_crt.c +++ b/drivers/gpu/drm/i915/intel_crt.c | |||
@@ -198,9 +198,142 @@ static bool intel_crt_detect_ddc(struct drm_connector *connector) | |||
198 | return intel_ddc_probe(intel_output); | 198 | return intel_ddc_probe(intel_output); |
199 | } | 199 | } |
200 | 200 | ||
201 | static enum drm_connector_status | ||
202 | intel_crt_load_detect(struct drm_crtc *crtc, struct intel_output *intel_output) | ||
203 | { | ||
204 | struct drm_encoder *encoder = &intel_output->enc; | ||
205 | struct drm_device *dev = encoder->dev; | ||
206 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
207 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | ||
208 | uint32_t pipe = intel_crtc->pipe; | ||
209 | uint32_t save_bclrpat; | ||
210 | uint32_t save_vtotal; | ||
211 | uint32_t vtotal, vactive; | ||
212 | uint32_t vsample; | ||
213 | uint32_t vblank, vblank_start, vblank_end; | ||
214 | uint32_t dsl; | ||
215 | uint32_t bclrpat_reg; | ||
216 | uint32_t vtotal_reg; | ||
217 | uint32_t vblank_reg; | ||
218 | uint32_t vsync_reg; | ||
219 | uint32_t pipeconf_reg; | ||
220 | uint32_t pipe_dsl_reg; | ||
221 | uint8_t st00; | ||
222 | enum drm_connector_status status; | ||
223 | |||
224 | if (pipe == 0) { | ||
225 | bclrpat_reg = BCLRPAT_A; | ||
226 | vtotal_reg = VTOTAL_A; | ||
227 | vblank_reg = VBLANK_A; | ||
228 | vsync_reg = VSYNC_A; | ||
229 | pipeconf_reg = PIPEACONF; | ||
230 | pipe_dsl_reg = PIPEADSL; | ||
231 | } else { | ||
232 | bclrpat_reg = BCLRPAT_B; | ||
233 | vtotal_reg = VTOTAL_B; | ||
234 | vblank_reg = VBLANK_B; | ||
235 | vsync_reg = VSYNC_B; | ||
236 | pipeconf_reg = PIPEBCONF; | ||
237 | pipe_dsl_reg = PIPEBDSL; | ||
238 | } | ||
239 | |||
240 | save_bclrpat = I915_READ(bclrpat_reg); | ||
241 | save_vtotal = I915_READ(vtotal_reg); | ||
242 | vblank = I915_READ(vblank_reg); | ||
243 | |||
244 | vtotal = ((save_vtotal >> 16) & 0xfff) + 1; | ||
245 | vactive = (save_vtotal & 0x7ff) + 1; | ||
246 | |||
247 | vblank_start = (vblank & 0xfff) + 1; | ||
248 | vblank_end = ((vblank >> 16) & 0xfff) + 1; | ||
249 | |||
250 | /* Set the border color to purple. */ | ||
251 | I915_WRITE(bclrpat_reg, 0x500050); | ||
252 | |||
253 | if (IS_I9XX(dev)) { | ||
254 | uint32_t pipeconf = I915_READ(pipeconf_reg); | ||
255 | I915_WRITE(pipeconf_reg, pipeconf | PIPECONF_FORCE_BORDER); | ||
256 | /* Wait for next Vblank to substitue | ||
257 | * border color for Color info */ | ||
258 | intel_wait_for_vblank(dev); | ||
259 | st00 = I915_READ8(VGA_MSR_WRITE); | ||
260 | status = ((st00 & (1 << 4)) != 0) ? | ||
261 | connector_status_connected : | ||
262 | connector_status_disconnected; | ||
263 | |||
264 | I915_WRITE(pipeconf_reg, pipeconf); | ||
265 | } else { | ||
266 | bool restore_vblank = false; | ||
267 | int count, detect; | ||
268 | |||
269 | /* | ||
270 | * If there isn't any border, add some. | ||
271 | * Yes, this will flicker | ||
272 | */ | ||
273 | if (vblank_start <= vactive && vblank_end >= vtotal) { | ||
274 | uint32_t vsync = I915_READ(vsync_reg); | ||
275 | uint32_t vsync_start = (vsync & 0xffff) + 1; | ||
276 | |||
277 | vblank_start = vsync_start; | ||
278 | I915_WRITE(vblank_reg, | ||
279 | (vblank_start - 1) | | ||
280 | ((vblank_end - 1) << 16)); | ||
281 | restore_vblank = true; | ||
282 | } | ||
283 | /* sample in the vertical border, selecting the larger one */ | ||
284 | if (vblank_start - vactive >= vtotal - vblank_end) | ||
285 | vsample = (vblank_start + vactive) >> 1; | ||
286 | else | ||
287 | vsample = (vtotal + vblank_end) >> 1; | ||
288 | |||
289 | /* | ||
290 | * Wait for the border to be displayed | ||
291 | */ | ||
292 | while (I915_READ(pipe_dsl_reg) >= vactive) | ||
293 | ; | ||
294 | while ((dsl = I915_READ(pipe_dsl_reg)) <= vsample) | ||
295 | ; | ||
296 | /* | ||
297 | * Watch ST00 for an entire scanline | ||
298 | */ | ||
299 | detect = 0; | ||
300 | count = 0; | ||
301 | do { | ||
302 | count++; | ||
303 | /* Read the ST00 VGA status register */ | ||
304 | st00 = I915_READ8(VGA_MSR_WRITE); | ||
305 | if (st00 & (1 << 4)) | ||
306 | detect++; | ||
307 | } while ((I915_READ(pipe_dsl_reg) == dsl)); | ||
308 | |||
309 | /* restore vblank if necessary */ | ||
310 | if (restore_vblank) | ||
311 | I915_WRITE(vblank_reg, vblank); | ||
312 | /* | ||
313 | * If more than 3/4 of the scanline detected a monitor, | ||
314 | * then it is assumed to be present. This works even on i830, | ||
315 | * where there isn't any way to force the border color across | ||
316 | * the screen | ||
317 | */ | ||
318 | status = detect * 4 > count * 3 ? | ||
319 | connector_status_connected : | ||
320 | connector_status_disconnected; | ||
321 | } | ||
322 | |||
323 | /* Restore previous settings */ | ||
324 | I915_WRITE(bclrpat_reg, save_bclrpat); | ||
325 | |||
326 | return status; | ||
327 | } | ||
328 | |||
201 | static enum drm_connector_status intel_crt_detect(struct drm_connector *connector) | 329 | static enum drm_connector_status intel_crt_detect(struct drm_connector *connector) |
202 | { | 330 | { |
203 | struct drm_device *dev = connector->dev; | 331 | struct drm_device *dev = connector->dev; |
332 | struct intel_output *intel_output = to_intel_output(connector); | ||
333 | struct drm_encoder *encoder = &intel_output->enc; | ||
334 | struct drm_crtc *crtc; | ||
335 | int dpms_mode; | ||
336 | enum drm_connector_status status; | ||
204 | 337 | ||
205 | if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev)) { | 338 | if (IS_I9XX(dev) && !IS_I915G(dev) && !IS_I915GM(dev)) { |
206 | if (intel_crt_detect_hotplug(connector)) | 339 | if (intel_crt_detect_hotplug(connector)) |
@@ -212,8 +345,20 @@ static enum drm_connector_status intel_crt_detect(struct drm_connector *connecto | |||
212 | if (intel_crt_detect_ddc(connector)) | 345 | if (intel_crt_detect_ddc(connector)) |
213 | return connector_status_connected; | 346 | return connector_status_connected; |
214 | 347 | ||
215 | /* TODO use load detect */ | 348 | /* for pre-945g platforms use load detect */ |
216 | return connector_status_unknown; | 349 | if (encoder->crtc && encoder->crtc->enabled) { |
350 | status = intel_crt_load_detect(encoder->crtc, intel_output); | ||
351 | } else { | ||
352 | crtc = intel_get_load_detect_pipe(intel_output, | ||
353 | NULL, &dpms_mode); | ||
354 | if (crtc) { | ||
355 | status = intel_crt_load_detect(crtc, intel_output); | ||
356 | intel_release_load_detect_pipe(intel_output, dpms_mode); | ||
357 | } else | ||
358 | status = connector_status_unknown; | ||
359 | } | ||
360 | |||
361 | return status; | ||
217 | } | 362 | } |
218 | 363 | ||
219 | static void intel_crt_destroy(struct drm_connector *connector) | 364 | static void intel_crt_destroy(struct drm_connector *connector) |
@@ -236,11 +381,6 @@ static int intel_crt_set_property(struct drm_connector *connector, | |||
236 | struct drm_property *property, | 381 | struct drm_property *property, |
237 | uint64_t value) | 382 | uint64_t value) |
238 | { | 383 | { |
239 | struct drm_device *dev = connector->dev; | ||
240 | |||
241 | if (property == dev->mode_config.dpms_property && connector->encoder) | ||
242 | intel_crt_dpms(connector->encoder, (uint32_t)(value & 0xf)); | ||
243 | |||
244 | return 0; | 384 | return 0; |
245 | } | 385 | } |
246 | 386 | ||
@@ -257,6 +397,7 @@ static const struct drm_encoder_helper_funcs intel_crt_helper_funcs = { | |||
257 | }; | 397 | }; |
258 | 398 | ||
259 | static const struct drm_connector_funcs intel_crt_connector_funcs = { | 399 | static const struct drm_connector_funcs intel_crt_connector_funcs = { |
400 | .dpms = drm_helper_connector_dpms, | ||
260 | .detect = intel_crt_detect, | 401 | .detect = intel_crt_detect, |
261 | .fill_modes = drm_helper_probe_single_connector_modes, | 402 | .fill_modes = drm_helper_probe_single_connector_modes, |
262 | .destroy = intel_crt_destroy, | 403 | .destroy = intel_crt_destroy, |
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 3387cf32f385..c9d6f10ba92e 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c | |||
@@ -1357,7 +1357,7 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc, | |||
1357 | int pipe = intel_crtc->pipe; | 1357 | int pipe = intel_crtc->pipe; |
1358 | uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR; | 1358 | uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR; |
1359 | uint32_t base = (pipe == 0) ? CURABASE : CURBBASE; | 1359 | uint32_t base = (pipe == 0) ? CURABASE : CURBBASE; |
1360 | uint32_t temp; | 1360 | uint32_t temp = I915_READ(control); |
1361 | size_t addr; | 1361 | size_t addr; |
1362 | int ret; | 1362 | int ret; |
1363 | 1363 | ||
@@ -1366,7 +1366,12 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc, | |||
1366 | /* if we want to turn off the cursor ignore width and height */ | 1366 | /* if we want to turn off the cursor ignore width and height */ |
1367 | if (!handle) { | 1367 | if (!handle) { |
1368 | DRM_DEBUG("cursor off\n"); | 1368 | DRM_DEBUG("cursor off\n"); |
1369 | temp = CURSOR_MODE_DISABLE; | 1369 | if (IS_MOBILE(dev) || IS_I9XX(dev)) { |
1370 | temp &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE); | ||
1371 | temp |= CURSOR_MODE_DISABLE; | ||
1372 | } else { | ||
1373 | temp &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE); | ||
1374 | } | ||
1370 | addr = 0; | 1375 | addr = 0; |
1371 | bo = NULL; | 1376 | bo = NULL; |
1372 | mutex_lock(&dev->struct_mutex); | 1377 | mutex_lock(&dev->struct_mutex); |
@@ -1409,10 +1414,19 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc, | |||
1409 | addr = obj_priv->phys_obj->handle->busaddr; | 1414 | addr = obj_priv->phys_obj->handle->busaddr; |
1410 | } | 1415 | } |
1411 | 1416 | ||
1412 | temp = 0; | 1417 | if (!IS_I9XX(dev)) |
1413 | /* set the pipe for the cursor */ | 1418 | I915_WRITE(CURSIZE, (height << 12) | width); |
1414 | temp |= (pipe << 28); | 1419 | |
1415 | temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE; | 1420 | /* Hooray for CUR*CNTR differences */ |
1421 | if (IS_MOBILE(dev) || IS_I9XX(dev)) { | ||
1422 | temp &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT); | ||
1423 | temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE; | ||
1424 | temp |= (pipe << 28); /* Connect to correct pipe */ | ||
1425 | } else { | ||
1426 | temp &= ~(CURSOR_FORMAT_MASK); | ||
1427 | temp |= CURSOR_ENABLE; | ||
1428 | temp |= CURSOR_FORMAT_ARGB | CURSOR_GAMMA_ENABLE; | ||
1429 | } | ||
1416 | 1430 | ||
1417 | finish: | 1431 | finish: |
1418 | I915_WRITE(control, temp); | 1432 | I915_WRITE(control, temp); |
diff --git a/drivers/gpu/drm/i915/intel_dvo.c b/drivers/gpu/drm/i915/intel_dvo.c index 8b8d6e65cd3f..1ee3007d6ec0 100644 --- a/drivers/gpu/drm/i915/intel_dvo.c +++ b/drivers/gpu/drm/i915/intel_dvo.c | |||
@@ -316,6 +316,7 @@ static const struct drm_encoder_helper_funcs intel_dvo_helper_funcs = { | |||
316 | }; | 316 | }; |
317 | 317 | ||
318 | static const struct drm_connector_funcs intel_dvo_connector_funcs = { | 318 | static const struct drm_connector_funcs intel_dvo_connector_funcs = { |
319 | .dpms = drm_helper_connector_dpms, | ||
319 | .save = intel_dvo_save, | 320 | .save = intel_dvo_save, |
320 | .restore = intel_dvo_restore, | 321 | .restore = intel_dvo_restore, |
321 | .detect = intel_dvo_detect, | 322 | .detect = intel_dvo_detect, |
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c index d0983bb93a18..7d6bdd705326 100644 --- a/drivers/gpu/drm/i915/intel_hdmi.c +++ b/drivers/gpu/drm/i915/intel_hdmi.c | |||
@@ -219,6 +219,7 @@ static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = { | |||
219 | }; | 219 | }; |
220 | 220 | ||
221 | static const struct drm_connector_funcs intel_hdmi_connector_funcs = { | 221 | static const struct drm_connector_funcs intel_hdmi_connector_funcs = { |
222 | .dpms = drm_helper_connector_dpms, | ||
222 | .save = intel_hdmi_save, | 223 | .save = intel_hdmi_save, |
223 | .restore = intel_hdmi_restore, | 224 | .restore = intel_hdmi_restore, |
224 | .detect = intel_hdmi_detect, | 225 | .detect = intel_hdmi_detect, |
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c index 439a86514993..53cccfa58b95 100644 --- a/drivers/gpu/drm/i915/intel_lvds.c +++ b/drivers/gpu/drm/i915/intel_lvds.c | |||
@@ -343,11 +343,6 @@ static int intel_lvds_set_property(struct drm_connector *connector, | |||
343 | struct drm_property *property, | 343 | struct drm_property *property, |
344 | uint64_t value) | 344 | uint64_t value) |
345 | { | 345 | { |
346 | struct drm_device *dev = connector->dev; | ||
347 | |||
348 | if (property == dev->mode_config.dpms_property && connector->encoder) | ||
349 | intel_lvds_dpms(connector->encoder, (uint32_t)(value & 0xf)); | ||
350 | |||
351 | return 0; | 346 | return 0; |
352 | } | 347 | } |
353 | 348 | ||
@@ -366,6 +361,7 @@ static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs | |||
366 | }; | 361 | }; |
367 | 362 | ||
368 | static const struct drm_connector_funcs intel_lvds_connector_funcs = { | 363 | static const struct drm_connector_funcs intel_lvds_connector_funcs = { |
364 | .dpms = drm_helper_connector_dpms, | ||
369 | .save = intel_lvds_save, | 365 | .save = intel_lvds_save, |
370 | .restore = intel_lvds_restore, | 366 | .restore = intel_lvds_restore, |
371 | .detect = intel_lvds_detect, | 367 | .detect = intel_lvds_detect, |
@@ -391,7 +387,7 @@ static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id) | |||
391 | } | 387 | } |
392 | 388 | ||
393 | /* These systems claim to have LVDS, but really don't */ | 389 | /* These systems claim to have LVDS, but really don't */ |
394 | static const struct dmi_system_id __initdata intel_no_lvds[] = { | 390 | static const struct dmi_system_id intel_no_lvds[] = { |
395 | { | 391 | { |
396 | .callback = intel_no_lvds_dmi_callback, | 392 | .callback = intel_no_lvds_dmi_callback, |
397 | .ident = "Apple Mac Mini (Core series)", | 393 | .ident = "Apple Mac Mini (Core series)", |
@@ -511,10 +507,10 @@ void intel_lvds_init(struct drm_device *dev) | |||
511 | } | 507 | } |
512 | 508 | ||
513 | /* Failed to get EDID, what about VBT? */ | 509 | /* Failed to get EDID, what about VBT? */ |
514 | if (dev_priv->vbt_mode) { | 510 | if (dev_priv->lfp_lvds_vbt_mode) { |
515 | mutex_lock(&dev->mode_config.mutex); | 511 | mutex_lock(&dev->mode_config.mutex); |
516 | dev_priv->panel_fixed_mode = | 512 | dev_priv->panel_fixed_mode = |
517 | drm_mode_duplicate(dev, dev_priv->vbt_mode); | 513 | drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode); |
518 | mutex_unlock(&dev->mode_config.mutex); | 514 | mutex_unlock(&dev->mode_config.mutex); |
519 | if (dev_priv->panel_fixed_mode) { | 515 | if (dev_priv->panel_fixed_mode) { |
520 | dev_priv->panel_fixed_mode->type |= | 516 | dev_priv->panel_fixed_mode->type |= |
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c index 9913651c1e17..3093b4d4a4dd 100644 --- a/drivers/gpu/drm/i915/intel_sdvo.c +++ b/drivers/gpu/drm/i915/intel_sdvo.c | |||
@@ -69,6 +69,10 @@ struct intel_sdvo_priv { | |||
69 | * This is set if we treat the device as HDMI, instead of DVI. | 69 | * This is set if we treat the device as HDMI, instead of DVI. |
70 | */ | 70 | */ |
71 | bool is_hdmi; | 71 | bool is_hdmi; |
72 | /** | ||
73 | * This is set if we detect output of sdvo device as LVDS. | ||
74 | */ | ||
75 | bool is_lvds; | ||
72 | 76 | ||
73 | /** | 77 | /** |
74 | * Returned SDTV resolutions allowed for the current format, if the | 78 | * Returned SDTV resolutions allowed for the current format, if the |
@@ -1398,10 +1402,8 @@ static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connect | |||
1398 | static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) | 1402 | static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) |
1399 | { | 1403 | { |
1400 | struct intel_output *intel_output = to_intel_output(connector); | 1404 | struct intel_output *intel_output = to_intel_output(connector); |
1401 | struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; | ||
1402 | 1405 | ||
1403 | /* set the bus switch and get the modes */ | 1406 | /* set the bus switch and get the modes */ |
1404 | intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus); | ||
1405 | intel_ddc_get_modes(intel_output); | 1407 | intel_ddc_get_modes(intel_output); |
1406 | 1408 | ||
1407 | #if 0 | 1409 | #if 0 |
@@ -1543,6 +1545,37 @@ static void intel_sdvo_get_tv_modes(struct drm_connector *connector) | |||
1543 | } | 1545 | } |
1544 | } | 1546 | } |
1545 | 1547 | ||
1548 | static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) | ||
1549 | { | ||
1550 | struct intel_output *intel_output = to_intel_output(connector); | ||
1551 | struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; | ||
1552 | struct drm_i915_private *dev_priv = connector->dev->dev_private; | ||
1553 | |||
1554 | /* | ||
1555 | * Attempt to get the mode list from DDC. | ||
1556 | * Assume that the preferred modes are | ||
1557 | * arranged in priority order. | ||
1558 | */ | ||
1559 | /* set the bus switch and get the modes */ | ||
1560 | intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus); | ||
1561 | intel_ddc_get_modes(intel_output); | ||
1562 | if (list_empty(&connector->probed_modes) == false) | ||
1563 | return; | ||
1564 | |||
1565 | /* Fetch modes from VBT */ | ||
1566 | if (dev_priv->sdvo_lvds_vbt_mode != NULL) { | ||
1567 | struct drm_display_mode *newmode; | ||
1568 | newmode = drm_mode_duplicate(connector->dev, | ||
1569 | dev_priv->sdvo_lvds_vbt_mode); | ||
1570 | if (newmode != NULL) { | ||
1571 | /* Guarantee the mode is preferred */ | ||
1572 | newmode->type = (DRM_MODE_TYPE_PREFERRED | | ||
1573 | DRM_MODE_TYPE_DRIVER); | ||
1574 | drm_mode_probed_add(connector, newmode); | ||
1575 | } | ||
1576 | } | ||
1577 | } | ||
1578 | |||
1546 | static int intel_sdvo_get_modes(struct drm_connector *connector) | 1579 | static int intel_sdvo_get_modes(struct drm_connector *connector) |
1547 | { | 1580 | { |
1548 | struct intel_output *output = to_intel_output(connector); | 1581 | struct intel_output *output = to_intel_output(connector); |
@@ -1550,6 +1583,8 @@ static int intel_sdvo_get_modes(struct drm_connector *connector) | |||
1550 | 1583 | ||
1551 | if (sdvo_priv->is_tv) | 1584 | if (sdvo_priv->is_tv) |
1552 | intel_sdvo_get_tv_modes(connector); | 1585 | intel_sdvo_get_tv_modes(connector); |
1586 | else if (sdvo_priv->is_lvds == true) | ||
1587 | intel_sdvo_get_lvds_modes(connector); | ||
1553 | else | 1588 | else |
1554 | intel_sdvo_get_ddc_modes(connector); | 1589 | intel_sdvo_get_ddc_modes(connector); |
1555 | 1590 | ||
@@ -1564,6 +1599,9 @@ static void intel_sdvo_destroy(struct drm_connector *connector) | |||
1564 | 1599 | ||
1565 | if (intel_output->i2c_bus) | 1600 | if (intel_output->i2c_bus) |
1566 | intel_i2c_destroy(intel_output->i2c_bus); | 1601 | intel_i2c_destroy(intel_output->i2c_bus); |
1602 | if (intel_output->ddc_bus) | ||
1603 | intel_i2c_destroy(intel_output->ddc_bus); | ||
1604 | |||
1567 | drm_sysfs_connector_remove(connector); | 1605 | drm_sysfs_connector_remove(connector); |
1568 | drm_connector_cleanup(connector); | 1606 | drm_connector_cleanup(connector); |
1569 | kfree(intel_output); | 1607 | kfree(intel_output); |
@@ -1578,6 +1616,7 @@ static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = { | |||
1578 | }; | 1616 | }; |
1579 | 1617 | ||
1580 | static const struct drm_connector_funcs intel_sdvo_connector_funcs = { | 1618 | static const struct drm_connector_funcs intel_sdvo_connector_funcs = { |
1619 | .dpms = drm_helper_connector_dpms, | ||
1581 | .save = intel_sdvo_save, | 1620 | .save = intel_sdvo_save, |
1582 | .restore = intel_sdvo_restore, | 1621 | .restore = intel_sdvo_restore, |
1583 | .detect = intel_sdvo_detect, | 1622 | .detect = intel_sdvo_detect, |
@@ -1660,12 +1699,56 @@ intel_sdvo_get_digital_encoding_mode(struct intel_output *output) | |||
1660 | return true; | 1699 | return true; |
1661 | } | 1700 | } |
1662 | 1701 | ||
1702 | static struct intel_output * | ||
1703 | intel_sdvo_chan_to_intel_output(struct intel_i2c_chan *chan) | ||
1704 | { | ||
1705 | struct drm_device *dev = chan->drm_dev; | ||
1706 | struct drm_connector *connector; | ||
1707 | struct intel_output *intel_output = NULL; | ||
1708 | |||
1709 | list_for_each_entry(connector, | ||
1710 | &dev->mode_config.connector_list, head) { | ||
1711 | if (to_intel_output(connector)->ddc_bus == chan) { | ||
1712 | intel_output = to_intel_output(connector); | ||
1713 | break; | ||
1714 | } | ||
1715 | } | ||
1716 | return intel_output; | ||
1717 | } | ||
1718 | |||
1719 | static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap, | ||
1720 | struct i2c_msg msgs[], int num) | ||
1721 | { | ||
1722 | struct intel_output *intel_output; | ||
1723 | struct intel_sdvo_priv *sdvo_priv; | ||
1724 | struct i2c_algo_bit_data *algo_data; | ||
1725 | struct i2c_algorithm *algo; | ||
1726 | |||
1727 | algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data; | ||
1728 | intel_output = | ||
1729 | intel_sdvo_chan_to_intel_output( | ||
1730 | (struct intel_i2c_chan *)(algo_data->data)); | ||
1731 | if (intel_output == NULL) | ||
1732 | return -EINVAL; | ||
1733 | |||
1734 | sdvo_priv = intel_output->dev_priv; | ||
1735 | algo = (struct i2c_algorithm *)intel_output->i2c_bus->adapter.algo; | ||
1736 | |||
1737 | intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus); | ||
1738 | return algo->master_xfer(i2c_adap, msgs, num); | ||
1739 | } | ||
1740 | |||
1741 | static struct i2c_algorithm intel_sdvo_i2c_bit_algo = { | ||
1742 | .master_xfer = intel_sdvo_master_xfer, | ||
1743 | }; | ||
1744 | |||
1663 | bool intel_sdvo_init(struct drm_device *dev, int output_device) | 1745 | bool intel_sdvo_init(struct drm_device *dev, int output_device) |
1664 | { | 1746 | { |
1665 | struct drm_connector *connector; | 1747 | struct drm_connector *connector; |
1666 | struct intel_output *intel_output; | 1748 | struct intel_output *intel_output; |
1667 | struct intel_sdvo_priv *sdvo_priv; | 1749 | struct intel_sdvo_priv *sdvo_priv; |
1668 | struct intel_i2c_chan *i2cbus = NULL; | 1750 | struct intel_i2c_chan *i2cbus = NULL; |
1751 | struct intel_i2c_chan *ddcbus = NULL; | ||
1669 | int connector_type; | 1752 | int connector_type; |
1670 | u8 ch[0x40]; | 1753 | u8 ch[0x40]; |
1671 | int i; | 1754 | int i; |
@@ -1676,17 +1759,9 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device) | |||
1676 | return false; | 1759 | return false; |
1677 | } | 1760 | } |
1678 | 1761 | ||
1679 | connector = &intel_output->base; | ||
1680 | |||
1681 | drm_connector_init(dev, connector, &intel_sdvo_connector_funcs, | ||
1682 | DRM_MODE_CONNECTOR_Unknown); | ||
1683 | drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs); | ||
1684 | sdvo_priv = (struct intel_sdvo_priv *)(intel_output + 1); | 1762 | sdvo_priv = (struct intel_sdvo_priv *)(intel_output + 1); |
1685 | intel_output->type = INTEL_OUTPUT_SDVO; | 1763 | intel_output->type = INTEL_OUTPUT_SDVO; |
1686 | 1764 | ||
1687 | connector->interlace_allowed = 0; | ||
1688 | connector->doublescan_allowed = 0; | ||
1689 | |||
1690 | /* setup the DDC bus. */ | 1765 | /* setup the DDC bus. */ |
1691 | if (output_device == SDVOB) | 1766 | if (output_device == SDVOB) |
1692 | i2cbus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB"); | 1767 | i2cbus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB"); |
@@ -1694,7 +1769,7 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device) | |||
1694 | i2cbus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC"); | 1769 | i2cbus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC"); |
1695 | 1770 | ||
1696 | if (!i2cbus) | 1771 | if (!i2cbus) |
1697 | goto err_connector; | 1772 | goto err_inteloutput; |
1698 | 1773 | ||
1699 | sdvo_priv->i2c_bus = i2cbus; | 1774 | sdvo_priv->i2c_bus = i2cbus; |
1700 | 1775 | ||
@@ -1710,7 +1785,6 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device) | |||
1710 | intel_output->i2c_bus = i2cbus; | 1785 | intel_output->i2c_bus = i2cbus; |
1711 | intel_output->dev_priv = sdvo_priv; | 1786 | intel_output->dev_priv = sdvo_priv; |
1712 | 1787 | ||
1713 | |||
1714 | /* Read the regs to test if we can talk to the device */ | 1788 | /* Read the regs to test if we can talk to the device */ |
1715 | for (i = 0; i < 0x40; i++) { | 1789 | for (i = 0; i < 0x40; i++) { |
1716 | if (!intel_sdvo_read_byte(intel_output, i, &ch[i])) { | 1790 | if (!intel_sdvo_read_byte(intel_output, i, &ch[i])) { |
@@ -1720,6 +1794,22 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device) | |||
1720 | } | 1794 | } |
1721 | } | 1795 | } |
1722 | 1796 | ||
1797 | /* setup the DDC bus. */ | ||
1798 | if (output_device == SDVOB) | ||
1799 | ddcbus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS"); | ||
1800 | else | ||
1801 | ddcbus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS"); | ||
1802 | |||
1803 | if (ddcbus == NULL) | ||
1804 | goto err_i2c; | ||
1805 | |||
1806 | intel_sdvo_i2c_bit_algo.functionality = | ||
1807 | intel_output->i2c_bus->adapter.algo->functionality; | ||
1808 | ddcbus->adapter.algo = &intel_sdvo_i2c_bit_algo; | ||
1809 | intel_output->ddc_bus = ddcbus; | ||
1810 | |||
1811 | /* In defaut case sdvo lvds is false */ | ||
1812 | sdvo_priv->is_lvds = false; | ||
1723 | intel_sdvo_get_capabilities(intel_output, &sdvo_priv->caps); | 1813 | intel_sdvo_get_capabilities(intel_output, &sdvo_priv->caps); |
1724 | 1814 | ||
1725 | if (sdvo_priv->caps.output_flags & | 1815 | if (sdvo_priv->caps.output_flags & |
@@ -1729,7 +1819,6 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device) | |||
1729 | else | 1819 | else |
1730 | sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS1; | 1820 | sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS1; |
1731 | 1821 | ||
1732 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; | ||
1733 | encoder_type = DRM_MODE_ENCODER_TMDS; | 1822 | encoder_type = DRM_MODE_ENCODER_TMDS; |
1734 | connector_type = DRM_MODE_CONNECTOR_DVID; | 1823 | connector_type = DRM_MODE_CONNECTOR_DVID; |
1735 | 1824 | ||
@@ -1747,7 +1836,6 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device) | |||
1747 | else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_SVID0) | 1836 | else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_SVID0) |
1748 | { | 1837 | { |
1749 | sdvo_priv->controlled_output = SDVO_OUTPUT_SVID0; | 1838 | sdvo_priv->controlled_output = SDVO_OUTPUT_SVID0; |
1750 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; | ||
1751 | encoder_type = DRM_MODE_ENCODER_TVDAC; | 1839 | encoder_type = DRM_MODE_ENCODER_TVDAC; |
1752 | connector_type = DRM_MODE_CONNECTOR_SVIDEO; | 1840 | connector_type = DRM_MODE_CONNECTOR_SVIDEO; |
1753 | sdvo_priv->is_tv = true; | 1841 | sdvo_priv->is_tv = true; |
@@ -1756,30 +1844,28 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device) | |||
1756 | else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_RGB0) | 1844 | else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_RGB0) |
1757 | { | 1845 | { |
1758 | sdvo_priv->controlled_output = SDVO_OUTPUT_RGB0; | 1846 | sdvo_priv->controlled_output = SDVO_OUTPUT_RGB0; |
1759 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; | ||
1760 | encoder_type = DRM_MODE_ENCODER_DAC; | 1847 | encoder_type = DRM_MODE_ENCODER_DAC; |
1761 | connector_type = DRM_MODE_CONNECTOR_VGA; | 1848 | connector_type = DRM_MODE_CONNECTOR_VGA; |
1762 | } | 1849 | } |
1763 | else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_RGB1) | 1850 | else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_RGB1) |
1764 | { | 1851 | { |
1765 | sdvo_priv->controlled_output = SDVO_OUTPUT_RGB1; | 1852 | sdvo_priv->controlled_output = SDVO_OUTPUT_RGB1; |
1766 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; | ||
1767 | encoder_type = DRM_MODE_ENCODER_DAC; | 1853 | encoder_type = DRM_MODE_ENCODER_DAC; |
1768 | connector_type = DRM_MODE_CONNECTOR_VGA; | 1854 | connector_type = DRM_MODE_CONNECTOR_VGA; |
1769 | } | 1855 | } |
1770 | else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_LVDS0) | 1856 | else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_LVDS0) |
1771 | { | 1857 | { |
1772 | sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS0; | 1858 | sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS0; |
1773 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; | ||
1774 | encoder_type = DRM_MODE_ENCODER_LVDS; | 1859 | encoder_type = DRM_MODE_ENCODER_LVDS; |
1775 | connector_type = DRM_MODE_CONNECTOR_LVDS; | 1860 | connector_type = DRM_MODE_CONNECTOR_LVDS; |
1861 | sdvo_priv->is_lvds = true; | ||
1776 | } | 1862 | } |
1777 | else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_LVDS1) | 1863 | else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_LVDS1) |
1778 | { | 1864 | { |
1779 | sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS1; | 1865 | sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS1; |
1780 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; | ||
1781 | encoder_type = DRM_MODE_ENCODER_LVDS; | 1866 | encoder_type = DRM_MODE_ENCODER_LVDS; |
1782 | connector_type = DRM_MODE_CONNECTOR_LVDS; | 1867 | connector_type = DRM_MODE_CONNECTOR_LVDS; |
1868 | sdvo_priv->is_lvds = true; | ||
1783 | } | 1869 | } |
1784 | else | 1870 | else |
1785 | { | 1871 | { |
@@ -1795,9 +1881,16 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device) | |||
1795 | goto err_i2c; | 1881 | goto err_i2c; |
1796 | } | 1882 | } |
1797 | 1883 | ||
1884 | connector = &intel_output->base; | ||
1885 | drm_connector_init(dev, connector, &intel_sdvo_connector_funcs, | ||
1886 | connector_type); | ||
1887 | drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs); | ||
1888 | connector->interlace_allowed = 0; | ||
1889 | connector->doublescan_allowed = 0; | ||
1890 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; | ||
1891 | |||
1798 | drm_encoder_init(dev, &intel_output->enc, &intel_sdvo_enc_funcs, encoder_type); | 1892 | drm_encoder_init(dev, &intel_output->enc, &intel_sdvo_enc_funcs, encoder_type); |
1799 | drm_encoder_helper_add(&intel_output->enc, &intel_sdvo_helper_funcs); | 1893 | drm_encoder_helper_add(&intel_output->enc, &intel_sdvo_helper_funcs); |
1800 | connector->connector_type = connector_type; | ||
1801 | 1894 | ||
1802 | drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc); | 1895 | drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc); |
1803 | drm_sysfs_connector_add(connector); | 1896 | drm_sysfs_connector_add(connector); |
@@ -1829,14 +1922,13 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device) | |||
1829 | sdvo_priv->caps.output_flags & | 1922 | sdvo_priv->caps.output_flags & |
1830 | (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N'); | 1923 | (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N'); |
1831 | 1924 | ||
1832 | intel_output->ddc_bus = i2cbus; | ||
1833 | |||
1834 | return true; | 1925 | return true; |
1835 | 1926 | ||
1836 | err_i2c: | 1927 | err_i2c: |
1928 | if (ddcbus != NULL) | ||
1929 | intel_i2c_destroy(intel_output->ddc_bus); | ||
1837 | intel_i2c_destroy(intel_output->i2c_bus); | 1930 | intel_i2c_destroy(intel_output->i2c_bus); |
1838 | err_connector: | 1931 | err_inteloutput: |
1839 | drm_connector_cleanup(connector); | ||
1840 | kfree(intel_output); | 1932 | kfree(intel_output); |
1841 | 1933 | ||
1842 | return false; | 1934 | return false; |
diff --git a/drivers/gpu/drm/i915/intel_tv.c b/drivers/gpu/drm/i915/intel_tv.c index d2c32983242d..98ac0546b7bd 100644 --- a/drivers/gpu/drm/i915/intel_tv.c +++ b/drivers/gpu/drm/i915/intel_tv.c | |||
@@ -1626,6 +1626,7 @@ static const struct drm_encoder_helper_funcs intel_tv_helper_funcs = { | |||
1626 | }; | 1626 | }; |
1627 | 1627 | ||
1628 | static const struct drm_connector_funcs intel_tv_connector_funcs = { | 1628 | static const struct drm_connector_funcs intel_tv_connector_funcs = { |
1629 | .dpms = drm_helper_connector_dpms, | ||
1629 | .save = intel_tv_save, | 1630 | .save = intel_tv_save, |
1630 | .restore = intel_tv_restore, | 1631 | .restore = intel_tv_restore, |
1631 | .detect = intel_tv_detect, | 1632 | .detect = intel_tv_detect, |
diff --git a/drivers/gpu/drm/radeon/radeon_cp.c b/drivers/gpu/drm/radeon/radeon_cp.c index 77a7a4d84650..aff90bb96488 100644 --- a/drivers/gpu/drm/radeon/radeon_cp.c +++ b/drivers/gpu/drm/radeon/radeon_cp.c | |||
@@ -2185,9 +2185,9 @@ void radeon_commit_ring(drm_radeon_private_t *dev_priv) | |||
2185 | 2185 | ||
2186 | /* check if the ring is padded out to 16-dword alignment */ | 2186 | /* check if the ring is padded out to 16-dword alignment */ |
2187 | 2187 | ||
2188 | tail_aligned = dev_priv->ring.tail & 0xf; | 2188 | tail_aligned = dev_priv->ring.tail & (RADEON_RING_ALIGN-1); |
2189 | if (tail_aligned) { | 2189 | if (tail_aligned) { |
2190 | int num_p2 = 16 - tail_aligned; | 2190 | int num_p2 = RADEON_RING_ALIGN - tail_aligned; |
2191 | 2191 | ||
2192 | ring = dev_priv->ring.start; | 2192 | ring = dev_priv->ring.start; |
2193 | /* pad with some CP_PACKET2 */ | 2193 | /* pad with some CP_PACKET2 */ |
diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h index 8071d965f142..0c6bfc1de153 100644 --- a/drivers/gpu/drm/radeon/radeon_drv.h +++ b/drivers/gpu/drm/radeon/radeon_drv.h | |||
@@ -1964,11 +1964,14 @@ do { \ | |||
1964 | 1964 | ||
1965 | #define RING_LOCALS int write, _nr, _align_nr; unsigned int mask; u32 *ring; | 1965 | #define RING_LOCALS int write, _nr, _align_nr; unsigned int mask; u32 *ring; |
1966 | 1966 | ||
1967 | #define RADEON_RING_ALIGN 16 | ||
1968 | |||
1967 | #define BEGIN_RING( n ) do { \ | 1969 | #define BEGIN_RING( n ) do { \ |
1968 | if ( RADEON_VERBOSE ) { \ | 1970 | if ( RADEON_VERBOSE ) { \ |
1969 | DRM_INFO( "BEGIN_RING( %d )\n", (n)); \ | 1971 | DRM_INFO( "BEGIN_RING( %d )\n", (n)); \ |
1970 | } \ | 1972 | } \ |
1971 | _align_nr = (n + 0xf) & ~0xf; \ | 1973 | _align_nr = RADEON_RING_ALIGN - ((dev_priv->ring.tail + n) & (RADEON_RING_ALIGN-1)); \ |
1974 | _align_nr += n; \ | ||
1972 | if (dev_priv->ring.space <= (_align_nr * sizeof(u32))) { \ | 1975 | if (dev_priv->ring.space <= (_align_nr * sizeof(u32))) { \ |
1973 | COMMIT_RING(); \ | 1976 | COMMIT_RING(); \ |
1974 | radeon_wait_ring( dev_priv, _align_nr * sizeof(u32)); \ | 1977 | radeon_wait_ring( dev_priv, _align_nr * sizeof(u32)); \ |
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c index b5e3b2851698..a1787fdf5b9f 100644 --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c | |||
@@ -182,7 +182,7 @@ static struct platform_driver lm78_isa_driver = { | |||
182 | .name = "lm78", | 182 | .name = "lm78", |
183 | }, | 183 | }, |
184 | .probe = lm78_isa_probe, | 184 | .probe = lm78_isa_probe, |
185 | .remove = lm78_isa_remove, | 185 | .remove = __devexit_p(lm78_isa_remove), |
186 | }; | 186 | }; |
187 | 187 | ||
188 | 188 | ||
diff --git a/drivers/i2c/busses/i2c-sh7760.c b/drivers/i2c/busses/i2c-sh7760.c index baa28b73ae42..b9680f50f541 100644 --- a/drivers/i2c/busses/i2c-sh7760.c +++ b/drivers/i2c/busses/i2c-sh7760.c | |||
@@ -396,7 +396,7 @@ static int __devinit calc_CCR(unsigned long scl_hz) | |||
396 | signed char cdf, cdfm; | 396 | signed char cdf, cdfm; |
397 | int scgd, scgdm, scgds; | 397 | int scgd, scgdm, scgds; |
398 | 398 | ||
399 | mclk = clk_get(NULL, "module_clk"); | 399 | mclk = clk_get(NULL, "peripheral_clk"); |
400 | if (IS_ERR(mclk)) { | 400 | if (IS_ERR(mclk)) { |
401 | return PTR_ERR(mclk); | 401 | return PTR_ERR(mclk); |
402 | } else { | 402 | } else { |
diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c index 537da1cde16d..e59b6dee9ae2 100644 --- a/drivers/ide/alim15x3.c +++ b/drivers/ide/alim15x3.c | |||
@@ -402,27 +402,23 @@ static u8 ali_cable_detect(ide_hwif_t *hwif) | |||
402 | return cbl; | 402 | return cbl; |
403 | } | 403 | } |
404 | 404 | ||
405 | #if !defined(CONFIG_SPARC64) && !defined(CONFIG_PPC) | 405 | #ifndef CONFIG_SPARC64 |
406 | /** | 406 | /** |
407 | * init_hwif_ali15x3 - Initialize the ALI IDE x86 stuff | 407 | * init_hwif_ali15x3 - Initialize the ALI IDE x86 stuff |
408 | * @hwif: interface to configure | 408 | * @hwif: interface to configure |
409 | * | 409 | * |
410 | * Obtain the IRQ tables for an ALi based IDE solution on the PC | 410 | * Obtain the IRQ tables for an ALi based IDE solution on the PC |
411 | * class platforms. This part of the code isn't applicable to the | 411 | * class platforms. This part of the code isn't applicable to the |
412 | * Sparc and PowerPC systems. | 412 | * Sparc systems. |
413 | */ | 413 | */ |
414 | 414 | ||
415 | static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif) | 415 | static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif) |
416 | { | 416 | { |
417 | struct pci_dev *dev = to_pci_dev(hwif->dev); | ||
418 | u8 ideic, inmir; | 417 | u8 ideic, inmir; |
419 | s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6, | 418 | s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6, |
420 | 1, 11, 0, 12, 0, 14, 0, 15 }; | 419 | 1, 11, 0, 12, 0, 14, 0, 15 }; |
421 | int irq = -1; | 420 | int irq = -1; |
422 | 421 | ||
423 | if (dev->device == PCI_DEVICE_ID_AL_M5229) | ||
424 | hwif->irq = hwif->channel ? 15 : 14; | ||
425 | |||
426 | if (isa_dev) { | 422 | if (isa_dev) { |
427 | /* | 423 | /* |
428 | * read IDE interface control | 424 | * read IDE interface control |
@@ -455,7 +451,7 @@ static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif) | |||
455 | } | 451 | } |
456 | #else | 452 | #else |
457 | #define init_hwif_ali15x3 NULL | 453 | #define init_hwif_ali15x3 NULL |
458 | #endif /* !defined(CONFIG_SPARC64) && !defined(CONFIG_PPC) */ | 454 | #endif /* CONFIG_SPARC64 */ |
459 | 455 | ||
460 | /** | 456 | /** |
461 | * init_dma_ali15x3 - set up DMA on ALi15x3 | 457 | * init_dma_ali15x3 - set up DMA on ALi15x3 |
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c index 8a894fa37b53..757e5956b132 100644 --- a/drivers/ide/ide-atapi.c +++ b/drivers/ide/ide-atapi.c | |||
@@ -415,6 +415,12 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive) | |||
415 | if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0) | 415 | if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0) |
416 | dsc = 1; | 416 | dsc = 1; |
417 | 417 | ||
418 | /* | ||
419 | * ->pc_callback() might change rq->data_len for | ||
420 | * residual count, cache total length. | ||
421 | */ | ||
422 | done = blk_rq_bytes(rq); | ||
423 | |||
418 | /* Command finished - Call the callback function */ | 424 | /* Command finished - Call the callback function */ |
419 | uptodate = drive->pc_callback(drive, dsc); | 425 | uptodate = drive->pc_callback(drive, dsc); |
420 | 426 | ||
diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c index 61111fd27130..39d4e01f5c9c 100644 --- a/drivers/ide/ide-pci-generic.c +++ b/drivers/ide/ide-pci-generic.c | |||
@@ -33,6 +33,16 @@ static int ide_generic_all; /* Set to claim all devices */ | |||
33 | module_param_named(all_generic_ide, ide_generic_all, bool, 0444); | 33 | module_param_named(all_generic_ide, ide_generic_all, bool, 0444); |
34 | MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers."); | 34 | MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers."); |
35 | 35 | ||
36 | static void netcell_quirkproc(ide_drive_t *drive) | ||
37 | { | ||
38 | /* mark words 85-87 as valid */ | ||
39 | drive->id[ATA_ID_CSF_DEFAULT] |= 0x4000; | ||
40 | } | ||
41 | |||
42 | static const struct ide_port_ops netcell_port_ops = { | ||
43 | .quirkproc = netcell_quirkproc, | ||
44 | }; | ||
45 | |||
36 | #define DECLARE_GENERIC_PCI_DEV(extra_flags) \ | 46 | #define DECLARE_GENERIC_PCI_DEV(extra_flags) \ |
37 | { \ | 47 | { \ |
38 | .name = DRV_NAME, \ | 48 | .name = DRV_NAME, \ |
@@ -74,6 +84,7 @@ static const struct ide_port_info generic_chipsets[] __devinitdata = { | |||
74 | 84 | ||
75 | { /* 6: Revolution */ | 85 | { /* 6: Revolution */ |
76 | .name = DRV_NAME, | 86 | .name = DRV_NAME, |
87 | .port_ops = &netcell_port_ops, | ||
77 | .host_flags = IDE_HFLAG_CLEAR_SIMPLEX | | 88 | .host_flags = IDE_HFLAG_CLEAR_SIMPLEX | |
78 | IDE_HFLAG_TRUST_BIOS_FOR_DMA | | 89 | IDE_HFLAG_TRUST_BIOS_FOR_DMA | |
79 | IDE_HFLAG_OFF_BOARD, | 90 | IDE_HFLAG_OFF_BOARD, |
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c index 683ff37d4079..d9764f0bc82f 100644 --- a/drivers/ide/ide-tape.c +++ b/drivers/ide/ide-tape.c | |||
@@ -892,6 +892,7 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size) | |||
892 | rq->cmd_type = REQ_TYPE_SPECIAL; | 892 | rq->cmd_type = REQ_TYPE_SPECIAL; |
893 | rq->cmd[13] = cmd; | 893 | rq->cmd[13] = cmd; |
894 | rq->rq_disk = tape->disk; | 894 | rq->rq_disk = tape->disk; |
895 | rq->__sector = tape->first_frame; | ||
895 | 896 | ||
896 | if (size) { | 897 | if (size) { |
897 | ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size, | 898 | ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size, |
diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c index c2a16a8f486d..e24ecc87a9b1 100644 --- a/drivers/ide/pdc202xx_old.c +++ b/drivers/ide/pdc202xx_old.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org> | 2 | * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org> |
3 | * Copyright (C) 2006-2007 MontaVista Software, Inc. | 3 | * Copyright (C) 2006-2007, 2009 MontaVista Software, Inc. |
4 | * Copyright (C) 2007 Bartlomiej Zolnierkiewicz | 4 | * Copyright (C) 2007 Bartlomiej Zolnierkiewicz |
5 | * | 5 | * |
6 | * Portions Copyright (C) 1999 Promise Technology, Inc. | 6 | * Portions Copyright (C) 1999 Promise Technology, Inc. |
@@ -227,28 +227,19 @@ somebody_else: | |||
227 | return (dma_stat & 4) == 4; /* return 1 if INTR asserted */ | 227 | return (dma_stat & 4) == 4; /* return 1 if INTR asserted */ |
228 | } | 228 | } |
229 | 229 | ||
230 | static void pdc202xx_reset_host (ide_hwif_t *hwif) | 230 | static void pdc202xx_reset(ide_drive_t *drive) |
231 | { | 231 | { |
232 | ide_hwif_t *hwif = drive->hwif; | ||
232 | unsigned long high_16 = hwif->extra_base - 16; | 233 | unsigned long high_16 = hwif->extra_base - 16; |
233 | u8 udma_speed_flag = inb(high_16 | 0x001f); | 234 | u8 udma_speed_flag = inb(high_16 | 0x001f); |
234 | 235 | ||
236 | printk(KERN_WARNING "PDC202xx: software reset...\n"); | ||
237 | |||
235 | outb(udma_speed_flag | 0x10, high_16 | 0x001f); | 238 | outb(udma_speed_flag | 0x10, high_16 | 0x001f); |
236 | mdelay(100); | 239 | mdelay(100); |
237 | outb(udma_speed_flag & ~0x10, high_16 | 0x001f); | 240 | outb(udma_speed_flag & ~0x10, high_16 | 0x001f); |
238 | mdelay(2000); /* 2 seconds ?! */ | 241 | mdelay(2000); /* 2 seconds ?! */ |
239 | 242 | ||
240 | printk(KERN_WARNING "PDC202XX: %s channel reset.\n", | ||
241 | hwif->channel ? "Secondary" : "Primary"); | ||
242 | } | ||
243 | |||
244 | static void pdc202xx_reset (ide_drive_t *drive) | ||
245 | { | ||
246 | ide_hwif_t *hwif = drive->hwif; | ||
247 | ide_hwif_t *mate = hwif->mate; | ||
248 | |||
249 | pdc202xx_reset_host(hwif); | ||
250 | pdc202xx_reset_host(mate); | ||
251 | |||
252 | ide_set_max_pio(drive); | 243 | ide_set_max_pio(drive); |
253 | } | 244 | } |
254 | 245 | ||
@@ -328,9 +319,8 @@ static const struct ide_dma_ops pdc20246_dma_ops = { | |||
328 | .dma_start = ide_dma_start, | 319 | .dma_start = ide_dma_start, |
329 | .dma_end = ide_dma_end, | 320 | .dma_end = ide_dma_end, |
330 | .dma_test_irq = pdc202xx_dma_test_irq, | 321 | .dma_test_irq = pdc202xx_dma_test_irq, |
331 | .dma_lost_irq = pdc202xx_dma_lost_irq, | 322 | .dma_lost_irq = ide_dma_lost_irq, |
332 | .dma_timer_expiry = ide_dma_sff_timer_expiry, | 323 | .dma_timer_expiry = ide_dma_sff_timer_expiry, |
333 | .dma_clear = pdc202xx_reset, | ||
334 | .dma_sff_read_status = ide_dma_sff_read_status, | 324 | .dma_sff_read_status = ide_dma_sff_read_status, |
335 | }; | 325 | }; |
336 | 326 | ||
diff --git a/drivers/idle/i7300_idle.c b/drivers/idle/i7300_idle.c index bf740394d704..949c97ff57e3 100644 --- a/drivers/idle/i7300_idle.c +++ b/drivers/idle/i7300_idle.c | |||
@@ -41,6 +41,10 @@ static int debug; | |||
41 | module_param_named(debug, debug, uint, 0644); | 41 | module_param_named(debug, debug, uint, 0644); |
42 | MODULE_PARM_DESC(debug, "Enable debug printks in this driver"); | 42 | MODULE_PARM_DESC(debug, "Enable debug printks in this driver"); |
43 | 43 | ||
44 | static int forceload; | ||
45 | module_param_named(forceload, forceload, uint, 0644); | ||
46 | MODULE_PARM_DESC(debug, "Enable driver testing on unvalidated i5000"); | ||
47 | |||
44 | #define dprintk(fmt, arg...) \ | 48 | #define dprintk(fmt, arg...) \ |
45 | do { if (debug) printk(KERN_INFO I7300_PRINT fmt, ##arg); } while (0) | 49 | do { if (debug) printk(KERN_INFO I7300_PRINT fmt, ##arg); } while (0) |
46 | 50 | ||
@@ -552,7 +556,7 @@ static int __init i7300_idle_init(void) | |||
552 | cpus_clear(idle_cpumask); | 556 | cpus_clear(idle_cpumask); |
553 | total_us = 0; | 557 | total_us = 0; |
554 | 558 | ||
555 | if (i7300_idle_platform_probe(&fbd_dev, &ioat_dev)) | 559 | if (i7300_idle_platform_probe(&fbd_dev, &ioat_dev, forceload)) |
556 | return -ENODEV; | 560 | return -ENODEV; |
557 | 561 | ||
558 | if (i7300_idle_thrt_save()) | 562 | if (i7300_idle_thrt_save()) |
diff --git a/drivers/input/input.c b/drivers/input/input.c index e54e002665b0..5d445f48789b 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
@@ -42,6 +42,7 @@ static unsigned int input_abs_bypass_init_data[] __initdata = { | |||
42 | ABS_MT_POSITION_Y, | 42 | ABS_MT_POSITION_Y, |
43 | ABS_MT_TOOL_TYPE, | 43 | ABS_MT_TOOL_TYPE, |
44 | ABS_MT_BLOB_ID, | 44 | ABS_MT_BLOB_ID, |
45 | ABS_MT_TRACKING_ID, | ||
45 | 0 | 46 | 0 |
46 | }; | 47 | }; |
47 | static unsigned long input_abs_bypass[BITS_TO_LONGS(ABS_CNT)]; | 48 | static unsigned long input_abs_bypass[BITS_TO_LONGS(ABS_CNT)]; |
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c index 67248c31e19a..be5bbbb8ae4e 100644 --- a/drivers/input/serio/libps2.c +++ b/drivers/input/serio/libps2.c | |||
@@ -210,7 +210,7 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command) | |||
210 | timeout = wait_event_timeout(ps2dev->wait, | 210 | timeout = wait_event_timeout(ps2dev->wait, |
211 | !(ps2dev->flags & PS2_FLAG_CMD1), timeout); | 211 | !(ps2dev->flags & PS2_FLAG_CMD1), timeout); |
212 | 212 | ||
213 | if (ps2dev->cmdcnt && timeout > 0) { | 213 | if (ps2dev->cmdcnt && !(ps2dev->flags & PS2_FLAG_CMD1)) { |
214 | 214 | ||
215 | timeout = ps2_adjust_timeout(ps2dev, command, timeout); | 215 | timeout = ps2_adjust_timeout(ps2dev, command, timeout); |
216 | wait_event_timeout(ps2dev->wait, | 216 | wait_event_timeout(ps2dev->wait, |
diff --git a/drivers/input/touchscreen/ucb1400_ts.c b/drivers/input/touchscreen/ucb1400_ts.c index f100c7f4c1db..6954f5500108 100644 --- a/drivers/input/touchscreen/ucb1400_ts.c +++ b/drivers/input/touchscreen/ucb1400_ts.c | |||
@@ -419,7 +419,7 @@ static int ucb1400_ts_remove(struct platform_device *dev) | |||
419 | #ifdef CONFIG_PM | 419 | #ifdef CONFIG_PM |
420 | static int ucb1400_ts_resume(struct platform_device *dev) | 420 | static int ucb1400_ts_resume(struct platform_device *dev) |
421 | { | 421 | { |
422 | struct ucb1400_ts *ucb = platform_get_drvdata(dev); | 422 | struct ucb1400_ts *ucb = dev->dev.platform_data; |
423 | 423 | ||
424 | if (ucb->ts_task) { | 424 | if (ucb->ts_task) { |
425 | /* | 425 | /* |
diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c index b171e75cb52e..29808c4fb1cb 100644 --- a/drivers/isdn/gigaset/isocdata.c +++ b/drivers/isdn/gigaset/isocdata.c | |||
@@ -175,7 +175,7 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size) | |||
175 | return -EINVAL; | 175 | return -EINVAL; |
176 | } | 176 | } |
177 | src = iwb->read; | 177 | src = iwb->read; |
178 | if (unlikely(limit > BAS_OUTBUFSIZE + BAS_OUTBUFPAD || | 178 | if (unlikely(limit >= BAS_OUTBUFSIZE + BAS_OUTBUFPAD || |
179 | (read < src && limit >= src))) { | 179 | (read < src && limit >= src))) { |
180 | pr_err("isoc write buffer frame reservation violated\n"); | 180 | pr_err("isoc write buffer frame reservation violated\n"); |
181 | return -EFAULT; | 181 | return -EFAULT; |
diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c index 1a83910f674f..eaf722fe309a 100644 --- a/drivers/lguest/x86/core.c +++ b/drivers/lguest/x86/core.c | |||
@@ -358,6 +358,16 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu) | |||
358 | if (emulate_insn(cpu)) | 358 | if (emulate_insn(cpu)) |
359 | return; | 359 | return; |
360 | } | 360 | } |
361 | /* If KVM is active, the vmcall instruction triggers a | ||
362 | * General Protection Fault. Normally it triggers an | ||
363 | * invalid opcode fault (6): */ | ||
364 | case 6: | ||
365 | /* We need to check if ring == GUEST_PL and | ||
366 | * faulting instruction == vmcall. */ | ||
367 | if (is_hypercall(cpu)) { | ||
368 | rewrite_hypercall(cpu); | ||
369 | return; | ||
370 | } | ||
361 | break; | 371 | break; |
362 | case 14: /* We've intercepted a Page Fault. */ | 372 | case 14: /* We've intercepted a Page Fault. */ |
363 | /* The Guest accessed a virtual address that wasn't mapped. | 373 | /* The Guest accessed a virtual address that wasn't mapped. |
@@ -403,15 +413,6 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu) | |||
403 | * up the pointer now to indicate a hypercall is pending. */ | 413 | * up the pointer now to indicate a hypercall is pending. */ |
404 | cpu->hcall = (struct hcall_args *)cpu->regs; | 414 | cpu->hcall = (struct hcall_args *)cpu->regs; |
405 | return; | 415 | return; |
406 | case 6: | ||
407 | /* kvm hypercalls trigger an invalid opcode fault (6). | ||
408 | * We need to check if ring == GUEST_PL and | ||
409 | * faulting instruction == vmcall. */ | ||
410 | if (is_hypercall(cpu)) { | ||
411 | rewrite_hypercall(cpu); | ||
412 | return; | ||
413 | } | ||
414 | break; | ||
415 | } | 416 | } |
416 | 417 | ||
417 | /* We didn't handle the trap, so it needs to go to the Guest. */ | 418 | /* We didn't handle the trap, so it needs to go to the Guest. */ |
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c index 06b0ded1ce23..3319c2fec28e 100644 --- a/drivers/md/bitmap.c +++ b/drivers/md/bitmap.c | |||
@@ -1097,14 +1097,12 @@ void bitmap_daemon_work(struct bitmap *bitmap) | |||
1097 | } | 1097 | } |
1098 | bitmap->allclean = 1; | 1098 | bitmap->allclean = 1; |
1099 | 1099 | ||
1100 | spin_lock_irqsave(&bitmap->lock, flags); | ||
1100 | for (j = 0; j < bitmap->chunks; j++) { | 1101 | for (j = 0; j < bitmap->chunks; j++) { |
1101 | bitmap_counter_t *bmc; | 1102 | bitmap_counter_t *bmc; |
1102 | spin_lock_irqsave(&bitmap->lock, flags); | 1103 | if (!bitmap->filemap) |
1103 | if (!bitmap->filemap) { | ||
1104 | /* error or shutdown */ | 1104 | /* error or shutdown */ |
1105 | spin_unlock_irqrestore(&bitmap->lock, flags); | ||
1106 | break; | 1105 | break; |
1107 | } | ||
1108 | 1106 | ||
1109 | page = filemap_get_page(bitmap, j); | 1107 | page = filemap_get_page(bitmap, j); |
1110 | 1108 | ||
@@ -1121,6 +1119,8 @@ void bitmap_daemon_work(struct bitmap *bitmap) | |||
1121 | write_page(bitmap, page, 0); | 1119 | write_page(bitmap, page, 0); |
1122 | bitmap->allclean = 0; | 1120 | bitmap->allclean = 0; |
1123 | } | 1121 | } |
1122 | spin_lock_irqsave(&bitmap->lock, flags); | ||
1123 | j |= (PAGE_BITS - 1); | ||
1124 | continue; | 1124 | continue; |
1125 | } | 1125 | } |
1126 | 1126 | ||
@@ -1181,9 +1181,10 @@ void bitmap_daemon_work(struct bitmap *bitmap) | |||
1181 | ext2_clear_bit(file_page_offset(j), paddr); | 1181 | ext2_clear_bit(file_page_offset(j), paddr); |
1182 | kunmap_atomic(paddr, KM_USER0); | 1182 | kunmap_atomic(paddr, KM_USER0); |
1183 | } | 1183 | } |
1184 | } | 1184 | } else |
1185 | spin_unlock_irqrestore(&bitmap->lock, flags); | 1185 | j |= PAGE_COUNTER_MASK; |
1186 | } | 1186 | } |
1187 | spin_unlock_irqrestore(&bitmap->lock, flags); | ||
1187 | 1188 | ||
1188 | /* now sync the final page */ | 1189 | /* now sync the final page */ |
1189 | if (lastpage != NULL) { | 1190 | if (lastpage != NULL) { |
diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 424f7b048c30..3fd8b1e65483 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c | |||
@@ -20,7 +20,8 @@ | |||
20 | #include <linux/idr.h> | 20 | #include <linux/idr.h> |
21 | #include <linux/hdreg.h> | 21 | #include <linux/hdreg.h> |
22 | #include <linux/blktrace_api.h> | 22 | #include <linux/blktrace_api.h> |
23 | #include <trace/block.h> | 23 | |
24 | #include <trace/events/block.h> | ||
24 | 25 | ||
25 | #define DM_MSG_PREFIX "core" | 26 | #define DM_MSG_PREFIX "core" |
26 | 27 | ||
@@ -53,8 +54,6 @@ struct dm_target_io { | |||
53 | union map_info info; | 54 | union map_info info; |
54 | }; | 55 | }; |
55 | 56 | ||
56 | DEFINE_TRACE(block_bio_complete); | ||
57 | |||
58 | /* | 57 | /* |
59 | * For request-based dm. | 58 | * For request-based dm. |
60 | * One of these is allocated per request. | 59 | * One of these is allocated per request. |
@@ -656,8 +655,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone, | |||
656 | /* the bio has been remapped so dispatch it */ | 655 | /* the bio has been remapped so dispatch it */ |
657 | 656 | ||
658 | trace_block_remap(bdev_get_queue(clone->bi_bdev), clone, | 657 | trace_block_remap(bdev_get_queue(clone->bi_bdev), clone, |
659 | tio->io->bio->bi_bdev->bd_dev, | 658 | tio->io->bio->bi_bdev->bd_dev, sector); |
660 | clone->bi_sector, sector); | ||
661 | 659 | ||
662 | generic_make_request(clone); | 660 | generic_make_request(clone); |
663 | } else if (r < 0 || r == DM_MAPIO_REQUEUE) { | 661 | } else if (r < 0 || r == DM_MAPIO_REQUEUE) { |
diff --git a/drivers/md/md.c b/drivers/md/md.c index 4cbc19f5c304..20f6ac338349 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c | |||
@@ -1375,6 +1375,9 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev) | |||
1375 | 1375 | ||
1376 | sb->raid_disks = cpu_to_le32(mddev->raid_disks); | 1376 | sb->raid_disks = cpu_to_le32(mddev->raid_disks); |
1377 | sb->size = cpu_to_le64(mddev->dev_sectors); | 1377 | sb->size = cpu_to_le64(mddev->dev_sectors); |
1378 | sb->chunksize = cpu_to_le32(mddev->chunk_size >> 9); | ||
1379 | sb->level = cpu_to_le32(mddev->level); | ||
1380 | sb->layout = cpu_to_le32(mddev->layout); | ||
1378 | 1381 | ||
1379 | if (mddev->bitmap && mddev->bitmap_file == NULL) { | 1382 | if (mddev->bitmap && mddev->bitmap_file == NULL) { |
1380 | sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_offset); | 1383 | sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_offset); |
@@ -3303,7 +3306,9 @@ static ssize_t | |||
3303 | action_show(mddev_t *mddev, char *page) | 3306 | action_show(mddev_t *mddev, char *page) |
3304 | { | 3307 | { |
3305 | char *type = "idle"; | 3308 | char *type = "idle"; |
3306 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || | 3309 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
3310 | type = "frozen"; | ||
3311 | else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || | ||
3307 | (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))) { | 3312 | (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))) { |
3308 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) | 3313 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
3309 | type = "reshape"; | 3314 | type = "reshape"; |
@@ -3326,7 +3331,12 @@ action_store(mddev_t *mddev, const char *page, size_t len) | |||
3326 | if (!mddev->pers || !mddev->pers->sync_request) | 3331 | if (!mddev->pers || !mddev->pers->sync_request) |
3327 | return -EINVAL; | 3332 | return -EINVAL; |
3328 | 3333 | ||
3329 | if (cmd_match(page, "idle")) { | 3334 | if (cmd_match(page, "frozen")) |
3335 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); | ||
3336 | else | ||
3337 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); | ||
3338 | |||
3339 | if (cmd_match(page, "idle") || cmd_match(page, "frozen")) { | ||
3330 | if (mddev->sync_thread) { | 3340 | if (mddev->sync_thread) { |
3331 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); | 3341 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
3332 | md_unregister_thread(mddev->sync_thread); | 3342 | md_unregister_thread(mddev->sync_thread); |
@@ -3680,7 +3690,7 @@ array_size_store(mddev_t *mddev, const char *buf, size_t len) | |||
3680 | if (strict_blocks_to_sectors(buf, §ors) < 0) | 3690 | if (strict_blocks_to_sectors(buf, §ors) < 0) |
3681 | return -EINVAL; | 3691 | return -EINVAL; |
3682 | if (mddev->pers && mddev->pers->size(mddev, 0, 0) < sectors) | 3692 | if (mddev->pers && mddev->pers->size(mddev, 0, 0) < sectors) |
3683 | return -EINVAL; | 3693 | return -E2BIG; |
3684 | 3694 | ||
3685 | mddev->external_size = 1; | 3695 | mddev->external_size = 1; |
3686 | } | 3696 | } |
@@ -5557,7 +5567,7 @@ static struct block_device_operations md_fops = | |||
5557 | .owner = THIS_MODULE, | 5567 | .owner = THIS_MODULE, |
5558 | .open = md_open, | 5568 | .open = md_open, |
5559 | .release = md_release, | 5569 | .release = md_release, |
5560 | .locked_ioctl = md_ioctl, | 5570 | .ioctl = md_ioctl, |
5561 | .getgeo = md_getgeo, | 5571 | .getgeo = md_getgeo, |
5562 | .media_changed = md_media_changed, | 5572 | .media_changed = md_media_changed, |
5563 | .revalidate_disk= md_revalidate, | 5573 | .revalidate_disk= md_revalidate, |
@@ -6352,12 +6362,13 @@ void md_do_sync(mddev_t *mddev) | |||
6352 | 6362 | ||
6353 | skipped = 0; | 6363 | skipped = 0; |
6354 | 6364 | ||
6355 | if ((mddev->curr_resync > mddev->curr_resync_completed && | 6365 | if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && |
6356 | (mddev->curr_resync - mddev->curr_resync_completed) | 6366 | ((mddev->curr_resync > mddev->curr_resync_completed && |
6357 | > (max_sectors >> 4)) || | 6367 | (mddev->curr_resync - mddev->curr_resync_completed) |
6358 | (j - mddev->curr_resync_completed)*2 | 6368 | > (max_sectors >> 4)) || |
6359 | >= mddev->resync_max - mddev->curr_resync_completed | 6369 | (j - mddev->curr_resync_completed)*2 |
6360 | ) { | 6370 | >= mddev->resync_max - mddev->curr_resync_completed |
6371 | )) { | ||
6361 | /* time to update curr_resync_completed */ | 6372 | /* time to update curr_resync_completed */ |
6362 | blk_unplug(mddev->queue); | 6373 | blk_unplug(mddev->queue); |
6363 | wait_event(mddev->recovery_wait, | 6374 | wait_event(mddev->recovery_wait, |
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 7970dc8c522e..bef876698232 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c | |||
@@ -362,7 +362,7 @@ static void raid5_unplug_device(struct request_queue *q); | |||
362 | 362 | ||
363 | static struct stripe_head * | 363 | static struct stripe_head * |
364 | get_active_stripe(raid5_conf_t *conf, sector_t sector, | 364 | get_active_stripe(raid5_conf_t *conf, sector_t sector, |
365 | int previous, int noblock) | 365 | int previous, int noblock, int noquiesce) |
366 | { | 366 | { |
367 | struct stripe_head *sh; | 367 | struct stripe_head *sh; |
368 | 368 | ||
@@ -372,7 +372,7 @@ get_active_stripe(raid5_conf_t *conf, sector_t sector, | |||
372 | 372 | ||
373 | do { | 373 | do { |
374 | wait_event_lock_irq(conf->wait_for_stripe, | 374 | wait_event_lock_irq(conf->wait_for_stripe, |
375 | conf->quiesce == 0, | 375 | conf->quiesce == 0 || noquiesce, |
376 | conf->device_lock, /* nothing */); | 376 | conf->device_lock, /* nothing */); |
377 | sh = __find_stripe(conf, sector, conf->generation - previous); | 377 | sh = __find_stripe(conf, sector, conf->generation - previous); |
378 | if (!sh) { | 378 | if (!sh) { |
@@ -2671,7 +2671,7 @@ static void handle_stripe_expansion(raid5_conf_t *conf, struct stripe_head *sh, | |||
2671 | sector_t bn = compute_blocknr(sh, i, 1); | 2671 | sector_t bn = compute_blocknr(sh, i, 1); |
2672 | sector_t s = raid5_compute_sector(conf, bn, 0, | 2672 | sector_t s = raid5_compute_sector(conf, bn, 0, |
2673 | &dd_idx, NULL); | 2673 | &dd_idx, NULL); |
2674 | sh2 = get_active_stripe(conf, s, 0, 1); | 2674 | sh2 = get_active_stripe(conf, s, 0, 1, 1); |
2675 | if (sh2 == NULL) | 2675 | if (sh2 == NULL) |
2676 | /* so far only the early blocks of this stripe | 2676 | /* so far only the early blocks of this stripe |
2677 | * have been requested. When later blocks | 2677 | * have been requested. When later blocks |
@@ -2944,7 +2944,7 @@ static bool handle_stripe5(struct stripe_head *sh) | |||
2944 | /* Finish reconstruct operations initiated by the expansion process */ | 2944 | /* Finish reconstruct operations initiated by the expansion process */ |
2945 | if (sh->reconstruct_state == reconstruct_state_result) { | 2945 | if (sh->reconstruct_state == reconstruct_state_result) { |
2946 | struct stripe_head *sh2 | 2946 | struct stripe_head *sh2 |
2947 | = get_active_stripe(conf, sh->sector, 1, 1); | 2947 | = get_active_stripe(conf, sh->sector, 1, 1, 1); |
2948 | if (sh2 && test_bit(STRIPE_EXPAND_SOURCE, &sh2->state)) { | 2948 | if (sh2 && test_bit(STRIPE_EXPAND_SOURCE, &sh2->state)) { |
2949 | /* sh cannot be written until sh2 has been read. | 2949 | /* sh cannot be written until sh2 has been read. |
2950 | * so arrange for sh to be delayed a little | 2950 | * so arrange for sh to be delayed a little |
@@ -3189,7 +3189,7 @@ static bool handle_stripe6(struct stripe_head *sh, struct page *tmp_page) | |||
3189 | 3189 | ||
3190 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state)) { | 3190 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state)) { |
3191 | struct stripe_head *sh2 | 3191 | struct stripe_head *sh2 |
3192 | = get_active_stripe(conf, sh->sector, 1, 1); | 3192 | = get_active_stripe(conf, sh->sector, 1, 1, 1); |
3193 | if (sh2 && test_bit(STRIPE_EXPAND_SOURCE, &sh2->state)) { | 3193 | if (sh2 && test_bit(STRIPE_EXPAND_SOURCE, &sh2->state)) { |
3194 | /* sh cannot be written until sh2 has been read. | 3194 | /* sh cannot be written until sh2 has been read. |
3195 | * so arrange for sh to be delayed a little | 3195 | * so arrange for sh to be delayed a little |
@@ -3288,7 +3288,7 @@ static void unplug_slaves(mddev_t *mddev) | |||
3288 | int i; | 3288 | int i; |
3289 | 3289 | ||
3290 | rcu_read_lock(); | 3290 | rcu_read_lock(); |
3291 | for (i=0; i<mddev->raid_disks; i++) { | 3291 | for (i = 0; i < conf->raid_disks; i++) { |
3292 | mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev); | 3292 | mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev); |
3293 | if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) { | 3293 | if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) { |
3294 | struct request_queue *r_queue = bdev_get_queue(rdev->bdev); | 3294 | struct request_queue *r_queue = bdev_get_queue(rdev->bdev); |
@@ -3675,7 +3675,7 @@ static int make_request(struct request_queue *q, struct bio * bi) | |||
3675 | (unsigned long long)logical_sector); | 3675 | (unsigned long long)logical_sector); |
3676 | 3676 | ||
3677 | sh = get_active_stripe(conf, new_sector, previous, | 3677 | sh = get_active_stripe(conf, new_sector, previous, |
3678 | (bi->bi_rw&RWA_MASK)); | 3678 | (bi->bi_rw&RWA_MASK), 0); |
3679 | if (sh) { | 3679 | if (sh) { |
3680 | if (unlikely(previous)) { | 3680 | if (unlikely(previous)) { |
3681 | /* expansion might have moved on while waiting for a | 3681 | /* expansion might have moved on while waiting for a |
@@ -3811,13 +3811,13 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped | |||
3811 | safepos = conf->reshape_safe; | 3811 | safepos = conf->reshape_safe; |
3812 | sector_div(safepos, data_disks); | 3812 | sector_div(safepos, data_disks); |
3813 | if (mddev->delta_disks < 0) { | 3813 | if (mddev->delta_disks < 0) { |
3814 | writepos -= reshape_sectors; | 3814 | writepos -= min_t(sector_t, reshape_sectors, writepos); |
3815 | readpos += reshape_sectors; | 3815 | readpos += reshape_sectors; |
3816 | safepos += reshape_sectors; | 3816 | safepos += reshape_sectors; |
3817 | } else { | 3817 | } else { |
3818 | writepos += reshape_sectors; | 3818 | writepos += reshape_sectors; |
3819 | readpos -= reshape_sectors; | 3819 | readpos -= min_t(sector_t, reshape_sectors, readpos); |
3820 | safepos -= reshape_sectors; | 3820 | safepos -= min_t(sector_t, reshape_sectors, safepos); |
3821 | } | 3821 | } |
3822 | 3822 | ||
3823 | /* 'writepos' is the most advanced device address we might write. | 3823 | /* 'writepos' is the most advanced device address we might write. |
@@ -3873,7 +3873,7 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped | |||
3873 | for (i = 0; i < reshape_sectors; i += STRIPE_SECTORS) { | 3873 | for (i = 0; i < reshape_sectors; i += STRIPE_SECTORS) { |
3874 | int j; | 3874 | int j; |
3875 | int skipped = 0; | 3875 | int skipped = 0; |
3876 | sh = get_active_stripe(conf, stripe_addr+i, 0, 0); | 3876 | sh = get_active_stripe(conf, stripe_addr+i, 0, 0, 1); |
3877 | set_bit(STRIPE_EXPANDING, &sh->state); | 3877 | set_bit(STRIPE_EXPANDING, &sh->state); |
3878 | atomic_inc(&conf->reshape_stripes); | 3878 | atomic_inc(&conf->reshape_stripes); |
3879 | /* If any of this stripe is beyond the end of the old | 3879 | /* If any of this stripe is beyond the end of the old |
@@ -3916,13 +3916,13 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped | |||
3916 | raid5_compute_sector(conf, stripe_addr*(new_data_disks), | 3916 | raid5_compute_sector(conf, stripe_addr*(new_data_disks), |
3917 | 1, &dd_idx, NULL); | 3917 | 1, &dd_idx, NULL); |
3918 | last_sector = | 3918 | last_sector = |
3919 | raid5_compute_sector(conf, ((stripe_addr+conf->chunk_size/512) | 3919 | raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) |
3920 | *(new_data_disks) - 1), | 3920 | *(new_data_disks) - 1), |
3921 | 1, &dd_idx, NULL); | 3921 | 1, &dd_idx, NULL); |
3922 | if (last_sector >= mddev->dev_sectors) | 3922 | if (last_sector >= mddev->dev_sectors) |
3923 | last_sector = mddev->dev_sectors - 1; | 3923 | last_sector = mddev->dev_sectors - 1; |
3924 | while (first_sector <= last_sector) { | 3924 | while (first_sector <= last_sector) { |
3925 | sh = get_active_stripe(conf, first_sector, 1, 0); | 3925 | sh = get_active_stripe(conf, first_sector, 1, 0, 1); |
3926 | set_bit(STRIPE_EXPAND_SOURCE, &sh->state); | 3926 | set_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
3927 | set_bit(STRIPE_HANDLE, &sh->state); | 3927 | set_bit(STRIPE_HANDLE, &sh->state); |
3928 | release_stripe(sh); | 3928 | release_stripe(sh); |
@@ -4022,9 +4022,9 @@ static inline sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *ski | |||
4022 | 4022 | ||
4023 | bitmap_cond_end_sync(mddev->bitmap, sector_nr); | 4023 | bitmap_cond_end_sync(mddev->bitmap, sector_nr); |
4024 | 4024 | ||
4025 | sh = get_active_stripe(conf, sector_nr, 0, 1); | 4025 | sh = get_active_stripe(conf, sector_nr, 0, 1, 0); |
4026 | if (sh == NULL) { | 4026 | if (sh == NULL) { |
4027 | sh = get_active_stripe(conf, sector_nr, 0, 0); | 4027 | sh = get_active_stripe(conf, sector_nr, 0, 0, 0); |
4028 | /* make sure we don't swamp the stripe cache if someone else | 4028 | /* make sure we don't swamp the stripe cache if someone else |
4029 | * is trying to get access | 4029 | * is trying to get access |
4030 | */ | 4030 | */ |
@@ -4034,7 +4034,7 @@ static inline sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *ski | |||
4034 | * We don't need to check the 'failed' flag as when that gets set, | 4034 | * We don't need to check the 'failed' flag as when that gets set, |
4035 | * recovery aborts. | 4035 | * recovery aborts. |
4036 | */ | 4036 | */ |
4037 | for (i=0; i<mddev->raid_disks; i++) | 4037 | for (i = 0; i < conf->raid_disks; i++) |
4038 | if (conf->disks[i].rdev == NULL) | 4038 | if (conf->disks[i].rdev == NULL) |
4039 | still_degraded = 1; | 4039 | still_degraded = 1; |
4040 | 4040 | ||
@@ -4086,7 +4086,7 @@ static int retry_aligned_read(raid5_conf_t *conf, struct bio *raid_bio) | |||
4086 | /* already done this stripe */ | 4086 | /* already done this stripe */ |
4087 | continue; | 4087 | continue; |
4088 | 4088 | ||
4089 | sh = get_active_stripe(conf, sector, 0, 1); | 4089 | sh = get_active_stripe(conf, sector, 0, 1, 0); |
4090 | 4090 | ||
4091 | if (!sh) { | 4091 | if (!sh) { |
4092 | /* failed to get a stripe - must wait */ | 4092 | /* failed to get a stripe - must wait */ |
diff --git a/drivers/media/video/ivtv/ivtv-queue.c b/drivers/media/video/ivtv/ivtv-queue.c index ff7b7deded4f..7fde36e6d227 100644 --- a/drivers/media/video/ivtv/ivtv-queue.c +++ b/drivers/media/video/ivtv/ivtv-queue.c | |||
@@ -230,7 +230,8 @@ int ivtv_stream_alloc(struct ivtv_stream *s) | |||
230 | return -ENOMEM; | 230 | return -ENOMEM; |
231 | } | 231 | } |
232 | if (ivtv_might_use_dma(s)) { | 232 | if (ivtv_might_use_dma(s)) { |
233 | s->sg_handle = pci_map_single(itv->pdev, s->sg_dma, sizeof(struct ivtv_sg_element), s->dma); | 233 | s->sg_handle = pci_map_single(itv->pdev, s->sg_dma, |
234 | sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE); | ||
234 | ivtv_stream_sync_for_cpu(s); | 235 | ivtv_stream_sync_for_cpu(s); |
235 | } | 236 | } |
236 | 237 | ||
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c index 3cf61ece71d7..348443bdb23b 100644 --- a/drivers/misc/enclosure.c +++ b/drivers/misc/enclosure.c | |||
@@ -119,7 +119,7 @@ enclosure_register(struct device *dev, const char *name, int components, | |||
119 | edev->edev.class = &enclosure_class; | 119 | edev->edev.class = &enclosure_class; |
120 | edev->edev.parent = get_device(dev); | 120 | edev->edev.parent = get_device(dev); |
121 | edev->cb = cb; | 121 | edev->cb = cb; |
122 | dev_set_name(&edev->edev, name); | 122 | dev_set_name(&edev->edev, "%s", name); |
123 | err = device_register(&edev->edev); | 123 | err = device_register(&edev->edev); |
124 | if (err) | 124 | if (err) |
125 | goto err; | 125 | goto err; |
@@ -255,8 +255,8 @@ enclosure_component_register(struct enclosure_device *edev, | |||
255 | ecomp->number = number; | 255 | ecomp->number = number; |
256 | cdev = &ecomp->cdev; | 256 | cdev = &ecomp->cdev; |
257 | cdev->parent = get_device(&edev->edev); | 257 | cdev->parent = get_device(&edev->edev); |
258 | if (name) | 258 | if (name && name[0]) |
259 | dev_set_name(cdev, name); | 259 | dev_set_name(cdev, "%s", name); |
260 | else | 260 | else |
261 | dev_set_name(cdev, "%u", number); | 261 | dev_set_name(cdev, "%u", number); |
262 | 262 | ||
diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c index c643d0fe118f..b56d72ff06e9 100644 --- a/drivers/mmc/host/mvsdio.c +++ b/drivers/mmc/host/mvsdio.c | |||
@@ -64,6 +64,31 @@ static int mvsd_setup_data(struct mvsd_host *host, struct mmc_data *data) | |||
64 | unsigned int tmout; | 64 | unsigned int tmout; |
65 | int tmout_index; | 65 | int tmout_index; |
66 | 66 | ||
67 | /* | ||
68 | * Hardware weirdness. The FIFO_EMPTY bit of the HW_STATE | ||
69 | * register is sometimes not set before a while when some | ||
70 | * "unusual" data block sizes are used (such as with the SWITCH | ||
71 | * command), even despite the fact that the XFER_DONE interrupt | ||
72 | * was raised. And if another data transfer starts before | ||
73 | * this bit comes to good sense (which eventually happens by | ||
74 | * itself) then the new transfer simply fails with a timeout. | ||
75 | */ | ||
76 | if (!(mvsd_read(MVSD_HW_STATE) & (1 << 13))) { | ||
77 | unsigned long t = jiffies + HZ; | ||
78 | unsigned int hw_state, count = 0; | ||
79 | do { | ||
80 | if (time_after(jiffies, t)) { | ||
81 | dev_warn(host->dev, "FIFO_EMPTY bit missing\n"); | ||
82 | break; | ||
83 | } | ||
84 | hw_state = mvsd_read(MVSD_HW_STATE); | ||
85 | count++; | ||
86 | } while (!(hw_state & (1 << 13))); | ||
87 | dev_dbg(host->dev, "*** wait for FIFO_EMPTY bit " | ||
88 | "(hw=0x%04x, count=%d, jiffies=%ld)\n", | ||
89 | hw_state, count, jiffies - (t - HZ)); | ||
90 | } | ||
91 | |||
67 | /* If timeout=0 then maximum timeout index is used. */ | 92 | /* If timeout=0 then maximum timeout index is used. */ |
68 | tmout = DIV_ROUND_UP(data->timeout_ns, host->ns_per_clk); | 93 | tmout = DIV_ROUND_UP(data->timeout_ns, host->ns_per_clk); |
69 | tmout += data->timeout_clks; | 94 | tmout += data->timeout_clks; |
@@ -620,9 +645,18 @@ static void mvsd_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
620 | if (ios->bus_width == MMC_BUS_WIDTH_4) | 645 | if (ios->bus_width == MMC_BUS_WIDTH_4) |
621 | ctrl_reg |= MVSD_HOST_CTRL_DATA_WIDTH_4_BITS; | 646 | ctrl_reg |= MVSD_HOST_CTRL_DATA_WIDTH_4_BITS; |
622 | 647 | ||
648 | /* | ||
649 | * The HI_SPEED_EN bit is causing trouble with many (but not all) | ||
650 | * high speed SD, SDHC and SDIO cards. Not enabling that bit | ||
651 | * makes all cards work. So let's just ignore that bit for now | ||
652 | * and revisit this issue if problems for not enabling this bit | ||
653 | * are ever reported. | ||
654 | */ | ||
655 | #if 0 | ||
623 | if (ios->timing == MMC_TIMING_MMC_HS || | 656 | if (ios->timing == MMC_TIMING_MMC_HS || |
624 | ios->timing == MMC_TIMING_SD_HS) | 657 | ios->timing == MMC_TIMING_SD_HS) |
625 | ctrl_reg |= MVSD_HOST_CTRL_HI_SPEED_EN; | 658 | ctrl_reg |= MVSD_HOST_CTRL_HI_SPEED_EN; |
659 | #endif | ||
626 | 660 | ||
627 | host->ctrl = ctrl_reg; | 661 | host->ctrl = ctrl_reg; |
628 | mvsd_write(MVSD_HOST_CTRL, ctrl_reg); | 662 | mvsd_write(MVSD_HOST_CTRL, ctrl_reg); |
@@ -882,3 +916,4 @@ module_param(nodma, int, 0); | |||
882 | MODULE_AUTHOR("Maen Suleiman, Nicolas Pitre"); | 916 | MODULE_AUTHOR("Maen Suleiman, Nicolas Pitre"); |
883 | MODULE_DESCRIPTION("Marvell MMC,SD,SDIO Host Controller driver"); | 917 | MODULE_DESCRIPTION("Marvell MMC,SD,SDIO Host Controller driver"); |
884 | MODULE_LICENSE("GPL"); | 918 | MODULE_LICENSE("GPL"); |
919 | MODULE_ALIAS("platform:mvsdio"); | ||
diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c index b4a615c55f28..f4cbe473670e 100644 --- a/drivers/mmc/host/mxcmmc.c +++ b/drivers/mmc/host/mxcmmc.c | |||
@@ -140,6 +140,8 @@ struct mxcmci_host { | |||
140 | struct work_struct datawork; | 140 | struct work_struct datawork; |
141 | }; | 141 | }; |
142 | 142 | ||
143 | static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios); | ||
144 | |||
143 | static inline int mxcmci_use_dma(struct mxcmci_host *host) | 145 | static inline int mxcmci_use_dma(struct mxcmci_host *host) |
144 | { | 146 | { |
145 | return host->do_dma; | 147 | return host->do_dma; |
@@ -160,7 +162,7 @@ static void mxcmci_softreset(struct mxcmci_host *host) | |||
160 | writew(0xff, host->base + MMC_REG_RES_TO); | 162 | writew(0xff, host->base + MMC_REG_RES_TO); |
161 | } | 163 | } |
162 | 164 | ||
163 | static void mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) | 165 | static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) |
164 | { | 166 | { |
165 | unsigned int nob = data->blocks; | 167 | unsigned int nob = data->blocks; |
166 | unsigned int blksz = data->blksz; | 168 | unsigned int blksz = data->blksz; |
@@ -168,6 +170,7 @@ static void mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) | |||
168 | #ifdef HAS_DMA | 170 | #ifdef HAS_DMA |
169 | struct scatterlist *sg; | 171 | struct scatterlist *sg; |
170 | int i; | 172 | int i; |
173 | int ret; | ||
171 | #endif | 174 | #endif |
172 | if (data->flags & MMC_DATA_STREAM) | 175 | if (data->flags & MMC_DATA_STREAM) |
173 | nob = 0xffff; | 176 | nob = 0xffff; |
@@ -183,7 +186,7 @@ static void mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) | |||
183 | for_each_sg(data->sg, sg, data->sg_len, i) { | 186 | for_each_sg(data->sg, sg, data->sg_len, i) { |
184 | if (sg->offset & 3 || sg->length & 3) { | 187 | if (sg->offset & 3 || sg->length & 3) { |
185 | host->do_dma = 0; | 188 | host->do_dma = 0; |
186 | return; | 189 | return 0; |
187 | } | 190 | } |
188 | } | 191 | } |
189 | 192 | ||
@@ -192,23 +195,30 @@ static void mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) | |||
192 | host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, | 195 | host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, |
193 | data->sg_len, host->dma_dir); | 196 | data->sg_len, host->dma_dir); |
194 | 197 | ||
195 | imx_dma_setup_sg(host->dma, data->sg, host->dma_nents, datasize, | 198 | ret = imx_dma_setup_sg(host->dma, data->sg, host->dma_nents, |
196 | host->res->start + MMC_REG_BUFFER_ACCESS, | 199 | datasize, |
197 | DMA_MODE_READ); | 200 | host->res->start + MMC_REG_BUFFER_ACCESS, |
201 | DMA_MODE_READ); | ||
198 | } else { | 202 | } else { |
199 | host->dma_dir = DMA_TO_DEVICE; | 203 | host->dma_dir = DMA_TO_DEVICE; |
200 | host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, | 204 | host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, |
201 | data->sg_len, host->dma_dir); | 205 | data->sg_len, host->dma_dir); |
202 | 206 | ||
203 | imx_dma_setup_sg(host->dma, data->sg, host->dma_nents, datasize, | 207 | ret = imx_dma_setup_sg(host->dma, data->sg, host->dma_nents, |
204 | host->res->start + MMC_REG_BUFFER_ACCESS, | 208 | datasize, |
205 | DMA_MODE_WRITE); | 209 | host->res->start + MMC_REG_BUFFER_ACCESS, |
210 | DMA_MODE_WRITE); | ||
206 | } | 211 | } |
207 | 212 | ||
213 | if (ret) { | ||
214 | dev_err(mmc_dev(host->mmc), "failed to setup DMA : %d\n", ret); | ||
215 | return ret; | ||
216 | } | ||
208 | wmb(); | 217 | wmb(); |
209 | 218 | ||
210 | imx_dma_enable(host->dma); | 219 | imx_dma_enable(host->dma); |
211 | #endif /* HAS_DMA */ | 220 | #endif /* HAS_DMA */ |
221 | return 0; | ||
212 | } | 222 | } |
213 | 223 | ||
214 | static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd, | 224 | static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd, |
@@ -345,8 +355,11 @@ static int mxcmci_poll_status(struct mxcmci_host *host, u32 mask) | |||
345 | stat = readl(host->base + MMC_REG_STATUS); | 355 | stat = readl(host->base + MMC_REG_STATUS); |
346 | if (stat & STATUS_ERR_MASK) | 356 | if (stat & STATUS_ERR_MASK) |
347 | return stat; | 357 | return stat; |
348 | if (time_after(jiffies, timeout)) | 358 | if (time_after(jiffies, timeout)) { |
359 | mxcmci_softreset(host); | ||
360 | mxcmci_set_clk_rate(host, host->clock); | ||
349 | return STATUS_TIME_OUT_READ; | 361 | return STATUS_TIME_OUT_READ; |
362 | } | ||
350 | if (stat & mask) | 363 | if (stat & mask) |
351 | return 0; | 364 | return 0; |
352 | cpu_relax(); | 365 | cpu_relax(); |
@@ -531,6 +544,7 @@ static void mxcmci_request(struct mmc_host *mmc, struct mmc_request *req) | |||
531 | { | 544 | { |
532 | struct mxcmci_host *host = mmc_priv(mmc); | 545 | struct mxcmci_host *host = mmc_priv(mmc); |
533 | unsigned int cmdat = host->cmdat; | 546 | unsigned int cmdat = host->cmdat; |
547 | int error; | ||
534 | 548 | ||
535 | WARN_ON(host->req != NULL); | 549 | WARN_ON(host->req != NULL); |
536 | 550 | ||
@@ -540,7 +554,12 @@ static void mxcmci_request(struct mmc_host *mmc, struct mmc_request *req) | |||
540 | host->do_dma = 1; | 554 | host->do_dma = 1; |
541 | #endif | 555 | #endif |
542 | if (req->data) { | 556 | if (req->data) { |
543 | mxcmci_setup_data(host, req->data); | 557 | error = mxcmci_setup_data(host, req->data); |
558 | if (error) { | ||
559 | req->cmd->error = error; | ||
560 | goto out; | ||
561 | } | ||
562 | |||
544 | 563 | ||
545 | cmdat |= CMD_DAT_CONT_DATA_ENABLE; | 564 | cmdat |= CMD_DAT_CONT_DATA_ENABLE; |
546 | 565 | ||
@@ -548,7 +567,9 @@ static void mxcmci_request(struct mmc_host *mmc, struct mmc_request *req) | |||
548 | cmdat |= CMD_DAT_CONT_WRITE; | 567 | cmdat |= CMD_DAT_CONT_WRITE; |
549 | } | 568 | } |
550 | 569 | ||
551 | if (mxcmci_start_cmd(host, req->cmd, cmdat)) | 570 | error = mxcmci_start_cmd(host, req->cmd, cmdat); |
571 | out: | ||
572 | if (error) | ||
552 | mxcmci_finish_request(host, req); | 573 | mxcmci_finish_request(host, req); |
553 | } | 574 | } |
554 | 575 | ||
@@ -724,7 +745,9 @@ static int mxcmci_probe(struct platform_device *pdev) | |||
724 | goto out_clk_put; | 745 | goto out_clk_put; |
725 | } | 746 | } |
726 | 747 | ||
727 | mmc->f_min = clk_get_rate(host->clk) >> 7; | 748 | mmc->f_min = clk_get_rate(host->clk) >> 16; |
749 | if (mmc->f_min < 400000) | ||
750 | mmc->f_min = 400000; | ||
728 | mmc->f_max = clk_get_rate(host->clk) >> 1; | 751 | mmc->f_max = clk_get_rate(host->clk) >> 1; |
729 | 752 | ||
730 | /* recommended in data sheet */ | 753 | /* recommended in data sheet */ |
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c index bfa25c01c872..dceb5ee3bda0 100644 --- a/drivers/mmc/host/omap.c +++ b/drivers/mmc/host/omap.c | |||
@@ -822,7 +822,7 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id) | |||
822 | del_timer(&host->cmd_abort_timer); | 822 | del_timer(&host->cmd_abort_timer); |
823 | host->abort = 1; | 823 | host->abort = 1; |
824 | OMAP_MMC_WRITE(host, IE, 0); | 824 | OMAP_MMC_WRITE(host, IE, 0); |
825 | disable_irq(host->irq); | 825 | disable_irq_nosync(host->irq); |
826 | schedule_work(&host->cmd_abort_work); | 826 | schedule_work(&host->cmd_abort_work); |
827 | return IRQ_HANDLED; | 827 | return IRQ_HANDLED; |
828 | } | 828 | } |
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index e62a22a7f00c..c40cb96255a2 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c | |||
@@ -680,7 +680,7 @@ static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data) | |||
680 | host->dma_ch = -1; | 680 | host->dma_ch = -1; |
681 | /* | 681 | /* |
682 | * DMA Callback: run in interrupt context. | 682 | * DMA Callback: run in interrupt context. |
683 | * mutex_unlock will through a kernel warning if used. | 683 | * mutex_unlock will throw a kernel warning if used. |
684 | */ | 684 | */ |
685 | up(&host->sem); | 685 | up(&host->sem); |
686 | } | 686 | } |
diff --git a/drivers/mmc/host/sdhci-of.c b/drivers/mmc/host/sdhci-of.c index 3ff4ac3abe8b..128c614d11aa 100644 --- a/drivers/mmc/host/sdhci-of.c +++ b/drivers/mmc/host/sdhci-of.c | |||
@@ -55,7 +55,13 @@ static u32 esdhc_readl(struct sdhci_host *host, int reg) | |||
55 | 55 | ||
56 | static u16 esdhc_readw(struct sdhci_host *host, int reg) | 56 | static u16 esdhc_readw(struct sdhci_host *host, int reg) |
57 | { | 57 | { |
58 | return in_be16(host->ioaddr + (reg ^ 0x2)); | 58 | u16 ret; |
59 | |||
60 | if (unlikely(reg == SDHCI_HOST_VERSION)) | ||
61 | ret = in_be16(host->ioaddr + reg); | ||
62 | else | ||
63 | ret = in_be16(host->ioaddr + (reg ^ 0x2)); | ||
64 | return ret; | ||
59 | } | 65 | } |
60 | 66 | ||
61 | static u8 esdhc_readb(struct sdhci_host *host, int reg) | 67 | static u8 esdhc_readb(struct sdhci_host *host, int reg) |
@@ -277,6 +283,7 @@ static int __devexit sdhci_of_remove(struct of_device *ofdev) | |||
277 | static const struct of_device_id sdhci_of_match[] = { | 283 | static const struct of_device_id sdhci_of_match[] = { |
278 | { .compatible = "fsl,mpc8379-esdhc", .data = &sdhci_esdhc, }, | 284 | { .compatible = "fsl,mpc8379-esdhc", .data = &sdhci_esdhc, }, |
279 | { .compatible = "fsl,mpc8536-esdhc", .data = &sdhci_esdhc, }, | 285 | { .compatible = "fsl,mpc8536-esdhc", .data = &sdhci_esdhc, }, |
286 | { .compatible = "fsl,esdhc", .data = &sdhci_esdhc, }, | ||
280 | { .compatible = "generic-sdhci", }, | 287 | { .compatible = "generic-sdhci", }, |
281 | {}, | 288 | {}, |
282 | }; | 289 | }; |
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c index 0119220de7d0..02700f769b8a 100644 --- a/drivers/mtd/nand/davinci_nand.c +++ b/drivers/mtd/nand/davinci_nand.c | |||
@@ -407,16 +407,17 @@ static int __init nand_davinci_probe(struct platform_device *pdev) | |||
407 | } | 407 | } |
408 | info->chip.ecc.mode = ecc_mode; | 408 | info->chip.ecc.mode = ecc_mode; |
409 | 409 | ||
410 | info->clk = clk_get(&pdev->dev, "AEMIFCLK"); | 410 | info->clk = clk_get(&pdev->dev, "aemif"); |
411 | if (IS_ERR(info->clk)) { | 411 | if (IS_ERR(info->clk)) { |
412 | ret = PTR_ERR(info->clk); | 412 | ret = PTR_ERR(info->clk); |
413 | dev_dbg(&pdev->dev, "unable to get AEMIFCLK, err %d\n", ret); | 413 | dev_dbg(&pdev->dev, "unable to get AEMIF clock, err %d\n", ret); |
414 | goto err_clk; | 414 | goto err_clk; |
415 | } | 415 | } |
416 | 416 | ||
417 | ret = clk_enable(info->clk); | 417 | ret = clk_enable(info->clk); |
418 | if (ret < 0) { | 418 | if (ret < 0) { |
419 | dev_dbg(&pdev->dev, "unable to enable AEMIFCLK, err %d\n", ret); | 419 | dev_dbg(&pdev->dev, "unable to enable AEMIF clock, err %d\n", |
420 | ret); | ||
420 | goto err_clk_enable; | 421 | goto err_clk_enable; |
421 | } | 422 | } |
422 | 423 | ||
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index f3548d048014..40c26080ecda 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c | |||
@@ -831,6 +831,7 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command, | |||
831 | break; | 831 | break; |
832 | 832 | ||
833 | case NAND_CMD_READID: | 833 | case NAND_CMD_READID: |
834 | host->col_addr = 0; | ||
834 | send_read_id(host); | 835 | send_read_id(host); |
835 | break; | 836 | break; |
836 | 837 | ||
@@ -867,6 +868,7 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
867 | mtd->priv = this; | 868 | mtd->priv = this; |
868 | mtd->owner = THIS_MODULE; | 869 | mtd->owner = THIS_MODULE; |
869 | mtd->dev.parent = &pdev->dev; | 870 | mtd->dev.parent = &pdev->dev; |
871 | mtd->name = "mxc_nand"; | ||
870 | 872 | ||
871 | /* 50 us command delay time */ | 873 | /* 50 us command delay time */ |
872 | this->chip_delay = 5; | 874 | this->chip_delay = 5; |
@@ -882,8 +884,10 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
882 | this->verify_buf = mxc_nand_verify_buf; | 884 | this->verify_buf = mxc_nand_verify_buf; |
883 | 885 | ||
884 | host->clk = clk_get(&pdev->dev, "nfc"); | 886 | host->clk = clk_get(&pdev->dev, "nfc"); |
885 | if (IS_ERR(host->clk)) | 887 | if (IS_ERR(host->clk)) { |
888 | err = PTR_ERR(host->clk); | ||
886 | goto eclk; | 889 | goto eclk; |
890 | } | ||
887 | 891 | ||
888 | clk_enable(host->clk); | 892 | clk_enable(host->clk); |
889 | host->clk_act = 1; | 893 | host->clk_act = 1; |
@@ -896,7 +900,7 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
896 | 900 | ||
897 | host->regs = ioremap(res->start, res->end - res->start + 1); | 901 | host->regs = ioremap(res->start, res->end - res->start + 1); |
898 | if (!host->regs) { | 902 | if (!host->regs) { |
899 | err = -EIO; | 903 | err = -ENOMEM; |
900 | goto eres; | 904 | goto eres; |
901 | } | 905 | } |
902 | 906 | ||
@@ -1011,30 +1015,35 @@ static int __devexit mxcnd_remove(struct platform_device *pdev) | |||
1011 | #ifdef CONFIG_PM | 1015 | #ifdef CONFIG_PM |
1012 | static int mxcnd_suspend(struct platform_device *pdev, pm_message_t state) | 1016 | static int mxcnd_suspend(struct platform_device *pdev, pm_message_t state) |
1013 | { | 1017 | { |
1014 | struct mtd_info *info = platform_get_drvdata(pdev); | 1018 | struct mtd_info *mtd = platform_get_drvdata(pdev); |
1019 | struct nand_chip *nand_chip = mtd->priv; | ||
1020 | struct mxc_nand_host *host = nand_chip->priv; | ||
1015 | int ret = 0; | 1021 | int ret = 0; |
1016 | 1022 | ||
1017 | DEBUG(MTD_DEBUG_LEVEL0, "MXC_ND : NAND suspend\n"); | 1023 | DEBUG(MTD_DEBUG_LEVEL0, "MXC_ND : NAND suspend\n"); |
1018 | if (info) | 1024 | if (mtd) { |
1019 | ret = info->suspend(info); | 1025 | ret = mtd->suspend(mtd); |
1020 | 1026 | /* Disable the NFC clock */ | |
1021 | /* Disable the NFC clock */ | 1027 | clk_disable(host->clk); |
1022 | clk_disable(nfc_clk); /* FIXME */ | 1028 | } |
1023 | 1029 | ||
1024 | return ret; | 1030 | return ret; |
1025 | } | 1031 | } |
1026 | 1032 | ||
1027 | static int mxcnd_resume(struct platform_device *pdev) | 1033 | static int mxcnd_resume(struct platform_device *pdev) |
1028 | { | 1034 | { |
1029 | struct mtd_info *info = platform_get_drvdata(pdev); | 1035 | struct mtd_info *mtd = platform_get_drvdata(pdev); |
1036 | struct nand_chip *nand_chip = mtd->priv; | ||
1037 | struct mxc_nand_host *host = nand_chip->priv; | ||
1030 | int ret = 0; | 1038 | int ret = 0; |
1031 | 1039 | ||
1032 | DEBUG(MTD_DEBUG_LEVEL0, "MXC_ND : NAND resume\n"); | 1040 | DEBUG(MTD_DEBUG_LEVEL0, "MXC_ND : NAND resume\n"); |
1033 | /* Enable the NFC clock */ | ||
1034 | clk_enable(nfc_clk); /* FIXME */ | ||
1035 | 1041 | ||
1036 | if (info) | 1042 | if (mtd) { |
1037 | info->resume(info); | 1043 | /* Enable the NFC clock */ |
1044 | clk_enable(host->clk); | ||
1045 | mtd->resume(mtd); | ||
1046 | } | ||
1038 | 1047 | ||
1039 | return ret; | 1048 | return ret; |
1040 | } | 1049 | } |
@@ -1055,13 +1064,7 @@ static struct platform_driver mxcnd_driver = { | |||
1055 | 1064 | ||
1056 | static int __init mxc_nd_init(void) | 1065 | static int __init mxc_nd_init(void) |
1057 | { | 1066 | { |
1058 | /* Register the device driver structure. */ | 1067 | return platform_driver_probe(&mxcnd_driver, mxcnd_probe); |
1059 | pr_info("MXC MTD nand Driver\n"); | ||
1060 | if (platform_driver_probe(&mxcnd_driver, mxcnd_probe) != 0) { | ||
1061 | printk(KERN_ERR "Driver register failed for mxcnd_driver\n"); | ||
1062 | return -ENODEV; | ||
1063 | } | ||
1064 | return 0; | ||
1065 | } | 1068 | } |
1066 | 1069 | ||
1067 | static void __exit mxc_nd_cleanup(void) | 1070 | static void __exit mxc_nd_cleanup(void) |
diff --git a/drivers/net/3c509.c b/drivers/net/3c509.c index fbb371921991..682aad897081 100644 --- a/drivers/net/3c509.c +++ b/drivers/net/3c509.c | |||
@@ -480,9 +480,13 @@ static int pnp_registered; | |||
480 | 480 | ||
481 | #ifdef CONFIG_EISA | 481 | #ifdef CONFIG_EISA |
482 | static struct eisa_device_id el3_eisa_ids[] = { | 482 | static struct eisa_device_id el3_eisa_ids[] = { |
483 | { "TCM5090" }, | ||
484 | { "TCM5091" }, | ||
483 | { "TCM5092" }, | 485 | { "TCM5092" }, |
484 | { "TCM5093" }, | 486 | { "TCM5093" }, |
487 | { "TCM5094" }, | ||
485 | { "TCM5095" }, | 488 | { "TCM5095" }, |
489 | { "TCM5098" }, | ||
486 | { "" } | 490 | { "" } |
487 | }; | 491 | }; |
488 | MODULE_DEVICE_TABLE(eisa, el3_eisa_ids); | 492 | MODULE_DEVICE_TABLE(eisa, el3_eisa_ids); |
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 1fc4602a6ff2..a1c25cb4669f 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile | |||
@@ -102,7 +102,7 @@ obj-$(CONFIG_HAMACHI) += hamachi.o | |||
102 | obj-$(CONFIG_NET) += Space.o loopback.o | 102 | obj-$(CONFIG_NET) += Space.o loopback.o |
103 | obj-$(CONFIG_SEEQ8005) += seeq8005.o | 103 | obj-$(CONFIG_SEEQ8005) += seeq8005.o |
104 | obj-$(CONFIG_NET_SB1000) += sb1000.o | 104 | obj-$(CONFIG_NET_SB1000) += sb1000.o |
105 | obj-$(CONFIG_MAC8390) += mac8390.o 8390.o | 105 | obj-$(CONFIG_MAC8390) += mac8390.o |
106 | obj-$(CONFIG_APNE) += apne.o 8390.o | 106 | obj-$(CONFIG_APNE) += apne.o 8390.o |
107 | obj-$(CONFIG_PCMCIA_PCNET) += 8390.o | 107 | obj-$(CONFIG_PCMCIA_PCNET) += 8390.o |
108 | obj-$(CONFIG_HP100) += hp100.o | 108 | obj-$(CONFIG_HP100) += hp100.o |
diff --git a/drivers/net/atl1e/atl1e_main.c b/drivers/net/atl1e/atl1e_main.c index fb57b750866b..1342418fb209 100644 --- a/drivers/net/atl1e/atl1e_main.c +++ b/drivers/net/atl1e/atl1e_main.c | |||
@@ -37,6 +37,7 @@ char atl1e_driver_version[] = DRV_VERSION; | |||
37 | */ | 37 | */ |
38 | static struct pci_device_id atl1e_pci_tbl[] = { | 38 | static struct pci_device_id atl1e_pci_tbl[] = { |
39 | {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L1E)}, | 39 | {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L1E)}, |
40 | {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, 0x1066)}, | ||
40 | /* required last entry */ | 41 | /* required last entry */ |
41 | { 0 } | 42 | { 0 } |
42 | }; | 43 | }; |
diff --git a/drivers/net/atlx/atl1.c b/drivers/net/atlx/atl1.c index 0ab22540bf59..4e817126e280 100644 --- a/drivers/net/atlx/atl1.c +++ b/drivers/net/atlx/atl1.c | |||
@@ -82,6 +82,12 @@ | |||
82 | 82 | ||
83 | #include "atl1.h" | 83 | #include "atl1.h" |
84 | 84 | ||
85 | #define ATLX_DRIVER_VERSION "2.1.3" | ||
86 | MODULE_AUTHOR("Xiong Huang <xiong.huang@atheros.com>, \ | ||
87 | Chris Snook <csnook@redhat.com>, Jay Cliburn <jcliburn@gmail.com>"); | ||
88 | MODULE_LICENSE("GPL"); | ||
89 | MODULE_VERSION(ATLX_DRIVER_VERSION); | ||
90 | |||
85 | /* Temporary hack for merging atl1 and atl2 */ | 91 | /* Temporary hack for merging atl1 and atl2 */ |
86 | #include "atlx.c" | 92 | #include "atlx.c" |
87 | 93 | ||
diff --git a/drivers/net/atlx/atlx.h b/drivers/net/atlx/atlx.h index 297a03da6b7f..14054b75aa62 100644 --- a/drivers/net/atlx/atlx.h +++ b/drivers/net/atlx/atlx.h | |||
@@ -29,12 +29,6 @@ | |||
29 | #include <linux/module.h> | 29 | #include <linux/module.h> |
30 | #include <linux/types.h> | 30 | #include <linux/types.h> |
31 | 31 | ||
32 | #define ATLX_DRIVER_VERSION "2.1.3" | ||
33 | MODULE_AUTHOR("Xiong Huang <xiong.huang@atheros.com>, \ | ||
34 | Chris Snook <csnook@redhat.com>, Jay Cliburn <jcliburn@gmail.com>"); | ||
35 | MODULE_LICENSE("GPL"); | ||
36 | MODULE_VERSION(ATLX_DRIVER_VERSION); | ||
37 | |||
38 | #define ATLX_ERR_PHY 2 | 32 | #define ATLX_ERR_PHY 2 |
39 | #define ATLX_ERR_PHY_SPEED 7 | 33 | #define ATLX_ERR_PHY_SPEED 7 |
40 | #define ATLX_ERR_PHY_RES 8 | 34 | #define ATLX_ERR_PHY_RES 8 |
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c index 9f971ed6b58d..b4da18213324 100644 --- a/drivers/net/bfin_mac.c +++ b/drivers/net/bfin_mac.c | |||
@@ -979,22 +979,7 @@ static int bfin_mac_open(struct net_device *dev) | |||
979 | return 0; | 979 | return 0; |
980 | } | 980 | } |
981 | 981 | ||
982 | static const struct net_device_ops bfin_mac_netdev_ops = { | ||
983 | .ndo_open = bfin_mac_open, | ||
984 | .ndo_stop = bfin_mac_close, | ||
985 | .ndo_start_xmit = bfin_mac_hard_start_xmit, | ||
986 | .ndo_set_mac_address = bfin_mac_set_mac_address, | ||
987 | .ndo_tx_timeout = bfin_mac_timeout, | ||
988 | .ndo_set_multicast_list = bfin_mac_set_multicast_list, | ||
989 | .ndo_validate_addr = eth_validate_addr, | ||
990 | .ndo_change_mtu = eth_change_mtu, | ||
991 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
992 | .ndo_poll_controller = bfin_mac_poll, | ||
993 | #endif | ||
994 | }; | ||
995 | |||
996 | /* | 982 | /* |
997 | * | ||
998 | * this makes the board clean up everything that it can | 983 | * this makes the board clean up everything that it can |
999 | * and not talk to the outside world. Caused by | 984 | * and not talk to the outside world. Caused by |
1000 | * an 'ifconfig ethX down' | 985 | * an 'ifconfig ethX down' |
@@ -1019,6 +1004,20 @@ static int bfin_mac_close(struct net_device *dev) | |||
1019 | return 0; | 1004 | return 0; |
1020 | } | 1005 | } |
1021 | 1006 | ||
1007 | static const struct net_device_ops bfin_mac_netdev_ops = { | ||
1008 | .ndo_open = bfin_mac_open, | ||
1009 | .ndo_stop = bfin_mac_close, | ||
1010 | .ndo_start_xmit = bfin_mac_hard_start_xmit, | ||
1011 | .ndo_set_mac_address = bfin_mac_set_mac_address, | ||
1012 | .ndo_tx_timeout = bfin_mac_timeout, | ||
1013 | .ndo_set_multicast_list = bfin_mac_set_multicast_list, | ||
1014 | .ndo_validate_addr = eth_validate_addr, | ||
1015 | .ndo_change_mtu = eth_change_mtu, | ||
1016 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
1017 | .ndo_poll_controller = bfin_mac_poll, | ||
1018 | #endif | ||
1019 | }; | ||
1020 | |||
1022 | static int __devinit bfin_mac_probe(struct platform_device *pdev) | 1021 | static int __devinit bfin_mac_probe(struct platform_device *pdev) |
1023 | { | 1022 | { |
1024 | struct net_device *ndev; | 1023 | struct net_device *ndev; |
diff --git a/drivers/net/cxgb3/adapter.h b/drivers/net/cxgb3/adapter.h index 714df2b675e6..c888e97c9671 100644 --- a/drivers/net/cxgb3/adapter.h +++ b/drivers/net/cxgb3/adapter.h | |||
@@ -85,8 +85,8 @@ struct fl_pg_chunk { | |||
85 | struct page *page; | 85 | struct page *page; |
86 | void *va; | 86 | void *va; |
87 | unsigned int offset; | 87 | unsigned int offset; |
88 | u64 *p_cnt; | 88 | unsigned long *p_cnt; |
89 | DECLARE_PCI_UNMAP_ADDR(mapping); | 89 | dma_addr_t mapping; |
90 | }; | 90 | }; |
91 | 91 | ||
92 | struct rx_desc; | 92 | struct rx_desc; |
diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c index 7ea48414c6cb..17858b9a5830 100644 --- a/drivers/net/cxgb3/cxgb3_main.c +++ b/drivers/net/cxgb3/cxgb3_main.c | |||
@@ -2496,14 +2496,16 @@ static void check_link_status(struct adapter *adapter) | |||
2496 | for_each_port(adapter, i) { | 2496 | for_each_port(adapter, i) { |
2497 | struct net_device *dev = adapter->port[i]; | 2497 | struct net_device *dev = adapter->port[i]; |
2498 | struct port_info *p = netdev_priv(dev); | 2498 | struct port_info *p = netdev_priv(dev); |
2499 | int link_fault; | ||
2499 | 2500 | ||
2500 | spin_lock_irq(&adapter->work_lock); | 2501 | spin_lock_irq(&adapter->work_lock); |
2501 | if (p->link_fault) { | 2502 | link_fault = p->link_fault; |
2503 | spin_unlock_irq(&adapter->work_lock); | ||
2504 | |||
2505 | if (link_fault) { | ||
2502 | t3_link_fault(adapter, i); | 2506 | t3_link_fault(adapter, i); |
2503 | spin_unlock_irq(&adapter->work_lock); | ||
2504 | continue; | 2507 | continue; |
2505 | } | 2508 | } |
2506 | spin_unlock_irq(&adapter->work_lock); | ||
2507 | 2509 | ||
2508 | if (!(p->phy.caps & SUPPORTED_IRQ) && netif_running(dev)) { | 2510 | if (!(p->phy.caps & SUPPORTED_IRQ) && netif_running(dev)) { |
2509 | t3_xgm_intr_disable(adapter, i); | 2511 | t3_xgm_intr_disable(adapter, i); |
diff --git a/drivers/net/cxgb3/sge.c b/drivers/net/cxgb3/sge.c index 26d3587f3399..b3ee2bc1a005 100644 --- a/drivers/net/cxgb3/sge.c +++ b/drivers/net/cxgb3/sge.c | |||
@@ -355,7 +355,7 @@ static void clear_rx_desc(struct pci_dev *pdev, const struct sge_fl *q, | |||
355 | (*d->pg_chunk.p_cnt)--; | 355 | (*d->pg_chunk.p_cnt)--; |
356 | if (!*d->pg_chunk.p_cnt) | 356 | if (!*d->pg_chunk.p_cnt) |
357 | pci_unmap_page(pdev, | 357 | pci_unmap_page(pdev, |
358 | pci_unmap_addr(&d->pg_chunk, mapping), | 358 | d->pg_chunk.mapping, |
359 | q->alloc_size, PCI_DMA_FROMDEVICE); | 359 | q->alloc_size, PCI_DMA_FROMDEVICE); |
360 | 360 | ||
361 | put_page(d->pg_chunk.page); | 361 | put_page(d->pg_chunk.page); |
@@ -454,7 +454,7 @@ static int alloc_pg_chunk(struct adapter *adapter, struct sge_fl *q, | |||
454 | q->pg_chunk.offset = 0; | 454 | q->pg_chunk.offset = 0; |
455 | mapping = pci_map_page(adapter->pdev, q->pg_chunk.page, | 455 | mapping = pci_map_page(adapter->pdev, q->pg_chunk.page, |
456 | 0, q->alloc_size, PCI_DMA_FROMDEVICE); | 456 | 0, q->alloc_size, PCI_DMA_FROMDEVICE); |
457 | pci_unmap_addr_set(&q->pg_chunk, mapping, mapping); | 457 | q->pg_chunk.mapping = mapping; |
458 | } | 458 | } |
459 | sd->pg_chunk = q->pg_chunk; | 459 | sd->pg_chunk = q->pg_chunk; |
460 | 460 | ||
@@ -511,8 +511,7 @@ static int refill_fl(struct adapter *adap, struct sge_fl *q, int n, gfp_t gfp) | |||
511 | nomem: q->alloc_failed++; | 511 | nomem: q->alloc_failed++; |
512 | break; | 512 | break; |
513 | } | 513 | } |
514 | mapping = pci_unmap_addr(&sd->pg_chunk, mapping) + | 514 | mapping = sd->pg_chunk.mapping + sd->pg_chunk.offset; |
515 | sd->pg_chunk.offset; | ||
516 | pci_unmap_addr_set(sd, dma_addr, mapping); | 515 | pci_unmap_addr_set(sd, dma_addr, mapping); |
517 | 516 | ||
518 | add_one_rx_chunk(mapping, d, q->gen); | 517 | add_one_rx_chunk(mapping, d, q->gen); |
@@ -881,7 +880,7 @@ recycle: | |||
881 | (*sd->pg_chunk.p_cnt)--; | 880 | (*sd->pg_chunk.p_cnt)--; |
882 | if (!*sd->pg_chunk.p_cnt) | 881 | if (!*sd->pg_chunk.p_cnt) |
883 | pci_unmap_page(adap->pdev, | 882 | pci_unmap_page(adap->pdev, |
884 | pci_unmap_addr(&sd->pg_chunk, mapping), | 883 | sd->pg_chunk.mapping, |
885 | fl->alloc_size, | 884 | fl->alloc_size, |
886 | PCI_DMA_FROMDEVICE); | 885 | PCI_DMA_FROMDEVICE); |
887 | if (!skb) { | 886 | if (!skb) { |
@@ -2096,7 +2095,7 @@ static void lro_add_page(struct adapter *adap, struct sge_qset *qs, | |||
2096 | (*sd->pg_chunk.p_cnt)--; | 2095 | (*sd->pg_chunk.p_cnt)--; |
2097 | if (!*sd->pg_chunk.p_cnt) | 2096 | if (!*sd->pg_chunk.p_cnt) |
2098 | pci_unmap_page(adap->pdev, | 2097 | pci_unmap_page(adap->pdev, |
2099 | pci_unmap_addr(&sd->pg_chunk, mapping), | 2098 | sd->pg_chunk.mapping, |
2100 | fl->alloc_size, | 2099 | fl->alloc_size, |
2101 | PCI_DMA_FROMDEVICE); | 2100 | PCI_DMA_FROMDEVICE); |
2102 | 2101 | ||
diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c index 4f68aeb2679a..4950d5d789ae 100644 --- a/drivers/net/cxgb3/t3_hw.c +++ b/drivers/net/cxgb3/t3_hw.c | |||
@@ -1274,6 +1274,11 @@ void t3_link_fault(struct adapter *adapter, int port_id) | |||
1274 | A_XGM_INT_STATUS + mac->offset); | 1274 | A_XGM_INT_STATUS + mac->offset); |
1275 | link_fault &= F_LINKFAULTCHANGE; | 1275 | link_fault &= F_LINKFAULTCHANGE; |
1276 | 1276 | ||
1277 | link_ok = lc->link_ok; | ||
1278 | speed = lc->speed; | ||
1279 | duplex = lc->duplex; | ||
1280 | fc = lc->fc; | ||
1281 | |||
1277 | phy->ops->get_link_status(phy, &link_ok, &speed, &duplex, &fc); | 1282 | phy->ops->get_link_status(phy, &link_ok, &speed, &duplex, &fc); |
1278 | 1283 | ||
1279 | if (link_fault) { | 1284 | if (link_fault) { |
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c index b1419e21b46b..fffb006b7d95 100644 --- a/drivers/net/e1000/e1000_main.c +++ b/drivers/net/e1000/e1000_main.c | |||
@@ -4027,8 +4027,9 @@ static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, | |||
4027 | PCI_DMA_FROMDEVICE); | 4027 | PCI_DMA_FROMDEVICE); |
4028 | 4028 | ||
4029 | length = le16_to_cpu(rx_desc->length); | 4029 | length = le16_to_cpu(rx_desc->length); |
4030 | 4030 | /* !EOP means multiple descriptors were used to store a single | |
4031 | if (unlikely(!(status & E1000_RXD_STAT_EOP))) { | 4031 | * packet, also make sure the frame isn't just CRC only */ |
4032 | if (unlikely(!(status & E1000_RXD_STAT_EOP) || (length <= 4))) { | ||
4032 | /* All receives must fit into a single buffer */ | 4033 | /* All receives must fit into a single buffer */ |
4033 | E1000_DBG("%s: Receive packet consumed multiple" | 4034 | E1000_DBG("%s: Receive packet consumed multiple" |
4034 | " buffers\n", netdev->name); | 4035 | " buffers\n", netdev->name); |
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c index f9a846b1b92f..9f6a68fb7b45 100644 --- a/drivers/net/forcedeth.c +++ b/drivers/net/forcedeth.c | |||
@@ -897,6 +897,12 @@ enum { | |||
897 | }; | 897 | }; |
898 | static int phy_cross = NV_CROSSOVER_DETECTION_DISABLED; | 898 | static int phy_cross = NV_CROSSOVER_DETECTION_DISABLED; |
899 | 899 | ||
900 | /* | ||
901 | * Power down phy when interface is down (persists through reboot; | ||
902 | * older Linux and other OSes may not power it up again) | ||
903 | */ | ||
904 | static int phy_power_down = 0; | ||
905 | |||
900 | static inline struct fe_priv *get_nvpriv(struct net_device *dev) | 906 | static inline struct fe_priv *get_nvpriv(struct net_device *dev) |
901 | { | 907 | { |
902 | return netdev_priv(dev); | 908 | return netdev_priv(dev); |
@@ -1485,7 +1491,10 @@ static int phy_init(struct net_device *dev) | |||
1485 | 1491 | ||
1486 | /* restart auto negotiation, power down phy */ | 1492 | /* restart auto negotiation, power down phy */ |
1487 | mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); | 1493 | mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
1488 | mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE | BMCR_PDOWN); | 1494 | mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE); |
1495 | if (phy_power_down) { | ||
1496 | mii_control |= BMCR_PDOWN; | ||
1497 | } | ||
1489 | if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) { | 1498 | if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) { |
1490 | return PHY_ERROR; | 1499 | return PHY_ERROR; |
1491 | } | 1500 | } |
@@ -5513,7 +5522,7 @@ static int nv_close(struct net_device *dev) | |||
5513 | 5522 | ||
5514 | nv_drain_rxtx(dev); | 5523 | nv_drain_rxtx(dev); |
5515 | 5524 | ||
5516 | if (np->wolenabled) { | 5525 | if (np->wolenabled || !phy_power_down) { |
5517 | writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags); | 5526 | writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags); |
5518 | nv_start_rx(dev); | 5527 | nv_start_rx(dev); |
5519 | } else { | 5528 | } else { |
@@ -6367,6 +6376,8 @@ module_param(dma_64bit, int, 0); | |||
6367 | MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0."); | 6376 | MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0."); |
6368 | module_param(phy_cross, int, 0); | 6377 | module_param(phy_cross, int, 0); |
6369 | MODULE_PARM_DESC(phy_cross, "Phy crossover detection for Realtek 8201 phy is enabled by setting to 1 and disabled by setting to 0."); | 6378 | MODULE_PARM_DESC(phy_cross, "Phy crossover detection for Realtek 8201 phy is enabled by setting to 1 and disabled by setting to 0."); |
6379 | module_param(phy_power_down, int, 0); | ||
6380 | MODULE_PARM_DESC(phy_power_down, "Power down phy and disable link when interface is down (1), or leave phy powered up (0)."); | ||
6370 | 6381 | ||
6371 | MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>"); | 6382 | MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>"); |
6372 | MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver"); | 6383 | MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver"); |
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c index b2c49679bba7..a0519184e54e 100644 --- a/drivers/net/gianfar.c +++ b/drivers/net/gianfar.c | |||
@@ -1885,8 +1885,17 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit) | |||
1885 | 1885 | ||
1886 | if (unlikely(!newskb)) | 1886 | if (unlikely(!newskb)) |
1887 | newskb = skb; | 1887 | newskb = skb; |
1888 | else if (skb) | 1888 | else if (skb) { |
1889 | /* | ||
1890 | * We need to reset ->data to what it | ||
1891 | * was before gfar_new_skb() re-aligned | ||
1892 | * it to an RXBUF_ALIGNMENT boundary | ||
1893 | * before we put the skb back on the | ||
1894 | * recycle list. | ||
1895 | */ | ||
1896 | skb->data = skb->head + NET_SKB_PAD; | ||
1889 | __skb_queue_head(&priv->rx_recycle, skb); | 1897 | __skb_queue_head(&priv->rx_recycle, skb); |
1898 | } | ||
1890 | } else { | 1899 | } else { |
1891 | /* Increment the number of packets */ | 1900 | /* Increment the number of packets */ |
1892 | dev->stats.rx_packets++; | 1901 | dev->stats.rx_packets++; |
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h index 0642d52aef5c..cf352961ae9b 100644 --- a/drivers/net/gianfar.h +++ b/drivers/net/gianfar.h | |||
@@ -259,7 +259,7 @@ extern const char gfar_driver_version[]; | |||
259 | (IEVENT_RXC | IEVENT_BSY | IEVENT_EBERR | IEVENT_MSRO | \ | 259 | (IEVENT_RXC | IEVENT_BSY | IEVENT_EBERR | IEVENT_MSRO | \ |
260 | IEVENT_BABT | IEVENT_TXC | IEVENT_TXE | IEVENT_LC \ | 260 | IEVENT_BABT | IEVENT_TXC | IEVENT_TXE | IEVENT_LC \ |
261 | | IEVENT_CRL | IEVENT_XFUN | IEVENT_DPE | IEVENT_PERR \ | 261 | | IEVENT_CRL | IEVENT_XFUN | IEVENT_DPE | IEVENT_PERR \ |
262 | | IEVENT_MAG) | 262 | | IEVENT_MAG | IEVENT_BABR) |
263 | 263 | ||
264 | #define IMASK_INIT_CLEAR 0x00000000 | 264 | #define IMASK_INIT_CLEAR 0x00000000 |
265 | #define IMASK_BABR 0x80000000 | 265 | #define IMASK_BABR 0x80000000 |
diff --git a/drivers/net/mac8390.c b/drivers/net/mac8390.c index 8e884869a05b..22e74a0e0361 100644 --- a/drivers/net/mac8390.c +++ b/drivers/net/mac8390.c | |||
@@ -304,7 +304,7 @@ struct net_device * __init mac8390_probe(int unit) | |||
304 | if (!MACH_IS_MAC) | 304 | if (!MACH_IS_MAC) |
305 | return ERR_PTR(-ENODEV); | 305 | return ERR_PTR(-ENODEV); |
306 | 306 | ||
307 | dev = alloc_ei_netdev(); | 307 | dev = ____alloc_ei_netdev(0); |
308 | if (!dev) | 308 | if (!dev) |
309 | return ERR_PTR(-ENOMEM); | 309 | return ERR_PTR(-ENOMEM); |
310 | 310 | ||
@@ -481,15 +481,15 @@ void cleanup_module(void) | |||
481 | static const struct net_device_ops mac8390_netdev_ops = { | 481 | static const struct net_device_ops mac8390_netdev_ops = { |
482 | .ndo_open = mac8390_open, | 482 | .ndo_open = mac8390_open, |
483 | .ndo_stop = mac8390_close, | 483 | .ndo_stop = mac8390_close, |
484 | .ndo_start_xmit = ei_start_xmit, | 484 | .ndo_start_xmit = __ei_start_xmit, |
485 | .ndo_tx_timeout = ei_tx_timeout, | 485 | .ndo_tx_timeout = __ei_tx_timeout, |
486 | .ndo_get_stats = ei_get_stats, | 486 | .ndo_get_stats = __ei_get_stats, |
487 | .ndo_set_multicast_list = ei_set_multicast_list, | 487 | .ndo_set_multicast_list = __ei_set_multicast_list, |
488 | .ndo_validate_addr = eth_validate_addr, | 488 | .ndo_validate_addr = eth_validate_addr, |
489 | .ndo_set_mac_address = eth_mac_addr, | 489 | .ndo_set_mac_address = eth_mac_addr, |
490 | .ndo_change_mtu = eth_change_mtu, | 490 | .ndo_change_mtu = eth_change_mtu, |
491 | #ifdef CONFIG_NET_POLL_CONTROLLER | 491 | #ifdef CONFIG_NET_POLL_CONTROLLER |
492 | .ndo_poll_controller = ei_poll, | 492 | .ndo_poll_controller = __ei_poll, |
493 | #endif | 493 | #endif |
494 | }; | 494 | }; |
495 | 495 | ||
diff --git a/drivers/net/mlx4/en_tx.c b/drivers/net/mlx4/en_tx.c index ac6fc499b280..e5c98a98ad37 100644 --- a/drivers/net/mlx4/en_tx.c +++ b/drivers/net/mlx4/en_tx.c | |||
@@ -426,7 +426,7 @@ void mlx4_en_poll_tx_cq(unsigned long data) | |||
426 | 426 | ||
427 | INC_PERF_COUNTER(priv->pstats.tx_poll); | 427 | INC_PERF_COUNTER(priv->pstats.tx_poll); |
428 | 428 | ||
429 | if (!spin_trylock(&ring->comp_lock)) { | 429 | if (!spin_trylock_irq(&ring->comp_lock)) { |
430 | mod_timer(&cq->timer, jiffies + MLX4_EN_TX_POLL_TIMEOUT); | 430 | mod_timer(&cq->timer, jiffies + MLX4_EN_TX_POLL_TIMEOUT); |
431 | return; | 431 | return; |
432 | } | 432 | } |
@@ -439,7 +439,7 @@ void mlx4_en_poll_tx_cq(unsigned long data) | |||
439 | if (inflight && priv->port_up) | 439 | if (inflight && priv->port_up) |
440 | mod_timer(&cq->timer, jiffies + MLX4_EN_TX_POLL_TIMEOUT); | 440 | mod_timer(&cq->timer, jiffies + MLX4_EN_TX_POLL_TIMEOUT); |
441 | 441 | ||
442 | spin_unlock(&ring->comp_lock); | 442 | spin_unlock_irq(&ring->comp_lock); |
443 | } | 443 | } |
444 | 444 | ||
445 | static struct mlx4_en_tx_desc *mlx4_en_bounce_to_desc(struct mlx4_en_priv *priv, | 445 | static struct mlx4_en_tx_desc *mlx4_en_bounce_to_desc(struct mlx4_en_priv *priv, |
@@ -482,9 +482,9 @@ static inline void mlx4_en_xmit_poll(struct mlx4_en_priv *priv, int tx_ind) | |||
482 | 482 | ||
483 | /* Poll the CQ every mlx4_en_TX_MODER_POLL packets */ | 483 | /* Poll the CQ every mlx4_en_TX_MODER_POLL packets */ |
484 | if ((++ring->poll_cnt & (MLX4_EN_TX_POLL_MODER - 1)) == 0) | 484 | if ((++ring->poll_cnt & (MLX4_EN_TX_POLL_MODER - 1)) == 0) |
485 | if (spin_trylock(&ring->comp_lock)) { | 485 | if (spin_trylock_irq(&ring->comp_lock)) { |
486 | mlx4_en_process_tx_cq(priv->dev, cq); | 486 | mlx4_en_process_tx_cq(priv->dev, cq); |
487 | spin_unlock(&ring->comp_lock); | 487 | spin_unlock_irq(&ring->comp_lock); |
488 | } | 488 | } |
489 | } | 489 | } |
490 | 490 | ||
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index 0b6e8c896835..3b19e0ce290f 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c | |||
@@ -66,7 +66,6 @@ static const int multicast_filter_limit = 32; | |||
66 | #define RX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ | 66 | #define RX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
67 | #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ | 67 | #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
68 | #define EarlyTxThld 0x3F /* 0x3F means NO early transmit */ | 68 | #define EarlyTxThld 0x3F /* 0x3F means NO early transmit */ |
69 | #define RxPacketMaxSize 0x3FE8 /* 16K - 1 - ETH_HLEN - VLAN - CRC... */ | ||
70 | #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */ | 69 | #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */ |
71 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ | 70 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
72 | 71 | ||
@@ -2357,10 +2356,10 @@ static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) | |||
2357 | return cmd; | 2356 | return cmd; |
2358 | } | 2357 | } |
2359 | 2358 | ||
2360 | static void rtl_set_rx_max_size(void __iomem *ioaddr) | 2359 | static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz) |
2361 | { | 2360 | { |
2362 | /* Low hurts. Let's disable the filtering. */ | 2361 | /* Low hurts. Let's disable the filtering. */ |
2363 | RTL_W16(RxMaxSize, 16383); | 2362 | RTL_W16(RxMaxSize, rx_buf_sz); |
2364 | } | 2363 | } |
2365 | 2364 | ||
2366 | static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) | 2365 | static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
@@ -2407,7 +2406,7 @@ static void rtl_hw_start_8169(struct net_device *dev) | |||
2407 | 2406 | ||
2408 | RTL_W8(EarlyTxThres, EarlyTxThld); | 2407 | RTL_W8(EarlyTxThres, EarlyTxThld); |
2409 | 2408 | ||
2410 | rtl_set_rx_max_size(ioaddr); | 2409 | rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz); |
2411 | 2410 | ||
2412 | if ((tp->mac_version == RTL_GIGA_MAC_VER_01) || | 2411 | if ((tp->mac_version == RTL_GIGA_MAC_VER_01) || |
2413 | (tp->mac_version == RTL_GIGA_MAC_VER_02) || | 2412 | (tp->mac_version == RTL_GIGA_MAC_VER_02) || |
@@ -2668,7 +2667,7 @@ static void rtl_hw_start_8168(struct net_device *dev) | |||
2668 | 2667 | ||
2669 | RTL_W8(EarlyTxThres, EarlyTxThld); | 2668 | RTL_W8(EarlyTxThres, EarlyTxThld); |
2670 | 2669 | ||
2671 | rtl_set_rx_max_size(ioaddr); | 2670 | rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz); |
2672 | 2671 | ||
2673 | tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; | 2672 | tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
2674 | 2673 | ||
@@ -2846,7 +2845,7 @@ static void rtl_hw_start_8101(struct net_device *dev) | |||
2846 | 2845 | ||
2847 | RTL_W8(EarlyTxThres, EarlyTxThld); | 2846 | RTL_W8(EarlyTxThres, EarlyTxThld); |
2848 | 2847 | ||
2849 | rtl_set_rx_max_size(ioaddr); | 2848 | rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz); |
2850 | 2849 | ||
2851 | tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; | 2850 | tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
2852 | 2851 | ||
@@ -3554,54 +3553,64 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) | |||
3554 | int handled = 0; | 3553 | int handled = 0; |
3555 | int status; | 3554 | int status; |
3556 | 3555 | ||
3556 | /* loop handling interrupts until we have no new ones or | ||
3557 | * we hit a invalid/hotplug case. | ||
3558 | */ | ||
3557 | status = RTL_R16(IntrStatus); | 3559 | status = RTL_R16(IntrStatus); |
3560 | while (status && status != 0xffff) { | ||
3561 | handled = 1; | ||
3558 | 3562 | ||
3559 | /* hotplug/major error/no more work/shared irq */ | 3563 | /* Handle all of the error cases first. These will reset |
3560 | if ((status == 0xffff) || !status) | 3564 | * the chip, so just exit the loop. |
3561 | goto out; | 3565 | */ |
3562 | 3566 | if (unlikely(!netif_running(dev))) { | |
3563 | handled = 1; | 3567 | rtl8169_asic_down(ioaddr); |
3568 | break; | ||
3569 | } | ||
3564 | 3570 | ||
3565 | if (unlikely(!netif_running(dev))) { | 3571 | /* Work around for rx fifo overflow */ |
3566 | rtl8169_asic_down(ioaddr); | 3572 | if (unlikely(status & RxFIFOOver) && |
3567 | goto out; | 3573 | (tp->mac_version == RTL_GIGA_MAC_VER_11)) { |
3568 | } | 3574 | netif_stop_queue(dev); |
3575 | rtl8169_tx_timeout(dev); | ||
3576 | break; | ||
3577 | } | ||
3569 | 3578 | ||
3570 | status &= tp->intr_mask; | 3579 | if (unlikely(status & SYSErr)) { |
3571 | RTL_W16(IntrStatus, | 3580 | rtl8169_pcierr_interrupt(dev); |
3572 | (status & RxFIFOOver) ? (status | RxOverflow) : status); | 3581 | break; |
3582 | } | ||
3573 | 3583 | ||
3574 | if (!(status & tp->intr_event)) | 3584 | if (status & LinkChg) |
3575 | goto out; | 3585 | rtl8169_check_link_status(dev, tp, ioaddr); |
3576 | 3586 | ||
3577 | /* Work around for rx fifo overflow */ | 3587 | /* We need to see the lastest version of tp->intr_mask to |
3578 | if (unlikely(status & RxFIFOOver) && | 3588 | * avoid ignoring an MSI interrupt and having to wait for |
3579 | (tp->mac_version == RTL_GIGA_MAC_VER_11)) { | 3589 | * another event which may never come. |
3580 | netif_stop_queue(dev); | 3590 | */ |
3581 | rtl8169_tx_timeout(dev); | 3591 | smp_rmb(); |
3582 | goto out; | 3592 | if (status & tp->intr_mask & tp->napi_event) { |
3583 | } | 3593 | RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event); |
3594 | tp->intr_mask = ~tp->napi_event; | ||
3595 | |||
3596 | if (likely(napi_schedule_prep(&tp->napi))) | ||
3597 | __napi_schedule(&tp->napi); | ||
3598 | else if (netif_msg_intr(tp)) { | ||
3599 | printk(KERN_INFO "%s: interrupt %04x in poll\n", | ||
3600 | dev->name, status); | ||
3601 | } | ||
3602 | } | ||
3584 | 3603 | ||
3585 | if (unlikely(status & SYSErr)) { | 3604 | /* We only get a new MSI interrupt when all active irq |
3586 | rtl8169_pcierr_interrupt(dev); | 3605 | * sources on the chip have been acknowledged. So, ack |
3587 | goto out; | 3606 | * everything we've seen and check if new sources have become |
3607 | * active to avoid blocking all interrupts from the chip. | ||
3608 | */ | ||
3609 | RTL_W16(IntrStatus, | ||
3610 | (status & RxFIFOOver) ? (status | RxOverflow) : status); | ||
3611 | status = RTL_R16(IntrStatus); | ||
3588 | } | 3612 | } |
3589 | 3613 | ||
3590 | if (status & LinkChg) | ||
3591 | rtl8169_check_link_status(dev, tp, ioaddr); | ||
3592 | |||
3593 | if (status & tp->napi_event) { | ||
3594 | RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event); | ||
3595 | tp->intr_mask = ~tp->napi_event; | ||
3596 | |||
3597 | if (likely(napi_schedule_prep(&tp->napi))) | ||
3598 | __napi_schedule(&tp->napi); | ||
3599 | else if (netif_msg_intr(tp)) { | ||
3600 | printk(KERN_INFO "%s: interrupt %04x in poll\n", | ||
3601 | dev->name, status); | ||
3602 | } | ||
3603 | } | ||
3604 | out: | ||
3605 | return IRQ_RETVAL(handled); | 3614 | return IRQ_RETVAL(handled); |
3606 | } | 3615 | } |
3607 | 3616 | ||
@@ -3617,13 +3626,15 @@ static int rtl8169_poll(struct napi_struct *napi, int budget) | |||
3617 | 3626 | ||
3618 | if (work_done < budget) { | 3627 | if (work_done < budget) { |
3619 | napi_complete(napi); | 3628 | napi_complete(napi); |
3620 | tp->intr_mask = 0xffff; | 3629 | |
3621 | /* | 3630 | /* We need for force the visibility of tp->intr_mask |
3622 | * 20040426: the barrier is not strictly required but the | 3631 | * for other CPUs, as we can loose an MSI interrupt |
3623 | * behavior of the irq handler could be less predictable | 3632 | * and potentially wait for a retransmit timeout if we don't. |
3624 | * without it. Btw, the lack of flush for the posted pci | 3633 | * The posted write to IntrMask is safe, as it will |
3625 | * write is safe - FR | 3634 | * eventually make it to the chip and we won't loose anything |
3635 | * until it does. | ||
3626 | */ | 3636 | */ |
3637 | tp->intr_mask = 0xffff; | ||
3627 | smp_wmb(); | 3638 | smp_wmb(); |
3628 | RTL_W16(IntrMask, tp->intr_event); | 3639 | RTL_W16(IntrMask, tp->intr_event); |
3629 | } | 3640 | } |
diff --git a/drivers/net/wimax/i2400m/usb.c b/drivers/net/wimax/i2400m/usb.c index ca4151a9e222..17851321b7fd 100644 --- a/drivers/net/wimax/i2400m/usb.c +++ b/drivers/net/wimax/i2400m/usb.c | |||
@@ -505,27 +505,52 @@ int i2400mu_suspend(struct usb_interface *iface, pm_message_t pm_msg) | |||
505 | #ifdef CONFIG_PM | 505 | #ifdef CONFIG_PM |
506 | struct usb_device *usb_dev = i2400mu->usb_dev; | 506 | struct usb_device *usb_dev = i2400mu->usb_dev; |
507 | #endif | 507 | #endif |
508 | unsigned is_autosuspend = 0; | ||
508 | struct i2400m *i2400m = &i2400mu->i2400m; | 509 | struct i2400m *i2400m = &i2400mu->i2400m; |
509 | 510 | ||
511 | #ifdef CONFIG_PM | ||
512 | if (usb_dev->auto_pm > 0) | ||
513 | is_autosuspend = 1; | ||
514 | #endif | ||
515 | |||
510 | d_fnstart(3, dev, "(iface %p pm_msg %u)\n", iface, pm_msg.event); | 516 | d_fnstart(3, dev, "(iface %p pm_msg %u)\n", iface, pm_msg.event); |
511 | if (i2400m->updown == 0) | 517 | if (i2400m->updown == 0) |
512 | goto no_firmware; | 518 | goto no_firmware; |
513 | d_printf(1, dev, "fw up, requesting standby\n"); | 519 | if (i2400m->state == I2400M_SS_DATA_PATH_CONNECTED && is_autosuspend) { |
520 | /* ugh -- the device is connected and this suspend | ||
521 | * request is an autosuspend one (not a system standby | ||
522 | * / hibernate). | ||
523 | * | ||
524 | * The only way the device can go to standby is if the | ||
525 | * link with the base station is in IDLE mode; that | ||
526 | * were the case, we'd be in status | ||
527 | * I2400M_SS_CONNECTED_IDLE. But we are not. | ||
528 | * | ||
529 | * If we *tell* him to go power save now, it'll reset | ||
530 | * as a precautionary measure, so if this is an | ||
531 | * autosuspend thing, say no and it'll come back | ||
532 | * later, when the link is IDLE | ||
533 | */ | ||
534 | result = -EBADF; | ||
535 | d_printf(1, dev, "fw up, link up, not-idle, autosuspend: " | ||
536 | "not entering powersave\n"); | ||
537 | goto error_not_now; | ||
538 | } | ||
539 | d_printf(1, dev, "fw up: entering powersave\n"); | ||
514 | atomic_dec(&i2400mu->do_autopm); | 540 | atomic_dec(&i2400mu->do_autopm); |
515 | result = i2400m_cmd_enter_powersave(i2400m); | 541 | result = i2400m_cmd_enter_powersave(i2400m); |
516 | atomic_inc(&i2400mu->do_autopm); | 542 | atomic_inc(&i2400mu->do_autopm); |
517 | #ifdef CONFIG_PM | 543 | if (result < 0 && !is_autosuspend) { |
518 | if (result < 0 && usb_dev->auto_pm == 0) { | ||
519 | /* System suspend, can't fail */ | 544 | /* System suspend, can't fail */ |
520 | dev_err(dev, "failed to suspend, will reset on resume\n"); | 545 | dev_err(dev, "failed to suspend, will reset on resume\n"); |
521 | result = 0; | 546 | result = 0; |
522 | } | 547 | } |
523 | #endif | ||
524 | if (result < 0) | 548 | if (result < 0) |
525 | goto error_enter_powersave; | 549 | goto error_enter_powersave; |
526 | i2400mu_notification_release(i2400mu); | 550 | i2400mu_notification_release(i2400mu); |
527 | d_printf(1, dev, "fw up, got standby\n"); | 551 | d_printf(1, dev, "powersave requested\n"); |
528 | error_enter_powersave: | 552 | error_enter_powersave: |
553 | error_not_now: | ||
529 | no_firmware: | 554 | no_firmware: |
530 | d_fnend(3, dev, "(iface %p pm_msg %u) = %d\n", | 555 | d_fnend(3, dev, "(iface %p pm_msg %u) = %d\n", |
531 | iface, pm_msg.event, result); | 556 | iface, pm_msg.event, result); |
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig index 8a0823588c51..3d94e7dfea69 100644 --- a/drivers/net/wireless/Kconfig +++ b/drivers/net/wireless/Kconfig | |||
@@ -430,6 +430,7 @@ config RTL8187 | |||
430 | ASUS P5B Deluxe | 430 | ASUS P5B Deluxe |
431 | Toshiba Satellite Pro series of laptops | 431 | Toshiba Satellite Pro series of laptops |
432 | Asus Wireless Link | 432 | Asus Wireless Link |
433 | Linksys WUSB54GC-EU | ||
433 | 434 | ||
434 | Thanks to Realtek for their support! | 435 | Thanks to Realtek for their support! |
435 | 436 | ||
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c index d73475739127..9eabf4d1f2e7 100644 --- a/drivers/net/wireless/airo.c +++ b/drivers/net/wireless/airo.c | |||
@@ -6467,6 +6467,7 @@ static int airo_get_encode(struct net_device *dev, | |||
6467 | { | 6467 | { |
6468 | struct airo_info *local = dev->ml_priv; | 6468 | struct airo_info *local = dev->ml_priv; |
6469 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; | 6469 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
6470 | int wep_key_len; | ||
6470 | u8 buf[16]; | 6471 | u8 buf[16]; |
6471 | 6472 | ||
6472 | if (!local->wep_capable) | 6473 | if (!local->wep_capable) |
@@ -6500,11 +6501,13 @@ static int airo_get_encode(struct net_device *dev, | |||
6500 | dwrq->flags |= index + 1; | 6501 | dwrq->flags |= index + 1; |
6501 | 6502 | ||
6502 | /* Copy the key to the user buffer */ | 6503 | /* Copy the key to the user buffer */ |
6503 | dwrq->length = get_wep_key(local, index, &buf[0], sizeof(buf)); | 6504 | wep_key_len = get_wep_key(local, index, &buf[0], sizeof(buf)); |
6504 | if (dwrq->length != -1) | 6505 | if (wep_key_len < 0) { |
6505 | memcpy(extra, buf, dwrq->length); | ||
6506 | else | ||
6507 | dwrq->length = 0; | 6506 | dwrq->length = 0; |
6507 | } else { | ||
6508 | dwrq->length = wep_key_len; | ||
6509 | memcpy(extra, buf, dwrq->length); | ||
6510 | } | ||
6508 | 6511 | ||
6509 | return 0; | 6512 | return 0; |
6510 | } | 6513 | } |
@@ -6617,7 +6620,7 @@ static int airo_get_encodeext(struct net_device *dev, | |||
6617 | struct airo_info *local = dev->ml_priv; | 6620 | struct airo_info *local = dev->ml_priv; |
6618 | struct iw_point *encoding = &wrqu->encoding; | 6621 | struct iw_point *encoding = &wrqu->encoding; |
6619 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | 6622 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
6620 | int idx, max_key_len; | 6623 | int idx, max_key_len, wep_key_len; |
6621 | u8 buf[16]; | 6624 | u8 buf[16]; |
6622 | 6625 | ||
6623 | if (!local->wep_capable) | 6626 | if (!local->wep_capable) |
@@ -6661,11 +6664,13 @@ static int airo_get_encodeext(struct net_device *dev, | |||
6661 | memset(extra, 0, 16); | 6664 | memset(extra, 0, 16); |
6662 | 6665 | ||
6663 | /* Copy the key to the user buffer */ | 6666 | /* Copy the key to the user buffer */ |
6664 | ext->key_len = get_wep_key(local, idx, &buf[0], sizeof(buf)); | 6667 | wep_key_len = get_wep_key(local, idx, &buf[0], sizeof(buf)); |
6665 | if (ext->key_len != -1) | 6668 | if (wep_key_len < 0) { |
6666 | memcpy(extra, buf, ext->key_len); | ||
6667 | else | ||
6668 | ext->key_len = 0; | 6669 | ext->key_len = 0; |
6670 | } else { | ||
6671 | ext->key_len = wep_key_len; | ||
6672 | memcpy(extra, buf, ext->key_len); | ||
6673 | } | ||
6669 | 6674 | ||
6670 | return 0; | 6675 | return 0; |
6671 | } | 6676 | } |
diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c index 744f4f4dd3d1..8d93ca4651b9 100644 --- a/drivers/net/wireless/at76c50x-usb.c +++ b/drivers/net/wireless/at76c50x-usb.c | |||
@@ -1873,18 +1873,18 @@ static void at76_dwork_hw_scan(struct work_struct *work) | |||
1873 | if (ret != CMD_STATUS_COMPLETE) { | 1873 | if (ret != CMD_STATUS_COMPLETE) { |
1874 | queue_delayed_work(priv->hw->workqueue, &priv->dwork_hw_scan, | 1874 | queue_delayed_work(priv->hw->workqueue, &priv->dwork_hw_scan, |
1875 | SCAN_POLL_INTERVAL); | 1875 | SCAN_POLL_INTERVAL); |
1876 | goto exit; | 1876 | mutex_unlock(&priv->mtx); |
1877 | return; | ||
1877 | } | 1878 | } |
1878 | 1879 | ||
1879 | ieee80211_scan_completed(priv->hw, false); | ||
1880 | |||
1881 | if (is_valid_ether_addr(priv->bssid)) | 1880 | if (is_valid_ether_addr(priv->bssid)) |
1882 | at76_join(priv); | 1881 | at76_join(priv); |
1883 | 1882 | ||
1884 | ieee80211_wake_queues(priv->hw); | ||
1885 | |||
1886 | exit: | ||
1887 | mutex_unlock(&priv->mtx); | 1883 | mutex_unlock(&priv->mtx); |
1884 | |||
1885 | ieee80211_scan_completed(priv->hw, false); | ||
1886 | |||
1887 | ieee80211_wake_queues(priv->hw); | ||
1888 | } | 1888 | } |
1889 | 1889 | ||
1890 | static int at76_hw_scan(struct ieee80211_hw *hw, | 1890 | static int at76_hw_scan(struct ieee80211_hw *hw, |
diff --git a/drivers/net/wireless/ath5k/phy.c b/drivers/net/wireless/ath5k/phy.c index 9e2faae5ae94..b48b29dca3d2 100644 --- a/drivers/net/wireless/ath5k/phy.c +++ b/drivers/net/wireless/ath5k/phy.c | |||
@@ -1487,28 +1487,35 @@ ath5k_get_linear_pcdac_min(const u8 *stepL, const u8 *stepR, | |||
1487 | { | 1487 | { |
1488 | s8 tmp; | 1488 | s8 tmp; |
1489 | s16 min_pwrL, min_pwrR; | 1489 | s16 min_pwrL, min_pwrR; |
1490 | s16 pwr_i = pwrL[0]; | 1490 | s16 pwr_i; |
1491 | 1491 | ||
1492 | do { | 1492 | if (pwrL[0] == pwrL[1]) |
1493 | pwr_i--; | 1493 | min_pwrL = pwrL[0]; |
1494 | tmp = (s8) ath5k_get_interpolated_value(pwr_i, | 1494 | else { |
1495 | pwrL[0], pwrL[1], | 1495 | pwr_i = pwrL[0]; |
1496 | stepL[0], stepL[1]); | 1496 | do { |
1497 | 1497 | pwr_i--; | |
1498 | } while (tmp > 1); | 1498 | tmp = (s8) ath5k_get_interpolated_value(pwr_i, |
1499 | 1499 | pwrL[0], pwrL[1], | |
1500 | min_pwrL = pwr_i; | 1500 | stepL[0], stepL[1]); |
1501 | 1501 | } while (tmp > 1); | |
1502 | pwr_i = pwrR[0]; | 1502 | |
1503 | do { | 1503 | min_pwrL = pwr_i; |
1504 | pwr_i--; | 1504 | } |
1505 | tmp = (s8) ath5k_get_interpolated_value(pwr_i, | ||
1506 | pwrR[0], pwrR[1], | ||
1507 | stepR[0], stepR[1]); | ||
1508 | |||
1509 | } while (tmp > 1); | ||
1510 | 1505 | ||
1511 | min_pwrR = pwr_i; | 1506 | if (pwrR[0] == pwrR[1]) |
1507 | min_pwrR = pwrR[0]; | ||
1508 | else { | ||
1509 | pwr_i = pwrR[0]; | ||
1510 | do { | ||
1511 | pwr_i--; | ||
1512 | tmp = (s8) ath5k_get_interpolated_value(pwr_i, | ||
1513 | pwrR[0], pwrR[1], | ||
1514 | stepR[0], stepR[1]); | ||
1515 | } while (tmp > 1); | ||
1516 | |||
1517 | min_pwrR = pwr_i; | ||
1518 | } | ||
1512 | 1519 | ||
1513 | /* Keep the right boundary so that it works for both curves */ | 1520 | /* Keep the right boundary so that it works for both curves */ |
1514 | return max(min_pwrL, min_pwrR); | 1521 | return max(min_pwrL, min_pwrR); |
diff --git a/drivers/net/wireless/ath5k/reset.c b/drivers/net/wireless/ath5k/reset.c index 7a17d31b2fd9..5f72c111c2e8 100644 --- a/drivers/net/wireless/ath5k/reset.c +++ b/drivers/net/wireless/ath5k/reset.c | |||
@@ -26,7 +26,7 @@ | |||
26 | \*****************************/ | 26 | \*****************************/ |
27 | 27 | ||
28 | #include <linux/pci.h> /* To determine if a card is pci-e */ | 28 | #include <linux/pci.h> /* To determine if a card is pci-e */ |
29 | #include <linux/bitops.h> /* For get_bitmask_order */ | 29 | #include <linux/log2.h> |
30 | #include "ath5k.h" | 30 | #include "ath5k.h" |
31 | #include "reg.h" | 31 | #include "reg.h" |
32 | #include "base.h" | 32 | #include "base.h" |
@@ -69,10 +69,10 @@ static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah, | |||
69 | 69 | ||
70 | /* Get exponent | 70 | /* Get exponent |
71 | * ALGO: coef_exp = 14 - highest set bit position */ | 71 | * ALGO: coef_exp = 14 - highest set bit position */ |
72 | coef_exp = get_bitmask_order(coef_scaled); | 72 | coef_exp = ilog2(coef_scaled); |
73 | 73 | ||
74 | /* Doesn't make sense if it's zero*/ | 74 | /* Doesn't make sense if it's zero*/ |
75 | if (!coef_exp) | 75 | if (!coef_scaled || !coef_exp) |
76 | return -EINVAL; | 76 | return -EINVAL; |
77 | 77 | ||
78 | /* Note: we've shifted coef_scaled by 24 */ | 78 | /* Note: we've shifted coef_scaled by 24 */ |
@@ -359,7 +359,7 @@ int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial) | |||
359 | mode |= AR5K_PHY_MODE_FREQ_5GHZ; | 359 | mode |= AR5K_PHY_MODE_FREQ_5GHZ; |
360 | 360 | ||
361 | if (ah->ah_radio == AR5K_RF5413) | 361 | if (ah->ah_radio == AR5K_RF5413) |
362 | clock |= AR5K_PHY_PLL_40MHZ_5413; | 362 | clock = AR5K_PHY_PLL_40MHZ_5413; |
363 | else | 363 | else |
364 | clock |= AR5K_PHY_PLL_40MHZ; | 364 | clock |= AR5K_PHY_PLL_40MHZ; |
365 | 365 | ||
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c index e5ca2511a81a..9452461ce864 100644 --- a/drivers/net/wireless/iwlwifi/iwl-5000.c +++ b/drivers/net/wireless/iwlwifi/iwl-5000.c | |||
@@ -46,7 +46,7 @@ | |||
46 | #include "iwl-6000-hw.h" | 46 | #include "iwl-6000-hw.h" |
47 | 47 | ||
48 | /* Highest firmware API version supported */ | 48 | /* Highest firmware API version supported */ |
49 | #define IWL5000_UCODE_API_MAX 1 | 49 | #define IWL5000_UCODE_API_MAX 2 |
50 | #define IWL5150_UCODE_API_MAX 2 | 50 | #define IWL5150_UCODE_API_MAX 2 |
51 | 51 | ||
52 | /* Lowest firmware API version supported */ | 52 | /* Lowest firmware API version supported */ |
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c index 3bb28db4a40f..f46ba2475776 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn.c | |||
@@ -669,13 +669,6 @@ static int iwl_set_mode(struct iwl_priv *priv, int mode) | |||
669 | if (!iwl_is_ready_rf(priv)) | 669 | if (!iwl_is_ready_rf(priv)) |
670 | return -EAGAIN; | 670 | return -EAGAIN; |
671 | 671 | ||
672 | cancel_delayed_work(&priv->scan_check); | ||
673 | if (iwl_scan_cancel_timeout(priv, 100)) { | ||
674 | IWL_WARN(priv, "Aborted scan still in progress after 100ms\n"); | ||
675 | IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n"); | ||
676 | return -EAGAIN; | ||
677 | } | ||
678 | |||
679 | iwl_commit_rxon(priv); | 672 | iwl_commit_rxon(priv); |
680 | 673 | ||
681 | return 0; | 674 | return 0; |
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c index e7c65c4f741b..6330b91e37ce 100644 --- a/drivers/net/wireless/iwlwifi/iwl-scan.c +++ b/drivers/net/wireless/iwlwifi/iwl-scan.c | |||
@@ -227,9 +227,6 @@ static void iwl_rx_scan_complete_notif(struct iwl_priv *priv, | |||
227 | /* The HW is no longer scanning */ | 227 | /* The HW is no longer scanning */ |
228 | clear_bit(STATUS_SCAN_HW, &priv->status); | 228 | clear_bit(STATUS_SCAN_HW, &priv->status); |
229 | 229 | ||
230 | /* The scan completion notification came in, so kill that timer... */ | ||
231 | cancel_delayed_work(&priv->scan_check); | ||
232 | |||
233 | IWL_DEBUG_INFO(priv, "Scan pass on %sGHz took %dms\n", | 230 | IWL_DEBUG_INFO(priv, "Scan pass on %sGHz took %dms\n", |
234 | (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ? | 231 | (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ? |
235 | "2.4" : "5.2", | 232 | "2.4" : "5.2", |
@@ -712,6 +709,8 @@ static void iwl_bg_request_scan(struct work_struct *data) | |||
712 | 709 | ||
713 | mutex_lock(&priv->mutex); | 710 | mutex_lock(&priv->mutex); |
714 | 711 | ||
712 | cancel_delayed_work(&priv->scan_check); | ||
713 | |||
715 | if (!iwl_is_ready(priv)) { | 714 | if (!iwl_is_ready(priv)) { |
716 | IWL_WARN(priv, "request scan called when driver not ready.\n"); | 715 | IWL_WARN(priv, "request scan called when driver not ready.\n"); |
717 | goto done; | 716 | goto done; |
@@ -925,6 +924,8 @@ void iwl_bg_scan_completed(struct work_struct *work) | |||
925 | 924 | ||
926 | IWL_DEBUG_SCAN(priv, "SCAN complete scan\n"); | 925 | IWL_DEBUG_SCAN(priv, "SCAN complete scan\n"); |
927 | 926 | ||
927 | cancel_delayed_work(&priv->scan_check); | ||
928 | |||
928 | ieee80211_scan_completed(priv->hw, false); | 929 | ieee80211_scan_completed(priv->hw, false); |
929 | 930 | ||
930 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | 931 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c index 4cce66133500..ff4d0e41d7c4 100644 --- a/drivers/net/wireless/iwlwifi/iwl3945-base.c +++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c | |||
@@ -782,13 +782,6 @@ static int iwl3945_set_mode(struct iwl_priv *priv, int mode) | |||
782 | if (!iwl_is_ready_rf(priv)) | 782 | if (!iwl_is_ready_rf(priv)) |
783 | return -EAGAIN; | 783 | return -EAGAIN; |
784 | 784 | ||
785 | cancel_delayed_work(&priv->scan_check); | ||
786 | if (iwl_scan_cancel_timeout(priv, 100)) { | ||
787 | IWL_WARN(priv, "Aborted scan still in progress after 100ms\n"); | ||
788 | IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n"); | ||
789 | return -EAGAIN; | ||
790 | } | ||
791 | |||
792 | iwl3945_commit_rxon(priv); | 785 | iwl3945_commit_rxon(priv); |
793 | 786 | ||
794 | return 0; | 787 | return 0; |
@@ -3298,6 +3291,8 @@ static void iwl3945_bg_request_scan(struct work_struct *data) | |||
3298 | 3291 | ||
3299 | mutex_lock(&priv->mutex); | 3292 | mutex_lock(&priv->mutex); |
3300 | 3293 | ||
3294 | cancel_delayed_work(&priv->scan_check); | ||
3295 | |||
3301 | if (!iwl_is_ready(priv)) { | 3296 | if (!iwl_is_ready(priv)) { |
3302 | IWL_WARN(priv, "request scan called when driver not ready.\n"); | 3297 | IWL_WARN(priv, "request scan called when driver not ready.\n"); |
3303 | goto done; | 3298 | goto done; |
diff --git a/drivers/net/wireless/rt2x00/rt2x00debug.c b/drivers/net/wireless/rt2x00/rt2x00debug.c index 07d378ef0b46..7b3ee8c2eaef 100644 --- a/drivers/net/wireless/rt2x00/rt2x00debug.c +++ b/drivers/net/wireless/rt2x00/rt2x00debug.c | |||
@@ -138,7 +138,7 @@ void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev, | |||
138 | 138 | ||
139 | if (cipher == CIPHER_TKIP_NO_MIC) | 139 | if (cipher == CIPHER_TKIP_NO_MIC) |
140 | cipher = CIPHER_TKIP; | 140 | cipher = CIPHER_TKIP; |
141 | if (cipher == CIPHER_NONE || cipher > CIPHER_MAX) | 141 | if (cipher == CIPHER_NONE || cipher >= CIPHER_MAX) |
142 | return; | 142 | return; |
143 | 143 | ||
144 | /* Remove CIPHER_NONE index */ | 144 | /* Remove CIPHER_NONE index */ |
diff --git a/drivers/net/wireless/rtl818x/rtl8187_dev.c b/drivers/net/wireless/rtl818x/rtl8187_dev.c index bac6cfba6abd..d51ba0a88c23 100644 --- a/drivers/net/wireless/rtl818x/rtl8187_dev.c +++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c | |||
@@ -71,6 +71,8 @@ static struct usb_device_id rtl8187_table[] __devinitdata = { | |||
71 | {USB_DEVICE(0x18E8, 0x6232), .driver_info = DEVICE_RTL8187}, | 71 | {USB_DEVICE(0x18E8, 0x6232), .driver_info = DEVICE_RTL8187}, |
72 | /* AirLive */ | 72 | /* AirLive */ |
73 | {USB_DEVICE(0x1b75, 0x8187), .driver_info = DEVICE_RTL8187}, | 73 | {USB_DEVICE(0x1b75, 0x8187), .driver_info = DEVICE_RTL8187}, |
74 | /* Linksys */ | ||
75 | {USB_DEVICE(0x1737, 0x0073), .driver_info = DEVICE_RTL8187B}, | ||
74 | {} | 76 | {} |
75 | }; | 77 | }; |
76 | 78 | ||
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c index f0e99d4c066b..242257b19441 100644 --- a/drivers/oprofile/cpu_buffer.c +++ b/drivers/oprofile/cpu_buffer.c | |||
@@ -78,16 +78,20 @@ void free_cpu_buffers(void) | |||
78 | op_ring_buffer_write = NULL; | 78 | op_ring_buffer_write = NULL; |
79 | } | 79 | } |
80 | 80 | ||
81 | #define RB_EVENT_HDR_SIZE 4 | ||
82 | |||
81 | int alloc_cpu_buffers(void) | 83 | int alloc_cpu_buffers(void) |
82 | { | 84 | { |
83 | int i; | 85 | int i; |
84 | 86 | ||
85 | unsigned long buffer_size = oprofile_cpu_buffer_size; | 87 | unsigned long buffer_size = oprofile_cpu_buffer_size; |
88 | unsigned long byte_size = buffer_size * (sizeof(struct op_sample) + | ||
89 | RB_EVENT_HDR_SIZE); | ||
86 | 90 | ||
87 | op_ring_buffer_read = ring_buffer_alloc(buffer_size, OP_BUFFER_FLAGS); | 91 | op_ring_buffer_read = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS); |
88 | if (!op_ring_buffer_read) | 92 | if (!op_ring_buffer_read) |
89 | goto fail; | 93 | goto fail; |
90 | op_ring_buffer_write = ring_buffer_alloc(buffer_size, OP_BUFFER_FLAGS); | 94 | op_ring_buffer_write = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS); |
91 | if (!op_ring_buffer_write) | 95 | if (!op_ring_buffer_write) |
92 | goto fail; | 96 | goto fail; |
93 | 97 | ||
diff --git a/drivers/parisc/iosapic.c b/drivers/parisc/iosapic.c index 73348c4047e9..4a9cc92d4d18 100644 --- a/drivers/parisc/iosapic.c +++ b/drivers/parisc/iosapic.c | |||
@@ -702,7 +702,7 @@ static unsigned int iosapic_startup_irq(unsigned int irq) | |||
702 | } | 702 | } |
703 | 703 | ||
704 | #ifdef CONFIG_SMP | 704 | #ifdef CONFIG_SMP |
705 | static void iosapic_set_affinity_irq(unsigned int irq, | 705 | static int iosapic_set_affinity_irq(unsigned int irq, |
706 | const struct cpumask *dest) | 706 | const struct cpumask *dest) |
707 | { | 707 | { |
708 | struct vector_info *vi = iosapic_get_vector(irq); | 708 | struct vector_info *vi = iosapic_get_vector(irq); |
@@ -712,7 +712,7 @@ static void iosapic_set_affinity_irq(unsigned int irq, | |||
712 | 712 | ||
713 | dest_cpu = cpu_check_affinity(irq, dest); | 713 | dest_cpu = cpu_check_affinity(irq, dest); |
714 | if (dest_cpu < 0) | 714 | if (dest_cpu < 0) |
715 | return; | 715 | return -1; |
716 | 716 | ||
717 | cpumask_copy(irq_desc[irq].affinity, cpumask_of(dest_cpu)); | 717 | cpumask_copy(irq_desc[irq].affinity, cpumask_of(dest_cpu)); |
718 | vi->txn_addr = txn_affinity_addr(irq, dest_cpu); | 718 | vi->txn_addr = txn_affinity_addr(irq, dest_cpu); |
@@ -724,6 +724,8 @@ static void iosapic_set_affinity_irq(unsigned int irq, | |||
724 | iosapic_set_irt_data(vi, &dummy_d0, &d1); | 724 | iosapic_set_irt_data(vi, &dummy_d0, &d1); |
725 | iosapic_wr_irt_entry(vi, d0, d1); | 725 | iosapic_wr_irt_entry(vi, d0, d1); |
726 | spin_unlock_irqrestore(&iosapic_lock, flags); | 726 | spin_unlock_irqrestore(&iosapic_lock, flags); |
727 | |||
728 | return 0; | ||
727 | } | 729 | } |
728 | #endif | 730 | #endif |
729 | 731 | ||
diff --git a/drivers/parport/parport_gsc.c b/drivers/parport/parport_gsc.c index e6a7e847ee80..ea31a452b153 100644 --- a/drivers/parport/parport_gsc.c +++ b/drivers/parport/parport_gsc.c | |||
@@ -352,8 +352,8 @@ static int __devinit parport_init_chip(struct parisc_device *dev) | |||
352 | unsigned long port; | 352 | unsigned long port; |
353 | 353 | ||
354 | if (!dev->irq) { | 354 | if (!dev->irq) { |
355 | printk(KERN_WARNING "IRQ not found for parallel device at 0x%lx\n", | 355 | printk(KERN_WARNING "IRQ not found for parallel device at 0x%llx\n", |
356 | dev->hpa.start); | 356 | (unsigned long long)dev->hpa.start); |
357 | return -ENODEV; | 357 | return -ENODEV; |
358 | } | 358 | } |
359 | 359 | ||
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c index 4e63cc9e2778..151bf5bc8afe 100644 --- a/drivers/parport/parport_pc.c +++ b/drivers/parport/parport_pc.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Low-level parallel-port routines for 8255-based PC-style hardware. | 1 | /* Low-level parallel-port routines for 8255-based PC-style hardware. |
2 | * | 2 | * |
3 | * Authors: Phil Blundell <philb@gnu.org> | 3 | * Authors: Phil Blundell <philb@gnu.org> |
4 | * Tim Waugh <tim@cyberelk.demon.co.uk> | 4 | * Tim Waugh <tim@cyberelk.demon.co.uk> |
5 | * Jose Renau <renau@acm.org> | 5 | * Jose Renau <renau@acm.org> |
@@ -11,7 +11,7 @@ | |||
11 | * Cleaned up include files - Russell King <linux@arm.uk.linux.org> | 11 | * Cleaned up include files - Russell King <linux@arm.uk.linux.org> |
12 | * DMA support - Bert De Jonghe <bert@sophis.be> | 12 | * DMA support - Bert De Jonghe <bert@sophis.be> |
13 | * Many ECP bugs fixed. Fred Barnes & Jamie Lokier, 1999 | 13 | * Many ECP bugs fixed. Fred Barnes & Jamie Lokier, 1999 |
14 | * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G. | 14 | * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G. |
15 | * Various hacks, Fred Barnes, 04/2001 | 15 | * Various hacks, Fred Barnes, 04/2001 |
16 | * Updated probing logic - Adam Belay <ambx1@neo.rr.com> | 16 | * Updated probing logic - Adam Belay <ambx1@neo.rr.com> |
17 | */ | 17 | */ |
@@ -56,10 +56,10 @@ | |||
56 | #include <linux/pnp.h> | 56 | #include <linux/pnp.h> |
57 | #include <linux/platform_device.h> | 57 | #include <linux/platform_device.h> |
58 | #include <linux/sysctl.h> | 58 | #include <linux/sysctl.h> |
59 | #include <linux/io.h> | ||
60 | #include <linux/uaccess.h> | ||
59 | 61 | ||
60 | #include <asm/io.h> | ||
61 | #include <asm/dma.h> | 62 | #include <asm/dma.h> |
62 | #include <asm/uaccess.h> | ||
63 | 63 | ||
64 | #include <linux/parport.h> | 64 | #include <linux/parport.h> |
65 | #include <linux/parport_pc.h> | 65 | #include <linux/parport_pc.h> |
@@ -82,7 +82,7 @@ | |||
82 | #define ECR_TST 06 | 82 | #define ECR_TST 06 |
83 | #define ECR_CNF 07 | 83 | #define ECR_CNF 07 |
84 | #define ECR_MODE_MASK 0xe0 | 84 | #define ECR_MODE_MASK 0xe0 |
85 | #define ECR_WRITE(p,v) frob_econtrol((p),0xff,(v)) | 85 | #define ECR_WRITE(p, v) frob_econtrol((p), 0xff, (v)) |
86 | 86 | ||
87 | #undef DEBUG | 87 | #undef DEBUG |
88 | 88 | ||
@@ -109,27 +109,27 @@ static int pci_registered_parport; | |||
109 | static int pnp_registered_parport; | 109 | static int pnp_registered_parport; |
110 | 110 | ||
111 | /* frob_control, but for ECR */ | 111 | /* frob_control, but for ECR */ |
112 | static void frob_econtrol (struct parport *pb, unsigned char m, | 112 | static void frob_econtrol(struct parport *pb, unsigned char m, |
113 | unsigned char v) | 113 | unsigned char v) |
114 | { | 114 | { |
115 | unsigned char ectr = 0; | 115 | unsigned char ectr = 0; |
116 | 116 | ||
117 | if (m != 0xff) | 117 | if (m != 0xff) |
118 | ectr = inb (ECONTROL (pb)); | 118 | ectr = inb(ECONTROL(pb)); |
119 | 119 | ||
120 | DPRINTK (KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n", | 120 | DPRINTK(KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n", |
121 | m, v, ectr, (ectr & ~m) ^ v); | 121 | m, v, ectr, (ectr & ~m) ^ v); |
122 | 122 | ||
123 | outb ((ectr & ~m) ^ v, ECONTROL (pb)); | 123 | outb((ectr & ~m) ^ v, ECONTROL(pb)); |
124 | } | 124 | } |
125 | 125 | ||
126 | static __inline__ void frob_set_mode (struct parport *p, int mode) | 126 | static inline void frob_set_mode(struct parport *p, int mode) |
127 | { | 127 | { |
128 | frob_econtrol (p, ECR_MODE_MASK, mode << 5); | 128 | frob_econtrol(p, ECR_MODE_MASK, mode << 5); |
129 | } | 129 | } |
130 | 130 | ||
131 | #ifdef CONFIG_PARPORT_PC_FIFO | 131 | #ifdef CONFIG_PARPORT_PC_FIFO |
132 | /* Safely change the mode bits in the ECR | 132 | /* Safely change the mode bits in the ECR |
133 | Returns: | 133 | Returns: |
134 | 0 : Success | 134 | 0 : Success |
135 | -EBUSY: Could not drain FIFO in some finite amount of time, | 135 | -EBUSY: Could not drain FIFO in some finite amount of time, |
@@ -141,17 +141,18 @@ static int change_mode(struct parport *p, int m) | |||
141 | unsigned char oecr; | 141 | unsigned char oecr; |
142 | int mode; | 142 | int mode; |
143 | 143 | ||
144 | DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n",m); | 144 | DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n", m); |
145 | 145 | ||
146 | if (!priv->ecr) { | 146 | if (!priv->ecr) { |
147 | printk (KERN_DEBUG "change_mode: but there's no ECR!\n"); | 147 | printk(KERN_DEBUG "change_mode: but there's no ECR!\n"); |
148 | return 0; | 148 | return 0; |
149 | } | 149 | } |
150 | 150 | ||
151 | /* Bits <7:5> contain the mode. */ | 151 | /* Bits <7:5> contain the mode. */ |
152 | oecr = inb (ECONTROL (p)); | 152 | oecr = inb(ECONTROL(p)); |
153 | mode = (oecr >> 5) & 0x7; | 153 | mode = (oecr >> 5) & 0x7; |
154 | if (mode == m) return 0; | 154 | if (mode == m) |
155 | return 0; | ||
155 | 156 | ||
156 | if (mode >= 2 && !(priv->ctr & 0x20)) { | 157 | if (mode >= 2 && !(priv->ctr & 0x20)) { |
157 | /* This mode resets the FIFO, so we may | 158 | /* This mode resets the FIFO, so we may |
@@ -163,19 +164,21 @@ static int change_mode(struct parport *p, int m) | |||
163 | case ECR_ECP: /* ECP Parallel Port mode */ | 164 | case ECR_ECP: /* ECP Parallel Port mode */ |
164 | /* Busy wait for 200us */ | 165 | /* Busy wait for 200us */ |
165 | for (counter = 0; counter < 40; counter++) { | 166 | for (counter = 0; counter < 40; counter++) { |
166 | if (inb (ECONTROL (p)) & 0x01) | 167 | if (inb(ECONTROL(p)) & 0x01) |
168 | break; | ||
169 | if (signal_pending(current)) | ||
167 | break; | 170 | break; |
168 | if (signal_pending (current)) break; | 171 | udelay(5); |
169 | udelay (5); | ||
170 | } | 172 | } |
171 | 173 | ||
172 | /* Poll slowly. */ | 174 | /* Poll slowly. */ |
173 | while (!(inb (ECONTROL (p)) & 0x01)) { | 175 | while (!(inb(ECONTROL(p)) & 0x01)) { |
174 | if (time_after_eq (jiffies, expire)) | 176 | if (time_after_eq(jiffies, expire)) |
175 | /* The FIFO is stuck. */ | 177 | /* The FIFO is stuck. */ |
176 | return -EBUSY; | 178 | return -EBUSY; |
177 | schedule_timeout_interruptible(msecs_to_jiffies(10)); | 179 | schedule_timeout_interruptible( |
178 | if (signal_pending (current)) | 180 | msecs_to_jiffies(10)); |
181 | if (signal_pending(current)) | ||
179 | break; | 182 | break; |
180 | } | 183 | } |
181 | } | 184 | } |
@@ -185,20 +188,20 @@ static int change_mode(struct parport *p, int m) | |||
185 | /* We have to go through mode 001 */ | 188 | /* We have to go through mode 001 */ |
186 | oecr &= ~(7 << 5); | 189 | oecr &= ~(7 << 5); |
187 | oecr |= ECR_PS2 << 5; | 190 | oecr |= ECR_PS2 << 5; |
188 | ECR_WRITE (p, oecr); | 191 | ECR_WRITE(p, oecr); |
189 | } | 192 | } |
190 | 193 | ||
191 | /* Set the mode. */ | 194 | /* Set the mode. */ |
192 | oecr &= ~(7 << 5); | 195 | oecr &= ~(7 << 5); |
193 | oecr |= m << 5; | 196 | oecr |= m << 5; |
194 | ECR_WRITE (p, oecr); | 197 | ECR_WRITE(p, oecr); |
195 | return 0; | 198 | return 0; |
196 | } | 199 | } |
197 | 200 | ||
198 | #ifdef CONFIG_PARPORT_1284 | 201 | #ifdef CONFIG_PARPORT_1284 |
199 | /* Find FIFO lossage; FIFO is reset */ | 202 | /* Find FIFO lossage; FIFO is reset */ |
200 | #if 0 | 203 | #if 0 |
201 | static int get_fifo_residue (struct parport *p) | 204 | static int get_fifo_residue(struct parport *p) |
202 | { | 205 | { |
203 | int residue; | 206 | int residue; |
204 | int cnfga; | 207 | int cnfga; |
@@ -206,26 +209,26 @@ static int get_fifo_residue (struct parport *p) | |||
206 | 209 | ||
207 | /* Adjust for the contents of the FIFO. */ | 210 | /* Adjust for the contents of the FIFO. */ |
208 | for (residue = priv->fifo_depth; ; residue--) { | 211 | for (residue = priv->fifo_depth; ; residue--) { |
209 | if (inb (ECONTROL (p)) & 0x2) | 212 | if (inb(ECONTROL(p)) & 0x2) |
210 | /* Full up. */ | 213 | /* Full up. */ |
211 | break; | 214 | break; |
212 | 215 | ||
213 | outb (0, FIFO (p)); | 216 | outb(0, FIFO(p)); |
214 | } | 217 | } |
215 | 218 | ||
216 | printk (KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name, | 219 | printk(KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name, |
217 | residue); | 220 | residue); |
218 | 221 | ||
219 | /* Reset the FIFO. */ | 222 | /* Reset the FIFO. */ |
220 | frob_set_mode (p, ECR_PS2); | 223 | frob_set_mode(p, ECR_PS2); |
221 | 224 | ||
222 | /* Now change to config mode and clean up. FIXME */ | 225 | /* Now change to config mode and clean up. FIXME */ |
223 | frob_set_mode (p, ECR_CNF); | 226 | frob_set_mode(p, ECR_CNF); |
224 | cnfga = inb (CONFIGA (p)); | 227 | cnfga = inb(CONFIGA(p)); |
225 | printk (KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga); | 228 | printk(KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga); |
226 | 229 | ||
227 | if (!(cnfga & (1<<2))) { | 230 | if (!(cnfga & (1<<2))) { |
228 | printk (KERN_DEBUG "%s: Accounting for extra byte\n", p->name); | 231 | printk(KERN_DEBUG "%s: Accounting for extra byte\n", p->name); |
229 | residue++; | 232 | residue++; |
230 | } | 233 | } |
231 | 234 | ||
@@ -233,9 +236,11 @@ static int get_fifo_residue (struct parport *p) | |||
233 | * PWord != 1 byte. */ | 236 | * PWord != 1 byte. */ |
234 | 237 | ||
235 | /* Back to PS2 mode. */ | 238 | /* Back to PS2 mode. */ |
236 | frob_set_mode (p, ECR_PS2); | 239 | frob_set_mode(p, ECR_PS2); |
237 | 240 | ||
238 | DPRINTK (KERN_DEBUG "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n", inb (ECONTROL (p))); | 241 | DPRINTK(KERN_DEBUG |
242 | "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n", | ||
243 | inb(ECONTROL(p))); | ||
239 | return residue; | 244 | return residue; |
240 | } | 245 | } |
241 | #endif /* 0 */ | 246 | #endif /* 0 */ |
@@ -257,8 +262,8 @@ static int clear_epp_timeout(struct parport *pb) | |||
257 | /* To clear timeout some chips require double read */ | 262 | /* To clear timeout some chips require double read */ |
258 | parport_pc_read_status(pb); | 263 | parport_pc_read_status(pb); |
259 | r = parport_pc_read_status(pb); | 264 | r = parport_pc_read_status(pb); |
260 | outb (r | 0x01, STATUS (pb)); /* Some reset by writing 1 */ | 265 | outb(r | 0x01, STATUS(pb)); /* Some reset by writing 1 */ |
261 | outb (r & 0xfe, STATUS (pb)); /* Others by writing 0 */ | 266 | outb(r & 0xfe, STATUS(pb)); /* Others by writing 0 */ |
262 | r = parport_pc_read_status(pb); | 267 | r = parport_pc_read_status(pb); |
263 | 268 | ||
264 | return !(r & 0x01); | 269 | return !(r & 0x01); |
@@ -272,7 +277,8 @@ static int clear_epp_timeout(struct parport *pb) | |||
272 | * of these are in parport_pc.h. | 277 | * of these are in parport_pc.h. |
273 | */ | 278 | */ |
274 | 279 | ||
275 | static void parport_pc_init_state(struct pardevice *dev, struct parport_state *s) | 280 | static void parport_pc_init_state(struct pardevice *dev, |
281 | struct parport_state *s) | ||
276 | { | 282 | { |
277 | s->u.pc.ctr = 0xc; | 283 | s->u.pc.ctr = 0xc; |
278 | if (dev->irq_func && | 284 | if (dev->irq_func && |
@@ -289,22 +295,23 @@ static void parport_pc_save_state(struct parport *p, struct parport_state *s) | |||
289 | const struct parport_pc_private *priv = p->physport->private_data; | 295 | const struct parport_pc_private *priv = p->physport->private_data; |
290 | s->u.pc.ctr = priv->ctr; | 296 | s->u.pc.ctr = priv->ctr; |
291 | if (priv->ecr) | 297 | if (priv->ecr) |
292 | s->u.pc.ecr = inb (ECONTROL (p)); | 298 | s->u.pc.ecr = inb(ECONTROL(p)); |
293 | } | 299 | } |
294 | 300 | ||
295 | static void parport_pc_restore_state(struct parport *p, struct parport_state *s) | 301 | static void parport_pc_restore_state(struct parport *p, |
302 | struct parport_state *s) | ||
296 | { | 303 | { |
297 | struct parport_pc_private *priv = p->physport->private_data; | 304 | struct parport_pc_private *priv = p->physport->private_data; |
298 | register unsigned char c = s->u.pc.ctr & priv->ctr_writable; | 305 | register unsigned char c = s->u.pc.ctr & priv->ctr_writable; |
299 | outb (c, CONTROL (p)); | 306 | outb(c, CONTROL(p)); |
300 | priv->ctr = c; | 307 | priv->ctr = c; |
301 | if (priv->ecr) | 308 | if (priv->ecr) |
302 | ECR_WRITE (p, s->u.pc.ecr); | 309 | ECR_WRITE(p, s->u.pc.ecr); |
303 | } | 310 | } |
304 | 311 | ||
305 | #ifdef CONFIG_PARPORT_1284 | 312 | #ifdef CONFIG_PARPORT_1284 |
306 | static size_t parport_pc_epp_read_data (struct parport *port, void *buf, | 313 | static size_t parport_pc_epp_read_data(struct parport *port, void *buf, |
307 | size_t length, int flags) | 314 | size_t length, int flags) |
308 | { | 315 | { |
309 | size_t got = 0; | 316 | size_t got = 0; |
310 | 317 | ||
@@ -316,54 +323,52 @@ static size_t parport_pc_epp_read_data (struct parport *port, void *buf, | |||
316 | * nFault is 0 if there is at least 1 byte in the Warp's FIFO | 323 | * nFault is 0 if there is at least 1 byte in the Warp's FIFO |
317 | * pError is 1 if there are 16 bytes in the Warp's FIFO | 324 | * pError is 1 if there are 16 bytes in the Warp's FIFO |
318 | */ | 325 | */ |
319 | status = inb (STATUS (port)); | 326 | status = inb(STATUS(port)); |
320 | 327 | ||
321 | while (!(status & 0x08) && (got < length)) { | 328 | while (!(status & 0x08) && got < length) { |
322 | if ((left >= 16) && (status & 0x20) && !(status & 0x08)) { | 329 | if (left >= 16 && (status & 0x20) && !(status & 0x08)) { |
323 | /* can grab 16 bytes from warp fifo */ | 330 | /* can grab 16 bytes from warp fifo */ |
324 | if (!((long)buf & 0x03)) { | 331 | if (!((long)buf & 0x03)) |
325 | insl (EPPDATA (port), buf, 4); | 332 | insl(EPPDATA(port), buf, 4); |
326 | } else { | 333 | else |
327 | insb (EPPDATA (port), buf, 16); | 334 | insb(EPPDATA(port), buf, 16); |
328 | } | ||
329 | buf += 16; | 335 | buf += 16; |
330 | got += 16; | 336 | got += 16; |
331 | left -= 16; | 337 | left -= 16; |
332 | } else { | 338 | } else { |
333 | /* grab single byte from the warp fifo */ | 339 | /* grab single byte from the warp fifo */ |
334 | *((char *)buf) = inb (EPPDATA (port)); | 340 | *((char *)buf) = inb(EPPDATA(port)); |
335 | buf++; | 341 | buf++; |
336 | got++; | 342 | got++; |
337 | left--; | 343 | left--; |
338 | } | 344 | } |
339 | status = inb (STATUS (port)); | 345 | status = inb(STATUS(port)); |
340 | if (status & 0x01) { | 346 | if (status & 0x01) { |
341 | /* EPP timeout should never occur... */ | 347 | /* EPP timeout should never occur... */ |
342 | printk (KERN_DEBUG "%s: EPP timeout occurred while talking to " | 348 | printk(KERN_DEBUG |
343 | "w91284pic (should not have done)\n", port->name); | 349 | "%s: EPP timeout occurred while talking to w91284pic (should not have done)\n", port->name); |
344 | clear_epp_timeout (port); | 350 | clear_epp_timeout(port); |
345 | } | 351 | } |
346 | } | 352 | } |
347 | return got; | 353 | return got; |
348 | } | 354 | } |
349 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | 355 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { |
350 | if (!(((long)buf | length) & 0x03)) { | 356 | if (!(((long)buf | length) & 0x03)) |
351 | insl (EPPDATA (port), buf, (length >> 2)); | 357 | insl(EPPDATA(port), buf, (length >> 2)); |
352 | } else { | 358 | else |
353 | insb (EPPDATA (port), buf, length); | 359 | insb(EPPDATA(port), buf, length); |
354 | } | 360 | if (inb(STATUS(port)) & 0x01) { |
355 | if (inb (STATUS (port)) & 0x01) { | 361 | clear_epp_timeout(port); |
356 | clear_epp_timeout (port); | ||
357 | return -EIO; | 362 | return -EIO; |
358 | } | 363 | } |
359 | return length; | 364 | return length; |
360 | } | 365 | } |
361 | for (; got < length; got++) { | 366 | for (; got < length; got++) { |
362 | *((char*)buf) = inb (EPPDATA(port)); | 367 | *((char *)buf) = inb(EPPDATA(port)); |
363 | buf++; | 368 | buf++; |
364 | if (inb (STATUS (port)) & 0x01) { | 369 | if (inb(STATUS(port)) & 0x01) { |
365 | /* EPP timeout */ | 370 | /* EPP timeout */ |
366 | clear_epp_timeout (port); | 371 | clear_epp_timeout(port); |
367 | break; | 372 | break; |
368 | } | 373 | } |
369 | } | 374 | } |
@@ -371,28 +376,27 @@ static size_t parport_pc_epp_read_data (struct parport *port, void *buf, | |||
371 | return got; | 376 | return got; |
372 | } | 377 | } |
373 | 378 | ||
374 | static size_t parport_pc_epp_write_data (struct parport *port, const void *buf, | 379 | static size_t parport_pc_epp_write_data(struct parport *port, const void *buf, |
375 | size_t length, int flags) | 380 | size_t length, int flags) |
376 | { | 381 | { |
377 | size_t written = 0; | 382 | size_t written = 0; |
378 | 383 | ||
379 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | 384 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { |
380 | if (!(((long)buf | length) & 0x03)) { | 385 | if (!(((long)buf | length) & 0x03)) |
381 | outsl (EPPDATA (port), buf, (length >> 2)); | 386 | outsl(EPPDATA(port), buf, (length >> 2)); |
382 | } else { | 387 | else |
383 | outsb (EPPDATA (port), buf, length); | 388 | outsb(EPPDATA(port), buf, length); |
384 | } | 389 | if (inb(STATUS(port)) & 0x01) { |
385 | if (inb (STATUS (port)) & 0x01) { | 390 | clear_epp_timeout(port); |
386 | clear_epp_timeout (port); | ||
387 | return -EIO; | 391 | return -EIO; |
388 | } | 392 | } |
389 | return length; | 393 | return length; |
390 | } | 394 | } |
391 | for (; written < length; written++) { | 395 | for (; written < length; written++) { |
392 | outb (*((char*)buf), EPPDATA(port)); | 396 | outb(*((char *)buf), EPPDATA(port)); |
393 | buf++; | 397 | buf++; |
394 | if (inb (STATUS(port)) & 0x01) { | 398 | if (inb(STATUS(port)) & 0x01) { |
395 | clear_epp_timeout (port); | 399 | clear_epp_timeout(port); |
396 | break; | 400 | break; |
397 | } | 401 | } |
398 | } | 402 | } |
@@ -400,24 +404,24 @@ static size_t parport_pc_epp_write_data (struct parport *port, const void *buf, | |||
400 | return written; | 404 | return written; |
401 | } | 405 | } |
402 | 406 | ||
403 | static size_t parport_pc_epp_read_addr (struct parport *port, void *buf, | 407 | static size_t parport_pc_epp_read_addr(struct parport *port, void *buf, |
404 | size_t length, int flags) | 408 | size_t length, int flags) |
405 | { | 409 | { |
406 | size_t got = 0; | 410 | size_t got = 0; |
407 | 411 | ||
408 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | 412 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { |
409 | insb (EPPADDR (port), buf, length); | 413 | insb(EPPADDR(port), buf, length); |
410 | if (inb (STATUS (port)) & 0x01) { | 414 | if (inb(STATUS(port)) & 0x01) { |
411 | clear_epp_timeout (port); | 415 | clear_epp_timeout(port); |
412 | return -EIO; | 416 | return -EIO; |
413 | } | 417 | } |
414 | return length; | 418 | return length; |
415 | } | 419 | } |
416 | for (; got < length; got++) { | 420 | for (; got < length; got++) { |
417 | *((char*)buf) = inb (EPPADDR (port)); | 421 | *((char *)buf) = inb(EPPADDR(port)); |
418 | buf++; | 422 | buf++; |
419 | if (inb (STATUS (port)) & 0x01) { | 423 | if (inb(STATUS(port)) & 0x01) { |
420 | clear_epp_timeout (port); | 424 | clear_epp_timeout(port); |
421 | break; | 425 | break; |
422 | } | 426 | } |
423 | } | 427 | } |
@@ -425,25 +429,25 @@ static size_t parport_pc_epp_read_addr (struct parport *port, void *buf, | |||
425 | return got; | 429 | return got; |
426 | } | 430 | } |
427 | 431 | ||
428 | static size_t parport_pc_epp_write_addr (struct parport *port, | 432 | static size_t parport_pc_epp_write_addr(struct parport *port, |
429 | const void *buf, size_t length, | 433 | const void *buf, size_t length, |
430 | int flags) | 434 | int flags) |
431 | { | 435 | { |
432 | size_t written = 0; | 436 | size_t written = 0; |
433 | 437 | ||
434 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | 438 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { |
435 | outsb (EPPADDR (port), buf, length); | 439 | outsb(EPPADDR(port), buf, length); |
436 | if (inb (STATUS (port)) & 0x01) { | 440 | if (inb(STATUS(port)) & 0x01) { |
437 | clear_epp_timeout (port); | 441 | clear_epp_timeout(port); |
438 | return -EIO; | 442 | return -EIO; |
439 | } | 443 | } |
440 | return length; | 444 | return length; |
441 | } | 445 | } |
442 | for (; written < length; written++) { | 446 | for (; written < length; written++) { |
443 | outb (*((char*)buf), EPPADDR (port)); | 447 | outb(*((char *)buf), EPPADDR(port)); |
444 | buf++; | 448 | buf++; |
445 | if (inb (STATUS (port)) & 0x01) { | 449 | if (inb(STATUS(port)) & 0x01) { |
446 | clear_epp_timeout (port); | 450 | clear_epp_timeout(port); |
447 | break; | 451 | break; |
448 | } | 452 | } |
449 | } | 453 | } |
@@ -451,74 +455,74 @@ static size_t parport_pc_epp_write_addr (struct parport *port, | |||
451 | return written; | 455 | return written; |
452 | } | 456 | } |
453 | 457 | ||
454 | static size_t parport_pc_ecpepp_read_data (struct parport *port, void *buf, | 458 | static size_t parport_pc_ecpepp_read_data(struct parport *port, void *buf, |
455 | size_t length, int flags) | 459 | size_t length, int flags) |
456 | { | 460 | { |
457 | size_t got; | 461 | size_t got; |
458 | 462 | ||
459 | frob_set_mode (port, ECR_EPP); | 463 | frob_set_mode(port, ECR_EPP); |
460 | parport_pc_data_reverse (port); | 464 | parport_pc_data_reverse(port); |
461 | parport_pc_write_control (port, 0x4); | 465 | parport_pc_write_control(port, 0x4); |
462 | got = parport_pc_epp_read_data (port, buf, length, flags); | 466 | got = parport_pc_epp_read_data(port, buf, length, flags); |
463 | frob_set_mode (port, ECR_PS2); | 467 | frob_set_mode(port, ECR_PS2); |
464 | 468 | ||
465 | return got; | 469 | return got; |
466 | } | 470 | } |
467 | 471 | ||
468 | static size_t parport_pc_ecpepp_write_data (struct parport *port, | 472 | static size_t parport_pc_ecpepp_write_data(struct parport *port, |
469 | const void *buf, size_t length, | 473 | const void *buf, size_t length, |
470 | int flags) | 474 | int flags) |
471 | { | 475 | { |
472 | size_t written; | 476 | size_t written; |
473 | 477 | ||
474 | frob_set_mode (port, ECR_EPP); | 478 | frob_set_mode(port, ECR_EPP); |
475 | parport_pc_write_control (port, 0x4); | 479 | parport_pc_write_control(port, 0x4); |
476 | parport_pc_data_forward (port); | 480 | parport_pc_data_forward(port); |
477 | written = parport_pc_epp_write_data (port, buf, length, flags); | 481 | written = parport_pc_epp_write_data(port, buf, length, flags); |
478 | frob_set_mode (port, ECR_PS2); | 482 | frob_set_mode(port, ECR_PS2); |
479 | 483 | ||
480 | return written; | 484 | return written; |
481 | } | 485 | } |
482 | 486 | ||
483 | static size_t parport_pc_ecpepp_read_addr (struct parport *port, void *buf, | 487 | static size_t parport_pc_ecpepp_read_addr(struct parport *port, void *buf, |
484 | size_t length, int flags) | 488 | size_t length, int flags) |
485 | { | 489 | { |
486 | size_t got; | 490 | size_t got; |
487 | 491 | ||
488 | frob_set_mode (port, ECR_EPP); | 492 | frob_set_mode(port, ECR_EPP); |
489 | parport_pc_data_reverse (port); | 493 | parport_pc_data_reverse(port); |
490 | parport_pc_write_control (port, 0x4); | 494 | parport_pc_write_control(port, 0x4); |
491 | got = parport_pc_epp_read_addr (port, buf, length, flags); | 495 | got = parport_pc_epp_read_addr(port, buf, length, flags); |
492 | frob_set_mode (port, ECR_PS2); | 496 | frob_set_mode(port, ECR_PS2); |
493 | 497 | ||
494 | return got; | 498 | return got; |
495 | } | 499 | } |
496 | 500 | ||
497 | static size_t parport_pc_ecpepp_write_addr (struct parport *port, | 501 | static size_t parport_pc_ecpepp_write_addr(struct parport *port, |
498 | const void *buf, size_t length, | 502 | const void *buf, size_t length, |
499 | int flags) | 503 | int flags) |
500 | { | 504 | { |
501 | size_t written; | 505 | size_t written; |
502 | 506 | ||
503 | frob_set_mode (port, ECR_EPP); | 507 | frob_set_mode(port, ECR_EPP); |
504 | parport_pc_write_control (port, 0x4); | 508 | parport_pc_write_control(port, 0x4); |
505 | parport_pc_data_forward (port); | 509 | parport_pc_data_forward(port); |
506 | written = parport_pc_epp_write_addr (port, buf, length, flags); | 510 | written = parport_pc_epp_write_addr(port, buf, length, flags); |
507 | frob_set_mode (port, ECR_PS2); | 511 | frob_set_mode(port, ECR_PS2); |
508 | 512 | ||
509 | return written; | 513 | return written; |
510 | } | 514 | } |
511 | #endif /* IEEE 1284 support */ | 515 | #endif /* IEEE 1284 support */ |
512 | 516 | ||
513 | #ifdef CONFIG_PARPORT_PC_FIFO | 517 | #ifdef CONFIG_PARPORT_PC_FIFO |
514 | static size_t parport_pc_fifo_write_block_pio (struct parport *port, | 518 | static size_t parport_pc_fifo_write_block_pio(struct parport *port, |
515 | const void *buf, size_t length) | 519 | const void *buf, size_t length) |
516 | { | 520 | { |
517 | int ret = 0; | 521 | int ret = 0; |
518 | const unsigned char *bufp = buf; | 522 | const unsigned char *bufp = buf; |
519 | size_t left = length; | 523 | size_t left = length; |
520 | unsigned long expire = jiffies + port->physport->cad->timeout; | 524 | unsigned long expire = jiffies + port->physport->cad->timeout; |
521 | const int fifo = FIFO (port); | 525 | const int fifo = FIFO(port); |
522 | int poll_for = 8; /* 80 usecs */ | 526 | int poll_for = 8; /* 80 usecs */ |
523 | const struct parport_pc_private *priv = port->physport->private_data; | 527 | const struct parport_pc_private *priv = port->physport->private_data; |
524 | const int fifo_depth = priv->fifo_depth; | 528 | const int fifo_depth = priv->fifo_depth; |
@@ -526,25 +530,25 @@ static size_t parport_pc_fifo_write_block_pio (struct parport *port, | |||
526 | port = port->physport; | 530 | port = port->physport; |
527 | 531 | ||
528 | /* We don't want to be interrupted every character. */ | 532 | /* We don't want to be interrupted every character. */ |
529 | parport_pc_disable_irq (port); | 533 | parport_pc_disable_irq(port); |
530 | /* set nErrIntrEn and serviceIntr */ | 534 | /* set nErrIntrEn and serviceIntr */ |
531 | frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2)); | 535 | frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2)); |
532 | 536 | ||
533 | /* Forward mode. */ | 537 | /* Forward mode. */ |
534 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | 538 | parport_pc_data_forward(port); /* Must be in PS2 mode */ |
535 | 539 | ||
536 | while (left) { | 540 | while (left) { |
537 | unsigned char byte; | 541 | unsigned char byte; |
538 | unsigned char ecrval = inb (ECONTROL (port)); | 542 | unsigned char ecrval = inb(ECONTROL(port)); |
539 | int i = 0; | 543 | int i = 0; |
540 | 544 | ||
541 | if (need_resched() && time_before (jiffies, expire)) | 545 | if (need_resched() && time_before(jiffies, expire)) |
542 | /* Can't yield the port. */ | 546 | /* Can't yield the port. */ |
543 | schedule (); | 547 | schedule(); |
544 | 548 | ||
545 | /* Anyone else waiting for the port? */ | 549 | /* Anyone else waiting for the port? */ |
546 | if (port->waithead) { | 550 | if (port->waithead) { |
547 | printk (KERN_DEBUG "Somebody wants the port\n"); | 551 | printk(KERN_DEBUG "Somebody wants the port\n"); |
548 | break; | 552 | break; |
549 | } | 553 | } |
550 | 554 | ||
@@ -552,21 +556,22 @@ static size_t parport_pc_fifo_write_block_pio (struct parport *port, | |||
552 | /* FIFO is full. Wait for interrupt. */ | 556 | /* FIFO is full. Wait for interrupt. */ |
553 | 557 | ||
554 | /* Clear serviceIntr */ | 558 | /* Clear serviceIntr */ |
555 | ECR_WRITE (port, ecrval & ~(1<<2)); | 559 | ECR_WRITE(port, ecrval & ~(1<<2)); |
556 | false_alarm: | 560 | false_alarm: |
557 | ret = parport_wait_event (port, HZ); | 561 | ret = parport_wait_event(port, HZ); |
558 | if (ret < 0) break; | 562 | if (ret < 0) |
563 | break; | ||
559 | ret = 0; | 564 | ret = 0; |
560 | if (!time_before (jiffies, expire)) { | 565 | if (!time_before(jiffies, expire)) { |
561 | /* Timed out. */ | 566 | /* Timed out. */ |
562 | printk (KERN_DEBUG "FIFO write timed out\n"); | 567 | printk(KERN_DEBUG "FIFO write timed out\n"); |
563 | break; | 568 | break; |
564 | } | 569 | } |
565 | ecrval = inb (ECONTROL (port)); | 570 | ecrval = inb(ECONTROL(port)); |
566 | if (!(ecrval & (1<<2))) { | 571 | if (!(ecrval & (1<<2))) { |
567 | if (need_resched() && | 572 | if (need_resched() && |
568 | time_before (jiffies, expire)) | 573 | time_before(jiffies, expire)) |
569 | schedule (); | 574 | schedule(); |
570 | 575 | ||
571 | goto false_alarm; | 576 | goto false_alarm; |
572 | } | 577 | } |
@@ -577,38 +582,38 @@ static size_t parport_pc_fifo_write_block_pio (struct parport *port, | |||
577 | /* Can't fail now. */ | 582 | /* Can't fail now. */ |
578 | expire = jiffies + port->cad->timeout; | 583 | expire = jiffies + port->cad->timeout; |
579 | 584 | ||
580 | poll: | 585 | poll: |
581 | if (signal_pending (current)) | 586 | if (signal_pending(current)) |
582 | break; | 587 | break; |
583 | 588 | ||
584 | if (ecrval & 0x01) { | 589 | if (ecrval & 0x01) { |
585 | /* FIFO is empty. Blast it full. */ | 590 | /* FIFO is empty. Blast it full. */ |
586 | const int n = left < fifo_depth ? left : fifo_depth; | 591 | const int n = left < fifo_depth ? left : fifo_depth; |
587 | outsb (fifo, bufp, n); | 592 | outsb(fifo, bufp, n); |
588 | bufp += n; | 593 | bufp += n; |
589 | left -= n; | 594 | left -= n; |
590 | 595 | ||
591 | /* Adjust the poll time. */ | 596 | /* Adjust the poll time. */ |
592 | if (i < (poll_for - 2)) poll_for--; | 597 | if (i < (poll_for - 2)) |
598 | poll_for--; | ||
593 | continue; | 599 | continue; |
594 | } else if (i++ < poll_for) { | 600 | } else if (i++ < poll_for) { |
595 | udelay (10); | 601 | udelay(10); |
596 | ecrval = inb (ECONTROL (port)); | 602 | ecrval = inb(ECONTROL(port)); |
597 | goto poll; | 603 | goto poll; |
598 | } | 604 | } |
599 | 605 | ||
600 | /* Half-full (call me an optimist) */ | 606 | /* Half-full(call me an optimist) */ |
601 | byte = *bufp++; | 607 | byte = *bufp++; |
602 | outb (byte, fifo); | 608 | outb(byte, fifo); |
603 | left--; | 609 | left--; |
604 | } | 610 | } |
605 | 611 | dump_parport_state("leave fifo_write_block_pio", port); | |
606 | dump_parport_state ("leave fifo_write_block_pio", port); | ||
607 | return length - left; | 612 | return length - left; |
608 | } | 613 | } |
609 | 614 | ||
610 | #ifdef HAS_DMA | 615 | #ifdef HAS_DMA |
611 | static size_t parport_pc_fifo_write_block_dma (struct parport *port, | 616 | static size_t parport_pc_fifo_write_block_dma(struct parport *port, |
612 | const void *buf, size_t length) | 617 | const void *buf, size_t length) |
613 | { | 618 | { |
614 | int ret = 0; | 619 | int ret = 0; |
@@ -621,7 +626,7 @@ static size_t parport_pc_fifo_write_block_dma (struct parport *port, | |||
621 | unsigned long start = (unsigned long) buf; | 626 | unsigned long start = (unsigned long) buf; |
622 | unsigned long end = (unsigned long) buf + length - 1; | 627 | unsigned long end = (unsigned long) buf + length - 1; |
623 | 628 | ||
624 | dump_parport_state ("enter fifo_write_block_dma", port); | 629 | dump_parport_state("enter fifo_write_block_dma", port); |
625 | if (end < MAX_DMA_ADDRESS) { | 630 | if (end < MAX_DMA_ADDRESS) { |
626 | /* If it would cross a 64k boundary, cap it at the end. */ | 631 | /* If it would cross a 64k boundary, cap it at the end. */ |
627 | if ((start ^ end) & ~0xffffUL) | 632 | if ((start ^ end) & ~0xffffUL) |
@@ -629,8 +634,9 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
629 | 634 | ||
630 | dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length, | 635 | dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length, |
631 | DMA_TO_DEVICE); | 636 | DMA_TO_DEVICE); |
632 | } else { | 637 | } else { |
633 | /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */ | 638 | /* above 16 MB we use a bounce buffer as ISA-DMA |
639 | is not possible */ | ||
634 | maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */ | 640 | maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */ |
635 | dma_addr = priv->dma_handle; | 641 | dma_addr = priv->dma_handle; |
636 | dma_handle = 0; | 642 | dma_handle = 0; |
@@ -639,12 +645,12 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
639 | port = port->physport; | 645 | port = port->physport; |
640 | 646 | ||
641 | /* We don't want to be interrupted every character. */ | 647 | /* We don't want to be interrupted every character. */ |
642 | parport_pc_disable_irq (port); | 648 | parport_pc_disable_irq(port); |
643 | /* set nErrIntrEn and serviceIntr */ | 649 | /* set nErrIntrEn and serviceIntr */ |
644 | frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2)); | 650 | frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2)); |
645 | 651 | ||
646 | /* Forward mode. */ | 652 | /* Forward mode. */ |
647 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | 653 | parport_pc_data_forward(port); /* Must be in PS2 mode */ |
648 | 654 | ||
649 | while (left) { | 655 | while (left) { |
650 | unsigned long expire = jiffies + port->physport->cad->timeout; | 656 | unsigned long expire = jiffies + port->physport->cad->timeout; |
@@ -665,10 +671,10 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
665 | set_dma_count(port->dma, count); | 671 | set_dma_count(port->dma, count); |
666 | 672 | ||
667 | /* Set DMA mode */ | 673 | /* Set DMA mode */ |
668 | frob_econtrol (port, 1<<3, 1<<3); | 674 | frob_econtrol(port, 1<<3, 1<<3); |
669 | 675 | ||
670 | /* Clear serviceIntr */ | 676 | /* Clear serviceIntr */ |
671 | frob_econtrol (port, 1<<2, 0); | 677 | frob_econtrol(port, 1<<2, 0); |
672 | 678 | ||
673 | enable_dma(port->dma); | 679 | enable_dma(port->dma); |
674 | release_dma_lock(dmaflag); | 680 | release_dma_lock(dmaflag); |
@@ -676,20 +682,22 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
676 | /* assume DMA will be successful */ | 682 | /* assume DMA will be successful */ |
677 | left -= count; | 683 | left -= count; |
678 | buf += count; | 684 | buf += count; |
679 | if (dma_handle) dma_addr += count; | 685 | if (dma_handle) |
686 | dma_addr += count; | ||
680 | 687 | ||
681 | /* Wait for interrupt. */ | 688 | /* Wait for interrupt. */ |
682 | false_alarm: | 689 | false_alarm: |
683 | ret = parport_wait_event (port, HZ); | 690 | ret = parport_wait_event(port, HZ); |
684 | if (ret < 0) break; | 691 | if (ret < 0) |
692 | break; | ||
685 | ret = 0; | 693 | ret = 0; |
686 | if (!time_before (jiffies, expire)) { | 694 | if (!time_before(jiffies, expire)) { |
687 | /* Timed out. */ | 695 | /* Timed out. */ |
688 | printk (KERN_DEBUG "DMA write timed out\n"); | 696 | printk(KERN_DEBUG "DMA write timed out\n"); |
689 | break; | 697 | break; |
690 | } | 698 | } |
691 | /* Is serviceIntr set? */ | 699 | /* Is serviceIntr set? */ |
692 | if (!(inb (ECONTROL (port)) & (1<<2))) { | 700 | if (!(inb(ECONTROL(port)) & (1<<2))) { |
693 | cond_resched(); | 701 | cond_resched(); |
694 | 702 | ||
695 | goto false_alarm; | 703 | goto false_alarm; |
@@ -705,14 +713,15 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
705 | 713 | ||
706 | /* Anyone else waiting for the port? */ | 714 | /* Anyone else waiting for the port? */ |
707 | if (port->waithead) { | 715 | if (port->waithead) { |
708 | printk (KERN_DEBUG "Somebody wants the port\n"); | 716 | printk(KERN_DEBUG "Somebody wants the port\n"); |
709 | break; | 717 | break; |
710 | } | 718 | } |
711 | 719 | ||
712 | /* update for possible DMA residue ! */ | 720 | /* update for possible DMA residue ! */ |
713 | buf -= count; | 721 | buf -= count; |
714 | left += count; | 722 | left += count; |
715 | if (dma_handle) dma_addr -= count; | 723 | if (dma_handle) |
724 | dma_addr -= count; | ||
716 | } | 725 | } |
717 | 726 | ||
718 | /* Maybe got here through break, so adjust for DMA residue! */ | 727 | /* Maybe got here through break, so adjust for DMA residue! */ |
@@ -723,12 +732,12 @@ dump_parport_state ("enter fifo_write_block_dma", port); | |||
723 | release_dma_lock(dmaflag); | 732 | release_dma_lock(dmaflag); |
724 | 733 | ||
725 | /* Turn off DMA mode */ | 734 | /* Turn off DMA mode */ |
726 | frob_econtrol (port, 1<<3, 0); | 735 | frob_econtrol(port, 1<<3, 0); |
727 | 736 | ||
728 | if (dma_handle) | 737 | if (dma_handle) |
729 | dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE); | 738 | dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE); |
730 | 739 | ||
731 | dump_parport_state ("leave fifo_write_block_dma", port); | 740 | dump_parport_state("leave fifo_write_block_dma", port); |
732 | return length - left; | 741 | return length - left; |
733 | } | 742 | } |
734 | #endif | 743 | #endif |
@@ -738,13 +747,13 @@ static inline size_t parport_pc_fifo_write_block(struct parport *port, | |||
738 | { | 747 | { |
739 | #ifdef HAS_DMA | 748 | #ifdef HAS_DMA |
740 | if (port->dma != PARPORT_DMA_NONE) | 749 | if (port->dma != PARPORT_DMA_NONE) |
741 | return parport_pc_fifo_write_block_dma (port, buf, length); | 750 | return parport_pc_fifo_write_block_dma(port, buf, length); |
742 | #endif | 751 | #endif |
743 | return parport_pc_fifo_write_block_pio (port, buf, length); | 752 | return parport_pc_fifo_write_block_pio(port, buf, length); |
744 | } | 753 | } |
745 | 754 | ||
746 | /* Parallel Port FIFO mode (ECP chipsets) */ | 755 | /* Parallel Port FIFO mode (ECP chipsets) */ |
747 | static size_t parport_pc_compat_write_block_pio (struct parport *port, | 756 | static size_t parport_pc_compat_write_block_pio(struct parport *port, |
748 | const void *buf, size_t length, | 757 | const void *buf, size_t length, |
749 | int flags) | 758 | int flags) |
750 | { | 759 | { |
@@ -756,14 +765,16 @@ static size_t parport_pc_compat_write_block_pio (struct parport *port, | |||
756 | /* Special case: a timeout of zero means we cannot call schedule(). | 765 | /* Special case: a timeout of zero means we cannot call schedule(). |
757 | * Also if O_NONBLOCK is set then use the default implementation. */ | 766 | * Also if O_NONBLOCK is set then use the default implementation. */ |
758 | if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) | 767 | if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) |
759 | return parport_ieee1284_write_compat (port, buf, | 768 | return parport_ieee1284_write_compat(port, buf, |
760 | length, flags); | 769 | length, flags); |
761 | 770 | ||
762 | /* Set up parallel port FIFO mode.*/ | 771 | /* Set up parallel port FIFO mode.*/ |
763 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | 772 | parport_pc_data_forward(port); /* Must be in PS2 mode */ |
764 | parport_pc_frob_control (port, PARPORT_CONTROL_STROBE, 0); | 773 | parport_pc_frob_control(port, PARPORT_CONTROL_STROBE, 0); |
765 | r = change_mode (port, ECR_PPF); /* Parallel port FIFO */ | 774 | r = change_mode(port, ECR_PPF); /* Parallel port FIFO */ |
766 | if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", port->name); | 775 | if (r) |
776 | printk(KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", | ||
777 | port->name); | ||
767 | 778 | ||
768 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; | 779 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; |
769 | 780 | ||
@@ -775,40 +786,39 @@ static size_t parport_pc_compat_write_block_pio (struct parport *port, | |||
775 | * the FIFO is empty, so allow 4 seconds for each position | 786 | * the FIFO is empty, so allow 4 seconds for each position |
776 | * in the fifo. | 787 | * in the fifo. |
777 | */ | 788 | */ |
778 | expire = jiffies + (priv->fifo_depth * HZ * 4); | 789 | expire = jiffies + (priv->fifo_depth * HZ * 4); |
779 | do { | 790 | do { |
780 | /* Wait for the FIFO to empty */ | 791 | /* Wait for the FIFO to empty */ |
781 | r = change_mode (port, ECR_PS2); | 792 | r = change_mode(port, ECR_PS2); |
782 | if (r != -EBUSY) { | 793 | if (r != -EBUSY) |
783 | break; | 794 | break; |
784 | } | 795 | } while (time_before(jiffies, expire)); |
785 | } while (time_before (jiffies, expire)); | ||
786 | if (r == -EBUSY) { | 796 | if (r == -EBUSY) { |
787 | 797 | ||
788 | printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name); | 798 | printk(KERN_DEBUG "%s: FIFO is stuck\n", port->name); |
789 | 799 | ||
790 | /* Prevent further data transfer. */ | 800 | /* Prevent further data transfer. */ |
791 | frob_set_mode (port, ECR_TST); | 801 | frob_set_mode(port, ECR_TST); |
792 | 802 | ||
793 | /* Adjust for the contents of the FIFO. */ | 803 | /* Adjust for the contents of the FIFO. */ |
794 | for (written -= priv->fifo_depth; ; written++) { | 804 | for (written -= priv->fifo_depth; ; written++) { |
795 | if (inb (ECONTROL (port)) & 0x2) { | 805 | if (inb(ECONTROL(port)) & 0x2) { |
796 | /* Full up. */ | 806 | /* Full up. */ |
797 | break; | 807 | break; |
798 | } | 808 | } |
799 | outb (0, FIFO (port)); | 809 | outb(0, FIFO(port)); |
800 | } | 810 | } |
801 | 811 | ||
802 | /* Reset the FIFO and return to PS2 mode. */ | 812 | /* Reset the FIFO and return to PS2 mode. */ |
803 | frob_set_mode (port, ECR_PS2); | 813 | frob_set_mode(port, ECR_PS2); |
804 | } | 814 | } |
805 | 815 | ||
806 | r = parport_wait_peripheral (port, | 816 | r = parport_wait_peripheral(port, |
807 | PARPORT_STATUS_BUSY, | 817 | PARPORT_STATUS_BUSY, |
808 | PARPORT_STATUS_BUSY); | 818 | PARPORT_STATUS_BUSY); |
809 | if (r) | 819 | if (r) |
810 | printk (KERN_DEBUG | 820 | printk(KERN_DEBUG |
811 | "%s: BUSY timeout (%d) in compat_write_block_pio\n", | 821 | "%s: BUSY timeout (%d) in compat_write_block_pio\n", |
812 | port->name, r); | 822 | port->name, r); |
813 | 823 | ||
814 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | 824 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE; |
@@ -818,7 +828,7 @@ static size_t parport_pc_compat_write_block_pio (struct parport *port, | |||
818 | 828 | ||
819 | /* ECP */ | 829 | /* ECP */ |
820 | #ifdef CONFIG_PARPORT_1284 | 830 | #ifdef CONFIG_PARPORT_1284 |
821 | static size_t parport_pc_ecp_write_block_pio (struct parport *port, | 831 | static size_t parport_pc_ecp_write_block_pio(struct parport *port, |
822 | const void *buf, size_t length, | 832 | const void *buf, size_t length, |
823 | int flags) | 833 | int flags) |
824 | { | 834 | { |
@@ -830,36 +840,38 @@ static size_t parport_pc_ecp_write_block_pio (struct parport *port, | |||
830 | /* Special case: a timeout of zero means we cannot call schedule(). | 840 | /* Special case: a timeout of zero means we cannot call schedule(). |
831 | * Also if O_NONBLOCK is set then use the default implementation. */ | 841 | * Also if O_NONBLOCK is set then use the default implementation. */ |
832 | if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) | 842 | if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) |
833 | return parport_ieee1284_ecp_write_data (port, buf, | 843 | return parport_ieee1284_ecp_write_data(port, buf, |
834 | length, flags); | 844 | length, flags); |
835 | 845 | ||
836 | /* Switch to forward mode if necessary. */ | 846 | /* Switch to forward mode if necessary. */ |
837 | if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) { | 847 | if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) { |
838 | /* Event 47: Set nInit high. */ | 848 | /* Event 47: Set nInit high. */ |
839 | parport_frob_control (port, | 849 | parport_frob_control(port, |
840 | PARPORT_CONTROL_INIT | 850 | PARPORT_CONTROL_INIT |
841 | | PARPORT_CONTROL_AUTOFD, | 851 | | PARPORT_CONTROL_AUTOFD, |
842 | PARPORT_CONTROL_INIT | 852 | PARPORT_CONTROL_INIT |
843 | | PARPORT_CONTROL_AUTOFD); | 853 | | PARPORT_CONTROL_AUTOFD); |
844 | 854 | ||
845 | /* Event 49: PError goes high. */ | 855 | /* Event 49: PError goes high. */ |
846 | r = parport_wait_peripheral (port, | 856 | r = parport_wait_peripheral(port, |
847 | PARPORT_STATUS_PAPEROUT, | 857 | PARPORT_STATUS_PAPEROUT, |
848 | PARPORT_STATUS_PAPEROUT); | 858 | PARPORT_STATUS_PAPEROUT); |
849 | if (r) { | 859 | if (r) { |
850 | printk (KERN_DEBUG "%s: PError timeout (%d) " | 860 | printk(KERN_DEBUG "%s: PError timeout (%d) " |
851 | "in ecp_write_block_pio\n", port->name, r); | 861 | "in ecp_write_block_pio\n", port->name, r); |
852 | } | 862 | } |
853 | } | 863 | } |
854 | 864 | ||
855 | /* Set up ECP parallel port mode.*/ | 865 | /* Set up ECP parallel port mode.*/ |
856 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | 866 | parport_pc_data_forward(port); /* Must be in PS2 mode */ |
857 | parport_pc_frob_control (port, | 867 | parport_pc_frob_control(port, |
858 | PARPORT_CONTROL_STROBE | | 868 | PARPORT_CONTROL_STROBE | |
859 | PARPORT_CONTROL_AUTOFD, | 869 | PARPORT_CONTROL_AUTOFD, |
860 | 0); | 870 | 0); |
861 | r = change_mode (port, ECR_ECP); /* ECP FIFO */ | 871 | r = change_mode(port, ECR_ECP); /* ECP FIFO */ |
862 | if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name); | 872 | if (r) |
873 | printk(KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", | ||
874 | port->name); | ||
863 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; | 875 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; |
864 | 876 | ||
865 | /* Write the data to the FIFO. */ | 877 | /* Write the data to the FIFO. */ |
@@ -873,55 +885,54 @@ static size_t parport_pc_ecp_write_block_pio (struct parport *port, | |||
873 | expire = jiffies + (priv->fifo_depth * (HZ * 4)); | 885 | expire = jiffies + (priv->fifo_depth * (HZ * 4)); |
874 | do { | 886 | do { |
875 | /* Wait for the FIFO to empty */ | 887 | /* Wait for the FIFO to empty */ |
876 | r = change_mode (port, ECR_PS2); | 888 | r = change_mode(port, ECR_PS2); |
877 | if (r != -EBUSY) { | 889 | if (r != -EBUSY) |
878 | break; | 890 | break; |
879 | } | 891 | } while (time_before(jiffies, expire)); |
880 | } while (time_before (jiffies, expire)); | ||
881 | if (r == -EBUSY) { | 892 | if (r == -EBUSY) { |
882 | 893 | ||
883 | printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name); | 894 | printk(KERN_DEBUG "%s: FIFO is stuck\n", port->name); |
884 | 895 | ||
885 | /* Prevent further data transfer. */ | 896 | /* Prevent further data transfer. */ |
886 | frob_set_mode (port, ECR_TST); | 897 | frob_set_mode(port, ECR_TST); |
887 | 898 | ||
888 | /* Adjust for the contents of the FIFO. */ | 899 | /* Adjust for the contents of the FIFO. */ |
889 | for (written -= priv->fifo_depth; ; written++) { | 900 | for (written -= priv->fifo_depth; ; written++) { |
890 | if (inb (ECONTROL (port)) & 0x2) { | 901 | if (inb(ECONTROL(port)) & 0x2) { |
891 | /* Full up. */ | 902 | /* Full up. */ |
892 | break; | 903 | break; |
893 | } | 904 | } |
894 | outb (0, FIFO (port)); | 905 | outb(0, FIFO(port)); |
895 | } | 906 | } |
896 | 907 | ||
897 | /* Reset the FIFO and return to PS2 mode. */ | 908 | /* Reset the FIFO and return to PS2 mode. */ |
898 | frob_set_mode (port, ECR_PS2); | 909 | frob_set_mode(port, ECR_PS2); |
899 | 910 | ||
900 | /* Host transfer recovery. */ | 911 | /* Host transfer recovery. */ |
901 | parport_pc_data_reverse (port); /* Must be in PS2 mode */ | 912 | parport_pc_data_reverse(port); /* Must be in PS2 mode */ |
902 | udelay (5); | 913 | udelay(5); |
903 | parport_frob_control (port, PARPORT_CONTROL_INIT, 0); | 914 | parport_frob_control(port, PARPORT_CONTROL_INIT, 0); |
904 | r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0); | 915 | r = parport_wait_peripheral(port, PARPORT_STATUS_PAPEROUT, 0); |
905 | if (r) | 916 | if (r) |
906 | printk (KERN_DEBUG "%s: PE,1 timeout (%d) " | 917 | printk(KERN_DEBUG "%s: PE,1 timeout (%d) " |
907 | "in ecp_write_block_pio\n", port->name, r); | 918 | "in ecp_write_block_pio\n", port->name, r); |
908 | 919 | ||
909 | parport_frob_control (port, | 920 | parport_frob_control(port, |
910 | PARPORT_CONTROL_INIT, | 921 | PARPORT_CONTROL_INIT, |
911 | PARPORT_CONTROL_INIT); | 922 | PARPORT_CONTROL_INIT); |
912 | r = parport_wait_peripheral (port, | 923 | r = parport_wait_peripheral(port, |
913 | PARPORT_STATUS_PAPEROUT, | 924 | PARPORT_STATUS_PAPEROUT, |
914 | PARPORT_STATUS_PAPEROUT); | 925 | PARPORT_STATUS_PAPEROUT); |
915 | if (r) | 926 | if (r) |
916 | printk (KERN_DEBUG "%s: PE,2 timeout (%d) " | 927 | printk(KERN_DEBUG "%s: PE,2 timeout (%d) " |
917 | "in ecp_write_block_pio\n", port->name, r); | 928 | "in ecp_write_block_pio\n", port->name, r); |
918 | } | 929 | } |
919 | 930 | ||
920 | r = parport_wait_peripheral (port, | 931 | r = parport_wait_peripheral(port, |
921 | PARPORT_STATUS_BUSY, | 932 | PARPORT_STATUS_BUSY, |
922 | PARPORT_STATUS_BUSY); | 933 | PARPORT_STATUS_BUSY); |
923 | if(r) | 934 | if (r) |
924 | printk (KERN_DEBUG | 935 | printk(KERN_DEBUG |
925 | "%s: BUSY timeout (%d) in ecp_write_block_pio\n", | 936 | "%s: BUSY timeout (%d) in ecp_write_block_pio\n", |
926 | port->name, r); | 937 | port->name, r); |
927 | 938 | ||
@@ -931,7 +942,7 @@ static size_t parport_pc_ecp_write_block_pio (struct parport *port, | |||
931 | } | 942 | } |
932 | 943 | ||
933 | #if 0 | 944 | #if 0 |
934 | static size_t parport_pc_ecp_read_block_pio (struct parport *port, | 945 | static size_t parport_pc_ecp_read_block_pio(struct parport *port, |
935 | void *buf, size_t length, | 946 | void *buf, size_t length, |
936 | int flags) | 947 | int flags) |
937 | { | 948 | { |
@@ -944,13 +955,13 @@ static size_t parport_pc_ecp_read_block_pio (struct parport *port, | |||
944 | char *bufp = buf; | 955 | char *bufp = buf; |
945 | 956 | ||
946 | port = port->physport; | 957 | port = port->physport; |
947 | DPRINTK (KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n"); | 958 | DPRINTK(KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n"); |
948 | dump_parport_state ("enter fcn", port); | 959 | dump_parport_state("enter fcn", port); |
949 | 960 | ||
950 | /* Special case: a timeout of zero means we cannot call schedule(). | 961 | /* Special case: a timeout of zero means we cannot call schedule(). |
951 | * Also if O_NONBLOCK is set then use the default implementation. */ | 962 | * Also if O_NONBLOCK is set then use the default implementation. */ |
952 | if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) | 963 | if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) |
953 | return parport_ieee1284_ecp_read_data (port, buf, | 964 | return parport_ieee1284_ecp_read_data(port, buf, |
954 | length, flags); | 965 | length, flags); |
955 | 966 | ||
956 | if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) { | 967 | if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) { |
@@ -966,173 +977,178 @@ dump_parport_state ("enter fcn", port); | |||
966 | * go through software emulation. Otherwise we may have to throw | 977 | * go through software emulation. Otherwise we may have to throw |
967 | * away data. */ | 978 | * away data. */ |
968 | if (length < fifofull) | 979 | if (length < fifofull) |
969 | return parport_ieee1284_ecp_read_data (port, buf, | 980 | return parport_ieee1284_ecp_read_data(port, buf, |
970 | length, flags); | 981 | length, flags); |
971 | 982 | ||
972 | if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) { | 983 | if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) { |
973 | /* change to reverse-idle phase (must be in forward-idle) */ | 984 | /* change to reverse-idle phase (must be in forward-idle) */ |
974 | 985 | ||
975 | /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */ | 986 | /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */ |
976 | parport_frob_control (port, | 987 | parport_frob_control(port, |
977 | PARPORT_CONTROL_AUTOFD | 988 | PARPORT_CONTROL_AUTOFD |
978 | | PARPORT_CONTROL_STROBE, | 989 | | PARPORT_CONTROL_STROBE, |
979 | PARPORT_CONTROL_AUTOFD); | 990 | PARPORT_CONTROL_AUTOFD); |
980 | parport_pc_data_reverse (port); /* Must be in PS2 mode */ | 991 | parport_pc_data_reverse(port); /* Must be in PS2 mode */ |
981 | udelay (5); | 992 | udelay(5); |
982 | /* Event 39: Set nInit low to initiate bus reversal */ | 993 | /* Event 39: Set nInit low to initiate bus reversal */ |
983 | parport_frob_control (port, | 994 | parport_frob_control(port, |
984 | PARPORT_CONTROL_INIT, | 995 | PARPORT_CONTROL_INIT, |
985 | 0); | 996 | 0); |
986 | /* Event 40: Wait for nAckReverse (PError) to go low */ | 997 | /* Event 40: Wait for nAckReverse (PError) to go low */ |
987 | r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0); | 998 | r = parport_wait_peripheral(port, PARPORT_STATUS_PAPEROUT, 0); |
988 | if (r) { | 999 | if (r) { |
989 | printk (KERN_DEBUG "%s: PE timeout Event 40 (%d) " | 1000 | printk(KERN_DEBUG "%s: PE timeout Event 40 (%d) " |
990 | "in ecp_read_block_pio\n", port->name, r); | 1001 | "in ecp_read_block_pio\n", port->name, r); |
991 | return 0; | 1002 | return 0; |
992 | } | 1003 | } |
993 | } | 1004 | } |
994 | 1005 | ||
995 | /* Set up ECP FIFO mode.*/ | 1006 | /* Set up ECP FIFO mode.*/ |
996 | /* parport_pc_frob_control (port, | 1007 | /* parport_pc_frob_control(port, |
997 | PARPORT_CONTROL_STROBE | | 1008 | PARPORT_CONTROL_STROBE | |
998 | PARPORT_CONTROL_AUTOFD, | 1009 | PARPORT_CONTROL_AUTOFD, |
999 | PARPORT_CONTROL_AUTOFD); */ | 1010 | PARPORT_CONTROL_AUTOFD); */ |
1000 | r = change_mode (port, ECR_ECP); /* ECP FIFO */ | 1011 | r = change_mode(port, ECR_ECP); /* ECP FIFO */ |
1001 | if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name); | 1012 | if (r) |
1013 | printk(KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", | ||
1014 | port->name); | ||
1002 | 1015 | ||
1003 | port->ieee1284.phase = IEEE1284_PH_REV_DATA; | 1016 | port->ieee1284.phase = IEEE1284_PH_REV_DATA; |
1004 | 1017 | ||
1005 | /* the first byte must be collected manually */ | 1018 | /* the first byte must be collected manually */ |
1006 | dump_parport_state ("pre 43", port); | 1019 | dump_parport_state("pre 43", port); |
1007 | /* Event 43: Wait for nAck to go low */ | 1020 | /* Event 43: Wait for nAck to go low */ |
1008 | r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0); | 1021 | r = parport_wait_peripheral(port, PARPORT_STATUS_ACK, 0); |
1009 | if (r) { | 1022 | if (r) { |
1010 | /* timed out while reading -- no data */ | 1023 | /* timed out while reading -- no data */ |
1011 | printk (KERN_DEBUG "PIO read timed out (initial byte)\n"); | 1024 | printk(KERN_DEBUG "PIO read timed out (initial byte)\n"); |
1012 | goto out_no_data; | 1025 | goto out_no_data; |
1013 | } | 1026 | } |
1014 | /* read byte */ | 1027 | /* read byte */ |
1015 | *bufp++ = inb (DATA (port)); | 1028 | *bufp++ = inb(DATA(port)); |
1016 | left--; | 1029 | left--; |
1017 | dump_parport_state ("43-44", port); | 1030 | dump_parport_state("43-44", port); |
1018 | /* Event 44: nAutoFd (HostAck) goes high to acknowledge */ | 1031 | /* Event 44: nAutoFd (HostAck) goes high to acknowledge */ |
1019 | parport_pc_frob_control (port, | 1032 | parport_pc_frob_control(port, |
1020 | PARPORT_CONTROL_AUTOFD, | 1033 | PARPORT_CONTROL_AUTOFD, |
1021 | 0); | 1034 | 0); |
1022 | dump_parport_state ("pre 45", port); | 1035 | dump_parport_state("pre 45", port); |
1023 | /* Event 45: Wait for nAck to go high */ | 1036 | /* Event 45: Wait for nAck to go high */ |
1024 | /* r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, PARPORT_STATUS_ACK); */ | 1037 | /* r = parport_wait_peripheral(port, PARPORT_STATUS_ACK, |
1025 | dump_parport_state ("post 45", port); | 1038 | PARPORT_STATUS_ACK); */ |
1026 | r = 0; | 1039 | dump_parport_state("post 45", port); |
1040 | r = 0; | ||
1027 | if (r) { | 1041 | if (r) { |
1028 | /* timed out while waiting for peripheral to respond to ack */ | 1042 | /* timed out while waiting for peripheral to respond to ack */ |
1029 | printk (KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n"); | 1043 | printk(KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n"); |
1030 | 1044 | ||
1031 | /* keep hold of the byte we've got already */ | 1045 | /* keep hold of the byte we've got already */ |
1032 | goto out_no_data; | 1046 | goto out_no_data; |
1033 | } | 1047 | } |
1034 | /* Event 46: nAutoFd (HostAck) goes low to accept more data */ | 1048 | /* Event 46: nAutoFd (HostAck) goes low to accept more data */ |
1035 | parport_pc_frob_control (port, | 1049 | parport_pc_frob_control(port, |
1036 | PARPORT_CONTROL_AUTOFD, | 1050 | PARPORT_CONTROL_AUTOFD, |
1037 | PARPORT_CONTROL_AUTOFD); | 1051 | PARPORT_CONTROL_AUTOFD); |
1038 | 1052 | ||
1039 | 1053 | ||
1040 | dump_parport_state ("rev idle", port); | 1054 | dump_parport_state("rev idle", port); |
1041 | /* Do the transfer. */ | 1055 | /* Do the transfer. */ |
1042 | while (left > fifofull) { | 1056 | while (left > fifofull) { |
1043 | int ret; | 1057 | int ret; |
1044 | unsigned long expire = jiffies + port->cad->timeout; | 1058 | unsigned long expire = jiffies + port->cad->timeout; |
1045 | unsigned char ecrval = inb (ECONTROL (port)); | 1059 | unsigned char ecrval = inb(ECONTROL(port)); |
1046 | 1060 | ||
1047 | if (need_resched() && time_before (jiffies, expire)) | 1061 | if (need_resched() && time_before(jiffies, expire)) |
1048 | /* Can't yield the port. */ | 1062 | /* Can't yield the port. */ |
1049 | schedule (); | 1063 | schedule(); |
1050 | 1064 | ||
1051 | /* At this point, the FIFO may already be full. In | 1065 | /* At this point, the FIFO may already be full. In |
1052 | * that case ECP is already holding back the | 1066 | * that case ECP is already holding back the |
1053 | * peripheral (assuming proper design) with a delayed | 1067 | * peripheral (assuming proper design) with a delayed |
1054 | * handshake. Work fast to avoid a peripheral | 1068 | * handshake. Work fast to avoid a peripheral |
1055 | * timeout. */ | 1069 | * timeout. */ |
1056 | 1070 | ||
1057 | if (ecrval & 0x01) { | 1071 | if (ecrval & 0x01) { |
1058 | /* FIFO is empty. Wait for interrupt. */ | 1072 | /* FIFO is empty. Wait for interrupt. */ |
1059 | dump_parport_state ("FIFO empty", port); | 1073 | dump_parport_state("FIFO empty", port); |
1060 | 1074 | ||
1061 | /* Anyone else waiting for the port? */ | 1075 | /* Anyone else waiting for the port? */ |
1062 | if (port->waithead) { | 1076 | if (port->waithead) { |
1063 | printk (KERN_DEBUG "Somebody wants the port\n"); | 1077 | printk(KERN_DEBUG "Somebody wants the port\n"); |
1064 | break; | 1078 | break; |
1065 | } | 1079 | } |
1066 | 1080 | ||
1067 | /* Clear serviceIntr */ | 1081 | /* Clear serviceIntr */ |
1068 | ECR_WRITE (port, ecrval & ~(1<<2)); | 1082 | ECR_WRITE(port, ecrval & ~(1<<2)); |
1069 | false_alarm: | 1083 | false_alarm: |
1070 | dump_parport_state ("waiting", port); | 1084 | dump_parport_state("waiting", port); |
1071 | ret = parport_wait_event (port, HZ); | 1085 | ret = parport_wait_event(port, HZ); |
1072 | DPRINTK (KERN_DEBUG "parport_wait_event returned %d\n", ret); | 1086 | DPRINTK(KERN_DEBUG "parport_wait_event returned %d\n", |
1087 | ret); | ||
1073 | if (ret < 0) | 1088 | if (ret < 0) |
1074 | break; | 1089 | break; |
1075 | ret = 0; | 1090 | ret = 0; |
1076 | if (!time_before (jiffies, expire)) { | 1091 | if (!time_before(jiffies, expire)) { |
1077 | /* Timed out. */ | 1092 | /* Timed out. */ |
1078 | dump_parport_state ("timeout", port); | 1093 | dump_parport_state("timeout", port); |
1079 | printk (KERN_DEBUG "PIO read timed out\n"); | 1094 | printk(KERN_DEBUG "PIO read timed out\n"); |
1080 | break; | 1095 | break; |
1081 | } | 1096 | } |
1082 | ecrval = inb (ECONTROL (port)); | 1097 | ecrval = inb(ECONTROL(port)); |
1083 | if (!(ecrval & (1<<2))) { | 1098 | if (!(ecrval & (1<<2))) { |
1084 | if (need_resched() && | 1099 | if (need_resched() && |
1085 | time_before (jiffies, expire)) { | 1100 | time_before(jiffies, expire)) { |
1086 | schedule (); | 1101 | schedule(); |
1087 | } | 1102 | } |
1088 | goto false_alarm; | 1103 | goto false_alarm; |
1089 | } | 1104 | } |
1090 | 1105 | ||
1091 | /* Depending on how the FIFO threshold was | 1106 | /* Depending on how the FIFO threshold was |
1092 | * set, how long interrupt service took, and | 1107 | * set, how long interrupt service took, and |
1093 | * how fast the peripheral is, we might be | 1108 | * how fast the peripheral is, we might be |
1094 | * lucky and have a just filled FIFO. */ | 1109 | * lucky and have a just filled FIFO. */ |
1095 | continue; | 1110 | continue; |
1096 | } | 1111 | } |
1097 | 1112 | ||
1098 | if (ecrval & 0x02) { | 1113 | if (ecrval & 0x02) { |
1099 | /* FIFO is full. */ | 1114 | /* FIFO is full. */ |
1100 | dump_parport_state ("FIFO full", port); | 1115 | dump_parport_state("FIFO full", port); |
1101 | insb (fifo, bufp, fifo_depth); | 1116 | insb(fifo, bufp, fifo_depth); |
1102 | bufp += fifo_depth; | 1117 | bufp += fifo_depth; |
1103 | left -= fifo_depth; | 1118 | left -= fifo_depth; |
1104 | continue; | 1119 | continue; |
1105 | } | 1120 | } |
1106 | 1121 | ||
1107 | DPRINTK (KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n"); | 1122 | DPRINTK(KERN_DEBUG |
1123 | "*** ecp_read_block_pio: reading one byte from the FIFO\n"); | ||
1108 | 1124 | ||
1109 | /* FIFO not filled. We will cycle this loop for a while | 1125 | /* FIFO not filled. We will cycle this loop for a while |
1110 | * and either the peripheral will fill it faster, | 1126 | * and either the peripheral will fill it faster, |
1111 | * tripping a fast empty with insb, or we empty it. */ | 1127 | * tripping a fast empty with insb, or we empty it. */ |
1112 | *bufp++ = inb (fifo); | 1128 | *bufp++ = inb(fifo); |
1113 | left--; | 1129 | left--; |
1114 | } | 1130 | } |
1115 | 1131 | ||
1116 | /* scoop up anything left in the FIFO */ | 1132 | /* scoop up anything left in the FIFO */ |
1117 | while (left && !(inb (ECONTROL (port) & 0x01))) { | 1133 | while (left && !(inb(ECONTROL(port) & 0x01))) { |
1118 | *bufp++ = inb (fifo); | 1134 | *bufp++ = inb(fifo); |
1119 | left--; | 1135 | left--; |
1120 | } | 1136 | } |
1121 | 1137 | ||
1122 | port->ieee1284.phase = IEEE1284_PH_REV_IDLE; | 1138 | port->ieee1284.phase = IEEE1284_PH_REV_IDLE; |
1123 | dump_parport_state ("rev idle2", port); | 1139 | dump_parport_state("rev idle2", port); |
1124 | 1140 | ||
1125 | out_no_data: | 1141 | out_no_data: |
1126 | 1142 | ||
1127 | /* Go to forward idle mode to shut the peripheral up (event 47). */ | 1143 | /* Go to forward idle mode to shut the peripheral up (event 47). */ |
1128 | parport_frob_control (port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT); | 1144 | parport_frob_control(port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT); |
1129 | 1145 | ||
1130 | /* event 49: PError goes high */ | 1146 | /* event 49: PError goes high */ |
1131 | r = parport_wait_peripheral (port, | 1147 | r = parport_wait_peripheral(port, |
1132 | PARPORT_STATUS_PAPEROUT, | 1148 | PARPORT_STATUS_PAPEROUT, |
1133 | PARPORT_STATUS_PAPEROUT); | 1149 | PARPORT_STATUS_PAPEROUT); |
1134 | if (r) { | 1150 | if (r) { |
1135 | printk (KERN_DEBUG | 1151 | printk(KERN_DEBUG |
1136 | "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n", | 1152 | "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n", |
1137 | port->name, r); | 1153 | port->name, r); |
1138 | } | 1154 | } |
@@ -1141,14 +1157,14 @@ out_no_data: | |||
1141 | 1157 | ||
1142 | /* Finish up. */ | 1158 | /* Finish up. */ |
1143 | { | 1159 | { |
1144 | int lost = get_fifo_residue (port); | 1160 | int lost = get_fifo_residue(port); |
1145 | if (lost) | 1161 | if (lost) |
1146 | /* Shouldn't happen with compliant peripherals. */ | 1162 | /* Shouldn't happen with compliant peripherals. */ |
1147 | printk (KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n", | 1163 | printk(KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n", |
1148 | port->name, lost); | 1164 | port->name, lost); |
1149 | } | 1165 | } |
1150 | 1166 | ||
1151 | dump_parport_state ("fwd idle", port); | 1167 | dump_parport_state("fwd idle", port); |
1152 | return length - left; | 1168 | return length - left; |
1153 | } | 1169 | } |
1154 | #endif /* 0 */ | 1170 | #endif /* 0 */ |
@@ -1164,8 +1180,7 @@ dump_parport_state ("fwd idle", port); | |||
1164 | 1180 | ||
1165 | /* GCC is not inlining extern inline function later overwriten to non-inline, | 1181 | /* GCC is not inlining extern inline function later overwriten to non-inline, |
1166 | so we use outlined_ variants here. */ | 1182 | so we use outlined_ variants here. */ |
1167 | static const struct parport_operations parport_pc_ops = | 1183 | static const struct parport_operations parport_pc_ops = { |
1168 | { | ||
1169 | .write_data = parport_pc_write_data, | 1184 | .write_data = parport_pc_write_data, |
1170 | .read_data = parport_pc_read_data, | 1185 | .read_data = parport_pc_read_data, |
1171 | 1186 | ||
@@ -1202,88 +1217,107 @@ static const struct parport_operations parport_pc_ops = | |||
1202 | }; | 1217 | }; |
1203 | 1218 | ||
1204 | #ifdef CONFIG_PARPORT_PC_SUPERIO | 1219 | #ifdef CONFIG_PARPORT_PC_SUPERIO |
1220 | |||
1221 | static struct superio_struct *find_free_superio(void) | ||
1222 | { | ||
1223 | int i; | ||
1224 | for (i = 0; i < NR_SUPERIOS; i++) | ||
1225 | if (superios[i].io == 0) | ||
1226 | return &superios[i]; | ||
1227 | return NULL; | ||
1228 | } | ||
1229 | |||
1230 | |||
1205 | /* Super-IO chipset detection, Winbond, SMSC */ | 1231 | /* Super-IO chipset detection, Winbond, SMSC */ |
1206 | static void __devinit show_parconfig_smsc37c669(int io, int key) | 1232 | static void __devinit show_parconfig_smsc37c669(int io, int key) |
1207 | { | 1233 | { |
1208 | int cr1,cr4,cra,cr23,cr26,cr27,i=0; | 1234 | int cr1, cr4, cra, cr23, cr26, cr27; |
1209 | static const char *const modes[]={ | 1235 | struct superio_struct *s; |
1236 | |||
1237 | static const char *const modes[] = { | ||
1210 | "SPP and Bidirectional (PS/2)", | 1238 | "SPP and Bidirectional (PS/2)", |
1211 | "EPP and SPP", | 1239 | "EPP and SPP", |
1212 | "ECP", | 1240 | "ECP", |
1213 | "ECP and EPP" }; | 1241 | "ECP and EPP" }; |
1214 | 1242 | ||
1215 | outb(key,io); | 1243 | outb(key, io); |
1216 | outb(key,io); | 1244 | outb(key, io); |
1217 | outb(1,io); | 1245 | outb(1, io); |
1218 | cr1=inb(io+1); | 1246 | cr1 = inb(io + 1); |
1219 | outb(4,io); | 1247 | outb(4, io); |
1220 | cr4=inb(io+1); | 1248 | cr4 = inb(io + 1); |
1221 | outb(0x0a,io); | 1249 | outb(0x0a, io); |
1222 | cra=inb(io+1); | 1250 | cra = inb(io + 1); |
1223 | outb(0x23,io); | 1251 | outb(0x23, io); |
1224 | cr23=inb(io+1); | 1252 | cr23 = inb(io + 1); |
1225 | outb(0x26,io); | 1253 | outb(0x26, io); |
1226 | cr26=inb(io+1); | 1254 | cr26 = inb(io + 1); |
1227 | outb(0x27,io); | 1255 | outb(0x27, io); |
1228 | cr27=inb(io+1); | 1256 | cr27 = inb(io + 1); |
1229 | outb(0xaa,io); | 1257 | outb(0xaa, io); |
1230 | 1258 | ||
1231 | if (verbose_probing) { | 1259 | if (verbose_probing) { |
1232 | printk (KERN_INFO "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, " | 1260 | printk(KERN_INFO |
1261 | "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, " | ||
1233 | "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n", | 1262 | "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n", |
1234 | cr1,cr4,cra,cr23,cr26,cr27); | 1263 | cr1, cr4, cra, cr23, cr26, cr27); |
1235 | 1264 | ||
1236 | /* The documentation calls DMA and IRQ-Lines by letters, so | 1265 | /* The documentation calls DMA and IRQ-Lines by letters, so |
1237 | the board maker can/will wire them | 1266 | the board maker can/will wire them |
1238 | appropriately/randomly... G=reserved H=IDE-irq, */ | 1267 | appropriately/randomly... G=reserved H=IDE-irq, */ |
1239 | printk (KERN_INFO "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, " | 1268 | printk(KERN_INFO |
1240 | "fifo threshold=%d\n", cr23*4, | 1269 | "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, fifo threshold=%d\n", |
1241 | (cr27 &0x0f) ? 'A'-1+(cr27 &0x0f): '-', | 1270 | cr23 * 4, |
1242 | (cr26 &0x0f) ? 'A'-1+(cr26 &0x0f): '-', cra & 0x0f); | 1271 | (cr27 & 0x0f) ? 'A' - 1 + (cr27 & 0x0f) : '-', |
1272 | (cr26 & 0x0f) ? 'A' - 1 + (cr26 & 0x0f) : '-', | ||
1273 | cra & 0x0f); | ||
1243 | printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n", | 1274 | printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n", |
1244 | (cr23*4 >=0x100) ?"yes":"no", (cr1 & 4) ? "yes" : "no"); | 1275 | (cr23 * 4 >= 0x100) ? "yes" : "no", |
1245 | printk(KERN_INFO "SMSC LPT Config: Port mode=%s, EPP version =%s\n", | 1276 | (cr1 & 4) ? "yes" : "no"); |
1246 | (cr1 & 0x08 ) ? "Standard mode only (SPP)" : modes[cr4 & 0x03], | 1277 | printk(KERN_INFO |
1247 | (cr4 & 0x40) ? "1.7" : "1.9"); | 1278 | "SMSC LPT Config: Port mode=%s, EPP version =%s\n", |
1279 | (cr1 & 0x08) ? "Standard mode only (SPP)" | ||
1280 | : modes[cr4 & 0x03], | ||
1281 | (cr4 & 0x40) ? "1.7" : "1.9"); | ||
1248 | } | 1282 | } |
1249 | 1283 | ||
1250 | /* Heuristics ! BIOS setup for this mainboard device limits | 1284 | /* Heuristics ! BIOS setup for this mainboard device limits |
1251 | the choices to standard settings, i.e. io-address and IRQ | 1285 | the choices to standard settings, i.e. io-address and IRQ |
1252 | are related, however DMA can be 1 or 3, assume DMA_A=DMA1, | 1286 | are related, however DMA can be 1 or 3, assume DMA_A=DMA1, |
1253 | DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */ | 1287 | DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */ |
1254 | if(cr23*4 >=0x100) { /* if active */ | 1288 | if (cr23 * 4 >= 0x100) { /* if active */ |
1255 | while((superios[i].io!= 0) && (i<NR_SUPERIOS)) | 1289 | s = find_free_superio(); |
1256 | i++; | 1290 | if (s == NULL) |
1257 | if(i==NR_SUPERIOS) | ||
1258 | printk(KERN_INFO "Super-IO: too many chips!\n"); | 1291 | printk(KERN_INFO "Super-IO: too many chips!\n"); |
1259 | else { | 1292 | else { |
1260 | int d; | 1293 | int d; |
1261 | switch (cr23*4) { | 1294 | switch (cr23 * 4) { |
1262 | case 0x3bc: | 1295 | case 0x3bc: |
1263 | superios[i].io = 0x3bc; | 1296 | s->io = 0x3bc; |
1264 | superios[i].irq = 7; | 1297 | s->irq = 7; |
1265 | break; | 1298 | break; |
1266 | case 0x378: | 1299 | case 0x378: |
1267 | superios[i].io = 0x378; | 1300 | s->io = 0x378; |
1268 | superios[i].irq = 7; | 1301 | s->irq = 7; |
1269 | break; | 1302 | break; |
1270 | case 0x278: | 1303 | case 0x278: |
1271 | superios[i].io = 0x278; | 1304 | s->io = 0x278; |
1272 | superios[i].irq = 5; | 1305 | s->irq = 5; |
1273 | } | 1306 | } |
1274 | d=(cr26 &0x0f); | 1307 | d = (cr26 & 0x0f); |
1275 | if((d==1) || (d==3)) | 1308 | if (d == 1 || d == 3) |
1276 | superios[i].dma= d; | 1309 | s->dma = d; |
1277 | else | 1310 | else |
1278 | superios[i].dma= PARPORT_DMA_NONE; | 1311 | s->dma = PARPORT_DMA_NONE; |
1279 | } | 1312 | } |
1280 | } | 1313 | } |
1281 | } | 1314 | } |
1282 | 1315 | ||
1283 | 1316 | ||
1284 | static void __devinit show_parconfig_winbond(int io, int key) | 1317 | static void __devinit show_parconfig_winbond(int io, int key) |
1285 | { | 1318 | { |
1286 | int cr30,cr60,cr61,cr70,cr74,crf0,i=0; | 1319 | int cr30, cr60, cr61, cr70, cr74, crf0; |
1320 | struct superio_struct *s; | ||
1287 | static const char *const modes[] = { | 1321 | static const char *const modes[] = { |
1288 | "Standard (SPP) and Bidirectional(PS/2)", /* 0 */ | 1322 | "Standard (SPP) and Bidirectional(PS/2)", /* 0 */ |
1289 | "EPP-1.9 and SPP", | 1323 | "EPP-1.9 and SPP", |
@@ -1296,110 +1330,134 @@ static void __devinit show_parconfig_winbond(int io, int key) | |||
1296 | static char *const irqtypes[] = { | 1330 | static char *const irqtypes[] = { |
1297 | "pulsed low, high-Z", | 1331 | "pulsed low, high-Z", |
1298 | "follows nACK" }; | 1332 | "follows nACK" }; |
1299 | 1333 | ||
1300 | /* The registers are called compatible-PnP because the | 1334 | /* The registers are called compatible-PnP because the |
1301 | register layout is modelled after ISA-PnP, the access | 1335 | register layout is modelled after ISA-PnP, the access |
1302 | method is just another ... */ | 1336 | method is just another ... */ |
1303 | outb(key,io); | 1337 | outb(key, io); |
1304 | outb(key,io); | 1338 | outb(key, io); |
1305 | outb(0x07,io); /* Register 7: Select Logical Device */ | 1339 | outb(0x07, io); /* Register 7: Select Logical Device */ |
1306 | outb(0x01,io+1); /* LD1 is Parallel Port */ | 1340 | outb(0x01, io + 1); /* LD1 is Parallel Port */ |
1307 | outb(0x30,io); | 1341 | outb(0x30, io); |
1308 | cr30=inb(io+1); | 1342 | cr30 = inb(io + 1); |
1309 | outb(0x60,io); | 1343 | outb(0x60, io); |
1310 | cr60=inb(io+1); | 1344 | cr60 = inb(io + 1); |
1311 | outb(0x61,io); | 1345 | outb(0x61, io); |
1312 | cr61=inb(io+1); | 1346 | cr61 = inb(io + 1); |
1313 | outb(0x70,io); | 1347 | outb(0x70, io); |
1314 | cr70=inb(io+1); | 1348 | cr70 = inb(io + 1); |
1315 | outb(0x74,io); | 1349 | outb(0x74, io); |
1316 | cr74=inb(io+1); | 1350 | cr74 = inb(io + 1); |
1317 | outb(0xf0,io); | 1351 | outb(0xf0, io); |
1318 | crf0=inb(io+1); | 1352 | crf0 = inb(io + 1); |
1319 | outb(0xaa,io); | 1353 | outb(0xaa, io); |
1320 | 1354 | ||
1321 | if (verbose_probing) { | 1355 | if (verbose_probing) { |
1322 | printk(KERN_INFO "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x " | 1356 | printk(KERN_INFO |
1323 | "70=%02x 74=%02x, f0=%02x\n", cr30,cr60,cr61,cr70,cr74,crf0); | 1357 | "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x 70=%02x 74=%02x, f0=%02x\n", |
1324 | printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ", | 1358 | cr30, cr60, cr61, cr70, cr74, crf0); |
1325 | (cr30 & 0x01) ? "yes":"no", cr60,cr61,cr70&0x0f ); | 1359 | printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ", |
1360 | (cr30 & 0x01) ? "yes" : "no", cr60, cr61, cr70 & 0x0f); | ||
1326 | if ((cr74 & 0x07) > 3) | 1361 | if ((cr74 & 0x07) > 3) |
1327 | printk("dma=none\n"); | 1362 | printk("dma=none\n"); |
1328 | else | 1363 | else |
1329 | printk("dma=%d\n",cr74 & 0x07); | 1364 | printk("dma=%d\n", cr74 & 0x07); |
1330 | printk(KERN_INFO "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n", | 1365 | printk(KERN_INFO |
1331 | irqtypes[crf0>>7], (crf0>>3)&0x0f); | 1366 | "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n", |
1332 | printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n", modes[crf0 & 0x07]); | 1367 | irqtypes[crf0>>7], (crf0>>3)&0x0f); |
1368 | printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n", | ||
1369 | modes[crf0 & 0x07]); | ||
1333 | } | 1370 | } |
1334 | 1371 | ||
1335 | if(cr30 & 0x01) { /* the settings can be interrogated later ... */ | 1372 | if (cr30 & 0x01) { /* the settings can be interrogated later ... */ |
1336 | while((superios[i].io!= 0) && (i<NR_SUPERIOS)) | 1373 | s = find_free_superio(); |
1337 | i++; | 1374 | if (s == NULL) |
1338 | if(i==NR_SUPERIOS) | ||
1339 | printk(KERN_INFO "Super-IO: too many chips!\n"); | 1375 | printk(KERN_INFO "Super-IO: too many chips!\n"); |
1340 | else { | 1376 | else { |
1341 | superios[i].io = (cr60<<8)|cr61; | 1377 | s->io = (cr60 << 8) | cr61; |
1342 | superios[i].irq = cr70&0x0f; | 1378 | s->irq = cr70 & 0x0f; |
1343 | superios[i].dma = (((cr74 & 0x07) > 3) ? | 1379 | s->dma = (((cr74 & 0x07) > 3) ? |
1344 | PARPORT_DMA_NONE : (cr74 & 0x07)); | 1380 | PARPORT_DMA_NONE : (cr74 & 0x07)); |
1345 | } | 1381 | } |
1346 | } | 1382 | } |
1347 | } | 1383 | } |
1348 | 1384 | ||
1349 | static void __devinit decode_winbond(int efer, int key, int devid, int devrev, int oldid) | 1385 | static void __devinit decode_winbond(int efer, int key, int devid, |
1386 | int devrev, int oldid) | ||
1350 | { | 1387 | { |
1351 | const char *type = "unknown"; | 1388 | const char *type = "unknown"; |
1352 | int id,progif=2; | 1389 | int id, progif = 2; |
1353 | 1390 | ||
1354 | if (devid == devrev) | 1391 | if (devid == devrev) |
1355 | /* simple heuristics, we happened to read some | 1392 | /* simple heuristics, we happened to read some |
1356 | non-winbond register */ | 1393 | non-winbond register */ |
1357 | return; | 1394 | return; |
1358 | 1395 | ||
1359 | id=(devid<<8) | devrev; | 1396 | id = (devid << 8) | devrev; |
1360 | 1397 | ||
1361 | /* Values are from public data sheets pdf files, I can just | 1398 | /* Values are from public data sheets pdf files, I can just |
1362 | confirm 83977TF is correct :-) */ | 1399 | confirm 83977TF is correct :-) */ |
1363 | if (id == 0x9771) type="83977F/AF"; | 1400 | if (id == 0x9771) |
1364 | else if (id == 0x9773) type="83977TF / SMSC 97w33x/97w34x"; | 1401 | type = "83977F/AF"; |
1365 | else if (id == 0x9774) type="83977ATF"; | 1402 | else if (id == 0x9773) |
1366 | else if ((id & ~0x0f) == 0x5270) type="83977CTF / SMSC 97w36x"; | 1403 | type = "83977TF / SMSC 97w33x/97w34x"; |
1367 | else if ((id & ~0x0f) == 0x52f0) type="83977EF / SMSC 97w35x"; | 1404 | else if (id == 0x9774) |
1368 | else if ((id & ~0x0f) == 0x5210) type="83627"; | 1405 | type = "83977ATF"; |
1369 | else if ((id & ~0x0f) == 0x6010) type="83697HF"; | 1406 | else if ((id & ~0x0f) == 0x5270) |
1370 | else if ((oldid &0x0f ) == 0x0a) { type="83877F"; progif=1;} | 1407 | type = "83977CTF / SMSC 97w36x"; |
1371 | else if ((oldid &0x0f ) == 0x0b) { type="83877AF"; progif=1;} | 1408 | else if ((id & ~0x0f) == 0x52f0) |
1372 | else if ((oldid &0x0f ) == 0x0c) { type="83877TF"; progif=1;} | 1409 | type = "83977EF / SMSC 97w35x"; |
1373 | else if ((oldid &0x0f ) == 0x0d) { type="83877ATF"; progif=1;} | 1410 | else if ((id & ~0x0f) == 0x5210) |
1374 | else progif=0; | 1411 | type = "83627"; |
1412 | else if ((id & ~0x0f) == 0x6010) | ||
1413 | type = "83697HF"; | ||
1414 | else if ((oldid & 0x0f) == 0x0a) { | ||
1415 | type = "83877F"; | ||
1416 | progif = 1; | ||
1417 | } else if ((oldid & 0x0f) == 0x0b) { | ||
1418 | type = "83877AF"; | ||
1419 | progif = 1; | ||
1420 | } else if ((oldid & 0x0f) == 0x0c) { | ||
1421 | type = "83877TF"; | ||
1422 | progif = 1; | ||
1423 | } else if ((oldid & 0x0f) == 0x0d) { | ||
1424 | type = "83877ATF"; | ||
1425 | progif = 1; | ||
1426 | } else | ||
1427 | progif = 0; | ||
1375 | 1428 | ||
1376 | if (verbose_probing) | 1429 | if (verbose_probing) |
1377 | printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x " | 1430 | printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x " |
1378 | "devid=%02x devrev=%02x oldid=%02x type=%s\n", | 1431 | "devid=%02x devrev=%02x oldid=%02x type=%s\n", |
1379 | efer, key, devid, devrev, oldid, type); | 1432 | efer, key, devid, devrev, oldid, type); |
1380 | 1433 | ||
1381 | if (progif == 2) | 1434 | if (progif == 2) |
1382 | show_parconfig_winbond(efer,key); | 1435 | show_parconfig_winbond(efer, key); |
1383 | } | 1436 | } |
1384 | 1437 | ||
1385 | static void __devinit decode_smsc(int efer, int key, int devid, int devrev) | 1438 | static void __devinit decode_smsc(int efer, int key, int devid, int devrev) |
1386 | { | 1439 | { |
1387 | const char *type = "unknown"; | 1440 | const char *type = "unknown"; |
1388 | void (*func)(int io, int key); | 1441 | void (*func)(int io, int key); |
1389 | int id; | 1442 | int id; |
1390 | 1443 | ||
1391 | if (devid == devrev) | 1444 | if (devid == devrev) |
1392 | /* simple heuristics, we happened to read some | 1445 | /* simple heuristics, we happened to read some |
1393 | non-smsc register */ | 1446 | non-smsc register */ |
1394 | return; | 1447 | return; |
1395 | 1448 | ||
1396 | func=NULL; | 1449 | func = NULL; |
1397 | id=(devid<<8) | devrev; | 1450 | id = (devid << 8) | devrev; |
1398 | 1451 | ||
1399 | if (id==0x0302) {type="37c669"; func=show_parconfig_smsc37c669;} | 1452 | if (id == 0x0302) { |
1400 | else if (id==0x6582) type="37c665IR"; | 1453 | type = "37c669"; |
1401 | else if (devid==0x65) type="37c665GT"; | 1454 | func = show_parconfig_smsc37c669; |
1402 | else if (devid==0x66) type="37c666GT"; | 1455 | } else if (id == 0x6582) |
1456 | type = "37c665IR"; | ||
1457 | else if (devid == 0x65) | ||
1458 | type = "37c665GT"; | ||
1459 | else if (devid == 0x66) | ||
1460 | type = "37c666GT"; | ||
1403 | 1461 | ||
1404 | if (verbose_probing) | 1462 | if (verbose_probing) |
1405 | printk(KERN_INFO "SMSC chip at EFER=0x%x " | 1463 | printk(KERN_INFO "SMSC chip at EFER=0x%x " |
@@ -1407,138 +1465,138 @@ static void __devinit decode_smsc(int efer, int key, int devid, int devrev) | |||
1407 | efer, key, devid, devrev, type); | 1465 | efer, key, devid, devrev, type); |
1408 | 1466 | ||
1409 | if (func) | 1467 | if (func) |
1410 | func(efer,key); | 1468 | func(efer, key); |
1411 | } | 1469 | } |
1412 | 1470 | ||
1413 | 1471 | ||
1414 | static void __devinit winbond_check(int io, int key) | 1472 | static void __devinit winbond_check(int io, int key) |
1415 | { | 1473 | { |
1416 | int devid,devrev,oldid,x_devid,x_devrev,x_oldid; | 1474 | int devid, devrev, oldid, x_devid, x_devrev, x_oldid; |
1417 | 1475 | ||
1418 | if (!request_region(io, 3, __func__)) | 1476 | if (!request_region(io, 3, __func__)) |
1419 | return; | 1477 | return; |
1420 | 1478 | ||
1421 | /* First probe without key */ | 1479 | /* First probe without key */ |
1422 | outb(0x20,io); | 1480 | outb(0x20, io); |
1423 | x_devid=inb(io+1); | 1481 | x_devid = inb(io + 1); |
1424 | outb(0x21,io); | 1482 | outb(0x21, io); |
1425 | x_devrev=inb(io+1); | 1483 | x_devrev = inb(io + 1); |
1426 | outb(0x09,io); | 1484 | outb(0x09, io); |
1427 | x_oldid=inb(io+1); | 1485 | x_oldid = inb(io + 1); |
1428 | 1486 | ||
1429 | outb(key,io); | 1487 | outb(key, io); |
1430 | outb(key,io); /* Write Magic Sequence to EFER, extended | 1488 | outb(key, io); /* Write Magic Sequence to EFER, extended |
1431 | funtion enable register */ | 1489 | funtion enable register */ |
1432 | outb(0x20,io); /* Write EFIR, extended function index register */ | 1490 | outb(0x20, io); /* Write EFIR, extended function index register */ |
1433 | devid=inb(io+1); /* Read EFDR, extended function data register */ | 1491 | devid = inb(io + 1); /* Read EFDR, extended function data register */ |
1434 | outb(0x21,io); | 1492 | outb(0x21, io); |
1435 | devrev=inb(io+1); | 1493 | devrev = inb(io + 1); |
1436 | outb(0x09,io); | 1494 | outb(0x09, io); |
1437 | oldid=inb(io+1); | 1495 | oldid = inb(io + 1); |
1438 | outb(0xaa,io); /* Magic Seal */ | 1496 | outb(0xaa, io); /* Magic Seal */ |
1439 | 1497 | ||
1440 | if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid)) | 1498 | if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid)) |
1441 | goto out; /* protection against false positives */ | 1499 | goto out; /* protection against false positives */ |
1442 | 1500 | ||
1443 | decode_winbond(io,key,devid,devrev,oldid); | 1501 | decode_winbond(io, key, devid, devrev, oldid); |
1444 | out: | 1502 | out: |
1445 | release_region(io, 3); | 1503 | release_region(io, 3); |
1446 | } | 1504 | } |
1447 | 1505 | ||
1448 | static void __devinit winbond_check2(int io,int key) | 1506 | static void __devinit winbond_check2(int io, int key) |
1449 | { | 1507 | { |
1450 | int devid,devrev,oldid,x_devid,x_devrev,x_oldid; | 1508 | int devid, devrev, oldid, x_devid, x_devrev, x_oldid; |
1451 | 1509 | ||
1452 | if (!request_region(io, 3, __func__)) | 1510 | if (!request_region(io, 3, __func__)) |
1453 | return; | 1511 | return; |
1454 | 1512 | ||
1455 | /* First probe without the key */ | 1513 | /* First probe without the key */ |
1456 | outb(0x20,io+2); | 1514 | outb(0x20, io + 2); |
1457 | x_devid=inb(io+2); | 1515 | x_devid = inb(io + 2); |
1458 | outb(0x21,io+1); | 1516 | outb(0x21, io + 1); |
1459 | x_devrev=inb(io+2); | 1517 | x_devrev = inb(io + 2); |
1460 | outb(0x09,io+1); | 1518 | outb(0x09, io + 1); |
1461 | x_oldid=inb(io+2); | 1519 | x_oldid = inb(io + 2); |
1462 | 1520 | ||
1463 | outb(key,io); /* Write Magic Byte to EFER, extended | 1521 | outb(key, io); /* Write Magic Byte to EFER, extended |
1464 | funtion enable register */ | 1522 | funtion enable register */ |
1465 | outb(0x20,io+2); /* Write EFIR, extended function index register */ | 1523 | outb(0x20, io + 2); /* Write EFIR, extended function index register */ |
1466 | devid=inb(io+2); /* Read EFDR, extended function data register */ | 1524 | devid = inb(io + 2); /* Read EFDR, extended function data register */ |
1467 | outb(0x21,io+1); | 1525 | outb(0x21, io + 1); |
1468 | devrev=inb(io+2); | 1526 | devrev = inb(io + 2); |
1469 | outb(0x09,io+1); | 1527 | outb(0x09, io + 1); |
1470 | oldid=inb(io+2); | 1528 | oldid = inb(io + 2); |
1471 | outb(0xaa,io); /* Magic Seal */ | 1529 | outb(0xaa, io); /* Magic Seal */ |
1472 | 1530 | ||
1473 | if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid)) | 1531 | if (x_devid == devid && x_devrev == devrev && x_oldid == oldid) |
1474 | goto out; /* protection against false positives */ | 1532 | goto out; /* protection against false positives */ |
1475 | 1533 | ||
1476 | decode_winbond(io,key,devid,devrev,oldid); | 1534 | decode_winbond(io, key, devid, devrev, oldid); |
1477 | out: | 1535 | out: |
1478 | release_region(io, 3); | 1536 | release_region(io, 3); |
1479 | } | 1537 | } |
1480 | 1538 | ||
1481 | static void __devinit smsc_check(int io, int key) | 1539 | static void __devinit smsc_check(int io, int key) |
1482 | { | 1540 | { |
1483 | int id,rev,oldid,oldrev,x_id,x_rev,x_oldid,x_oldrev; | 1541 | int id, rev, oldid, oldrev, x_id, x_rev, x_oldid, x_oldrev; |
1484 | 1542 | ||
1485 | if (!request_region(io, 3, __func__)) | 1543 | if (!request_region(io, 3, __func__)) |
1486 | return; | 1544 | return; |
1487 | 1545 | ||
1488 | /* First probe without the key */ | 1546 | /* First probe without the key */ |
1489 | outb(0x0d,io); | 1547 | outb(0x0d, io); |
1490 | x_oldid=inb(io+1); | 1548 | x_oldid = inb(io + 1); |
1491 | outb(0x0e,io); | 1549 | outb(0x0e, io); |
1492 | x_oldrev=inb(io+1); | 1550 | x_oldrev = inb(io + 1); |
1493 | outb(0x20,io); | 1551 | outb(0x20, io); |
1494 | x_id=inb(io+1); | 1552 | x_id = inb(io + 1); |
1495 | outb(0x21,io); | 1553 | outb(0x21, io); |
1496 | x_rev=inb(io+1); | 1554 | x_rev = inb(io + 1); |
1497 | 1555 | ||
1498 | outb(key,io); | 1556 | outb(key, io); |
1499 | outb(key,io); /* Write Magic Sequence to EFER, extended | 1557 | outb(key, io); /* Write Magic Sequence to EFER, extended |
1500 | funtion enable register */ | 1558 | funtion enable register */ |
1501 | outb(0x0d,io); /* Write EFIR, extended function index register */ | 1559 | outb(0x0d, io); /* Write EFIR, extended function index register */ |
1502 | oldid=inb(io+1); /* Read EFDR, extended function data register */ | 1560 | oldid = inb(io + 1); /* Read EFDR, extended function data register */ |
1503 | outb(0x0e,io); | 1561 | outb(0x0e, io); |
1504 | oldrev=inb(io+1); | 1562 | oldrev = inb(io + 1); |
1505 | outb(0x20,io); | 1563 | outb(0x20, io); |
1506 | id=inb(io+1); | 1564 | id = inb(io + 1); |
1507 | outb(0x21,io); | 1565 | outb(0x21, io); |
1508 | rev=inb(io+1); | 1566 | rev = inb(io + 1); |
1509 | outb(0xaa,io); /* Magic Seal */ | 1567 | outb(0xaa, io); /* Magic Seal */ |
1510 | 1568 | ||
1511 | if ((x_id == id) && (x_oldrev == oldrev) && | 1569 | if (x_id == id && x_oldrev == oldrev && |
1512 | (x_oldid == oldid) && (x_rev == rev)) | 1570 | x_oldid == oldid && x_rev == rev) |
1513 | goto out; /* protection against false positives */ | 1571 | goto out; /* protection against false positives */ |
1514 | 1572 | ||
1515 | decode_smsc(io,key,oldid,oldrev); | 1573 | decode_smsc(io, key, oldid, oldrev); |
1516 | out: | 1574 | out: |
1517 | release_region(io, 3); | 1575 | release_region(io, 3); |
1518 | } | 1576 | } |
1519 | 1577 | ||
1520 | 1578 | ||
1521 | static void __devinit detect_and_report_winbond (void) | 1579 | static void __devinit detect_and_report_winbond(void) |
1522 | { | 1580 | { |
1523 | if (verbose_probing) | 1581 | if (verbose_probing) |
1524 | printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n"); | 1582 | printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n"); |
1525 | winbond_check(0x3f0,0x87); | 1583 | winbond_check(0x3f0, 0x87); |
1526 | winbond_check(0x370,0x87); | 1584 | winbond_check(0x370, 0x87); |
1527 | winbond_check(0x2e ,0x87); | 1585 | winbond_check(0x2e , 0x87); |
1528 | winbond_check(0x4e ,0x87); | 1586 | winbond_check(0x4e , 0x87); |
1529 | winbond_check(0x3f0,0x86); | 1587 | winbond_check(0x3f0, 0x86); |
1530 | winbond_check2(0x250,0x88); | 1588 | winbond_check2(0x250, 0x88); |
1531 | winbond_check2(0x250,0x89); | 1589 | winbond_check2(0x250, 0x89); |
1532 | } | 1590 | } |
1533 | 1591 | ||
1534 | static void __devinit detect_and_report_smsc (void) | 1592 | static void __devinit detect_and_report_smsc(void) |
1535 | { | 1593 | { |
1536 | if (verbose_probing) | 1594 | if (verbose_probing) |
1537 | printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n"); | 1595 | printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n"); |
1538 | smsc_check(0x3f0,0x55); | 1596 | smsc_check(0x3f0, 0x55); |
1539 | smsc_check(0x370,0x55); | 1597 | smsc_check(0x370, 0x55); |
1540 | smsc_check(0x3f0,0x44); | 1598 | smsc_check(0x3f0, 0x44); |
1541 | smsc_check(0x370,0x44); | 1599 | smsc_check(0x370, 0x44); |
1542 | } | 1600 | } |
1543 | 1601 | ||
1544 | static void __devinit detect_and_report_it87(void) | 1602 | static void __devinit detect_and_report_it87(void) |
@@ -1573,34 +1631,39 @@ static void __devinit detect_and_report_it87(void) | |||
1573 | } | 1631 | } |
1574 | #endif /* CONFIG_PARPORT_PC_SUPERIO */ | 1632 | #endif /* CONFIG_PARPORT_PC_SUPERIO */ |
1575 | 1633 | ||
1576 | static int get_superio_dma (struct parport *p) | 1634 | static struct superio_struct *find_superio(struct parport *p) |
1577 | { | 1635 | { |
1578 | int i=0; | 1636 | int i; |
1579 | while( (superios[i].io != p->base) && (i<NR_SUPERIOS)) | 1637 | for (i = 0; i < NR_SUPERIOS; i++) |
1580 | i++; | 1638 | if (superios[i].io != p->base) |
1581 | if (i!=NR_SUPERIOS) | 1639 | return &superios[i]; |
1582 | return superios[i].dma; | 1640 | return NULL; |
1641 | } | ||
1642 | |||
1643 | static int get_superio_dma(struct parport *p) | ||
1644 | { | ||
1645 | struct superio_struct *s = find_superio(p); | ||
1646 | if (s) | ||
1647 | return s->dma; | ||
1583 | return PARPORT_DMA_NONE; | 1648 | return PARPORT_DMA_NONE; |
1584 | } | 1649 | } |
1585 | 1650 | ||
1586 | static int get_superio_irq (struct parport *p) | 1651 | static int get_superio_irq(struct parport *p) |
1587 | { | 1652 | { |
1588 | int i=0; | 1653 | struct superio_struct *s = find_superio(p); |
1589 | while( (superios[i].io != p->base) && (i<NR_SUPERIOS)) | 1654 | if (s) |
1590 | i++; | 1655 | return s->irq; |
1591 | if (i!=NR_SUPERIOS) | 1656 | return PARPORT_IRQ_NONE; |
1592 | return superios[i].irq; | ||
1593 | return PARPORT_IRQ_NONE; | ||
1594 | } | 1657 | } |
1595 | 1658 | ||
1596 | 1659 | ||
1597 | /* --- Mode detection ------------------------------------- */ | 1660 | /* --- Mode detection ------------------------------------- */ |
1598 | 1661 | ||
1599 | /* | 1662 | /* |
1600 | * Checks for port existence, all ports support SPP MODE | 1663 | * Checks for port existence, all ports support SPP MODE |
1601 | * Returns: | 1664 | * Returns: |
1602 | * 0 : No parallel port at this address | 1665 | * 0 : No parallel port at this address |
1603 | * PARPORT_MODE_PCSPP : SPP port detected | 1666 | * PARPORT_MODE_PCSPP : SPP port detected |
1604 | * (if the user specified an ioport himself, | 1667 | * (if the user specified an ioport himself, |
1605 | * this shall always be the case!) | 1668 | * this shall always be the case!) |
1606 | * | 1669 | * |
@@ -1610,7 +1673,7 @@ static int parport_SPP_supported(struct parport *pb) | |||
1610 | unsigned char r, w; | 1673 | unsigned char r, w; |
1611 | 1674 | ||
1612 | /* | 1675 | /* |
1613 | * first clear an eventually pending EPP timeout | 1676 | * first clear an eventually pending EPP timeout |
1614 | * I (sailer@ife.ee.ethz.ch) have an SMSC chipset | 1677 | * I (sailer@ife.ee.ethz.ch) have an SMSC chipset |
1615 | * that does not even respond to SPP cycles if an EPP | 1678 | * that does not even respond to SPP cycles if an EPP |
1616 | * timeout is pending | 1679 | * timeout is pending |
@@ -1619,19 +1682,19 @@ static int parport_SPP_supported(struct parport *pb) | |||
1619 | 1682 | ||
1620 | /* Do a simple read-write test to make sure the port exists. */ | 1683 | /* Do a simple read-write test to make sure the port exists. */ |
1621 | w = 0xc; | 1684 | w = 0xc; |
1622 | outb (w, CONTROL (pb)); | 1685 | outb(w, CONTROL(pb)); |
1623 | 1686 | ||
1624 | /* Is there a control register that we can read from? Some | 1687 | /* Is there a control register that we can read from? Some |
1625 | * ports don't allow reads, so read_control just returns a | 1688 | * ports don't allow reads, so read_control just returns a |
1626 | * software copy. Some ports _do_ allow reads, so bypass the | 1689 | * software copy. Some ports _do_ allow reads, so bypass the |
1627 | * software copy here. In addition, some bits aren't | 1690 | * software copy here. In addition, some bits aren't |
1628 | * writable. */ | 1691 | * writable. */ |
1629 | r = inb (CONTROL (pb)); | 1692 | r = inb(CONTROL(pb)); |
1630 | if ((r & 0xf) == w) { | 1693 | if ((r & 0xf) == w) { |
1631 | w = 0xe; | 1694 | w = 0xe; |
1632 | outb (w, CONTROL (pb)); | 1695 | outb(w, CONTROL(pb)); |
1633 | r = inb (CONTROL (pb)); | 1696 | r = inb(CONTROL(pb)); |
1634 | outb (0xc, CONTROL (pb)); | 1697 | outb(0xc, CONTROL(pb)); |
1635 | if ((r & 0xf) == w) | 1698 | if ((r & 0xf) == w) |
1636 | return PARPORT_MODE_PCSPP; | 1699 | return PARPORT_MODE_PCSPP; |
1637 | } | 1700 | } |
@@ -1639,18 +1702,18 @@ static int parport_SPP_supported(struct parport *pb) | |||
1639 | if (user_specified) | 1702 | if (user_specified) |
1640 | /* That didn't work, but the user thinks there's a | 1703 | /* That didn't work, but the user thinks there's a |
1641 | * port here. */ | 1704 | * port here. */ |
1642 | printk (KERN_INFO "parport 0x%lx (WARNING): CTR: " | 1705 | printk(KERN_INFO "parport 0x%lx (WARNING): CTR: " |
1643 | "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); | 1706 | "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); |
1644 | 1707 | ||
1645 | /* Try the data register. The data lines aren't tri-stated at | 1708 | /* Try the data register. The data lines aren't tri-stated at |
1646 | * this stage, so we expect back what we wrote. */ | 1709 | * this stage, so we expect back what we wrote. */ |
1647 | w = 0xaa; | 1710 | w = 0xaa; |
1648 | parport_pc_write_data (pb, w); | 1711 | parport_pc_write_data(pb, w); |
1649 | r = parport_pc_read_data (pb); | 1712 | r = parport_pc_read_data(pb); |
1650 | if (r == w) { | 1713 | if (r == w) { |
1651 | w = 0x55; | 1714 | w = 0x55; |
1652 | parport_pc_write_data (pb, w); | 1715 | parport_pc_write_data(pb, w); |
1653 | r = parport_pc_read_data (pb); | 1716 | r = parport_pc_read_data(pb); |
1654 | if (r == w) | 1717 | if (r == w) |
1655 | return PARPORT_MODE_PCSPP; | 1718 | return PARPORT_MODE_PCSPP; |
1656 | } | 1719 | } |
@@ -1658,9 +1721,9 @@ static int parport_SPP_supported(struct parport *pb) | |||
1658 | if (user_specified) { | 1721 | if (user_specified) { |
1659 | /* Didn't work, but the user is convinced this is the | 1722 | /* Didn't work, but the user is convinced this is the |
1660 | * place. */ | 1723 | * place. */ |
1661 | printk (KERN_INFO "parport 0x%lx (WARNING): DATA: " | 1724 | printk(KERN_INFO "parport 0x%lx (WARNING): DATA: " |
1662 | "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); | 1725 | "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); |
1663 | printk (KERN_INFO "parport 0x%lx: You gave this address, " | 1726 | printk(KERN_INFO "parport 0x%lx: You gave this address, " |
1664 | "but there is probably no parallel port there!\n", | 1727 | "but there is probably no parallel port there!\n", |
1665 | pb->base); | 1728 | pb->base); |
1666 | } | 1729 | } |
@@ -1691,33 +1754,33 @@ static int parport_ECR_present(struct parport *pb) | |||
1691 | struct parport_pc_private *priv = pb->private_data; | 1754 | struct parport_pc_private *priv = pb->private_data; |
1692 | unsigned char r = 0xc; | 1755 | unsigned char r = 0xc; |
1693 | 1756 | ||
1694 | outb (r, CONTROL (pb)); | 1757 | outb(r, CONTROL(pb)); |
1695 | if ((inb (ECONTROL (pb)) & 0x3) == (r & 0x3)) { | 1758 | if ((inb(ECONTROL(pb)) & 0x3) == (r & 0x3)) { |
1696 | outb (r ^ 0x2, CONTROL (pb)); /* Toggle bit 1 */ | 1759 | outb(r ^ 0x2, CONTROL(pb)); /* Toggle bit 1 */ |
1697 | 1760 | ||
1698 | r = inb (CONTROL (pb)); | 1761 | r = inb(CONTROL(pb)); |
1699 | if ((inb (ECONTROL (pb)) & 0x2) == (r & 0x2)) | 1762 | if ((inb(ECONTROL(pb)) & 0x2) == (r & 0x2)) |
1700 | goto no_reg; /* Sure that no ECR register exists */ | 1763 | goto no_reg; /* Sure that no ECR register exists */ |
1701 | } | 1764 | } |
1702 | 1765 | ||
1703 | if ((inb (ECONTROL (pb)) & 0x3 ) != 0x1) | 1766 | if ((inb(ECONTROL(pb)) & 0x3) != 0x1) |
1704 | goto no_reg; | 1767 | goto no_reg; |
1705 | 1768 | ||
1706 | ECR_WRITE (pb, 0x34); | 1769 | ECR_WRITE(pb, 0x34); |
1707 | if (inb (ECONTROL (pb)) != 0x35) | 1770 | if (inb(ECONTROL(pb)) != 0x35) |
1708 | goto no_reg; | 1771 | goto no_reg; |
1709 | 1772 | ||
1710 | priv->ecr = 1; | 1773 | priv->ecr = 1; |
1711 | outb (0xc, CONTROL (pb)); | 1774 | outb(0xc, CONTROL(pb)); |
1712 | 1775 | ||
1713 | /* Go to mode 000 */ | 1776 | /* Go to mode 000 */ |
1714 | frob_set_mode (pb, ECR_SPP); | 1777 | frob_set_mode(pb, ECR_SPP); |
1715 | 1778 | ||
1716 | return 1; | 1779 | return 1; |
1717 | 1780 | ||
1718 | no_reg: | 1781 | no_reg: |
1719 | outb (0xc, CONTROL (pb)); | 1782 | outb(0xc, CONTROL(pb)); |
1720 | return 0; | 1783 | return 0; |
1721 | } | 1784 | } |
1722 | 1785 | ||
1723 | #ifdef CONFIG_PARPORT_1284 | 1786 | #ifdef CONFIG_PARPORT_1284 |
@@ -1727,7 +1790,7 @@ static int parport_ECR_present(struct parport *pb) | |||
1727 | * allows us to read data from the data lines. In theory we would get back | 1790 | * allows us to read data from the data lines. In theory we would get back |
1728 | * 0xff but any peripheral attached to the port may drag some or all of the | 1791 | * 0xff but any peripheral attached to the port may drag some or all of the |
1729 | * lines down to zero. So if we get back anything that isn't the contents | 1792 | * lines down to zero. So if we get back anything that isn't the contents |
1730 | * of the data register we deem PS/2 support to be present. | 1793 | * of the data register we deem PS/2 support to be present. |
1731 | * | 1794 | * |
1732 | * Some SPP ports have "half PS/2" ability - you can't turn off the line | 1795 | * Some SPP ports have "half PS/2" ability - you can't turn off the line |
1733 | * drivers, but an external peripheral with sufficiently beefy drivers of | 1796 | * drivers, but an external peripheral with sufficiently beefy drivers of |
@@ -1735,26 +1798,28 @@ static int parport_ECR_present(struct parport *pb) | |||
1735 | * where they can then be read back as normal. Ports with this property | 1798 | * where they can then be read back as normal. Ports with this property |
1736 | * and the right type of device attached are likely to fail the SPP test, | 1799 | * and the right type of device attached are likely to fail the SPP test, |
1737 | * (as they will appear to have stuck bits) and so the fact that they might | 1800 | * (as they will appear to have stuck bits) and so the fact that they might |
1738 | * be misdetected here is rather academic. | 1801 | * be misdetected here is rather academic. |
1739 | */ | 1802 | */ |
1740 | 1803 | ||
1741 | static int parport_PS2_supported(struct parport *pb) | 1804 | static int parport_PS2_supported(struct parport *pb) |
1742 | { | 1805 | { |
1743 | int ok = 0; | 1806 | int ok = 0; |
1744 | 1807 | ||
1745 | clear_epp_timeout(pb); | 1808 | clear_epp_timeout(pb); |
1746 | 1809 | ||
1747 | /* try to tri-state the buffer */ | 1810 | /* try to tri-state the buffer */ |
1748 | parport_pc_data_reverse (pb); | 1811 | parport_pc_data_reverse(pb); |
1749 | 1812 | ||
1750 | parport_pc_write_data(pb, 0x55); | 1813 | parport_pc_write_data(pb, 0x55); |
1751 | if (parport_pc_read_data(pb) != 0x55) ok++; | 1814 | if (parport_pc_read_data(pb) != 0x55) |
1815 | ok++; | ||
1752 | 1816 | ||
1753 | parport_pc_write_data(pb, 0xaa); | 1817 | parport_pc_write_data(pb, 0xaa); |
1754 | if (parport_pc_read_data(pb) != 0xaa) ok++; | 1818 | if (parport_pc_read_data(pb) != 0xaa) |
1819 | ok++; | ||
1755 | 1820 | ||
1756 | /* cancel input mode */ | 1821 | /* cancel input mode */ |
1757 | parport_pc_data_forward (pb); | 1822 | parport_pc_data_forward(pb); |
1758 | 1823 | ||
1759 | if (ok) { | 1824 | if (ok) { |
1760 | pb->modes |= PARPORT_MODE_TRISTATE; | 1825 | pb->modes |= PARPORT_MODE_TRISTATE; |
@@ -1773,68 +1838,68 @@ static int parport_ECP_supported(struct parport *pb) | |||
1773 | int config, configb; | 1838 | int config, configb; |
1774 | int pword; | 1839 | int pword; |
1775 | struct parport_pc_private *priv = pb->private_data; | 1840 | struct parport_pc_private *priv = pb->private_data; |
1776 | /* Translate ECP intrLine to ISA irq value */ | 1841 | /* Translate ECP intrLine to ISA irq value */ |
1777 | static const int intrline[]= { 0, 7, 9, 10, 11, 14, 15, 5 }; | 1842 | static const int intrline[] = { 0, 7, 9, 10, 11, 14, 15, 5 }; |
1778 | 1843 | ||
1779 | /* If there is no ECR, we have no hope of supporting ECP. */ | 1844 | /* If there is no ECR, we have no hope of supporting ECP. */ |
1780 | if (!priv->ecr) | 1845 | if (!priv->ecr) |
1781 | return 0; | 1846 | return 0; |
1782 | 1847 | ||
1783 | /* Find out FIFO depth */ | 1848 | /* Find out FIFO depth */ |
1784 | ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ | 1849 | ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */ |
1785 | ECR_WRITE (pb, ECR_TST << 5); /* TEST FIFO */ | 1850 | ECR_WRITE(pb, ECR_TST << 5); /* TEST FIFO */ |
1786 | for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02); i++) | 1851 | for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02); i++) |
1787 | outb (0xaa, FIFO (pb)); | 1852 | outb(0xaa, FIFO(pb)); |
1788 | 1853 | ||
1789 | /* | 1854 | /* |
1790 | * Using LGS chipset it uses ECR register, but | 1855 | * Using LGS chipset it uses ECR register, but |
1791 | * it doesn't support ECP or FIFO MODE | 1856 | * it doesn't support ECP or FIFO MODE |
1792 | */ | 1857 | */ |
1793 | if (i == 1024) { | 1858 | if (i == 1024) { |
1794 | ECR_WRITE (pb, ECR_SPP << 5); | 1859 | ECR_WRITE(pb, ECR_SPP << 5); |
1795 | return 0; | 1860 | return 0; |
1796 | } | 1861 | } |
1797 | 1862 | ||
1798 | priv->fifo_depth = i; | 1863 | priv->fifo_depth = i; |
1799 | if (verbose_probing) | 1864 | if (verbose_probing) |
1800 | printk (KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i); | 1865 | printk(KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i); |
1801 | 1866 | ||
1802 | /* Find out writeIntrThreshold */ | 1867 | /* Find out writeIntrThreshold */ |
1803 | frob_econtrol (pb, 1<<2, 1<<2); | 1868 | frob_econtrol(pb, 1<<2, 1<<2); |
1804 | frob_econtrol (pb, 1<<2, 0); | 1869 | frob_econtrol(pb, 1<<2, 0); |
1805 | for (i = 1; i <= priv->fifo_depth; i++) { | 1870 | for (i = 1; i <= priv->fifo_depth; i++) { |
1806 | inb (FIFO (pb)); | 1871 | inb(FIFO(pb)); |
1807 | udelay (50); | 1872 | udelay(50); |
1808 | if (inb (ECONTROL (pb)) & (1<<2)) | 1873 | if (inb(ECONTROL(pb)) & (1<<2)) |
1809 | break; | 1874 | break; |
1810 | } | 1875 | } |
1811 | 1876 | ||
1812 | if (i <= priv->fifo_depth) { | 1877 | if (i <= priv->fifo_depth) { |
1813 | if (verbose_probing) | 1878 | if (verbose_probing) |
1814 | printk (KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n", | 1879 | printk(KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n", |
1815 | pb->base, i); | 1880 | pb->base, i); |
1816 | } else | 1881 | } else |
1817 | /* Number of bytes we know we can write if we get an | 1882 | /* Number of bytes we know we can write if we get an |
1818 | interrupt. */ | 1883 | interrupt. */ |
1819 | i = 0; | 1884 | i = 0; |
1820 | 1885 | ||
1821 | priv->writeIntrThreshold = i; | 1886 | priv->writeIntrThreshold = i; |
1822 | 1887 | ||
1823 | /* Find out readIntrThreshold */ | 1888 | /* Find out readIntrThreshold */ |
1824 | frob_set_mode (pb, ECR_PS2); /* Reset FIFO and enable PS2 */ | 1889 | frob_set_mode(pb, ECR_PS2); /* Reset FIFO and enable PS2 */ |
1825 | parport_pc_data_reverse (pb); /* Must be in PS2 mode */ | 1890 | parport_pc_data_reverse(pb); /* Must be in PS2 mode */ |
1826 | frob_set_mode (pb, ECR_TST); /* Test FIFO */ | 1891 | frob_set_mode(pb, ECR_TST); /* Test FIFO */ |
1827 | frob_econtrol (pb, 1<<2, 1<<2); | 1892 | frob_econtrol(pb, 1<<2, 1<<2); |
1828 | frob_econtrol (pb, 1<<2, 0); | 1893 | frob_econtrol(pb, 1<<2, 0); |
1829 | for (i = 1; i <= priv->fifo_depth; i++) { | 1894 | for (i = 1; i <= priv->fifo_depth; i++) { |
1830 | outb (0xaa, FIFO (pb)); | 1895 | outb(0xaa, FIFO(pb)); |
1831 | if (inb (ECONTROL (pb)) & (1<<2)) | 1896 | if (inb(ECONTROL(pb)) & (1<<2)) |
1832 | break; | 1897 | break; |
1833 | } | 1898 | } |
1834 | 1899 | ||
1835 | if (i <= priv->fifo_depth) { | 1900 | if (i <= priv->fifo_depth) { |
1836 | if (verbose_probing) | 1901 | if (verbose_probing) |
1837 | printk (KERN_INFO "0x%lx: readIntrThreshold is %d\n", | 1902 | printk(KERN_INFO "0x%lx: readIntrThreshold is %d\n", |
1838 | pb->base, i); | 1903 | pb->base, i); |
1839 | } else | 1904 | } else |
1840 | /* Number of bytes we can read if we get an interrupt. */ | 1905 | /* Number of bytes we can read if we get an interrupt. */ |
@@ -1842,23 +1907,23 @@ static int parport_ECP_supported(struct parport *pb) | |||
1842 | 1907 | ||
1843 | priv->readIntrThreshold = i; | 1908 | priv->readIntrThreshold = i; |
1844 | 1909 | ||
1845 | ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ | 1910 | ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */ |
1846 | ECR_WRITE (pb, 0xf4); /* Configuration mode */ | 1911 | ECR_WRITE(pb, 0xf4); /* Configuration mode */ |
1847 | config = inb (CONFIGA (pb)); | 1912 | config = inb(CONFIGA(pb)); |
1848 | pword = (config >> 4) & 0x7; | 1913 | pword = (config >> 4) & 0x7; |
1849 | switch (pword) { | 1914 | switch (pword) { |
1850 | case 0: | 1915 | case 0: |
1851 | pword = 2; | 1916 | pword = 2; |
1852 | printk (KERN_WARNING "0x%lx: Unsupported pword size!\n", | 1917 | printk(KERN_WARNING "0x%lx: Unsupported pword size!\n", |
1853 | pb->base); | 1918 | pb->base); |
1854 | break; | 1919 | break; |
1855 | case 2: | 1920 | case 2: |
1856 | pword = 4; | 1921 | pword = 4; |
1857 | printk (KERN_WARNING "0x%lx: Unsupported pword size!\n", | 1922 | printk(KERN_WARNING "0x%lx: Unsupported pword size!\n", |
1858 | pb->base); | 1923 | pb->base); |
1859 | break; | 1924 | break; |
1860 | default: | 1925 | default: |
1861 | printk (KERN_WARNING "0x%lx: Unknown implementation ID\n", | 1926 | printk(KERN_WARNING "0x%lx: Unknown implementation ID\n", |
1862 | pb->base); | 1927 | pb->base); |
1863 | /* Assume 1 */ | 1928 | /* Assume 1 */ |
1864 | case 1: | 1929 | case 1: |
@@ -1867,28 +1932,29 @@ static int parport_ECP_supported(struct parport *pb) | |||
1867 | priv->pword = pword; | 1932 | priv->pword = pword; |
1868 | 1933 | ||
1869 | if (verbose_probing) { | 1934 | if (verbose_probing) { |
1870 | printk (KERN_DEBUG "0x%lx: PWord is %d bits\n", pb->base, 8 * pword); | 1935 | printk(KERN_DEBUG "0x%lx: PWord is %d bits\n", |
1871 | 1936 | pb->base, 8 * pword); | |
1872 | printk (KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base, | 1937 | |
1938 | printk(KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base, | ||
1873 | config & 0x80 ? "Level" : "Pulses"); | 1939 | config & 0x80 ? "Level" : "Pulses"); |
1874 | 1940 | ||
1875 | configb = inb (CONFIGB (pb)); | 1941 | configb = inb(CONFIGB(pb)); |
1876 | printk (KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n", | 1942 | printk(KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n", |
1877 | pb->base, config, configb); | 1943 | pb->base, config, configb); |
1878 | printk (KERN_DEBUG "0x%lx: ECP settings irq=", pb->base); | 1944 | printk(KERN_DEBUG "0x%lx: ECP settings irq=", pb->base); |
1879 | if ((configb >>3) & 0x07) | 1945 | if ((configb >> 3) & 0x07) |
1880 | printk("%d",intrline[(configb >>3) & 0x07]); | 1946 | printk("%d", intrline[(configb >> 3) & 0x07]); |
1881 | else | 1947 | else |
1882 | printk("<none or set by other means>"); | 1948 | printk("<none or set by other means>"); |
1883 | printk (" dma="); | 1949 | printk(" dma="); |
1884 | if( (configb & 0x03 ) == 0x00) | 1950 | if ((configb & 0x03) == 0x00) |
1885 | printk("<none or set by other means>\n"); | 1951 | printk("<none or set by other means>\n"); |
1886 | else | 1952 | else |
1887 | printk("%d\n",configb & 0x07); | 1953 | printk("%d\n", configb & 0x07); |
1888 | } | 1954 | } |
1889 | 1955 | ||
1890 | /* Go back to mode 000 */ | 1956 | /* Go back to mode 000 */ |
1891 | frob_set_mode (pb, ECR_SPP); | 1957 | frob_set_mode(pb, ECR_SPP); |
1892 | 1958 | ||
1893 | return 1; | 1959 | return 1; |
1894 | } | 1960 | } |
@@ -1903,10 +1969,10 @@ static int parport_ECPPS2_supported(struct parport *pb) | |||
1903 | if (!priv->ecr) | 1969 | if (!priv->ecr) |
1904 | return 0; | 1970 | return 0; |
1905 | 1971 | ||
1906 | oecr = inb (ECONTROL (pb)); | 1972 | oecr = inb(ECONTROL(pb)); |
1907 | ECR_WRITE (pb, ECR_PS2 << 5); | 1973 | ECR_WRITE(pb, ECR_PS2 << 5); |
1908 | result = parport_PS2_supported(pb); | 1974 | result = parport_PS2_supported(pb); |
1909 | ECR_WRITE (pb, oecr); | 1975 | ECR_WRITE(pb, oecr); |
1910 | return result; | 1976 | return result; |
1911 | } | 1977 | } |
1912 | 1978 | ||
@@ -1930,16 +1996,15 @@ static int parport_EPP_supported(struct parport *pb) | |||
1930 | */ | 1996 | */ |
1931 | 1997 | ||
1932 | /* If EPP timeout bit clear then EPP available */ | 1998 | /* If EPP timeout bit clear then EPP available */ |
1933 | if (!clear_epp_timeout(pb)) { | 1999 | if (!clear_epp_timeout(pb)) |
1934 | return 0; /* No way to clear timeout */ | 2000 | return 0; /* No way to clear timeout */ |
1935 | } | ||
1936 | 2001 | ||
1937 | /* Check for Intel bug. */ | 2002 | /* Check for Intel bug. */ |
1938 | if (priv->ecr) { | 2003 | if (priv->ecr) { |
1939 | unsigned char i; | 2004 | unsigned char i; |
1940 | for (i = 0x00; i < 0x80; i += 0x20) { | 2005 | for (i = 0x00; i < 0x80; i += 0x20) { |
1941 | ECR_WRITE (pb, i); | 2006 | ECR_WRITE(pb, i); |
1942 | if (clear_epp_timeout (pb)) { | 2007 | if (clear_epp_timeout(pb)) { |
1943 | /* Phony EPP in ECP. */ | 2008 | /* Phony EPP in ECP. */ |
1944 | return 0; | 2009 | return 0; |
1945 | } | 2010 | } |
@@ -1963,17 +2028,16 @@ static int parport_ECPEPP_supported(struct parport *pb) | |||
1963 | int result; | 2028 | int result; |
1964 | unsigned char oecr; | 2029 | unsigned char oecr; |
1965 | 2030 | ||
1966 | if (!priv->ecr) { | 2031 | if (!priv->ecr) |
1967 | return 0; | 2032 | return 0; |
1968 | } | ||
1969 | 2033 | ||
1970 | oecr = inb (ECONTROL (pb)); | 2034 | oecr = inb(ECONTROL(pb)); |
1971 | /* Search for SMC style EPP+ECP mode */ | 2035 | /* Search for SMC style EPP+ECP mode */ |
1972 | ECR_WRITE (pb, 0x80); | 2036 | ECR_WRITE(pb, 0x80); |
1973 | outb (0x04, CONTROL (pb)); | 2037 | outb(0x04, CONTROL(pb)); |
1974 | result = parport_EPP_supported(pb); | 2038 | result = parport_EPP_supported(pb); |
1975 | 2039 | ||
1976 | ECR_WRITE (pb, oecr); | 2040 | ECR_WRITE(pb, oecr); |
1977 | 2041 | ||
1978 | if (result) { | 2042 | if (result) { |
1979 | /* Set up access functions to use ECP+EPP hardware. */ | 2043 | /* Set up access functions to use ECP+EPP hardware. */ |
@@ -1991,11 +2055,25 @@ static int parport_ECPEPP_supported(struct parport *pb) | |||
1991 | /* Don't bother probing for modes we know we won't use. */ | 2055 | /* Don't bother probing for modes we know we won't use. */ |
1992 | static int __devinit parport_PS2_supported(struct parport *pb) { return 0; } | 2056 | static int __devinit parport_PS2_supported(struct parport *pb) { return 0; } |
1993 | #ifdef CONFIG_PARPORT_PC_FIFO | 2057 | #ifdef CONFIG_PARPORT_PC_FIFO |
1994 | static int parport_ECP_supported(struct parport *pb) { return 0; } | 2058 | static int parport_ECP_supported(struct parport *pb) |
2059 | { | ||
2060 | return 0; | ||
2061 | } | ||
1995 | #endif | 2062 | #endif |
1996 | static int __devinit parport_EPP_supported(struct parport *pb) { return 0; } | 2063 | static int __devinit parport_EPP_supported(struct parport *pb) |
1997 | static int __devinit parport_ECPEPP_supported(struct parport *pb){return 0;} | 2064 | { |
1998 | static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;} | 2065 | return 0; |
2066 | } | ||
2067 | |||
2068 | static int __devinit parport_ECPEPP_supported(struct parport *pb) | ||
2069 | { | ||
2070 | return 0; | ||
2071 | } | ||
2072 | |||
2073 | static int __devinit parport_ECPPS2_supported(struct parport *pb) | ||
2074 | { | ||
2075 | return 0; | ||
2076 | } | ||
1999 | 2077 | ||
2000 | #endif /* No IEEE 1284 support */ | 2078 | #endif /* No IEEE 1284 support */ |
2001 | 2079 | ||
@@ -2005,17 +2083,17 @@ static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;} | |||
2005 | static int programmable_irq_support(struct parport *pb) | 2083 | static int programmable_irq_support(struct parport *pb) |
2006 | { | 2084 | { |
2007 | int irq, intrLine; | 2085 | int irq, intrLine; |
2008 | unsigned char oecr = inb (ECONTROL (pb)); | 2086 | unsigned char oecr = inb(ECONTROL(pb)); |
2009 | static const int lookup[8] = { | 2087 | static const int lookup[8] = { |
2010 | PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5 | 2088 | PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5 |
2011 | }; | 2089 | }; |
2012 | 2090 | ||
2013 | ECR_WRITE (pb, ECR_CNF << 5); /* Configuration MODE */ | 2091 | ECR_WRITE(pb, ECR_CNF << 5); /* Configuration MODE */ |
2014 | 2092 | ||
2015 | intrLine = (inb (CONFIGB (pb)) >> 3) & 0x07; | 2093 | intrLine = (inb(CONFIGB(pb)) >> 3) & 0x07; |
2016 | irq = lookup[intrLine]; | 2094 | irq = lookup[intrLine]; |
2017 | 2095 | ||
2018 | ECR_WRITE (pb, oecr); | 2096 | ECR_WRITE(pb, oecr); |
2019 | return irq; | 2097 | return irq; |
2020 | } | 2098 | } |
2021 | 2099 | ||
@@ -2025,17 +2103,17 @@ static int irq_probe_ECP(struct parport *pb) | |||
2025 | unsigned long irqs; | 2103 | unsigned long irqs; |
2026 | 2104 | ||
2027 | irqs = probe_irq_on(); | 2105 | irqs = probe_irq_on(); |
2028 | 2106 | ||
2029 | ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ | 2107 | ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */ |
2030 | ECR_WRITE (pb, (ECR_TST << 5) | 0x04); | 2108 | ECR_WRITE(pb, (ECR_TST << 5) | 0x04); |
2031 | ECR_WRITE (pb, ECR_TST << 5); | 2109 | ECR_WRITE(pb, ECR_TST << 5); |
2032 | 2110 | ||
2033 | /* If Full FIFO sure that writeIntrThreshold is generated */ | 2111 | /* If Full FIFO sure that writeIntrThreshold is generated */ |
2034 | for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02) ; i++) | 2112 | for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02) ; i++) |
2035 | outb (0xaa, FIFO (pb)); | 2113 | outb(0xaa, FIFO(pb)); |
2036 | 2114 | ||
2037 | pb->irq = probe_irq_off(irqs); | 2115 | pb->irq = probe_irq_off(irqs); |
2038 | ECR_WRITE (pb, ECR_SPP << 5); | 2116 | ECR_WRITE(pb, ECR_SPP << 5); |
2039 | 2117 | ||
2040 | if (pb->irq <= 0) | 2118 | if (pb->irq <= 0) |
2041 | pb->irq = PARPORT_IRQ_NONE; | 2119 | pb->irq = PARPORT_IRQ_NONE; |
@@ -2045,7 +2123,7 @@ static int irq_probe_ECP(struct parport *pb) | |||
2045 | 2123 | ||
2046 | /* | 2124 | /* |
2047 | * This detection seems that only works in National Semiconductors | 2125 | * This detection seems that only works in National Semiconductors |
2048 | * This doesn't work in SMC, LGS, and Winbond | 2126 | * This doesn't work in SMC, LGS, and Winbond |
2049 | */ | 2127 | */ |
2050 | static int irq_probe_EPP(struct parport *pb) | 2128 | static int irq_probe_EPP(struct parport *pb) |
2051 | { | 2129 | { |
@@ -2056,16 +2134,16 @@ static int irq_probe_EPP(struct parport *pb) | |||
2056 | unsigned char oecr; | 2134 | unsigned char oecr; |
2057 | 2135 | ||
2058 | if (pb->modes & PARPORT_MODE_PCECR) | 2136 | if (pb->modes & PARPORT_MODE_PCECR) |
2059 | oecr = inb (ECONTROL (pb)); | 2137 | oecr = inb(ECONTROL(pb)); |
2060 | 2138 | ||
2061 | irqs = probe_irq_on(); | 2139 | irqs = probe_irq_on(); |
2062 | 2140 | ||
2063 | if (pb->modes & PARPORT_MODE_PCECR) | 2141 | if (pb->modes & PARPORT_MODE_PCECR) |
2064 | frob_econtrol (pb, 0x10, 0x10); | 2142 | frob_econtrol(pb, 0x10, 0x10); |
2065 | 2143 | ||
2066 | clear_epp_timeout(pb); | 2144 | clear_epp_timeout(pb); |
2067 | parport_pc_frob_control (pb, 0x20, 0x20); | 2145 | parport_pc_frob_control(pb, 0x20, 0x20); |
2068 | parport_pc_frob_control (pb, 0x10, 0x10); | 2146 | parport_pc_frob_control(pb, 0x10, 0x10); |
2069 | clear_epp_timeout(pb); | 2147 | clear_epp_timeout(pb); |
2070 | 2148 | ||
2071 | /* Device isn't expecting an EPP read | 2149 | /* Device isn't expecting an EPP read |
@@ -2074,9 +2152,9 @@ static int irq_probe_EPP(struct parport *pb) | |||
2074 | parport_pc_read_epp(pb); | 2152 | parport_pc_read_epp(pb); |
2075 | udelay(20); | 2153 | udelay(20); |
2076 | 2154 | ||
2077 | pb->irq = probe_irq_off (irqs); | 2155 | pb->irq = probe_irq_off(irqs); |
2078 | if (pb->modes & PARPORT_MODE_PCECR) | 2156 | if (pb->modes & PARPORT_MODE_PCECR) |
2079 | ECR_WRITE (pb, oecr); | 2157 | ECR_WRITE(pb, oecr); |
2080 | parport_pc_write_control(pb, 0xc); | 2158 | parport_pc_write_control(pb, 0xc); |
2081 | 2159 | ||
2082 | if (pb->irq <= 0) | 2160 | if (pb->irq <= 0) |
@@ -2133,28 +2211,28 @@ static int parport_irq_probe(struct parport *pb) | |||
2133 | /* --- DMA detection -------------------------------------- */ | 2211 | /* --- DMA detection -------------------------------------- */ |
2134 | 2212 | ||
2135 | /* Only if chipset conforms to ECP ISA Interface Standard */ | 2213 | /* Only if chipset conforms to ECP ISA Interface Standard */ |
2136 | static int programmable_dma_support (struct parport *p) | 2214 | static int programmable_dma_support(struct parport *p) |
2137 | { | 2215 | { |
2138 | unsigned char oecr = inb (ECONTROL (p)); | 2216 | unsigned char oecr = inb(ECONTROL(p)); |
2139 | int dma; | 2217 | int dma; |
2140 | 2218 | ||
2141 | frob_set_mode (p, ECR_CNF); | 2219 | frob_set_mode(p, ECR_CNF); |
2142 | 2220 | ||
2143 | dma = inb (CONFIGB(p)) & 0x07; | 2221 | dma = inb(CONFIGB(p)) & 0x07; |
2144 | /* 000: Indicates jumpered 8-bit DMA if read-only. | 2222 | /* 000: Indicates jumpered 8-bit DMA if read-only. |
2145 | 100: Indicates jumpered 16-bit DMA if read-only. */ | 2223 | 100: Indicates jumpered 16-bit DMA if read-only. */ |
2146 | if ((dma & 0x03) == 0) | 2224 | if ((dma & 0x03) == 0) |
2147 | dma = PARPORT_DMA_NONE; | 2225 | dma = PARPORT_DMA_NONE; |
2148 | 2226 | ||
2149 | ECR_WRITE (p, oecr); | 2227 | ECR_WRITE(p, oecr); |
2150 | return dma; | 2228 | return dma; |
2151 | } | 2229 | } |
2152 | 2230 | ||
2153 | static int parport_dma_probe (struct parport *p) | 2231 | static int parport_dma_probe(struct parport *p) |
2154 | { | 2232 | { |
2155 | const struct parport_pc_private *priv = p->private_data; | 2233 | const struct parport_pc_private *priv = p->private_data; |
2156 | if (priv->ecr) | 2234 | if (priv->ecr) /* ask ECP chipset first */ |
2157 | p->dma = programmable_dma_support(p); /* ask ECP chipset first */ | 2235 | p->dma = programmable_dma_support(p); |
2158 | if (p->dma == PARPORT_DMA_NONE) { | 2236 | if (p->dma == PARPORT_DMA_NONE) { |
2159 | /* ask known Super-IO chips proper, although these | 2237 | /* ask known Super-IO chips proper, although these |
2160 | claim ECP compatible, some don't report their DMA | 2238 | claim ECP compatible, some don't report their DMA |
@@ -2212,7 +2290,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2212 | if (!base_res) | 2290 | if (!base_res) |
2213 | goto out4; | 2291 | goto out4; |
2214 | 2292 | ||
2215 | memcpy(ops, &parport_pc_ops, sizeof (struct parport_operations)); | 2293 | memcpy(ops, &parport_pc_ops, sizeof(struct parport_operations)); |
2216 | priv->ctr = 0xc; | 2294 | priv->ctr = 0xc; |
2217 | priv->ctr_writable = ~0x10; | 2295 | priv->ctr_writable = ~0x10; |
2218 | priv->ecr = 0; | 2296 | priv->ecr = 0; |
@@ -2239,7 +2317,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2239 | if (!parport_EPP_supported(p)) | 2317 | if (!parport_EPP_supported(p)) |
2240 | parport_ECPEPP_supported(p); | 2318 | parport_ECPEPP_supported(p); |
2241 | } | 2319 | } |
2242 | if (!parport_SPP_supported (p)) | 2320 | if (!parport_SPP_supported(p)) |
2243 | /* No port. */ | 2321 | /* No port. */ |
2244 | goto out5; | 2322 | goto out5; |
2245 | if (priv->ecr) | 2323 | if (priv->ecr) |
@@ -2247,7 +2325,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2247 | else | 2325 | else |
2248 | parport_PS2_supported(p); | 2326 | parport_PS2_supported(p); |
2249 | 2327 | ||
2250 | p->size = (p->modes & PARPORT_MODE_EPP)?8:3; | 2328 | p->size = (p->modes & PARPORT_MODE_EPP) ? 8 : 3; |
2251 | 2329 | ||
2252 | printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base); | 2330 | printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base); |
2253 | if (p->base_hi && priv->ecr) | 2331 | if (p->base_hi && priv->ecr) |
@@ -2271,7 +2349,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2271 | } | 2349 | } |
2272 | } | 2350 | } |
2273 | if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq | 2351 | if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq |
2274 | is mandatory (see above) */ | 2352 | is mandatory (see above) */ |
2275 | p->dma = PARPORT_DMA_NONE; | 2353 | p->dma = PARPORT_DMA_NONE; |
2276 | 2354 | ||
2277 | #ifdef CONFIG_PARPORT_PC_FIFO | 2355 | #ifdef CONFIG_PARPORT_PC_FIFO |
@@ -2288,16 +2366,23 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2288 | if (p->dma != PARPORT_DMA_NONE) { | 2366 | if (p->dma != PARPORT_DMA_NONE) { |
2289 | printk(", dma %d", p->dma); | 2367 | printk(", dma %d", p->dma); |
2290 | p->modes |= PARPORT_MODE_DMA; | 2368 | p->modes |= PARPORT_MODE_DMA; |
2291 | } | 2369 | } else |
2292 | else printk(", using FIFO"); | 2370 | printk(", using FIFO"); |
2293 | } | 2371 | } else |
2294 | else | ||
2295 | /* We can't use the DMA channel after all. */ | 2372 | /* We can't use the DMA channel after all. */ |
2296 | p->dma = PARPORT_DMA_NONE; | 2373 | p->dma = PARPORT_DMA_NONE; |
2297 | #endif /* Allowed to use FIFO/DMA */ | 2374 | #endif /* Allowed to use FIFO/DMA */ |
2298 | 2375 | ||
2299 | printk(" ["); | 2376 | printk(" ["); |
2300 | #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}} | 2377 | |
2378 | #define printmode(x) \ | ||
2379 | {\ | ||
2380 | if (p->modes & PARPORT_MODE_##x) {\ | ||
2381 | printk("%s%s", f ? "," : "", #x);\ | ||
2382 | f++;\ | ||
2383 | } \ | ||
2384 | } | ||
2385 | |||
2301 | { | 2386 | { |
2302 | int f = 0; | 2387 | int f = 0; |
2303 | printmode(PCSPP); | 2388 | printmode(PCSPP); |
@@ -2309,10 +2394,10 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2309 | } | 2394 | } |
2310 | #undef printmode | 2395 | #undef printmode |
2311 | #ifndef CONFIG_PARPORT_1284 | 2396 | #ifndef CONFIG_PARPORT_1284 |
2312 | printk ("(,...)"); | 2397 | printk("(,...)"); |
2313 | #endif /* CONFIG_PARPORT_1284 */ | 2398 | #endif /* CONFIG_PARPORT_1284 */ |
2314 | printk("]\n"); | 2399 | printk("]\n"); |
2315 | if (probedirq != PARPORT_IRQ_NONE) | 2400 | if (probedirq != PARPORT_IRQ_NONE) |
2316 | printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq); | 2401 | printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq); |
2317 | 2402 | ||
2318 | /* If No ECP release the ports grabbed above. */ | 2403 | /* If No ECP release the ports grabbed above. */ |
@@ -2328,7 +2413,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2328 | if (p->irq != PARPORT_IRQ_NONE) { | 2413 | if (p->irq != PARPORT_IRQ_NONE) { |
2329 | if (request_irq(p->irq, parport_irq_handler, | 2414 | if (request_irq(p->irq, parport_irq_handler, |
2330 | irqflags, p->name, p)) { | 2415 | irqflags, p->name, p)) { |
2331 | printk (KERN_WARNING "%s: irq %d in use, " | 2416 | printk(KERN_WARNING "%s: irq %d in use, " |
2332 | "resorting to polled operation\n", | 2417 | "resorting to polled operation\n", |
2333 | p->name, p->irq); | 2418 | p->name, p->irq); |
2334 | p->irq = PARPORT_IRQ_NONE; | 2419 | p->irq = PARPORT_IRQ_NONE; |
@@ -2338,8 +2423,8 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2338 | #ifdef CONFIG_PARPORT_PC_FIFO | 2423 | #ifdef CONFIG_PARPORT_PC_FIFO |
2339 | #ifdef HAS_DMA | 2424 | #ifdef HAS_DMA |
2340 | if (p->dma != PARPORT_DMA_NONE) { | 2425 | if (p->dma != PARPORT_DMA_NONE) { |
2341 | if (request_dma (p->dma, p->name)) { | 2426 | if (request_dma(p->dma, p->name)) { |
2342 | printk (KERN_WARNING "%s: dma %d in use, " | 2427 | printk(KERN_WARNING "%s: dma %d in use, " |
2343 | "resorting to PIO operation\n", | 2428 | "resorting to PIO operation\n", |
2344 | p->name, p->dma); | 2429 | p->name, p->dma); |
2345 | p->dma = PARPORT_DMA_NONE; | 2430 | p->dma = PARPORT_DMA_NONE; |
@@ -2349,8 +2434,8 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2349 | PAGE_SIZE, | 2434 | PAGE_SIZE, |
2350 | &priv->dma_handle, | 2435 | &priv->dma_handle, |
2351 | GFP_KERNEL); | 2436 | GFP_KERNEL); |
2352 | if (! priv->dma_buf) { | 2437 | if (!priv->dma_buf) { |
2353 | printk (KERN_WARNING "%s: " | 2438 | printk(KERN_WARNING "%s: " |
2354 | "cannot get buffer for DMA, " | 2439 | "cannot get buffer for DMA, " |
2355 | "resorting to PIO operation\n", | 2440 | "resorting to PIO operation\n", |
2356 | p->name); | 2441 | p->name); |
@@ -2369,10 +2454,10 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2369 | * Put the ECP detected port in PS2 mode. | 2454 | * Put the ECP detected port in PS2 mode. |
2370 | * Do this also for ports that have ECR but don't do ECP. | 2455 | * Do this also for ports that have ECR but don't do ECP. |
2371 | */ | 2456 | */ |
2372 | ECR_WRITE (p, 0x34); | 2457 | ECR_WRITE(p, 0x34); |
2373 | 2458 | ||
2374 | parport_pc_write_data(p, 0); | 2459 | parport_pc_write_data(p, 0); |
2375 | parport_pc_data_forward (p); | 2460 | parport_pc_data_forward(p); |
2376 | 2461 | ||
2377 | /* Now that we've told the sharing engine about the port, and | 2462 | /* Now that we've told the sharing engine about the port, and |
2378 | found out its characteristics, let the high-level drivers | 2463 | found out its characteristics, let the high-level drivers |
@@ -2380,7 +2465,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, | |||
2380 | spin_lock(&ports_lock); | 2465 | spin_lock(&ports_lock); |
2381 | list_add(&priv->list, &ports_list); | 2466 | list_add(&priv->list, &ports_list); |
2382 | spin_unlock(&ports_lock); | 2467 | spin_unlock(&ports_lock); |
2383 | parport_announce_port (p); | 2468 | parport_announce_port(p); |
2384 | 2469 | ||
2385 | return p; | 2470 | return p; |
2386 | 2471 | ||
@@ -2393,18 +2478,17 @@ out5: | |||
2393 | out4: | 2478 | out4: |
2394 | parport_put_port(p); | 2479 | parport_put_port(p); |
2395 | out3: | 2480 | out3: |
2396 | kfree (priv); | 2481 | kfree(priv); |
2397 | out2: | 2482 | out2: |
2398 | kfree (ops); | 2483 | kfree(ops); |
2399 | out1: | 2484 | out1: |
2400 | if (pdev) | 2485 | if (pdev) |
2401 | platform_device_unregister(pdev); | 2486 | platform_device_unregister(pdev); |
2402 | return NULL; | 2487 | return NULL; |
2403 | } | 2488 | } |
2489 | EXPORT_SYMBOL(parport_pc_probe_port); | ||
2404 | 2490 | ||
2405 | EXPORT_SYMBOL (parport_pc_probe_port); | 2491 | void parport_pc_unregister_port(struct parport *p) |
2406 | |||
2407 | void parport_pc_unregister_port (struct parport *p) | ||
2408 | { | 2492 | { |
2409 | struct parport_pc_private *priv = p->private_data; | 2493 | struct parport_pc_private *priv = p->private_data; |
2410 | struct parport_operations *ops = p->ops; | 2494 | struct parport_operations *ops = p->ops; |
@@ -2430,17 +2514,16 @@ void parport_pc_unregister_port (struct parport *p) | |||
2430 | priv->dma_buf, | 2514 | priv->dma_buf, |
2431 | priv->dma_handle); | 2515 | priv->dma_handle); |
2432 | #endif | 2516 | #endif |
2433 | kfree (p->private_data); | 2517 | kfree(p->private_data); |
2434 | parport_put_port(p); | 2518 | parport_put_port(p); |
2435 | kfree (ops); /* hope no-one cached it */ | 2519 | kfree(ops); /* hope no-one cached it */ |
2436 | } | 2520 | } |
2437 | 2521 | EXPORT_SYMBOL(parport_pc_unregister_port); | |
2438 | EXPORT_SYMBOL (parport_pc_unregister_port); | ||
2439 | 2522 | ||
2440 | #ifdef CONFIG_PCI | 2523 | #ifdef CONFIG_PCI |
2441 | 2524 | ||
2442 | /* ITE support maintained by Rich Liu <richliu@poorman.org> */ | 2525 | /* ITE support maintained by Rich Liu <richliu@poorman.org> */ |
2443 | static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, | 2526 | static int __devinit sio_ite_8872_probe(struct pci_dev *pdev, int autoirq, |
2444 | int autodma, | 2527 | int autodma, |
2445 | const struct parport_pc_via_data *via) | 2528 | const struct parport_pc_via_data *via) |
2446 | { | 2529 | { |
@@ -2452,73 +2535,74 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, | |||
2452 | int irq; | 2535 | int irq; |
2453 | int i; | 2536 | int i; |
2454 | 2537 | ||
2455 | DPRINTK (KERN_DEBUG "sio_ite_8872_probe()\n"); | 2538 | DPRINTK(KERN_DEBUG "sio_ite_8872_probe()\n"); |
2456 | 2539 | ||
2457 | // make sure which one chip | 2540 | /* make sure which one chip */ |
2458 | for(i = 0; i < 5; i++) { | 2541 | for (i = 0; i < 5; i++) { |
2459 | base_res = request_region(inta_addr[i], 32, "it887x"); | 2542 | base_res = request_region(inta_addr[i], 32, "it887x"); |
2460 | if (base_res) { | 2543 | if (base_res) { |
2461 | int test; | 2544 | int test; |
2462 | pci_write_config_dword (pdev, 0x60, | 2545 | pci_write_config_dword(pdev, 0x60, |
2463 | 0xe5000000 | inta_addr[i]); | 2546 | 0xe5000000 | inta_addr[i]); |
2464 | pci_write_config_dword (pdev, 0x78, | 2547 | pci_write_config_dword(pdev, 0x78, |
2465 | 0x00000000 | inta_addr[i]); | 2548 | 0x00000000 | inta_addr[i]); |
2466 | test = inb (inta_addr[i]); | 2549 | test = inb(inta_addr[i]); |
2467 | if (test != 0xff) break; | 2550 | if (test != 0xff) |
2551 | break; | ||
2468 | release_region(inta_addr[i], 0x8); | 2552 | release_region(inta_addr[i], 0x8); |
2469 | } | 2553 | } |
2470 | } | 2554 | } |
2471 | if(i >= 5) { | 2555 | if (i >= 5) { |
2472 | printk (KERN_INFO "parport_pc: cannot find ITE8872 INTA\n"); | 2556 | printk(KERN_INFO "parport_pc: cannot find ITE8872 INTA\n"); |
2473 | return 0; | 2557 | return 0; |
2474 | } | 2558 | } |
2475 | 2559 | ||
2476 | type = inb (inta_addr[i] + 0x18); | 2560 | type = inb(inta_addr[i] + 0x18); |
2477 | type &= 0x0f; | 2561 | type &= 0x0f; |
2478 | 2562 | ||
2479 | switch (type) { | 2563 | switch (type) { |
2480 | case 0x2: | 2564 | case 0x2: |
2481 | printk (KERN_INFO "parport_pc: ITE8871 found (1P)\n"); | 2565 | printk(KERN_INFO "parport_pc: ITE8871 found (1P)\n"); |
2482 | ite8872set = 0x64200000; | 2566 | ite8872set = 0x64200000; |
2483 | break; | 2567 | break; |
2484 | case 0xa: | 2568 | case 0xa: |
2485 | printk (KERN_INFO "parport_pc: ITE8875 found (1P)\n"); | 2569 | printk(KERN_INFO "parport_pc: ITE8875 found (1P)\n"); |
2486 | ite8872set = 0x64200000; | 2570 | ite8872set = 0x64200000; |
2487 | break; | 2571 | break; |
2488 | case 0xe: | 2572 | case 0xe: |
2489 | printk (KERN_INFO "parport_pc: ITE8872 found (2S1P)\n"); | 2573 | printk(KERN_INFO "parport_pc: ITE8872 found (2S1P)\n"); |
2490 | ite8872set = 0x64e00000; | 2574 | ite8872set = 0x64e00000; |
2491 | break; | 2575 | break; |
2492 | case 0x6: | 2576 | case 0x6: |
2493 | printk (KERN_INFO "parport_pc: ITE8873 found (1S)\n"); | 2577 | printk(KERN_INFO "parport_pc: ITE8873 found (1S)\n"); |
2494 | return 0; | 2578 | return 0; |
2495 | case 0x8: | 2579 | case 0x8: |
2496 | DPRINTK (KERN_DEBUG "parport_pc: ITE8874 found (2S)\n"); | 2580 | DPRINTK(KERN_DEBUG "parport_pc: ITE8874 found (2S)\n"); |
2497 | return 0; | 2581 | return 0; |
2498 | default: | 2582 | default: |
2499 | printk (KERN_INFO "parport_pc: unknown ITE887x\n"); | 2583 | printk(KERN_INFO "parport_pc: unknown ITE887x\n"); |
2500 | printk (KERN_INFO "parport_pc: please mail 'lspci -nvv' " | 2584 | printk(KERN_INFO "parport_pc: please mail 'lspci -nvv' " |
2501 | "output to Rich.Liu@ite.com.tw\n"); | 2585 | "output to Rich.Liu@ite.com.tw\n"); |
2502 | return 0; | 2586 | return 0; |
2503 | } | 2587 | } |
2504 | 2588 | ||
2505 | pci_read_config_byte (pdev, 0x3c, &ite8872_irq); | 2589 | pci_read_config_byte(pdev, 0x3c, &ite8872_irq); |
2506 | pci_read_config_dword (pdev, 0x1c, &ite8872_lpt); | 2590 | pci_read_config_dword(pdev, 0x1c, &ite8872_lpt); |
2507 | ite8872_lpt &= 0x0000ff00; | 2591 | ite8872_lpt &= 0x0000ff00; |
2508 | pci_read_config_dword (pdev, 0x20, &ite8872_lpthi); | 2592 | pci_read_config_dword(pdev, 0x20, &ite8872_lpthi); |
2509 | ite8872_lpthi &= 0x0000ff00; | 2593 | ite8872_lpthi &= 0x0000ff00; |
2510 | pci_write_config_dword (pdev, 0x6c, 0xe3000000 | ite8872_lpt); | 2594 | pci_write_config_dword(pdev, 0x6c, 0xe3000000 | ite8872_lpt); |
2511 | pci_write_config_dword (pdev, 0x70, 0xe3000000 | ite8872_lpthi); | 2595 | pci_write_config_dword(pdev, 0x70, 0xe3000000 | ite8872_lpthi); |
2512 | pci_write_config_dword (pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt); | 2596 | pci_write_config_dword(pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt); |
2513 | // SET SPP&EPP , Parallel Port NO DMA , Enable All Function | 2597 | /* SET SPP&EPP , Parallel Port NO DMA , Enable All Function */ |
2514 | // SET Parallel IRQ | 2598 | /* SET Parallel IRQ */ |
2515 | pci_write_config_dword (pdev, 0x9c, | 2599 | pci_write_config_dword(pdev, 0x9c, |
2516 | ite8872set | (ite8872_irq * 0x11111)); | 2600 | ite8872set | (ite8872_irq * 0x11111)); |
2517 | 2601 | ||
2518 | DPRINTK (KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq); | 2602 | DPRINTK(KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq); |
2519 | DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n", | 2603 | DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n", |
2520 | ite8872_lpt); | 2604 | ite8872_lpt); |
2521 | DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n", | 2605 | DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n", |
2522 | ite8872_lpthi); | 2606 | ite8872_lpthi); |
2523 | 2607 | ||
2524 | /* Let the user (or defaults) steer us away from interrupts */ | 2608 | /* Let the user (or defaults) steer us away from interrupts */ |
@@ -2530,14 +2614,14 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, | |||
2530 | * Release the resource so that parport_pc_probe_port can get it. | 2614 | * Release the resource so that parport_pc_probe_port can get it. |
2531 | */ | 2615 | */ |
2532 | release_resource(base_res); | 2616 | release_resource(base_res); |
2533 | if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi, | 2617 | if (parport_pc_probe_port(ite8872_lpt, ite8872_lpthi, |
2534 | irq, PARPORT_DMA_NONE, &pdev->dev, 0)) { | 2618 | irq, PARPORT_DMA_NONE, &pdev->dev, 0)) { |
2535 | printk (KERN_INFO | 2619 | printk(KERN_INFO |
2536 | "parport_pc: ITE 8872 parallel port: io=0x%X", | 2620 | "parport_pc: ITE 8872 parallel port: io=0x%X", |
2537 | ite8872_lpt); | 2621 | ite8872_lpt); |
2538 | if (irq != PARPORT_IRQ_NONE) | 2622 | if (irq != PARPORT_IRQ_NONE) |
2539 | printk (", irq=%d", irq); | 2623 | printk(", irq=%d", irq); |
2540 | printk ("\n"); | 2624 | printk("\n"); |
2541 | return 1; | 2625 | return 1; |
2542 | } | 2626 | } |
2543 | 2627 | ||
@@ -2546,7 +2630,7 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, | |||
2546 | 2630 | ||
2547 | /* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru> | 2631 | /* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru> |
2548 | based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */ | 2632 | based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */ |
2549 | static int __devinitdata parport_init_mode = 0; | 2633 | static int __devinitdata parport_init_mode; |
2550 | 2634 | ||
2551 | /* Data for two known VIA chips */ | 2635 | /* Data for two known VIA chips */ |
2552 | static struct parport_pc_via_data via_686a_data __devinitdata = { | 2636 | static struct parport_pc_via_data via_686a_data __devinitdata = { |
@@ -2568,7 +2652,7 @@ static struct parport_pc_via_data via_8231_data __devinitdata = { | |||
2568 | 0xF6 | 2652 | 0xF6 |
2569 | }; | 2653 | }; |
2570 | 2654 | ||
2571 | static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | 2655 | static int __devinit sio_via_probe(struct pci_dev *pdev, int autoirq, |
2572 | int autodma, | 2656 | int autodma, |
2573 | const struct parport_pc_via_data *via) | 2657 | const struct parport_pc_via_data *via) |
2574 | { | 2658 | { |
@@ -2580,38 +2664,38 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | |||
2580 | 2664 | ||
2581 | printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n"); | 2665 | printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n"); |
2582 | 2666 | ||
2583 | switch(parport_init_mode) | 2667 | switch (parport_init_mode) { |
2584 | { | ||
2585 | case 1: | 2668 | case 1: |
2586 | printk(KERN_DEBUG "parport_pc: setting SPP mode\n"); | 2669 | printk(KERN_DEBUG "parport_pc: setting SPP mode\n"); |
2587 | siofunc = VIA_FUNCTION_PARPORT_SPP; | 2670 | siofunc = VIA_FUNCTION_PARPORT_SPP; |
2588 | break; | 2671 | break; |
2589 | case 2: | 2672 | case 2: |
2590 | printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n"); | 2673 | printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n"); |
2591 | siofunc = VIA_FUNCTION_PARPORT_SPP; | 2674 | siofunc = VIA_FUNCTION_PARPORT_SPP; |
2592 | ppcontrol = VIA_PARPORT_BIDIR; | 2675 | ppcontrol = VIA_PARPORT_BIDIR; |
2593 | break; | 2676 | break; |
2594 | case 3: | 2677 | case 3: |
2595 | printk(KERN_DEBUG "parport_pc: setting EPP mode\n"); | 2678 | printk(KERN_DEBUG "parport_pc: setting EPP mode\n"); |
2596 | siofunc = VIA_FUNCTION_PARPORT_EPP; | 2679 | siofunc = VIA_FUNCTION_PARPORT_EPP; |
2597 | ppcontrol = VIA_PARPORT_BIDIR; | 2680 | ppcontrol = VIA_PARPORT_BIDIR; |
2598 | have_epp = 1; | 2681 | have_epp = 1; |
2599 | break; | 2682 | break; |
2600 | case 4: | 2683 | case 4: |
2601 | printk(KERN_DEBUG "parport_pc: setting ECP mode\n"); | 2684 | printk(KERN_DEBUG "parport_pc: setting ECP mode\n"); |
2602 | siofunc = VIA_FUNCTION_PARPORT_ECP; | 2685 | siofunc = VIA_FUNCTION_PARPORT_ECP; |
2603 | ppcontrol = VIA_PARPORT_BIDIR; | 2686 | ppcontrol = VIA_PARPORT_BIDIR; |
2604 | break; | 2687 | break; |
2605 | case 5: | 2688 | case 5: |
2606 | printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n"); | 2689 | printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n"); |
2607 | siofunc = VIA_FUNCTION_PARPORT_ECP; | 2690 | siofunc = VIA_FUNCTION_PARPORT_ECP; |
2608 | ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP; | 2691 | ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP; |
2609 | have_epp = 1; | 2692 | have_epp = 1; |
2610 | break; | 2693 | break; |
2611 | default: | 2694 | default: |
2612 | printk(KERN_DEBUG "parport_pc: probing current configuration\n"); | 2695 | printk(KERN_DEBUG |
2613 | siofunc = VIA_FUNCTION_PROBE; | 2696 | "parport_pc: probing current configuration\n"); |
2614 | break; | 2697 | siofunc = VIA_FUNCTION_PROBE; |
2698 | break; | ||
2615 | } | 2699 | } |
2616 | /* | 2700 | /* |
2617 | * unlock super i/o configuration | 2701 | * unlock super i/o configuration |
@@ -2622,38 +2706,36 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | |||
2622 | 2706 | ||
2623 | /* Bits 1-0: Parallel Port Mode / Enable */ | 2707 | /* Bits 1-0: Parallel Port Mode / Enable */ |
2624 | outb(via->viacfg_function, VIA_CONFIG_INDEX); | 2708 | outb(via->viacfg_function, VIA_CONFIG_INDEX); |
2625 | tmp = inb (VIA_CONFIG_DATA); | 2709 | tmp = inb(VIA_CONFIG_DATA); |
2626 | /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */ | 2710 | /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */ |
2627 | outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); | 2711 | outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); |
2628 | tmp2 = inb (VIA_CONFIG_DATA); | 2712 | tmp2 = inb(VIA_CONFIG_DATA); |
2629 | if (siofunc == VIA_FUNCTION_PROBE) | 2713 | if (siofunc == VIA_FUNCTION_PROBE) { |
2630 | { | 2714 | siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE; |
2631 | siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE; | 2715 | ppcontrol = tmp2; |
2632 | ppcontrol = tmp2; | 2716 | } else { |
2717 | tmp &= ~VIA_FUNCTION_PARPORT_DISABLE; | ||
2718 | tmp |= siofunc; | ||
2719 | outb(via->viacfg_function, VIA_CONFIG_INDEX); | ||
2720 | outb(tmp, VIA_CONFIG_DATA); | ||
2721 | tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP); | ||
2722 | tmp2 |= ppcontrol; | ||
2723 | outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); | ||
2724 | outb(tmp2, VIA_CONFIG_DATA); | ||
2633 | } | 2725 | } |
2634 | else | 2726 | |
2635 | { | ||
2636 | tmp &= ~VIA_FUNCTION_PARPORT_DISABLE; | ||
2637 | tmp |= siofunc; | ||
2638 | outb(via->viacfg_function, VIA_CONFIG_INDEX); | ||
2639 | outb(tmp, VIA_CONFIG_DATA); | ||
2640 | tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP); | ||
2641 | tmp2 |= ppcontrol; | ||
2642 | outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); | ||
2643 | outb(tmp2, VIA_CONFIG_DATA); | ||
2644 | } | ||
2645 | |||
2646 | /* Parallel Port I/O Base Address, bits 9-2 */ | 2727 | /* Parallel Port I/O Base Address, bits 9-2 */ |
2647 | outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); | 2728 | outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); |
2648 | port1 = inb(VIA_CONFIG_DATA) << 2; | 2729 | port1 = inb(VIA_CONFIG_DATA) << 2; |
2649 | 2730 | ||
2650 | printk (KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n",port1); | 2731 | printk(KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n", |
2651 | if ((port1 == 0x3BC) && have_epp) | 2732 | port1); |
2652 | { | 2733 | if (port1 == 0x3BC && have_epp) { |
2653 | outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); | 2734 | outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); |
2654 | outb((0x378 >> 2), VIA_CONFIG_DATA); | 2735 | outb((0x378 >> 2), VIA_CONFIG_DATA); |
2655 | printk(KERN_DEBUG "parport_pc: Parallel port base changed to 0x378\n"); | 2736 | printk(KERN_DEBUG |
2656 | port1 = 0x378; | 2737 | "parport_pc: Parallel port base changed to 0x378\n"); |
2738 | port1 = 0x378; | ||
2657 | } | 2739 | } |
2658 | 2740 | ||
2659 | /* | 2741 | /* |
@@ -2667,36 +2749,39 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | |||
2667 | printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n"); | 2749 | printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n"); |
2668 | return 0; | 2750 | return 0; |
2669 | } | 2751 | } |
2670 | 2752 | ||
2671 | /* Bits 7-4: PnP Routing for Parallel Port IRQ */ | 2753 | /* Bits 7-4: PnP Routing for Parallel Port IRQ */ |
2672 | pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp); | 2754 | pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp); |
2673 | irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4); | 2755 | irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4); |
2674 | 2756 | ||
2675 | if (siofunc == VIA_FUNCTION_PARPORT_ECP) | 2757 | if (siofunc == VIA_FUNCTION_PARPORT_ECP) { |
2676 | { | 2758 | /* Bits 3-2: PnP Routing for Parallel Port DMA */ |
2677 | /* Bits 3-2: PnP Routing for Parallel Port DMA */ | 2759 | pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp); |
2678 | pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp); | 2760 | dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2); |
2679 | dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2); | 2761 | } else |
2680 | } | 2762 | /* if ECP not enabled, DMA is not enabled, assumed |
2681 | else | 2763 | bogus 'dma' value */ |
2682 | /* if ECP not enabled, DMA is not enabled, assumed bogus 'dma' value */ | 2764 | dma = PARPORT_DMA_NONE; |
2683 | dma = PARPORT_DMA_NONE; | ||
2684 | 2765 | ||
2685 | /* Let the user (or defaults) steer us away from interrupts and DMA */ | 2766 | /* Let the user (or defaults) steer us away from interrupts and DMA */ |
2686 | if (autoirq == PARPORT_IRQ_NONE) { | 2767 | if (autoirq == PARPORT_IRQ_NONE) { |
2687 | irq = PARPORT_IRQ_NONE; | 2768 | irq = PARPORT_IRQ_NONE; |
2688 | dma = PARPORT_DMA_NONE; | 2769 | dma = PARPORT_DMA_NONE; |
2689 | } | 2770 | } |
2690 | if (autodma == PARPORT_DMA_NONE) | 2771 | if (autodma == PARPORT_DMA_NONE) |
2691 | dma = PARPORT_DMA_NONE; | 2772 | dma = PARPORT_DMA_NONE; |
2692 | 2773 | ||
2693 | switch (port1) { | 2774 | switch (port1) { |
2694 | case 0x3bc: port2 = 0x7bc; break; | 2775 | case 0x3bc: |
2695 | case 0x378: port2 = 0x778; break; | 2776 | port2 = 0x7bc; break; |
2696 | case 0x278: port2 = 0x678; break; | 2777 | case 0x378: |
2778 | port2 = 0x778; break; | ||
2779 | case 0x278: | ||
2780 | port2 = 0x678; break; | ||
2697 | default: | 2781 | default: |
2698 | printk(KERN_INFO "parport_pc: Weird VIA parport base 0x%X, ignoring\n", | 2782 | printk(KERN_INFO |
2699 | port1); | 2783 | "parport_pc: Weird VIA parport base 0x%X, ignoring\n", |
2784 | port1); | ||
2700 | return 0; | 2785 | return 0; |
2701 | } | 2786 | } |
2702 | 2787 | ||
@@ -2714,17 +2799,17 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | |||
2714 | } | 2799 | } |
2715 | 2800 | ||
2716 | /* finally, do the probe with values obtained */ | 2801 | /* finally, do the probe with values obtained */ |
2717 | if (parport_pc_probe_port (port1, port2, irq, dma, &pdev->dev, 0)) { | 2802 | if (parport_pc_probe_port(port1, port2, irq, dma, &pdev->dev, 0)) { |
2718 | printk (KERN_INFO | 2803 | printk(KERN_INFO |
2719 | "parport_pc: VIA parallel port: io=0x%X", port1); | 2804 | "parport_pc: VIA parallel port: io=0x%X", port1); |
2720 | if (irq != PARPORT_IRQ_NONE) | 2805 | if (irq != PARPORT_IRQ_NONE) |
2721 | printk (", irq=%d", irq); | 2806 | printk(", irq=%d", irq); |
2722 | if (dma != PARPORT_DMA_NONE) | 2807 | if (dma != PARPORT_DMA_NONE) |
2723 | printk (", dma=%d", dma); | 2808 | printk(", dma=%d", dma); |
2724 | printk ("\n"); | 2809 | printk("\n"); |
2725 | return 1; | 2810 | return 1; |
2726 | } | 2811 | } |
2727 | 2812 | ||
2728 | printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n", | 2813 | printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n", |
2729 | port1, irq, dma); | 2814 | port1, irq, dma); |
2730 | return 0; | 2815 | return 0; |
@@ -2732,8 +2817,8 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | |||
2732 | 2817 | ||
2733 | 2818 | ||
2734 | enum parport_pc_sio_types { | 2819 | enum parport_pc_sio_types { |
2735 | sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */ | 2820 | sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */ |
2736 | sio_via_8231, /* Via VT8231 south bridge integrated Super IO */ | 2821 | sio_via_8231, /* Via VT8231 south bridge integrated Super IO */ |
2737 | sio_ite_8872, | 2822 | sio_ite_8872, |
2738 | last_sio | 2823 | last_sio |
2739 | }; | 2824 | }; |
@@ -2804,15 +2889,15 @@ enum parport_pc_pci_cards { | |||
2804 | }; | 2889 | }; |
2805 | 2890 | ||
2806 | 2891 | ||
2807 | /* each element directly indexed from enum list, above | 2892 | /* each element directly indexed from enum list, above |
2808 | * (but offset by last_sio) */ | 2893 | * (but offset by last_sio) */ |
2809 | static struct parport_pc_pci { | 2894 | static struct parport_pc_pci { |
2810 | int numports; | 2895 | int numports; |
2811 | struct { /* BAR (base address registers) numbers in the config | 2896 | struct { /* BAR (base address registers) numbers in the config |
2812 | space header */ | 2897 | space header */ |
2813 | int lo; | 2898 | int lo; |
2814 | int hi; /* -1 if not there, >6 for offset-method (max | 2899 | int hi; |
2815 | BAR is 6) */ | 2900 | /* -1 if not there, >6 for offset-method (max BAR is 6) */ |
2816 | } addr[4]; | 2901 | } addr[4]; |
2817 | 2902 | ||
2818 | /* If set, this is called immediately after pci_enable_device. | 2903 | /* If set, this is called immediately after pci_enable_device. |
@@ -2857,7 +2942,7 @@ static struct parport_pc_pci { | |||
2857 | /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } }, | 2942 | /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } }, |
2858 | /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } }, | 2943 | /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } }, |
2859 | /* SYBA uses fixed offsets in | 2944 | /* SYBA uses fixed offsets in |
2860 | a 1K io window */ | 2945 | a 1K io window */ |
2861 | /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } }, | 2946 | /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } }, |
2862 | /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } }, | 2947 | /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } }, |
2863 | /* titan_010l */ { 1, { { 3, -1 }, } }, | 2948 | /* titan_010l */ { 1, { { 3, -1 }, } }, |
@@ -2873,11 +2958,14 @@ static struct parport_pc_pci { | |||
2873 | /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, } }, | 2958 | /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, } }, |
2874 | /* aks_0100 */ { 1, { { 0, -1 }, } }, | 2959 | /* aks_0100 */ { 1, { { 0, -1 }, } }, |
2875 | /* mobility_pp */ { 1, { { 0, 1 }, } }, | 2960 | /* mobility_pp */ { 1, { { 0, 1 }, } }, |
2876 | /* netmos_9705 */ { 1, { { 0, -1 }, } }, /* untested */ | 2961 | |
2877 | /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */ | 2962 | /* The netmos entries below are untested */ |
2878 | /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */ | 2963 | /* netmos_9705 */ { 1, { { 0, -1 }, } }, |
2879 | /* netmos_9805 */ { 1, { { 0, -1 }, } }, /* untested */ | 2964 | /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} }, |
2880 | /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */ | 2965 | /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} }, |
2966 | /* netmos_9805 */ { 1, { { 0, -1 }, } }, | ||
2967 | /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, | ||
2968 | |||
2881 | /* quatech_sppxp100 */ { 1, { { 0, 1 }, } }, | 2969 | /* quatech_sppxp100 */ { 1, { { 0, 1 }, } }, |
2882 | }; | 2970 | }; |
2883 | 2971 | ||
@@ -2906,7 +2994,7 @@ static const struct pci_device_id parport_pc_pci_tbl[] = { | |||
2906 | { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR, | 2994 | { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR, |
2907 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar }, | 2995 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar }, |
2908 | { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, | 2996 | { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, |
2909 | PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0,0, plx_9050 }, | 2997 | PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0, 0, plx_9050 }, |
2910 | /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/ | 2998 | /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/ |
2911 | { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a }, | 2999 | { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a }, |
2912 | { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h }, | 3000 | { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h }, |
@@ -2940,7 +3028,8 @@ static const struct pci_device_id parport_pc_pci_tbl[] = { | |||
2940 | { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 }, | 3028 | { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 }, |
2941 | { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 }, | 3029 | { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 }, |
2942 | /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/ | 3030 | /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/ |
2943 | { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, /* AFAVLAB_TK9902 */ | 3031 | /* AFAVLAB_TK9902 */ |
3032 | { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, | ||
2944 | { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p}, | 3033 | { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p}, |
2945 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP, | 3034 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP, |
2946 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 }, | 3035 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 }, |
@@ -2983,14 +3072,14 @@ static const struct pci_device_id parport_pc_pci_tbl[] = { | |||
2983 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 }, | 3072 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 }, |
2984 | { 0, } /* terminate list */ | 3073 | { 0, } /* terminate list */ |
2985 | }; | 3074 | }; |
2986 | MODULE_DEVICE_TABLE(pci,parport_pc_pci_tbl); | 3075 | MODULE_DEVICE_TABLE(pci, parport_pc_pci_tbl); |
2987 | 3076 | ||
2988 | struct pci_parport_data { | 3077 | struct pci_parport_data { |
2989 | int num; | 3078 | int num; |
2990 | struct parport *ports[2]; | 3079 | struct parport *ports[2]; |
2991 | }; | 3080 | }; |
2992 | 3081 | ||
2993 | static int parport_pc_pci_probe (struct pci_dev *dev, | 3082 | static int parport_pc_pci_probe(struct pci_dev *dev, |
2994 | const struct pci_device_id *id) | 3083 | const struct pci_device_id *id) |
2995 | { | 3084 | { |
2996 | int err, count, n, i = id->driver_data; | 3085 | int err, count, n, i = id->driver_data; |
@@ -3003,7 +3092,8 @@ static int parport_pc_pci_probe (struct pci_dev *dev, | |||
3003 | /* This is a PCI card */ | 3092 | /* This is a PCI card */ |
3004 | i -= last_sio; | 3093 | i -= last_sio; |
3005 | count = 0; | 3094 | count = 0; |
3006 | if ((err = pci_enable_device (dev)) != 0) | 3095 | err = pci_enable_device(dev); |
3096 | if (err) | ||
3007 | return err; | 3097 | return err; |
3008 | 3098 | ||
3009 | data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL); | 3099 | data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL); |
@@ -3011,7 +3101,7 @@ static int parport_pc_pci_probe (struct pci_dev *dev, | |||
3011 | return -ENOMEM; | 3101 | return -ENOMEM; |
3012 | 3102 | ||
3013 | if (cards[i].preinit_hook && | 3103 | if (cards[i].preinit_hook && |
3014 | cards[i].preinit_hook (dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) { | 3104 | cards[i].preinit_hook(dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) { |
3015 | kfree(data); | 3105 | kfree(data); |
3016 | return -ENODEV; | 3106 | return -ENODEV; |
3017 | } | 3107 | } |
@@ -3021,25 +3111,25 @@ static int parport_pc_pci_probe (struct pci_dev *dev, | |||
3021 | int hi = cards[i].addr[n].hi; | 3111 | int hi = cards[i].addr[n].hi; |
3022 | int irq; | 3112 | int irq; |
3023 | unsigned long io_lo, io_hi; | 3113 | unsigned long io_lo, io_hi; |
3024 | io_lo = pci_resource_start (dev, lo); | 3114 | io_lo = pci_resource_start(dev, lo); |
3025 | io_hi = 0; | 3115 | io_hi = 0; |
3026 | if ((hi >= 0) && (hi <= 6)) | 3116 | if ((hi >= 0) && (hi <= 6)) |
3027 | io_hi = pci_resource_start (dev, hi); | 3117 | io_hi = pci_resource_start(dev, hi); |
3028 | else if (hi > 6) | 3118 | else if (hi > 6) |
3029 | io_lo += hi; /* Reinterpret the meaning of | 3119 | io_lo += hi; /* Reinterpret the meaning of |
3030 | "hi" as an offset (see SYBA | 3120 | "hi" as an offset (see SYBA |
3031 | def.) */ | 3121 | def.) */ |
3032 | /* TODO: test if sharing interrupts works */ | 3122 | /* TODO: test if sharing interrupts works */ |
3033 | irq = dev->irq; | 3123 | irq = dev->irq; |
3034 | if (irq == IRQ_NONE) { | 3124 | if (irq == IRQ_NONE) { |
3035 | printk (KERN_DEBUG | 3125 | printk(KERN_DEBUG |
3036 | "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx)\n", | 3126 | "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx)\n", |
3037 | parport_pc_pci_tbl[i + last_sio].vendor, | 3127 | parport_pc_pci_tbl[i + last_sio].vendor, |
3038 | parport_pc_pci_tbl[i + last_sio].device, | 3128 | parport_pc_pci_tbl[i + last_sio].device, |
3039 | io_lo, io_hi); | 3129 | io_lo, io_hi); |
3040 | irq = PARPORT_IRQ_NONE; | 3130 | irq = PARPORT_IRQ_NONE; |
3041 | } else { | 3131 | } else { |
3042 | printk (KERN_DEBUG | 3132 | printk(KERN_DEBUG |
3043 | "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx), IRQ %d\n", | 3133 | "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx), IRQ %d\n", |
3044 | parport_pc_pci_tbl[i + last_sio].vendor, | 3134 | parport_pc_pci_tbl[i + last_sio].vendor, |
3045 | parport_pc_pci_tbl[i + last_sio].device, | 3135 | parport_pc_pci_tbl[i + last_sio].device, |
@@ -3056,7 +3146,7 @@ static int parport_pc_pci_probe (struct pci_dev *dev, | |||
3056 | data->num = count; | 3146 | data->num = count; |
3057 | 3147 | ||
3058 | if (cards[i].postinit_hook) | 3148 | if (cards[i].postinit_hook) |
3059 | cards[i].postinit_hook (dev, count == 0); | 3149 | cards[i].postinit_hook(dev, count == 0); |
3060 | 3150 | ||
3061 | if (count) { | 3151 | if (count) { |
3062 | pci_set_drvdata(dev, data); | 3152 | pci_set_drvdata(dev, data); |
@@ -3090,7 +3180,7 @@ static struct pci_driver parport_pc_pci_driver = { | |||
3090 | .remove = __devexit_p(parport_pc_pci_remove), | 3180 | .remove = __devexit_p(parport_pc_pci_remove), |
3091 | }; | 3181 | }; |
3092 | 3182 | ||
3093 | static int __init parport_pc_init_superio (int autoirq, int autodma) | 3183 | static int __init parport_pc_init_superio(int autoirq, int autodma) |
3094 | { | 3184 | { |
3095 | const struct pci_device_id *id; | 3185 | const struct pci_device_id *id; |
3096 | struct pci_dev *pdev = NULL; | 3186 | struct pci_dev *pdev = NULL; |
@@ -3101,8 +3191,9 @@ static int __init parport_pc_init_superio (int autoirq, int autodma) | |||
3101 | if (id == NULL || id->driver_data >= last_sio) | 3191 | if (id == NULL || id->driver_data >= last_sio) |
3102 | continue; | 3192 | continue; |
3103 | 3193 | ||
3104 | if (parport_pc_superio_info[id->driver_data].probe | 3194 | if (parport_pc_superio_info[id->driver_data].probe( |
3105 | (pdev, autoirq, autodma,parport_pc_superio_info[id->driver_data].via)) { | 3195 | pdev, autoirq, autodma, |
3196 | parport_pc_superio_info[id->driver_data].via)) { | ||
3106 | ret++; | 3197 | ret++; |
3107 | } | 3198 | } |
3108 | } | 3199 | } |
@@ -3111,7 +3202,10 @@ static int __init parport_pc_init_superio (int autoirq, int autodma) | |||
3111 | } | 3202 | } |
3112 | #else | 3203 | #else |
3113 | static struct pci_driver parport_pc_pci_driver; | 3204 | static struct pci_driver parport_pc_pci_driver; |
3114 | static int __init parport_pc_init_superio(int autoirq, int autodma) {return 0;} | 3205 | static int __init parport_pc_init_superio(int autoirq, int autodma) |
3206 | { | ||
3207 | return 0; | ||
3208 | } | ||
3115 | #endif /* CONFIG_PCI */ | 3209 | #endif /* CONFIG_PCI */ |
3116 | 3210 | ||
3117 | #ifdef CONFIG_PNP | 3211 | #ifdef CONFIG_PNP |
@@ -3124,44 +3218,45 @@ static const struct pnp_device_id parport_pc_pnp_tbl[] = { | |||
3124 | { } | 3218 | { } |
3125 | }; | 3219 | }; |
3126 | 3220 | ||
3127 | MODULE_DEVICE_TABLE(pnp,parport_pc_pnp_tbl); | 3221 | MODULE_DEVICE_TABLE(pnp, parport_pc_pnp_tbl); |
3128 | 3222 | ||
3129 | static int parport_pc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *id) | 3223 | static int parport_pc_pnp_probe(struct pnp_dev *dev, |
3224 | const struct pnp_device_id *id) | ||
3130 | { | 3225 | { |
3131 | struct parport *pdata; | 3226 | struct parport *pdata; |
3132 | unsigned long io_lo, io_hi; | 3227 | unsigned long io_lo, io_hi; |
3133 | int dma, irq; | 3228 | int dma, irq; |
3134 | 3229 | ||
3135 | if (pnp_port_valid(dev,0) && | 3230 | if (pnp_port_valid(dev, 0) && |
3136 | !(pnp_port_flags(dev,0) & IORESOURCE_DISABLED)) { | 3231 | !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) { |
3137 | io_lo = pnp_port_start(dev,0); | 3232 | io_lo = pnp_port_start(dev, 0); |
3138 | } else | 3233 | } else |
3139 | return -EINVAL; | 3234 | return -EINVAL; |
3140 | 3235 | ||
3141 | if (pnp_port_valid(dev,1) && | 3236 | if (pnp_port_valid(dev, 1) && |
3142 | !(pnp_port_flags(dev,1) & IORESOURCE_DISABLED)) { | 3237 | !(pnp_port_flags(dev, 1) & IORESOURCE_DISABLED)) { |
3143 | io_hi = pnp_port_start(dev,1); | 3238 | io_hi = pnp_port_start(dev, 1); |
3144 | } else | 3239 | } else |
3145 | io_hi = 0; | 3240 | io_hi = 0; |
3146 | 3241 | ||
3147 | if (pnp_irq_valid(dev,0) && | 3242 | if (pnp_irq_valid(dev, 0) && |
3148 | !(pnp_irq_flags(dev,0) & IORESOURCE_DISABLED)) { | 3243 | !(pnp_irq_flags(dev, 0) & IORESOURCE_DISABLED)) { |
3149 | irq = pnp_irq(dev,0); | 3244 | irq = pnp_irq(dev, 0); |
3150 | } else | 3245 | } else |
3151 | irq = PARPORT_IRQ_NONE; | 3246 | irq = PARPORT_IRQ_NONE; |
3152 | 3247 | ||
3153 | if (pnp_dma_valid(dev,0) && | 3248 | if (pnp_dma_valid(dev, 0) && |
3154 | !(pnp_dma_flags(dev,0) & IORESOURCE_DISABLED)) { | 3249 | !(pnp_dma_flags(dev, 0) & IORESOURCE_DISABLED)) { |
3155 | dma = pnp_dma(dev,0); | 3250 | dma = pnp_dma(dev, 0); |
3156 | } else | 3251 | } else |
3157 | dma = PARPORT_DMA_NONE; | 3252 | dma = PARPORT_DMA_NONE; |
3158 | 3253 | ||
3159 | dev_info(&dev->dev, "reported by %s\n", dev->protocol->name); | 3254 | dev_info(&dev->dev, "reported by %s\n", dev->protocol->name); |
3160 | if (!(pdata = parport_pc_probe_port(io_lo, io_hi, | 3255 | pdata = parport_pc_probe_port(io_lo, io_hi, irq, dma, &dev->dev, 0); |
3161 | irq, dma, &dev->dev, 0))) | 3256 | if (pdata == NULL) |
3162 | return -ENODEV; | 3257 | return -ENODEV; |
3163 | 3258 | ||
3164 | pnp_set_drvdata(dev,pdata); | 3259 | pnp_set_drvdata(dev, pdata); |
3165 | return 0; | 3260 | return 0; |
3166 | } | 3261 | } |
3167 | 3262 | ||
@@ -3203,7 +3298,7 @@ static struct platform_driver parport_pc_platform_driver = { | |||
3203 | 3298 | ||
3204 | /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */ | 3299 | /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */ |
3205 | static int __devinit __attribute__((unused)) | 3300 | static int __devinit __attribute__((unused)) |
3206 | parport_pc_find_isa_ports (int autoirq, int autodma) | 3301 | parport_pc_find_isa_ports(int autoirq, int autodma) |
3207 | { | 3302 | { |
3208 | int count = 0; | 3303 | int count = 0; |
3209 | 3304 | ||
@@ -3227,7 +3322,7 @@ parport_pc_find_isa_ports (int autoirq, int autodma) | |||
3227 | * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY | 3322 | * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY |
3228 | * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO | 3323 | * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO |
3229 | */ | 3324 | */ |
3230 | static void __init parport_pc_find_ports (int autoirq, int autodma) | 3325 | static void __init parport_pc_find_ports(int autoirq, int autodma) |
3231 | { | 3326 | { |
3232 | int count = 0, err; | 3327 | int count = 0, err; |
3233 | 3328 | ||
@@ -3261,11 +3356,18 @@ static void __init parport_pc_find_ports (int autoirq, int autodma) | |||
3261 | * syntax and keep in mind that code below is a cleaned up version. | 3356 | * syntax and keep in mind that code below is a cleaned up version. |
3262 | */ | 3357 | */ |
3263 | 3358 | ||
3264 | static int __initdata io[PARPORT_PC_MAX_PORTS+1] = { [0 ... PARPORT_PC_MAX_PORTS] = 0 }; | 3359 | static int __initdata io[PARPORT_PC_MAX_PORTS+1] = { |
3265 | static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] = | 3360 | [0 ... PARPORT_PC_MAX_PORTS] = 0 |
3266 | { [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO }; | 3361 | }; |
3267 | static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE }; | 3362 | static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] = { |
3268 | static int __initdata irqval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY }; | 3363 | [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO |
3364 | }; | ||
3365 | static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = { | ||
3366 | [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE | ||
3367 | }; | ||
3368 | static int __initdata irqval[PARPORT_PC_MAX_PORTS] = { | ||
3369 | [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY | ||
3370 | }; | ||
3269 | 3371 | ||
3270 | static int __init parport_parse_param(const char *s, int *val, | 3372 | static int __init parport_parse_param(const char *s, int *val, |
3271 | int automatic, int none, int nofifo) | 3373 | int automatic, int none, int nofifo) |
@@ -3306,18 +3408,19 @@ static int __init parport_parse_dma(const char *dmastr, int *val) | |||
3306 | #ifdef CONFIG_PCI | 3408 | #ifdef CONFIG_PCI |
3307 | static int __init parport_init_mode_setup(char *str) | 3409 | static int __init parport_init_mode_setup(char *str) |
3308 | { | 3410 | { |
3309 | printk(KERN_DEBUG "parport_pc.c: Specified parameter parport_init_mode=%s\n", str); | 3411 | printk(KERN_DEBUG |
3310 | 3412 | "parport_pc.c: Specified parameter parport_init_mode=%s\n", str); | |
3311 | if (!strcmp (str, "spp")) | 3413 | |
3312 | parport_init_mode=1; | 3414 | if (!strcmp(str, "spp")) |
3313 | if (!strcmp (str, "ps2")) | 3415 | parport_init_mode = 1; |
3314 | parport_init_mode=2; | 3416 | if (!strcmp(str, "ps2")) |
3315 | if (!strcmp (str, "epp")) | 3417 | parport_init_mode = 2; |
3316 | parport_init_mode=3; | 3418 | if (!strcmp(str, "epp")) |
3317 | if (!strcmp (str, "ecp")) | 3419 | parport_init_mode = 3; |
3318 | parport_init_mode=4; | 3420 | if (!strcmp(str, "ecp")) |
3319 | if (!strcmp (str, "ecpepp")) | 3421 | parport_init_mode = 4; |
3320 | parport_init_mode=5; | 3422 | if (!strcmp(str, "ecpepp")) |
3423 | parport_init_mode = 5; | ||
3321 | return 1; | 3424 | return 1; |
3322 | } | 3425 | } |
3323 | #endif | 3426 | #endif |
@@ -3341,7 +3444,8 @@ module_param(verbose_probing, int, 0644); | |||
3341 | #endif | 3444 | #endif |
3342 | #ifdef CONFIG_PCI | 3445 | #ifdef CONFIG_PCI |
3343 | static char *init_mode; | 3446 | static char *init_mode; |
3344 | MODULE_PARM_DESC(init_mode, "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)"); | 3447 | MODULE_PARM_DESC(init_mode, |
3448 | "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)"); | ||
3345 | module_param(init_mode, charp, 0); | 3449 | module_param(init_mode, charp, 0); |
3346 | #endif | 3450 | #endif |
3347 | 3451 | ||
@@ -3372,7 +3476,7 @@ static int __init parse_parport_params(void) | |||
3372 | irqval[0] = val; | 3476 | irqval[0] = val; |
3373 | break; | 3477 | break; |
3374 | default: | 3478 | default: |
3375 | printk (KERN_WARNING | 3479 | printk(KERN_WARNING |
3376 | "parport_pc: irq specified " | 3480 | "parport_pc: irq specified " |
3377 | "without base address. Use 'io=' " | 3481 | "without base address. Use 'io=' " |
3378 | "to specify one\n"); | 3482 | "to specify one\n"); |
@@ -3385,7 +3489,7 @@ static int __init parse_parport_params(void) | |||
3385 | dmaval[0] = val; | 3489 | dmaval[0] = val; |
3386 | break; | 3490 | break; |
3387 | default: | 3491 | default: |
3388 | printk (KERN_WARNING | 3492 | printk(KERN_WARNING |
3389 | "parport_pc: dma specified " | 3493 | "parport_pc: dma specified " |
3390 | "without base address. Use 'io=' " | 3494 | "without base address. Use 'io=' " |
3391 | "to specify one\n"); | 3495 | "to specify one\n"); |
@@ -3396,7 +3500,7 @@ static int __init parse_parport_params(void) | |||
3396 | 3500 | ||
3397 | #else | 3501 | #else |
3398 | 3502 | ||
3399 | static int parport_setup_ptr __initdata = 0; | 3503 | static int parport_setup_ptr __initdata; |
3400 | 3504 | ||
3401 | /* | 3505 | /* |
3402 | * Acceptable parameters: | 3506 | * Acceptable parameters: |
@@ -3407,7 +3511,7 @@ static int parport_setup_ptr __initdata = 0; | |||
3407 | * | 3511 | * |
3408 | * IRQ/DMA may be numeric or 'auto' or 'none' | 3512 | * IRQ/DMA may be numeric or 'auto' or 'none' |
3409 | */ | 3513 | */ |
3410 | static int __init parport_setup (char *str) | 3514 | static int __init parport_setup(char *str) |
3411 | { | 3515 | { |
3412 | char *endptr; | 3516 | char *endptr; |
3413 | char *sep; | 3517 | char *sep; |
@@ -3419,15 +3523,15 @@ static int __init parport_setup (char *str) | |||
3419 | return 1; | 3523 | return 1; |
3420 | } | 3524 | } |
3421 | 3525 | ||
3422 | if (!strncmp (str, "auto", 4)) { | 3526 | if (!strncmp(str, "auto", 4)) { |
3423 | irqval[0] = PARPORT_IRQ_AUTO; | 3527 | irqval[0] = PARPORT_IRQ_AUTO; |
3424 | dmaval[0] = PARPORT_DMA_AUTO; | 3528 | dmaval[0] = PARPORT_DMA_AUTO; |
3425 | return 1; | 3529 | return 1; |
3426 | } | 3530 | } |
3427 | 3531 | ||
3428 | val = simple_strtoul (str, &endptr, 0); | 3532 | val = simple_strtoul(str, &endptr, 0); |
3429 | if (endptr == str) { | 3533 | if (endptr == str) { |
3430 | printk (KERN_WARNING "parport=%s not understood\n", str); | 3534 | printk(KERN_WARNING "parport=%s not understood\n", str); |
3431 | return 1; | 3535 | return 1; |
3432 | } | 3536 | } |
3433 | 3537 | ||
@@ -3461,7 +3565,7 @@ static int __init parse_parport_params(void) | |||
3461 | return io[0] == PARPORT_DISABLE; | 3565 | return io[0] == PARPORT_DISABLE; |
3462 | } | 3566 | } |
3463 | 3567 | ||
3464 | __setup ("parport=", parport_setup); | 3568 | __setup("parport=", parport_setup); |
3465 | 3569 | ||
3466 | /* | 3570 | /* |
3467 | * Acceptable parameters: | 3571 | * Acceptable parameters: |
@@ -3469,7 +3573,7 @@ __setup ("parport=", parport_setup); | |||
3469 | * parport_init_mode=[spp|ps2|epp|ecp|ecpepp] | 3573 | * parport_init_mode=[spp|ps2|epp|ecp|ecpepp] |
3470 | */ | 3574 | */ |
3471 | #ifdef CONFIG_PCI | 3575 | #ifdef CONFIG_PCI |
3472 | __setup("parport_init_mode=",parport_init_mode_setup); | 3576 | __setup("parport_init_mode=", parport_init_mode_setup); |
3473 | #endif | 3577 | #endif |
3474 | #endif | 3578 | #endif |
3475 | 3579 | ||
@@ -3493,13 +3597,13 @@ static int __init parport_pc_init(void) | |||
3493 | for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) { | 3597 | for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) { |
3494 | if (!io[i]) | 3598 | if (!io[i]) |
3495 | break; | 3599 | break; |
3496 | if ((io_hi[i]) == PARPORT_IOHI_AUTO) | 3600 | if (io_hi[i] == PARPORT_IOHI_AUTO) |
3497 | io_hi[i] = 0x400 + io[i]; | 3601 | io_hi[i] = 0x400 + io[i]; |
3498 | parport_pc_probe_port(io[i], io_hi[i], | 3602 | parport_pc_probe_port(io[i], io_hi[i], |
3499 | irqval[i], dmaval[i], NULL, 0); | 3603 | irqval[i], dmaval[i], NULL, 0); |
3500 | } | 3604 | } |
3501 | } else | 3605 | } else |
3502 | parport_pc_find_ports (irqval[0], dmaval[0]); | 3606 | parport_pc_find_ports(irqval[0], dmaval[0]); |
3503 | 3607 | ||
3504 | return 0; | 3608 | return 0; |
3505 | } | 3609 | } |
@@ -3507,9 +3611,9 @@ static int __init parport_pc_init(void) | |||
3507 | static void __exit parport_pc_exit(void) | 3611 | static void __exit parport_pc_exit(void) |
3508 | { | 3612 | { |
3509 | if (pci_registered_parport) | 3613 | if (pci_registered_parport) |
3510 | pci_unregister_driver (&parport_pc_pci_driver); | 3614 | pci_unregister_driver(&parport_pc_pci_driver); |
3511 | if (pnp_registered_parport) | 3615 | if (pnp_registered_parport) |
3512 | pnp_unregister_driver (&parport_pc_pnp_driver); | 3616 | pnp_unregister_driver(&parport_pc_pnp_driver); |
3513 | platform_driver_unregister(&parport_pc_platform_driver); | 3617 | platform_driver_unregister(&parport_pc_platform_driver); |
3514 | 3618 | ||
3515 | while (!list_empty(&ports_list)) { | 3619 | while (!list_empty(&ports_list)) { |
diff --git a/drivers/parport/share.c b/drivers/parport/share.c index 0ebca450ed29..dffa5d4fb298 100644 --- a/drivers/parport/share.c +++ b/drivers/parport/share.c | |||
@@ -614,7 +614,10 @@ parport_register_device(struct parport *port, const char *name, | |||
614 | * pardevice fields. -arca | 614 | * pardevice fields. -arca |
615 | */ | 615 | */ |
616 | port->ops->init_state(tmp, tmp->state); | 616 | port->ops->init_state(tmp, tmp->state); |
617 | parport_device_proc_register(tmp); | 617 | if (!test_and_set_bit(PARPORT_DEVPROC_REGISTERED, &port->devflags)) { |
618 | port->proc_device = tmp; | ||
619 | parport_device_proc_register(tmp); | ||
620 | } | ||
618 | return tmp; | 621 | return tmp; |
619 | 622 | ||
620 | out_free_all: | 623 | out_free_all: |
@@ -646,10 +649,14 @@ void parport_unregister_device(struct pardevice *dev) | |||
646 | } | 649 | } |
647 | #endif | 650 | #endif |
648 | 651 | ||
649 | parport_device_proc_unregister(dev); | ||
650 | |||
651 | port = dev->port->physport; | 652 | port = dev->port->physport; |
652 | 653 | ||
654 | if (port->proc_device == dev) { | ||
655 | port->proc_device = NULL; | ||
656 | clear_bit(PARPORT_DEVPROC_REGISTERED, &port->devflags); | ||
657 | parport_device_proc_unregister(dev); | ||
658 | } | ||
659 | |||
653 | if (port->cad == dev) { | 660 | if (port->cad == dev) { |
654 | printk(KERN_DEBUG "%s: %s forgot to release port\n", | 661 | printk(KERN_DEBUG "%s: %s forgot to release port\n", |
655 | port->name, dev->name); | 662 | port->name, dev->name); |
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h index 4fc168b70095..e68d5f20ffb3 100644 --- a/drivers/pci/hotplug/acpiphp.h +++ b/drivers/pci/hotplug/acpiphp.h | |||
@@ -129,7 +129,6 @@ struct acpiphp_func { | |||
129 | struct acpiphp_bridge *bridge; /* Ejectable PCI-to-PCI bridge */ | 129 | struct acpiphp_bridge *bridge; /* Ejectable PCI-to-PCI bridge */ |
130 | 130 | ||
131 | struct list_head sibling; | 131 | struct list_head sibling; |
132 | struct pci_dev *pci_dev; | ||
133 | struct notifier_block nb; | 132 | struct notifier_block nb; |
134 | acpi_handle handle; | 133 | acpi_handle handle; |
135 | 134 | ||
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index a33794d9e0dc..3a6064bce561 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c | |||
@@ -32,9 +32,6 @@ | |||
32 | 32 | ||
33 | /* | 33 | /* |
34 | * Lifetime rules for pci_dev: | 34 | * Lifetime rules for pci_dev: |
35 | * - The one in acpiphp_func has its refcount elevated by pci_get_slot() | ||
36 | * when the driver is loaded or when an insertion event occurs. It loses | ||
37 | * a refcount when its ejected or the driver unloads. | ||
38 | * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot() | 35 | * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot() |
39 | * when the bridge is scanned and it loses a refcount when the bridge | 36 | * when the bridge is scanned and it loses a refcount when the bridge |
40 | * is removed. | 37 | * is removed. |
@@ -130,6 +127,7 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
130 | unsigned long long adr, sun; | 127 | unsigned long long adr, sun; |
131 | int device, function, retval; | 128 | int device, function, retval; |
132 | struct pci_bus *pbus = bridge->pci_bus; | 129 | struct pci_bus *pbus = bridge->pci_bus; |
130 | struct pci_dev *pdev; | ||
133 | 131 | ||
134 | if (!acpi_pci_check_ejectable(pbus, handle) && !is_dock_device(handle)) | 132 | if (!acpi_pci_check_ejectable(pbus, handle) && !is_dock_device(handle)) |
135 | return AE_OK; | 133 | return AE_OK; |
@@ -213,10 +211,10 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
213 | newfunc->slot = slot; | 211 | newfunc->slot = slot; |
214 | list_add_tail(&newfunc->sibling, &slot->funcs); | 212 | list_add_tail(&newfunc->sibling, &slot->funcs); |
215 | 213 | ||
216 | /* associate corresponding pci_dev */ | 214 | pdev = pci_get_slot(pbus, PCI_DEVFN(device, function)); |
217 | newfunc->pci_dev = pci_get_slot(pbus, PCI_DEVFN(device, function)); | 215 | if (pdev) { |
218 | if (newfunc->pci_dev) { | ||
219 | slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); | 216 | slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); |
217 | pci_dev_put(pdev); | ||
220 | } | 218 | } |
221 | 219 | ||
222 | if (is_dock_device(handle)) { | 220 | if (is_dock_device(handle)) { |
@@ -617,7 +615,6 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge) | |||
617 | if (ACPI_FAILURE(status)) | 615 | if (ACPI_FAILURE(status)) |
618 | err("failed to remove notify handler\n"); | 616 | err("failed to remove notify handler\n"); |
619 | } | 617 | } |
620 | pci_dev_put(func->pci_dev); | ||
621 | list_del(list); | 618 | list_del(list); |
622 | kfree(func); | 619 | kfree(func); |
623 | } | 620 | } |
@@ -1101,22 +1098,24 @@ static int __ref enable_device(struct acpiphp_slot *slot) | |||
1101 | pci_enable_bridges(bus); | 1098 | pci_enable_bridges(bus); |
1102 | pci_bus_add_devices(bus); | 1099 | pci_bus_add_devices(bus); |
1103 | 1100 | ||
1104 | /* associate pci_dev to our representation */ | ||
1105 | list_for_each (l, &slot->funcs) { | 1101 | list_for_each (l, &slot->funcs) { |
1106 | func = list_entry(l, struct acpiphp_func, sibling); | 1102 | func = list_entry(l, struct acpiphp_func, sibling); |
1107 | func->pci_dev = pci_get_slot(bus, PCI_DEVFN(slot->device, | 1103 | dev = pci_get_slot(bus, PCI_DEVFN(slot->device, |
1108 | func->function)); | 1104 | func->function)); |
1109 | if (!func->pci_dev) | 1105 | if (!dev) |
1110 | continue; | 1106 | continue; |
1111 | 1107 | ||
1112 | if (func->pci_dev->hdr_type != PCI_HEADER_TYPE_BRIDGE && | 1108 | if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE && |
1113 | func->pci_dev->hdr_type != PCI_HEADER_TYPE_CARDBUS) | 1109 | dev->hdr_type != PCI_HEADER_TYPE_CARDBUS) { |
1110 | pci_dev_put(dev); | ||
1114 | continue; | 1111 | continue; |
1112 | } | ||
1115 | 1113 | ||
1116 | status = find_p2p_bridge(func->handle, (u32)1, bus, NULL); | 1114 | status = find_p2p_bridge(func->handle, (u32)1, bus, NULL); |
1117 | if (ACPI_FAILURE(status)) | 1115 | if (ACPI_FAILURE(status)) |
1118 | warn("find_p2p_bridge failed (error code = 0x%x)\n", | 1116 | warn("find_p2p_bridge failed (error code = 0x%x)\n", |
1119 | status); | 1117 | status); |
1118 | pci_dev_put(dev); | ||
1120 | } | 1119 | } |
1121 | 1120 | ||
1122 | slot->flags |= SLOT_ENABLED; | 1121 | slot->flags |= SLOT_ENABLED; |
@@ -1142,17 +1141,14 @@ static void disable_bridges(struct pci_bus *bus) | |||
1142 | */ | 1141 | */ |
1143 | static int disable_device(struct acpiphp_slot *slot) | 1142 | static int disable_device(struct acpiphp_slot *slot) |
1144 | { | 1143 | { |
1145 | int retval = 0; | ||
1146 | struct acpiphp_func *func; | 1144 | struct acpiphp_func *func; |
1147 | struct list_head *l; | 1145 | struct pci_dev *pdev; |
1148 | 1146 | ||
1149 | /* is this slot already disabled? */ | 1147 | /* is this slot already disabled? */ |
1150 | if (!(slot->flags & SLOT_ENABLED)) | 1148 | if (!(slot->flags & SLOT_ENABLED)) |
1151 | goto err_exit; | 1149 | goto err_exit; |
1152 | 1150 | ||
1153 | list_for_each (l, &slot->funcs) { | 1151 | list_for_each_entry(func, &slot->funcs, sibling) { |
1154 | func = list_entry(l, struct acpiphp_func, sibling); | ||
1155 | |||
1156 | if (func->bridge) { | 1152 | if (func->bridge) { |
1157 | /* cleanup p2p bridges under this P2P bridge */ | 1153 | /* cleanup p2p bridges under this P2P bridge */ |
1158 | cleanup_p2p_bridge(func->bridge->handle, | 1154 | cleanup_p2p_bridge(func->bridge->handle, |
@@ -1160,35 +1156,28 @@ static int disable_device(struct acpiphp_slot *slot) | |||
1160 | func->bridge = NULL; | 1156 | func->bridge = NULL; |
1161 | } | 1157 | } |
1162 | 1158 | ||
1163 | if (func->pci_dev) { | 1159 | pdev = pci_get_slot(slot->bridge->pci_bus, |
1164 | pci_stop_bus_device(func->pci_dev); | 1160 | PCI_DEVFN(slot->device, func->function)); |
1165 | if (func->pci_dev->subordinate) { | 1161 | if (pdev) { |
1166 | disable_bridges(func->pci_dev->subordinate); | 1162 | pci_stop_bus_device(pdev); |
1167 | pci_disable_device(func->pci_dev); | 1163 | if (pdev->subordinate) { |
1164 | disable_bridges(pdev->subordinate); | ||
1165 | pci_disable_device(pdev); | ||
1168 | } | 1166 | } |
1167 | pci_remove_bus_device(pdev); | ||
1168 | pci_dev_put(pdev); | ||
1169 | } | 1169 | } |
1170 | } | 1170 | } |
1171 | 1171 | ||
1172 | list_for_each (l, &slot->funcs) { | 1172 | list_for_each_entry(func, &slot->funcs, sibling) { |
1173 | func = list_entry(l, struct acpiphp_func, sibling); | ||
1174 | |||
1175 | acpiphp_unconfigure_ioapics(func->handle); | 1173 | acpiphp_unconfigure_ioapics(func->handle); |
1176 | acpiphp_bus_trim(func->handle); | 1174 | acpiphp_bus_trim(func->handle); |
1177 | /* try to remove anyway. | ||
1178 | * acpiphp_bus_add might have been failed */ | ||
1179 | |||
1180 | if (!func->pci_dev) | ||
1181 | continue; | ||
1182 | |||
1183 | pci_remove_bus_device(func->pci_dev); | ||
1184 | pci_dev_put(func->pci_dev); | ||
1185 | func->pci_dev = NULL; | ||
1186 | } | 1175 | } |
1187 | 1176 | ||
1188 | slot->flags &= (~SLOT_ENABLED); | 1177 | slot->flags &= (~SLOT_ENABLED); |
1189 | 1178 | ||
1190 | err_exit: | 1179 | err_exit: |
1191 | return retval; | 1180 | return 0; |
1192 | } | 1181 | } |
1193 | 1182 | ||
1194 | 1183 | ||
diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c index dd18f857dfb0..42e4260c3b12 100644 --- a/drivers/pci/hotplug/ibmphp_core.c +++ b/drivers/pci/hotplug/ibmphp_core.c | |||
@@ -153,45 +153,47 @@ int ibmphp_init_devno(struct slot **cur_slot) | |||
153 | return -1; | 153 | return -1; |
154 | } | 154 | } |
155 | for (loop = 0; loop < len; loop++) { | 155 | for (loop = 0; loop < len; loop++) { |
156 | if ((*cur_slot)->number == rtable->slots[loop].slot) { | 156 | if ((*cur_slot)->number == rtable->slots[loop].slot && |
157 | if ((*cur_slot)->bus == rtable->slots[loop].bus) { | 157 | (*cur_slot)->bus == rtable->slots[loop].bus) { |
158 | struct io_apic_irq_attr irq_attr; | ||
159 | |||
158 | (*cur_slot)->device = PCI_SLOT(rtable->slots[loop].devfn); | 160 | (*cur_slot)->device = PCI_SLOT(rtable->slots[loop].devfn); |
159 | for (i = 0; i < 4; i++) | 161 | for (i = 0; i < 4; i++) |
160 | (*cur_slot)->irq[i] = IO_APIC_get_PCI_irq_vector((int) (*cur_slot)->bus, | 162 | (*cur_slot)->irq[i] = IO_APIC_get_PCI_irq_vector((int) (*cur_slot)->bus, |
161 | (int) (*cur_slot)->device, i); | 163 | (int) (*cur_slot)->device, i, |
162 | 164 | &irq_attr); | |
163 | debug("(*cur_slot)->irq[0] = %x\n", | 165 | |
164 | (*cur_slot)->irq[0]); | 166 | debug("(*cur_slot)->irq[0] = %x\n", |
165 | debug("(*cur_slot)->irq[1] = %x\n", | 167 | (*cur_slot)->irq[0]); |
166 | (*cur_slot)->irq[1]); | 168 | debug("(*cur_slot)->irq[1] = %x\n", |
167 | debug("(*cur_slot)->irq[2] = %x\n", | 169 | (*cur_slot)->irq[1]); |
168 | (*cur_slot)->irq[2]); | 170 | debug("(*cur_slot)->irq[2] = %x\n", |
169 | debug("(*cur_slot)->irq[3] = %x\n", | 171 | (*cur_slot)->irq[2]); |
170 | (*cur_slot)->irq[3]); | 172 | debug("(*cur_slot)->irq[3] = %x\n", |
171 | 173 | (*cur_slot)->irq[3]); | |
172 | debug("rtable->exlusive_irqs = %x\n", | 174 | |
175 | debug("rtable->exlusive_irqs = %x\n", | ||
173 | rtable->exclusive_irqs); | 176 | rtable->exclusive_irqs); |
174 | debug("rtable->slots[loop].irq[0].bitmap = %x\n", | 177 | debug("rtable->slots[loop].irq[0].bitmap = %x\n", |
175 | rtable->slots[loop].irq[0].bitmap); | 178 | rtable->slots[loop].irq[0].bitmap); |
176 | debug("rtable->slots[loop].irq[1].bitmap = %x\n", | 179 | debug("rtable->slots[loop].irq[1].bitmap = %x\n", |
177 | rtable->slots[loop].irq[1].bitmap); | 180 | rtable->slots[loop].irq[1].bitmap); |
178 | debug("rtable->slots[loop].irq[2].bitmap = %x\n", | 181 | debug("rtable->slots[loop].irq[2].bitmap = %x\n", |
179 | rtable->slots[loop].irq[2].bitmap); | 182 | rtable->slots[loop].irq[2].bitmap); |
180 | debug("rtable->slots[loop].irq[3].bitmap = %x\n", | 183 | debug("rtable->slots[loop].irq[3].bitmap = %x\n", |
181 | rtable->slots[loop].irq[3].bitmap); | 184 | rtable->slots[loop].irq[3].bitmap); |
182 | 185 | ||
183 | debug("rtable->slots[loop].irq[0].link = %x\n", | 186 | debug("rtable->slots[loop].irq[0].link = %x\n", |
184 | rtable->slots[loop].irq[0].link); | 187 | rtable->slots[loop].irq[0].link); |
185 | debug("rtable->slots[loop].irq[1].link = %x\n", | 188 | debug("rtable->slots[loop].irq[1].link = %x\n", |
186 | rtable->slots[loop].irq[1].link); | 189 | rtable->slots[loop].irq[1].link); |
187 | debug("rtable->slots[loop].irq[2].link = %x\n", | 190 | debug("rtable->slots[loop].irq[2].link = %x\n", |
188 | rtable->slots[loop].irq[2].link); | 191 | rtable->slots[loop].irq[2].link); |
189 | debug("rtable->slots[loop].irq[3].link = %x\n", | 192 | debug("rtable->slots[loop].irq[3].link = %x\n", |
190 | rtable->slots[loop].irq[3].link); | 193 | rtable->slots[loop].irq[3].link); |
191 | debug("end of init_devno\n"); | 194 | debug("end of init_devno\n"); |
192 | kfree(rtable); | 195 | kfree(rtable); |
193 | return 0; | 196 | return 0; |
194 | } | ||
195 | } | 197 | } |
196 | } | 198 | } |
197 | 199 | ||
diff --git a/drivers/pci/htirq.c b/drivers/pci/htirq.c index 6808d8333ecc..737a1c44b07a 100644 --- a/drivers/pci/htirq.c +++ b/drivers/pci/htirq.c | |||
@@ -98,6 +98,7 @@ int __ht_create_irq(struct pci_dev *dev, int idx, ht_irq_update_t *update) | |||
98 | int max_irq; | 98 | int max_irq; |
99 | int pos; | 99 | int pos; |
100 | int irq; | 100 | int irq; |
101 | int node; | ||
101 | 102 | ||
102 | pos = pci_find_ht_capability(dev, HT_CAPTYPE_IRQ); | 103 | pos = pci_find_ht_capability(dev, HT_CAPTYPE_IRQ); |
103 | if (!pos) | 104 | if (!pos) |
@@ -125,7 +126,8 @@ int __ht_create_irq(struct pci_dev *dev, int idx, ht_irq_update_t *update) | |||
125 | cfg->msg.address_lo = 0xffffffff; | 126 | cfg->msg.address_lo = 0xffffffff; |
126 | cfg->msg.address_hi = 0xffffffff; | 127 | cfg->msg.address_hi = 0xffffffff; |
127 | 128 | ||
128 | irq = create_irq(); | 129 | node = dev_to_node(&dev->dev); |
130 | irq = create_irq_nr(0, node); | ||
129 | 131 | ||
130 | if (irq <= 0) { | 132 | if (irq <= 0) { |
131 | kfree(cfg); | 133 | kfree(cfg); |
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c index a563fbe559d0..cd389162735f 100644 --- a/drivers/pci/intel-iommu.c +++ b/drivers/pci/intel-iommu.c | |||
@@ -1972,15 +1972,6 @@ static int __init init_dmars(void) | |||
1972 | } | 1972 | } |
1973 | } | 1973 | } |
1974 | 1974 | ||
1975 | #ifdef CONFIG_INTR_REMAP | ||
1976 | if (!intr_remapping_enabled) { | ||
1977 | ret = enable_intr_remapping(0); | ||
1978 | if (ret) | ||
1979 | printk(KERN_ERR | ||
1980 | "IOMMU: enable interrupt remapping failed\n"); | ||
1981 | } | ||
1982 | #endif | ||
1983 | |||
1984 | /* | 1975 | /* |
1985 | * For each rmrr | 1976 | * For each rmrr |
1986 | * for each dev attached to rmrr | 1977 | * for each dev attached to rmrr |
diff --git a/drivers/pci/intr_remapping.c b/drivers/pci/intr_remapping.c index f5e0ea724a6f..3a0cb0bb0593 100644 --- a/drivers/pci/intr_remapping.c +++ b/drivers/pci/intr_remapping.c | |||
@@ -15,6 +15,14 @@ static struct ioapic_scope ir_ioapic[MAX_IO_APICS]; | |||
15 | static int ir_ioapic_num; | 15 | static int ir_ioapic_num; |
16 | int intr_remapping_enabled; | 16 | int intr_remapping_enabled; |
17 | 17 | ||
18 | static int disable_intremap; | ||
19 | static __init int setup_nointremap(char *str) | ||
20 | { | ||
21 | disable_intremap = 1; | ||
22 | return 0; | ||
23 | } | ||
24 | early_param("nointremap", setup_nointremap); | ||
25 | |||
18 | struct irq_2_iommu { | 26 | struct irq_2_iommu { |
19 | struct intel_iommu *iommu; | 27 | struct intel_iommu *iommu; |
20 | u16 irte_index; | 28 | u16 irte_index; |
@@ -23,15 +31,12 @@ struct irq_2_iommu { | |||
23 | }; | 31 | }; |
24 | 32 | ||
25 | #ifdef CONFIG_GENERIC_HARDIRQS | 33 | #ifdef CONFIG_GENERIC_HARDIRQS |
26 | static struct irq_2_iommu *get_one_free_irq_2_iommu(int cpu) | 34 | static struct irq_2_iommu *get_one_free_irq_2_iommu(int node) |
27 | { | 35 | { |
28 | struct irq_2_iommu *iommu; | 36 | struct irq_2_iommu *iommu; |
29 | int node; | ||
30 | |||
31 | node = cpu_to_node(cpu); | ||
32 | 37 | ||
33 | iommu = kzalloc_node(sizeof(*iommu), GFP_ATOMIC, node); | 38 | iommu = kzalloc_node(sizeof(*iommu), GFP_ATOMIC, node); |
34 | printk(KERN_DEBUG "alloc irq_2_iommu on cpu %d node %d\n", cpu, node); | 39 | printk(KERN_DEBUG "alloc irq_2_iommu on node %d\n", node); |
35 | 40 | ||
36 | return iommu; | 41 | return iommu; |
37 | } | 42 | } |
@@ -48,7 +53,7 @@ static struct irq_2_iommu *irq_2_iommu(unsigned int irq) | |||
48 | return desc->irq_2_iommu; | 53 | return desc->irq_2_iommu; |
49 | } | 54 | } |
50 | 55 | ||
51 | static struct irq_2_iommu *irq_2_iommu_alloc_cpu(unsigned int irq, int cpu) | 56 | static struct irq_2_iommu *irq_2_iommu_alloc_node(unsigned int irq, int node) |
52 | { | 57 | { |
53 | struct irq_desc *desc; | 58 | struct irq_desc *desc; |
54 | struct irq_2_iommu *irq_iommu; | 59 | struct irq_2_iommu *irq_iommu; |
@@ -56,7 +61,7 @@ static struct irq_2_iommu *irq_2_iommu_alloc_cpu(unsigned int irq, int cpu) | |||
56 | /* | 61 | /* |
57 | * alloc irq desc if not allocated already. | 62 | * alloc irq desc if not allocated already. |
58 | */ | 63 | */ |
59 | desc = irq_to_desc_alloc_cpu(irq, cpu); | 64 | desc = irq_to_desc_alloc_node(irq, node); |
60 | if (!desc) { | 65 | if (!desc) { |
61 | printk(KERN_INFO "can not get irq_desc for %d\n", irq); | 66 | printk(KERN_INFO "can not get irq_desc for %d\n", irq); |
62 | return NULL; | 67 | return NULL; |
@@ -65,14 +70,14 @@ static struct irq_2_iommu *irq_2_iommu_alloc_cpu(unsigned int irq, int cpu) | |||
65 | irq_iommu = desc->irq_2_iommu; | 70 | irq_iommu = desc->irq_2_iommu; |
66 | 71 | ||
67 | if (!irq_iommu) | 72 | if (!irq_iommu) |
68 | desc->irq_2_iommu = get_one_free_irq_2_iommu(cpu); | 73 | desc->irq_2_iommu = get_one_free_irq_2_iommu(node); |
69 | 74 | ||
70 | return desc->irq_2_iommu; | 75 | return desc->irq_2_iommu; |
71 | } | 76 | } |
72 | 77 | ||
73 | static struct irq_2_iommu *irq_2_iommu_alloc(unsigned int irq) | 78 | static struct irq_2_iommu *irq_2_iommu_alloc(unsigned int irq) |
74 | { | 79 | { |
75 | return irq_2_iommu_alloc_cpu(irq, boot_cpu_id); | 80 | return irq_2_iommu_alloc_node(irq, cpu_to_node(boot_cpu_id)); |
76 | } | 81 | } |
77 | 82 | ||
78 | #else /* !CONFIG_SPARSE_IRQ */ | 83 | #else /* !CONFIG_SPARSE_IRQ */ |
@@ -423,20 +428,6 @@ static void iommu_set_intr_remapping(struct intel_iommu *iommu, int mode) | |||
423 | readl, (sts & DMA_GSTS_IRTPS), sts); | 428 | readl, (sts & DMA_GSTS_IRTPS), sts); |
424 | spin_unlock_irqrestore(&iommu->register_lock, flags); | 429 | spin_unlock_irqrestore(&iommu->register_lock, flags); |
425 | 430 | ||
426 | if (mode == 0) { | ||
427 | spin_lock_irqsave(&iommu->register_lock, flags); | ||
428 | |||
429 | /* enable comaptiblity format interrupt pass through */ | ||
430 | cmd = iommu->gcmd | DMA_GCMD_CFI; | ||
431 | iommu->gcmd |= DMA_GCMD_CFI; | ||
432 | writel(cmd, iommu->reg + DMAR_GCMD_REG); | ||
433 | |||
434 | IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, | ||
435 | readl, (sts & DMA_GSTS_CFIS), sts); | ||
436 | |||
437 | spin_unlock_irqrestore(&iommu->register_lock, flags); | ||
438 | } | ||
439 | |||
440 | /* | 431 | /* |
441 | * global invalidation of interrupt entry cache before enabling | 432 | * global invalidation of interrupt entry cache before enabling |
442 | * interrupt-remapping. | 433 | * interrupt-remapping. |
@@ -516,6 +507,23 @@ end: | |||
516 | spin_unlock_irqrestore(&iommu->register_lock, flags); | 507 | spin_unlock_irqrestore(&iommu->register_lock, flags); |
517 | } | 508 | } |
518 | 509 | ||
510 | int __init intr_remapping_supported(void) | ||
511 | { | ||
512 | struct dmar_drhd_unit *drhd; | ||
513 | |||
514 | if (disable_intremap) | ||
515 | return 0; | ||
516 | |||
517 | for_each_drhd_unit(drhd) { | ||
518 | struct intel_iommu *iommu = drhd->iommu; | ||
519 | |||
520 | if (!ecap_ir_support(iommu->ecap)) | ||
521 | return 0; | ||
522 | } | ||
523 | |||
524 | return 1; | ||
525 | } | ||
526 | |||
519 | int __init enable_intr_remapping(int eim) | 527 | int __init enable_intr_remapping(int eim) |
520 | { | 528 | { |
521 | struct dmar_drhd_unit *drhd; | 529 | struct dmar_drhd_unit *drhd; |
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index e3c3e081b834..f1ae2475ffff 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c | |||
@@ -745,6 +745,8 @@ int pci_setup_device(struct pci_dev *dev) | |||
745 | 745 | ||
746 | /* Early fixups, before probing the BARs */ | 746 | /* Early fixups, before probing the BARs */ |
747 | pci_fixup_device(pci_fixup_early, dev); | 747 | pci_fixup_device(pci_fixup_early, dev); |
748 | /* device class may be changed after fixup */ | ||
749 | class = dev->class >> 8; | ||
748 | 750 | ||
749 | switch (dev->hdr_type) { /* header type */ | 751 | switch (dev->hdr_type) { /* header type */ |
750 | case PCI_HEADER_TYPE_NORMAL: /* standard header */ | 752 | case PCI_HEADER_TYPE_NORMAL: /* standard header */ |
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c index adf17856bacc..7f207f335bec 100644 --- a/drivers/pnp/pnpacpi/rsparser.c +++ b/drivers/pnp/pnpacpi/rsparser.c | |||
@@ -123,7 +123,7 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev, | |||
123 | } | 123 | } |
124 | 124 | ||
125 | flags = irq_flags(triggering, polarity, shareable); | 125 | flags = irq_flags(triggering, polarity, shareable); |
126 | irq = acpi_register_gsi(gsi, triggering, polarity); | 126 | irq = acpi_register_gsi(&dev->dev, gsi, triggering, polarity); |
127 | if (irq >= 0) | 127 | if (irq >= 0) |
128 | pcibios_penalize_isa_irq(irq, 1); | 128 | pcibios_penalize_isa_irq(irq, 1); |
129 | else | 129 | else |
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 4e9851fc1746..277d35d232fa 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -692,7 +692,7 @@ config RTC_DRV_GENERIC | |||
692 | tristate "Generic RTC support" | 692 | tristate "Generic RTC support" |
693 | # Please consider writing a new RTC driver instead of using the generic | 693 | # Please consider writing a new RTC driver instead of using the generic |
694 | # RTC abstraction | 694 | # RTC abstraction |
695 | depends on PARISC || M68K || PPC | 695 | depends on PARISC || M68K || PPC || SUPERH32 |
696 | help | 696 | help |
697 | Say Y or M here to enable RTC support on systems using the generic | 697 | Say Y or M here to enable RTC support on systems using the generic |
698 | RTC abstraction. If you do not know what you are doing, you should | 698 | RTC abstraction. If you do not know what you are doing, you should |
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c index 8b7983aba8f7..36c21b19e5d7 100644 --- a/drivers/scsi/3w-9xxx.c +++ b/drivers/scsi/3w-9xxx.c | |||
@@ -1978,7 +1978,8 @@ static void twa_unmap_scsi_data(TW_Device_Extension *tw_dev, int request_id) | |||
1978 | { | 1978 | { |
1979 | struct scsi_cmnd *cmd = tw_dev->srb[request_id]; | 1979 | struct scsi_cmnd *cmd = tw_dev->srb[request_id]; |
1980 | 1980 | ||
1981 | scsi_dma_unmap(cmd); | 1981 | if (cmd->SCp.phase == TW_PHASE_SGLIST) |
1982 | scsi_dma_unmap(cmd); | ||
1982 | } /* End twa_unmap_scsi_data() */ | 1983 | } /* End twa_unmap_scsi_data() */ |
1983 | 1984 | ||
1984 | /* scsi_host_template initializer */ | 1985 | /* scsi_host_template initializer */ |
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c index c03f1d2c9e2e..faa0fcfed71e 100644 --- a/drivers/scsi/3w-xxxx.c +++ b/drivers/scsi/3w-xxxx.c | |||
@@ -6,7 +6,7 @@ | |||
6 | Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 6 | Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
7 | Brad Strand <linux@3ware.com> | 7 | Brad Strand <linux@3ware.com> |
8 | 8 | ||
9 | Copyright (C) 1999-2007 3ware Inc. | 9 | Copyright (C) 1999-2009 3ware Inc. |
10 | 10 | ||
11 | Kernel compatiblity By: Andre Hedrick <andre@suse.com> | 11 | Kernel compatiblity By: Andre Hedrick <andre@suse.com> |
12 | Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com> | 12 | Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com> |
@@ -1294,7 +1294,8 @@ static void tw_unmap_scsi_data(struct pci_dev *pdev, struct scsi_cmnd *cmd) | |||
1294 | { | 1294 | { |
1295 | dprintk(KERN_WARNING "3w-xxxx: tw_unmap_scsi_data()\n"); | 1295 | dprintk(KERN_WARNING "3w-xxxx: tw_unmap_scsi_data()\n"); |
1296 | 1296 | ||
1297 | scsi_dma_unmap(cmd); | 1297 | if (cmd->SCp.phase == TW_PHASE_SGLIST) |
1298 | scsi_dma_unmap(cmd); | ||
1298 | } /* End tw_unmap_scsi_data() */ | 1299 | } /* End tw_unmap_scsi_data() */ |
1299 | 1300 | ||
1300 | /* This function will reset a device extension */ | 1301 | /* This function will reset a device extension */ |
diff --git a/drivers/scsi/3w-xxxx.h b/drivers/scsi/3w-xxxx.h index 8e71e5e122b3..a5a2ba2561d9 100644 --- a/drivers/scsi/3w-xxxx.h +++ b/drivers/scsi/3w-xxxx.h | |||
@@ -6,7 +6,7 @@ | |||
6 | Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 6 | Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
7 | Brad Strand <linux@3ware.com> | 7 | Brad Strand <linux@3ware.com> |
8 | 8 | ||
9 | Copyright (C) 1999-2007 3ware Inc. | 9 | Copyright (C) 1999-2009 3ware Inc. |
10 | 10 | ||
11 | Kernel compatiblity By: Andre Hedrick <andre@suse.com> | 11 | Kernel compatiblity By: Andre Hedrick <andre@suse.com> |
12 | Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com> | 12 | Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com> |
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index 8ed2990c826e..fb2740789b68 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig | |||
@@ -628,6 +628,17 @@ config FCOE | |||
628 | ---help--- | 628 | ---help--- |
629 | Fibre Channel over Ethernet module | 629 | Fibre Channel over Ethernet module |
630 | 630 | ||
631 | config FCOE_FNIC | ||
632 | tristate "Cisco FNIC Driver" | ||
633 | depends on PCI && X86 | ||
634 | select LIBFC | ||
635 | help | ||
636 | This is support for the Cisco PCI-Express FCoE HBA. | ||
637 | |||
638 | To compile this driver as a module, choose M here and read | ||
639 | <file:Documentation/scsi/scsi.txt>. | ||
640 | The module will be called fnic. | ||
641 | |||
631 | config SCSI_DMX3191D | 642 | config SCSI_DMX3191D |
632 | tristate "DMX3191D SCSI support" | 643 | tristate "DMX3191D SCSI support" |
633 | depends on PCI && SCSI | 644 | depends on PCI && SCSI |
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile index e7c861ac417d..a5049cfb40ed 100644 --- a/drivers/scsi/Makefile +++ b/drivers/scsi/Makefile | |||
@@ -39,6 +39,7 @@ obj-$(CONFIG_SCSI_DH) += device_handler/ | |||
39 | obj-$(CONFIG_LIBFC) += libfc/ | 39 | obj-$(CONFIG_LIBFC) += libfc/ |
40 | obj-$(CONFIG_LIBFCOE) += fcoe/ | 40 | obj-$(CONFIG_LIBFCOE) += fcoe/ |
41 | obj-$(CONFIG_FCOE) += fcoe/ | 41 | obj-$(CONFIG_FCOE) += fcoe/ |
42 | obj-$(CONFIG_FCOE_FNIC) += fnic/ | ||
42 | obj-$(CONFIG_ISCSI_TCP) += libiscsi.o libiscsi_tcp.o iscsi_tcp.o | 43 | obj-$(CONFIG_ISCSI_TCP) += libiscsi.o libiscsi_tcp.o iscsi_tcp.o |
43 | obj-$(CONFIG_INFINIBAND_ISER) += libiscsi.o | 44 | obj-$(CONFIG_INFINIBAND_ISER) += libiscsi.o |
44 | obj-$(CONFIG_SCSI_A4000T) += 53c700.o a4000t.o | 45 | obj-$(CONFIG_SCSI_A4000T) += 53c700.o a4000t.o |
diff --git a/drivers/scsi/fnic/Makefile b/drivers/scsi/fnic/Makefile new file mode 100644 index 000000000000..37c3440bc17c --- /dev/null +++ b/drivers/scsi/fnic/Makefile | |||
@@ -0,0 +1,15 @@ | |||
1 | obj-$(CONFIG_FCOE_FNIC) += fnic.o | ||
2 | |||
3 | fnic-y := \ | ||
4 | fnic_attrs.o \ | ||
5 | fnic_isr.o \ | ||
6 | fnic_main.o \ | ||
7 | fnic_res.o \ | ||
8 | fnic_fcs.o \ | ||
9 | fnic_scsi.o \ | ||
10 | vnic_cq.o \ | ||
11 | vnic_dev.o \ | ||
12 | vnic_intr.o \ | ||
13 | vnic_rq.o \ | ||
14 | vnic_wq_copy.o \ | ||
15 | vnic_wq.o | ||
diff --git a/drivers/scsi/fnic/cq_desc.h b/drivers/scsi/fnic/cq_desc.h new file mode 100644 index 000000000000..d1225cf6320e --- /dev/null +++ b/drivers/scsi/fnic/cq_desc.h | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _CQ_DESC_H_ | ||
19 | #define _CQ_DESC_H_ | ||
20 | |||
21 | /* | ||
22 | * Completion queue descriptor types | ||
23 | */ | ||
24 | enum cq_desc_types { | ||
25 | CQ_DESC_TYPE_WQ_ENET = 0, | ||
26 | CQ_DESC_TYPE_DESC_COPY = 1, | ||
27 | CQ_DESC_TYPE_WQ_EXCH = 2, | ||
28 | CQ_DESC_TYPE_RQ_ENET = 3, | ||
29 | CQ_DESC_TYPE_RQ_FCP = 4, | ||
30 | }; | ||
31 | |||
32 | /* Completion queue descriptor: 16B | ||
33 | * | ||
34 | * All completion queues have this basic layout. The | ||
35 | * type_specfic area is unique for each completion | ||
36 | * queue type. | ||
37 | */ | ||
38 | struct cq_desc { | ||
39 | __le16 completed_index; | ||
40 | __le16 q_number; | ||
41 | u8 type_specfic[11]; | ||
42 | u8 type_color; | ||
43 | }; | ||
44 | |||
45 | #define CQ_DESC_TYPE_BITS 4 | ||
46 | #define CQ_DESC_TYPE_MASK ((1 << CQ_DESC_TYPE_BITS) - 1) | ||
47 | #define CQ_DESC_COLOR_MASK 1 | ||
48 | #define CQ_DESC_COLOR_SHIFT 7 | ||
49 | #define CQ_DESC_Q_NUM_BITS 10 | ||
50 | #define CQ_DESC_Q_NUM_MASK ((1 << CQ_DESC_Q_NUM_BITS) - 1) | ||
51 | #define CQ_DESC_COMP_NDX_BITS 12 | ||
52 | #define CQ_DESC_COMP_NDX_MASK ((1 << CQ_DESC_COMP_NDX_BITS) - 1) | ||
53 | |||
54 | static inline void cq_desc_dec(const struct cq_desc *desc_arg, | ||
55 | u8 *type, u8 *color, u16 *q_number, u16 *completed_index) | ||
56 | { | ||
57 | const struct cq_desc *desc = desc_arg; | ||
58 | const u8 type_color = desc->type_color; | ||
59 | |||
60 | *color = (type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK; | ||
61 | |||
62 | /* | ||
63 | * Make sure color bit is read from desc *before* other fields | ||
64 | * are read from desc. Hardware guarantees color bit is last | ||
65 | * bit (byte) written. Adding the rmb() prevents the compiler | ||
66 | * and/or CPU from reordering the reads which would potentially | ||
67 | * result in reading stale values. | ||
68 | */ | ||
69 | |||
70 | rmb(); | ||
71 | |||
72 | *type = type_color & CQ_DESC_TYPE_MASK; | ||
73 | *q_number = le16_to_cpu(desc->q_number) & CQ_DESC_Q_NUM_MASK; | ||
74 | *completed_index = le16_to_cpu(desc->completed_index) & | ||
75 | CQ_DESC_COMP_NDX_MASK; | ||
76 | } | ||
77 | |||
78 | #endif /* _CQ_DESC_H_ */ | ||
diff --git a/drivers/scsi/fnic/cq_enet_desc.h b/drivers/scsi/fnic/cq_enet_desc.h new file mode 100644 index 000000000000..a9fa26f82ddd --- /dev/null +++ b/drivers/scsi/fnic/cq_enet_desc.h | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _CQ_ENET_DESC_H_ | ||
19 | #define _CQ_ENET_DESC_H_ | ||
20 | |||
21 | #include "cq_desc.h" | ||
22 | |||
23 | /* Ethernet completion queue descriptor: 16B */ | ||
24 | struct cq_enet_wq_desc { | ||
25 | __le16 completed_index; | ||
26 | __le16 q_number; | ||
27 | u8 reserved[11]; | ||
28 | u8 type_color; | ||
29 | }; | ||
30 | |||
31 | static inline void cq_enet_wq_desc_dec(struct cq_enet_wq_desc *desc, | ||
32 | u8 *type, u8 *color, u16 *q_number, u16 *completed_index) | ||
33 | { | ||
34 | cq_desc_dec((struct cq_desc *)desc, type, | ||
35 | color, q_number, completed_index); | ||
36 | } | ||
37 | |||
38 | /* Completion queue descriptor: Ethernet receive queue, 16B */ | ||
39 | struct cq_enet_rq_desc { | ||
40 | __le16 completed_index_flags; | ||
41 | __le16 q_number_rss_type_flags; | ||
42 | __le32 rss_hash; | ||
43 | __le16 bytes_written_flags; | ||
44 | __le16 vlan; | ||
45 | __le16 checksum_fcoe; | ||
46 | u8 flags; | ||
47 | u8 type_color; | ||
48 | }; | ||
49 | |||
50 | #define CQ_ENET_RQ_DESC_FLAGS_INGRESS_PORT (0x1 << 12) | ||
51 | #define CQ_ENET_RQ_DESC_FLAGS_FCOE (0x1 << 13) | ||
52 | #define CQ_ENET_RQ_DESC_FLAGS_EOP (0x1 << 14) | ||
53 | #define CQ_ENET_RQ_DESC_FLAGS_SOP (0x1 << 15) | ||
54 | |||
55 | #define CQ_ENET_RQ_DESC_RSS_TYPE_BITS 4 | ||
56 | #define CQ_ENET_RQ_DESC_RSS_TYPE_MASK \ | ||
57 | ((1 << CQ_ENET_RQ_DESC_RSS_TYPE_BITS) - 1) | ||
58 | #define CQ_ENET_RQ_DESC_RSS_TYPE_NONE 0 | ||
59 | #define CQ_ENET_RQ_DESC_RSS_TYPE_IPv4 1 | ||
60 | #define CQ_ENET_RQ_DESC_RSS_TYPE_TCP_IPv4 2 | ||
61 | #define CQ_ENET_RQ_DESC_RSS_TYPE_IPv6 3 | ||
62 | #define CQ_ENET_RQ_DESC_RSS_TYPE_TCP_IPv6 4 | ||
63 | #define CQ_ENET_RQ_DESC_RSS_TYPE_IPv6_EX 5 | ||
64 | #define CQ_ENET_RQ_DESC_RSS_TYPE_TCP_IPv6_EX 6 | ||
65 | |||
66 | #define CQ_ENET_RQ_DESC_FLAGS_CSUM_NOT_CALC (0x1 << 14) | ||
67 | |||
68 | #define CQ_ENET_RQ_DESC_BYTES_WRITTEN_BITS 14 | ||
69 | #define CQ_ENET_RQ_DESC_BYTES_WRITTEN_MASK \ | ||
70 | ((1 << CQ_ENET_RQ_DESC_BYTES_WRITTEN_BITS) - 1) | ||
71 | #define CQ_ENET_RQ_DESC_FLAGS_TRUNCATED (0x1 << 14) | ||
72 | #define CQ_ENET_RQ_DESC_FLAGS_VLAN_STRIPPED (0x1 << 15) | ||
73 | |||
74 | #define CQ_ENET_RQ_DESC_FCOE_SOF_BITS 4 | ||
75 | #define CQ_ENET_RQ_DESC_FCOE_SOF_MASK \ | ||
76 | ((1 << CQ_ENET_RQ_DESC_FCOE_SOF_BITS) - 1) | ||
77 | #define CQ_ENET_RQ_DESC_FCOE_EOF_BITS 8 | ||
78 | #define CQ_ENET_RQ_DESC_FCOE_EOF_MASK \ | ||
79 | ((1 << CQ_ENET_RQ_DESC_FCOE_EOF_BITS) - 1) | ||
80 | #define CQ_ENET_RQ_DESC_FCOE_EOF_SHIFT 8 | ||
81 | |||
82 | #define CQ_ENET_RQ_DESC_FLAGS_TCP_UDP_CSUM_OK (0x1 << 0) | ||
83 | #define CQ_ENET_RQ_DESC_FCOE_FC_CRC_OK (0x1 << 0) | ||
84 | #define CQ_ENET_RQ_DESC_FLAGS_UDP (0x1 << 1) | ||
85 | #define CQ_ENET_RQ_DESC_FCOE_ENC_ERROR (0x1 << 1) | ||
86 | #define CQ_ENET_RQ_DESC_FLAGS_TCP (0x1 << 2) | ||
87 | #define CQ_ENET_RQ_DESC_FLAGS_IPV4_CSUM_OK (0x1 << 3) | ||
88 | #define CQ_ENET_RQ_DESC_FLAGS_IPV6 (0x1 << 4) | ||
89 | #define CQ_ENET_RQ_DESC_FLAGS_IPV4 (0x1 << 5) | ||
90 | #define CQ_ENET_RQ_DESC_FLAGS_IPV4_FRAGMENT (0x1 << 6) | ||
91 | #define CQ_ENET_RQ_DESC_FLAGS_FCS_OK (0x1 << 7) | ||
92 | |||
93 | static inline void cq_enet_rq_desc_dec(struct cq_enet_rq_desc *desc, | ||
94 | u8 *type, u8 *color, u16 *q_number, u16 *completed_index, | ||
95 | u8 *ingress_port, u8 *fcoe, u8 *eop, u8 *sop, u8 *rss_type, | ||
96 | u8 *csum_not_calc, u32 *rss_hash, u16 *bytes_written, u8 *packet_error, | ||
97 | u8 *vlan_stripped, u16 *vlan, u16 *checksum, u8 *fcoe_sof, | ||
98 | u8 *fcoe_fc_crc_ok, u8 *fcoe_enc_error, u8 *fcoe_eof, | ||
99 | u8 *tcp_udp_csum_ok, u8 *udp, u8 *tcp, u8 *ipv4_csum_ok, | ||
100 | u8 *ipv6, u8 *ipv4, u8 *ipv4_fragment, u8 *fcs_ok) | ||
101 | { | ||
102 | u16 completed_index_flags = le16_to_cpu(desc->completed_index_flags); | ||
103 | u16 q_number_rss_type_flags = | ||
104 | le16_to_cpu(desc->q_number_rss_type_flags); | ||
105 | u16 bytes_written_flags = le16_to_cpu(desc->bytes_written_flags); | ||
106 | |||
107 | cq_desc_dec((struct cq_desc *)desc, type, | ||
108 | color, q_number, completed_index); | ||
109 | |||
110 | *ingress_port = (completed_index_flags & | ||
111 | CQ_ENET_RQ_DESC_FLAGS_INGRESS_PORT) ? 1 : 0; | ||
112 | *fcoe = (completed_index_flags & CQ_ENET_RQ_DESC_FLAGS_FCOE) ? | ||
113 | 1 : 0; | ||
114 | *eop = (completed_index_flags & CQ_ENET_RQ_DESC_FLAGS_EOP) ? | ||
115 | 1 : 0; | ||
116 | *sop = (completed_index_flags & CQ_ENET_RQ_DESC_FLAGS_SOP) ? | ||
117 | 1 : 0; | ||
118 | |||
119 | *rss_type = (u8)((q_number_rss_type_flags >> CQ_DESC_Q_NUM_BITS) & | ||
120 | CQ_ENET_RQ_DESC_RSS_TYPE_MASK); | ||
121 | *csum_not_calc = (q_number_rss_type_flags & | ||
122 | CQ_ENET_RQ_DESC_FLAGS_CSUM_NOT_CALC) ? 1 : 0; | ||
123 | |||
124 | *rss_hash = le32_to_cpu(desc->rss_hash); | ||
125 | |||
126 | *bytes_written = bytes_written_flags & | ||
127 | CQ_ENET_RQ_DESC_BYTES_WRITTEN_MASK; | ||
128 | *packet_error = (bytes_written_flags & | ||
129 | CQ_ENET_RQ_DESC_FLAGS_TRUNCATED) ? 1 : 0; | ||
130 | *vlan_stripped = (bytes_written_flags & | ||
131 | CQ_ENET_RQ_DESC_FLAGS_VLAN_STRIPPED) ? 1 : 0; | ||
132 | |||
133 | *vlan = le16_to_cpu(desc->vlan); | ||
134 | |||
135 | if (*fcoe) { | ||
136 | *fcoe_sof = (u8)(le16_to_cpu(desc->checksum_fcoe) & | ||
137 | CQ_ENET_RQ_DESC_FCOE_SOF_MASK); | ||
138 | *fcoe_fc_crc_ok = (desc->flags & | ||
139 | CQ_ENET_RQ_DESC_FCOE_FC_CRC_OK) ? 1 : 0; | ||
140 | *fcoe_enc_error = (desc->flags & | ||
141 | CQ_ENET_RQ_DESC_FCOE_ENC_ERROR) ? 1 : 0; | ||
142 | *fcoe_eof = (u8)((desc->checksum_fcoe >> | ||
143 | CQ_ENET_RQ_DESC_FCOE_EOF_SHIFT) & | ||
144 | CQ_ENET_RQ_DESC_FCOE_EOF_MASK); | ||
145 | *checksum = 0; | ||
146 | } else { | ||
147 | *fcoe_sof = 0; | ||
148 | *fcoe_fc_crc_ok = 0; | ||
149 | *fcoe_enc_error = 0; | ||
150 | *fcoe_eof = 0; | ||
151 | *checksum = le16_to_cpu(desc->checksum_fcoe); | ||
152 | } | ||
153 | |||
154 | *tcp_udp_csum_ok = | ||
155 | (desc->flags & CQ_ENET_RQ_DESC_FLAGS_TCP_UDP_CSUM_OK) ? 1 : 0; | ||
156 | *udp = (desc->flags & CQ_ENET_RQ_DESC_FLAGS_UDP) ? 1 : 0; | ||
157 | *tcp = (desc->flags & CQ_ENET_RQ_DESC_FLAGS_TCP) ? 1 : 0; | ||
158 | *ipv4_csum_ok = | ||
159 | (desc->flags & CQ_ENET_RQ_DESC_FLAGS_IPV4_CSUM_OK) ? 1 : 0; | ||
160 | *ipv6 = (desc->flags & CQ_ENET_RQ_DESC_FLAGS_IPV6) ? 1 : 0; | ||
161 | *ipv4 = (desc->flags & CQ_ENET_RQ_DESC_FLAGS_IPV4) ? 1 : 0; | ||
162 | *ipv4_fragment = | ||
163 | (desc->flags & CQ_ENET_RQ_DESC_FLAGS_IPV4_FRAGMENT) ? 1 : 0; | ||
164 | *fcs_ok = (desc->flags & CQ_ENET_RQ_DESC_FLAGS_FCS_OK) ? 1 : 0; | ||
165 | } | ||
166 | |||
167 | #endif /* _CQ_ENET_DESC_H_ */ | ||
diff --git a/drivers/scsi/fnic/cq_exch_desc.h b/drivers/scsi/fnic/cq_exch_desc.h new file mode 100644 index 000000000000..501660cfe228 --- /dev/null +++ b/drivers/scsi/fnic/cq_exch_desc.h | |||
@@ -0,0 +1,182 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _CQ_EXCH_DESC_H_ | ||
19 | #define _CQ_EXCH_DESC_H_ | ||
20 | |||
21 | #include "cq_desc.h" | ||
22 | |||
23 | /* Exchange completion queue descriptor: 16B */ | ||
24 | struct cq_exch_wq_desc { | ||
25 | u16 completed_index; | ||
26 | u16 q_number; | ||
27 | u16 exchange_id; | ||
28 | u8 tmpl; | ||
29 | u8 reserved0; | ||
30 | u32 reserved1; | ||
31 | u8 exch_status; | ||
32 | u8 reserved2[2]; | ||
33 | u8 type_color; | ||
34 | }; | ||
35 | |||
36 | #define CQ_EXCH_WQ_STATUS_BITS 2 | ||
37 | #define CQ_EXCH_WQ_STATUS_MASK ((1 << CQ_EXCH_WQ_STATUS_BITS) - 1) | ||
38 | |||
39 | enum cq_exch_status_types { | ||
40 | CQ_EXCH_WQ_STATUS_TYPE_COMPLETE = 0, | ||
41 | CQ_EXCH_WQ_STATUS_TYPE_ABORT = 1, | ||
42 | CQ_EXCH_WQ_STATUS_TYPE_SGL_EOF = 2, | ||
43 | CQ_EXCH_WQ_STATUS_TYPE_TMPL_ERR = 3, | ||
44 | }; | ||
45 | |||
46 | static inline void cq_exch_wq_desc_dec(struct cq_exch_wq_desc *desc_ptr, | ||
47 | u8 *type, | ||
48 | u8 *color, | ||
49 | u16 *q_number, | ||
50 | u16 *completed_index, | ||
51 | u8 *exch_status) | ||
52 | { | ||
53 | cq_desc_dec((struct cq_desc *)desc_ptr, type, | ||
54 | color, q_number, completed_index); | ||
55 | *exch_status = desc_ptr->exch_status & CQ_EXCH_WQ_STATUS_MASK; | ||
56 | } | ||
57 | |||
58 | struct cq_fcp_rq_desc { | ||
59 | u16 completed_index_eop_sop_prt; | ||
60 | u16 q_number; | ||
61 | u16 exchange_id; | ||
62 | u16 tmpl; | ||
63 | u16 bytes_written; | ||
64 | u16 vlan; | ||
65 | u8 sof; | ||
66 | u8 eof; | ||
67 | u8 fcs_fer_fck; | ||
68 | u8 type_color; | ||
69 | }; | ||
70 | |||
71 | #define CQ_FCP_RQ_DESC_FLAGS_SOP (1 << 15) | ||
72 | #define CQ_FCP_RQ_DESC_FLAGS_EOP (1 << 14) | ||
73 | #define CQ_FCP_RQ_DESC_FLAGS_PRT (1 << 12) | ||
74 | #define CQ_FCP_RQ_DESC_TMPL_MASK 0x1f | ||
75 | #define CQ_FCP_RQ_DESC_BYTES_WRITTEN_MASK 0x3fff | ||
76 | #define CQ_FCP_RQ_DESC_PACKET_ERR_SHIFT 14 | ||
77 | #define CQ_FCP_RQ_DESC_PACKET_ERR_MASK (1 << CQ_FCP_RQ_DESC_PACKET_ERR_SHIFT) | ||
78 | #define CQ_FCP_RQ_DESC_VS_STRIPPED_SHIFT 15 | ||
79 | #define CQ_FCP_RQ_DESC_VS_STRIPPED_MASK (1 << CQ_FCP_RQ_DESC_VS_STRIPPED_SHIFT) | ||
80 | #define CQ_FCP_RQ_DESC_FC_CRC_OK_MASK 0x1 | ||
81 | #define CQ_FCP_RQ_DESC_FCOE_ERR_SHIFT 1 | ||
82 | #define CQ_FCP_RQ_DESC_FCOE_ERR_MASK (1 << CQ_FCP_RQ_DESC_FCOE_ERR_SHIFT) | ||
83 | #define CQ_FCP_RQ_DESC_FCS_OK_SHIFT 7 | ||
84 | #define CQ_FCP_RQ_DESC_FCS_OK_MASK (1 << CQ_FCP_RQ_DESC_FCS_OK_SHIFT) | ||
85 | |||
86 | static inline void cq_fcp_rq_desc_dec(struct cq_fcp_rq_desc *desc_ptr, | ||
87 | u8 *type, | ||
88 | u8 *color, | ||
89 | u16 *q_number, | ||
90 | u16 *completed_index, | ||
91 | u8 *eop, | ||
92 | u8 *sop, | ||
93 | u8 *fck, | ||
94 | u16 *exchange_id, | ||
95 | u16 *tmpl, | ||
96 | u32 *bytes_written, | ||
97 | u8 *sof, | ||
98 | u8 *eof, | ||
99 | u8 *ingress_port, | ||
100 | u8 *packet_err, | ||
101 | u8 *fcoe_err, | ||
102 | u8 *fcs_ok, | ||
103 | u8 *vlan_stripped, | ||
104 | u16 *vlan) | ||
105 | { | ||
106 | cq_desc_dec((struct cq_desc *)desc_ptr, type, | ||
107 | color, q_number, completed_index); | ||
108 | *eop = (desc_ptr->completed_index_eop_sop_prt & | ||
109 | CQ_FCP_RQ_DESC_FLAGS_EOP) ? 1 : 0; | ||
110 | *sop = (desc_ptr->completed_index_eop_sop_prt & | ||
111 | CQ_FCP_RQ_DESC_FLAGS_SOP) ? 1 : 0; | ||
112 | *ingress_port = | ||
113 | (desc_ptr->completed_index_eop_sop_prt & | ||
114 | CQ_FCP_RQ_DESC_FLAGS_PRT) ? 1 : 0; | ||
115 | *exchange_id = desc_ptr->exchange_id; | ||
116 | *tmpl = desc_ptr->tmpl & CQ_FCP_RQ_DESC_TMPL_MASK; | ||
117 | *bytes_written = | ||
118 | desc_ptr->bytes_written & CQ_FCP_RQ_DESC_BYTES_WRITTEN_MASK; | ||
119 | *packet_err = | ||
120 | (desc_ptr->bytes_written & CQ_FCP_RQ_DESC_PACKET_ERR_MASK) >> | ||
121 | CQ_FCP_RQ_DESC_PACKET_ERR_SHIFT; | ||
122 | *vlan_stripped = | ||
123 | (desc_ptr->bytes_written & CQ_FCP_RQ_DESC_VS_STRIPPED_MASK) >> | ||
124 | CQ_FCP_RQ_DESC_VS_STRIPPED_SHIFT; | ||
125 | *vlan = desc_ptr->vlan; | ||
126 | *sof = desc_ptr->sof; | ||
127 | *fck = desc_ptr->fcs_fer_fck & CQ_FCP_RQ_DESC_FC_CRC_OK_MASK; | ||
128 | *fcoe_err = (desc_ptr->fcs_fer_fck & CQ_FCP_RQ_DESC_FCOE_ERR_MASK) >> | ||
129 | CQ_FCP_RQ_DESC_FCOE_ERR_SHIFT; | ||
130 | *eof = desc_ptr->eof; | ||
131 | *fcs_ok = | ||
132 | (desc_ptr->fcs_fer_fck & CQ_FCP_RQ_DESC_FCS_OK_MASK) >> | ||
133 | CQ_FCP_RQ_DESC_FCS_OK_SHIFT; | ||
134 | } | ||
135 | |||
136 | struct cq_sgl_desc { | ||
137 | u16 exchange_id; | ||
138 | u16 q_number; | ||
139 | u32 active_burst_offset; | ||
140 | u32 tot_data_bytes; | ||
141 | u16 tmpl; | ||
142 | u8 sgl_err; | ||
143 | u8 type_color; | ||
144 | }; | ||
145 | |||
146 | enum cq_sgl_err_types { | ||
147 | CQ_SGL_ERR_NO_ERROR = 0, | ||
148 | CQ_SGL_ERR_OVERFLOW, /* data ran beyond end of SGL */ | ||
149 | CQ_SGL_ERR_SGL_LCL_ADDR_ERR, /* sgl access to local vnic addr illegal*/ | ||
150 | CQ_SGL_ERR_ADDR_RSP_ERR, /* sgl address error */ | ||
151 | CQ_SGL_ERR_DATA_RSP_ERR, /* sgl data rsp error */ | ||
152 | CQ_SGL_ERR_CNT_ZERO_ERR, /* SGL count is 0 */ | ||
153 | CQ_SGL_ERR_CNT_MAX_ERR, /* SGL count is larger than supported */ | ||
154 | CQ_SGL_ERR_ORDER_ERR, /* frames recv on both ports, order err */ | ||
155 | CQ_SGL_ERR_DATA_LCL_ADDR_ERR,/* sgl data buf to local vnic addr ill */ | ||
156 | CQ_SGL_ERR_HOST_CQ_ERR, /* host cq entry to local vnic addr ill */ | ||
157 | }; | ||
158 | |||
159 | #define CQ_SGL_SGL_ERR_MASK 0x1f | ||
160 | #define CQ_SGL_TMPL_MASK 0x1f | ||
161 | |||
162 | static inline void cq_sgl_desc_dec(struct cq_sgl_desc *desc_ptr, | ||
163 | u8 *type, | ||
164 | u8 *color, | ||
165 | u16 *q_number, | ||
166 | u16 *exchange_id, | ||
167 | u32 *active_burst_offset, | ||
168 | u32 *tot_data_bytes, | ||
169 | u16 *tmpl, | ||
170 | u8 *sgl_err) | ||
171 | { | ||
172 | /* Cheat a little by assuming exchange_id is the same as completed | ||
173 | index */ | ||
174 | cq_desc_dec((struct cq_desc *)desc_ptr, type, color, q_number, | ||
175 | exchange_id); | ||
176 | *active_burst_offset = desc_ptr->active_burst_offset; | ||
177 | *tot_data_bytes = desc_ptr->tot_data_bytes; | ||
178 | *tmpl = desc_ptr->tmpl & CQ_SGL_TMPL_MASK; | ||
179 | *sgl_err = desc_ptr->sgl_err & CQ_SGL_SGL_ERR_MASK; | ||
180 | } | ||
181 | |||
182 | #endif /* _CQ_EXCH_DESC_H_ */ | ||
diff --git a/drivers/scsi/fnic/fcpio.h b/drivers/scsi/fnic/fcpio.h new file mode 100644 index 000000000000..12d770d885c5 --- /dev/null +++ b/drivers/scsi/fnic/fcpio.h | |||
@@ -0,0 +1,780 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _FCPIO_H_ | ||
19 | #define _FCPIO_H_ | ||
20 | |||
21 | #include <linux/if_ether.h> | ||
22 | |||
23 | /* | ||
24 | * This header file includes all of the data structures used for | ||
25 | * communication by the host driver to the fcp firmware. | ||
26 | */ | ||
27 | |||
28 | /* | ||
29 | * Exchange and sequence id space allocated to the host driver | ||
30 | */ | ||
31 | #define FCPIO_HOST_EXCH_RANGE_START 0x1000 | ||
32 | #define FCPIO_HOST_EXCH_RANGE_END 0x1fff | ||
33 | #define FCPIO_HOST_SEQ_ID_RANGE_START 0x80 | ||
34 | #define FCPIO_HOST_SEQ_ID_RANGE_END 0xff | ||
35 | |||
36 | /* | ||
37 | * Command entry type | ||
38 | */ | ||
39 | enum fcpio_type { | ||
40 | /* | ||
41 | * Initiator request types | ||
42 | */ | ||
43 | FCPIO_ICMND_16 = 0x1, | ||
44 | FCPIO_ICMND_32, | ||
45 | FCPIO_ICMND_CMPL, | ||
46 | FCPIO_ITMF, | ||
47 | FCPIO_ITMF_CMPL, | ||
48 | |||
49 | /* | ||
50 | * Target request types | ||
51 | */ | ||
52 | FCPIO_TCMND_16 = 0x11, | ||
53 | FCPIO_TCMND_32, | ||
54 | FCPIO_TDATA, | ||
55 | FCPIO_TXRDY, | ||
56 | FCPIO_TRSP, | ||
57 | FCPIO_TDRSP_CMPL, | ||
58 | FCPIO_TTMF, | ||
59 | FCPIO_TTMF_ACK, | ||
60 | FCPIO_TABORT, | ||
61 | FCPIO_TABORT_CMPL, | ||
62 | |||
63 | /* | ||
64 | * Misc request types | ||
65 | */ | ||
66 | FCPIO_ACK = 0x20, | ||
67 | FCPIO_RESET, | ||
68 | FCPIO_RESET_CMPL, | ||
69 | FCPIO_FLOGI_REG, | ||
70 | FCPIO_FLOGI_REG_CMPL, | ||
71 | FCPIO_ECHO, | ||
72 | FCPIO_ECHO_CMPL, | ||
73 | FCPIO_LUNMAP_CHNG, | ||
74 | FCPIO_LUNMAP_REQ, | ||
75 | FCPIO_LUNMAP_REQ_CMPL, | ||
76 | FCPIO_FLOGI_FIP_REG, | ||
77 | FCPIO_FLOGI_FIP_REG_CMPL, | ||
78 | }; | ||
79 | |||
80 | /* | ||
81 | * Header status codes from the firmware | ||
82 | */ | ||
83 | enum fcpio_status { | ||
84 | FCPIO_SUCCESS = 0, /* request was successful */ | ||
85 | |||
86 | /* | ||
87 | * If a request to the firmware is rejected, the original request | ||
88 | * header will be returned with the status set to one of the following: | ||
89 | */ | ||
90 | FCPIO_INVALID_HEADER, /* header contains invalid data */ | ||
91 | FCPIO_OUT_OF_RESOURCE, /* out of resources to complete request */ | ||
92 | FCPIO_INVALID_PARAM, /* some parameter in request is invalid */ | ||
93 | FCPIO_REQ_NOT_SUPPORTED, /* request type is not supported */ | ||
94 | FCPIO_IO_NOT_FOUND, /* requested I/O was not found */ | ||
95 | |||
96 | /* | ||
97 | * Once a request is processed, the firmware will usually return | ||
98 | * a cmpl message type. In cases where errors occurred, | ||
99 | * the header status field would be filled in with one of the following: | ||
100 | */ | ||
101 | FCPIO_ABORTED = 0x41, /* request was aborted */ | ||
102 | FCPIO_TIMEOUT, /* request was timed out */ | ||
103 | FCPIO_SGL_INVALID, /* request was aborted due to sgl error */ | ||
104 | FCPIO_MSS_INVALID, /* request was aborted due to mss error */ | ||
105 | FCPIO_DATA_CNT_MISMATCH, /* recv/sent more/less data than exp. */ | ||
106 | FCPIO_FW_ERR, /* request was terminated due to fw error */ | ||
107 | FCPIO_ITMF_REJECTED, /* itmf req was rejected by remote node */ | ||
108 | FCPIO_ITMF_FAILED, /* itmf req was failed by remote node */ | ||
109 | FCPIO_ITMF_INCORRECT_LUN, /* itmf req targeted incorrect LUN */ | ||
110 | FCPIO_CMND_REJECTED, /* request was invalid and rejected */ | ||
111 | FCPIO_NO_PATH_AVAIL, /* no paths to the lun was available */ | ||
112 | FCPIO_PATH_FAILED, /* i/o sent to current path failed */ | ||
113 | FCPIO_LUNMAP_CHNG_PEND, /* i/o rejected due to lunmap change */ | ||
114 | }; | ||
115 | |||
116 | /* | ||
117 | * The header command tag. All host requests will use the "tag" field | ||
118 | * to mark commands with a unique tag. When the firmware responds to | ||
119 | * a host request, it will copy the tag field into the response. | ||
120 | * | ||
121 | * The only firmware requests that will use the rx_id/ox_id fields instead | ||
122 | * of the tag field will be the target command and target task management | ||
123 | * requests. These two requests do not have corresponding host requests | ||
124 | * since they come directly from the FC initiator on the network. | ||
125 | */ | ||
126 | struct fcpio_tag { | ||
127 | union { | ||
128 | u32 req_id; | ||
129 | struct { | ||
130 | u16 rx_id; | ||
131 | u16 ox_id; | ||
132 | } ex_id; | ||
133 | } u; | ||
134 | }; | ||
135 | |||
136 | static inline void | ||
137 | fcpio_tag_id_enc(struct fcpio_tag *tag, u32 id) | ||
138 | { | ||
139 | tag->u.req_id = id; | ||
140 | } | ||
141 | |||
142 | static inline void | ||
143 | fcpio_tag_id_dec(struct fcpio_tag *tag, u32 *id) | ||
144 | { | ||
145 | *id = tag->u.req_id; | ||
146 | } | ||
147 | |||
148 | static inline void | ||
149 | fcpio_tag_exid_enc(struct fcpio_tag *tag, u16 ox_id, u16 rx_id) | ||
150 | { | ||
151 | tag->u.ex_id.rx_id = rx_id; | ||
152 | tag->u.ex_id.ox_id = ox_id; | ||
153 | } | ||
154 | |||
155 | static inline void | ||
156 | fcpio_tag_exid_dec(struct fcpio_tag *tag, u16 *ox_id, u16 *rx_id) | ||
157 | { | ||
158 | *rx_id = tag->u.ex_id.rx_id; | ||
159 | *ox_id = tag->u.ex_id.ox_id; | ||
160 | } | ||
161 | |||
162 | /* | ||
163 | * The header for an fcpio request, whether from the firmware or from the | ||
164 | * host driver | ||
165 | */ | ||
166 | struct fcpio_header { | ||
167 | u8 type; /* enum fcpio_type */ | ||
168 | u8 status; /* header status entry */ | ||
169 | u16 _resvd; /* reserved */ | ||
170 | struct fcpio_tag tag; /* header tag */ | ||
171 | }; | ||
172 | |||
173 | static inline void | ||
174 | fcpio_header_enc(struct fcpio_header *hdr, | ||
175 | u8 type, u8 status, | ||
176 | struct fcpio_tag tag) | ||
177 | { | ||
178 | hdr->type = type; | ||
179 | hdr->status = status; | ||
180 | hdr->_resvd = 0; | ||
181 | hdr->tag = tag; | ||
182 | } | ||
183 | |||
184 | static inline void | ||
185 | fcpio_header_dec(struct fcpio_header *hdr, | ||
186 | u8 *type, u8 *status, | ||
187 | struct fcpio_tag *tag) | ||
188 | { | ||
189 | *type = hdr->type; | ||
190 | *status = hdr->status; | ||
191 | *tag = hdr->tag; | ||
192 | } | ||
193 | |||
194 | #define CDB_16 16 | ||
195 | #define CDB_32 32 | ||
196 | #define LUN_ADDRESS 8 | ||
197 | |||
198 | /* | ||
199 | * fcpio_icmnd_16: host -> firmware request | ||
200 | * | ||
201 | * used for sending out an initiator SCSI 16-byte command | ||
202 | */ | ||
203 | struct fcpio_icmnd_16 { | ||
204 | u32 lunmap_id; /* index into lunmap table */ | ||
205 | u8 special_req_flags; /* special exchange request flags */ | ||
206 | u8 _resvd0[3]; /* reserved */ | ||
207 | u32 sgl_cnt; /* scatter-gather list count */ | ||
208 | u32 sense_len; /* sense buffer length */ | ||
209 | u64 sgl_addr; /* scatter-gather list addr */ | ||
210 | u64 sense_addr; /* sense buffer address */ | ||
211 | u8 crn; /* SCSI Command Reference No. */ | ||
212 | u8 pri_ta; /* SCSI Priority and Task attribute */ | ||
213 | u8 _resvd1; /* reserved: should be 0 */ | ||
214 | u8 flags; /* command flags */ | ||
215 | u8 scsi_cdb[CDB_16]; /* SCSI Cmnd Descriptor Block */ | ||
216 | u32 data_len; /* length of data expected */ | ||
217 | u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */ | ||
218 | u8 _resvd2; /* reserved */ | ||
219 | u8 d_id[3]; /* FC vNIC only: Target D_ID */ | ||
220 | u16 mss; /* FC vNIC only: max burst */ | ||
221 | u16 _resvd3; /* reserved */ | ||
222 | u32 r_a_tov; /* FC vNIC only: Res. Alloc Timeout */ | ||
223 | u32 e_d_tov; /* FC vNIC only: Err Detect Timeout */ | ||
224 | }; | ||
225 | |||
226 | /* | ||
227 | * Special request flags | ||
228 | */ | ||
229 | #define FCPIO_ICMND_SRFLAG_RETRY 0x01 /* Enable Retry handling on exchange */ | ||
230 | |||
231 | /* | ||
232 | * Priority/Task Attribute settings | ||
233 | */ | ||
234 | #define FCPIO_ICMND_PTA_SIMPLE 0 /* simple task attribute */ | ||
235 | #define FCPIO_ICMND_PTA_HEADQ 1 /* head of queue task attribute */ | ||
236 | #define FCPIO_ICMND_PTA_ORDERED 2 /* ordered task attribute */ | ||
237 | #define FCPIO_ICMND_PTA_ACA 4 /* auto contingent allegiance */ | ||
238 | #define FCPIO_ICMND_PRI_SHIFT 3 /* priority field starts in bit 3 */ | ||
239 | |||
240 | /* | ||
241 | * Command flags | ||
242 | */ | ||
243 | #define FCPIO_ICMND_RDDATA 0x02 /* read data */ | ||
244 | #define FCPIO_ICMND_WRDATA 0x01 /* write data */ | ||
245 | |||
246 | /* | ||
247 | * fcpio_icmnd_32: host -> firmware request | ||
248 | * | ||
249 | * used for sending out an initiator SCSI 32-byte command | ||
250 | */ | ||
251 | struct fcpio_icmnd_32 { | ||
252 | u32 lunmap_id; /* index into lunmap table */ | ||
253 | u8 special_req_flags; /* special exchange request flags */ | ||
254 | u8 _resvd0[3]; /* reserved */ | ||
255 | u32 sgl_cnt; /* scatter-gather list count */ | ||
256 | u32 sense_len; /* sense buffer length */ | ||
257 | u64 sgl_addr; /* scatter-gather list addr */ | ||
258 | u64 sense_addr; /* sense buffer address */ | ||
259 | u8 crn; /* SCSI Command Reference No. */ | ||
260 | u8 pri_ta; /* SCSI Priority and Task attribute */ | ||
261 | u8 _resvd1; /* reserved: should be 0 */ | ||
262 | u8 flags; /* command flags */ | ||
263 | u8 scsi_cdb[CDB_32]; /* SCSI Cmnd Descriptor Block */ | ||
264 | u32 data_len; /* length of data expected */ | ||
265 | u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */ | ||
266 | u8 _resvd2; /* reserved */ | ||
267 | u8 d_id[3]; /* FC vNIC only: Target D_ID */ | ||
268 | u16 mss; /* FC vNIC only: max burst */ | ||
269 | u16 _resvd3; /* reserved */ | ||
270 | u32 r_a_tov; /* FC vNIC only: Res. Alloc Timeout */ | ||
271 | u32 e_d_tov; /* FC vNIC only: Error Detect Timeout */ | ||
272 | }; | ||
273 | |||
274 | /* | ||
275 | * fcpio_itmf: host -> firmware request | ||
276 | * | ||
277 | * used for requesting the firmware to abort a request and/or send out | ||
278 | * a task management function | ||
279 | * | ||
280 | * The t_tag field is only needed when the request type is ABT_TASK. | ||
281 | */ | ||
282 | struct fcpio_itmf { | ||
283 | u32 lunmap_id; /* index into lunmap table */ | ||
284 | u32 tm_req; /* SCSI Task Management request */ | ||
285 | u32 t_tag; /* header tag of fcpio to be aborted */ | ||
286 | u32 _resvd; /* _reserved */ | ||
287 | u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */ | ||
288 | u8 _resvd1; /* reserved */ | ||
289 | u8 d_id[3]; /* FC vNIC only: Target D_ID */ | ||
290 | u32 r_a_tov; /* FC vNIC only: R_A_TOV in msec */ | ||
291 | u32 e_d_tov; /* FC vNIC only: E_D_TOV in msec */ | ||
292 | }; | ||
293 | |||
294 | /* | ||
295 | * Task Management request | ||
296 | */ | ||
297 | enum fcpio_itmf_tm_req_type { | ||
298 | FCPIO_ITMF_ABT_TASK_TERM = 0x01, /* abort task and terminate */ | ||
299 | FCPIO_ITMF_ABT_TASK, /* abort task and issue abts */ | ||
300 | FCPIO_ITMF_ABT_TASK_SET, /* abort task set */ | ||
301 | FCPIO_ITMF_CLR_TASK_SET, /* clear task set */ | ||
302 | FCPIO_ITMF_LUN_RESET, /* logical unit reset task mgmt */ | ||
303 | FCPIO_ITMF_CLR_ACA, /* Clear ACA condition */ | ||
304 | }; | ||
305 | |||
306 | /* | ||
307 | * fcpio_tdata: host -> firmware request | ||
308 | * | ||
309 | * used for requesting the firmware to send out a read data transfer for a | ||
310 | * target command | ||
311 | */ | ||
312 | struct fcpio_tdata { | ||
313 | u16 rx_id; /* FC rx_id of target command */ | ||
314 | u16 flags; /* command flags */ | ||
315 | u32 rel_offset; /* data sequence relative offset */ | ||
316 | u32 sgl_cnt; /* scatter-gather list count */ | ||
317 | u32 data_len; /* length of data expected to send */ | ||
318 | u64 sgl_addr; /* scatter-gather list address */ | ||
319 | }; | ||
320 | |||
321 | /* | ||
322 | * Command flags | ||
323 | */ | ||
324 | #define FCPIO_TDATA_SCSI_RSP 0x01 /* send a scsi resp. after last frame */ | ||
325 | |||
326 | /* | ||
327 | * fcpio_txrdy: host -> firmware request | ||
328 | * | ||
329 | * used for requesting the firmware to send out a write data transfer for a | ||
330 | * target command | ||
331 | */ | ||
332 | struct fcpio_txrdy { | ||
333 | u16 rx_id; /* FC rx_id of target command */ | ||
334 | u16 _resvd0; /* reserved */ | ||
335 | u32 rel_offset; /* data sequence relative offset */ | ||
336 | u32 sgl_cnt; /* scatter-gather list count */ | ||
337 | u32 data_len; /* length of data expected to send */ | ||
338 | u64 sgl_addr; /* scatter-gather list address */ | ||
339 | }; | ||
340 | |||
341 | /* | ||
342 | * fcpio_trsp: host -> firmware request | ||
343 | * | ||
344 | * used for requesting the firmware to send out a response for a target | ||
345 | * command | ||
346 | */ | ||
347 | struct fcpio_trsp { | ||
348 | u16 rx_id; /* FC rx_id of target command */ | ||
349 | u16 _resvd0; /* reserved */ | ||
350 | u32 sense_len; /* sense data buffer length */ | ||
351 | u64 sense_addr; /* sense data buffer address */ | ||
352 | u16 _resvd1; /* reserved */ | ||
353 | u8 flags; /* response request flags */ | ||
354 | u8 scsi_status; /* SCSI status */ | ||
355 | u32 residual; /* SCSI data residual value of I/O */ | ||
356 | }; | ||
357 | |||
358 | /* | ||
359 | * resposnse request flags | ||
360 | */ | ||
361 | #define FCPIO_TRSP_RESID_UNDER 0x08 /* residual is valid and is underflow */ | ||
362 | #define FCPIO_TRSP_RESID_OVER 0x04 /* residual is valid and is overflow */ | ||
363 | |||
364 | /* | ||
365 | * fcpio_ttmf_ack: host -> firmware response | ||
366 | * | ||
367 | * used by the host to indicate to the firmware it has received and processed | ||
368 | * the target tmf request | ||
369 | */ | ||
370 | struct fcpio_ttmf_ack { | ||
371 | u16 rx_id; /* FC rx_id of target command */ | ||
372 | u16 _resvd0; /* reserved */ | ||
373 | u32 tmf_status; /* SCSI task management status */ | ||
374 | }; | ||
375 | |||
376 | /* | ||
377 | * fcpio_tabort: host -> firmware request | ||
378 | * | ||
379 | * used by the host to request the firmware to abort a target request that was | ||
380 | * received by the firmware | ||
381 | */ | ||
382 | struct fcpio_tabort { | ||
383 | u16 rx_id; /* rx_id of the target request */ | ||
384 | }; | ||
385 | |||
386 | /* | ||
387 | * fcpio_reset: host -> firmware request | ||
388 | * | ||
389 | * used by the host to signal a reset of the driver to the firmware | ||
390 | * and to request firmware to clean up all outstanding I/O | ||
391 | */ | ||
392 | struct fcpio_reset { | ||
393 | u32 _resvd; | ||
394 | }; | ||
395 | |||
396 | enum fcpio_flogi_reg_format_type { | ||
397 | FCPIO_FLOGI_REG_DEF_DEST = 0, /* Use the oui | s_id mac format */ | ||
398 | FCPIO_FLOGI_REG_GW_DEST, /* Use the fixed gateway mac */ | ||
399 | }; | ||
400 | |||
401 | /* | ||
402 | * fcpio_flogi_reg: host -> firmware request | ||
403 | * | ||
404 | * fc vnic only | ||
405 | * used by the host to notify the firmware of the lif's s_id | ||
406 | * and destination mac address format | ||
407 | */ | ||
408 | struct fcpio_flogi_reg { | ||
409 | u8 format; | ||
410 | u8 s_id[3]; /* FC vNIC only: Source S_ID */ | ||
411 | u8 gateway_mac[ETH_ALEN]; /* Destination gateway mac */ | ||
412 | u16 _resvd; | ||
413 | u32 r_a_tov; /* R_A_TOV in msec */ | ||
414 | u32 e_d_tov; /* E_D_TOV in msec */ | ||
415 | }; | ||
416 | |||
417 | /* | ||
418 | * fcpio_echo: host -> firmware request | ||
419 | * | ||
420 | * sends a heartbeat echo request to the firmware | ||
421 | */ | ||
422 | struct fcpio_echo { | ||
423 | u32 _resvd; | ||
424 | }; | ||
425 | |||
426 | /* | ||
427 | * fcpio_lunmap_req: host -> firmware request | ||
428 | * | ||
429 | * scsi vnic only | ||
430 | * sends a request to retrieve the lunmap table for scsi vnics | ||
431 | */ | ||
432 | struct fcpio_lunmap_req { | ||
433 | u64 addr; /* address of the buffer */ | ||
434 | u32 len; /* len of the buffer */ | ||
435 | }; | ||
436 | |||
437 | /* | ||
438 | * fcpio_flogi_fip_reg: host -> firmware request | ||
439 | * | ||
440 | * fc vnic only | ||
441 | * used by the host to notify the firmware of the lif's s_id | ||
442 | * and destination mac address format | ||
443 | */ | ||
444 | struct fcpio_flogi_fip_reg { | ||
445 | u8 _resvd0; | ||
446 | u8 s_id[3]; /* FC vNIC only: Source S_ID */ | ||
447 | u8 fcf_mac[ETH_ALEN]; /* FCF Target destination mac */ | ||
448 | u16 _resvd1; | ||
449 | u32 r_a_tov; /* R_A_TOV in msec */ | ||
450 | u32 e_d_tov; /* E_D_TOV in msec */ | ||
451 | u8 ha_mac[ETH_ALEN]; /* Host adapter source mac */ | ||
452 | u16 _resvd2; | ||
453 | }; | ||
454 | |||
455 | /* | ||
456 | * Basic structure for all fcpio structures that are sent from the host to the | ||
457 | * firmware. They are 128 bytes per structure. | ||
458 | */ | ||
459 | #define FCPIO_HOST_REQ_LEN 128 /* expected length of host requests */ | ||
460 | |||
461 | struct fcpio_host_req { | ||
462 | struct fcpio_header hdr; | ||
463 | |||
464 | union { | ||
465 | /* | ||
466 | * Defines space needed for request | ||
467 | */ | ||
468 | u8 buf[FCPIO_HOST_REQ_LEN - sizeof(struct fcpio_header)]; | ||
469 | |||
470 | /* | ||
471 | * Initiator host requests | ||
472 | */ | ||
473 | struct fcpio_icmnd_16 icmnd_16; | ||
474 | struct fcpio_icmnd_32 icmnd_32; | ||
475 | struct fcpio_itmf itmf; | ||
476 | |||
477 | /* | ||
478 | * Target host requests | ||
479 | */ | ||
480 | struct fcpio_tdata tdata; | ||
481 | struct fcpio_txrdy txrdy; | ||
482 | struct fcpio_trsp trsp; | ||
483 | struct fcpio_ttmf_ack ttmf_ack; | ||
484 | struct fcpio_tabort tabort; | ||
485 | |||
486 | /* | ||
487 | * Misc requests | ||
488 | */ | ||
489 | struct fcpio_reset reset; | ||
490 | struct fcpio_flogi_reg flogi_reg; | ||
491 | struct fcpio_echo echo; | ||
492 | struct fcpio_lunmap_req lunmap_req; | ||
493 | struct fcpio_flogi_fip_reg flogi_fip_reg; | ||
494 | } u; | ||
495 | }; | ||
496 | |||
497 | /* | ||
498 | * fcpio_icmnd_cmpl: firmware -> host response | ||
499 | * | ||
500 | * used for sending the host a response to an initiator command | ||
501 | */ | ||
502 | struct fcpio_icmnd_cmpl { | ||
503 | u8 _resvd0[6]; /* reserved */ | ||
504 | u8 flags; /* response flags */ | ||
505 | u8 scsi_status; /* SCSI status */ | ||
506 | u32 residual; /* SCSI data residual length */ | ||
507 | u32 sense_len; /* SCSI sense length */ | ||
508 | }; | ||
509 | |||
510 | /* | ||
511 | * response flags | ||
512 | */ | ||
513 | #define FCPIO_ICMND_CMPL_RESID_UNDER 0x08 /* resid under and valid */ | ||
514 | #define FCPIO_ICMND_CMPL_RESID_OVER 0x04 /* resid over and valid */ | ||
515 | |||
516 | /* | ||
517 | * fcpio_itmf_cmpl: firmware -> host response | ||
518 | * | ||
519 | * used for sending the host a response for a itmf request | ||
520 | */ | ||
521 | struct fcpio_itmf_cmpl { | ||
522 | u32 _resvd; /* reserved */ | ||
523 | }; | ||
524 | |||
525 | /* | ||
526 | * fcpio_tcmnd_16: firmware -> host request | ||
527 | * | ||
528 | * used by the firmware to notify the host of an incoming target SCSI 16-Byte | ||
529 | * request | ||
530 | */ | ||
531 | struct fcpio_tcmnd_16 { | ||
532 | u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */ | ||
533 | u8 crn; /* SCSI Command Reference No. */ | ||
534 | u8 pri_ta; /* SCSI Priority and Task attribute */ | ||
535 | u8 _resvd2; /* reserved: should be 0 */ | ||
536 | u8 flags; /* command flags */ | ||
537 | u8 scsi_cdb[CDB_16]; /* SCSI Cmnd Descriptor Block */ | ||
538 | u32 data_len; /* length of data expected */ | ||
539 | u8 _resvd1; /* reserved */ | ||
540 | u8 s_id[3]; /* FC vNIC only: Source S_ID */ | ||
541 | }; | ||
542 | |||
543 | /* | ||
544 | * Priority/Task Attribute settings | ||
545 | */ | ||
546 | #define FCPIO_TCMND_PTA_SIMPLE 0 /* simple task attribute */ | ||
547 | #define FCPIO_TCMND_PTA_HEADQ 1 /* head of queue task attribute */ | ||
548 | #define FCPIO_TCMND_PTA_ORDERED 2 /* ordered task attribute */ | ||
549 | #define FCPIO_TCMND_PTA_ACA 4 /* auto contingent allegiance */ | ||
550 | #define FCPIO_TCMND_PRI_SHIFT 3 /* priority field starts in bit 3 */ | ||
551 | |||
552 | /* | ||
553 | * Command flags | ||
554 | */ | ||
555 | #define FCPIO_TCMND_RDDATA 0x02 /* read data */ | ||
556 | #define FCPIO_TCMND_WRDATA 0x01 /* write data */ | ||
557 | |||
558 | /* | ||
559 | * fcpio_tcmnd_32: firmware -> host request | ||
560 | * | ||
561 | * used by the firmware to notify the host of an incoming target SCSI 32-Byte | ||
562 | * request | ||
563 | */ | ||
564 | struct fcpio_tcmnd_32 { | ||
565 | u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */ | ||
566 | u8 crn; /* SCSI Command Reference No. */ | ||
567 | u8 pri_ta; /* SCSI Priority and Task attribute */ | ||
568 | u8 _resvd2; /* reserved: should be 0 */ | ||
569 | u8 flags; /* command flags */ | ||
570 | u8 scsi_cdb[CDB_32]; /* SCSI Cmnd Descriptor Block */ | ||
571 | u32 data_len; /* length of data expected */ | ||
572 | u8 _resvd0; /* reserved */ | ||
573 | u8 s_id[3]; /* FC vNIC only: Source S_ID */ | ||
574 | }; | ||
575 | |||
576 | /* | ||
577 | * fcpio_tdrsp_cmpl: firmware -> host response | ||
578 | * | ||
579 | * used by the firmware to notify the host of a response to a host target | ||
580 | * command | ||
581 | */ | ||
582 | struct fcpio_tdrsp_cmpl { | ||
583 | u16 rx_id; /* rx_id of the target request */ | ||
584 | u16 _resvd0; /* reserved */ | ||
585 | }; | ||
586 | |||
587 | /* | ||
588 | * fcpio_ttmf: firmware -> host request | ||
589 | * | ||
590 | * used by the firmware to notify the host of an incoming task management | ||
591 | * function request | ||
592 | */ | ||
593 | struct fcpio_ttmf { | ||
594 | u8 _resvd0; /* reserved */ | ||
595 | u8 s_id[3]; /* FC vNIC only: Source S_ID */ | ||
596 | u8 lun[LUN_ADDRESS]; /* FC vNIC only: LUN address */ | ||
597 | u8 crn; /* SCSI Command Reference No. */ | ||
598 | u8 _resvd2[3]; /* reserved */ | ||
599 | u32 tmf_type; /* task management request type */ | ||
600 | }; | ||
601 | |||
602 | /* | ||
603 | * Task Management request | ||
604 | */ | ||
605 | #define FCPIO_TTMF_CLR_ACA 0x40 /* Clear ACA condition */ | ||
606 | #define FCPIO_TTMF_LUN_RESET 0x10 /* logical unit reset task mgmt */ | ||
607 | #define FCPIO_TTMF_CLR_TASK_SET 0x04 /* clear task set */ | ||
608 | #define FCPIO_TTMF_ABT_TASK_SET 0x02 /* abort task set */ | ||
609 | #define FCPIO_TTMF_ABT_TASK 0x01 /* abort task */ | ||
610 | |||
611 | /* | ||
612 | * fcpio_tabort_cmpl: firmware -> host response | ||
613 | * | ||
614 | * used by the firmware to respond to a host's tabort request | ||
615 | */ | ||
616 | struct fcpio_tabort_cmpl { | ||
617 | u16 rx_id; /* rx_id of the target request */ | ||
618 | u16 _resvd0; /* reserved */ | ||
619 | }; | ||
620 | |||
621 | /* | ||
622 | * fcpio_ack: firmware -> host response | ||
623 | * | ||
624 | * used by firmware to notify the host of the last work request received | ||
625 | */ | ||
626 | struct fcpio_ack { | ||
627 | u16 request_out; /* last host entry received */ | ||
628 | u16 _resvd; | ||
629 | }; | ||
630 | |||
631 | /* | ||
632 | * fcpio_reset_cmpl: firmware -> host response | ||
633 | * | ||
634 | * use by firmware to respond to the host's reset request | ||
635 | */ | ||
636 | struct fcpio_reset_cmpl { | ||
637 | u16 vnic_id; | ||
638 | }; | ||
639 | |||
640 | /* | ||
641 | * fcpio_flogi_reg_cmpl: firmware -> host response | ||
642 | * | ||
643 | * fc vnic only | ||
644 | * response to the fcpio_flogi_reg request | ||
645 | */ | ||
646 | struct fcpio_flogi_reg_cmpl { | ||
647 | u32 _resvd; | ||
648 | }; | ||
649 | |||
650 | /* | ||
651 | * fcpio_echo_cmpl: firmware -> host response | ||
652 | * | ||
653 | * response to the fcpio_echo request | ||
654 | */ | ||
655 | struct fcpio_echo_cmpl { | ||
656 | u32 _resvd; | ||
657 | }; | ||
658 | |||
659 | /* | ||
660 | * fcpio_lunmap_chng: firmware -> host notification | ||
661 | * | ||
662 | * scsi vnic only | ||
663 | * notifies the host that the lunmap tables have changed | ||
664 | */ | ||
665 | struct fcpio_lunmap_chng { | ||
666 | u32 _resvd; | ||
667 | }; | ||
668 | |||
669 | /* | ||
670 | * fcpio_lunmap_req_cmpl: firmware -> host response | ||
671 | * | ||
672 | * scsi vnic only | ||
673 | * response for lunmap table request from the host | ||
674 | */ | ||
675 | struct fcpio_lunmap_req_cmpl { | ||
676 | u32 _resvd; | ||
677 | }; | ||
678 | |||
679 | /* | ||
680 | * Basic structure for all fcpio structures that are sent from the firmware to | ||
681 | * the host. They are 64 bytes per structure. | ||
682 | */ | ||
683 | #define FCPIO_FW_REQ_LEN 64 /* expected length of fw requests */ | ||
684 | struct fcpio_fw_req { | ||
685 | struct fcpio_header hdr; | ||
686 | |||
687 | union { | ||
688 | /* | ||
689 | * Defines space needed for request | ||
690 | */ | ||
691 | u8 buf[FCPIO_FW_REQ_LEN - sizeof(struct fcpio_header)]; | ||
692 | |||
693 | /* | ||
694 | * Initiator firmware responses | ||
695 | */ | ||
696 | struct fcpio_icmnd_cmpl icmnd_cmpl; | ||
697 | struct fcpio_itmf_cmpl itmf_cmpl; | ||
698 | |||
699 | /* | ||
700 | * Target firmware new requests | ||
701 | */ | ||
702 | struct fcpio_tcmnd_16 tcmnd_16; | ||
703 | struct fcpio_tcmnd_32 tcmnd_32; | ||
704 | |||
705 | /* | ||
706 | * Target firmware responses | ||
707 | */ | ||
708 | struct fcpio_tdrsp_cmpl tdrsp_cmpl; | ||
709 | struct fcpio_ttmf ttmf; | ||
710 | struct fcpio_tabort_cmpl tabort_cmpl; | ||
711 | |||
712 | /* | ||
713 | * Firmware response to work received | ||
714 | */ | ||
715 | struct fcpio_ack ack; | ||
716 | |||
717 | /* | ||
718 | * Misc requests | ||
719 | */ | ||
720 | struct fcpio_reset_cmpl reset_cmpl; | ||
721 | struct fcpio_flogi_reg_cmpl flogi_reg_cmpl; | ||
722 | struct fcpio_echo_cmpl echo_cmpl; | ||
723 | struct fcpio_lunmap_chng lunmap_chng; | ||
724 | struct fcpio_lunmap_req_cmpl lunmap_req_cmpl; | ||
725 | } u; | ||
726 | }; | ||
727 | |||
728 | /* | ||
729 | * Access routines to encode and decode the color bit, which is the most | ||
730 | * significant bit of the MSB of the structure | ||
731 | */ | ||
732 | static inline void fcpio_color_enc(struct fcpio_fw_req *fw_req, u8 color) | ||
733 | { | ||
734 | u8 *c = ((u8 *) fw_req) + sizeof(struct fcpio_fw_req) - 1; | ||
735 | |||
736 | if (color) | ||
737 | *c |= 0x80; | ||
738 | else | ||
739 | *c &= ~0x80; | ||
740 | } | ||
741 | |||
742 | static inline void fcpio_color_dec(struct fcpio_fw_req *fw_req, u8 *color) | ||
743 | { | ||
744 | u8 *c = ((u8 *) fw_req) + sizeof(struct fcpio_fw_req) - 1; | ||
745 | |||
746 | *color = *c >> 7; | ||
747 | |||
748 | /* | ||
749 | * Make sure color bit is read from desc *before* other fields | ||
750 | * are read from desc. Hardware guarantees color bit is last | ||
751 | * bit (byte) written. Adding the rmb() prevents the compiler | ||
752 | * and/or CPU from reordering the reads which would potentially | ||
753 | * result in reading stale values. | ||
754 | */ | ||
755 | |||
756 | rmb(); | ||
757 | |||
758 | } | ||
759 | |||
760 | /* | ||
761 | * Lunmap table entry for scsi vnics | ||
762 | */ | ||
763 | #define FCPIO_LUNMAP_TABLE_SIZE 256 | ||
764 | #define FCPIO_FLAGS_LUNMAP_VALID 0x80 | ||
765 | #define FCPIO_FLAGS_BOOT 0x01 | ||
766 | struct fcpio_lunmap_entry { | ||
767 | u8 bus; | ||
768 | u8 target; | ||
769 | u8 lun; | ||
770 | u8 path_cnt; | ||
771 | u16 flags; | ||
772 | u16 update_cnt; | ||
773 | }; | ||
774 | |||
775 | struct fcpio_lunmap_tbl { | ||
776 | u32 update_cnt; | ||
777 | struct fcpio_lunmap_entry lunmaps[FCPIO_LUNMAP_TABLE_SIZE]; | ||
778 | }; | ||
779 | |||
780 | #endif /* _FCPIO_H_ */ | ||
diff --git a/drivers/scsi/fnic/fnic.h b/drivers/scsi/fnic/fnic.h new file mode 100644 index 000000000000..e4c0a3d7d87b --- /dev/null +++ b/drivers/scsi/fnic/fnic.h | |||
@@ -0,0 +1,265 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _FNIC_H_ | ||
19 | #define _FNIC_H_ | ||
20 | |||
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/netdevice.h> | ||
23 | #include <linux/workqueue.h> | ||
24 | #include <scsi/libfc.h> | ||
25 | #include "fnic_io.h" | ||
26 | #include "fnic_res.h" | ||
27 | #include "vnic_dev.h" | ||
28 | #include "vnic_wq.h" | ||
29 | #include "vnic_rq.h" | ||
30 | #include "vnic_cq.h" | ||
31 | #include "vnic_wq_copy.h" | ||
32 | #include "vnic_intr.h" | ||
33 | #include "vnic_stats.h" | ||
34 | #include "vnic_scsi.h" | ||
35 | |||
36 | #define DRV_NAME "fnic" | ||
37 | #define DRV_DESCRIPTION "Cisco FCoE HBA Driver" | ||
38 | #define DRV_VERSION "1.0.0.1121" | ||
39 | #define PFX DRV_NAME ": " | ||
40 | #define DFX DRV_NAME "%d: " | ||
41 | |||
42 | #define DESC_CLEAN_LOW_WATERMARK 8 | ||
43 | #define FNIC_MAX_IO_REQ 2048 /* scsi_cmnd tag map entries */ | ||
44 | #define FNIC_IO_LOCKS 64 /* IO locks: power of 2 */ | ||
45 | #define FNIC_DFLT_QUEUE_DEPTH 32 | ||
46 | #define FNIC_STATS_RATE_LIMIT 4 /* limit rate at which stats are pulled up */ | ||
47 | |||
48 | /* | ||
49 | * Tag bits used for special requests. | ||
50 | */ | ||
51 | #define BIT(nr) (1UL << (nr)) | ||
52 | #define FNIC_TAG_ABORT BIT(30) /* tag bit indicating abort */ | ||
53 | #define FNIC_TAG_DEV_RST BIT(29) /* indicates device reset */ | ||
54 | #define FNIC_TAG_MASK (BIT(24) - 1) /* mask for lookup */ | ||
55 | #define FNIC_NO_TAG -1 | ||
56 | |||
57 | /* | ||
58 | * Usage of the scsi_cmnd scratchpad. | ||
59 | * These fields are locked by the hashed io_req_lock. | ||
60 | */ | ||
61 | #define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr) | ||
62 | #define CMD_STATE(Cmnd) ((Cmnd)->SCp.phase) | ||
63 | #define CMD_ABTS_STATUS(Cmnd) ((Cmnd)->SCp.Message) | ||
64 | #define CMD_LR_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in) | ||
65 | #define CMD_TAG(Cmnd) ((Cmnd)->SCp.sent_command) | ||
66 | |||
67 | #define FCPIO_INVALID_CODE 0x100 /* hdr_status value unused by firmware */ | ||
68 | |||
69 | #define FNIC_LUN_RESET_TIMEOUT 10000 /* mSec */ | ||
70 | #define FNIC_HOST_RESET_TIMEOUT 10000 /* mSec */ | ||
71 | #define FNIC_RMDEVICE_TIMEOUT 1000 /* mSec */ | ||
72 | #define FNIC_HOST_RESET_SETTLE_TIME 30 /* Sec */ | ||
73 | |||
74 | #define FNIC_MAX_FCP_TARGET 256 | ||
75 | |||
76 | extern unsigned int fnic_log_level; | ||
77 | |||
78 | #define FNIC_MAIN_LOGGING 0x01 | ||
79 | #define FNIC_FCS_LOGGING 0x02 | ||
80 | #define FNIC_SCSI_LOGGING 0x04 | ||
81 | #define FNIC_ISR_LOGGING 0x08 | ||
82 | |||
83 | #define FNIC_CHECK_LOGGING(LEVEL, CMD) \ | ||
84 | do { \ | ||
85 | if (unlikely(fnic_log_level & LEVEL)) \ | ||
86 | do { \ | ||
87 | CMD; \ | ||
88 | } while (0); \ | ||
89 | } while (0) | ||
90 | |||
91 | #define FNIC_MAIN_DBG(kern_level, host, fmt, args...) \ | ||
92 | FNIC_CHECK_LOGGING(FNIC_MAIN_LOGGING, \ | ||
93 | shost_printk(kern_level, host, fmt, ##args);) | ||
94 | |||
95 | #define FNIC_FCS_DBG(kern_level, host, fmt, args...) \ | ||
96 | FNIC_CHECK_LOGGING(FNIC_FCS_LOGGING, \ | ||
97 | shost_printk(kern_level, host, fmt, ##args);) | ||
98 | |||
99 | #define FNIC_SCSI_DBG(kern_level, host, fmt, args...) \ | ||
100 | FNIC_CHECK_LOGGING(FNIC_SCSI_LOGGING, \ | ||
101 | shost_printk(kern_level, host, fmt, ##args);) | ||
102 | |||
103 | #define FNIC_ISR_DBG(kern_level, host, fmt, args...) \ | ||
104 | FNIC_CHECK_LOGGING(FNIC_ISR_LOGGING, \ | ||
105 | shost_printk(kern_level, host, fmt, ##args);) | ||
106 | |||
107 | extern const char *fnic_state_str[]; | ||
108 | |||
109 | enum fnic_intx_intr_index { | ||
110 | FNIC_INTX_WQ_RQ_COPYWQ, | ||
111 | FNIC_INTX_ERR, | ||
112 | FNIC_INTX_NOTIFY, | ||
113 | FNIC_INTX_INTR_MAX, | ||
114 | }; | ||
115 | |||
116 | enum fnic_msix_intr_index { | ||
117 | FNIC_MSIX_RQ, | ||
118 | FNIC_MSIX_WQ, | ||
119 | FNIC_MSIX_WQ_COPY, | ||
120 | FNIC_MSIX_ERR_NOTIFY, | ||
121 | FNIC_MSIX_INTR_MAX, | ||
122 | }; | ||
123 | |||
124 | struct fnic_msix_entry { | ||
125 | int requested; | ||
126 | char devname[IFNAMSIZ]; | ||
127 | irqreturn_t (*isr)(int, void *); | ||
128 | void *devid; | ||
129 | }; | ||
130 | |||
131 | enum fnic_state { | ||
132 | FNIC_IN_FC_MODE = 0, | ||
133 | FNIC_IN_FC_TRANS_ETH_MODE, | ||
134 | FNIC_IN_ETH_MODE, | ||
135 | FNIC_IN_ETH_TRANS_FC_MODE, | ||
136 | }; | ||
137 | |||
138 | #define FNIC_WQ_COPY_MAX 1 | ||
139 | #define FNIC_WQ_MAX 1 | ||
140 | #define FNIC_RQ_MAX 1 | ||
141 | #define FNIC_CQ_MAX (FNIC_WQ_COPY_MAX + FNIC_WQ_MAX + FNIC_RQ_MAX) | ||
142 | |||
143 | struct mempool; | ||
144 | |||
145 | /* Per-instance private data structure */ | ||
146 | struct fnic { | ||
147 | struct fc_lport *lport; | ||
148 | struct vnic_dev_bar bar0; | ||
149 | |||
150 | struct msix_entry msix_entry[FNIC_MSIX_INTR_MAX]; | ||
151 | struct fnic_msix_entry msix[FNIC_MSIX_INTR_MAX]; | ||
152 | |||
153 | struct vnic_stats *stats; | ||
154 | unsigned long stats_time; /* time of stats update */ | ||
155 | struct vnic_nic_cfg *nic_cfg; | ||
156 | char name[IFNAMSIZ]; | ||
157 | struct timer_list notify_timer; /* used for MSI interrupts */ | ||
158 | |||
159 | unsigned int err_intr_offset; | ||
160 | unsigned int link_intr_offset; | ||
161 | |||
162 | unsigned int wq_count; | ||
163 | unsigned int cq_count; | ||
164 | |||
165 | u32 fcoui_mode:1; /* use fcoui address*/ | ||
166 | u32 vlan_hw_insert:1; /* let hw insert the tag */ | ||
167 | u32 in_remove:1; /* fnic device in removal */ | ||
168 | u32 stop_rx_link_events:1; /* stop proc. rx frames, link events */ | ||
169 | |||
170 | struct completion *remove_wait; /* device remove thread blocks */ | ||
171 | |||
172 | struct fc_frame *flogi; | ||
173 | struct fc_frame *flogi_resp; | ||
174 | u16 flogi_oxid; | ||
175 | unsigned long s_id; | ||
176 | enum fnic_state state; | ||
177 | spinlock_t fnic_lock; | ||
178 | |||
179 | u16 vlan_id; /* VLAN tag including priority */ | ||
180 | u8 mac_addr[ETH_ALEN]; | ||
181 | u8 dest_addr[ETH_ALEN]; | ||
182 | u8 data_src_addr[ETH_ALEN]; | ||
183 | u64 fcp_input_bytes; /* internal statistic */ | ||
184 | u64 fcp_output_bytes; /* internal statistic */ | ||
185 | u32 link_down_cnt; | ||
186 | int link_status; | ||
187 | |||
188 | struct list_head list; | ||
189 | struct pci_dev *pdev; | ||
190 | struct vnic_fc_config config; | ||
191 | struct vnic_dev *vdev; | ||
192 | unsigned int raw_wq_count; | ||
193 | unsigned int wq_copy_count; | ||
194 | unsigned int rq_count; | ||
195 | int fw_ack_index[FNIC_WQ_COPY_MAX]; | ||
196 | unsigned short fw_ack_recd[FNIC_WQ_COPY_MAX]; | ||
197 | unsigned short wq_copy_desc_low[FNIC_WQ_COPY_MAX]; | ||
198 | unsigned int intr_count; | ||
199 | u32 __iomem *legacy_pba; | ||
200 | struct fnic_host_tag *tags; | ||
201 | mempool_t *io_req_pool; | ||
202 | mempool_t *io_sgl_pool[FNIC_SGL_NUM_CACHES]; | ||
203 | spinlock_t io_req_lock[FNIC_IO_LOCKS]; /* locks for scsi cmnds */ | ||
204 | |||
205 | struct work_struct link_work; | ||
206 | struct work_struct frame_work; | ||
207 | struct sk_buff_head frame_queue; | ||
208 | |||
209 | /* copy work queue cache line section */ | ||
210 | ____cacheline_aligned struct vnic_wq_copy wq_copy[FNIC_WQ_COPY_MAX]; | ||
211 | /* completion queue cache line section */ | ||
212 | ____cacheline_aligned struct vnic_cq cq[FNIC_CQ_MAX]; | ||
213 | |||
214 | spinlock_t wq_copy_lock[FNIC_WQ_COPY_MAX]; | ||
215 | |||
216 | /* work queue cache line section */ | ||
217 | ____cacheline_aligned struct vnic_wq wq[FNIC_WQ_MAX]; | ||
218 | spinlock_t wq_lock[FNIC_WQ_MAX]; | ||
219 | |||
220 | /* receive queue cache line section */ | ||
221 | ____cacheline_aligned struct vnic_rq rq[FNIC_RQ_MAX]; | ||
222 | |||
223 | /* interrupt resource cache line section */ | ||
224 | ____cacheline_aligned struct vnic_intr intr[FNIC_MSIX_INTR_MAX]; | ||
225 | }; | ||
226 | |||
227 | extern struct workqueue_struct *fnic_event_queue; | ||
228 | extern struct device_attribute *fnic_attrs[]; | ||
229 | |||
230 | void fnic_clear_intr_mode(struct fnic *fnic); | ||
231 | int fnic_set_intr_mode(struct fnic *fnic); | ||
232 | void fnic_free_intr(struct fnic *fnic); | ||
233 | int fnic_request_intr(struct fnic *fnic); | ||
234 | |||
235 | int fnic_send(struct fc_lport *, struct fc_frame *); | ||
236 | void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf); | ||
237 | void fnic_handle_frame(struct work_struct *work); | ||
238 | void fnic_handle_link(struct work_struct *work); | ||
239 | int fnic_rq_cmpl_handler(struct fnic *fnic, int); | ||
240 | int fnic_alloc_rq_frame(struct vnic_rq *rq); | ||
241 | void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf); | ||
242 | int fnic_send_frame(struct fnic *fnic, struct fc_frame *fp); | ||
243 | |||
244 | int fnic_queuecommand(struct scsi_cmnd *, void (*done)(struct scsi_cmnd *)); | ||
245 | int fnic_abort_cmd(struct scsi_cmnd *); | ||
246 | int fnic_device_reset(struct scsi_cmnd *); | ||
247 | int fnic_host_reset(struct scsi_cmnd *); | ||
248 | int fnic_reset(struct Scsi_Host *); | ||
249 | void fnic_scsi_cleanup(struct fc_lport *); | ||
250 | void fnic_scsi_abort_io(struct fc_lport *); | ||
251 | void fnic_empty_scsi_cleanup(struct fc_lport *); | ||
252 | void fnic_exch_mgr_reset(struct fc_lport *, u32, u32); | ||
253 | int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int); | ||
254 | int fnic_wq_cmpl_handler(struct fnic *fnic, int); | ||
255 | int fnic_flogi_reg_handler(struct fnic *fnic); | ||
256 | void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq, | ||
257 | struct fcpio_host_req *desc); | ||
258 | int fnic_fw_reset_handler(struct fnic *fnic); | ||
259 | void fnic_terminate_rport_io(struct fc_rport *); | ||
260 | const char *fnic_state_to_str(unsigned int state); | ||
261 | |||
262 | void fnic_log_q_error(struct fnic *fnic); | ||
263 | void fnic_handle_link_event(struct fnic *fnic); | ||
264 | |||
265 | #endif /* _FNIC_H_ */ | ||
diff --git a/drivers/scsi/fnic/fnic_attrs.c b/drivers/scsi/fnic/fnic_attrs.c new file mode 100644 index 000000000000..aea0c3becfd4 --- /dev/null +++ b/drivers/scsi/fnic/fnic_attrs.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #include <linux/string.h> | ||
19 | #include <linux/device.h> | ||
20 | #include <scsi/scsi_host.h> | ||
21 | #include "fnic.h" | ||
22 | |||
23 | static ssize_t fnic_show_state(struct device *dev, | ||
24 | struct device_attribute *attr, char *buf) | ||
25 | { | ||
26 | struct fc_lport *lp = shost_priv(class_to_shost(dev)); | ||
27 | struct fnic *fnic = lport_priv(lp); | ||
28 | |||
29 | return snprintf(buf, PAGE_SIZE, "%s\n", fnic_state_str[fnic->state]); | ||
30 | } | ||
31 | |||
32 | static ssize_t fnic_show_drv_version(struct device *dev, | ||
33 | struct device_attribute *attr, char *buf) | ||
34 | { | ||
35 | return snprintf(buf, PAGE_SIZE, "%s\n", DRV_VERSION); | ||
36 | } | ||
37 | |||
38 | static ssize_t fnic_show_link_state(struct device *dev, | ||
39 | struct device_attribute *attr, char *buf) | ||
40 | { | ||
41 | struct fc_lport *lp = shost_priv(class_to_shost(dev)); | ||
42 | |||
43 | return snprintf(buf, PAGE_SIZE, "%s\n", (lp->link_up) | ||
44 | ? "Link Up" : "Link Down"); | ||
45 | } | ||
46 | |||
47 | static DEVICE_ATTR(fnic_state, S_IRUGO, fnic_show_state, NULL); | ||
48 | static DEVICE_ATTR(drv_version, S_IRUGO, fnic_show_drv_version, NULL); | ||
49 | static DEVICE_ATTR(link_state, S_IRUGO, fnic_show_link_state, NULL); | ||
50 | |||
51 | struct device_attribute *fnic_attrs[] = { | ||
52 | &dev_attr_fnic_state, | ||
53 | &dev_attr_drv_version, | ||
54 | &dev_attr_link_state, | ||
55 | NULL, | ||
56 | }; | ||
diff --git a/drivers/scsi/fnic/fnic_fcs.c b/drivers/scsi/fnic/fnic_fcs.c new file mode 100644 index 000000000000..07e6eedb83ce --- /dev/null +++ b/drivers/scsi/fnic/fnic_fcs.c | |||
@@ -0,0 +1,742 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #include <linux/errno.h> | ||
19 | #include <linux/pci.h> | ||
20 | #include <linux/skbuff.h> | ||
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/spinlock.h> | ||
23 | #include <linux/if_ether.h> | ||
24 | #include <linux/if_vlan.h> | ||
25 | #include <linux/workqueue.h> | ||
26 | #include <scsi/fc/fc_els.h> | ||
27 | #include <scsi/fc/fc_fcoe.h> | ||
28 | #include <scsi/fc_frame.h> | ||
29 | #include <scsi/libfc.h> | ||
30 | #include "fnic_io.h" | ||
31 | #include "fnic.h" | ||
32 | #include "cq_enet_desc.h" | ||
33 | #include "cq_exch_desc.h" | ||
34 | |||
35 | struct workqueue_struct *fnic_event_queue; | ||
36 | |||
37 | void fnic_handle_link(struct work_struct *work) | ||
38 | { | ||
39 | struct fnic *fnic = container_of(work, struct fnic, link_work); | ||
40 | unsigned long flags; | ||
41 | int old_link_status; | ||
42 | u32 old_link_down_cnt; | ||
43 | |||
44 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
45 | |||
46 | if (fnic->stop_rx_link_events) { | ||
47 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
48 | return; | ||
49 | } | ||
50 | |||
51 | old_link_down_cnt = fnic->link_down_cnt; | ||
52 | old_link_status = fnic->link_status; | ||
53 | fnic->link_status = vnic_dev_link_status(fnic->vdev); | ||
54 | fnic->link_down_cnt = vnic_dev_link_down_cnt(fnic->vdev); | ||
55 | |||
56 | if (old_link_status == fnic->link_status) { | ||
57 | if (!fnic->link_status) | ||
58 | /* DOWN -> DOWN */ | ||
59 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
60 | else { | ||
61 | if (old_link_down_cnt != fnic->link_down_cnt) { | ||
62 | /* UP -> DOWN -> UP */ | ||
63 | fnic->lport->host_stats.link_failure_count++; | ||
64 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
65 | FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, | ||
66 | "link down\n"); | ||
67 | fc_linkdown(fnic->lport); | ||
68 | FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, | ||
69 | "link up\n"); | ||
70 | fc_linkup(fnic->lport); | ||
71 | } else | ||
72 | /* UP -> UP */ | ||
73 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
74 | } | ||
75 | } else if (fnic->link_status) { | ||
76 | /* DOWN -> UP */ | ||
77 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
78 | FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "link up\n"); | ||
79 | fc_linkup(fnic->lport); | ||
80 | } else { | ||
81 | /* UP -> DOWN */ | ||
82 | fnic->lport->host_stats.link_failure_count++; | ||
83 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
84 | FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "link down\n"); | ||
85 | fc_linkdown(fnic->lport); | ||
86 | } | ||
87 | |||
88 | } | ||
89 | |||
90 | /* | ||
91 | * This function passes incoming fabric frames to libFC | ||
92 | */ | ||
93 | void fnic_handle_frame(struct work_struct *work) | ||
94 | { | ||
95 | struct fnic *fnic = container_of(work, struct fnic, frame_work); | ||
96 | struct fc_lport *lp = fnic->lport; | ||
97 | unsigned long flags; | ||
98 | struct sk_buff *skb; | ||
99 | struct fc_frame *fp; | ||
100 | |||
101 | while ((skb = skb_dequeue(&fnic->frame_queue))) { | ||
102 | |||
103 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
104 | if (fnic->stop_rx_link_events) { | ||
105 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
106 | dev_kfree_skb(skb); | ||
107 | return; | ||
108 | } | ||
109 | fp = (struct fc_frame *)skb; | ||
110 | /* if Flogi resp frame, register the address */ | ||
111 | if (fr_flags(fp)) { | ||
112 | vnic_dev_add_addr(fnic->vdev, | ||
113 | fnic->data_src_addr); | ||
114 | fr_flags(fp) = 0; | ||
115 | } | ||
116 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
117 | |||
118 | fc_exch_recv(lp, lp->emp, fp); | ||
119 | } | ||
120 | |||
121 | } | ||
122 | |||
123 | static inline void fnic_import_rq_fc_frame(struct sk_buff *skb, | ||
124 | u32 len, u8 sof, u8 eof) | ||
125 | { | ||
126 | struct fc_frame *fp = (struct fc_frame *)skb; | ||
127 | |||
128 | skb_trim(skb, len); | ||
129 | fr_eof(fp) = eof; | ||
130 | fr_sof(fp) = sof; | ||
131 | } | ||
132 | |||
133 | |||
134 | static inline int fnic_import_rq_eth_pkt(struct sk_buff *skb, u32 len) | ||
135 | { | ||
136 | struct fc_frame *fp; | ||
137 | struct ethhdr *eh; | ||
138 | struct vlan_ethhdr *vh; | ||
139 | struct fcoe_hdr *fcoe_hdr; | ||
140 | struct fcoe_crc_eof *ft; | ||
141 | u32 transport_len = 0; | ||
142 | |||
143 | eh = (struct ethhdr *)skb->data; | ||
144 | vh = (struct vlan_ethhdr *)skb->data; | ||
145 | if (vh->h_vlan_proto == htons(ETH_P_8021Q) && | ||
146 | vh->h_vlan_encapsulated_proto == htons(ETH_P_FCOE)) { | ||
147 | skb_pull(skb, sizeof(struct vlan_ethhdr)); | ||
148 | transport_len += sizeof(struct vlan_ethhdr); | ||
149 | } else if (eh->h_proto == htons(ETH_P_FCOE)) { | ||
150 | transport_len += sizeof(struct ethhdr); | ||
151 | skb_pull(skb, sizeof(struct ethhdr)); | ||
152 | } else | ||
153 | return -1; | ||
154 | |||
155 | fcoe_hdr = (struct fcoe_hdr *)skb->data; | ||
156 | if (FC_FCOE_DECAPS_VER(fcoe_hdr) != FC_FCOE_VER) | ||
157 | return -1; | ||
158 | |||
159 | fp = (struct fc_frame *)skb; | ||
160 | fc_frame_init(fp); | ||
161 | fr_sof(fp) = fcoe_hdr->fcoe_sof; | ||
162 | skb_pull(skb, sizeof(struct fcoe_hdr)); | ||
163 | transport_len += sizeof(struct fcoe_hdr); | ||
164 | |||
165 | ft = (struct fcoe_crc_eof *)(skb->data + len - | ||
166 | transport_len - sizeof(*ft)); | ||
167 | fr_eof(fp) = ft->fcoe_eof; | ||
168 | skb_trim(skb, len - transport_len - sizeof(*ft)); | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | static inline int fnic_handle_flogi_resp(struct fnic *fnic, | ||
173 | struct fc_frame *fp) | ||
174 | { | ||
175 | u8 mac[ETH_ALEN] = FC_FCOE_FLOGI_MAC; | ||
176 | struct ethhdr *eth_hdr; | ||
177 | struct fc_frame_header *fh; | ||
178 | int ret = 0; | ||
179 | unsigned long flags; | ||
180 | struct fc_frame *old_flogi_resp = NULL; | ||
181 | |||
182 | fh = (struct fc_frame_header *)fr_hdr(fp); | ||
183 | |||
184 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
185 | |||
186 | if (fnic->state == FNIC_IN_ETH_MODE) { | ||
187 | |||
188 | /* | ||
189 | * Check if oxid matches on taking the lock. A new Flogi | ||
190 | * issued by libFC might have changed the fnic cached oxid | ||
191 | */ | ||
192 | if (fnic->flogi_oxid != ntohs(fh->fh_ox_id)) { | ||
193 | FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, | ||
194 | "Flogi response oxid not" | ||
195 | " matching cached oxid, dropping frame" | ||
196 | "\n"); | ||
197 | ret = -1; | ||
198 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
199 | dev_kfree_skb_irq(fp_skb(fp)); | ||
200 | goto handle_flogi_resp_end; | ||
201 | } | ||
202 | |||
203 | /* Drop older cached flogi response frame, cache this frame */ | ||
204 | old_flogi_resp = fnic->flogi_resp; | ||
205 | fnic->flogi_resp = fp; | ||
206 | fnic->flogi_oxid = FC_XID_UNKNOWN; | ||
207 | |||
208 | /* | ||
209 | * this frame is part of flogi get the src mac addr from this | ||
210 | * frame if the src mac is fcoui based then we mark the | ||
211 | * address mode flag to use fcoui base for dst mac addr | ||
212 | * otherwise we have to store the fcoe gateway addr | ||
213 | */ | ||
214 | eth_hdr = (struct ethhdr *)skb_mac_header(fp_skb(fp)); | ||
215 | memcpy(mac, eth_hdr->h_source, ETH_ALEN); | ||
216 | |||
217 | if (ntoh24(mac) == FC_FCOE_OUI) | ||
218 | fnic->fcoui_mode = 1; | ||
219 | else { | ||
220 | fnic->fcoui_mode = 0; | ||
221 | memcpy(fnic->dest_addr, mac, ETH_ALEN); | ||
222 | } | ||
223 | |||
224 | /* | ||
225 | * Except for Flogi frame, all outbound frames from us have the | ||
226 | * Eth Src address as FC_FCOE_OUI"our_sid". Flogi frame uses | ||
227 | * the vnic MAC address as the Eth Src address | ||
228 | */ | ||
229 | fc_fcoe_set_mac(fnic->data_src_addr, fh->fh_d_id); | ||
230 | |||
231 | /* We get our s_id from the d_id of the flogi resp frame */ | ||
232 | fnic->s_id = ntoh24(fh->fh_d_id); | ||
233 | |||
234 | /* Change state to reflect transition from Eth to FC mode */ | ||
235 | fnic->state = FNIC_IN_ETH_TRANS_FC_MODE; | ||
236 | |||
237 | } else { | ||
238 | FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, | ||
239 | "Unexpected fnic state %s while" | ||
240 | " processing flogi resp\n", | ||
241 | fnic_state_to_str(fnic->state)); | ||
242 | ret = -1; | ||
243 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
244 | dev_kfree_skb_irq(fp_skb(fp)); | ||
245 | goto handle_flogi_resp_end; | ||
246 | } | ||
247 | |||
248 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
249 | |||
250 | /* Drop older cached frame */ | ||
251 | if (old_flogi_resp) | ||
252 | dev_kfree_skb_irq(fp_skb(old_flogi_resp)); | ||
253 | |||
254 | /* | ||
255 | * send flogi reg request to firmware, this will put the fnic in | ||
256 | * in FC mode | ||
257 | */ | ||
258 | ret = fnic_flogi_reg_handler(fnic); | ||
259 | |||
260 | if (ret < 0) { | ||
261 | int free_fp = 1; | ||
262 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
263 | /* | ||
264 | * free the frame is some other thread is not | ||
265 | * pointing to it | ||
266 | */ | ||
267 | if (fnic->flogi_resp != fp) | ||
268 | free_fp = 0; | ||
269 | else | ||
270 | fnic->flogi_resp = NULL; | ||
271 | |||
272 | if (fnic->state == FNIC_IN_ETH_TRANS_FC_MODE) | ||
273 | fnic->state = FNIC_IN_ETH_MODE; | ||
274 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
275 | if (free_fp) | ||
276 | dev_kfree_skb_irq(fp_skb(fp)); | ||
277 | } | ||
278 | |||
279 | handle_flogi_resp_end: | ||
280 | return ret; | ||
281 | } | ||
282 | |||
283 | /* Returns 1 for a response that matches cached flogi oxid */ | ||
284 | static inline int is_matching_flogi_resp_frame(struct fnic *fnic, | ||
285 | struct fc_frame *fp) | ||
286 | { | ||
287 | struct fc_frame_header *fh; | ||
288 | int ret = 0; | ||
289 | u32 f_ctl; | ||
290 | |||
291 | fh = fc_frame_header_get(fp); | ||
292 | f_ctl = ntoh24(fh->fh_f_ctl); | ||
293 | |||
294 | if (fnic->flogi_oxid == ntohs(fh->fh_ox_id) && | ||
295 | fh->fh_r_ctl == FC_RCTL_ELS_REP && | ||
296 | (f_ctl & (FC_FC_EX_CTX | FC_FC_SEQ_CTX)) == FC_FC_EX_CTX && | ||
297 | fh->fh_type == FC_TYPE_ELS) | ||
298 | ret = 1; | ||
299 | |||
300 | return ret; | ||
301 | } | ||
302 | |||
303 | static void fnic_rq_cmpl_frame_recv(struct vnic_rq *rq, struct cq_desc | ||
304 | *cq_desc, struct vnic_rq_buf *buf, | ||
305 | int skipped __attribute__((unused)), | ||
306 | void *opaque) | ||
307 | { | ||
308 | struct fnic *fnic = vnic_dev_priv(rq->vdev); | ||
309 | struct sk_buff *skb; | ||
310 | struct fc_frame *fp; | ||
311 | unsigned int eth_hdrs_stripped; | ||
312 | u8 type, color, eop, sop, ingress_port, vlan_stripped; | ||
313 | u8 fcoe = 0, fcoe_sof, fcoe_eof; | ||
314 | u8 fcoe_fc_crc_ok = 1, fcoe_enc_error = 0; | ||
315 | u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok; | ||
316 | u8 ipv6, ipv4, ipv4_fragment, rss_type, csum_not_calc; | ||
317 | u8 fcs_ok = 1, packet_error = 0; | ||
318 | u16 q_number, completed_index, bytes_written = 0, vlan, checksum; | ||
319 | u32 rss_hash; | ||
320 | u16 exchange_id, tmpl; | ||
321 | u8 sof = 0; | ||
322 | u8 eof = 0; | ||
323 | u32 fcp_bytes_written = 0; | ||
324 | unsigned long flags; | ||
325 | |||
326 | pci_unmap_single(fnic->pdev, buf->dma_addr, buf->len, | ||
327 | PCI_DMA_FROMDEVICE); | ||
328 | skb = buf->os_buf; | ||
329 | buf->os_buf = NULL; | ||
330 | |||
331 | cq_desc_dec(cq_desc, &type, &color, &q_number, &completed_index); | ||
332 | if (type == CQ_DESC_TYPE_RQ_FCP) { | ||
333 | cq_fcp_rq_desc_dec((struct cq_fcp_rq_desc *)cq_desc, | ||
334 | &type, &color, &q_number, &completed_index, | ||
335 | &eop, &sop, &fcoe_fc_crc_ok, &exchange_id, | ||
336 | &tmpl, &fcp_bytes_written, &sof, &eof, | ||
337 | &ingress_port, &packet_error, | ||
338 | &fcoe_enc_error, &fcs_ok, &vlan_stripped, | ||
339 | &vlan); | ||
340 | eth_hdrs_stripped = 1; | ||
341 | |||
342 | } else if (type == CQ_DESC_TYPE_RQ_ENET) { | ||
343 | cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc, | ||
344 | &type, &color, &q_number, &completed_index, | ||
345 | &ingress_port, &fcoe, &eop, &sop, | ||
346 | &rss_type, &csum_not_calc, &rss_hash, | ||
347 | &bytes_written, &packet_error, | ||
348 | &vlan_stripped, &vlan, &checksum, | ||
349 | &fcoe_sof, &fcoe_fc_crc_ok, | ||
350 | &fcoe_enc_error, &fcoe_eof, | ||
351 | &tcp_udp_csum_ok, &udp, &tcp, | ||
352 | &ipv4_csum_ok, &ipv6, &ipv4, | ||
353 | &ipv4_fragment, &fcs_ok); | ||
354 | eth_hdrs_stripped = 0; | ||
355 | |||
356 | } else { | ||
357 | /* wrong CQ type*/ | ||
358 | shost_printk(KERN_ERR, fnic->lport->host, | ||
359 | "fnic rq_cmpl wrong cq type x%x\n", type); | ||
360 | goto drop; | ||
361 | } | ||
362 | |||
363 | if (!fcs_ok || packet_error || !fcoe_fc_crc_ok || fcoe_enc_error) { | ||
364 | FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, | ||
365 | "fnic rq_cmpl fcoe x%x fcsok x%x" | ||
366 | " pkterr x%x fcoe_fc_crc_ok x%x, fcoe_enc_err" | ||
367 | " x%x\n", | ||
368 | fcoe, fcs_ok, packet_error, | ||
369 | fcoe_fc_crc_ok, fcoe_enc_error); | ||
370 | goto drop; | ||
371 | } | ||
372 | |||
373 | if (eth_hdrs_stripped) | ||
374 | fnic_import_rq_fc_frame(skb, fcp_bytes_written, sof, eof); | ||
375 | else if (fnic_import_rq_eth_pkt(skb, bytes_written)) | ||
376 | goto drop; | ||
377 | |||
378 | fp = (struct fc_frame *)skb; | ||
379 | |||
380 | /* | ||
381 | * If frame is an ELS response that matches the cached FLOGI OX_ID, | ||
382 | * and is accept, issue flogi_reg_request copy wq request to firmware | ||
383 | * to register the S_ID and determine whether FC_OUI mode or GW mode. | ||
384 | */ | ||
385 | if (is_matching_flogi_resp_frame(fnic, fp)) { | ||
386 | if (!eth_hdrs_stripped) { | ||
387 | if (fc_frame_payload_op(fp) == ELS_LS_ACC) { | ||
388 | fnic_handle_flogi_resp(fnic, fp); | ||
389 | return; | ||
390 | } | ||
391 | /* | ||
392 | * Recd. Flogi reject. No point registering | ||
393 | * with fw, but forward to libFC | ||
394 | */ | ||
395 | goto forward; | ||
396 | } | ||
397 | goto drop; | ||
398 | } | ||
399 | if (!eth_hdrs_stripped) | ||
400 | goto drop; | ||
401 | |||
402 | forward: | ||
403 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
404 | if (fnic->stop_rx_link_events) { | ||
405 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
406 | goto drop; | ||
407 | } | ||
408 | /* Use fr_flags to indicate whether succ. flogi resp or not */ | ||
409 | fr_flags(fp) = 0; | ||
410 | fr_dev(fp) = fnic->lport; | ||
411 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
412 | |||
413 | skb_queue_tail(&fnic->frame_queue, skb); | ||
414 | queue_work(fnic_event_queue, &fnic->frame_work); | ||
415 | |||
416 | return; | ||
417 | drop: | ||
418 | dev_kfree_skb_irq(skb); | ||
419 | } | ||
420 | |||
421 | static int fnic_rq_cmpl_handler_cont(struct vnic_dev *vdev, | ||
422 | struct cq_desc *cq_desc, u8 type, | ||
423 | u16 q_number, u16 completed_index, | ||
424 | void *opaque) | ||
425 | { | ||
426 | struct fnic *fnic = vnic_dev_priv(vdev); | ||
427 | |||
428 | vnic_rq_service(&fnic->rq[q_number], cq_desc, completed_index, | ||
429 | VNIC_RQ_RETURN_DESC, fnic_rq_cmpl_frame_recv, | ||
430 | NULL); | ||
431 | return 0; | ||
432 | } | ||
433 | |||
434 | int fnic_rq_cmpl_handler(struct fnic *fnic, int rq_work_to_do) | ||
435 | { | ||
436 | unsigned int tot_rq_work_done = 0, cur_work_done; | ||
437 | unsigned int i; | ||
438 | int err; | ||
439 | |||
440 | for (i = 0; i < fnic->rq_count; i++) { | ||
441 | cur_work_done = vnic_cq_service(&fnic->cq[i], rq_work_to_do, | ||
442 | fnic_rq_cmpl_handler_cont, | ||
443 | NULL); | ||
444 | if (cur_work_done) { | ||
445 | err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame); | ||
446 | if (err) | ||
447 | shost_printk(KERN_ERR, fnic->lport->host, | ||
448 | "fnic_alloc_rq_frame cant alloc" | ||
449 | " frame\n"); | ||
450 | } | ||
451 | tot_rq_work_done += cur_work_done; | ||
452 | } | ||
453 | |||
454 | return tot_rq_work_done; | ||
455 | } | ||
456 | |||
457 | /* | ||
458 | * This function is called once at init time to allocate and fill RQ | ||
459 | * buffers. Subsequently, it is called in the interrupt context after RQ | ||
460 | * buffer processing to replenish the buffers in the RQ | ||
461 | */ | ||
462 | int fnic_alloc_rq_frame(struct vnic_rq *rq) | ||
463 | { | ||
464 | struct fnic *fnic = vnic_dev_priv(rq->vdev); | ||
465 | struct sk_buff *skb; | ||
466 | u16 len; | ||
467 | dma_addr_t pa; | ||
468 | |||
469 | len = FC_FRAME_HEADROOM + FC_MAX_FRAME + FC_FRAME_TAILROOM; | ||
470 | skb = dev_alloc_skb(len); | ||
471 | if (!skb) { | ||
472 | FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, | ||
473 | "Unable to allocate RQ sk_buff\n"); | ||
474 | return -ENOMEM; | ||
475 | } | ||
476 | skb_reset_mac_header(skb); | ||
477 | skb_reset_transport_header(skb); | ||
478 | skb_reset_network_header(skb); | ||
479 | skb_put(skb, len); | ||
480 | pa = pci_map_single(fnic->pdev, skb->data, len, PCI_DMA_FROMDEVICE); | ||
481 | fnic_queue_rq_desc(rq, skb, pa, len); | ||
482 | return 0; | ||
483 | } | ||
484 | |||
485 | void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf) | ||
486 | { | ||
487 | struct fc_frame *fp = buf->os_buf; | ||
488 | struct fnic *fnic = vnic_dev_priv(rq->vdev); | ||
489 | |||
490 | pci_unmap_single(fnic->pdev, buf->dma_addr, buf->len, | ||
491 | PCI_DMA_FROMDEVICE); | ||
492 | |||
493 | dev_kfree_skb(fp_skb(fp)); | ||
494 | buf->os_buf = NULL; | ||
495 | } | ||
496 | |||
497 | static inline int is_flogi_frame(struct fc_frame_header *fh) | ||
498 | { | ||
499 | return fh->fh_r_ctl == FC_RCTL_ELS_REQ && *(u8 *)(fh + 1) == ELS_FLOGI; | ||
500 | } | ||
501 | |||
502 | int fnic_send_frame(struct fnic *fnic, struct fc_frame *fp) | ||
503 | { | ||
504 | struct vnic_wq *wq = &fnic->wq[0]; | ||
505 | struct sk_buff *skb; | ||
506 | dma_addr_t pa; | ||
507 | struct ethhdr *eth_hdr; | ||
508 | struct vlan_ethhdr *vlan_hdr; | ||
509 | struct fcoe_hdr *fcoe_hdr; | ||
510 | struct fc_frame_header *fh; | ||
511 | u32 tot_len, eth_hdr_len; | ||
512 | int ret = 0; | ||
513 | unsigned long flags; | ||
514 | |||
515 | fh = fc_frame_header_get(fp); | ||
516 | skb = fp_skb(fp); | ||
517 | |||
518 | if (!fnic->vlan_hw_insert) { | ||
519 | eth_hdr_len = sizeof(*vlan_hdr) + sizeof(*fcoe_hdr); | ||
520 | vlan_hdr = (struct vlan_ethhdr *)skb_push(skb, eth_hdr_len); | ||
521 | eth_hdr = (struct ethhdr *)vlan_hdr; | ||
522 | vlan_hdr->h_vlan_proto = htons(ETH_P_8021Q); | ||
523 | vlan_hdr->h_vlan_encapsulated_proto = htons(ETH_P_FCOE); | ||
524 | vlan_hdr->h_vlan_TCI = htons(fnic->vlan_id); | ||
525 | fcoe_hdr = (struct fcoe_hdr *)(vlan_hdr + 1); | ||
526 | } else { | ||
527 | eth_hdr_len = sizeof(*eth_hdr) + sizeof(*fcoe_hdr); | ||
528 | eth_hdr = (struct ethhdr *)skb_push(skb, eth_hdr_len); | ||
529 | eth_hdr->h_proto = htons(ETH_P_FCOE); | ||
530 | fcoe_hdr = (struct fcoe_hdr *)(eth_hdr + 1); | ||
531 | } | ||
532 | |||
533 | if (is_flogi_frame(fh)) { | ||
534 | fc_fcoe_set_mac(eth_hdr->h_dest, fh->fh_d_id); | ||
535 | memcpy(eth_hdr->h_source, fnic->mac_addr, ETH_ALEN); | ||
536 | } else { | ||
537 | if (fnic->fcoui_mode) | ||
538 | fc_fcoe_set_mac(eth_hdr->h_dest, fh->fh_d_id); | ||
539 | else | ||
540 | memcpy(eth_hdr->h_dest, fnic->dest_addr, ETH_ALEN); | ||
541 | memcpy(eth_hdr->h_source, fnic->data_src_addr, ETH_ALEN); | ||
542 | } | ||
543 | |||
544 | tot_len = skb->len; | ||
545 | BUG_ON(tot_len % 4); | ||
546 | |||
547 | memset(fcoe_hdr, 0, sizeof(*fcoe_hdr)); | ||
548 | fcoe_hdr->fcoe_sof = fr_sof(fp); | ||
549 | if (FC_FCOE_VER) | ||
550 | FC_FCOE_ENCAPS_VER(fcoe_hdr, FC_FCOE_VER); | ||
551 | |||
552 | pa = pci_map_single(fnic->pdev, eth_hdr, tot_len, PCI_DMA_TODEVICE); | ||
553 | |||
554 | spin_lock_irqsave(&fnic->wq_lock[0], flags); | ||
555 | |||
556 | if (!vnic_wq_desc_avail(wq)) { | ||
557 | pci_unmap_single(fnic->pdev, pa, | ||
558 | tot_len, PCI_DMA_TODEVICE); | ||
559 | ret = -1; | ||
560 | goto fnic_send_frame_end; | ||
561 | } | ||
562 | |||
563 | fnic_queue_wq_desc(wq, skb, pa, tot_len, fr_eof(fp), | ||
564 | fnic->vlan_hw_insert, fnic->vlan_id, 1, 1, 1); | ||
565 | fnic_send_frame_end: | ||
566 | spin_unlock_irqrestore(&fnic->wq_lock[0], flags); | ||
567 | |||
568 | if (ret) | ||
569 | dev_kfree_skb_any(fp_skb(fp)); | ||
570 | |||
571 | return ret; | ||
572 | } | ||
573 | |||
574 | /* | ||
575 | * fnic_send | ||
576 | * Routine to send a raw frame | ||
577 | */ | ||
578 | int fnic_send(struct fc_lport *lp, struct fc_frame *fp) | ||
579 | { | ||
580 | struct fnic *fnic = lport_priv(lp); | ||
581 | struct fc_frame_header *fh; | ||
582 | int ret = 0; | ||
583 | enum fnic_state old_state; | ||
584 | unsigned long flags; | ||
585 | struct fc_frame *old_flogi = NULL; | ||
586 | struct fc_frame *old_flogi_resp = NULL; | ||
587 | |||
588 | if (fnic->in_remove) { | ||
589 | dev_kfree_skb(fp_skb(fp)); | ||
590 | ret = -1; | ||
591 | goto fnic_send_end; | ||
592 | } | ||
593 | |||
594 | fh = fc_frame_header_get(fp); | ||
595 | /* if not an Flogi frame, send it out, this is the common case */ | ||
596 | if (!is_flogi_frame(fh)) | ||
597 | return fnic_send_frame(fnic, fp); | ||
598 | |||
599 | /* Flogi frame, now enter the state machine */ | ||
600 | |||
601 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
602 | again: | ||
603 | /* Get any old cached frames, free them after dropping lock */ | ||
604 | old_flogi = fnic->flogi; | ||
605 | fnic->flogi = NULL; | ||
606 | old_flogi_resp = fnic->flogi_resp; | ||
607 | fnic->flogi_resp = NULL; | ||
608 | |||
609 | fnic->flogi_oxid = FC_XID_UNKNOWN; | ||
610 | |||
611 | old_state = fnic->state; | ||
612 | switch (old_state) { | ||
613 | case FNIC_IN_FC_MODE: | ||
614 | case FNIC_IN_ETH_TRANS_FC_MODE: | ||
615 | default: | ||
616 | fnic->state = FNIC_IN_FC_TRANS_ETH_MODE; | ||
617 | vnic_dev_del_addr(fnic->vdev, fnic->data_src_addr); | ||
618 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
619 | |||
620 | if (old_flogi) { | ||
621 | dev_kfree_skb(fp_skb(old_flogi)); | ||
622 | old_flogi = NULL; | ||
623 | } | ||
624 | if (old_flogi_resp) { | ||
625 | dev_kfree_skb(fp_skb(old_flogi_resp)); | ||
626 | old_flogi_resp = NULL; | ||
627 | } | ||
628 | |||
629 | ret = fnic_fw_reset_handler(fnic); | ||
630 | |||
631 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
632 | if (fnic->state != FNIC_IN_FC_TRANS_ETH_MODE) | ||
633 | goto again; | ||
634 | if (ret) { | ||
635 | fnic->state = old_state; | ||
636 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
637 | dev_kfree_skb(fp_skb(fp)); | ||
638 | goto fnic_send_end; | ||
639 | } | ||
640 | old_flogi = fnic->flogi; | ||
641 | fnic->flogi = fp; | ||
642 | fnic->flogi_oxid = ntohs(fh->fh_ox_id); | ||
643 | old_flogi_resp = fnic->flogi_resp; | ||
644 | fnic->flogi_resp = NULL; | ||
645 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
646 | break; | ||
647 | |||
648 | case FNIC_IN_FC_TRANS_ETH_MODE: | ||
649 | /* | ||
650 | * A reset is pending with the firmware. Store the flogi | ||
651 | * and its oxid. The transition out of this state happens | ||
652 | * only when Firmware completes the reset, either with | ||
653 | * success or failed. If success, transition to | ||
654 | * FNIC_IN_ETH_MODE, if fail, then transition to | ||
655 | * FNIC_IN_FC_MODE | ||
656 | */ | ||
657 | fnic->flogi = fp; | ||
658 | fnic->flogi_oxid = ntohs(fh->fh_ox_id); | ||
659 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
660 | break; | ||
661 | |||
662 | case FNIC_IN_ETH_MODE: | ||
663 | /* | ||
664 | * The fw/hw is already in eth mode. Store the oxid, | ||
665 | * and send the flogi frame out. The transition out of this | ||
666 | * state happens only we receive flogi response from the | ||
667 | * network, and the oxid matches the cached oxid when the | ||
668 | * flogi frame was sent out. If they match, then we issue | ||
669 | * a flogi_reg request and transition to state | ||
670 | * FNIC_IN_ETH_TRANS_FC_MODE | ||
671 | */ | ||
672 | fnic->flogi_oxid = ntohs(fh->fh_ox_id); | ||
673 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
674 | ret = fnic_send_frame(fnic, fp); | ||
675 | break; | ||
676 | } | ||
677 | |||
678 | fnic_send_end: | ||
679 | if (old_flogi) | ||
680 | dev_kfree_skb(fp_skb(old_flogi)); | ||
681 | if (old_flogi_resp) | ||
682 | dev_kfree_skb(fp_skb(old_flogi_resp)); | ||
683 | return ret; | ||
684 | } | ||
685 | |||
686 | static void fnic_wq_complete_frame_send(struct vnic_wq *wq, | ||
687 | struct cq_desc *cq_desc, | ||
688 | struct vnic_wq_buf *buf, void *opaque) | ||
689 | { | ||
690 | struct sk_buff *skb = buf->os_buf; | ||
691 | struct fc_frame *fp = (struct fc_frame *)skb; | ||
692 | struct fnic *fnic = vnic_dev_priv(wq->vdev); | ||
693 | |||
694 | pci_unmap_single(fnic->pdev, buf->dma_addr, | ||
695 | buf->len, PCI_DMA_TODEVICE); | ||
696 | dev_kfree_skb_irq(fp_skb(fp)); | ||
697 | buf->os_buf = NULL; | ||
698 | } | ||
699 | |||
700 | static int fnic_wq_cmpl_handler_cont(struct vnic_dev *vdev, | ||
701 | struct cq_desc *cq_desc, u8 type, | ||
702 | u16 q_number, u16 completed_index, | ||
703 | void *opaque) | ||
704 | { | ||
705 | struct fnic *fnic = vnic_dev_priv(vdev); | ||
706 | unsigned long flags; | ||
707 | |||
708 | spin_lock_irqsave(&fnic->wq_lock[q_number], flags); | ||
709 | vnic_wq_service(&fnic->wq[q_number], cq_desc, completed_index, | ||
710 | fnic_wq_complete_frame_send, NULL); | ||
711 | spin_unlock_irqrestore(&fnic->wq_lock[q_number], flags); | ||
712 | |||
713 | return 0; | ||
714 | } | ||
715 | |||
716 | int fnic_wq_cmpl_handler(struct fnic *fnic, int work_to_do) | ||
717 | { | ||
718 | unsigned int wq_work_done = 0; | ||
719 | unsigned int i; | ||
720 | |||
721 | for (i = 0; i < fnic->raw_wq_count; i++) { | ||
722 | wq_work_done += vnic_cq_service(&fnic->cq[fnic->rq_count+i], | ||
723 | work_to_do, | ||
724 | fnic_wq_cmpl_handler_cont, | ||
725 | NULL); | ||
726 | } | ||
727 | |||
728 | return wq_work_done; | ||
729 | } | ||
730 | |||
731 | |||
732 | void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf) | ||
733 | { | ||
734 | struct fc_frame *fp = buf->os_buf; | ||
735 | struct fnic *fnic = vnic_dev_priv(wq->vdev); | ||
736 | |||
737 | pci_unmap_single(fnic->pdev, buf->dma_addr, | ||
738 | buf->len, PCI_DMA_TODEVICE); | ||
739 | |||
740 | dev_kfree_skb(fp_skb(fp)); | ||
741 | buf->os_buf = NULL; | ||
742 | } | ||
diff --git a/drivers/scsi/fnic/fnic_io.h b/drivers/scsi/fnic/fnic_io.h new file mode 100644 index 000000000000..f0b896988cd5 --- /dev/null +++ b/drivers/scsi/fnic/fnic_io.h | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _FNIC_IO_H_ | ||
19 | #define _FNIC_IO_H_ | ||
20 | |||
21 | #include <scsi/fc/fc_fcp.h> | ||
22 | |||
23 | #define FNIC_DFLT_SG_DESC_CNT 32 | ||
24 | #define FNIC_MAX_SG_DESC_CNT 1024 /* Maximum descriptors per sgl */ | ||
25 | #define FNIC_SG_DESC_ALIGN 16 /* Descriptor address alignment */ | ||
26 | |||
27 | struct host_sg_desc { | ||
28 | __le64 addr; | ||
29 | __le32 len; | ||
30 | u32 _resvd; | ||
31 | }; | ||
32 | |||
33 | struct fnic_dflt_sgl_list { | ||
34 | struct host_sg_desc sg_desc[FNIC_DFLT_SG_DESC_CNT]; | ||
35 | }; | ||
36 | |||
37 | struct fnic_sgl_list { | ||
38 | struct host_sg_desc sg_desc[FNIC_MAX_SG_DESC_CNT]; | ||
39 | }; | ||
40 | |||
41 | enum fnic_sgl_list_type { | ||
42 | FNIC_SGL_CACHE_DFLT = 0, /* cache with default size sgl */ | ||
43 | FNIC_SGL_CACHE_MAX, /* cache with max size sgl */ | ||
44 | FNIC_SGL_NUM_CACHES /* number of sgl caches */ | ||
45 | }; | ||
46 | |||
47 | enum fnic_ioreq_state { | ||
48 | FNIC_IOREQ_CMD_PENDING = 0, | ||
49 | FNIC_IOREQ_ABTS_PENDING, | ||
50 | FNIC_IOREQ_ABTS_COMPLETE, | ||
51 | FNIC_IOREQ_CMD_COMPLETE, | ||
52 | }; | ||
53 | |||
54 | struct fnic_io_req { | ||
55 | struct host_sg_desc *sgl_list; /* sgl list */ | ||
56 | void *sgl_list_alloc; /* sgl list address used for free */ | ||
57 | dma_addr_t sense_buf_pa; /* dma address for sense buffer*/ | ||
58 | dma_addr_t sgl_list_pa; /* dma address for sgl list */ | ||
59 | u16 sgl_cnt; | ||
60 | u8 sgl_type; /* device DMA descriptor list type */ | ||
61 | u8 io_completed:1; /* set to 1 when fw completes IO */ | ||
62 | u32 port_id; /* remote port DID */ | ||
63 | struct completion *abts_done; /* completion for abts */ | ||
64 | struct completion *dr_done; /* completion for device reset */ | ||
65 | }; | ||
66 | |||
67 | #endif /* _FNIC_IO_H_ */ | ||
diff --git a/drivers/scsi/fnic/fnic_isr.c b/drivers/scsi/fnic/fnic_isr.c new file mode 100644 index 000000000000..2b3064828aea --- /dev/null +++ b/drivers/scsi/fnic/fnic_isr.c | |||
@@ -0,0 +1,332 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #include <linux/string.h> | ||
19 | #include <linux/errno.h> | ||
20 | #include <linux/pci.h> | ||
21 | #include <linux/interrupt.h> | ||
22 | #include <scsi/libfc.h> | ||
23 | #include <scsi/fc_frame.h> | ||
24 | #include "vnic_dev.h" | ||
25 | #include "vnic_intr.h" | ||
26 | #include "vnic_stats.h" | ||
27 | #include "fnic_io.h" | ||
28 | #include "fnic.h" | ||
29 | |||
30 | static irqreturn_t fnic_isr_legacy(int irq, void *data) | ||
31 | { | ||
32 | struct fnic *fnic = data; | ||
33 | u32 pba; | ||
34 | unsigned long work_done = 0; | ||
35 | |||
36 | pba = vnic_intr_legacy_pba(fnic->legacy_pba); | ||
37 | if (!pba) | ||
38 | return IRQ_NONE; | ||
39 | |||
40 | if (pba & (1 << FNIC_INTX_NOTIFY)) { | ||
41 | vnic_intr_return_all_credits(&fnic->intr[FNIC_INTX_NOTIFY]); | ||
42 | fnic_handle_link_event(fnic); | ||
43 | } | ||
44 | |||
45 | if (pba & (1 << FNIC_INTX_ERR)) { | ||
46 | vnic_intr_return_all_credits(&fnic->intr[FNIC_INTX_ERR]); | ||
47 | fnic_log_q_error(fnic); | ||
48 | } | ||
49 | |||
50 | if (pba & (1 << FNIC_INTX_WQ_RQ_COPYWQ)) { | ||
51 | work_done += fnic_wq_copy_cmpl_handler(fnic, 8); | ||
52 | work_done += fnic_wq_cmpl_handler(fnic, 4); | ||
53 | work_done += fnic_rq_cmpl_handler(fnic, 4); | ||
54 | |||
55 | vnic_intr_return_credits(&fnic->intr[FNIC_INTX_WQ_RQ_COPYWQ], | ||
56 | work_done, | ||
57 | 1 /* unmask intr */, | ||
58 | 1 /* reset intr timer */); | ||
59 | } | ||
60 | |||
61 | return IRQ_HANDLED; | ||
62 | } | ||
63 | |||
64 | static irqreturn_t fnic_isr_msi(int irq, void *data) | ||
65 | { | ||
66 | struct fnic *fnic = data; | ||
67 | unsigned long work_done = 0; | ||
68 | |||
69 | work_done += fnic_wq_copy_cmpl_handler(fnic, 8); | ||
70 | work_done += fnic_wq_cmpl_handler(fnic, 4); | ||
71 | work_done += fnic_rq_cmpl_handler(fnic, 4); | ||
72 | |||
73 | vnic_intr_return_credits(&fnic->intr[0], | ||
74 | work_done, | ||
75 | 1 /* unmask intr */, | ||
76 | 1 /* reset intr timer */); | ||
77 | |||
78 | return IRQ_HANDLED; | ||
79 | } | ||
80 | |||
81 | static irqreturn_t fnic_isr_msix_rq(int irq, void *data) | ||
82 | { | ||
83 | struct fnic *fnic = data; | ||
84 | unsigned long rq_work_done = 0; | ||
85 | |||
86 | rq_work_done = fnic_rq_cmpl_handler(fnic, 4); | ||
87 | vnic_intr_return_credits(&fnic->intr[FNIC_MSIX_RQ], | ||
88 | rq_work_done, | ||
89 | 1 /* unmask intr */, | ||
90 | 1 /* reset intr timer */); | ||
91 | |||
92 | return IRQ_HANDLED; | ||
93 | } | ||
94 | |||
95 | static irqreturn_t fnic_isr_msix_wq(int irq, void *data) | ||
96 | { | ||
97 | struct fnic *fnic = data; | ||
98 | unsigned long wq_work_done = 0; | ||
99 | |||
100 | wq_work_done = fnic_wq_cmpl_handler(fnic, 4); | ||
101 | vnic_intr_return_credits(&fnic->intr[FNIC_MSIX_WQ], | ||
102 | wq_work_done, | ||
103 | 1 /* unmask intr */, | ||
104 | 1 /* reset intr timer */); | ||
105 | return IRQ_HANDLED; | ||
106 | } | ||
107 | |||
108 | static irqreturn_t fnic_isr_msix_wq_copy(int irq, void *data) | ||
109 | { | ||
110 | struct fnic *fnic = data; | ||
111 | unsigned long wq_copy_work_done = 0; | ||
112 | |||
113 | wq_copy_work_done = fnic_wq_copy_cmpl_handler(fnic, 8); | ||
114 | vnic_intr_return_credits(&fnic->intr[FNIC_MSIX_WQ_COPY], | ||
115 | wq_copy_work_done, | ||
116 | 1 /* unmask intr */, | ||
117 | 1 /* reset intr timer */); | ||
118 | return IRQ_HANDLED; | ||
119 | } | ||
120 | |||
121 | static irqreturn_t fnic_isr_msix_err_notify(int irq, void *data) | ||
122 | { | ||
123 | struct fnic *fnic = data; | ||
124 | |||
125 | vnic_intr_return_all_credits(&fnic->intr[FNIC_MSIX_ERR_NOTIFY]); | ||
126 | fnic_log_q_error(fnic); | ||
127 | fnic_handle_link_event(fnic); | ||
128 | |||
129 | return IRQ_HANDLED; | ||
130 | } | ||
131 | |||
132 | void fnic_free_intr(struct fnic *fnic) | ||
133 | { | ||
134 | int i; | ||
135 | |||
136 | switch (vnic_dev_get_intr_mode(fnic->vdev)) { | ||
137 | case VNIC_DEV_INTR_MODE_INTX: | ||
138 | case VNIC_DEV_INTR_MODE_MSI: | ||
139 | free_irq(fnic->pdev->irq, fnic); | ||
140 | break; | ||
141 | |||
142 | case VNIC_DEV_INTR_MODE_MSIX: | ||
143 | for (i = 0; i < ARRAY_SIZE(fnic->msix); i++) | ||
144 | if (fnic->msix[i].requested) | ||
145 | free_irq(fnic->msix_entry[i].vector, | ||
146 | fnic->msix[i].devid); | ||
147 | break; | ||
148 | |||
149 | default: | ||
150 | break; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | int fnic_request_intr(struct fnic *fnic) | ||
155 | { | ||
156 | int err = 0; | ||
157 | int i; | ||
158 | |||
159 | switch (vnic_dev_get_intr_mode(fnic->vdev)) { | ||
160 | |||
161 | case VNIC_DEV_INTR_MODE_INTX: | ||
162 | err = request_irq(fnic->pdev->irq, &fnic_isr_legacy, | ||
163 | IRQF_SHARED, DRV_NAME, fnic); | ||
164 | break; | ||
165 | |||
166 | case VNIC_DEV_INTR_MODE_MSI: | ||
167 | err = request_irq(fnic->pdev->irq, &fnic_isr_msi, | ||
168 | 0, fnic->name, fnic); | ||
169 | break; | ||
170 | |||
171 | case VNIC_DEV_INTR_MODE_MSIX: | ||
172 | |||
173 | sprintf(fnic->msix[FNIC_MSIX_RQ].devname, | ||
174 | "%.11s-fcs-rq", fnic->name); | ||
175 | fnic->msix[FNIC_MSIX_RQ].isr = fnic_isr_msix_rq; | ||
176 | fnic->msix[FNIC_MSIX_RQ].devid = fnic; | ||
177 | |||
178 | sprintf(fnic->msix[FNIC_MSIX_WQ].devname, | ||
179 | "%.11s-fcs-wq", fnic->name); | ||
180 | fnic->msix[FNIC_MSIX_WQ].isr = fnic_isr_msix_wq; | ||
181 | fnic->msix[FNIC_MSIX_WQ].devid = fnic; | ||
182 | |||
183 | sprintf(fnic->msix[FNIC_MSIX_WQ_COPY].devname, | ||
184 | "%.11s-scsi-wq", fnic->name); | ||
185 | fnic->msix[FNIC_MSIX_WQ_COPY].isr = fnic_isr_msix_wq_copy; | ||
186 | fnic->msix[FNIC_MSIX_WQ_COPY].devid = fnic; | ||
187 | |||
188 | sprintf(fnic->msix[FNIC_MSIX_ERR_NOTIFY].devname, | ||
189 | "%.11s-err-notify", fnic->name); | ||
190 | fnic->msix[FNIC_MSIX_ERR_NOTIFY].isr = | ||
191 | fnic_isr_msix_err_notify; | ||
192 | fnic->msix[FNIC_MSIX_ERR_NOTIFY].devid = fnic; | ||
193 | |||
194 | for (i = 0; i < ARRAY_SIZE(fnic->msix); i++) { | ||
195 | err = request_irq(fnic->msix_entry[i].vector, | ||
196 | fnic->msix[i].isr, 0, | ||
197 | fnic->msix[i].devname, | ||
198 | fnic->msix[i].devid); | ||
199 | if (err) { | ||
200 | shost_printk(KERN_ERR, fnic->lport->host, | ||
201 | "MSIX: request_irq" | ||
202 | " failed %d\n", err); | ||
203 | fnic_free_intr(fnic); | ||
204 | break; | ||
205 | } | ||
206 | fnic->msix[i].requested = 1; | ||
207 | } | ||
208 | break; | ||
209 | |||
210 | default: | ||
211 | break; | ||
212 | } | ||
213 | |||
214 | return err; | ||
215 | } | ||
216 | |||
217 | int fnic_set_intr_mode(struct fnic *fnic) | ||
218 | { | ||
219 | unsigned int n = ARRAY_SIZE(fnic->rq); | ||
220 | unsigned int m = ARRAY_SIZE(fnic->wq); | ||
221 | unsigned int o = ARRAY_SIZE(fnic->wq_copy); | ||
222 | unsigned int i; | ||
223 | |||
224 | /* | ||
225 | * Set interrupt mode (INTx, MSI, MSI-X) depending | ||
226 | * system capabilities. | ||
227 | * | ||
228 | * Try MSI-X first | ||
229 | * | ||
230 | * We need n RQs, m WQs, o Copy WQs, n+m+o CQs, and n+m+o+1 INTRs | ||
231 | * (last INTR is used for WQ/RQ errors and notification area) | ||
232 | */ | ||
233 | |||
234 | BUG_ON(ARRAY_SIZE(fnic->msix_entry) < n + m + o + 1); | ||
235 | for (i = 0; i < n + m + o + 1; i++) | ||
236 | fnic->msix_entry[i].entry = i; | ||
237 | |||
238 | if (fnic->rq_count >= n && | ||
239 | fnic->raw_wq_count >= m && | ||
240 | fnic->wq_copy_count >= o && | ||
241 | fnic->cq_count >= n + m + o) { | ||
242 | if (!pci_enable_msix(fnic->pdev, fnic->msix_entry, | ||
243 | n + m + o + 1)) { | ||
244 | fnic->rq_count = n; | ||
245 | fnic->raw_wq_count = m; | ||
246 | fnic->wq_copy_count = o; | ||
247 | fnic->wq_count = m + o; | ||
248 | fnic->cq_count = n + m + o; | ||
249 | fnic->intr_count = n + m + o + 1; | ||
250 | fnic->err_intr_offset = FNIC_MSIX_ERR_NOTIFY; | ||
251 | |||
252 | FNIC_ISR_DBG(KERN_DEBUG, fnic->lport->host, | ||
253 | "Using MSI-X Interrupts\n"); | ||
254 | vnic_dev_set_intr_mode(fnic->vdev, | ||
255 | VNIC_DEV_INTR_MODE_MSIX); | ||
256 | return 0; | ||
257 | } | ||
258 | } | ||
259 | |||
260 | /* | ||
261 | * Next try MSI | ||
262 | * We need 1 RQ, 1 WQ, 1 WQ_COPY, 3 CQs, and 1 INTR | ||
263 | */ | ||
264 | if (fnic->rq_count >= 1 && | ||
265 | fnic->raw_wq_count >= 1 && | ||
266 | fnic->wq_copy_count >= 1 && | ||
267 | fnic->cq_count >= 3 && | ||
268 | fnic->intr_count >= 1 && | ||
269 | !pci_enable_msi(fnic->pdev)) { | ||
270 | |||
271 | fnic->rq_count = 1; | ||
272 | fnic->raw_wq_count = 1; | ||
273 | fnic->wq_copy_count = 1; | ||
274 | fnic->wq_count = 2; | ||
275 | fnic->cq_count = 3; | ||
276 | fnic->intr_count = 1; | ||
277 | fnic->err_intr_offset = 0; | ||
278 | |||
279 | FNIC_ISR_DBG(KERN_DEBUG, fnic->lport->host, | ||
280 | "Using MSI Interrupts\n"); | ||
281 | vnic_dev_set_intr_mode(fnic->vdev, VNIC_DEV_INTR_MODE_MSI); | ||
282 | |||
283 | return 0; | ||
284 | } | ||
285 | |||
286 | /* | ||
287 | * Next try INTx | ||
288 | * We need 1 RQ, 1 WQ, 1 WQ_COPY, 3 CQs, and 3 INTRs | ||
289 | * 1 INTR is used for all 3 queues, 1 INTR for queue errors | ||
290 | * 1 INTR for notification area | ||
291 | */ | ||
292 | |||
293 | if (fnic->rq_count >= 1 && | ||
294 | fnic->raw_wq_count >= 1 && | ||
295 | fnic->wq_copy_count >= 1 && | ||
296 | fnic->cq_count >= 3 && | ||
297 | fnic->intr_count >= 3) { | ||
298 | |||
299 | fnic->rq_count = 1; | ||
300 | fnic->raw_wq_count = 1; | ||
301 | fnic->wq_copy_count = 1; | ||
302 | fnic->cq_count = 3; | ||
303 | fnic->intr_count = 3; | ||
304 | |||
305 | FNIC_ISR_DBG(KERN_DEBUG, fnic->lport->host, | ||
306 | "Using Legacy Interrupts\n"); | ||
307 | vnic_dev_set_intr_mode(fnic->vdev, VNIC_DEV_INTR_MODE_INTX); | ||
308 | |||
309 | return 0; | ||
310 | } | ||
311 | |||
312 | vnic_dev_set_intr_mode(fnic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN); | ||
313 | |||
314 | return -EINVAL; | ||
315 | } | ||
316 | |||
317 | void fnic_clear_intr_mode(struct fnic *fnic) | ||
318 | { | ||
319 | switch (vnic_dev_get_intr_mode(fnic->vdev)) { | ||
320 | case VNIC_DEV_INTR_MODE_MSIX: | ||
321 | pci_disable_msix(fnic->pdev); | ||
322 | break; | ||
323 | case VNIC_DEV_INTR_MODE_MSI: | ||
324 | pci_disable_msi(fnic->pdev); | ||
325 | break; | ||
326 | default: | ||
327 | break; | ||
328 | } | ||
329 | |||
330 | vnic_dev_set_intr_mode(fnic->vdev, VNIC_DEV_INTR_MODE_INTX); | ||
331 | } | ||
332 | |||
diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c new file mode 100644 index 000000000000..32ef6b87d895 --- /dev/null +++ b/drivers/scsi/fnic/fnic_main.c | |||
@@ -0,0 +1,942 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/mempool.h> | ||
20 | #include <linux/string.h> | ||
21 | #include <linux/errno.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/pci.h> | ||
24 | #include <linux/skbuff.h> | ||
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/spinlock.h> | ||
27 | #include <linux/workqueue.h> | ||
28 | #include <scsi/scsi_host.h> | ||
29 | #include <scsi/scsi_transport.h> | ||
30 | #include <scsi/scsi_transport_fc.h> | ||
31 | #include <scsi/scsi_tcq.h> | ||
32 | #include <scsi/libfc.h> | ||
33 | #include <scsi/fc_frame.h> | ||
34 | |||
35 | #include "vnic_dev.h" | ||
36 | #include "vnic_intr.h" | ||
37 | #include "vnic_stats.h" | ||
38 | #include "fnic_io.h" | ||
39 | #include "fnic.h" | ||
40 | |||
41 | #define PCI_DEVICE_ID_CISCO_FNIC 0x0045 | ||
42 | |||
43 | /* Timer to poll notification area for events. Used for MSI interrupts */ | ||
44 | #define FNIC_NOTIFY_TIMER_PERIOD (2 * HZ) | ||
45 | |||
46 | static struct kmem_cache *fnic_sgl_cache[FNIC_SGL_NUM_CACHES]; | ||
47 | static struct kmem_cache *fnic_io_req_cache; | ||
48 | LIST_HEAD(fnic_list); | ||
49 | DEFINE_SPINLOCK(fnic_list_lock); | ||
50 | |||
51 | /* Supported devices by fnic module */ | ||
52 | static struct pci_device_id fnic_id_table[] = { | ||
53 | { PCI_DEVICE(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_FNIC) }, | ||
54 | { 0, } | ||
55 | }; | ||
56 | |||
57 | MODULE_DESCRIPTION(DRV_DESCRIPTION); | ||
58 | MODULE_AUTHOR("Abhijeet Joglekar <abjoglek@cisco.com>, " | ||
59 | "Joseph R. Eykholt <jeykholt@cisco.com>"); | ||
60 | MODULE_LICENSE("GPL v2"); | ||
61 | MODULE_VERSION(DRV_VERSION); | ||
62 | MODULE_DEVICE_TABLE(pci, fnic_id_table); | ||
63 | |||
64 | unsigned int fnic_log_level; | ||
65 | module_param(fnic_log_level, int, S_IRUGO|S_IWUSR); | ||
66 | MODULE_PARM_DESC(fnic_log_level, "bit mask of fnic logging levels"); | ||
67 | |||
68 | |||
69 | static struct libfc_function_template fnic_transport_template = { | ||
70 | .frame_send = fnic_send, | ||
71 | .fcp_abort_io = fnic_empty_scsi_cleanup, | ||
72 | .fcp_cleanup = fnic_empty_scsi_cleanup, | ||
73 | .exch_mgr_reset = fnic_exch_mgr_reset | ||
74 | }; | ||
75 | |||
76 | static int fnic_slave_alloc(struct scsi_device *sdev) | ||
77 | { | ||
78 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); | ||
79 | struct fc_lport *lp = shost_priv(sdev->host); | ||
80 | struct fnic *fnic = lport_priv(lp); | ||
81 | |||
82 | sdev->tagged_supported = 1; | ||
83 | |||
84 | if (!rport || fc_remote_port_chkready(rport)) | ||
85 | return -ENXIO; | ||
86 | |||
87 | scsi_activate_tcq(sdev, FNIC_DFLT_QUEUE_DEPTH); | ||
88 | rport->dev_loss_tmo = fnic->config.port_down_timeout / 1000; | ||
89 | |||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | static struct scsi_host_template fnic_host_template = { | ||
94 | .module = THIS_MODULE, | ||
95 | .name = DRV_NAME, | ||
96 | .queuecommand = fnic_queuecommand, | ||
97 | .eh_abort_handler = fnic_abort_cmd, | ||
98 | .eh_device_reset_handler = fnic_device_reset, | ||
99 | .eh_host_reset_handler = fnic_host_reset, | ||
100 | .slave_alloc = fnic_slave_alloc, | ||
101 | .change_queue_depth = fc_change_queue_depth, | ||
102 | .change_queue_type = fc_change_queue_type, | ||
103 | .this_id = -1, | ||
104 | .cmd_per_lun = 3, | ||
105 | .can_queue = FNIC_MAX_IO_REQ, | ||
106 | .use_clustering = ENABLE_CLUSTERING, | ||
107 | .sg_tablesize = FNIC_MAX_SG_DESC_CNT, | ||
108 | .max_sectors = 0xffff, | ||
109 | .shost_attrs = fnic_attrs, | ||
110 | }; | ||
111 | |||
112 | static void fnic_get_host_speed(struct Scsi_Host *shost); | ||
113 | static struct scsi_transport_template *fnic_fc_transport; | ||
114 | static struct fc_host_statistics *fnic_get_stats(struct Scsi_Host *); | ||
115 | |||
116 | static struct fc_function_template fnic_fc_functions = { | ||
117 | |||
118 | .show_host_node_name = 1, | ||
119 | .show_host_port_name = 1, | ||
120 | .show_host_supported_classes = 1, | ||
121 | .show_host_supported_fc4s = 1, | ||
122 | .show_host_active_fc4s = 1, | ||
123 | .show_host_maxframe_size = 1, | ||
124 | .show_host_port_id = 1, | ||
125 | .show_host_supported_speeds = 1, | ||
126 | .get_host_speed = fnic_get_host_speed, | ||
127 | .show_host_speed = 1, | ||
128 | .show_host_port_type = 1, | ||
129 | .get_host_port_state = fc_get_host_port_state, | ||
130 | .show_host_port_state = 1, | ||
131 | .show_host_symbolic_name = 1, | ||
132 | .show_rport_maxframe_size = 1, | ||
133 | .show_rport_supported_classes = 1, | ||
134 | .show_host_fabric_name = 1, | ||
135 | .show_starget_node_name = 1, | ||
136 | .show_starget_port_name = 1, | ||
137 | .show_starget_port_id = 1, | ||
138 | .show_rport_dev_loss_tmo = 1, | ||
139 | .issue_fc_host_lip = fnic_reset, | ||
140 | .get_fc_host_stats = fnic_get_stats, | ||
141 | .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv), | ||
142 | .terminate_rport_io = fnic_terminate_rport_io, | ||
143 | }; | ||
144 | |||
145 | static void fnic_get_host_speed(struct Scsi_Host *shost) | ||
146 | { | ||
147 | struct fc_lport *lp = shost_priv(shost); | ||
148 | struct fnic *fnic = lport_priv(lp); | ||
149 | u32 port_speed = vnic_dev_port_speed(fnic->vdev); | ||
150 | |||
151 | /* Add in other values as they get defined in fw */ | ||
152 | switch (port_speed) { | ||
153 | case 10000: | ||
154 | fc_host_speed(shost) = FC_PORTSPEED_10GBIT; | ||
155 | break; | ||
156 | default: | ||
157 | fc_host_speed(shost) = FC_PORTSPEED_10GBIT; | ||
158 | break; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | static struct fc_host_statistics *fnic_get_stats(struct Scsi_Host *host) | ||
163 | { | ||
164 | int ret; | ||
165 | struct fc_lport *lp = shost_priv(host); | ||
166 | struct fnic *fnic = lport_priv(lp); | ||
167 | struct fc_host_statistics *stats = &lp->host_stats; | ||
168 | struct vnic_stats *vs; | ||
169 | unsigned long flags; | ||
170 | |||
171 | if (time_before(jiffies, fnic->stats_time + HZ / FNIC_STATS_RATE_LIMIT)) | ||
172 | return stats; | ||
173 | fnic->stats_time = jiffies; | ||
174 | |||
175 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
176 | ret = vnic_dev_stats_dump(fnic->vdev, &fnic->stats); | ||
177 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
178 | |||
179 | if (ret) { | ||
180 | FNIC_MAIN_DBG(KERN_DEBUG, fnic->lport->host, | ||
181 | "fnic: Get vnic stats failed" | ||
182 | " 0x%x", ret); | ||
183 | return stats; | ||
184 | } | ||
185 | vs = fnic->stats; | ||
186 | stats->tx_frames = vs->tx.tx_unicast_frames_ok; | ||
187 | stats->tx_words = vs->tx.tx_unicast_bytes_ok / 4; | ||
188 | stats->rx_frames = vs->rx.rx_unicast_frames_ok; | ||
189 | stats->rx_words = vs->rx.rx_unicast_bytes_ok / 4; | ||
190 | stats->error_frames = vs->tx.tx_errors + vs->rx.rx_errors; | ||
191 | stats->dumped_frames = vs->tx.tx_drops + vs->rx.rx_drop; | ||
192 | stats->invalid_crc_count = vs->rx.rx_crc_errors; | ||
193 | stats->seconds_since_last_reset = (jiffies - lp->boot_time) / HZ; | ||
194 | stats->fcp_input_megabytes = div_u64(fnic->fcp_input_bytes, 1000000); | ||
195 | stats->fcp_output_megabytes = div_u64(fnic->fcp_output_bytes, 1000000); | ||
196 | |||
197 | return stats; | ||
198 | } | ||
199 | |||
200 | void fnic_log_q_error(struct fnic *fnic) | ||
201 | { | ||
202 | unsigned int i; | ||
203 | u32 error_status; | ||
204 | |||
205 | for (i = 0; i < fnic->raw_wq_count; i++) { | ||
206 | error_status = ioread32(&fnic->wq[i].ctrl->error_status); | ||
207 | if (error_status) | ||
208 | shost_printk(KERN_ERR, fnic->lport->host, | ||
209 | "WQ[%d] error_status" | ||
210 | " %d\n", i, error_status); | ||
211 | } | ||
212 | |||
213 | for (i = 0; i < fnic->rq_count; i++) { | ||
214 | error_status = ioread32(&fnic->rq[i].ctrl->error_status); | ||
215 | if (error_status) | ||
216 | shost_printk(KERN_ERR, fnic->lport->host, | ||
217 | "RQ[%d] error_status" | ||
218 | " %d\n", i, error_status); | ||
219 | } | ||
220 | |||
221 | for (i = 0; i < fnic->wq_copy_count; i++) { | ||
222 | error_status = ioread32(&fnic->wq_copy[i].ctrl->error_status); | ||
223 | if (error_status) | ||
224 | shost_printk(KERN_ERR, fnic->lport->host, | ||
225 | "CWQ[%d] error_status" | ||
226 | " %d\n", i, error_status); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | void fnic_handle_link_event(struct fnic *fnic) | ||
231 | { | ||
232 | unsigned long flags; | ||
233 | |||
234 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
235 | if (fnic->stop_rx_link_events) { | ||
236 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
237 | return; | ||
238 | } | ||
239 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
240 | |||
241 | queue_work(fnic_event_queue, &fnic->link_work); | ||
242 | |||
243 | } | ||
244 | |||
245 | static int fnic_notify_set(struct fnic *fnic) | ||
246 | { | ||
247 | int err; | ||
248 | |||
249 | switch (vnic_dev_get_intr_mode(fnic->vdev)) { | ||
250 | case VNIC_DEV_INTR_MODE_INTX: | ||
251 | err = vnic_dev_notify_set(fnic->vdev, FNIC_INTX_NOTIFY); | ||
252 | break; | ||
253 | case VNIC_DEV_INTR_MODE_MSI: | ||
254 | err = vnic_dev_notify_set(fnic->vdev, -1); | ||
255 | break; | ||
256 | case VNIC_DEV_INTR_MODE_MSIX: | ||
257 | err = vnic_dev_notify_set(fnic->vdev, FNIC_MSIX_ERR_NOTIFY); | ||
258 | break; | ||
259 | default: | ||
260 | shost_printk(KERN_ERR, fnic->lport->host, | ||
261 | "Interrupt mode should be set up" | ||
262 | " before devcmd notify set %d\n", | ||
263 | vnic_dev_get_intr_mode(fnic->vdev)); | ||
264 | err = -1; | ||
265 | break; | ||
266 | } | ||
267 | |||
268 | return err; | ||
269 | } | ||
270 | |||
271 | static void fnic_notify_timer(unsigned long data) | ||
272 | { | ||
273 | struct fnic *fnic = (struct fnic *)data; | ||
274 | |||
275 | fnic_handle_link_event(fnic); | ||
276 | mod_timer(&fnic->notify_timer, | ||
277 | round_jiffies(jiffies + FNIC_NOTIFY_TIMER_PERIOD)); | ||
278 | } | ||
279 | |||
280 | static void fnic_notify_timer_start(struct fnic *fnic) | ||
281 | { | ||
282 | switch (vnic_dev_get_intr_mode(fnic->vdev)) { | ||
283 | case VNIC_DEV_INTR_MODE_MSI: | ||
284 | /* | ||
285 | * Schedule first timeout immediately. The driver is | ||
286 | * initiatialized and ready to look for link up notification | ||
287 | */ | ||
288 | mod_timer(&fnic->notify_timer, jiffies); | ||
289 | break; | ||
290 | default: | ||
291 | /* Using intr for notification for INTx/MSI-X */ | ||
292 | break; | ||
293 | }; | ||
294 | } | ||
295 | |||
296 | static int fnic_dev_wait(struct vnic_dev *vdev, | ||
297 | int (*start)(struct vnic_dev *, int), | ||
298 | int (*finished)(struct vnic_dev *, int *), | ||
299 | int arg) | ||
300 | { | ||
301 | unsigned long time; | ||
302 | int done; | ||
303 | int err; | ||
304 | |||
305 | err = start(vdev, arg); | ||
306 | if (err) | ||
307 | return err; | ||
308 | |||
309 | /* Wait for func to complete...2 seconds max */ | ||
310 | time = jiffies + (HZ * 2); | ||
311 | do { | ||
312 | err = finished(vdev, &done); | ||
313 | if (err) | ||
314 | return err; | ||
315 | if (done) | ||
316 | return 0; | ||
317 | schedule_timeout_uninterruptible(HZ / 10); | ||
318 | } while (time_after(time, jiffies)); | ||
319 | |||
320 | return -ETIMEDOUT; | ||
321 | } | ||
322 | |||
323 | static int fnic_cleanup(struct fnic *fnic) | ||
324 | { | ||
325 | unsigned int i; | ||
326 | int err; | ||
327 | unsigned long flags; | ||
328 | struct fc_frame *flogi = NULL; | ||
329 | struct fc_frame *flogi_resp = NULL; | ||
330 | |||
331 | vnic_dev_disable(fnic->vdev); | ||
332 | for (i = 0; i < fnic->intr_count; i++) | ||
333 | vnic_intr_mask(&fnic->intr[i]); | ||
334 | |||
335 | for (i = 0; i < fnic->rq_count; i++) { | ||
336 | err = vnic_rq_disable(&fnic->rq[i]); | ||
337 | if (err) | ||
338 | return err; | ||
339 | } | ||
340 | for (i = 0; i < fnic->raw_wq_count; i++) { | ||
341 | err = vnic_wq_disable(&fnic->wq[i]); | ||
342 | if (err) | ||
343 | return err; | ||
344 | } | ||
345 | for (i = 0; i < fnic->wq_copy_count; i++) { | ||
346 | err = vnic_wq_copy_disable(&fnic->wq_copy[i]); | ||
347 | if (err) | ||
348 | return err; | ||
349 | } | ||
350 | |||
351 | /* Clean up completed IOs and FCS frames */ | ||
352 | fnic_wq_copy_cmpl_handler(fnic, -1); | ||
353 | fnic_wq_cmpl_handler(fnic, -1); | ||
354 | fnic_rq_cmpl_handler(fnic, -1); | ||
355 | |||
356 | /* Clean up the IOs and FCS frames that have not completed */ | ||
357 | for (i = 0; i < fnic->raw_wq_count; i++) | ||
358 | vnic_wq_clean(&fnic->wq[i], fnic_free_wq_buf); | ||
359 | for (i = 0; i < fnic->rq_count; i++) | ||
360 | vnic_rq_clean(&fnic->rq[i], fnic_free_rq_buf); | ||
361 | for (i = 0; i < fnic->wq_copy_count; i++) | ||
362 | vnic_wq_copy_clean(&fnic->wq_copy[i], | ||
363 | fnic_wq_copy_cleanup_handler); | ||
364 | |||
365 | for (i = 0; i < fnic->cq_count; i++) | ||
366 | vnic_cq_clean(&fnic->cq[i]); | ||
367 | for (i = 0; i < fnic->intr_count; i++) | ||
368 | vnic_intr_clean(&fnic->intr[i]); | ||
369 | |||
370 | /* | ||
371 | * Remove cached flogi and flogi resp frames if any | ||
372 | * These frames are not in any queue, and therefore queue | ||
373 | * cleanup does not clean them. So clean them explicitly | ||
374 | */ | ||
375 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
376 | flogi = fnic->flogi; | ||
377 | fnic->flogi = NULL; | ||
378 | flogi_resp = fnic->flogi_resp; | ||
379 | fnic->flogi_resp = NULL; | ||
380 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
381 | |||
382 | if (flogi) | ||
383 | dev_kfree_skb(fp_skb(flogi)); | ||
384 | |||
385 | if (flogi_resp) | ||
386 | dev_kfree_skb(fp_skb(flogi_resp)); | ||
387 | |||
388 | mempool_destroy(fnic->io_req_pool); | ||
389 | for (i = 0; i < FNIC_SGL_NUM_CACHES; i++) | ||
390 | mempool_destroy(fnic->io_sgl_pool[i]); | ||
391 | |||
392 | return 0; | ||
393 | } | ||
394 | |||
395 | static void fnic_iounmap(struct fnic *fnic) | ||
396 | { | ||
397 | if (fnic->bar0.vaddr) | ||
398 | iounmap(fnic->bar0.vaddr); | ||
399 | } | ||
400 | |||
401 | /* | ||
402 | * Allocate element for mempools requiring GFP_DMA flag. | ||
403 | * Otherwise, checks in kmem_flagcheck() hit BUG_ON(). | ||
404 | */ | ||
405 | static void *fnic_alloc_slab_dma(gfp_t gfp_mask, void *pool_data) | ||
406 | { | ||
407 | struct kmem_cache *mem = pool_data; | ||
408 | |||
409 | return kmem_cache_alloc(mem, gfp_mask | GFP_ATOMIC | GFP_DMA); | ||
410 | } | ||
411 | |||
412 | static int __devinit fnic_probe(struct pci_dev *pdev, | ||
413 | const struct pci_device_id *ent) | ||
414 | { | ||
415 | struct Scsi_Host *host; | ||
416 | struct fc_lport *lp; | ||
417 | struct fnic *fnic; | ||
418 | mempool_t *pool; | ||
419 | int err; | ||
420 | int i; | ||
421 | unsigned long flags; | ||
422 | |||
423 | /* | ||
424 | * Allocate SCSI Host and set up association between host, | ||
425 | * local port, and fnic | ||
426 | */ | ||
427 | host = scsi_host_alloc(&fnic_host_template, | ||
428 | sizeof(struct fc_lport) + sizeof(struct fnic)); | ||
429 | if (!host) { | ||
430 | printk(KERN_ERR PFX "Unable to alloc SCSI host\n"); | ||
431 | err = -ENOMEM; | ||
432 | goto err_out; | ||
433 | } | ||
434 | lp = shost_priv(host); | ||
435 | lp->host = host; | ||
436 | fnic = lport_priv(lp); | ||
437 | fnic->lport = lp; | ||
438 | |||
439 | snprintf(fnic->name, sizeof(fnic->name) - 1, "%s%d", DRV_NAME, | ||
440 | host->host_no); | ||
441 | |||
442 | host->transportt = fnic_fc_transport; | ||
443 | |||
444 | err = scsi_init_shared_tag_map(host, FNIC_MAX_IO_REQ); | ||
445 | if (err) { | ||
446 | shost_printk(KERN_ERR, fnic->lport->host, | ||
447 | "Unable to alloc shared tag map\n"); | ||
448 | goto err_out_free_hba; | ||
449 | } | ||
450 | |||
451 | /* Setup PCI resources */ | ||
452 | pci_set_drvdata(pdev, fnic); | ||
453 | |||
454 | fnic->pdev = pdev; | ||
455 | |||
456 | err = pci_enable_device(pdev); | ||
457 | if (err) { | ||
458 | shost_printk(KERN_ERR, fnic->lport->host, | ||
459 | "Cannot enable PCI device, aborting.\n"); | ||
460 | goto err_out_free_hba; | ||
461 | } | ||
462 | |||
463 | err = pci_request_regions(pdev, DRV_NAME); | ||
464 | if (err) { | ||
465 | shost_printk(KERN_ERR, fnic->lport->host, | ||
466 | "Cannot enable PCI resources, aborting\n"); | ||
467 | goto err_out_disable_device; | ||
468 | } | ||
469 | |||
470 | pci_set_master(pdev); | ||
471 | |||
472 | /* Query PCI controller on system for DMA addressing | ||
473 | * limitation for the device. Try 40-bit first, and | ||
474 | * fail to 32-bit. | ||
475 | */ | ||
476 | err = pci_set_dma_mask(pdev, DMA_40BIT_MASK); | ||
477 | if (err) { | ||
478 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); | ||
479 | if (err) { | ||
480 | shost_printk(KERN_ERR, fnic->lport->host, | ||
481 | "No usable DMA configuration " | ||
482 | "aborting\n"); | ||
483 | goto err_out_release_regions; | ||
484 | } | ||
485 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); | ||
486 | if (err) { | ||
487 | shost_printk(KERN_ERR, fnic->lport->host, | ||
488 | "Unable to obtain 32-bit DMA " | ||
489 | "for consistent allocations, aborting.\n"); | ||
490 | goto err_out_release_regions; | ||
491 | } | ||
492 | } else { | ||
493 | err = pci_set_consistent_dma_mask(pdev, DMA_40BIT_MASK); | ||
494 | if (err) { | ||
495 | shost_printk(KERN_ERR, fnic->lport->host, | ||
496 | "Unable to obtain 40-bit DMA " | ||
497 | "for consistent allocations, aborting.\n"); | ||
498 | goto err_out_release_regions; | ||
499 | } | ||
500 | } | ||
501 | |||
502 | /* Map vNIC resources from BAR0 */ | ||
503 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { | ||
504 | shost_printk(KERN_ERR, fnic->lport->host, | ||
505 | "BAR0 not memory-map'able, aborting.\n"); | ||
506 | err = -ENODEV; | ||
507 | goto err_out_release_regions; | ||
508 | } | ||
509 | |||
510 | fnic->bar0.vaddr = pci_iomap(pdev, 0, 0); | ||
511 | fnic->bar0.bus_addr = pci_resource_start(pdev, 0); | ||
512 | fnic->bar0.len = pci_resource_len(pdev, 0); | ||
513 | |||
514 | if (!fnic->bar0.vaddr) { | ||
515 | shost_printk(KERN_ERR, fnic->lport->host, | ||
516 | "Cannot memory-map BAR0 res hdr, " | ||
517 | "aborting.\n"); | ||
518 | err = -ENODEV; | ||
519 | goto err_out_release_regions; | ||
520 | } | ||
521 | |||
522 | fnic->vdev = vnic_dev_register(NULL, fnic, pdev, &fnic->bar0); | ||
523 | if (!fnic->vdev) { | ||
524 | shost_printk(KERN_ERR, fnic->lport->host, | ||
525 | "vNIC registration failed, " | ||
526 | "aborting.\n"); | ||
527 | err = -ENODEV; | ||
528 | goto err_out_iounmap; | ||
529 | } | ||
530 | |||
531 | err = fnic_dev_wait(fnic->vdev, vnic_dev_open, | ||
532 | vnic_dev_open_done, 0); | ||
533 | if (err) { | ||
534 | shost_printk(KERN_ERR, fnic->lport->host, | ||
535 | "vNIC dev open failed, aborting.\n"); | ||
536 | goto err_out_vnic_unregister; | ||
537 | } | ||
538 | |||
539 | err = vnic_dev_init(fnic->vdev, 0); | ||
540 | if (err) { | ||
541 | shost_printk(KERN_ERR, fnic->lport->host, | ||
542 | "vNIC dev init failed, aborting.\n"); | ||
543 | goto err_out_dev_close; | ||
544 | } | ||
545 | |||
546 | err = vnic_dev_mac_addr(fnic->vdev, fnic->mac_addr); | ||
547 | if (err) { | ||
548 | shost_printk(KERN_ERR, fnic->lport->host, | ||
549 | "vNIC get MAC addr failed \n"); | ||
550 | goto err_out_dev_close; | ||
551 | } | ||
552 | |||
553 | /* Get vNIC configuration */ | ||
554 | err = fnic_get_vnic_config(fnic); | ||
555 | if (err) { | ||
556 | shost_printk(KERN_ERR, fnic->lport->host, | ||
557 | "Get vNIC configuration failed, " | ||
558 | "aborting.\n"); | ||
559 | goto err_out_dev_close; | ||
560 | } | ||
561 | host->max_lun = fnic->config.luns_per_tgt; | ||
562 | host->max_id = FNIC_MAX_FCP_TARGET; | ||
563 | |||
564 | fnic_get_res_counts(fnic); | ||
565 | |||
566 | err = fnic_set_intr_mode(fnic); | ||
567 | if (err) { | ||
568 | shost_printk(KERN_ERR, fnic->lport->host, | ||
569 | "Failed to set intr mode, " | ||
570 | "aborting.\n"); | ||
571 | goto err_out_dev_close; | ||
572 | } | ||
573 | |||
574 | err = fnic_request_intr(fnic); | ||
575 | if (err) { | ||
576 | shost_printk(KERN_ERR, fnic->lport->host, | ||
577 | "Unable to request irq.\n"); | ||
578 | goto err_out_clear_intr; | ||
579 | } | ||
580 | |||
581 | err = fnic_alloc_vnic_resources(fnic); | ||
582 | if (err) { | ||
583 | shost_printk(KERN_ERR, fnic->lport->host, | ||
584 | "Failed to alloc vNIC resources, " | ||
585 | "aborting.\n"); | ||
586 | goto err_out_free_intr; | ||
587 | } | ||
588 | |||
589 | |||
590 | /* initialize all fnic locks */ | ||
591 | spin_lock_init(&fnic->fnic_lock); | ||
592 | |||
593 | for (i = 0; i < FNIC_WQ_MAX; i++) | ||
594 | spin_lock_init(&fnic->wq_lock[i]); | ||
595 | |||
596 | for (i = 0; i < FNIC_WQ_COPY_MAX; i++) { | ||
597 | spin_lock_init(&fnic->wq_copy_lock[i]); | ||
598 | fnic->wq_copy_desc_low[i] = DESC_CLEAN_LOW_WATERMARK; | ||
599 | fnic->fw_ack_recd[i] = 0; | ||
600 | fnic->fw_ack_index[i] = -1; | ||
601 | } | ||
602 | |||
603 | for (i = 0; i < FNIC_IO_LOCKS; i++) | ||
604 | spin_lock_init(&fnic->io_req_lock[i]); | ||
605 | |||
606 | fnic->io_req_pool = mempool_create_slab_pool(2, fnic_io_req_cache); | ||
607 | if (!fnic->io_req_pool) | ||
608 | goto err_out_free_resources; | ||
609 | |||
610 | pool = mempool_create(2, fnic_alloc_slab_dma, mempool_free_slab, | ||
611 | fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]); | ||
612 | if (!pool) | ||
613 | goto err_out_free_ioreq_pool; | ||
614 | fnic->io_sgl_pool[FNIC_SGL_CACHE_DFLT] = pool; | ||
615 | |||
616 | pool = mempool_create(2, fnic_alloc_slab_dma, mempool_free_slab, | ||
617 | fnic_sgl_cache[FNIC_SGL_CACHE_MAX]); | ||
618 | if (!pool) | ||
619 | goto err_out_free_dflt_pool; | ||
620 | fnic->io_sgl_pool[FNIC_SGL_CACHE_MAX] = pool; | ||
621 | |||
622 | /* setup vlan config, hw inserts vlan header */ | ||
623 | fnic->vlan_hw_insert = 1; | ||
624 | fnic->vlan_id = 0; | ||
625 | |||
626 | fnic->flogi_oxid = FC_XID_UNKNOWN; | ||
627 | fnic->flogi = NULL; | ||
628 | fnic->flogi_resp = NULL; | ||
629 | fnic->state = FNIC_IN_FC_MODE; | ||
630 | |||
631 | /* Enable hardware stripping of vlan header on ingress */ | ||
632 | fnic_set_nic_config(fnic, 0, 0, 0, 0, 0, 0, 1); | ||
633 | |||
634 | /* Setup notification buffer area */ | ||
635 | err = fnic_notify_set(fnic); | ||
636 | if (err) { | ||
637 | shost_printk(KERN_ERR, fnic->lport->host, | ||
638 | "Failed to alloc notify buffer, aborting.\n"); | ||
639 | goto err_out_free_max_pool; | ||
640 | } | ||
641 | |||
642 | /* Setup notify timer when using MSI interrupts */ | ||
643 | if (vnic_dev_get_intr_mode(fnic->vdev) == VNIC_DEV_INTR_MODE_MSI) | ||
644 | setup_timer(&fnic->notify_timer, | ||
645 | fnic_notify_timer, (unsigned long)fnic); | ||
646 | |||
647 | /* allocate RQ buffers and post them to RQ*/ | ||
648 | for (i = 0; i < fnic->rq_count; i++) { | ||
649 | err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame); | ||
650 | if (err) { | ||
651 | shost_printk(KERN_ERR, fnic->lport->host, | ||
652 | "fnic_alloc_rq_frame can't alloc " | ||
653 | "frame\n"); | ||
654 | goto err_out_free_rq_buf; | ||
655 | } | ||
656 | } | ||
657 | |||
658 | /* | ||
659 | * Initialization done with PCI system, hardware, firmware. | ||
660 | * Add host to SCSI | ||
661 | */ | ||
662 | err = scsi_add_host(lp->host, &pdev->dev); | ||
663 | if (err) { | ||
664 | shost_printk(KERN_ERR, fnic->lport->host, | ||
665 | "fnic: scsi_add_host failed...exiting\n"); | ||
666 | goto err_out_free_rq_buf; | ||
667 | } | ||
668 | |||
669 | /* Start local port initiatialization */ | ||
670 | |||
671 | lp->link_up = 0; | ||
672 | lp->tt = fnic_transport_template; | ||
673 | |||
674 | lp->emp = fc_exch_mgr_alloc(lp, FC_CLASS_3, | ||
675 | FCPIO_HOST_EXCH_RANGE_START, | ||
676 | FCPIO_HOST_EXCH_RANGE_END); | ||
677 | if (!lp->emp) { | ||
678 | err = -ENOMEM; | ||
679 | goto err_out_remove_scsi_host; | ||
680 | } | ||
681 | |||
682 | lp->max_retry_count = fnic->config.flogi_retries; | ||
683 | lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | | ||
684 | FCP_SPPF_CONF_COMPL); | ||
685 | if (fnic->config.flags & VFCF_FCP_SEQ_LVL_ERR) | ||
686 | lp->service_params |= FCP_SPPF_RETRY; | ||
687 | |||
688 | lp->boot_time = jiffies; | ||
689 | lp->e_d_tov = fnic->config.ed_tov; | ||
690 | lp->r_a_tov = fnic->config.ra_tov; | ||
691 | lp->link_supported_speeds = FC_PORTSPEED_10GBIT; | ||
692 | fc_set_wwnn(lp, fnic->config.node_wwn); | ||
693 | fc_set_wwpn(lp, fnic->config.port_wwn); | ||
694 | |||
695 | fc_exch_init(lp); | ||
696 | fc_lport_init(lp); | ||
697 | fc_elsct_init(lp); | ||
698 | fc_rport_init(lp); | ||
699 | fc_disc_init(lp); | ||
700 | |||
701 | fc_lport_config(lp); | ||
702 | |||
703 | if (fc_set_mfs(lp, fnic->config.maxdatafieldsize + | ||
704 | sizeof(struct fc_frame_header))) { | ||
705 | err = -EINVAL; | ||
706 | goto err_out_free_exch_mgr; | ||
707 | } | ||
708 | fc_host_maxframe_size(lp->host) = lp->mfs; | ||
709 | |||
710 | sprintf(fc_host_symbolic_name(lp->host), | ||
711 | DRV_NAME " v" DRV_VERSION " over %s", fnic->name); | ||
712 | |||
713 | spin_lock_irqsave(&fnic_list_lock, flags); | ||
714 | list_add_tail(&fnic->list, &fnic_list); | ||
715 | spin_unlock_irqrestore(&fnic_list_lock, flags); | ||
716 | |||
717 | INIT_WORK(&fnic->link_work, fnic_handle_link); | ||
718 | INIT_WORK(&fnic->frame_work, fnic_handle_frame); | ||
719 | skb_queue_head_init(&fnic->frame_queue); | ||
720 | |||
721 | /* Enable all queues */ | ||
722 | for (i = 0; i < fnic->raw_wq_count; i++) | ||
723 | vnic_wq_enable(&fnic->wq[i]); | ||
724 | for (i = 0; i < fnic->rq_count; i++) | ||
725 | vnic_rq_enable(&fnic->rq[i]); | ||
726 | for (i = 0; i < fnic->wq_copy_count; i++) | ||
727 | vnic_wq_copy_enable(&fnic->wq_copy[i]); | ||
728 | |||
729 | fc_fabric_login(lp); | ||
730 | |||
731 | vnic_dev_enable(fnic->vdev); | ||
732 | for (i = 0; i < fnic->intr_count; i++) | ||
733 | vnic_intr_unmask(&fnic->intr[i]); | ||
734 | |||
735 | fnic_notify_timer_start(fnic); | ||
736 | |||
737 | return 0; | ||
738 | |||
739 | err_out_free_exch_mgr: | ||
740 | fc_exch_mgr_free(lp->emp); | ||
741 | err_out_remove_scsi_host: | ||
742 | fc_remove_host(fnic->lport->host); | ||
743 | scsi_remove_host(fnic->lport->host); | ||
744 | err_out_free_rq_buf: | ||
745 | for (i = 0; i < fnic->rq_count; i++) | ||
746 | vnic_rq_clean(&fnic->rq[i], fnic_free_rq_buf); | ||
747 | vnic_dev_notify_unset(fnic->vdev); | ||
748 | err_out_free_max_pool: | ||
749 | mempool_destroy(fnic->io_sgl_pool[FNIC_SGL_CACHE_MAX]); | ||
750 | err_out_free_dflt_pool: | ||
751 | mempool_destroy(fnic->io_sgl_pool[FNIC_SGL_CACHE_DFLT]); | ||
752 | err_out_free_ioreq_pool: | ||
753 | mempool_destroy(fnic->io_req_pool); | ||
754 | err_out_free_resources: | ||
755 | fnic_free_vnic_resources(fnic); | ||
756 | err_out_free_intr: | ||
757 | fnic_free_intr(fnic); | ||
758 | err_out_clear_intr: | ||
759 | fnic_clear_intr_mode(fnic); | ||
760 | err_out_dev_close: | ||
761 | vnic_dev_close(fnic->vdev); | ||
762 | err_out_vnic_unregister: | ||
763 | vnic_dev_unregister(fnic->vdev); | ||
764 | err_out_iounmap: | ||
765 | fnic_iounmap(fnic); | ||
766 | err_out_release_regions: | ||
767 | pci_release_regions(pdev); | ||
768 | err_out_disable_device: | ||
769 | pci_disable_device(pdev); | ||
770 | err_out_free_hba: | ||
771 | scsi_host_put(lp->host); | ||
772 | err_out: | ||
773 | return err; | ||
774 | } | ||
775 | |||
776 | static void __devexit fnic_remove(struct pci_dev *pdev) | ||
777 | { | ||
778 | struct fnic *fnic = pci_get_drvdata(pdev); | ||
779 | unsigned long flags; | ||
780 | |||
781 | /* | ||
782 | * Mark state so that the workqueue thread stops forwarding | ||
783 | * received frames and link events to the local port. ISR and | ||
784 | * other threads that can queue work items will also stop | ||
785 | * creating work items on the fnic workqueue | ||
786 | */ | ||
787 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
788 | fnic->stop_rx_link_events = 1; | ||
789 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
790 | |||
791 | if (vnic_dev_get_intr_mode(fnic->vdev) == VNIC_DEV_INTR_MODE_MSI) | ||
792 | del_timer_sync(&fnic->notify_timer); | ||
793 | |||
794 | /* | ||
795 | * Flush the fnic event queue. After this call, there should | ||
796 | * be no event queued for this fnic device in the workqueue | ||
797 | */ | ||
798 | flush_workqueue(fnic_event_queue); | ||
799 | skb_queue_purge(&fnic->frame_queue); | ||
800 | |||
801 | /* | ||
802 | * Log off the fabric. This stops all remote ports, dns port, | ||
803 | * logs off the fabric. This flushes all rport, disc, lport work | ||
804 | * before returning | ||
805 | */ | ||
806 | fc_fabric_logoff(fnic->lport); | ||
807 | |||
808 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
809 | fnic->in_remove = 1; | ||
810 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
811 | |||
812 | fc_lport_destroy(fnic->lport); | ||
813 | |||
814 | /* | ||
815 | * This stops the fnic device, masks all interrupts. Completed | ||
816 | * CQ entries are drained. Posted WQ/RQ/Copy-WQ entries are | ||
817 | * cleaned up | ||
818 | */ | ||
819 | fnic_cleanup(fnic); | ||
820 | |||
821 | BUG_ON(!skb_queue_empty(&fnic->frame_queue)); | ||
822 | |||
823 | spin_lock_irqsave(&fnic_list_lock, flags); | ||
824 | list_del(&fnic->list); | ||
825 | spin_unlock_irqrestore(&fnic_list_lock, flags); | ||
826 | |||
827 | fc_remove_host(fnic->lport->host); | ||
828 | scsi_remove_host(fnic->lport->host); | ||
829 | fc_exch_mgr_free(fnic->lport->emp); | ||
830 | vnic_dev_notify_unset(fnic->vdev); | ||
831 | fnic_free_vnic_resources(fnic); | ||
832 | fnic_free_intr(fnic); | ||
833 | fnic_clear_intr_mode(fnic); | ||
834 | vnic_dev_close(fnic->vdev); | ||
835 | vnic_dev_unregister(fnic->vdev); | ||
836 | fnic_iounmap(fnic); | ||
837 | pci_release_regions(pdev); | ||
838 | pci_disable_device(pdev); | ||
839 | pci_set_drvdata(pdev, NULL); | ||
840 | scsi_host_put(fnic->lport->host); | ||
841 | } | ||
842 | |||
843 | static struct pci_driver fnic_driver = { | ||
844 | .name = DRV_NAME, | ||
845 | .id_table = fnic_id_table, | ||
846 | .probe = fnic_probe, | ||
847 | .remove = __devexit_p(fnic_remove), | ||
848 | }; | ||
849 | |||
850 | static int __init fnic_init_module(void) | ||
851 | { | ||
852 | size_t len; | ||
853 | int err = 0; | ||
854 | |||
855 | printk(KERN_INFO PFX "%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION); | ||
856 | |||
857 | /* Create a cache for allocation of default size sgls */ | ||
858 | len = sizeof(struct fnic_dflt_sgl_list); | ||
859 | fnic_sgl_cache[FNIC_SGL_CACHE_DFLT] = kmem_cache_create | ||
860 | ("fnic_sgl_dflt", len + FNIC_SG_DESC_ALIGN, FNIC_SG_DESC_ALIGN, | ||
861 | SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA, | ||
862 | NULL); | ||
863 | if (!fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]) { | ||
864 | printk(KERN_ERR PFX "failed to create fnic dflt sgl slab\n"); | ||
865 | err = -ENOMEM; | ||
866 | goto err_create_fnic_sgl_slab_dflt; | ||
867 | } | ||
868 | |||
869 | /* Create a cache for allocation of max size sgls*/ | ||
870 | len = sizeof(struct fnic_sgl_list); | ||
871 | fnic_sgl_cache[FNIC_SGL_CACHE_MAX] = kmem_cache_create | ||
872 | ("fnic_sgl_max", len + FNIC_SG_DESC_ALIGN, FNIC_SG_DESC_ALIGN, | ||
873 | SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA, | ||
874 | NULL); | ||
875 | if (!fnic_sgl_cache[FNIC_SGL_CACHE_MAX]) { | ||
876 | printk(KERN_ERR PFX "failed to create fnic max sgl slab\n"); | ||
877 | err = -ENOMEM; | ||
878 | goto err_create_fnic_sgl_slab_max; | ||
879 | } | ||
880 | |||
881 | /* Create a cache of io_req structs for use via mempool */ | ||
882 | fnic_io_req_cache = kmem_cache_create("fnic_io_req", | ||
883 | sizeof(struct fnic_io_req), | ||
884 | 0, SLAB_HWCACHE_ALIGN, NULL); | ||
885 | if (!fnic_io_req_cache) { | ||
886 | printk(KERN_ERR PFX "failed to create fnic io_req slab\n"); | ||
887 | err = -ENOMEM; | ||
888 | goto err_create_fnic_ioreq_slab; | ||
889 | } | ||
890 | |||
891 | fnic_event_queue = create_singlethread_workqueue("fnic_event_wq"); | ||
892 | if (!fnic_event_queue) { | ||
893 | printk(KERN_ERR PFX "fnic work queue create failed\n"); | ||
894 | err = -ENOMEM; | ||
895 | goto err_create_fnic_workq; | ||
896 | } | ||
897 | |||
898 | spin_lock_init(&fnic_list_lock); | ||
899 | INIT_LIST_HEAD(&fnic_list); | ||
900 | |||
901 | fnic_fc_transport = fc_attach_transport(&fnic_fc_functions); | ||
902 | if (!fnic_fc_transport) { | ||
903 | printk(KERN_ERR PFX "fc_attach_transport error\n"); | ||
904 | err = -ENOMEM; | ||
905 | goto err_fc_transport; | ||
906 | } | ||
907 | |||
908 | /* register the driver with PCI system */ | ||
909 | err = pci_register_driver(&fnic_driver); | ||
910 | if (err < 0) { | ||
911 | printk(KERN_ERR PFX "pci register error\n"); | ||
912 | goto err_pci_register; | ||
913 | } | ||
914 | return err; | ||
915 | |||
916 | err_pci_register: | ||
917 | fc_release_transport(fnic_fc_transport); | ||
918 | err_fc_transport: | ||
919 | destroy_workqueue(fnic_event_queue); | ||
920 | err_create_fnic_workq: | ||
921 | kmem_cache_destroy(fnic_io_req_cache); | ||
922 | err_create_fnic_ioreq_slab: | ||
923 | kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_MAX]); | ||
924 | err_create_fnic_sgl_slab_max: | ||
925 | kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]); | ||
926 | err_create_fnic_sgl_slab_dflt: | ||
927 | return err; | ||
928 | } | ||
929 | |||
930 | static void __exit fnic_cleanup_module(void) | ||
931 | { | ||
932 | pci_unregister_driver(&fnic_driver); | ||
933 | destroy_workqueue(fnic_event_queue); | ||
934 | kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_MAX]); | ||
935 | kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]); | ||
936 | kmem_cache_destroy(fnic_io_req_cache); | ||
937 | fc_release_transport(fnic_fc_transport); | ||
938 | } | ||
939 | |||
940 | module_init(fnic_init_module); | ||
941 | module_exit(fnic_cleanup_module); | ||
942 | |||
diff --git a/drivers/scsi/fnic/fnic_res.c b/drivers/scsi/fnic/fnic_res.c new file mode 100644 index 000000000000..7ba61ec715d2 --- /dev/null +++ b/drivers/scsi/fnic/fnic_res.c | |||
@@ -0,0 +1,444 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #include <linux/errno.h> | ||
19 | #include <linux/types.h> | ||
20 | #include <linux/pci.h> | ||
21 | #include "wq_enet_desc.h" | ||
22 | #include "rq_enet_desc.h" | ||
23 | #include "cq_enet_desc.h" | ||
24 | #include "vnic_resource.h" | ||
25 | #include "vnic_dev.h" | ||
26 | #include "vnic_wq.h" | ||
27 | #include "vnic_rq.h" | ||
28 | #include "vnic_cq.h" | ||
29 | #include "vnic_intr.h" | ||
30 | #include "vnic_stats.h" | ||
31 | #include "vnic_nic.h" | ||
32 | #include "fnic.h" | ||
33 | |||
34 | int fnic_get_vnic_config(struct fnic *fnic) | ||
35 | { | ||
36 | struct vnic_fc_config *c = &fnic->config; | ||
37 | int err; | ||
38 | |||
39 | #define GET_CONFIG(m) \ | ||
40 | do { \ | ||
41 | err = vnic_dev_spec(fnic->vdev, \ | ||
42 | offsetof(struct vnic_fc_config, m), \ | ||
43 | sizeof(c->m), &c->m); \ | ||
44 | if (err) { \ | ||
45 | shost_printk(KERN_ERR, fnic->lport->host, \ | ||
46 | "Error getting %s, %d\n", #m, \ | ||
47 | err); \ | ||
48 | return err; \ | ||
49 | } \ | ||
50 | } while (0); | ||
51 | |||
52 | GET_CONFIG(node_wwn); | ||
53 | GET_CONFIG(port_wwn); | ||
54 | GET_CONFIG(wq_enet_desc_count); | ||
55 | GET_CONFIG(wq_copy_desc_count); | ||
56 | GET_CONFIG(rq_desc_count); | ||
57 | GET_CONFIG(maxdatafieldsize); | ||
58 | GET_CONFIG(ed_tov); | ||
59 | GET_CONFIG(ra_tov); | ||
60 | GET_CONFIG(intr_timer); | ||
61 | GET_CONFIG(intr_timer_type); | ||
62 | GET_CONFIG(flags); | ||
63 | GET_CONFIG(flogi_retries); | ||
64 | GET_CONFIG(flogi_timeout); | ||
65 | GET_CONFIG(plogi_retries); | ||
66 | GET_CONFIG(plogi_timeout); | ||
67 | GET_CONFIG(io_throttle_count); | ||
68 | GET_CONFIG(link_down_timeout); | ||
69 | GET_CONFIG(port_down_timeout); | ||
70 | GET_CONFIG(port_down_io_retries); | ||
71 | GET_CONFIG(luns_per_tgt); | ||
72 | |||
73 | c->wq_enet_desc_count = | ||
74 | min_t(u32, VNIC_FNIC_WQ_DESCS_MAX, | ||
75 | max_t(u32, VNIC_FNIC_WQ_DESCS_MIN, | ||
76 | c->wq_enet_desc_count)); | ||
77 | c->wq_enet_desc_count = ALIGN(c->wq_enet_desc_count, 16); | ||
78 | |||
79 | c->wq_copy_desc_count = | ||
80 | min_t(u32, VNIC_FNIC_WQ_COPY_DESCS_MAX, | ||
81 | max_t(u32, VNIC_FNIC_WQ_COPY_DESCS_MIN, | ||
82 | c->wq_copy_desc_count)); | ||
83 | c->wq_copy_desc_count = ALIGN(c->wq_copy_desc_count, 16); | ||
84 | |||
85 | c->rq_desc_count = | ||
86 | min_t(u32, VNIC_FNIC_RQ_DESCS_MAX, | ||
87 | max_t(u32, VNIC_FNIC_RQ_DESCS_MIN, | ||
88 | c->rq_desc_count)); | ||
89 | c->rq_desc_count = ALIGN(c->rq_desc_count, 16); | ||
90 | |||
91 | c->maxdatafieldsize = | ||
92 | min_t(u16, VNIC_FNIC_MAXDATAFIELDSIZE_MAX, | ||
93 | max_t(u16, VNIC_FNIC_MAXDATAFIELDSIZE_MIN, | ||
94 | c->maxdatafieldsize)); | ||
95 | c->ed_tov = | ||
96 | min_t(u32, VNIC_FNIC_EDTOV_MAX, | ||
97 | max_t(u32, VNIC_FNIC_EDTOV_MIN, | ||
98 | c->ed_tov)); | ||
99 | |||
100 | c->ra_tov = | ||
101 | min_t(u32, VNIC_FNIC_RATOV_MAX, | ||
102 | max_t(u32, VNIC_FNIC_RATOV_MIN, | ||
103 | c->ra_tov)); | ||
104 | |||
105 | c->flogi_retries = | ||
106 | min_t(u32, VNIC_FNIC_FLOGI_RETRIES_MAX, c->flogi_retries); | ||
107 | |||
108 | c->flogi_timeout = | ||
109 | min_t(u32, VNIC_FNIC_FLOGI_TIMEOUT_MAX, | ||
110 | max_t(u32, VNIC_FNIC_FLOGI_TIMEOUT_MIN, | ||
111 | c->flogi_timeout)); | ||
112 | |||
113 | c->plogi_retries = | ||
114 | min_t(u32, VNIC_FNIC_PLOGI_RETRIES_MAX, c->plogi_retries); | ||
115 | |||
116 | c->plogi_timeout = | ||
117 | min_t(u32, VNIC_FNIC_PLOGI_TIMEOUT_MAX, | ||
118 | max_t(u32, VNIC_FNIC_PLOGI_TIMEOUT_MIN, | ||
119 | c->plogi_timeout)); | ||
120 | |||
121 | c->io_throttle_count = | ||
122 | min_t(u32, VNIC_FNIC_IO_THROTTLE_COUNT_MAX, | ||
123 | max_t(u32, VNIC_FNIC_IO_THROTTLE_COUNT_MIN, | ||
124 | c->io_throttle_count)); | ||
125 | |||
126 | c->link_down_timeout = | ||
127 | min_t(u32, VNIC_FNIC_LINK_DOWN_TIMEOUT_MAX, | ||
128 | c->link_down_timeout); | ||
129 | |||
130 | c->port_down_timeout = | ||
131 | min_t(u32, VNIC_FNIC_PORT_DOWN_TIMEOUT_MAX, | ||
132 | c->port_down_timeout); | ||
133 | |||
134 | c->port_down_io_retries = | ||
135 | min_t(u32, VNIC_FNIC_PORT_DOWN_IO_RETRIES_MAX, | ||
136 | c->port_down_io_retries); | ||
137 | |||
138 | c->luns_per_tgt = | ||
139 | min_t(u32, VNIC_FNIC_LUNS_PER_TARGET_MAX, | ||
140 | max_t(u32, VNIC_FNIC_LUNS_PER_TARGET_MIN, | ||
141 | c->luns_per_tgt)); | ||
142 | |||
143 | c->intr_timer = min_t(u16, VNIC_INTR_TIMER_MAX, c->intr_timer); | ||
144 | c->intr_timer_type = c->intr_timer_type; | ||
145 | |||
146 | shost_printk(KERN_INFO, fnic->lport->host, | ||
147 | "vNIC MAC addr %02x:%02x:%02x:%02x:%02x:%02x " | ||
148 | "wq/wq_copy/rq %d/%d/%d\n", | ||
149 | fnic->mac_addr[0], fnic->mac_addr[1], fnic->mac_addr[2], | ||
150 | fnic->mac_addr[3], fnic->mac_addr[4], fnic->mac_addr[5], | ||
151 | c->wq_enet_desc_count, c->wq_copy_desc_count, | ||
152 | c->rq_desc_count); | ||
153 | shost_printk(KERN_INFO, fnic->lport->host, | ||
154 | "vNIC node wwn %llx port wwn %llx\n", | ||
155 | c->node_wwn, c->port_wwn); | ||
156 | shost_printk(KERN_INFO, fnic->lport->host, | ||
157 | "vNIC ed_tov %d ra_tov %d\n", | ||
158 | c->ed_tov, c->ra_tov); | ||
159 | shost_printk(KERN_INFO, fnic->lport->host, | ||
160 | "vNIC mtu %d intr timer %d\n", | ||
161 | c->maxdatafieldsize, c->intr_timer); | ||
162 | shost_printk(KERN_INFO, fnic->lport->host, | ||
163 | "vNIC flags 0x%x luns per tgt %d\n", | ||
164 | c->flags, c->luns_per_tgt); | ||
165 | shost_printk(KERN_INFO, fnic->lport->host, | ||
166 | "vNIC flogi_retries %d flogi timeout %d\n", | ||
167 | c->flogi_retries, c->flogi_timeout); | ||
168 | shost_printk(KERN_INFO, fnic->lport->host, | ||
169 | "vNIC plogi retries %d plogi timeout %d\n", | ||
170 | c->plogi_retries, c->plogi_timeout); | ||
171 | shost_printk(KERN_INFO, fnic->lport->host, | ||
172 | "vNIC io throttle count %d link dn timeout %d\n", | ||
173 | c->io_throttle_count, c->link_down_timeout); | ||
174 | shost_printk(KERN_INFO, fnic->lport->host, | ||
175 | "vNIC port dn io retries %d port dn timeout %d\n", | ||
176 | c->port_down_io_retries, c->port_down_timeout); | ||
177 | |||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | int fnic_set_nic_config(struct fnic *fnic, u8 rss_default_cpu, | ||
182 | u8 rss_hash_type, | ||
183 | u8 rss_hash_bits, u8 rss_base_cpu, u8 rss_enable, | ||
184 | u8 tso_ipid_split_en, u8 ig_vlan_strip_en) | ||
185 | { | ||
186 | u64 a0, a1; | ||
187 | u32 nic_cfg; | ||
188 | int wait = 1000; | ||
189 | |||
190 | vnic_set_nic_cfg(&nic_cfg, rss_default_cpu, | ||
191 | rss_hash_type, rss_hash_bits, rss_base_cpu, | ||
192 | rss_enable, tso_ipid_split_en, ig_vlan_strip_en); | ||
193 | |||
194 | a0 = nic_cfg; | ||
195 | a1 = 0; | ||
196 | |||
197 | return vnic_dev_cmd(fnic->vdev, CMD_NIC_CFG, &a0, &a1, wait); | ||
198 | } | ||
199 | |||
200 | void fnic_get_res_counts(struct fnic *fnic) | ||
201 | { | ||
202 | fnic->wq_count = vnic_dev_get_res_count(fnic->vdev, RES_TYPE_WQ); | ||
203 | fnic->raw_wq_count = fnic->wq_count - 1; | ||
204 | fnic->wq_copy_count = fnic->wq_count - fnic->raw_wq_count; | ||
205 | fnic->rq_count = vnic_dev_get_res_count(fnic->vdev, RES_TYPE_RQ); | ||
206 | fnic->cq_count = vnic_dev_get_res_count(fnic->vdev, RES_TYPE_CQ); | ||
207 | fnic->intr_count = vnic_dev_get_res_count(fnic->vdev, | ||
208 | RES_TYPE_INTR_CTRL); | ||
209 | } | ||
210 | |||
211 | void fnic_free_vnic_resources(struct fnic *fnic) | ||
212 | { | ||
213 | unsigned int i; | ||
214 | |||
215 | for (i = 0; i < fnic->raw_wq_count; i++) | ||
216 | vnic_wq_free(&fnic->wq[i]); | ||
217 | |||
218 | for (i = 0; i < fnic->wq_copy_count; i++) | ||
219 | vnic_wq_copy_free(&fnic->wq_copy[i]); | ||
220 | |||
221 | for (i = 0; i < fnic->rq_count; i++) | ||
222 | vnic_rq_free(&fnic->rq[i]); | ||
223 | |||
224 | for (i = 0; i < fnic->cq_count; i++) | ||
225 | vnic_cq_free(&fnic->cq[i]); | ||
226 | |||
227 | for (i = 0; i < fnic->intr_count; i++) | ||
228 | vnic_intr_free(&fnic->intr[i]); | ||
229 | } | ||
230 | |||
231 | int fnic_alloc_vnic_resources(struct fnic *fnic) | ||
232 | { | ||
233 | enum vnic_dev_intr_mode intr_mode; | ||
234 | unsigned int mask_on_assertion; | ||
235 | unsigned int interrupt_offset; | ||
236 | unsigned int error_interrupt_enable; | ||
237 | unsigned int error_interrupt_offset; | ||
238 | unsigned int i, cq_index; | ||
239 | unsigned int wq_copy_cq_desc_count; | ||
240 | int err; | ||
241 | |||
242 | intr_mode = vnic_dev_get_intr_mode(fnic->vdev); | ||
243 | |||
244 | shost_printk(KERN_INFO, fnic->lport->host, "vNIC interrupt mode: %s\n", | ||
245 | intr_mode == VNIC_DEV_INTR_MODE_INTX ? "legacy PCI INTx" : | ||
246 | intr_mode == VNIC_DEV_INTR_MODE_MSI ? "MSI" : | ||
247 | intr_mode == VNIC_DEV_INTR_MODE_MSIX ? | ||
248 | "MSI-X" : "unknown"); | ||
249 | |||
250 | shost_printk(KERN_INFO, fnic->lport->host, "vNIC resources avail: " | ||
251 | "wq %d cp_wq %d raw_wq %d rq %d cq %d intr %d\n", | ||
252 | fnic->wq_count, fnic->wq_copy_count, fnic->raw_wq_count, | ||
253 | fnic->rq_count, fnic->cq_count, fnic->intr_count); | ||
254 | |||
255 | /* Allocate Raw WQ used for FCS frames */ | ||
256 | for (i = 0; i < fnic->raw_wq_count; i++) { | ||
257 | err = vnic_wq_alloc(fnic->vdev, &fnic->wq[i], i, | ||
258 | fnic->config.wq_enet_desc_count, | ||
259 | sizeof(struct wq_enet_desc)); | ||
260 | if (err) | ||
261 | goto err_out_cleanup; | ||
262 | } | ||
263 | |||
264 | /* Allocate Copy WQs used for SCSI IOs */ | ||
265 | for (i = 0; i < fnic->wq_copy_count; i++) { | ||
266 | err = vnic_wq_copy_alloc(fnic->vdev, &fnic->wq_copy[i], | ||
267 | (fnic->raw_wq_count + i), | ||
268 | fnic->config.wq_copy_desc_count, | ||
269 | sizeof(struct fcpio_host_req)); | ||
270 | if (err) | ||
271 | goto err_out_cleanup; | ||
272 | } | ||
273 | |||
274 | /* RQ for receiving FCS frames */ | ||
275 | for (i = 0; i < fnic->rq_count; i++) { | ||
276 | err = vnic_rq_alloc(fnic->vdev, &fnic->rq[i], i, | ||
277 | fnic->config.rq_desc_count, | ||
278 | sizeof(struct rq_enet_desc)); | ||
279 | if (err) | ||
280 | goto err_out_cleanup; | ||
281 | } | ||
282 | |||
283 | /* CQ for each RQ */ | ||
284 | for (i = 0; i < fnic->rq_count; i++) { | ||
285 | cq_index = i; | ||
286 | err = vnic_cq_alloc(fnic->vdev, | ||
287 | &fnic->cq[cq_index], cq_index, | ||
288 | fnic->config.rq_desc_count, | ||
289 | sizeof(struct cq_enet_rq_desc)); | ||
290 | if (err) | ||
291 | goto err_out_cleanup; | ||
292 | } | ||
293 | |||
294 | /* CQ for each WQ */ | ||
295 | for (i = 0; i < fnic->raw_wq_count; i++) { | ||
296 | cq_index = fnic->rq_count + i; | ||
297 | err = vnic_cq_alloc(fnic->vdev, &fnic->cq[cq_index], cq_index, | ||
298 | fnic->config.wq_enet_desc_count, | ||
299 | sizeof(struct cq_enet_wq_desc)); | ||
300 | if (err) | ||
301 | goto err_out_cleanup; | ||
302 | } | ||
303 | |||
304 | /* CQ for each COPY WQ */ | ||
305 | wq_copy_cq_desc_count = (fnic->config.wq_copy_desc_count * 3); | ||
306 | for (i = 0; i < fnic->wq_copy_count; i++) { | ||
307 | cq_index = fnic->raw_wq_count + fnic->rq_count + i; | ||
308 | err = vnic_cq_alloc(fnic->vdev, &fnic->cq[cq_index], | ||
309 | cq_index, | ||
310 | wq_copy_cq_desc_count, | ||
311 | sizeof(struct fcpio_fw_req)); | ||
312 | if (err) | ||
313 | goto err_out_cleanup; | ||
314 | } | ||
315 | |||
316 | for (i = 0; i < fnic->intr_count; i++) { | ||
317 | err = vnic_intr_alloc(fnic->vdev, &fnic->intr[i], i); | ||
318 | if (err) | ||
319 | goto err_out_cleanup; | ||
320 | } | ||
321 | |||
322 | fnic->legacy_pba = vnic_dev_get_res(fnic->vdev, | ||
323 | RES_TYPE_INTR_PBA_LEGACY, 0); | ||
324 | |||
325 | if (!fnic->legacy_pba && intr_mode == VNIC_DEV_INTR_MODE_INTX) { | ||
326 | shost_printk(KERN_ERR, fnic->lport->host, | ||
327 | "Failed to hook legacy pba resource\n"); | ||
328 | err = -ENODEV; | ||
329 | goto err_out_cleanup; | ||
330 | } | ||
331 | |||
332 | /* | ||
333 | * Init RQ/WQ resources. | ||
334 | * | ||
335 | * RQ[0 to n-1] point to CQ[0 to n-1] | ||
336 | * WQ[0 to m-1] point to CQ[n to n+m-1] | ||
337 | * WQ_COPY[0 to k-1] points to CQ[n+m to n+m+k-1] | ||
338 | * | ||
339 | * Note for copy wq we always initialize with cq_index = 0 | ||
340 | * | ||
341 | * Error interrupt is not enabled for MSI. | ||
342 | */ | ||
343 | |||
344 | switch (intr_mode) { | ||
345 | case VNIC_DEV_INTR_MODE_INTX: | ||
346 | case VNIC_DEV_INTR_MODE_MSIX: | ||
347 | error_interrupt_enable = 1; | ||
348 | error_interrupt_offset = fnic->err_intr_offset; | ||
349 | break; | ||
350 | default: | ||
351 | error_interrupt_enable = 0; | ||
352 | error_interrupt_offset = 0; | ||
353 | break; | ||
354 | } | ||
355 | |||
356 | for (i = 0; i < fnic->rq_count; i++) { | ||
357 | cq_index = i; | ||
358 | vnic_rq_init(&fnic->rq[i], | ||
359 | cq_index, | ||
360 | error_interrupt_enable, | ||
361 | error_interrupt_offset); | ||
362 | } | ||
363 | |||
364 | for (i = 0; i < fnic->raw_wq_count; i++) { | ||
365 | cq_index = i + fnic->rq_count; | ||
366 | vnic_wq_init(&fnic->wq[i], | ||
367 | cq_index, | ||
368 | error_interrupt_enable, | ||
369 | error_interrupt_offset); | ||
370 | } | ||
371 | |||
372 | for (i = 0; i < fnic->wq_copy_count; i++) { | ||
373 | vnic_wq_copy_init(&fnic->wq_copy[i], | ||
374 | 0 /* cq_index 0 - always */, | ||
375 | error_interrupt_enable, | ||
376 | error_interrupt_offset); | ||
377 | } | ||
378 | |||
379 | for (i = 0; i < fnic->cq_count; i++) { | ||
380 | |||
381 | switch (intr_mode) { | ||
382 | case VNIC_DEV_INTR_MODE_MSIX: | ||
383 | interrupt_offset = i; | ||
384 | break; | ||
385 | default: | ||
386 | interrupt_offset = 0; | ||
387 | break; | ||
388 | } | ||
389 | |||
390 | vnic_cq_init(&fnic->cq[i], | ||
391 | 0 /* flow_control_enable */, | ||
392 | 1 /* color_enable */, | ||
393 | 0 /* cq_head */, | ||
394 | 0 /* cq_tail */, | ||
395 | 1 /* cq_tail_color */, | ||
396 | 1 /* interrupt_enable */, | ||
397 | 1 /* cq_entry_enable */, | ||
398 | 0 /* cq_message_enable */, | ||
399 | interrupt_offset, | ||
400 | 0 /* cq_message_addr */); | ||
401 | } | ||
402 | |||
403 | /* | ||
404 | * Init INTR resources | ||
405 | * | ||
406 | * mask_on_assertion is not used for INTx due to the level- | ||
407 | * triggered nature of INTx | ||
408 | */ | ||
409 | |||
410 | switch (intr_mode) { | ||
411 | case VNIC_DEV_INTR_MODE_MSI: | ||
412 | case VNIC_DEV_INTR_MODE_MSIX: | ||
413 | mask_on_assertion = 1; | ||
414 | break; | ||
415 | default: | ||
416 | mask_on_assertion = 0; | ||
417 | break; | ||
418 | } | ||
419 | |||
420 | for (i = 0; i < fnic->intr_count; i++) { | ||
421 | vnic_intr_init(&fnic->intr[i], | ||
422 | fnic->config.intr_timer, | ||
423 | fnic->config.intr_timer_type, | ||
424 | mask_on_assertion); | ||
425 | } | ||
426 | |||
427 | /* init the stats memory by making the first call here */ | ||
428 | err = vnic_dev_stats_dump(fnic->vdev, &fnic->stats); | ||
429 | if (err) { | ||
430 | shost_printk(KERN_ERR, fnic->lport->host, | ||
431 | "vnic_dev_stats_dump failed - x%x\n", err); | ||
432 | goto err_out_cleanup; | ||
433 | } | ||
434 | |||
435 | /* Clear LIF stats */ | ||
436 | vnic_dev_stats_clear(fnic->vdev); | ||
437 | |||
438 | return 0; | ||
439 | |||
440 | err_out_cleanup: | ||
441 | fnic_free_vnic_resources(fnic); | ||
442 | |||
443 | return err; | ||
444 | } | ||
diff --git a/drivers/scsi/fnic/fnic_res.h b/drivers/scsi/fnic/fnic_res.h new file mode 100644 index 000000000000..b6f310262534 --- /dev/null +++ b/drivers/scsi/fnic/fnic_res.h | |||
@@ -0,0 +1,197 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _FNIC_RES_H_ | ||
19 | #define _FNIC_RES_H_ | ||
20 | |||
21 | #include "wq_enet_desc.h" | ||
22 | #include "rq_enet_desc.h" | ||
23 | #include "vnic_wq.h" | ||
24 | #include "vnic_rq.h" | ||
25 | #include "fnic_io.h" | ||
26 | #include "fcpio.h" | ||
27 | #include "vnic_wq_copy.h" | ||
28 | #include "vnic_cq_copy.h" | ||
29 | |||
30 | static inline void fnic_queue_wq_desc(struct vnic_wq *wq, | ||
31 | void *os_buf, dma_addr_t dma_addr, | ||
32 | unsigned int len, unsigned int fc_eof, | ||
33 | int vlan_tag_insert, | ||
34 | unsigned int vlan_tag, | ||
35 | int cq_entry, int sop, int eop) | ||
36 | { | ||
37 | struct wq_enet_desc *desc = vnic_wq_next_desc(wq); | ||
38 | |||
39 | wq_enet_desc_enc(desc, | ||
40 | (u64)dma_addr | VNIC_PADDR_TARGET, | ||
41 | (u16)len, | ||
42 | 0, /* mss_or_csum_offset */ | ||
43 | (u16)fc_eof, | ||
44 | 0, /* offload_mode */ | ||
45 | (u8)eop, (u8)cq_entry, | ||
46 | 1, /* fcoe_encap */ | ||
47 | (u8)vlan_tag_insert, | ||
48 | (u16)vlan_tag, | ||
49 | 0 /* loopback */); | ||
50 | |||
51 | vnic_wq_post(wq, os_buf, dma_addr, len, sop, eop); | ||
52 | } | ||
53 | |||
54 | static inline void fnic_queue_wq_copy_desc_icmnd_16(struct vnic_wq_copy *wq, | ||
55 | u32 req_id, | ||
56 | u32 lunmap_id, u8 spl_flags, | ||
57 | u32 sgl_cnt, u32 sense_len, | ||
58 | u64 sgl_addr, u64 sns_addr, | ||
59 | u8 crn, u8 pri_ta, | ||
60 | u8 flags, u8 *scsi_cdb, | ||
61 | u32 data_len, u8 *lun, | ||
62 | u32 d_id, u16 mss, | ||
63 | u32 ratov, u32 edtov) | ||
64 | { | ||
65 | struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq); | ||
66 | |||
67 | desc->hdr.type = FCPIO_ICMND_16; /* enum fcpio_type */ | ||
68 | desc->hdr.status = 0; /* header status entry */ | ||
69 | desc->hdr._resvd = 0; /* reserved */ | ||
70 | desc->hdr.tag.u.req_id = req_id; /* id for this request */ | ||
71 | |||
72 | desc->u.icmnd_16.lunmap_id = lunmap_id; /* index into lunmap table */ | ||
73 | desc->u.icmnd_16.special_req_flags = spl_flags; /* exch req flags */ | ||
74 | desc->u.icmnd_16._resvd0[0] = 0; /* reserved */ | ||
75 | desc->u.icmnd_16._resvd0[1] = 0; /* reserved */ | ||
76 | desc->u.icmnd_16._resvd0[2] = 0; /* reserved */ | ||
77 | desc->u.icmnd_16.sgl_cnt = sgl_cnt; /* scatter-gather list count */ | ||
78 | desc->u.icmnd_16.sense_len = sense_len; /* sense buffer length */ | ||
79 | desc->u.icmnd_16.sgl_addr = sgl_addr; /* scatter-gather list addr */ | ||
80 | desc->u.icmnd_16.sense_addr = sns_addr; /* sense buffer address */ | ||
81 | desc->u.icmnd_16.crn = crn; /* SCSI Command Reference No.*/ | ||
82 | desc->u.icmnd_16.pri_ta = pri_ta; /* SCSI Pri & Task attribute */ | ||
83 | desc->u.icmnd_16._resvd1 = 0; /* reserved: should be 0 */ | ||
84 | desc->u.icmnd_16.flags = flags; /* command flags */ | ||
85 | memcpy(desc->u.icmnd_16.scsi_cdb, scsi_cdb, CDB_16); /* SCSI CDB */ | ||
86 | desc->u.icmnd_16.data_len = data_len; /* length of data expected */ | ||
87 | memcpy(desc->u.icmnd_16.lun, lun, LUN_ADDRESS); /* LUN address */ | ||
88 | desc->u.icmnd_16._resvd2 = 0; /* reserved */ | ||
89 | hton24(desc->u.icmnd_16.d_id, d_id); /* FC vNIC only: Target D_ID */ | ||
90 | desc->u.icmnd_16.mss = mss; /* FC vNIC only: max burst */ | ||
91 | desc->u.icmnd_16.r_a_tov = ratov; /*FC vNIC only: Res. Alloc Timeout */ | ||
92 | desc->u.icmnd_16.e_d_tov = edtov; /*FC vNIC only: Err Detect Timeout */ | ||
93 | |||
94 | vnic_wq_copy_post(wq); | ||
95 | } | ||
96 | |||
97 | static inline void fnic_queue_wq_copy_desc_itmf(struct vnic_wq_copy *wq, | ||
98 | u32 req_id, u32 lunmap_id, | ||
99 | u32 tm_req, u32 tm_id, u8 *lun, | ||
100 | u32 d_id, u32 r_a_tov, | ||
101 | u32 e_d_tov) | ||
102 | { | ||
103 | struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq); | ||
104 | |||
105 | desc->hdr.type = FCPIO_ITMF; /* enum fcpio_type */ | ||
106 | desc->hdr.status = 0; /* header status entry */ | ||
107 | desc->hdr._resvd = 0; /* reserved */ | ||
108 | desc->hdr.tag.u.req_id = req_id; /* id for this request */ | ||
109 | |||
110 | desc->u.itmf.lunmap_id = lunmap_id; /* index into lunmap table */ | ||
111 | desc->u.itmf.tm_req = tm_req; /* SCSI Task Management request */ | ||
112 | desc->u.itmf.t_tag = tm_id; /* tag of fcpio to be aborted */ | ||
113 | desc->u.itmf._resvd = 0; | ||
114 | memcpy(desc->u.itmf.lun, lun, LUN_ADDRESS); /* LUN address */ | ||
115 | desc->u.itmf._resvd1 = 0; | ||
116 | hton24(desc->u.itmf.d_id, d_id); /* FC vNIC only: Target D_ID */ | ||
117 | desc->u.itmf.r_a_tov = r_a_tov; /* FC vNIC only: R_A_TOV in msec */ | ||
118 | desc->u.itmf.e_d_tov = e_d_tov; /* FC vNIC only: E_D_TOV in msec */ | ||
119 | |||
120 | vnic_wq_copy_post(wq); | ||
121 | } | ||
122 | |||
123 | static inline void fnic_queue_wq_copy_desc_flogi_reg(struct vnic_wq_copy *wq, | ||
124 | u32 req_id, u8 format, | ||
125 | u32 s_id, u8 *gw_mac) | ||
126 | { | ||
127 | struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq); | ||
128 | |||
129 | desc->hdr.type = FCPIO_FLOGI_REG; /* enum fcpio_type */ | ||
130 | desc->hdr.status = 0; /* header status entry */ | ||
131 | desc->hdr._resvd = 0; /* reserved */ | ||
132 | desc->hdr.tag.u.req_id = req_id; /* id for this request */ | ||
133 | |||
134 | desc->u.flogi_reg.format = format; | ||
135 | hton24(desc->u.flogi_reg.s_id, s_id); | ||
136 | memcpy(desc->u.flogi_reg.gateway_mac, gw_mac, ETH_ALEN); | ||
137 | |||
138 | vnic_wq_copy_post(wq); | ||
139 | } | ||
140 | |||
141 | static inline void fnic_queue_wq_copy_desc_fw_reset(struct vnic_wq_copy *wq, | ||
142 | u32 req_id) | ||
143 | { | ||
144 | struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq); | ||
145 | |||
146 | desc->hdr.type = FCPIO_RESET; /* enum fcpio_type */ | ||
147 | desc->hdr.status = 0; /* header status entry */ | ||
148 | desc->hdr._resvd = 0; /* reserved */ | ||
149 | desc->hdr.tag.u.req_id = req_id; /* id for this request */ | ||
150 | |||
151 | vnic_wq_copy_post(wq); | ||
152 | } | ||
153 | |||
154 | static inline void fnic_queue_wq_copy_desc_lunmap(struct vnic_wq_copy *wq, | ||
155 | u32 req_id, u64 lunmap_addr, | ||
156 | u32 lunmap_len) | ||
157 | { | ||
158 | struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq); | ||
159 | |||
160 | desc->hdr.type = FCPIO_LUNMAP_REQ; /* enum fcpio_type */ | ||
161 | desc->hdr.status = 0; /* header status entry */ | ||
162 | desc->hdr._resvd = 0; /* reserved */ | ||
163 | desc->hdr.tag.u.req_id = req_id; /* id for this request */ | ||
164 | |||
165 | desc->u.lunmap_req.addr = lunmap_addr; /* address of the buffer */ | ||
166 | desc->u.lunmap_req.len = lunmap_len; /* len of the buffer */ | ||
167 | |||
168 | vnic_wq_copy_post(wq); | ||
169 | } | ||
170 | |||
171 | static inline void fnic_queue_rq_desc(struct vnic_rq *rq, | ||
172 | void *os_buf, dma_addr_t dma_addr, | ||
173 | u16 len) | ||
174 | { | ||
175 | struct rq_enet_desc *desc = vnic_rq_next_desc(rq); | ||
176 | |||
177 | rq_enet_desc_enc(desc, | ||
178 | (u64)dma_addr | VNIC_PADDR_TARGET, | ||
179 | RQ_ENET_TYPE_ONLY_SOP, | ||
180 | (u16)len); | ||
181 | |||
182 | vnic_rq_post(rq, os_buf, 0, dma_addr, len); | ||
183 | } | ||
184 | |||
185 | |||
186 | struct fnic; | ||
187 | |||
188 | int fnic_get_vnic_config(struct fnic *); | ||
189 | int fnic_alloc_vnic_resources(struct fnic *); | ||
190 | void fnic_free_vnic_resources(struct fnic *); | ||
191 | void fnic_get_res_counts(struct fnic *); | ||
192 | int fnic_set_nic_config(struct fnic *fnic, u8 rss_default_cpu, | ||
193 | u8 rss_hash_type, u8 rss_hash_bits, u8 rss_base_cpu, | ||
194 | u8 rss_enable, u8 tso_ipid_split_en, | ||
195 | u8 ig_vlan_strip_en); | ||
196 | |||
197 | #endif /* _FNIC_RES_H_ */ | ||
diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c new file mode 100644 index 000000000000..eabf36502856 --- /dev/null +++ b/drivers/scsi/fnic/fnic_scsi.c | |||
@@ -0,0 +1,1850 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #include <linux/mempool.h> | ||
19 | #include <linux/errno.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/workqueue.h> | ||
22 | #include <linux/pci.h> | ||
23 | #include <linux/scatterlist.h> | ||
24 | #include <linux/skbuff.h> | ||
25 | #include <linux/spinlock.h> | ||
26 | #include <linux/if_ether.h> | ||
27 | #include <linux/if_vlan.h> | ||
28 | #include <linux/delay.h> | ||
29 | #include <scsi/scsi.h> | ||
30 | #include <scsi/scsi_host.h> | ||
31 | #include <scsi/scsi_device.h> | ||
32 | #include <scsi/scsi_cmnd.h> | ||
33 | #include <scsi/scsi_tcq.h> | ||
34 | #include <scsi/fc/fc_els.h> | ||
35 | #include <scsi/fc/fc_fcoe.h> | ||
36 | #include <scsi/libfc.h> | ||
37 | #include <scsi/fc_frame.h> | ||
38 | #include "fnic_io.h" | ||
39 | #include "fnic.h" | ||
40 | |||
41 | const char *fnic_state_str[] = { | ||
42 | [FNIC_IN_FC_MODE] = "FNIC_IN_FC_MODE", | ||
43 | [FNIC_IN_FC_TRANS_ETH_MODE] = "FNIC_IN_FC_TRANS_ETH_MODE", | ||
44 | [FNIC_IN_ETH_MODE] = "FNIC_IN_ETH_MODE", | ||
45 | [FNIC_IN_ETH_TRANS_FC_MODE] = "FNIC_IN_ETH_TRANS_FC_MODE", | ||
46 | }; | ||
47 | |||
48 | static const char *fnic_ioreq_state_str[] = { | ||
49 | [FNIC_IOREQ_CMD_PENDING] = "FNIC_IOREQ_CMD_PENDING", | ||
50 | [FNIC_IOREQ_ABTS_PENDING] = "FNIC_IOREQ_ABTS_PENDING", | ||
51 | [FNIC_IOREQ_ABTS_COMPLETE] = "FNIC_IOREQ_ABTS_COMPLETE", | ||
52 | [FNIC_IOREQ_CMD_COMPLETE] = "FNIC_IOREQ_CMD_COMPLETE", | ||
53 | }; | ||
54 | |||
55 | static const char *fcpio_status_str[] = { | ||
56 | [FCPIO_SUCCESS] = "FCPIO_SUCCESS", /*0x0*/ | ||
57 | [FCPIO_INVALID_HEADER] = "FCPIO_INVALID_HEADER", | ||
58 | [FCPIO_OUT_OF_RESOURCE] = "FCPIO_OUT_OF_RESOURCE", | ||
59 | [FCPIO_INVALID_PARAM] = "FCPIO_INVALID_PARAM]", | ||
60 | [FCPIO_REQ_NOT_SUPPORTED] = "FCPIO_REQ_NOT_SUPPORTED", | ||
61 | [FCPIO_IO_NOT_FOUND] = "FCPIO_IO_NOT_FOUND", | ||
62 | [FCPIO_ABORTED] = "FCPIO_ABORTED", /*0x41*/ | ||
63 | [FCPIO_TIMEOUT] = "FCPIO_TIMEOUT", | ||
64 | [FCPIO_SGL_INVALID] = "FCPIO_SGL_INVALID", | ||
65 | [FCPIO_MSS_INVALID] = "FCPIO_MSS_INVALID", | ||
66 | [FCPIO_DATA_CNT_MISMATCH] = "FCPIO_DATA_CNT_MISMATCH", | ||
67 | [FCPIO_FW_ERR] = "FCPIO_FW_ERR", | ||
68 | [FCPIO_ITMF_REJECTED] = "FCPIO_ITMF_REJECTED", | ||
69 | [FCPIO_ITMF_FAILED] = "FCPIO_ITMF_FAILED", | ||
70 | [FCPIO_ITMF_INCORRECT_LUN] = "FCPIO_ITMF_INCORRECT_LUN", | ||
71 | [FCPIO_CMND_REJECTED] = "FCPIO_CMND_REJECTED", | ||
72 | [FCPIO_NO_PATH_AVAIL] = "FCPIO_NO_PATH_AVAIL", | ||
73 | [FCPIO_PATH_FAILED] = "FCPIO_PATH_FAILED", | ||
74 | [FCPIO_LUNMAP_CHNG_PEND] = "FCPIO_LUNHMAP_CHNG_PEND", | ||
75 | }; | ||
76 | |||
77 | const char *fnic_state_to_str(unsigned int state) | ||
78 | { | ||
79 | if (state >= ARRAY_SIZE(fnic_state_str) || !fnic_state_str[state]) | ||
80 | return "unknown"; | ||
81 | |||
82 | return fnic_state_str[state]; | ||
83 | } | ||
84 | |||
85 | static const char *fnic_ioreq_state_to_str(unsigned int state) | ||
86 | { | ||
87 | if (state >= ARRAY_SIZE(fnic_ioreq_state_str) || | ||
88 | !fnic_ioreq_state_str[state]) | ||
89 | return "unknown"; | ||
90 | |||
91 | return fnic_ioreq_state_str[state]; | ||
92 | } | ||
93 | |||
94 | static const char *fnic_fcpio_status_to_str(unsigned int status) | ||
95 | { | ||
96 | if (status >= ARRAY_SIZE(fcpio_status_str) || !fcpio_status_str[status]) | ||
97 | return "unknown"; | ||
98 | |||
99 | return fcpio_status_str[status]; | ||
100 | } | ||
101 | |||
102 | static void fnic_cleanup_io(struct fnic *fnic, int exclude_id); | ||
103 | |||
104 | static inline spinlock_t *fnic_io_lock_hash(struct fnic *fnic, | ||
105 | struct scsi_cmnd *sc) | ||
106 | { | ||
107 | u32 hash = sc->request->tag & (FNIC_IO_LOCKS - 1); | ||
108 | |||
109 | return &fnic->io_req_lock[hash]; | ||
110 | } | ||
111 | |||
112 | /* | ||
113 | * Unmap the data buffer and sense buffer for an io_req, | ||
114 | * also unmap and free the device-private scatter/gather list. | ||
115 | */ | ||
116 | static void fnic_release_ioreq_buf(struct fnic *fnic, | ||
117 | struct fnic_io_req *io_req, | ||
118 | struct scsi_cmnd *sc) | ||
119 | { | ||
120 | if (io_req->sgl_list_pa) | ||
121 | pci_unmap_single(fnic->pdev, io_req->sgl_list_pa, | ||
122 | sizeof(io_req->sgl_list[0]) * io_req->sgl_cnt, | ||
123 | PCI_DMA_TODEVICE); | ||
124 | scsi_dma_unmap(sc); | ||
125 | |||
126 | if (io_req->sgl_cnt) | ||
127 | mempool_free(io_req->sgl_list_alloc, | ||
128 | fnic->io_sgl_pool[io_req->sgl_type]); | ||
129 | if (io_req->sense_buf_pa) | ||
130 | pci_unmap_single(fnic->pdev, io_req->sense_buf_pa, | ||
131 | SCSI_SENSE_BUFFERSIZE, PCI_DMA_FROMDEVICE); | ||
132 | } | ||
133 | |||
134 | /* Free up Copy Wq descriptors. Called with copy_wq lock held */ | ||
135 | static int free_wq_copy_descs(struct fnic *fnic, struct vnic_wq_copy *wq) | ||
136 | { | ||
137 | /* if no Ack received from firmware, then nothing to clean */ | ||
138 | if (!fnic->fw_ack_recd[0]) | ||
139 | return 1; | ||
140 | |||
141 | /* | ||
142 | * Update desc_available count based on number of freed descriptors | ||
143 | * Account for wraparound | ||
144 | */ | ||
145 | if (wq->to_clean_index <= fnic->fw_ack_index[0]) | ||
146 | wq->ring.desc_avail += (fnic->fw_ack_index[0] | ||
147 | - wq->to_clean_index + 1); | ||
148 | else | ||
149 | wq->ring.desc_avail += (wq->ring.desc_count | ||
150 | - wq->to_clean_index | ||
151 | + fnic->fw_ack_index[0] + 1); | ||
152 | |||
153 | /* | ||
154 | * just bump clean index to ack_index+1 accounting for wraparound | ||
155 | * this will essentially free up all descriptors between | ||
156 | * to_clean_index and fw_ack_index, both inclusive | ||
157 | */ | ||
158 | wq->to_clean_index = | ||
159 | (fnic->fw_ack_index[0] + 1) % wq->ring.desc_count; | ||
160 | |||
161 | /* we have processed the acks received so far */ | ||
162 | fnic->fw_ack_recd[0] = 0; | ||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | |||
167 | /* | ||
168 | * fnic_fw_reset_handler | ||
169 | * Routine to send reset msg to fw | ||
170 | */ | ||
171 | int fnic_fw_reset_handler(struct fnic *fnic) | ||
172 | { | ||
173 | struct vnic_wq_copy *wq = &fnic->wq_copy[0]; | ||
174 | int ret = 0; | ||
175 | unsigned long flags; | ||
176 | |||
177 | spin_lock_irqsave(&fnic->wq_copy_lock[0], flags); | ||
178 | |||
179 | if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0]) | ||
180 | free_wq_copy_descs(fnic, wq); | ||
181 | |||
182 | if (!vnic_wq_copy_desc_avail(wq)) | ||
183 | ret = -EAGAIN; | ||
184 | else | ||
185 | fnic_queue_wq_copy_desc_fw_reset(wq, SCSI_NO_TAG); | ||
186 | |||
187 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags); | ||
188 | |||
189 | if (!ret) | ||
190 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
191 | "Issued fw reset\n"); | ||
192 | else | ||
193 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
194 | "Failed to issue fw reset\n"); | ||
195 | return ret; | ||
196 | } | ||
197 | |||
198 | |||
199 | /* | ||
200 | * fnic_flogi_reg_handler | ||
201 | * Routine to send flogi register msg to fw | ||
202 | */ | ||
203 | int fnic_flogi_reg_handler(struct fnic *fnic) | ||
204 | { | ||
205 | struct vnic_wq_copy *wq = &fnic->wq_copy[0]; | ||
206 | u8 gw_mac[ETH_ALEN]; | ||
207 | int ret = 0; | ||
208 | unsigned long flags; | ||
209 | |||
210 | spin_lock_irqsave(&fnic->wq_copy_lock[0], flags); | ||
211 | |||
212 | if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0]) | ||
213 | free_wq_copy_descs(fnic, wq); | ||
214 | |||
215 | if (!vnic_wq_copy_desc_avail(wq)) { | ||
216 | ret = -EAGAIN; | ||
217 | goto flogi_reg_ioreq_end; | ||
218 | } | ||
219 | |||
220 | if (fnic->fcoui_mode) | ||
221 | memset(gw_mac, 0xff, ETH_ALEN); | ||
222 | else | ||
223 | memcpy(gw_mac, fnic->dest_addr, ETH_ALEN); | ||
224 | |||
225 | fnic_queue_wq_copy_desc_flogi_reg(wq, SCSI_NO_TAG, | ||
226 | FCPIO_FLOGI_REG_GW_DEST, | ||
227 | fnic->s_id, | ||
228 | gw_mac); | ||
229 | |||
230 | flogi_reg_ioreq_end: | ||
231 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags); | ||
232 | |||
233 | if (!ret) | ||
234 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
235 | "flog reg issued\n"); | ||
236 | |||
237 | return ret; | ||
238 | } | ||
239 | |||
240 | /* | ||
241 | * fnic_queue_wq_copy_desc | ||
242 | * Routine to enqueue a wq copy desc | ||
243 | */ | ||
244 | static inline int fnic_queue_wq_copy_desc(struct fnic *fnic, | ||
245 | struct vnic_wq_copy *wq, | ||
246 | struct fnic_io_req *io_req, | ||
247 | struct scsi_cmnd *sc, | ||
248 | u32 sg_count) | ||
249 | { | ||
250 | struct scatterlist *sg; | ||
251 | struct fc_rport *rport = starget_to_rport(scsi_target(sc->device)); | ||
252 | struct fc_rport_libfc_priv *rp = rport->dd_data; | ||
253 | struct host_sg_desc *desc; | ||
254 | u8 pri_tag = 0; | ||
255 | unsigned int i; | ||
256 | unsigned long intr_flags; | ||
257 | int flags; | ||
258 | u8 exch_flags; | ||
259 | struct scsi_lun fc_lun; | ||
260 | char msg[2]; | ||
261 | |||
262 | if (sg_count) { | ||
263 | BUG_ON(sg_count < 0); | ||
264 | BUG_ON(sg_count > FNIC_MAX_SG_DESC_CNT); | ||
265 | |||
266 | /* For each SGE, create a device desc entry */ | ||
267 | desc = io_req->sgl_list; | ||
268 | for_each_sg(scsi_sglist(sc), sg, sg_count, i) { | ||
269 | desc->addr = cpu_to_le64(sg_dma_address(sg)); | ||
270 | desc->len = cpu_to_le32(sg_dma_len(sg)); | ||
271 | desc->_resvd = 0; | ||
272 | desc++; | ||
273 | } | ||
274 | |||
275 | io_req->sgl_list_pa = pci_map_single | ||
276 | (fnic->pdev, | ||
277 | io_req->sgl_list, | ||
278 | sizeof(io_req->sgl_list[0]) * sg_count, | ||
279 | PCI_DMA_TODEVICE); | ||
280 | } | ||
281 | |||
282 | io_req->sense_buf_pa = pci_map_single(fnic->pdev, | ||
283 | sc->sense_buffer, | ||
284 | SCSI_SENSE_BUFFERSIZE, | ||
285 | PCI_DMA_FROMDEVICE); | ||
286 | |||
287 | int_to_scsilun(sc->device->lun, &fc_lun); | ||
288 | |||
289 | pri_tag = FCPIO_ICMND_PTA_SIMPLE; | ||
290 | msg[0] = MSG_SIMPLE_TAG; | ||
291 | scsi_populate_tag_msg(sc, msg); | ||
292 | if (msg[0] == MSG_ORDERED_TAG) | ||
293 | pri_tag = FCPIO_ICMND_PTA_ORDERED; | ||
294 | |||
295 | /* Enqueue the descriptor in the Copy WQ */ | ||
296 | spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags); | ||
297 | |||
298 | if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0]) | ||
299 | free_wq_copy_descs(fnic, wq); | ||
300 | |||
301 | if (unlikely(!vnic_wq_copy_desc_avail(wq))) { | ||
302 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], intr_flags); | ||
303 | return SCSI_MLQUEUE_HOST_BUSY; | ||
304 | } | ||
305 | |||
306 | flags = 0; | ||
307 | if (sc->sc_data_direction == DMA_FROM_DEVICE) | ||
308 | flags = FCPIO_ICMND_RDDATA; | ||
309 | else if (sc->sc_data_direction == DMA_TO_DEVICE) | ||
310 | flags = FCPIO_ICMND_WRDATA; | ||
311 | |||
312 | exch_flags = 0; | ||
313 | if ((fnic->config.flags & VFCF_FCP_SEQ_LVL_ERR) && | ||
314 | (rp->flags & FC_RP_FLAGS_RETRY)) | ||
315 | exch_flags |= FCPIO_ICMND_SRFLAG_RETRY; | ||
316 | |||
317 | fnic_queue_wq_copy_desc_icmnd_16(wq, sc->request->tag, | ||
318 | 0, exch_flags, io_req->sgl_cnt, | ||
319 | SCSI_SENSE_BUFFERSIZE, | ||
320 | io_req->sgl_list_pa, | ||
321 | io_req->sense_buf_pa, | ||
322 | 0, /* scsi cmd ref, always 0 */ | ||
323 | pri_tag, /* scsi pri and tag */ | ||
324 | flags, /* command flags */ | ||
325 | sc->cmnd, scsi_bufflen(sc), | ||
326 | fc_lun.scsi_lun, io_req->port_id, | ||
327 | rport->maxframe_size, rp->r_a_tov, | ||
328 | rp->e_d_tov); | ||
329 | |||
330 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], intr_flags); | ||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | /* | ||
335 | * fnic_queuecommand | ||
336 | * Routine to send a scsi cdb | ||
337 | * Called with host_lock held and interrupts disabled. | ||
338 | */ | ||
339 | int fnic_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *)) | ||
340 | { | ||
341 | struct fc_lport *lp; | ||
342 | struct fc_rport *rport; | ||
343 | struct fnic_io_req *io_req; | ||
344 | struct fnic *fnic; | ||
345 | struct vnic_wq_copy *wq; | ||
346 | int ret; | ||
347 | u32 sg_count; | ||
348 | unsigned long flags; | ||
349 | unsigned long ptr; | ||
350 | |||
351 | rport = starget_to_rport(scsi_target(sc->device)); | ||
352 | ret = fc_remote_port_chkready(rport); | ||
353 | if (ret) { | ||
354 | sc->result = ret; | ||
355 | done(sc); | ||
356 | return 0; | ||
357 | } | ||
358 | |||
359 | lp = shost_priv(sc->device->host); | ||
360 | if (lp->state != LPORT_ST_READY || !(lp->link_up)) | ||
361 | return SCSI_MLQUEUE_HOST_BUSY; | ||
362 | |||
363 | /* | ||
364 | * Release host lock, use driver resource specific locks from here. | ||
365 | * Don't re-enable interrupts in case they were disabled prior to the | ||
366 | * caller disabling them. | ||
367 | */ | ||
368 | spin_unlock(lp->host->host_lock); | ||
369 | |||
370 | /* Get a new io_req for this SCSI IO */ | ||
371 | fnic = lport_priv(lp); | ||
372 | |||
373 | io_req = mempool_alloc(fnic->io_req_pool, GFP_ATOMIC); | ||
374 | if (!io_req) { | ||
375 | ret = SCSI_MLQUEUE_HOST_BUSY; | ||
376 | goto out; | ||
377 | } | ||
378 | memset(io_req, 0, sizeof(*io_req)); | ||
379 | |||
380 | /* Map the data buffer */ | ||
381 | sg_count = scsi_dma_map(sc); | ||
382 | if (sg_count < 0) { | ||
383 | mempool_free(io_req, fnic->io_req_pool); | ||
384 | goto out; | ||
385 | } | ||
386 | |||
387 | /* Determine the type of scatter/gather list we need */ | ||
388 | io_req->sgl_cnt = sg_count; | ||
389 | io_req->sgl_type = FNIC_SGL_CACHE_DFLT; | ||
390 | if (sg_count > FNIC_DFLT_SG_DESC_CNT) | ||
391 | io_req->sgl_type = FNIC_SGL_CACHE_MAX; | ||
392 | |||
393 | if (sg_count) { | ||
394 | io_req->sgl_list = | ||
395 | mempool_alloc(fnic->io_sgl_pool[io_req->sgl_type], | ||
396 | GFP_ATOMIC | GFP_DMA); | ||
397 | if (!io_req->sgl_list) { | ||
398 | ret = SCSI_MLQUEUE_HOST_BUSY; | ||
399 | scsi_dma_unmap(sc); | ||
400 | mempool_free(io_req, fnic->io_req_pool); | ||
401 | goto out; | ||
402 | } | ||
403 | |||
404 | /* Cache sgl list allocated address before alignment */ | ||
405 | io_req->sgl_list_alloc = io_req->sgl_list; | ||
406 | ptr = (unsigned long) io_req->sgl_list; | ||
407 | if (ptr % FNIC_SG_DESC_ALIGN) { | ||
408 | io_req->sgl_list = (struct host_sg_desc *) | ||
409 | (((unsigned long) ptr | ||
410 | + FNIC_SG_DESC_ALIGN - 1) | ||
411 | & ~(FNIC_SG_DESC_ALIGN - 1)); | ||
412 | } | ||
413 | } | ||
414 | |||
415 | /* initialize rest of io_req */ | ||
416 | io_req->port_id = rport->port_id; | ||
417 | CMD_STATE(sc) = FNIC_IOREQ_CMD_PENDING; | ||
418 | CMD_SP(sc) = (char *)io_req; | ||
419 | sc->scsi_done = done; | ||
420 | |||
421 | /* create copy wq desc and enqueue it */ | ||
422 | wq = &fnic->wq_copy[0]; | ||
423 | ret = fnic_queue_wq_copy_desc(fnic, wq, io_req, sc, sg_count); | ||
424 | if (ret) { | ||
425 | /* | ||
426 | * In case another thread cancelled the request, | ||
427 | * refetch the pointer under the lock. | ||
428 | */ | ||
429 | spinlock_t *io_lock = fnic_io_lock_hash(fnic, sc); | ||
430 | |||
431 | spin_lock_irqsave(io_lock, flags); | ||
432 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
433 | CMD_SP(sc) = NULL; | ||
434 | CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE; | ||
435 | spin_unlock_irqrestore(io_lock, flags); | ||
436 | if (io_req) { | ||
437 | fnic_release_ioreq_buf(fnic, io_req, sc); | ||
438 | mempool_free(io_req, fnic->io_req_pool); | ||
439 | } | ||
440 | } | ||
441 | out: | ||
442 | /* acquire host lock before returning to SCSI */ | ||
443 | spin_lock(lp->host->host_lock); | ||
444 | return ret; | ||
445 | } | ||
446 | |||
447 | /* | ||
448 | * fnic_fcpio_fw_reset_cmpl_handler | ||
449 | * Routine to handle fw reset completion | ||
450 | */ | ||
451 | static int fnic_fcpio_fw_reset_cmpl_handler(struct fnic *fnic, | ||
452 | struct fcpio_fw_req *desc) | ||
453 | { | ||
454 | u8 type; | ||
455 | u8 hdr_status; | ||
456 | struct fcpio_tag tag; | ||
457 | int ret = 0; | ||
458 | struct fc_frame *flogi; | ||
459 | unsigned long flags; | ||
460 | |||
461 | fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag); | ||
462 | |||
463 | /* Clean up all outstanding io requests */ | ||
464 | fnic_cleanup_io(fnic, SCSI_NO_TAG); | ||
465 | |||
466 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
467 | |||
468 | flogi = fnic->flogi; | ||
469 | fnic->flogi = NULL; | ||
470 | |||
471 | /* fnic should be in FC_TRANS_ETH_MODE */ | ||
472 | if (fnic->state == FNIC_IN_FC_TRANS_ETH_MODE) { | ||
473 | /* Check status of reset completion */ | ||
474 | if (!hdr_status) { | ||
475 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
476 | "reset cmpl success\n"); | ||
477 | /* Ready to send flogi out */ | ||
478 | fnic->state = FNIC_IN_ETH_MODE; | ||
479 | } else { | ||
480 | FNIC_SCSI_DBG(KERN_DEBUG, | ||
481 | fnic->lport->host, | ||
482 | "fnic fw_reset : failed %s\n", | ||
483 | fnic_fcpio_status_to_str(hdr_status)); | ||
484 | |||
485 | /* | ||
486 | * Unable to change to eth mode, cannot send out flogi | ||
487 | * Change state to fc mode, so that subsequent Flogi | ||
488 | * requests from libFC will cause more attempts to | ||
489 | * reset the firmware. Free the cached flogi | ||
490 | */ | ||
491 | fnic->state = FNIC_IN_FC_MODE; | ||
492 | ret = -1; | ||
493 | } | ||
494 | } else { | ||
495 | FNIC_SCSI_DBG(KERN_DEBUG, | ||
496 | fnic->lport->host, | ||
497 | "Unexpected state %s while processing" | ||
498 | " reset cmpl\n", fnic_state_to_str(fnic->state)); | ||
499 | ret = -1; | ||
500 | } | ||
501 | |||
502 | /* Thread removing device blocks till firmware reset is complete */ | ||
503 | if (fnic->remove_wait) | ||
504 | complete(fnic->remove_wait); | ||
505 | |||
506 | /* | ||
507 | * If fnic is being removed, or fw reset failed | ||
508 | * free the flogi frame. Else, send it out | ||
509 | */ | ||
510 | if (fnic->remove_wait || ret) { | ||
511 | fnic->flogi_oxid = FC_XID_UNKNOWN; | ||
512 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
513 | if (flogi) | ||
514 | dev_kfree_skb_irq(fp_skb(flogi)); | ||
515 | goto reset_cmpl_handler_end; | ||
516 | } | ||
517 | |||
518 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
519 | |||
520 | if (flogi) | ||
521 | ret = fnic_send_frame(fnic, flogi); | ||
522 | |||
523 | reset_cmpl_handler_end: | ||
524 | return ret; | ||
525 | } | ||
526 | |||
527 | /* | ||
528 | * fnic_fcpio_flogi_reg_cmpl_handler | ||
529 | * Routine to handle flogi register completion | ||
530 | */ | ||
531 | static int fnic_fcpio_flogi_reg_cmpl_handler(struct fnic *fnic, | ||
532 | struct fcpio_fw_req *desc) | ||
533 | { | ||
534 | u8 type; | ||
535 | u8 hdr_status; | ||
536 | struct fcpio_tag tag; | ||
537 | int ret = 0; | ||
538 | struct fc_frame *flogi_resp = NULL; | ||
539 | unsigned long flags; | ||
540 | struct sk_buff *skb; | ||
541 | |||
542 | fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag); | ||
543 | |||
544 | /* Update fnic state based on status of flogi reg completion */ | ||
545 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
546 | |||
547 | flogi_resp = fnic->flogi_resp; | ||
548 | fnic->flogi_resp = NULL; | ||
549 | |||
550 | if (fnic->state == FNIC_IN_ETH_TRANS_FC_MODE) { | ||
551 | |||
552 | /* Check flogi registration completion status */ | ||
553 | if (!hdr_status) { | ||
554 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
555 | "flog reg succeeded\n"); | ||
556 | fnic->state = FNIC_IN_FC_MODE; | ||
557 | } else { | ||
558 | FNIC_SCSI_DBG(KERN_DEBUG, | ||
559 | fnic->lport->host, | ||
560 | "fnic flogi reg :failed %s\n", | ||
561 | fnic_fcpio_status_to_str(hdr_status)); | ||
562 | fnic->state = FNIC_IN_ETH_MODE; | ||
563 | ret = -1; | ||
564 | } | ||
565 | } else { | ||
566 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
567 | "Unexpected fnic state %s while" | ||
568 | " processing flogi reg completion\n", | ||
569 | fnic_state_to_str(fnic->state)); | ||
570 | ret = -1; | ||
571 | } | ||
572 | |||
573 | /* Successful flogi reg cmpl, pass frame to LibFC */ | ||
574 | if (!ret && flogi_resp) { | ||
575 | if (fnic->stop_rx_link_events) { | ||
576 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
577 | goto reg_cmpl_handler_end; | ||
578 | } | ||
579 | skb = (struct sk_buff *)flogi_resp; | ||
580 | /* Use fr_flags to indicate whether flogi resp or not */ | ||
581 | fr_flags(flogi_resp) = 1; | ||
582 | fr_dev(flogi_resp) = fnic->lport; | ||
583 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
584 | |||
585 | skb_queue_tail(&fnic->frame_queue, skb); | ||
586 | queue_work(fnic_event_queue, &fnic->frame_work); | ||
587 | |||
588 | } else { | ||
589 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
590 | if (flogi_resp) | ||
591 | dev_kfree_skb_irq(fp_skb(flogi_resp)); | ||
592 | } | ||
593 | |||
594 | reg_cmpl_handler_end: | ||
595 | return ret; | ||
596 | } | ||
597 | |||
598 | static inline int is_ack_index_in_range(struct vnic_wq_copy *wq, | ||
599 | u16 request_out) | ||
600 | { | ||
601 | if (wq->to_clean_index <= wq->to_use_index) { | ||
602 | /* out of range, stale request_out index */ | ||
603 | if (request_out < wq->to_clean_index || | ||
604 | request_out >= wq->to_use_index) | ||
605 | return 0; | ||
606 | } else { | ||
607 | /* out of range, stale request_out index */ | ||
608 | if (request_out < wq->to_clean_index && | ||
609 | request_out >= wq->to_use_index) | ||
610 | return 0; | ||
611 | } | ||
612 | /* request_out index is in range */ | ||
613 | return 1; | ||
614 | } | ||
615 | |||
616 | |||
617 | /* | ||
618 | * Mark that ack received and store the Ack index. If there are multiple | ||
619 | * acks received before Tx thread cleans it up, the latest value will be | ||
620 | * used which is correct behavior. This state should be in the copy Wq | ||
621 | * instead of in the fnic | ||
622 | */ | ||
623 | static inline void fnic_fcpio_ack_handler(struct fnic *fnic, | ||
624 | unsigned int cq_index, | ||
625 | struct fcpio_fw_req *desc) | ||
626 | { | ||
627 | struct vnic_wq_copy *wq; | ||
628 | u16 request_out = desc->u.ack.request_out; | ||
629 | unsigned long flags; | ||
630 | |||
631 | /* mark the ack state */ | ||
632 | wq = &fnic->wq_copy[cq_index - fnic->raw_wq_count - fnic->rq_count]; | ||
633 | spin_lock_irqsave(&fnic->wq_copy_lock[0], flags); | ||
634 | |||
635 | if (is_ack_index_in_range(wq, request_out)) { | ||
636 | fnic->fw_ack_index[0] = request_out; | ||
637 | fnic->fw_ack_recd[0] = 1; | ||
638 | } | ||
639 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags); | ||
640 | } | ||
641 | |||
642 | /* | ||
643 | * fnic_fcpio_icmnd_cmpl_handler | ||
644 | * Routine to handle icmnd completions | ||
645 | */ | ||
646 | static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, | ||
647 | struct fcpio_fw_req *desc) | ||
648 | { | ||
649 | u8 type; | ||
650 | u8 hdr_status; | ||
651 | struct fcpio_tag tag; | ||
652 | u32 id; | ||
653 | u64 xfer_len = 0; | ||
654 | struct fcpio_icmnd_cmpl *icmnd_cmpl; | ||
655 | struct fnic_io_req *io_req; | ||
656 | struct scsi_cmnd *sc; | ||
657 | unsigned long flags; | ||
658 | spinlock_t *io_lock; | ||
659 | |||
660 | /* Decode the cmpl description to get the io_req id */ | ||
661 | fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag); | ||
662 | fcpio_tag_id_dec(&tag, &id); | ||
663 | |||
664 | if (id >= FNIC_MAX_IO_REQ) | ||
665 | return; | ||
666 | |||
667 | sc = scsi_host_find_tag(fnic->lport->host, id); | ||
668 | WARN_ON_ONCE(!sc); | ||
669 | if (!sc) | ||
670 | return; | ||
671 | |||
672 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
673 | spin_lock_irqsave(io_lock, flags); | ||
674 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
675 | WARN_ON_ONCE(!io_req); | ||
676 | if (!io_req) { | ||
677 | spin_unlock_irqrestore(io_lock, flags); | ||
678 | return; | ||
679 | } | ||
680 | |||
681 | /* firmware completed the io */ | ||
682 | io_req->io_completed = 1; | ||
683 | |||
684 | /* | ||
685 | * if SCSI-ML has already issued abort on this command, | ||
686 | * ignore completion of the IO. The abts path will clean it up | ||
687 | */ | ||
688 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { | ||
689 | spin_unlock_irqrestore(io_lock, flags); | ||
690 | return; | ||
691 | } | ||
692 | |||
693 | /* Mark the IO as complete */ | ||
694 | CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE; | ||
695 | |||
696 | icmnd_cmpl = &desc->u.icmnd_cmpl; | ||
697 | |||
698 | switch (hdr_status) { | ||
699 | case FCPIO_SUCCESS: | ||
700 | sc->result = (DID_OK << 16) | icmnd_cmpl->scsi_status; | ||
701 | xfer_len = scsi_bufflen(sc); | ||
702 | scsi_set_resid(sc, icmnd_cmpl->residual); | ||
703 | |||
704 | if (icmnd_cmpl->flags & FCPIO_ICMND_CMPL_RESID_UNDER) | ||
705 | xfer_len -= icmnd_cmpl->residual; | ||
706 | |||
707 | /* | ||
708 | * If queue_full, then try to reduce queue depth for all | ||
709 | * LUNS on the target. Todo: this should be accompanied | ||
710 | * by a periodic queue_depth rampup based on successful | ||
711 | * IO completion. | ||
712 | */ | ||
713 | if (icmnd_cmpl->scsi_status == QUEUE_FULL) { | ||
714 | struct scsi_device *t_sdev; | ||
715 | int qd = 0; | ||
716 | |||
717 | shost_for_each_device(t_sdev, sc->device->host) { | ||
718 | if (t_sdev->id != sc->device->id) | ||
719 | continue; | ||
720 | |||
721 | if (t_sdev->queue_depth > 1) { | ||
722 | qd = scsi_track_queue_full | ||
723 | (t_sdev, | ||
724 | t_sdev->queue_depth - 1); | ||
725 | if (qd == -1) | ||
726 | qd = t_sdev->host->cmd_per_lun; | ||
727 | shost_printk(KERN_INFO, | ||
728 | fnic->lport->host, | ||
729 | "scsi[%d:%d:%d:%d" | ||
730 | "] queue full detected," | ||
731 | "new depth = %d\n", | ||
732 | t_sdev->host->host_no, | ||
733 | t_sdev->channel, | ||
734 | t_sdev->id, t_sdev->lun, | ||
735 | t_sdev->queue_depth); | ||
736 | } | ||
737 | } | ||
738 | } | ||
739 | break; | ||
740 | |||
741 | case FCPIO_TIMEOUT: /* request was timed out */ | ||
742 | sc->result = (DID_TIME_OUT << 16) | icmnd_cmpl->scsi_status; | ||
743 | break; | ||
744 | |||
745 | case FCPIO_ABORTED: /* request was aborted */ | ||
746 | sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status; | ||
747 | break; | ||
748 | |||
749 | case FCPIO_DATA_CNT_MISMATCH: /* recv/sent more/less data than exp. */ | ||
750 | scsi_set_resid(sc, icmnd_cmpl->residual); | ||
751 | sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status; | ||
752 | break; | ||
753 | |||
754 | case FCPIO_OUT_OF_RESOURCE: /* out of resources to complete request */ | ||
755 | sc->result = (DID_REQUEUE << 16) | icmnd_cmpl->scsi_status; | ||
756 | break; | ||
757 | case FCPIO_INVALID_HEADER: /* header contains invalid data */ | ||
758 | case FCPIO_INVALID_PARAM: /* some parameter in request invalid */ | ||
759 | case FCPIO_REQ_NOT_SUPPORTED:/* request type is not supported */ | ||
760 | case FCPIO_IO_NOT_FOUND: /* requested I/O was not found */ | ||
761 | case FCPIO_SGL_INVALID: /* request was aborted due to sgl error */ | ||
762 | case FCPIO_MSS_INVALID: /* request was aborted due to mss error */ | ||
763 | case FCPIO_FW_ERR: /* request was terminated due fw error */ | ||
764 | default: | ||
765 | shost_printk(KERN_ERR, fnic->lport->host, "hdr status = %s\n", | ||
766 | fnic_fcpio_status_to_str(hdr_status)); | ||
767 | sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status; | ||
768 | break; | ||
769 | } | ||
770 | |||
771 | /* Break link with the SCSI command */ | ||
772 | CMD_SP(sc) = NULL; | ||
773 | |||
774 | spin_unlock_irqrestore(io_lock, flags); | ||
775 | |||
776 | fnic_release_ioreq_buf(fnic, io_req, sc); | ||
777 | |||
778 | mempool_free(io_req, fnic->io_req_pool); | ||
779 | |||
780 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { | ||
781 | fnic->lport->host_stats.fcp_input_requests++; | ||
782 | fnic->fcp_input_bytes += xfer_len; | ||
783 | } else if (sc->sc_data_direction == DMA_TO_DEVICE) { | ||
784 | fnic->lport->host_stats.fcp_output_requests++; | ||
785 | fnic->fcp_output_bytes += xfer_len; | ||
786 | } else | ||
787 | fnic->lport->host_stats.fcp_control_requests++; | ||
788 | |||
789 | /* Call SCSI completion function to complete the IO */ | ||
790 | if (sc->scsi_done) | ||
791 | sc->scsi_done(sc); | ||
792 | |||
793 | } | ||
794 | |||
795 | /* fnic_fcpio_itmf_cmpl_handler | ||
796 | * Routine to handle itmf completions | ||
797 | */ | ||
798 | static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, | ||
799 | struct fcpio_fw_req *desc) | ||
800 | { | ||
801 | u8 type; | ||
802 | u8 hdr_status; | ||
803 | struct fcpio_tag tag; | ||
804 | u32 id; | ||
805 | struct scsi_cmnd *sc; | ||
806 | struct fnic_io_req *io_req; | ||
807 | unsigned long flags; | ||
808 | spinlock_t *io_lock; | ||
809 | |||
810 | fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag); | ||
811 | fcpio_tag_id_dec(&tag, &id); | ||
812 | |||
813 | if ((id & FNIC_TAG_MASK) >= FNIC_MAX_IO_REQ) | ||
814 | return; | ||
815 | |||
816 | sc = scsi_host_find_tag(fnic->lport->host, id & FNIC_TAG_MASK); | ||
817 | WARN_ON_ONCE(!sc); | ||
818 | if (!sc) | ||
819 | return; | ||
820 | |||
821 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
822 | spin_lock_irqsave(io_lock, flags); | ||
823 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
824 | WARN_ON_ONCE(!io_req); | ||
825 | if (!io_req) { | ||
826 | spin_unlock_irqrestore(io_lock, flags); | ||
827 | return; | ||
828 | } | ||
829 | |||
830 | if (id & FNIC_TAG_ABORT) { | ||
831 | /* Completion of abort cmd */ | ||
832 | if (CMD_STATE(sc) != FNIC_IOREQ_ABTS_PENDING) { | ||
833 | /* This is a late completion. Ignore it */ | ||
834 | spin_unlock_irqrestore(io_lock, flags); | ||
835 | return; | ||
836 | } | ||
837 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_COMPLETE; | ||
838 | CMD_ABTS_STATUS(sc) = hdr_status; | ||
839 | |||
840 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
841 | "abts cmpl recd. id %d status %s\n", | ||
842 | (int)(id & FNIC_TAG_MASK), | ||
843 | fnic_fcpio_status_to_str(hdr_status)); | ||
844 | |||
845 | /* | ||
846 | * If scsi_eh thread is blocked waiting for abts to complete, | ||
847 | * signal completion to it. IO will be cleaned in the thread | ||
848 | * else clean it in this context | ||
849 | */ | ||
850 | if (io_req->abts_done) { | ||
851 | complete(io_req->abts_done); | ||
852 | spin_unlock_irqrestore(io_lock, flags); | ||
853 | } else { | ||
854 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
855 | "abts cmpl, completing IO\n"); | ||
856 | CMD_SP(sc) = NULL; | ||
857 | sc->result = (DID_ERROR << 16); | ||
858 | |||
859 | spin_unlock_irqrestore(io_lock, flags); | ||
860 | |||
861 | fnic_release_ioreq_buf(fnic, io_req, sc); | ||
862 | mempool_free(io_req, fnic->io_req_pool); | ||
863 | if (sc->scsi_done) | ||
864 | sc->scsi_done(sc); | ||
865 | } | ||
866 | |||
867 | } else if (id & FNIC_TAG_DEV_RST) { | ||
868 | /* Completion of device reset */ | ||
869 | CMD_LR_STATUS(sc) = hdr_status; | ||
870 | CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE; | ||
871 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
872 | "dev reset cmpl recd. id %d status %s\n", | ||
873 | (int)(id & FNIC_TAG_MASK), | ||
874 | fnic_fcpio_status_to_str(hdr_status)); | ||
875 | if (io_req->dr_done) | ||
876 | complete(io_req->dr_done); | ||
877 | spin_unlock_irqrestore(io_lock, flags); | ||
878 | |||
879 | } else { | ||
880 | shost_printk(KERN_ERR, fnic->lport->host, | ||
881 | "Unexpected itmf io state %s tag %x\n", | ||
882 | fnic_ioreq_state_to_str(CMD_STATE(sc)), id); | ||
883 | spin_unlock_irqrestore(io_lock, flags); | ||
884 | } | ||
885 | |||
886 | } | ||
887 | |||
888 | /* | ||
889 | * fnic_fcpio_cmpl_handler | ||
890 | * Routine to service the cq for wq_copy | ||
891 | */ | ||
892 | static int fnic_fcpio_cmpl_handler(struct vnic_dev *vdev, | ||
893 | unsigned int cq_index, | ||
894 | struct fcpio_fw_req *desc) | ||
895 | { | ||
896 | struct fnic *fnic = vnic_dev_priv(vdev); | ||
897 | int ret = 0; | ||
898 | |||
899 | switch (desc->hdr.type) { | ||
900 | case FCPIO_ACK: /* fw copied copy wq desc to its queue */ | ||
901 | fnic_fcpio_ack_handler(fnic, cq_index, desc); | ||
902 | break; | ||
903 | |||
904 | case FCPIO_ICMND_CMPL: /* fw completed a command */ | ||
905 | fnic_fcpio_icmnd_cmpl_handler(fnic, desc); | ||
906 | break; | ||
907 | |||
908 | case FCPIO_ITMF_CMPL: /* fw completed itmf (abort cmd, lun reset)*/ | ||
909 | fnic_fcpio_itmf_cmpl_handler(fnic, desc); | ||
910 | break; | ||
911 | |||
912 | case FCPIO_FLOGI_REG_CMPL: /* fw completed flogi_reg */ | ||
913 | ret = fnic_fcpio_flogi_reg_cmpl_handler(fnic, desc); | ||
914 | break; | ||
915 | |||
916 | case FCPIO_RESET_CMPL: /* fw completed reset */ | ||
917 | ret = fnic_fcpio_fw_reset_cmpl_handler(fnic, desc); | ||
918 | break; | ||
919 | |||
920 | default: | ||
921 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
922 | "firmware completion type %d\n", | ||
923 | desc->hdr.type); | ||
924 | break; | ||
925 | } | ||
926 | |||
927 | return ret; | ||
928 | } | ||
929 | |||
930 | /* | ||
931 | * fnic_wq_copy_cmpl_handler | ||
932 | * Routine to process wq copy | ||
933 | */ | ||
934 | int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int copy_work_to_do) | ||
935 | { | ||
936 | unsigned int wq_work_done = 0; | ||
937 | unsigned int i, cq_index; | ||
938 | unsigned int cur_work_done; | ||
939 | |||
940 | for (i = 0; i < fnic->wq_copy_count; i++) { | ||
941 | cq_index = i + fnic->raw_wq_count + fnic->rq_count; | ||
942 | cur_work_done = vnic_cq_copy_service(&fnic->cq[cq_index], | ||
943 | fnic_fcpio_cmpl_handler, | ||
944 | copy_work_to_do); | ||
945 | wq_work_done += cur_work_done; | ||
946 | } | ||
947 | return wq_work_done; | ||
948 | } | ||
949 | |||
950 | static void fnic_cleanup_io(struct fnic *fnic, int exclude_id) | ||
951 | { | ||
952 | unsigned int i; | ||
953 | struct fnic_io_req *io_req; | ||
954 | unsigned long flags = 0; | ||
955 | struct scsi_cmnd *sc; | ||
956 | spinlock_t *io_lock; | ||
957 | |||
958 | for (i = 0; i < FNIC_MAX_IO_REQ; i++) { | ||
959 | if (i == exclude_id) | ||
960 | continue; | ||
961 | |||
962 | sc = scsi_host_find_tag(fnic->lport->host, i); | ||
963 | if (!sc) | ||
964 | continue; | ||
965 | |||
966 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
967 | spin_lock_irqsave(io_lock, flags); | ||
968 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
969 | if (!io_req) { | ||
970 | spin_unlock_irqrestore(io_lock, flags); | ||
971 | goto cleanup_scsi_cmd; | ||
972 | } | ||
973 | |||
974 | CMD_SP(sc) = NULL; | ||
975 | |||
976 | spin_unlock_irqrestore(io_lock, flags); | ||
977 | |||
978 | /* | ||
979 | * If there is a scsi_cmnd associated with this io_req, then | ||
980 | * free the corresponding state | ||
981 | */ | ||
982 | fnic_release_ioreq_buf(fnic, io_req, sc); | ||
983 | mempool_free(io_req, fnic->io_req_pool); | ||
984 | |||
985 | cleanup_scsi_cmd: | ||
986 | sc->result = DID_TRANSPORT_DISRUPTED << 16; | ||
987 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "fnic_cleanup_io:" | ||
988 | " DID_TRANSPORT_DISRUPTED\n"); | ||
989 | |||
990 | /* Complete the command to SCSI */ | ||
991 | if (sc->scsi_done) | ||
992 | sc->scsi_done(sc); | ||
993 | } | ||
994 | } | ||
995 | |||
996 | void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq, | ||
997 | struct fcpio_host_req *desc) | ||
998 | { | ||
999 | u32 id; | ||
1000 | struct fnic *fnic = vnic_dev_priv(wq->vdev); | ||
1001 | struct fnic_io_req *io_req; | ||
1002 | struct scsi_cmnd *sc; | ||
1003 | unsigned long flags; | ||
1004 | spinlock_t *io_lock; | ||
1005 | |||
1006 | /* get the tag reference */ | ||
1007 | fcpio_tag_id_dec(&desc->hdr.tag, &id); | ||
1008 | id &= FNIC_TAG_MASK; | ||
1009 | |||
1010 | if (id >= FNIC_MAX_IO_REQ) | ||
1011 | return; | ||
1012 | |||
1013 | sc = scsi_host_find_tag(fnic->lport->host, id); | ||
1014 | if (!sc) | ||
1015 | return; | ||
1016 | |||
1017 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
1018 | spin_lock_irqsave(io_lock, flags); | ||
1019 | |||
1020 | /* Get the IO context which this desc refers to */ | ||
1021 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1022 | |||
1023 | /* fnic interrupts are turned off by now */ | ||
1024 | |||
1025 | if (!io_req) { | ||
1026 | spin_unlock_irqrestore(io_lock, flags); | ||
1027 | goto wq_copy_cleanup_scsi_cmd; | ||
1028 | } | ||
1029 | |||
1030 | CMD_SP(sc) = NULL; | ||
1031 | |||
1032 | spin_unlock_irqrestore(io_lock, flags); | ||
1033 | |||
1034 | fnic_release_ioreq_buf(fnic, io_req, sc); | ||
1035 | mempool_free(io_req, fnic->io_req_pool); | ||
1036 | |||
1037 | wq_copy_cleanup_scsi_cmd: | ||
1038 | sc->result = DID_NO_CONNECT << 16; | ||
1039 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "wq_copy_cleanup_handler:" | ||
1040 | " DID_NO_CONNECT\n"); | ||
1041 | |||
1042 | if (sc->scsi_done) | ||
1043 | sc->scsi_done(sc); | ||
1044 | } | ||
1045 | |||
1046 | static inline int fnic_queue_abort_io_req(struct fnic *fnic, int tag, | ||
1047 | u32 task_req, u8 *fc_lun, | ||
1048 | struct fnic_io_req *io_req) | ||
1049 | { | ||
1050 | struct vnic_wq_copy *wq = &fnic->wq_copy[0]; | ||
1051 | unsigned long flags; | ||
1052 | |||
1053 | spin_lock_irqsave(&fnic->wq_copy_lock[0], flags); | ||
1054 | |||
1055 | if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0]) | ||
1056 | free_wq_copy_descs(fnic, wq); | ||
1057 | |||
1058 | if (!vnic_wq_copy_desc_avail(wq)) { | ||
1059 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags); | ||
1060 | return 1; | ||
1061 | } | ||
1062 | fnic_queue_wq_copy_desc_itmf(wq, tag | FNIC_TAG_ABORT, | ||
1063 | 0, task_req, tag, fc_lun, io_req->port_id, | ||
1064 | fnic->config.ra_tov, fnic->config.ed_tov); | ||
1065 | |||
1066 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags); | ||
1067 | return 0; | ||
1068 | } | ||
1069 | |||
1070 | void fnic_rport_exch_reset(struct fnic *fnic, u32 port_id) | ||
1071 | { | ||
1072 | int tag; | ||
1073 | struct fnic_io_req *io_req; | ||
1074 | spinlock_t *io_lock; | ||
1075 | unsigned long flags; | ||
1076 | struct scsi_cmnd *sc; | ||
1077 | struct scsi_lun fc_lun; | ||
1078 | enum fnic_ioreq_state old_ioreq_state; | ||
1079 | |||
1080 | FNIC_SCSI_DBG(KERN_DEBUG, | ||
1081 | fnic->lport->host, | ||
1082 | "fnic_rport_reset_exch called portid 0x%06x\n", | ||
1083 | port_id); | ||
1084 | |||
1085 | if (fnic->in_remove) | ||
1086 | return; | ||
1087 | |||
1088 | for (tag = 0; tag < FNIC_MAX_IO_REQ; tag++) { | ||
1089 | sc = scsi_host_find_tag(fnic->lport->host, tag); | ||
1090 | if (!sc) | ||
1091 | continue; | ||
1092 | |||
1093 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
1094 | spin_lock_irqsave(io_lock, flags); | ||
1095 | |||
1096 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1097 | |||
1098 | if (!io_req || io_req->port_id != port_id) { | ||
1099 | spin_unlock_irqrestore(io_lock, flags); | ||
1100 | continue; | ||
1101 | } | ||
1102 | |||
1103 | /* | ||
1104 | * Found IO that is still pending with firmware and | ||
1105 | * belongs to rport that went away | ||
1106 | */ | ||
1107 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { | ||
1108 | spin_unlock_irqrestore(io_lock, flags); | ||
1109 | continue; | ||
1110 | } | ||
1111 | old_ioreq_state = CMD_STATE(sc); | ||
1112 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; | ||
1113 | CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; | ||
1114 | |||
1115 | BUG_ON(io_req->abts_done); | ||
1116 | |||
1117 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
1118 | "fnic_rport_reset_exch: Issuing abts\n"); | ||
1119 | |||
1120 | spin_unlock_irqrestore(io_lock, flags); | ||
1121 | |||
1122 | /* Now queue the abort command to firmware */ | ||
1123 | int_to_scsilun(sc->device->lun, &fc_lun); | ||
1124 | |||
1125 | if (fnic_queue_abort_io_req(fnic, tag, | ||
1126 | FCPIO_ITMF_ABT_TASK_TERM, | ||
1127 | fc_lun.scsi_lun, io_req)) { | ||
1128 | /* | ||
1129 | * Revert the cmd state back to old state, if | ||
1130 | * it hasnt changed in between. This cmd will get | ||
1131 | * aborted later by scsi_eh, or cleaned up during | ||
1132 | * lun reset | ||
1133 | */ | ||
1134 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
1135 | |||
1136 | spin_lock_irqsave(io_lock, flags); | ||
1137 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) | ||
1138 | CMD_STATE(sc) = old_ioreq_state; | ||
1139 | spin_unlock_irqrestore(io_lock, flags); | ||
1140 | } | ||
1141 | } | ||
1142 | |||
1143 | } | ||
1144 | |||
1145 | void fnic_terminate_rport_io(struct fc_rport *rport) | ||
1146 | { | ||
1147 | int tag; | ||
1148 | struct fnic_io_req *io_req; | ||
1149 | spinlock_t *io_lock; | ||
1150 | unsigned long flags; | ||
1151 | struct scsi_cmnd *sc; | ||
1152 | struct scsi_lun fc_lun; | ||
1153 | struct fc_rport_libfc_priv *rdata = rport->dd_data; | ||
1154 | struct fc_lport *lport = rdata->local_port; | ||
1155 | struct fnic *fnic = lport_priv(lport); | ||
1156 | struct fc_rport *cmd_rport; | ||
1157 | enum fnic_ioreq_state old_ioreq_state; | ||
1158 | |||
1159 | FNIC_SCSI_DBG(KERN_DEBUG, | ||
1160 | fnic->lport->host, "fnic_terminate_rport_io called" | ||
1161 | " wwpn 0x%llx, wwnn0x%llx, portid 0x%06x\n", | ||
1162 | rport->port_name, rport->node_name, | ||
1163 | rport->port_id); | ||
1164 | |||
1165 | if (fnic->in_remove) | ||
1166 | return; | ||
1167 | |||
1168 | for (tag = 0; tag < FNIC_MAX_IO_REQ; tag++) { | ||
1169 | sc = scsi_host_find_tag(fnic->lport->host, tag); | ||
1170 | if (!sc) | ||
1171 | continue; | ||
1172 | |||
1173 | cmd_rport = starget_to_rport(scsi_target(sc->device)); | ||
1174 | if (rport != cmd_rport) | ||
1175 | continue; | ||
1176 | |||
1177 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
1178 | spin_lock_irqsave(io_lock, flags); | ||
1179 | |||
1180 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1181 | |||
1182 | if (!io_req || rport != cmd_rport) { | ||
1183 | spin_unlock_irqrestore(io_lock, flags); | ||
1184 | continue; | ||
1185 | } | ||
1186 | |||
1187 | /* | ||
1188 | * Found IO that is still pending with firmware and | ||
1189 | * belongs to rport that went away | ||
1190 | */ | ||
1191 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { | ||
1192 | spin_unlock_irqrestore(io_lock, flags); | ||
1193 | continue; | ||
1194 | } | ||
1195 | old_ioreq_state = CMD_STATE(sc); | ||
1196 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; | ||
1197 | CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; | ||
1198 | |||
1199 | BUG_ON(io_req->abts_done); | ||
1200 | |||
1201 | FNIC_SCSI_DBG(KERN_DEBUG, | ||
1202 | fnic->lport->host, | ||
1203 | "fnic_terminate_rport_io: Issuing abts\n"); | ||
1204 | |||
1205 | spin_unlock_irqrestore(io_lock, flags); | ||
1206 | |||
1207 | /* Now queue the abort command to firmware */ | ||
1208 | int_to_scsilun(sc->device->lun, &fc_lun); | ||
1209 | |||
1210 | if (fnic_queue_abort_io_req(fnic, tag, | ||
1211 | FCPIO_ITMF_ABT_TASK_TERM, | ||
1212 | fc_lun.scsi_lun, io_req)) { | ||
1213 | /* | ||
1214 | * Revert the cmd state back to old state, if | ||
1215 | * it hasnt changed in between. This cmd will get | ||
1216 | * aborted later by scsi_eh, or cleaned up during | ||
1217 | * lun reset | ||
1218 | */ | ||
1219 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
1220 | |||
1221 | spin_lock_irqsave(io_lock, flags); | ||
1222 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) | ||
1223 | CMD_STATE(sc) = old_ioreq_state; | ||
1224 | spin_unlock_irqrestore(io_lock, flags); | ||
1225 | } | ||
1226 | } | ||
1227 | |||
1228 | } | ||
1229 | |||
1230 | static void fnic_block_error_handler(struct scsi_cmnd *sc) | ||
1231 | { | ||
1232 | struct Scsi_Host *shost = sc->device->host; | ||
1233 | struct fc_rport *rport = starget_to_rport(scsi_target(sc->device)); | ||
1234 | unsigned long flags; | ||
1235 | |||
1236 | spin_lock_irqsave(shost->host_lock, flags); | ||
1237 | while (rport->port_state == FC_PORTSTATE_BLOCKED) { | ||
1238 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
1239 | msleep(1000); | ||
1240 | spin_lock_irqsave(shost->host_lock, flags); | ||
1241 | } | ||
1242 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
1243 | |||
1244 | } | ||
1245 | |||
1246 | /* | ||
1247 | * This function is exported to SCSI for sending abort cmnds. | ||
1248 | * A SCSI IO is represented by a io_req in the driver. | ||
1249 | * The ioreq is linked to the SCSI Cmd, thus a link with the ULP's IO. | ||
1250 | */ | ||
1251 | int fnic_abort_cmd(struct scsi_cmnd *sc) | ||
1252 | { | ||
1253 | struct fc_lport *lp; | ||
1254 | struct fnic *fnic; | ||
1255 | struct fnic_io_req *io_req; | ||
1256 | struct fc_rport *rport; | ||
1257 | spinlock_t *io_lock; | ||
1258 | unsigned long flags; | ||
1259 | int ret = SUCCESS; | ||
1260 | u32 task_req; | ||
1261 | struct scsi_lun fc_lun; | ||
1262 | DECLARE_COMPLETION_ONSTACK(tm_done); | ||
1263 | |||
1264 | /* Wait for rport to unblock */ | ||
1265 | fnic_block_error_handler(sc); | ||
1266 | |||
1267 | /* Get local-port, check ready and link up */ | ||
1268 | lp = shost_priv(sc->device->host); | ||
1269 | |||
1270 | fnic = lport_priv(lp); | ||
1271 | FNIC_SCSI_DBG(KERN_DEBUG, | ||
1272 | fnic->lport->host, | ||
1273 | "Abort Cmd called FCID 0x%x, LUN 0x%x TAG %d\n", | ||
1274 | (starget_to_rport(scsi_target(sc->device)))->port_id, | ||
1275 | sc->device->lun, sc->request->tag); | ||
1276 | |||
1277 | if (lp->state != LPORT_ST_READY || !(lp->link_up)) { | ||
1278 | ret = FAILED; | ||
1279 | goto fnic_abort_cmd_end; | ||
1280 | } | ||
1281 | |||
1282 | /* | ||
1283 | * Avoid a race between SCSI issuing the abort and the device | ||
1284 | * completing the command. | ||
1285 | * | ||
1286 | * If the command is already completed by the fw cmpl code, | ||
1287 | * we just return SUCCESS from here. This means that the abort | ||
1288 | * succeeded. In the SCSI ML, since the timeout for command has | ||
1289 | * happened, the completion wont actually complete the command | ||
1290 | * and it will be considered as an aborted command | ||
1291 | * | ||
1292 | * The CMD_SP will not be cleared except while holding io_req_lock. | ||
1293 | */ | ||
1294 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
1295 | spin_lock_irqsave(io_lock, flags); | ||
1296 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1297 | if (!io_req) { | ||
1298 | spin_unlock_irqrestore(io_lock, flags); | ||
1299 | goto fnic_abort_cmd_end; | ||
1300 | } | ||
1301 | |||
1302 | io_req->abts_done = &tm_done; | ||
1303 | |||
1304 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { | ||
1305 | spin_unlock_irqrestore(io_lock, flags); | ||
1306 | goto wait_pending; | ||
1307 | } | ||
1308 | /* | ||
1309 | * Command is still pending, need to abort it | ||
1310 | * If the firmware completes the command after this point, | ||
1311 | * the completion wont be done till mid-layer, since abort | ||
1312 | * has already started. | ||
1313 | */ | ||
1314 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; | ||
1315 | CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; | ||
1316 | |||
1317 | spin_unlock_irqrestore(io_lock, flags); | ||
1318 | |||
1319 | /* | ||
1320 | * Check readiness of the remote port. If the path to remote | ||
1321 | * port is up, then send abts to the remote port to terminate | ||
1322 | * the IO. Else, just locally terminate the IO in the firmware | ||
1323 | */ | ||
1324 | rport = starget_to_rport(scsi_target(sc->device)); | ||
1325 | if (fc_remote_port_chkready(rport) == 0) | ||
1326 | task_req = FCPIO_ITMF_ABT_TASK; | ||
1327 | else | ||
1328 | task_req = FCPIO_ITMF_ABT_TASK_TERM; | ||
1329 | |||
1330 | /* Now queue the abort command to firmware */ | ||
1331 | int_to_scsilun(sc->device->lun, &fc_lun); | ||
1332 | |||
1333 | if (fnic_queue_abort_io_req(fnic, sc->request->tag, task_req, | ||
1334 | fc_lun.scsi_lun, io_req)) { | ||
1335 | spin_lock_irqsave(io_lock, flags); | ||
1336 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1337 | if (io_req) | ||
1338 | io_req->abts_done = NULL; | ||
1339 | spin_unlock_irqrestore(io_lock, flags); | ||
1340 | ret = FAILED; | ||
1341 | goto fnic_abort_cmd_end; | ||
1342 | } | ||
1343 | |||
1344 | /* | ||
1345 | * We queued an abort IO, wait for its completion. | ||
1346 | * Once the firmware completes the abort command, it will | ||
1347 | * wake up this thread. | ||
1348 | */ | ||
1349 | wait_pending: | ||
1350 | wait_for_completion_timeout(&tm_done, | ||
1351 | msecs_to_jiffies | ||
1352 | (2 * fnic->config.ra_tov + | ||
1353 | fnic->config.ed_tov)); | ||
1354 | |||
1355 | /* Check the abort status */ | ||
1356 | spin_lock_irqsave(io_lock, flags); | ||
1357 | |||
1358 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1359 | if (!io_req) { | ||
1360 | spin_unlock_irqrestore(io_lock, flags); | ||
1361 | ret = FAILED; | ||
1362 | goto fnic_abort_cmd_end; | ||
1363 | } | ||
1364 | io_req->abts_done = NULL; | ||
1365 | |||
1366 | /* fw did not complete abort, timed out */ | ||
1367 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { | ||
1368 | spin_unlock_irqrestore(io_lock, flags); | ||
1369 | ret = FAILED; | ||
1370 | goto fnic_abort_cmd_end; | ||
1371 | } | ||
1372 | |||
1373 | /* | ||
1374 | * firmware completed the abort, check the status, | ||
1375 | * free the io_req irrespective of failure or success | ||
1376 | */ | ||
1377 | if (CMD_ABTS_STATUS(sc) != FCPIO_SUCCESS) | ||
1378 | ret = FAILED; | ||
1379 | |||
1380 | CMD_SP(sc) = NULL; | ||
1381 | |||
1382 | spin_unlock_irqrestore(io_lock, flags); | ||
1383 | |||
1384 | fnic_release_ioreq_buf(fnic, io_req, sc); | ||
1385 | mempool_free(io_req, fnic->io_req_pool); | ||
1386 | |||
1387 | fnic_abort_cmd_end: | ||
1388 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
1389 | "Returning from abort cmd %s\n", | ||
1390 | (ret == SUCCESS) ? | ||
1391 | "SUCCESS" : "FAILED"); | ||
1392 | return ret; | ||
1393 | } | ||
1394 | |||
1395 | static inline int fnic_queue_dr_io_req(struct fnic *fnic, | ||
1396 | struct scsi_cmnd *sc, | ||
1397 | struct fnic_io_req *io_req) | ||
1398 | { | ||
1399 | struct vnic_wq_copy *wq = &fnic->wq_copy[0]; | ||
1400 | struct scsi_lun fc_lun; | ||
1401 | int ret = 0; | ||
1402 | unsigned long intr_flags; | ||
1403 | |||
1404 | spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags); | ||
1405 | |||
1406 | if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0]) | ||
1407 | free_wq_copy_descs(fnic, wq); | ||
1408 | |||
1409 | if (!vnic_wq_copy_desc_avail(wq)) { | ||
1410 | ret = -EAGAIN; | ||
1411 | goto lr_io_req_end; | ||
1412 | } | ||
1413 | |||
1414 | /* fill in the lun info */ | ||
1415 | int_to_scsilun(sc->device->lun, &fc_lun); | ||
1416 | |||
1417 | fnic_queue_wq_copy_desc_itmf(wq, sc->request->tag | FNIC_TAG_DEV_RST, | ||
1418 | 0, FCPIO_ITMF_LUN_RESET, SCSI_NO_TAG, | ||
1419 | fc_lun.scsi_lun, io_req->port_id, | ||
1420 | fnic->config.ra_tov, fnic->config.ed_tov); | ||
1421 | |||
1422 | lr_io_req_end: | ||
1423 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], intr_flags); | ||
1424 | |||
1425 | return ret; | ||
1426 | } | ||
1427 | |||
1428 | /* | ||
1429 | * Clean up any pending aborts on the lun | ||
1430 | * For each outstanding IO on this lun, whose abort is not completed by fw, | ||
1431 | * issue a local abort. Wait for abort to complete. Return 0 if all commands | ||
1432 | * successfully aborted, 1 otherwise | ||
1433 | */ | ||
1434 | static int fnic_clean_pending_aborts(struct fnic *fnic, | ||
1435 | struct scsi_cmnd *lr_sc) | ||
1436 | { | ||
1437 | int tag; | ||
1438 | struct fnic_io_req *io_req; | ||
1439 | spinlock_t *io_lock; | ||
1440 | unsigned long flags; | ||
1441 | int ret = 0; | ||
1442 | struct scsi_cmnd *sc; | ||
1443 | struct fc_rport *rport; | ||
1444 | struct scsi_lun fc_lun; | ||
1445 | struct scsi_device *lun_dev = lr_sc->device; | ||
1446 | DECLARE_COMPLETION_ONSTACK(tm_done); | ||
1447 | |||
1448 | for (tag = 0; tag < FNIC_MAX_IO_REQ; tag++) { | ||
1449 | sc = scsi_host_find_tag(fnic->lport->host, tag); | ||
1450 | /* | ||
1451 | * ignore this lun reset cmd or cmds that do not belong to | ||
1452 | * this lun | ||
1453 | */ | ||
1454 | if (!sc || sc == lr_sc || sc->device != lun_dev) | ||
1455 | continue; | ||
1456 | |||
1457 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
1458 | spin_lock_irqsave(io_lock, flags); | ||
1459 | |||
1460 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1461 | |||
1462 | if (!io_req || sc->device != lun_dev) { | ||
1463 | spin_unlock_irqrestore(io_lock, flags); | ||
1464 | continue; | ||
1465 | } | ||
1466 | |||
1467 | /* | ||
1468 | * Found IO that is still pending with firmware and | ||
1469 | * belongs to the LUN that we are resetting | ||
1470 | */ | ||
1471 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
1472 | "Found IO in %s on lun\n", | ||
1473 | fnic_ioreq_state_to_str(CMD_STATE(sc))); | ||
1474 | |||
1475 | BUG_ON(CMD_STATE(sc) != FNIC_IOREQ_ABTS_PENDING); | ||
1476 | |||
1477 | CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; | ||
1478 | io_req->abts_done = &tm_done; | ||
1479 | spin_unlock_irqrestore(io_lock, flags); | ||
1480 | |||
1481 | /* Now queue the abort command to firmware */ | ||
1482 | int_to_scsilun(sc->device->lun, &fc_lun); | ||
1483 | rport = starget_to_rport(scsi_target(sc->device)); | ||
1484 | |||
1485 | if (fnic_queue_abort_io_req(fnic, tag, | ||
1486 | FCPIO_ITMF_ABT_TASK_TERM, | ||
1487 | fc_lun.scsi_lun, io_req)) { | ||
1488 | spin_lock_irqsave(io_lock, flags); | ||
1489 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1490 | if (io_req) | ||
1491 | io_req->abts_done = NULL; | ||
1492 | spin_unlock_irqrestore(io_lock, flags); | ||
1493 | ret = 1; | ||
1494 | goto clean_pending_aborts_end; | ||
1495 | } | ||
1496 | |||
1497 | wait_for_completion_timeout(&tm_done, | ||
1498 | msecs_to_jiffies | ||
1499 | (fnic->config.ed_tov)); | ||
1500 | |||
1501 | /* Recheck cmd state to check if it is now aborted */ | ||
1502 | spin_lock_irqsave(io_lock, flags); | ||
1503 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1504 | if (!io_req) { | ||
1505 | spin_unlock_irqrestore(io_lock, flags); | ||
1506 | ret = 1; | ||
1507 | goto clean_pending_aborts_end; | ||
1508 | } | ||
1509 | |||
1510 | io_req->abts_done = NULL; | ||
1511 | |||
1512 | /* if abort is still pending with fw, fail */ | ||
1513 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { | ||
1514 | spin_unlock_irqrestore(io_lock, flags); | ||
1515 | ret = 1; | ||
1516 | goto clean_pending_aborts_end; | ||
1517 | } | ||
1518 | CMD_SP(sc) = NULL; | ||
1519 | spin_unlock_irqrestore(io_lock, flags); | ||
1520 | |||
1521 | fnic_release_ioreq_buf(fnic, io_req, sc); | ||
1522 | mempool_free(io_req, fnic->io_req_pool); | ||
1523 | } | ||
1524 | |||
1525 | clean_pending_aborts_end: | ||
1526 | return ret; | ||
1527 | } | ||
1528 | |||
1529 | /* | ||
1530 | * SCSI Eh thread issues a Lun Reset when one or more commands on a LUN | ||
1531 | * fail to get aborted. It calls driver's eh_device_reset with a SCSI command | ||
1532 | * on the LUN. | ||
1533 | */ | ||
1534 | int fnic_device_reset(struct scsi_cmnd *sc) | ||
1535 | { | ||
1536 | struct fc_lport *lp; | ||
1537 | struct fnic *fnic; | ||
1538 | struct fnic_io_req *io_req; | ||
1539 | struct fc_rport *rport; | ||
1540 | int status; | ||
1541 | int ret = FAILED; | ||
1542 | spinlock_t *io_lock; | ||
1543 | unsigned long flags; | ||
1544 | DECLARE_COMPLETION_ONSTACK(tm_done); | ||
1545 | |||
1546 | /* Wait for rport to unblock */ | ||
1547 | fnic_block_error_handler(sc); | ||
1548 | |||
1549 | /* Get local-port, check ready and link up */ | ||
1550 | lp = shost_priv(sc->device->host); | ||
1551 | |||
1552 | fnic = lport_priv(lp); | ||
1553 | FNIC_SCSI_DBG(KERN_DEBUG, | ||
1554 | fnic->lport->host, | ||
1555 | "Device reset called FCID 0x%x, LUN 0x%x\n", | ||
1556 | (starget_to_rport(scsi_target(sc->device)))->port_id, | ||
1557 | sc->device->lun); | ||
1558 | |||
1559 | |||
1560 | if (lp->state != LPORT_ST_READY || !(lp->link_up)) | ||
1561 | goto fnic_device_reset_end; | ||
1562 | |||
1563 | /* Check if remote port up */ | ||
1564 | rport = starget_to_rport(scsi_target(sc->device)); | ||
1565 | if (fc_remote_port_chkready(rport)) | ||
1566 | goto fnic_device_reset_end; | ||
1567 | |||
1568 | io_lock = fnic_io_lock_hash(fnic, sc); | ||
1569 | spin_lock_irqsave(io_lock, flags); | ||
1570 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1571 | |||
1572 | /* | ||
1573 | * If there is a io_req attached to this command, then use it, | ||
1574 | * else allocate a new one. | ||
1575 | */ | ||
1576 | if (!io_req) { | ||
1577 | io_req = mempool_alloc(fnic->io_req_pool, GFP_ATOMIC); | ||
1578 | if (!io_req) { | ||
1579 | spin_unlock_irqrestore(io_lock, flags); | ||
1580 | goto fnic_device_reset_end; | ||
1581 | } | ||
1582 | memset(io_req, 0, sizeof(*io_req)); | ||
1583 | io_req->port_id = rport->port_id; | ||
1584 | CMD_SP(sc) = (char *)io_req; | ||
1585 | } | ||
1586 | io_req->dr_done = &tm_done; | ||
1587 | CMD_STATE(sc) = FNIC_IOREQ_CMD_PENDING; | ||
1588 | CMD_LR_STATUS(sc) = FCPIO_INVALID_CODE; | ||
1589 | spin_unlock_irqrestore(io_lock, flags); | ||
1590 | |||
1591 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "TAG %d\n", | ||
1592 | sc->request->tag); | ||
1593 | |||
1594 | /* | ||
1595 | * issue the device reset, if enqueue failed, clean up the ioreq | ||
1596 | * and break assoc with scsi cmd | ||
1597 | */ | ||
1598 | if (fnic_queue_dr_io_req(fnic, sc, io_req)) { | ||
1599 | spin_lock_irqsave(io_lock, flags); | ||
1600 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1601 | if (io_req) | ||
1602 | io_req->dr_done = NULL; | ||
1603 | goto fnic_device_reset_clean; | ||
1604 | } | ||
1605 | |||
1606 | /* | ||
1607 | * Wait on the local completion for LUN reset. The io_req may be | ||
1608 | * freed while we wait since we hold no lock. | ||
1609 | */ | ||
1610 | wait_for_completion_timeout(&tm_done, | ||
1611 | msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT)); | ||
1612 | |||
1613 | spin_lock_irqsave(io_lock, flags); | ||
1614 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1615 | if (!io_req) { | ||
1616 | spin_unlock_irqrestore(io_lock, flags); | ||
1617 | goto fnic_device_reset_end; | ||
1618 | } | ||
1619 | io_req->dr_done = NULL; | ||
1620 | |||
1621 | status = CMD_LR_STATUS(sc); | ||
1622 | spin_unlock_irqrestore(io_lock, flags); | ||
1623 | |||
1624 | /* | ||
1625 | * If lun reset not completed, bail out with failed. io_req | ||
1626 | * gets cleaned up during higher levels of EH | ||
1627 | */ | ||
1628 | if (status == FCPIO_INVALID_CODE) { | ||
1629 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
1630 | "Device reset timed out\n"); | ||
1631 | goto fnic_device_reset_end; | ||
1632 | } | ||
1633 | |||
1634 | /* Completed, but not successful, clean up the io_req, return fail */ | ||
1635 | if (status != FCPIO_SUCCESS) { | ||
1636 | spin_lock_irqsave(io_lock, flags); | ||
1637 | FNIC_SCSI_DBG(KERN_DEBUG, | ||
1638 | fnic->lport->host, | ||
1639 | "Device reset completed - failed\n"); | ||
1640 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1641 | goto fnic_device_reset_clean; | ||
1642 | } | ||
1643 | |||
1644 | /* | ||
1645 | * Clean up any aborts on this lun that have still not | ||
1646 | * completed. If any of these fail, then LUN reset fails. | ||
1647 | * clean_pending_aborts cleans all cmds on this lun except | ||
1648 | * the lun reset cmd. If all cmds get cleaned, the lun reset | ||
1649 | * succeeds | ||
1650 | */ | ||
1651 | if (fnic_clean_pending_aborts(fnic, sc)) { | ||
1652 | spin_lock_irqsave(io_lock, flags); | ||
1653 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1654 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
1655 | "Device reset failed" | ||
1656 | " since could not abort all IOs\n"); | ||
1657 | goto fnic_device_reset_clean; | ||
1658 | } | ||
1659 | |||
1660 | /* Clean lun reset command */ | ||
1661 | spin_lock_irqsave(io_lock, flags); | ||
1662 | io_req = (struct fnic_io_req *)CMD_SP(sc); | ||
1663 | if (io_req) | ||
1664 | /* Completed, and successful */ | ||
1665 | ret = SUCCESS; | ||
1666 | |||
1667 | fnic_device_reset_clean: | ||
1668 | if (io_req) | ||
1669 | CMD_SP(sc) = NULL; | ||
1670 | |||
1671 | spin_unlock_irqrestore(io_lock, flags); | ||
1672 | |||
1673 | if (io_req) { | ||
1674 | fnic_release_ioreq_buf(fnic, io_req, sc); | ||
1675 | mempool_free(io_req, fnic->io_req_pool); | ||
1676 | } | ||
1677 | |||
1678 | fnic_device_reset_end: | ||
1679 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
1680 | "Returning from device reset %s\n", | ||
1681 | (ret == SUCCESS) ? | ||
1682 | "SUCCESS" : "FAILED"); | ||
1683 | return ret; | ||
1684 | } | ||
1685 | |||
1686 | /* Clean up all IOs, clean up libFC local port */ | ||
1687 | int fnic_reset(struct Scsi_Host *shost) | ||
1688 | { | ||
1689 | struct fc_lport *lp; | ||
1690 | struct fnic *fnic; | ||
1691 | int ret = SUCCESS; | ||
1692 | |||
1693 | lp = shost_priv(shost); | ||
1694 | fnic = lport_priv(lp); | ||
1695 | |||
1696 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
1697 | "fnic_reset called\n"); | ||
1698 | |||
1699 | /* | ||
1700 | * Reset local port, this will clean up libFC exchanges, | ||
1701 | * reset remote port sessions, and if link is up, begin flogi | ||
1702 | */ | ||
1703 | if (lp->tt.lport_reset(lp)) | ||
1704 | ret = FAILED; | ||
1705 | |||
1706 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
1707 | "Returning from fnic reset %s\n", | ||
1708 | (ret == SUCCESS) ? | ||
1709 | "SUCCESS" : "FAILED"); | ||
1710 | |||
1711 | return ret; | ||
1712 | } | ||
1713 | |||
1714 | /* | ||
1715 | * SCSI Error handling calls driver's eh_host_reset if all prior | ||
1716 | * error handling levels return FAILED. If host reset completes | ||
1717 | * successfully, and if link is up, then Fabric login begins. | ||
1718 | * | ||
1719 | * Host Reset is the highest level of error recovery. If this fails, then | ||
1720 | * host is offlined by SCSI. | ||
1721 | * | ||
1722 | */ | ||
1723 | int fnic_host_reset(struct scsi_cmnd *sc) | ||
1724 | { | ||
1725 | int ret; | ||
1726 | unsigned long wait_host_tmo; | ||
1727 | struct Scsi_Host *shost = sc->device->host; | ||
1728 | struct fc_lport *lp = shost_priv(shost); | ||
1729 | |||
1730 | /* | ||
1731 | * If fnic_reset is successful, wait for fabric login to complete | ||
1732 | * scsi-ml tries to send a TUR to every device if host reset is | ||
1733 | * successful, so before returning to scsi, fabric should be up | ||
1734 | */ | ||
1735 | ret = fnic_reset(shost); | ||
1736 | if (ret == SUCCESS) { | ||
1737 | wait_host_tmo = jiffies + FNIC_HOST_RESET_SETTLE_TIME * HZ; | ||
1738 | ret = FAILED; | ||
1739 | while (time_before(jiffies, wait_host_tmo)) { | ||
1740 | if ((lp->state == LPORT_ST_READY) && | ||
1741 | (lp->link_up)) { | ||
1742 | ret = SUCCESS; | ||
1743 | break; | ||
1744 | } | ||
1745 | ssleep(1); | ||
1746 | } | ||
1747 | } | ||
1748 | |||
1749 | return ret; | ||
1750 | } | ||
1751 | |||
1752 | /* | ||
1753 | * This fxn is called from libFC when host is removed | ||
1754 | */ | ||
1755 | void fnic_scsi_abort_io(struct fc_lport *lp) | ||
1756 | { | ||
1757 | int err = 0; | ||
1758 | unsigned long flags; | ||
1759 | enum fnic_state old_state; | ||
1760 | struct fnic *fnic = lport_priv(lp); | ||
1761 | DECLARE_COMPLETION_ONSTACK(remove_wait); | ||
1762 | |||
1763 | /* Issue firmware reset for fnic, wait for reset to complete */ | ||
1764 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
1765 | fnic->remove_wait = &remove_wait; | ||
1766 | old_state = fnic->state; | ||
1767 | fnic->state = FNIC_IN_FC_TRANS_ETH_MODE; | ||
1768 | vnic_dev_del_addr(fnic->vdev, fnic->data_src_addr); | ||
1769 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
1770 | |||
1771 | err = fnic_fw_reset_handler(fnic); | ||
1772 | if (err) { | ||
1773 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
1774 | if (fnic->state == FNIC_IN_FC_TRANS_ETH_MODE) | ||
1775 | fnic->state = old_state; | ||
1776 | fnic->remove_wait = NULL; | ||
1777 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
1778 | return; | ||
1779 | } | ||
1780 | |||
1781 | /* Wait for firmware reset to complete */ | ||
1782 | wait_for_completion_timeout(&remove_wait, | ||
1783 | msecs_to_jiffies(FNIC_RMDEVICE_TIMEOUT)); | ||
1784 | |||
1785 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
1786 | fnic->remove_wait = NULL; | ||
1787 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, | ||
1788 | "fnic_scsi_abort_io %s\n", | ||
1789 | (fnic->state == FNIC_IN_ETH_MODE) ? | ||
1790 | "SUCCESS" : "FAILED"); | ||
1791 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
1792 | |||
1793 | } | ||
1794 | |||
1795 | /* | ||
1796 | * This fxn called from libFC to clean up driver IO state on link down | ||
1797 | */ | ||
1798 | void fnic_scsi_cleanup(struct fc_lport *lp) | ||
1799 | { | ||
1800 | unsigned long flags; | ||
1801 | enum fnic_state old_state; | ||
1802 | struct fnic *fnic = lport_priv(lp); | ||
1803 | |||
1804 | /* issue fw reset */ | ||
1805 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
1806 | old_state = fnic->state; | ||
1807 | fnic->state = FNIC_IN_FC_TRANS_ETH_MODE; | ||
1808 | vnic_dev_del_addr(fnic->vdev, fnic->data_src_addr); | ||
1809 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
1810 | |||
1811 | if (fnic_fw_reset_handler(fnic)) { | ||
1812 | spin_lock_irqsave(&fnic->fnic_lock, flags); | ||
1813 | if (fnic->state == FNIC_IN_FC_TRANS_ETH_MODE) | ||
1814 | fnic->state = old_state; | ||
1815 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); | ||
1816 | } | ||
1817 | |||
1818 | } | ||
1819 | |||
1820 | void fnic_empty_scsi_cleanup(struct fc_lport *lp) | ||
1821 | { | ||
1822 | } | ||
1823 | |||
1824 | void fnic_exch_mgr_reset(struct fc_lport *lp, u32 sid, u32 did) | ||
1825 | { | ||
1826 | struct fnic *fnic = lport_priv(lp); | ||
1827 | |||
1828 | /* Non-zero sid, nothing to do */ | ||
1829 | if (sid) | ||
1830 | goto call_fc_exch_mgr_reset; | ||
1831 | |||
1832 | if (did) { | ||
1833 | fnic_rport_exch_reset(fnic, did); | ||
1834 | goto call_fc_exch_mgr_reset; | ||
1835 | } | ||
1836 | |||
1837 | /* | ||
1838 | * sid = 0, did = 0 | ||
1839 | * link down or device being removed | ||
1840 | */ | ||
1841 | if (!fnic->in_remove) | ||
1842 | fnic_scsi_cleanup(lp); | ||
1843 | else | ||
1844 | fnic_scsi_abort_io(lp); | ||
1845 | |||
1846 | /* call libFC exch mgr reset to reset its exchanges */ | ||
1847 | call_fc_exch_mgr_reset: | ||
1848 | fc_exch_mgr_reset(lp, sid, did); | ||
1849 | |||
1850 | } | ||
diff --git a/drivers/scsi/fnic/rq_enet_desc.h b/drivers/scsi/fnic/rq_enet_desc.h new file mode 100644 index 000000000000..92e80ae6b725 --- /dev/null +++ b/drivers/scsi/fnic/rq_enet_desc.h | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _RQ_ENET_DESC_H_ | ||
19 | #define _RQ_ENET_DESC_H_ | ||
20 | |||
21 | /* Ethernet receive queue descriptor: 16B */ | ||
22 | struct rq_enet_desc { | ||
23 | __le64 address; | ||
24 | __le16 length_type; | ||
25 | u8 reserved[6]; | ||
26 | }; | ||
27 | |||
28 | enum rq_enet_type_types { | ||
29 | RQ_ENET_TYPE_ONLY_SOP = 0, | ||
30 | RQ_ENET_TYPE_NOT_SOP = 1, | ||
31 | RQ_ENET_TYPE_RESV2 = 2, | ||
32 | RQ_ENET_TYPE_RESV3 = 3, | ||
33 | }; | ||
34 | |||
35 | #define RQ_ENET_ADDR_BITS 64 | ||
36 | #define RQ_ENET_LEN_BITS 14 | ||
37 | #define RQ_ENET_LEN_MASK ((1 << RQ_ENET_LEN_BITS) - 1) | ||
38 | #define RQ_ENET_TYPE_BITS 2 | ||
39 | #define RQ_ENET_TYPE_MASK ((1 << RQ_ENET_TYPE_BITS) - 1) | ||
40 | |||
41 | static inline void rq_enet_desc_enc(struct rq_enet_desc *desc, | ||
42 | u64 address, u8 type, u16 length) | ||
43 | { | ||
44 | desc->address = cpu_to_le64(address); | ||
45 | desc->length_type = cpu_to_le16((length & RQ_ENET_LEN_MASK) | | ||
46 | ((type & RQ_ENET_TYPE_MASK) << RQ_ENET_LEN_BITS)); | ||
47 | } | ||
48 | |||
49 | static inline void rq_enet_desc_dec(struct rq_enet_desc *desc, | ||
50 | u64 *address, u8 *type, u16 *length) | ||
51 | { | ||
52 | *address = le64_to_cpu(desc->address); | ||
53 | *length = le16_to_cpu(desc->length_type) & RQ_ENET_LEN_MASK; | ||
54 | *type = (u8)((le16_to_cpu(desc->length_type) >> RQ_ENET_LEN_BITS) & | ||
55 | RQ_ENET_TYPE_MASK); | ||
56 | } | ||
57 | |||
58 | #endif /* _RQ_ENET_DESC_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_cq.c b/drivers/scsi/fnic/vnic_cq.c new file mode 100644 index 000000000000..c5db32eda5ef --- /dev/null +++ b/drivers/scsi/fnic/vnic_cq.c | |||
@@ -0,0 +1,85 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #include <linux/errno.h> | ||
19 | #include <linux/types.h> | ||
20 | #include <linux/pci.h> | ||
21 | #include "vnic_dev.h" | ||
22 | #include "vnic_cq.h" | ||
23 | |||
24 | void vnic_cq_free(struct vnic_cq *cq) | ||
25 | { | ||
26 | vnic_dev_free_desc_ring(cq->vdev, &cq->ring); | ||
27 | |||
28 | cq->ctrl = NULL; | ||
29 | } | ||
30 | |||
31 | int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index, | ||
32 | unsigned int desc_count, unsigned int desc_size) | ||
33 | { | ||
34 | int err; | ||
35 | |||
36 | cq->index = index; | ||
37 | cq->vdev = vdev; | ||
38 | |||
39 | cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index); | ||
40 | if (!cq->ctrl) { | ||
41 | printk(KERN_ERR "Failed to hook CQ[%d] resource\n", index); | ||
42 | return -EINVAL; | ||
43 | } | ||
44 | |||
45 | err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size); | ||
46 | if (err) | ||
47 | return err; | ||
48 | |||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable, | ||
53 | unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail, | ||
54 | unsigned int cq_tail_color, unsigned int interrupt_enable, | ||
55 | unsigned int cq_entry_enable, unsigned int cq_message_enable, | ||
56 | unsigned int interrupt_offset, u64 cq_message_addr) | ||
57 | { | ||
58 | u64 paddr; | ||
59 | |||
60 | paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET; | ||
61 | writeq(paddr, &cq->ctrl->ring_base); | ||
62 | iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size); | ||
63 | iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable); | ||
64 | iowrite32(color_enable, &cq->ctrl->color_enable); | ||
65 | iowrite32(cq_head, &cq->ctrl->cq_head); | ||
66 | iowrite32(cq_tail, &cq->ctrl->cq_tail); | ||
67 | iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color); | ||
68 | iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable); | ||
69 | iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable); | ||
70 | iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable); | ||
71 | iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset); | ||
72 | writeq(cq_message_addr, &cq->ctrl->cq_message_addr); | ||
73 | } | ||
74 | |||
75 | void vnic_cq_clean(struct vnic_cq *cq) | ||
76 | { | ||
77 | cq->to_clean = 0; | ||
78 | cq->last_color = 0; | ||
79 | |||
80 | iowrite32(0, &cq->ctrl->cq_head); | ||
81 | iowrite32(0, &cq->ctrl->cq_tail); | ||
82 | iowrite32(1, &cq->ctrl->cq_tail_color); | ||
83 | |||
84 | vnic_dev_clear_desc_ring(&cq->ring); | ||
85 | } | ||
diff --git a/drivers/scsi/fnic/vnic_cq.h b/drivers/scsi/fnic/vnic_cq.h new file mode 100644 index 000000000000..4ede6809fb1e --- /dev/null +++ b/drivers/scsi/fnic/vnic_cq.h | |||
@@ -0,0 +1,121 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_CQ_H_ | ||
19 | #define _VNIC_CQ_H_ | ||
20 | |||
21 | #include "cq_desc.h" | ||
22 | #include "vnic_dev.h" | ||
23 | |||
24 | /* | ||
25 | * These defines avoid symbol clash between fnic and enic (Cisco 10G Eth | ||
26 | * Driver) when both are built with CONFIG options =y | ||
27 | */ | ||
28 | #define vnic_cq_service fnic_cq_service | ||
29 | #define vnic_cq_free fnic_cq_free | ||
30 | #define vnic_cq_alloc fnic_cq_alloc | ||
31 | #define vnic_cq_init fnic_cq_init | ||
32 | #define vnic_cq_clean fnic_cq_clean | ||
33 | |||
34 | /* Completion queue control */ | ||
35 | struct vnic_cq_ctrl { | ||
36 | u64 ring_base; /* 0x00 */ | ||
37 | u32 ring_size; /* 0x08 */ | ||
38 | u32 pad0; | ||
39 | u32 flow_control_enable; /* 0x10 */ | ||
40 | u32 pad1; | ||
41 | u32 color_enable; /* 0x18 */ | ||
42 | u32 pad2; | ||
43 | u32 cq_head; /* 0x20 */ | ||
44 | u32 pad3; | ||
45 | u32 cq_tail; /* 0x28 */ | ||
46 | u32 pad4; | ||
47 | u32 cq_tail_color; /* 0x30 */ | ||
48 | u32 pad5; | ||
49 | u32 interrupt_enable; /* 0x38 */ | ||
50 | u32 pad6; | ||
51 | u32 cq_entry_enable; /* 0x40 */ | ||
52 | u32 pad7; | ||
53 | u32 cq_message_enable; /* 0x48 */ | ||
54 | u32 pad8; | ||
55 | u32 interrupt_offset; /* 0x50 */ | ||
56 | u32 pad9; | ||
57 | u64 cq_message_addr; /* 0x58 */ | ||
58 | u32 pad10; | ||
59 | }; | ||
60 | |||
61 | struct vnic_cq { | ||
62 | unsigned int index; | ||
63 | struct vnic_dev *vdev; | ||
64 | struct vnic_cq_ctrl __iomem *ctrl; /* memory-mapped */ | ||
65 | struct vnic_dev_ring ring; | ||
66 | unsigned int to_clean; | ||
67 | unsigned int last_color; | ||
68 | }; | ||
69 | |||
70 | static inline unsigned int vnic_cq_service(struct vnic_cq *cq, | ||
71 | unsigned int work_to_do, | ||
72 | int (*q_service)(struct vnic_dev *vdev, struct cq_desc *cq_desc, | ||
73 | u8 type, u16 q_number, u16 completed_index, void *opaque), | ||
74 | void *opaque) | ||
75 | { | ||
76 | struct cq_desc *cq_desc; | ||
77 | unsigned int work_done = 0; | ||
78 | u16 q_number, completed_index; | ||
79 | u8 type, color; | ||
80 | |||
81 | cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs + | ||
82 | cq->ring.desc_size * cq->to_clean); | ||
83 | cq_desc_dec(cq_desc, &type, &color, | ||
84 | &q_number, &completed_index); | ||
85 | |||
86 | while (color != cq->last_color) { | ||
87 | |||
88 | if ((*q_service)(cq->vdev, cq_desc, type, | ||
89 | q_number, completed_index, opaque)) | ||
90 | break; | ||
91 | |||
92 | cq->to_clean++; | ||
93 | if (cq->to_clean == cq->ring.desc_count) { | ||
94 | cq->to_clean = 0; | ||
95 | cq->last_color = cq->last_color ? 0 : 1; | ||
96 | } | ||
97 | |||
98 | cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs + | ||
99 | cq->ring.desc_size * cq->to_clean); | ||
100 | cq_desc_dec(cq_desc, &type, &color, | ||
101 | &q_number, &completed_index); | ||
102 | |||
103 | work_done++; | ||
104 | if (work_done >= work_to_do) | ||
105 | break; | ||
106 | } | ||
107 | |||
108 | return work_done; | ||
109 | } | ||
110 | |||
111 | void vnic_cq_free(struct vnic_cq *cq); | ||
112 | int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index, | ||
113 | unsigned int desc_count, unsigned int desc_size); | ||
114 | void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable, | ||
115 | unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail, | ||
116 | unsigned int cq_tail_color, unsigned int interrupt_enable, | ||
117 | unsigned int cq_entry_enable, unsigned int message_enable, | ||
118 | unsigned int interrupt_offset, u64 message_addr); | ||
119 | void vnic_cq_clean(struct vnic_cq *cq); | ||
120 | |||
121 | #endif /* _VNIC_CQ_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_cq_copy.h b/drivers/scsi/fnic/vnic_cq_copy.h new file mode 100644 index 000000000000..7901ce255a81 --- /dev/null +++ b/drivers/scsi/fnic/vnic_cq_copy.h | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_CQ_COPY_H_ | ||
19 | #define _VNIC_CQ_COPY_H_ | ||
20 | |||
21 | #include "fcpio.h" | ||
22 | |||
23 | static inline unsigned int vnic_cq_copy_service( | ||
24 | struct vnic_cq *cq, | ||
25 | int (*q_service)(struct vnic_dev *vdev, | ||
26 | unsigned int index, | ||
27 | struct fcpio_fw_req *desc), | ||
28 | unsigned int work_to_do) | ||
29 | |||
30 | { | ||
31 | struct fcpio_fw_req *desc; | ||
32 | unsigned int work_done = 0; | ||
33 | u8 color; | ||
34 | |||
35 | desc = (struct fcpio_fw_req *)((u8 *)cq->ring.descs + | ||
36 | cq->ring.desc_size * cq->to_clean); | ||
37 | fcpio_color_dec(desc, &color); | ||
38 | |||
39 | while (color != cq->last_color) { | ||
40 | |||
41 | if ((*q_service)(cq->vdev, cq->index, desc)) | ||
42 | break; | ||
43 | |||
44 | cq->to_clean++; | ||
45 | if (cq->to_clean == cq->ring.desc_count) { | ||
46 | cq->to_clean = 0; | ||
47 | cq->last_color = cq->last_color ? 0 : 1; | ||
48 | } | ||
49 | |||
50 | desc = (struct fcpio_fw_req *)((u8 *)cq->ring.descs + | ||
51 | cq->ring.desc_size * cq->to_clean); | ||
52 | fcpio_color_dec(desc, &color); | ||
53 | |||
54 | work_done++; | ||
55 | if (work_done >= work_to_do) | ||
56 | break; | ||
57 | } | ||
58 | |||
59 | return work_done; | ||
60 | } | ||
61 | |||
62 | #endif /* _VNIC_CQ_COPY_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_dev.c b/drivers/scsi/fnic/vnic_dev.c new file mode 100644 index 000000000000..566770645086 --- /dev/null +++ b/drivers/scsi/fnic/vnic_dev.c | |||
@@ -0,0 +1,690 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/pci.h> | ||
23 | #include <linux/delay.h> | ||
24 | #include <linux/if_ether.h> | ||
25 | #include "vnic_resource.h" | ||
26 | #include "vnic_devcmd.h" | ||
27 | #include "vnic_dev.h" | ||
28 | #include "vnic_stats.h" | ||
29 | |||
30 | struct vnic_res { | ||
31 | void __iomem *vaddr; | ||
32 | unsigned int count; | ||
33 | }; | ||
34 | |||
35 | struct vnic_dev { | ||
36 | void *priv; | ||
37 | struct pci_dev *pdev; | ||
38 | struct vnic_res res[RES_TYPE_MAX]; | ||
39 | enum vnic_dev_intr_mode intr_mode; | ||
40 | struct vnic_devcmd __iomem *devcmd; | ||
41 | struct vnic_devcmd_notify *notify; | ||
42 | struct vnic_devcmd_notify notify_copy; | ||
43 | dma_addr_t notify_pa; | ||
44 | u32 *linkstatus; | ||
45 | dma_addr_t linkstatus_pa; | ||
46 | struct vnic_stats *stats; | ||
47 | dma_addr_t stats_pa; | ||
48 | struct vnic_devcmd_fw_info *fw_info; | ||
49 | dma_addr_t fw_info_pa; | ||
50 | }; | ||
51 | |||
52 | #define VNIC_MAX_RES_HDR_SIZE \ | ||
53 | (sizeof(struct vnic_resource_header) + \ | ||
54 | sizeof(struct vnic_resource) * RES_TYPE_MAX) | ||
55 | #define VNIC_RES_STRIDE 128 | ||
56 | |||
57 | void *vnic_dev_priv(struct vnic_dev *vdev) | ||
58 | { | ||
59 | return vdev->priv; | ||
60 | } | ||
61 | |||
62 | static int vnic_dev_discover_res(struct vnic_dev *vdev, | ||
63 | struct vnic_dev_bar *bar) | ||
64 | { | ||
65 | struct vnic_resource_header __iomem *rh; | ||
66 | struct vnic_resource __iomem *r; | ||
67 | u8 type; | ||
68 | |||
69 | if (bar->len < VNIC_MAX_RES_HDR_SIZE) { | ||
70 | printk(KERN_ERR "vNIC BAR0 res hdr length error\n"); | ||
71 | return -EINVAL; | ||
72 | } | ||
73 | |||
74 | rh = bar->vaddr; | ||
75 | if (!rh) { | ||
76 | printk(KERN_ERR "vNIC BAR0 res hdr not mem-mapped\n"); | ||
77 | return -EINVAL; | ||
78 | } | ||
79 | |||
80 | if (ioread32(&rh->magic) != VNIC_RES_MAGIC || | ||
81 | ioread32(&rh->version) != VNIC_RES_VERSION) { | ||
82 | printk(KERN_ERR "vNIC BAR0 res magic/version error " | ||
83 | "exp (%lx/%lx) curr (%x/%x)\n", | ||
84 | VNIC_RES_MAGIC, VNIC_RES_VERSION, | ||
85 | ioread32(&rh->magic), ioread32(&rh->version)); | ||
86 | return -EINVAL; | ||
87 | } | ||
88 | |||
89 | r = (struct vnic_resource __iomem *)(rh + 1); | ||
90 | |||
91 | while ((type = ioread8(&r->type)) != RES_TYPE_EOL) { | ||
92 | |||
93 | u8 bar_num = ioread8(&r->bar); | ||
94 | u32 bar_offset = ioread32(&r->bar_offset); | ||
95 | u32 count = ioread32(&r->count); | ||
96 | u32 len; | ||
97 | |||
98 | r++; | ||
99 | |||
100 | if (bar_num != 0) /* only mapping in BAR0 resources */ | ||
101 | continue; | ||
102 | |||
103 | switch (type) { | ||
104 | case RES_TYPE_WQ: | ||
105 | case RES_TYPE_RQ: | ||
106 | case RES_TYPE_CQ: | ||
107 | case RES_TYPE_INTR_CTRL: | ||
108 | /* each count is stride bytes long */ | ||
109 | len = count * VNIC_RES_STRIDE; | ||
110 | if (len + bar_offset > bar->len) { | ||
111 | printk(KERN_ERR "vNIC BAR0 resource %d " | ||
112 | "out-of-bounds, offset 0x%x + " | ||
113 | "size 0x%x > bar len 0x%lx\n", | ||
114 | type, bar_offset, | ||
115 | len, | ||
116 | bar->len); | ||
117 | return -EINVAL; | ||
118 | } | ||
119 | break; | ||
120 | case RES_TYPE_INTR_PBA_LEGACY: | ||
121 | case RES_TYPE_DEVCMD: | ||
122 | len = count; | ||
123 | break; | ||
124 | default: | ||
125 | continue; | ||
126 | } | ||
127 | |||
128 | vdev->res[type].count = count; | ||
129 | vdev->res[type].vaddr = (char __iomem *)bar->vaddr + bar_offset; | ||
130 | } | ||
131 | |||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev, | ||
136 | enum vnic_res_type type) | ||
137 | { | ||
138 | return vdev->res[type].count; | ||
139 | } | ||
140 | |||
141 | void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type, | ||
142 | unsigned int index) | ||
143 | { | ||
144 | if (!vdev->res[type].vaddr) | ||
145 | return NULL; | ||
146 | |||
147 | switch (type) { | ||
148 | case RES_TYPE_WQ: | ||
149 | case RES_TYPE_RQ: | ||
150 | case RES_TYPE_CQ: | ||
151 | case RES_TYPE_INTR_CTRL: | ||
152 | return (char __iomem *)vdev->res[type].vaddr + | ||
153 | index * VNIC_RES_STRIDE; | ||
154 | default: | ||
155 | return (char __iomem *)vdev->res[type].vaddr; | ||
156 | } | ||
157 | } | ||
158 | |||
159 | unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring, | ||
160 | unsigned int desc_count, | ||
161 | unsigned int desc_size) | ||
162 | { | ||
163 | /* The base address of the desc rings must be 512 byte aligned. | ||
164 | * Descriptor count is aligned to groups of 32 descriptors. A | ||
165 | * count of 0 means the maximum 4096 descriptors. Descriptor | ||
166 | * size is aligned to 16 bytes. | ||
167 | */ | ||
168 | |||
169 | unsigned int count_align = 32; | ||
170 | unsigned int desc_align = 16; | ||
171 | |||
172 | ring->base_align = 512; | ||
173 | |||
174 | if (desc_count == 0) | ||
175 | desc_count = 4096; | ||
176 | |||
177 | ring->desc_count = ALIGN(desc_count, count_align); | ||
178 | |||
179 | ring->desc_size = ALIGN(desc_size, desc_align); | ||
180 | |||
181 | ring->size = ring->desc_count * ring->desc_size; | ||
182 | ring->size_unaligned = ring->size + ring->base_align; | ||
183 | |||
184 | return ring->size_unaligned; | ||
185 | } | ||
186 | |||
187 | void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring) | ||
188 | { | ||
189 | memset(ring->descs, 0, ring->size); | ||
190 | } | ||
191 | |||
192 | int vnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring, | ||
193 | unsigned int desc_count, unsigned int desc_size) | ||
194 | { | ||
195 | vnic_dev_desc_ring_size(ring, desc_count, desc_size); | ||
196 | |||
197 | ring->descs_unaligned = pci_alloc_consistent(vdev->pdev, | ||
198 | ring->size_unaligned, | ||
199 | &ring->base_addr_unaligned); | ||
200 | |||
201 | if (!ring->descs_unaligned) { | ||
202 | printk(KERN_ERR | ||
203 | "Failed to allocate ring (size=%d), aborting\n", | ||
204 | (int)ring->size); | ||
205 | return -ENOMEM; | ||
206 | } | ||
207 | |||
208 | ring->base_addr = ALIGN(ring->base_addr_unaligned, | ||
209 | ring->base_align); | ||
210 | ring->descs = (u8 *)ring->descs_unaligned + | ||
211 | (ring->base_addr - ring->base_addr_unaligned); | ||
212 | |||
213 | vnic_dev_clear_desc_ring(ring); | ||
214 | |||
215 | ring->desc_avail = ring->desc_count - 1; | ||
216 | |||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | void vnic_dev_free_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring) | ||
221 | { | ||
222 | if (ring->descs) { | ||
223 | pci_free_consistent(vdev->pdev, | ||
224 | ring->size_unaligned, | ||
225 | ring->descs_unaligned, | ||
226 | ring->base_addr_unaligned); | ||
227 | ring->descs = NULL; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd, | ||
232 | u64 *a0, u64 *a1, int wait) | ||
233 | { | ||
234 | struct vnic_devcmd __iomem *devcmd = vdev->devcmd; | ||
235 | int delay; | ||
236 | u32 status; | ||
237 | int dev_cmd_err[] = { | ||
238 | /* convert from fw's version of error.h to host's version */ | ||
239 | 0, /* ERR_SUCCESS */ | ||
240 | EINVAL, /* ERR_EINVAL */ | ||
241 | EFAULT, /* ERR_EFAULT */ | ||
242 | EPERM, /* ERR_EPERM */ | ||
243 | EBUSY, /* ERR_EBUSY */ | ||
244 | }; | ||
245 | int err; | ||
246 | |||
247 | status = ioread32(&devcmd->status); | ||
248 | if (status & STAT_BUSY) { | ||
249 | printk(KERN_ERR "Busy devcmd %d\n", _CMD_N(cmd)); | ||
250 | return -EBUSY; | ||
251 | } | ||
252 | |||
253 | if (_CMD_DIR(cmd) & _CMD_DIR_WRITE) { | ||
254 | writeq(*a0, &devcmd->args[0]); | ||
255 | writeq(*a1, &devcmd->args[1]); | ||
256 | wmb(); | ||
257 | } | ||
258 | |||
259 | iowrite32(cmd, &devcmd->cmd); | ||
260 | |||
261 | if ((_CMD_FLAGS(cmd) & _CMD_FLAGS_NOWAIT)) | ||
262 | return 0; | ||
263 | |||
264 | for (delay = 0; delay < wait; delay++) { | ||
265 | |||
266 | udelay(100); | ||
267 | |||
268 | status = ioread32(&devcmd->status); | ||
269 | if (!(status & STAT_BUSY)) { | ||
270 | |||
271 | if (status & STAT_ERROR) { | ||
272 | err = dev_cmd_err[(int)readq(&devcmd->args[0])]; | ||
273 | printk(KERN_ERR "Error %d devcmd %d\n", | ||
274 | err, _CMD_N(cmd)); | ||
275 | return -err; | ||
276 | } | ||
277 | |||
278 | if (_CMD_DIR(cmd) & _CMD_DIR_READ) { | ||
279 | rmb(); | ||
280 | *a0 = readq(&devcmd->args[0]); | ||
281 | *a1 = readq(&devcmd->args[1]); | ||
282 | } | ||
283 | |||
284 | return 0; | ||
285 | } | ||
286 | } | ||
287 | |||
288 | printk(KERN_ERR "Timedout devcmd %d\n", _CMD_N(cmd)); | ||
289 | return -ETIMEDOUT; | ||
290 | } | ||
291 | |||
292 | int vnic_dev_fw_info(struct vnic_dev *vdev, | ||
293 | struct vnic_devcmd_fw_info **fw_info) | ||
294 | { | ||
295 | u64 a0, a1 = 0; | ||
296 | int wait = 1000; | ||
297 | int err = 0; | ||
298 | |||
299 | if (!vdev->fw_info) { | ||
300 | vdev->fw_info = pci_alloc_consistent(vdev->pdev, | ||
301 | sizeof(struct vnic_devcmd_fw_info), | ||
302 | &vdev->fw_info_pa); | ||
303 | if (!vdev->fw_info) | ||
304 | return -ENOMEM; | ||
305 | |||
306 | a0 = vdev->fw_info_pa; | ||
307 | |||
308 | /* only get fw_info once and cache it */ | ||
309 | err = vnic_dev_cmd(vdev, CMD_MCPU_FW_INFO, &a0, &a1, wait); | ||
310 | } | ||
311 | |||
312 | *fw_info = vdev->fw_info; | ||
313 | |||
314 | return err; | ||
315 | } | ||
316 | |||
317 | int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, unsigned int size, | ||
318 | void *value) | ||
319 | { | ||
320 | u64 a0, a1; | ||
321 | int wait = 1000; | ||
322 | int err; | ||
323 | |||
324 | a0 = offset; | ||
325 | a1 = size; | ||
326 | |||
327 | err = vnic_dev_cmd(vdev, CMD_DEV_SPEC, &a0, &a1, wait); | ||
328 | |||
329 | switch (size) { | ||
330 | case 1: | ||
331 | *(u8 *)value = (u8)a0; | ||
332 | break; | ||
333 | case 2: | ||
334 | *(u16 *)value = (u16)a0; | ||
335 | break; | ||
336 | case 4: | ||
337 | *(u32 *)value = (u32)a0; | ||
338 | break; | ||
339 | case 8: | ||
340 | *(u64 *)value = a0; | ||
341 | break; | ||
342 | default: | ||
343 | BUG(); | ||
344 | break; | ||
345 | } | ||
346 | |||
347 | return err; | ||
348 | } | ||
349 | |||
350 | int vnic_dev_stats_clear(struct vnic_dev *vdev) | ||
351 | { | ||
352 | u64 a0 = 0, a1 = 0; | ||
353 | int wait = 1000; | ||
354 | return vnic_dev_cmd(vdev, CMD_STATS_CLEAR, &a0, &a1, wait); | ||
355 | } | ||
356 | |||
357 | int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats) | ||
358 | { | ||
359 | u64 a0, a1; | ||
360 | int wait = 1000; | ||
361 | |||
362 | if (!vdev->stats) { | ||
363 | vdev->stats = pci_alloc_consistent(vdev->pdev, | ||
364 | sizeof(struct vnic_stats), &vdev->stats_pa); | ||
365 | if (!vdev->stats) | ||
366 | return -ENOMEM; | ||
367 | } | ||
368 | |||
369 | *stats = vdev->stats; | ||
370 | a0 = vdev->stats_pa; | ||
371 | a1 = sizeof(struct vnic_stats); | ||
372 | |||
373 | return vnic_dev_cmd(vdev, CMD_STATS_DUMP, &a0, &a1, wait); | ||
374 | } | ||
375 | |||
376 | int vnic_dev_close(struct vnic_dev *vdev) | ||
377 | { | ||
378 | u64 a0 = 0, a1 = 0; | ||
379 | int wait = 1000; | ||
380 | return vnic_dev_cmd(vdev, CMD_CLOSE, &a0, &a1, wait); | ||
381 | } | ||
382 | |||
383 | int vnic_dev_enable(struct vnic_dev *vdev) | ||
384 | { | ||
385 | u64 a0 = 0, a1 = 0; | ||
386 | int wait = 1000; | ||
387 | return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait); | ||
388 | } | ||
389 | |||
390 | int vnic_dev_disable(struct vnic_dev *vdev) | ||
391 | { | ||
392 | u64 a0 = 0, a1 = 0; | ||
393 | int wait = 1000; | ||
394 | return vnic_dev_cmd(vdev, CMD_DISABLE, &a0, &a1, wait); | ||
395 | } | ||
396 | |||
397 | int vnic_dev_open(struct vnic_dev *vdev, int arg) | ||
398 | { | ||
399 | u64 a0 = (u32)arg, a1 = 0; | ||
400 | int wait = 1000; | ||
401 | return vnic_dev_cmd(vdev, CMD_OPEN, &a0, &a1, wait); | ||
402 | } | ||
403 | |||
404 | int vnic_dev_open_done(struct vnic_dev *vdev, int *done) | ||
405 | { | ||
406 | u64 a0 = 0, a1 = 0; | ||
407 | int wait = 1000; | ||
408 | int err; | ||
409 | |||
410 | *done = 0; | ||
411 | |||
412 | err = vnic_dev_cmd(vdev, CMD_OPEN_STATUS, &a0, &a1, wait); | ||
413 | if (err) | ||
414 | return err; | ||
415 | |||
416 | *done = (a0 == 0); | ||
417 | |||
418 | return 0; | ||
419 | } | ||
420 | |||
421 | int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg) | ||
422 | { | ||
423 | u64 a0 = (u32)arg, a1 = 0; | ||
424 | int wait = 1000; | ||
425 | return vnic_dev_cmd(vdev, CMD_SOFT_RESET, &a0, &a1, wait); | ||
426 | } | ||
427 | |||
428 | int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done) | ||
429 | { | ||
430 | u64 a0 = 0, a1 = 0; | ||
431 | int wait = 1000; | ||
432 | int err; | ||
433 | |||
434 | *done = 0; | ||
435 | |||
436 | err = vnic_dev_cmd(vdev, CMD_SOFT_RESET_STATUS, &a0, &a1, wait); | ||
437 | if (err) | ||
438 | return err; | ||
439 | |||
440 | *done = (a0 == 0); | ||
441 | |||
442 | return 0; | ||
443 | } | ||
444 | |||
445 | int vnic_dev_hang_notify(struct vnic_dev *vdev) | ||
446 | { | ||
447 | u64 a0, a1; | ||
448 | int wait = 1000; | ||
449 | return vnic_dev_cmd(vdev, CMD_HANG_NOTIFY, &a0, &a1, wait); | ||
450 | } | ||
451 | |||
452 | int vnic_dev_mac_addr(struct vnic_dev *vdev, u8 *mac_addr) | ||
453 | { | ||
454 | u64 a0, a1; | ||
455 | int wait = 1000; | ||
456 | int err, i; | ||
457 | |||
458 | for (i = 0; i < ETH_ALEN; i++) | ||
459 | mac_addr[i] = 0; | ||
460 | |||
461 | err = vnic_dev_cmd(vdev, CMD_MAC_ADDR, &a0, &a1, wait); | ||
462 | if (err) | ||
463 | return err; | ||
464 | |||
465 | for (i = 0; i < ETH_ALEN; i++) | ||
466 | mac_addr[i] = ((u8 *)&a0)[i]; | ||
467 | |||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | void vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast, | ||
472 | int broadcast, int promisc, int allmulti) | ||
473 | { | ||
474 | u64 a0, a1 = 0; | ||
475 | int wait = 1000; | ||
476 | int err; | ||
477 | |||
478 | a0 = (directed ? CMD_PFILTER_DIRECTED : 0) | | ||
479 | (multicast ? CMD_PFILTER_MULTICAST : 0) | | ||
480 | (broadcast ? CMD_PFILTER_BROADCAST : 0) | | ||
481 | (promisc ? CMD_PFILTER_PROMISCUOUS : 0) | | ||
482 | (allmulti ? CMD_PFILTER_ALL_MULTICAST : 0); | ||
483 | |||
484 | err = vnic_dev_cmd(vdev, CMD_PACKET_FILTER, &a0, &a1, wait); | ||
485 | if (err) | ||
486 | printk(KERN_ERR "Can't set packet filter\n"); | ||
487 | } | ||
488 | |||
489 | void vnic_dev_add_addr(struct vnic_dev *vdev, u8 *addr) | ||
490 | { | ||
491 | u64 a0 = 0, a1 = 0; | ||
492 | int wait = 1000; | ||
493 | int err; | ||
494 | int i; | ||
495 | |||
496 | for (i = 0; i < ETH_ALEN; i++) | ||
497 | ((u8 *)&a0)[i] = addr[i]; | ||
498 | |||
499 | err = vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait); | ||
500 | if (err) | ||
501 | printk(KERN_ERR | ||
502 | "Can't add addr [%02x:%02x:%02x:%02x:%02x:%02x], %d\n", | ||
503 | addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], | ||
504 | err); | ||
505 | } | ||
506 | |||
507 | void vnic_dev_del_addr(struct vnic_dev *vdev, u8 *addr) | ||
508 | { | ||
509 | u64 a0 = 0, a1 = 0; | ||
510 | int wait = 1000; | ||
511 | int err; | ||
512 | int i; | ||
513 | |||
514 | for (i = 0; i < ETH_ALEN; i++) | ||
515 | ((u8 *)&a0)[i] = addr[i]; | ||
516 | |||
517 | err = vnic_dev_cmd(vdev, CMD_ADDR_DEL, &a0, &a1, wait); | ||
518 | if (err) | ||
519 | printk(KERN_ERR | ||
520 | "Can't del addr [%02x:%02x:%02x:%02x:%02x:%02x], %d\n", | ||
521 | addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], | ||
522 | err); | ||
523 | } | ||
524 | |||
525 | int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr) | ||
526 | { | ||
527 | u64 a0, a1; | ||
528 | int wait = 1000; | ||
529 | |||
530 | if (!vdev->notify) { | ||
531 | vdev->notify = pci_alloc_consistent(vdev->pdev, | ||
532 | sizeof(struct vnic_devcmd_notify), | ||
533 | &vdev->notify_pa); | ||
534 | if (!vdev->notify) | ||
535 | return -ENOMEM; | ||
536 | } | ||
537 | |||
538 | a0 = vdev->notify_pa; | ||
539 | a1 = ((u64)intr << 32) & 0x0000ffff00000000ULL; | ||
540 | a1 += sizeof(struct vnic_devcmd_notify); | ||
541 | |||
542 | return vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait); | ||
543 | } | ||
544 | |||
545 | void vnic_dev_notify_unset(struct vnic_dev *vdev) | ||
546 | { | ||
547 | u64 a0, a1; | ||
548 | int wait = 1000; | ||
549 | |||
550 | a0 = 0; /* paddr = 0 to unset notify buffer */ | ||
551 | a1 = 0x0000ffff00000000ULL; /* intr num = -1 to unreg for intr */ | ||
552 | a1 += sizeof(struct vnic_devcmd_notify); | ||
553 | |||
554 | vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait); | ||
555 | } | ||
556 | |||
557 | static int vnic_dev_notify_ready(struct vnic_dev *vdev) | ||
558 | { | ||
559 | u32 *words; | ||
560 | unsigned int nwords = sizeof(struct vnic_devcmd_notify) / 4; | ||
561 | unsigned int i; | ||
562 | u32 csum; | ||
563 | |||
564 | if (!vdev->notify) | ||
565 | return 0; | ||
566 | |||
567 | do { | ||
568 | csum = 0; | ||
569 | memcpy(&vdev->notify_copy, vdev->notify, | ||
570 | sizeof(struct vnic_devcmd_notify)); | ||
571 | words = (u32 *)&vdev->notify_copy; | ||
572 | for (i = 1; i < nwords; i++) | ||
573 | csum += words[i]; | ||
574 | } while (csum != words[0]); | ||
575 | |||
576 | return 1; | ||
577 | } | ||
578 | |||
579 | int vnic_dev_init(struct vnic_dev *vdev, int arg) | ||
580 | { | ||
581 | u64 a0 = (u32)arg, a1 = 0; | ||
582 | int wait = 1000; | ||
583 | return vnic_dev_cmd(vdev, CMD_INIT, &a0, &a1, wait); | ||
584 | } | ||
585 | |||
586 | int vnic_dev_link_status(struct vnic_dev *vdev) | ||
587 | { | ||
588 | if (vdev->linkstatus) | ||
589 | return *vdev->linkstatus; | ||
590 | |||
591 | if (!vnic_dev_notify_ready(vdev)) | ||
592 | return 0; | ||
593 | |||
594 | return vdev->notify_copy.link_state; | ||
595 | } | ||
596 | |||
597 | u32 vnic_dev_port_speed(struct vnic_dev *vdev) | ||
598 | { | ||
599 | if (!vnic_dev_notify_ready(vdev)) | ||
600 | return 0; | ||
601 | |||
602 | return vdev->notify_copy.port_speed; | ||
603 | } | ||
604 | |||
605 | u32 vnic_dev_msg_lvl(struct vnic_dev *vdev) | ||
606 | { | ||
607 | if (!vnic_dev_notify_ready(vdev)) | ||
608 | return 0; | ||
609 | |||
610 | return vdev->notify_copy.msglvl; | ||
611 | } | ||
612 | |||
613 | u32 vnic_dev_mtu(struct vnic_dev *vdev) | ||
614 | { | ||
615 | if (!vnic_dev_notify_ready(vdev)) | ||
616 | return 0; | ||
617 | |||
618 | return vdev->notify_copy.mtu; | ||
619 | } | ||
620 | |||
621 | u32 vnic_dev_link_down_cnt(struct vnic_dev *vdev) | ||
622 | { | ||
623 | if (!vnic_dev_notify_ready(vdev)) | ||
624 | return 0; | ||
625 | |||
626 | return vdev->notify_copy.link_down_cnt; | ||
627 | } | ||
628 | |||
629 | void vnic_dev_set_intr_mode(struct vnic_dev *vdev, | ||
630 | enum vnic_dev_intr_mode intr_mode) | ||
631 | { | ||
632 | vdev->intr_mode = intr_mode; | ||
633 | } | ||
634 | |||
635 | enum vnic_dev_intr_mode vnic_dev_get_intr_mode( | ||
636 | struct vnic_dev *vdev) | ||
637 | { | ||
638 | return vdev->intr_mode; | ||
639 | } | ||
640 | |||
641 | void vnic_dev_unregister(struct vnic_dev *vdev) | ||
642 | { | ||
643 | if (vdev) { | ||
644 | if (vdev->notify) | ||
645 | pci_free_consistent(vdev->pdev, | ||
646 | sizeof(struct vnic_devcmd_notify), | ||
647 | vdev->notify, | ||
648 | vdev->notify_pa); | ||
649 | if (vdev->linkstatus) | ||
650 | pci_free_consistent(vdev->pdev, | ||
651 | sizeof(u32), | ||
652 | vdev->linkstatus, | ||
653 | vdev->linkstatus_pa); | ||
654 | if (vdev->stats) | ||
655 | pci_free_consistent(vdev->pdev, | ||
656 | sizeof(struct vnic_dev), | ||
657 | vdev->stats, vdev->stats_pa); | ||
658 | if (vdev->fw_info) | ||
659 | pci_free_consistent(vdev->pdev, | ||
660 | sizeof(struct vnic_devcmd_fw_info), | ||
661 | vdev->fw_info, vdev->fw_info_pa); | ||
662 | kfree(vdev); | ||
663 | } | ||
664 | } | ||
665 | |||
666 | struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev, | ||
667 | void *priv, struct pci_dev *pdev, struct vnic_dev_bar *bar) | ||
668 | { | ||
669 | if (!vdev) { | ||
670 | vdev = kzalloc(sizeof(struct vnic_dev), GFP_KERNEL); | ||
671 | if (!vdev) | ||
672 | return NULL; | ||
673 | } | ||
674 | |||
675 | vdev->priv = priv; | ||
676 | vdev->pdev = pdev; | ||
677 | |||
678 | if (vnic_dev_discover_res(vdev, bar)) | ||
679 | goto err_out; | ||
680 | |||
681 | vdev->devcmd = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD, 0); | ||
682 | if (!vdev->devcmd) | ||
683 | goto err_out; | ||
684 | |||
685 | return vdev; | ||
686 | |||
687 | err_out: | ||
688 | vnic_dev_unregister(vdev); | ||
689 | return NULL; | ||
690 | } | ||
diff --git a/drivers/scsi/fnic/vnic_dev.h b/drivers/scsi/fnic/vnic_dev.h new file mode 100644 index 000000000000..f9935a8a5a09 --- /dev/null +++ b/drivers/scsi/fnic/vnic_dev.h | |||
@@ -0,0 +1,161 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_DEV_H_ | ||
19 | #define _VNIC_DEV_H_ | ||
20 | |||
21 | #include "vnic_resource.h" | ||
22 | #include "vnic_devcmd.h" | ||
23 | |||
24 | /* | ||
25 | * These defines avoid symbol clash between fnic and enic (Cisco 10G Eth | ||
26 | * Driver) when both are built with CONFIG options =y | ||
27 | */ | ||
28 | #define vnic_dev_priv fnic_dev_priv | ||
29 | #define vnic_dev_get_res_count fnic_dev_get_res_count | ||
30 | #define vnic_dev_get_res fnic_dev_get_res | ||
31 | #define vnic_dev_desc_ring_size fnic_dev_desc_ring_siz | ||
32 | #define vnic_dev_clear_desc_ring fnic_dev_clear_desc_ring | ||
33 | #define vnic_dev_alloc_desc_ring fnic_dev_alloc_desc_ring | ||
34 | #define vnic_dev_free_desc_ring fnic_dev_free_desc_ring | ||
35 | #define vnic_dev_cmd fnic_dev_cmd | ||
36 | #define vnic_dev_fw_info fnic_dev_fw_info | ||
37 | #define vnic_dev_spec fnic_dev_spec | ||
38 | #define vnic_dev_stats_clear fnic_dev_stats_clear | ||
39 | #define vnic_dev_stats_dump fnic_dev_stats_dump | ||
40 | #define vnic_dev_hang_notify fnic_dev_hang_notify | ||
41 | #define vnic_dev_packet_filter fnic_dev_packet_filter | ||
42 | #define vnic_dev_add_addr fnic_dev_add_addr | ||
43 | #define vnic_dev_del_addr fnic_dev_del_addr | ||
44 | #define vnic_dev_mac_addr fnic_dev_mac_addr | ||
45 | #define vnic_dev_notify_set fnic_dev_notify_set | ||
46 | #define vnic_dev_notify_unset fnic_dev_notify_unset | ||
47 | #define vnic_dev_link_status fnic_dev_link_status | ||
48 | #define vnic_dev_port_speed fnic_dev_port_speed | ||
49 | #define vnic_dev_msg_lvl fnic_dev_msg_lvl | ||
50 | #define vnic_dev_mtu fnic_dev_mtu | ||
51 | #define vnic_dev_link_down_cnt fnic_dev_link_down_cnt | ||
52 | #define vnic_dev_close fnic_dev_close | ||
53 | #define vnic_dev_enable fnic_dev_enable | ||
54 | #define vnic_dev_disable fnic_dev_disable | ||
55 | #define vnic_dev_open fnic_dev_open | ||
56 | #define vnic_dev_open_done fnic_dev_open_done | ||
57 | #define vnic_dev_init fnic_dev_init | ||
58 | #define vnic_dev_soft_reset fnic_dev_soft_reset | ||
59 | #define vnic_dev_soft_reset_done fnic_dev_soft_reset_done | ||
60 | #define vnic_dev_set_intr_mode fnic_dev_set_intr_mode | ||
61 | #define vnic_dev_get_intr_mode fnic_dev_get_intr_mode | ||
62 | #define vnic_dev_unregister fnic_dev_unregister | ||
63 | #define vnic_dev_register fnic_dev_register | ||
64 | |||
65 | #ifndef VNIC_PADDR_TARGET | ||
66 | #define VNIC_PADDR_TARGET 0x0000000000000000ULL | ||
67 | #endif | ||
68 | |||
69 | #ifndef readq | ||
70 | static inline u64 readq(void __iomem *reg) | ||
71 | { | ||
72 | return ((u64)readl(reg + 0x4UL) << 32) | (u64)readl(reg); | ||
73 | } | ||
74 | |||
75 | static inline void writeq(u64 val, void __iomem *reg) | ||
76 | { | ||
77 | writel(val & 0xffffffff, reg); | ||
78 | writel(val >> 32, reg + 0x4UL); | ||
79 | } | ||
80 | #endif | ||
81 | |||
82 | enum vnic_dev_intr_mode { | ||
83 | VNIC_DEV_INTR_MODE_UNKNOWN, | ||
84 | VNIC_DEV_INTR_MODE_INTX, | ||
85 | VNIC_DEV_INTR_MODE_MSI, | ||
86 | VNIC_DEV_INTR_MODE_MSIX, | ||
87 | }; | ||
88 | |||
89 | struct vnic_dev_bar { | ||
90 | void __iomem *vaddr; | ||
91 | dma_addr_t bus_addr; | ||
92 | unsigned long len; | ||
93 | }; | ||
94 | |||
95 | struct vnic_dev_ring { | ||
96 | void *descs; | ||
97 | size_t size; | ||
98 | dma_addr_t base_addr; | ||
99 | size_t base_align; | ||
100 | void *descs_unaligned; | ||
101 | size_t size_unaligned; | ||
102 | dma_addr_t base_addr_unaligned; | ||
103 | unsigned int desc_size; | ||
104 | unsigned int desc_count; | ||
105 | unsigned int desc_avail; | ||
106 | }; | ||
107 | |||
108 | struct vnic_dev; | ||
109 | struct vnic_stats; | ||
110 | |||
111 | void *vnic_dev_priv(struct vnic_dev *vdev); | ||
112 | unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev, | ||
113 | enum vnic_res_type type); | ||
114 | void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type, | ||
115 | unsigned int index); | ||
116 | unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring, | ||
117 | unsigned int desc_count, | ||
118 | unsigned int desc_size); | ||
119 | void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring); | ||
120 | int vnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring, | ||
121 | unsigned int desc_count, unsigned int desc_size); | ||
122 | void vnic_dev_free_desc_ring(struct vnic_dev *vdev, | ||
123 | struct vnic_dev_ring *ring); | ||
124 | int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd, | ||
125 | u64 *a0, u64 *a1, int wait); | ||
126 | int vnic_dev_fw_info(struct vnic_dev *vdev, | ||
127 | struct vnic_devcmd_fw_info **fw_info); | ||
128 | int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, | ||
129 | unsigned int size, void *value); | ||
130 | int vnic_dev_stats_clear(struct vnic_dev *vdev); | ||
131 | int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats); | ||
132 | int vnic_dev_hang_notify(struct vnic_dev *vdev); | ||
133 | void vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast, | ||
134 | int broadcast, int promisc, int allmulti); | ||
135 | void vnic_dev_add_addr(struct vnic_dev *vdev, u8 *addr); | ||
136 | void vnic_dev_del_addr(struct vnic_dev *vdev, u8 *addr); | ||
137 | int vnic_dev_mac_addr(struct vnic_dev *vdev, u8 *mac_addr); | ||
138 | int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr); | ||
139 | void vnic_dev_notify_unset(struct vnic_dev *vdev); | ||
140 | int vnic_dev_link_status(struct vnic_dev *vdev); | ||
141 | u32 vnic_dev_port_speed(struct vnic_dev *vdev); | ||
142 | u32 vnic_dev_msg_lvl(struct vnic_dev *vdev); | ||
143 | u32 vnic_dev_mtu(struct vnic_dev *vdev); | ||
144 | u32 vnic_dev_link_down_cnt(struct vnic_dev *vdev); | ||
145 | int vnic_dev_close(struct vnic_dev *vdev); | ||
146 | int vnic_dev_enable(struct vnic_dev *vdev); | ||
147 | int vnic_dev_disable(struct vnic_dev *vdev); | ||
148 | int vnic_dev_open(struct vnic_dev *vdev, int arg); | ||
149 | int vnic_dev_open_done(struct vnic_dev *vdev, int *done); | ||
150 | int vnic_dev_init(struct vnic_dev *vdev, int arg); | ||
151 | int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg); | ||
152 | int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done); | ||
153 | void vnic_dev_set_intr_mode(struct vnic_dev *vdev, | ||
154 | enum vnic_dev_intr_mode intr_mode); | ||
155 | enum vnic_dev_intr_mode vnic_dev_get_intr_mode(struct vnic_dev *vdev); | ||
156 | void vnic_dev_unregister(struct vnic_dev *vdev); | ||
157 | struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev, | ||
158 | void *priv, struct pci_dev *pdev, | ||
159 | struct vnic_dev_bar *bar); | ||
160 | |||
161 | #endif /* _VNIC_DEV_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_devcmd.h b/drivers/scsi/fnic/vnic_devcmd.h new file mode 100644 index 000000000000..d62b9061bf12 --- /dev/null +++ b/drivers/scsi/fnic/vnic_devcmd.h | |||
@@ -0,0 +1,281 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_DEVCMD_H_ | ||
19 | #define _VNIC_DEVCMD_H_ | ||
20 | |||
21 | #define _CMD_NBITS 14 | ||
22 | #define _CMD_VTYPEBITS 10 | ||
23 | #define _CMD_FLAGSBITS 6 | ||
24 | #define _CMD_DIRBITS 2 | ||
25 | |||
26 | #define _CMD_NMASK ((1 << _CMD_NBITS)-1) | ||
27 | #define _CMD_VTYPEMASK ((1 << _CMD_VTYPEBITS)-1) | ||
28 | #define _CMD_FLAGSMASK ((1 << _CMD_FLAGSBITS)-1) | ||
29 | #define _CMD_DIRMASK ((1 << _CMD_DIRBITS)-1) | ||
30 | |||
31 | #define _CMD_NSHIFT 0 | ||
32 | #define _CMD_VTYPESHIFT (_CMD_NSHIFT+_CMD_NBITS) | ||
33 | #define _CMD_FLAGSSHIFT (_CMD_VTYPESHIFT+_CMD_VTYPEBITS) | ||
34 | #define _CMD_DIRSHIFT (_CMD_FLAGSSHIFT+_CMD_FLAGSBITS) | ||
35 | |||
36 | /* | ||
37 | * Direction bits (from host perspective). | ||
38 | */ | ||
39 | #define _CMD_DIR_NONE 0U | ||
40 | #define _CMD_DIR_WRITE 1U | ||
41 | #define _CMD_DIR_READ 2U | ||
42 | #define _CMD_DIR_RW (_CMD_DIR_WRITE | _CMD_DIR_READ) | ||
43 | |||
44 | /* | ||
45 | * Flag bits. | ||
46 | */ | ||
47 | #define _CMD_FLAGS_NONE 0U | ||
48 | #define _CMD_FLAGS_NOWAIT 1U | ||
49 | |||
50 | /* | ||
51 | * vNIC type bits. | ||
52 | */ | ||
53 | #define _CMD_VTYPE_NONE 0U | ||
54 | #define _CMD_VTYPE_ENET 1U | ||
55 | #define _CMD_VTYPE_FC 2U | ||
56 | #define _CMD_VTYPE_SCSI 4U | ||
57 | #define _CMD_VTYPE_ALL (_CMD_VTYPE_ENET | _CMD_VTYPE_FC | _CMD_VTYPE_SCSI) | ||
58 | |||
59 | /* | ||
60 | * Used to create cmds.. | ||
61 | */ | ||
62 | #define _CMDCF(dir, flags, vtype, nr) \ | ||
63 | (((dir) << _CMD_DIRSHIFT) | \ | ||
64 | ((flags) << _CMD_FLAGSSHIFT) | \ | ||
65 | ((vtype) << _CMD_VTYPESHIFT) | \ | ||
66 | ((nr) << _CMD_NSHIFT)) | ||
67 | #define _CMDC(dir, vtype, nr) _CMDCF(dir, 0, vtype, nr) | ||
68 | #define _CMDCNW(dir, vtype, nr) _CMDCF(dir, _CMD_FLAGS_NOWAIT, vtype, nr) | ||
69 | |||
70 | /* | ||
71 | * Used to decode cmds.. | ||
72 | */ | ||
73 | #define _CMD_DIR(cmd) (((cmd) >> _CMD_DIRSHIFT) & _CMD_DIRMASK) | ||
74 | #define _CMD_FLAGS(cmd) (((cmd) >> _CMD_FLAGSSHIFT) & _CMD_FLAGSMASK) | ||
75 | #define _CMD_VTYPE(cmd) (((cmd) >> _CMD_VTYPESHIFT) & _CMD_VTYPEMASK) | ||
76 | #define _CMD_N(cmd) (((cmd) >> _CMD_NSHIFT) & _CMD_NMASK) | ||
77 | |||
78 | enum vnic_devcmd_cmd { | ||
79 | CMD_NONE = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_NONE, 0), | ||
80 | |||
81 | /* mcpu fw info in mem: (u64)a0=paddr to struct vnic_devcmd_fw_info */ | ||
82 | CMD_MCPU_FW_INFO = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 1), | ||
83 | |||
84 | /* dev-specific block member: | ||
85 | * in: (u16)a0=offset,(u8)a1=size | ||
86 | * out: a0=value */ | ||
87 | CMD_DEV_SPEC = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 2), | ||
88 | |||
89 | /* stats clear */ | ||
90 | CMD_STATS_CLEAR = _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 3), | ||
91 | |||
92 | /* stats dump in mem: (u64)a0=paddr to stats area, | ||
93 | * (u16)a1=sizeof stats area */ | ||
94 | CMD_STATS_DUMP = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 4), | ||
95 | |||
96 | /* set Rx packet filter: (u32)a0=filters (see CMD_PFILTER_*) */ | ||
97 | CMD_PACKET_FILTER = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 7), | ||
98 | |||
99 | /* hang detection notification */ | ||
100 | CMD_HANG_NOTIFY = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 8), | ||
101 | |||
102 | /* MAC address in (u48)a0 */ | ||
103 | CMD_MAC_ADDR = _CMDC(_CMD_DIR_READ, | ||
104 | _CMD_VTYPE_ENET | _CMD_VTYPE_FC, 9), | ||
105 | |||
106 | /* disable/enable promisc mode: (u8)a0=0/1 */ | ||
107 | /***** XXX DEPRECATED *****/ | ||
108 | CMD_PROMISC_MODE = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 10), | ||
109 | |||
110 | /* disable/enable all-multi mode: (u8)a0=0/1 */ | ||
111 | /***** XXX DEPRECATED *****/ | ||
112 | CMD_ALLMULTI_MODE = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 11), | ||
113 | |||
114 | /* add addr from (u48)a0 */ | ||
115 | CMD_ADDR_ADD = _CMDCNW(_CMD_DIR_WRITE, | ||
116 | _CMD_VTYPE_ENET | _CMD_VTYPE_FC, 12), | ||
117 | |||
118 | /* del addr from (u48)a0 */ | ||
119 | CMD_ADDR_DEL = _CMDCNW(_CMD_DIR_WRITE, | ||
120 | _CMD_VTYPE_ENET | _CMD_VTYPE_FC, 13), | ||
121 | |||
122 | /* add VLAN id in (u16)a0 */ | ||
123 | CMD_VLAN_ADD = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 14), | ||
124 | |||
125 | /* del VLAN id in (u16)a0 */ | ||
126 | CMD_VLAN_DEL = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 15), | ||
127 | |||
128 | /* nic_cfg in (u32)a0 */ | ||
129 | CMD_NIC_CFG = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 16), | ||
130 | |||
131 | /* union vnic_rss_key in mem: (u64)a0=paddr, (u16)a1=len */ | ||
132 | CMD_RSS_KEY = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 17), | ||
133 | |||
134 | /* union vnic_rss_cpu in mem: (u64)a0=paddr, (u16)a1=len */ | ||
135 | CMD_RSS_CPU = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 18), | ||
136 | |||
137 | /* initiate softreset */ | ||
138 | CMD_SOFT_RESET = _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 19), | ||
139 | |||
140 | /* softreset status: | ||
141 | * out: a0=0 reset complete, a0=1 reset in progress */ | ||
142 | CMD_SOFT_RESET_STATUS = _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 20), | ||
143 | |||
144 | /* set struct vnic_devcmd_notify buffer in mem: | ||
145 | * in: | ||
146 | * (u64)a0=paddr to notify (set paddr=0 to unset) | ||
147 | * (u32)a1 & 0x00000000ffffffff=sizeof(struct vnic_devcmd_notify) | ||
148 | * (u16)a1 & 0x0000ffff00000000=intr num (-1 for no intr) | ||
149 | * out: | ||
150 | * (u32)a1 = effective size | ||
151 | */ | ||
152 | CMD_NOTIFY = _CMDC(_CMD_DIR_RW, _CMD_VTYPE_ALL, 21), | ||
153 | |||
154 | /* UNDI API: (u64)a0=paddr to s_PXENV_UNDI_ struct, | ||
155 | * (u8)a1=PXENV_UNDI_xxx */ | ||
156 | CMD_UNDI = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 22), | ||
157 | |||
158 | /* initiate open sequence (u32)a0=flags (see CMD_OPENF_*) */ | ||
159 | CMD_OPEN = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 23), | ||
160 | |||
161 | /* open status: | ||
162 | * out: a0=0 open complete, a0=1 open in progress */ | ||
163 | CMD_OPEN_STATUS = _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 24), | ||
164 | |||
165 | /* close vnic */ | ||
166 | CMD_CLOSE = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 25), | ||
167 | |||
168 | /* initialize virtual link: (u32)a0=flags (see CMD_INITF_*) */ | ||
169 | CMD_INIT = _CMDCNW(_CMD_DIR_READ, _CMD_VTYPE_ALL, 26), | ||
170 | |||
171 | /* variant of CMD_INIT, with provisioning info | ||
172 | * (u64)a0=paddr of vnic_devcmd_provinfo | ||
173 | * (u32)a1=sizeof provision info */ | ||
174 | CMD_INIT_PROV_INFO = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 27), | ||
175 | |||
176 | /* enable virtual link */ | ||
177 | CMD_ENABLE = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 28), | ||
178 | |||
179 | /* disable virtual link */ | ||
180 | CMD_DISABLE = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 29), | ||
181 | |||
182 | /* stats dump all vnics on uplink in mem: (u64)a0=paddr (u32)a1=uif */ | ||
183 | CMD_STATS_DUMP_ALL = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 30), | ||
184 | |||
185 | /* init status: | ||
186 | * out: a0=0 init complete, a0=1 init in progress | ||
187 | * if a0=0, a1=errno */ | ||
188 | CMD_INIT_STATUS = _CMDC(_CMD_DIR_READ, _CMD_VTYPE_ALL, 31), | ||
189 | |||
190 | /* INT13 API: (u64)a0=paddr to vnic_int13_params struct | ||
191 | * (u8)a1=INT13_CMD_xxx */ | ||
192 | CMD_INT13 = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_FC, 32), | ||
193 | |||
194 | /* logical uplink enable/disable: (u64)a0: 0/1=disable/enable */ | ||
195 | CMD_LOGICAL_UPLINK = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 33), | ||
196 | |||
197 | /* undo initialize of virtual link */ | ||
198 | CMD_DEINIT = _CMDCNW(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 34), | ||
199 | }; | ||
200 | |||
201 | /* flags for CMD_OPEN */ | ||
202 | #define CMD_OPENF_OPROM 0x1 /* open coming from option rom */ | ||
203 | |||
204 | /* flags for CMD_INIT */ | ||
205 | #define CMD_INITF_DEFAULT_MAC 0x1 /* init with default mac addr */ | ||
206 | |||
207 | /* flags for CMD_PACKET_FILTER */ | ||
208 | #define CMD_PFILTER_DIRECTED 0x01 | ||
209 | #define CMD_PFILTER_MULTICAST 0x02 | ||
210 | #define CMD_PFILTER_BROADCAST 0x04 | ||
211 | #define CMD_PFILTER_PROMISCUOUS 0x08 | ||
212 | #define CMD_PFILTER_ALL_MULTICAST 0x10 | ||
213 | |||
214 | enum vnic_devcmd_status { | ||
215 | STAT_NONE = 0, | ||
216 | STAT_BUSY = 1 << 0, /* cmd in progress */ | ||
217 | STAT_ERROR = 1 << 1, /* last cmd caused error (code in a0) */ | ||
218 | }; | ||
219 | |||
220 | enum vnic_devcmd_error { | ||
221 | ERR_SUCCESS = 0, | ||
222 | ERR_EINVAL = 1, | ||
223 | ERR_EFAULT = 2, | ||
224 | ERR_EPERM = 3, | ||
225 | ERR_EBUSY = 4, | ||
226 | ERR_ECMDUNKNOWN = 5, | ||
227 | ERR_EBADSTATE = 6, | ||
228 | ERR_ENOMEM = 7, | ||
229 | ERR_ETIMEDOUT = 8, | ||
230 | ERR_ELINKDOWN = 9, | ||
231 | }; | ||
232 | |||
233 | struct vnic_devcmd_fw_info { | ||
234 | char fw_version[32]; | ||
235 | char fw_build[32]; | ||
236 | char hw_version[32]; | ||
237 | char hw_serial_number[32]; | ||
238 | }; | ||
239 | |||
240 | struct vnic_devcmd_notify { | ||
241 | u32 csum; /* checksum over following words */ | ||
242 | |||
243 | u32 link_state; /* link up == 1 */ | ||
244 | u32 port_speed; /* effective port speed (rate limit) */ | ||
245 | u32 mtu; /* MTU */ | ||
246 | u32 msglvl; /* requested driver msg lvl */ | ||
247 | u32 uif; /* uplink interface */ | ||
248 | u32 status; /* status bits (see VNIC_STF_*) */ | ||
249 | u32 error; /* error code (see ERR_*) for first ERR */ | ||
250 | u32 link_down_cnt; /* running count of link down transitions */ | ||
251 | }; | ||
252 | #define VNIC_STF_FATAL_ERR 0x0001 /* fatal fw error */ | ||
253 | |||
254 | struct vnic_devcmd_provinfo { | ||
255 | u8 oui[3]; | ||
256 | u8 type; | ||
257 | u8 data[0]; | ||
258 | }; | ||
259 | |||
260 | /* | ||
261 | * Writing cmd register causes STAT_BUSY to get set in status register. | ||
262 | * When cmd completes, STAT_BUSY will be cleared. | ||
263 | * | ||
264 | * If cmd completed successfully STAT_ERROR will be clear | ||
265 | * and args registers contain cmd-specific results. | ||
266 | * | ||
267 | * If cmd error, STAT_ERROR will be set and args[0] contains error code. | ||
268 | * | ||
269 | * status register is read-only. While STAT_BUSY is set, | ||
270 | * all other register contents are read-only. | ||
271 | */ | ||
272 | |||
273 | /* Make sizeof(vnic_devcmd) a power-of-2 for I/O BAR. */ | ||
274 | #define VNIC_DEVCMD_NARGS 15 | ||
275 | struct vnic_devcmd { | ||
276 | u32 status; /* RO */ | ||
277 | u32 cmd; /* RW */ | ||
278 | u64 args[VNIC_DEVCMD_NARGS]; /* RW cmd args (little-endian) */ | ||
279 | }; | ||
280 | |||
281 | #endif /* _VNIC_DEVCMD_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_intr.c b/drivers/scsi/fnic/vnic_intr.c new file mode 100644 index 000000000000..4f4dc8793d23 --- /dev/null +++ b/drivers/scsi/fnic/vnic_intr.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/pci.h> | ||
23 | #include <linux/delay.h> | ||
24 | #include "vnic_dev.h" | ||
25 | #include "vnic_intr.h" | ||
26 | |||
27 | void vnic_intr_free(struct vnic_intr *intr) | ||
28 | { | ||
29 | intr->ctrl = NULL; | ||
30 | } | ||
31 | |||
32 | int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr, | ||
33 | unsigned int index) | ||
34 | { | ||
35 | intr->index = index; | ||
36 | intr->vdev = vdev; | ||
37 | |||
38 | intr->ctrl = vnic_dev_get_res(vdev, RES_TYPE_INTR_CTRL, index); | ||
39 | if (!intr->ctrl) { | ||
40 | printk(KERN_ERR "Failed to hook INTR[%d].ctrl resource\n", | ||
41 | index); | ||
42 | return -EINVAL; | ||
43 | } | ||
44 | |||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | void vnic_intr_init(struct vnic_intr *intr, unsigned int coalescing_timer, | ||
49 | unsigned int coalescing_type, unsigned int mask_on_assertion) | ||
50 | { | ||
51 | iowrite32(coalescing_timer, &intr->ctrl->coalescing_timer); | ||
52 | iowrite32(coalescing_type, &intr->ctrl->coalescing_type); | ||
53 | iowrite32(mask_on_assertion, &intr->ctrl->mask_on_assertion); | ||
54 | iowrite32(0, &intr->ctrl->int_credits); | ||
55 | } | ||
56 | |||
57 | void vnic_intr_clean(struct vnic_intr *intr) | ||
58 | { | ||
59 | iowrite32(0, &intr->ctrl->int_credits); | ||
60 | } | ||
diff --git a/drivers/scsi/fnic/vnic_intr.h b/drivers/scsi/fnic/vnic_intr.h new file mode 100644 index 000000000000..d5fb40e7c98e --- /dev/null +++ b/drivers/scsi/fnic/vnic_intr.h | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_INTR_H_ | ||
19 | #define _VNIC_INTR_H_ | ||
20 | |||
21 | #include <linux/pci.h> | ||
22 | #include "vnic_dev.h" | ||
23 | |||
24 | /* | ||
25 | * These defines avoid symbol clash between fnic and enic (Cisco 10G Eth | ||
26 | * Driver) when both are built with CONFIG options =y | ||
27 | */ | ||
28 | #define vnic_intr_unmask fnic_intr_unmask | ||
29 | #define vnic_intr_mask fnic_intr_mask | ||
30 | #define vnic_intr_return_credits fnic_intr_return_credits | ||
31 | #define vnic_intr_credits fnic_intr_credits | ||
32 | #define vnic_intr_return_all_credits fnic_intr_return_all_credits | ||
33 | #define vnic_intr_legacy_pba fnic_intr_legacy_pba | ||
34 | #define vnic_intr_free fnic_intr_free | ||
35 | #define vnic_intr_alloc fnic_intr_alloc | ||
36 | #define vnic_intr_init fnic_intr_init | ||
37 | #define vnic_intr_clean fnic_intr_clean | ||
38 | |||
39 | #define VNIC_INTR_TIMER_MAX 0xffff | ||
40 | |||
41 | #define VNIC_INTR_TIMER_TYPE_ABS 0 | ||
42 | #define VNIC_INTR_TIMER_TYPE_QUIET 1 | ||
43 | |||
44 | /* Interrupt control */ | ||
45 | struct vnic_intr_ctrl { | ||
46 | u32 coalescing_timer; /* 0x00 */ | ||
47 | u32 pad0; | ||
48 | u32 coalescing_value; /* 0x08 */ | ||
49 | u32 pad1; | ||
50 | u32 coalescing_type; /* 0x10 */ | ||
51 | u32 pad2; | ||
52 | u32 mask_on_assertion; /* 0x18 */ | ||
53 | u32 pad3; | ||
54 | u32 mask; /* 0x20 */ | ||
55 | u32 pad4; | ||
56 | u32 int_credits; /* 0x28 */ | ||
57 | u32 pad5; | ||
58 | u32 int_credit_return; /* 0x30 */ | ||
59 | u32 pad6; | ||
60 | }; | ||
61 | |||
62 | struct vnic_intr { | ||
63 | unsigned int index; | ||
64 | struct vnic_dev *vdev; | ||
65 | struct vnic_intr_ctrl __iomem *ctrl; /* memory-mapped */ | ||
66 | }; | ||
67 | |||
68 | static inline void vnic_intr_unmask(struct vnic_intr *intr) | ||
69 | { | ||
70 | iowrite32(0, &intr->ctrl->mask); | ||
71 | } | ||
72 | |||
73 | static inline void vnic_intr_mask(struct vnic_intr *intr) | ||
74 | { | ||
75 | iowrite32(1, &intr->ctrl->mask); | ||
76 | } | ||
77 | |||
78 | static inline void vnic_intr_return_credits(struct vnic_intr *intr, | ||
79 | unsigned int credits, int unmask, int reset_timer) | ||
80 | { | ||
81 | #define VNIC_INTR_UNMASK_SHIFT 16 | ||
82 | #define VNIC_INTR_RESET_TIMER_SHIFT 17 | ||
83 | |||
84 | u32 int_credit_return = (credits & 0xffff) | | ||
85 | (unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) | | ||
86 | (reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0); | ||
87 | |||
88 | iowrite32(int_credit_return, &intr->ctrl->int_credit_return); | ||
89 | } | ||
90 | |||
91 | static inline unsigned int vnic_intr_credits(struct vnic_intr *intr) | ||
92 | { | ||
93 | return ioread32(&intr->ctrl->int_credits); | ||
94 | } | ||
95 | |||
96 | static inline void vnic_intr_return_all_credits(struct vnic_intr *intr) | ||
97 | { | ||
98 | unsigned int credits = vnic_intr_credits(intr); | ||
99 | int unmask = 1; | ||
100 | int reset_timer = 1; | ||
101 | |||
102 | vnic_intr_return_credits(intr, credits, unmask, reset_timer); | ||
103 | } | ||
104 | |||
105 | static inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba) | ||
106 | { | ||
107 | /* read PBA without clearing */ | ||
108 | return ioread32(legacy_pba); | ||
109 | } | ||
110 | |||
111 | void vnic_intr_free(struct vnic_intr *intr); | ||
112 | int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr, | ||
113 | unsigned int index); | ||
114 | void vnic_intr_init(struct vnic_intr *intr, unsigned int coalescing_timer, | ||
115 | unsigned int coalescing_type, unsigned int mask_on_assertion); | ||
116 | void vnic_intr_clean(struct vnic_intr *intr); | ||
117 | |||
118 | #endif /* _VNIC_INTR_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_nic.h b/drivers/scsi/fnic/vnic_nic.h new file mode 100644 index 000000000000..f15b83eeaced --- /dev/null +++ b/drivers/scsi/fnic/vnic_nic.h | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_NIC_H_ | ||
19 | #define _VNIC_NIC_H_ | ||
20 | |||
21 | /* | ||
22 | * These defines avoid symbol clash between fnic and enic (Cisco 10G Eth | ||
23 | * Driver) when both are built with CONFIG options =y | ||
24 | */ | ||
25 | #define vnic_set_nic_cfg fnic_set_nic_cfg | ||
26 | |||
27 | #define NIC_CFG_RSS_DEFAULT_CPU_MASK_FIELD 0xffUL | ||
28 | #define NIC_CFG_RSS_DEFAULT_CPU_SHIFT 0 | ||
29 | #define NIC_CFG_RSS_HASH_TYPE (0xffUL << 8) | ||
30 | #define NIC_CFG_RSS_HASH_TYPE_MASK_FIELD 0xffUL | ||
31 | #define NIC_CFG_RSS_HASH_TYPE_SHIFT 8 | ||
32 | #define NIC_CFG_RSS_HASH_BITS (7UL << 16) | ||
33 | #define NIC_CFG_RSS_HASH_BITS_MASK_FIELD 7UL | ||
34 | #define NIC_CFG_RSS_HASH_BITS_SHIFT 16 | ||
35 | #define NIC_CFG_RSS_BASE_CPU (7UL << 19) | ||
36 | #define NIC_CFG_RSS_BASE_CPU_MASK_FIELD 7UL | ||
37 | #define NIC_CFG_RSS_BASE_CPU_SHIFT 19 | ||
38 | #define NIC_CFG_RSS_ENABLE (1UL << 22) | ||
39 | #define NIC_CFG_RSS_ENABLE_MASK_FIELD 1UL | ||
40 | #define NIC_CFG_RSS_ENABLE_SHIFT 22 | ||
41 | #define NIC_CFG_TSO_IPID_SPLIT_EN (1UL << 23) | ||
42 | #define NIC_CFG_TSO_IPID_SPLIT_EN_MASK_FIELD 1UL | ||
43 | #define NIC_CFG_TSO_IPID_SPLIT_EN_SHIFT 23 | ||
44 | #define NIC_CFG_IG_VLAN_STRIP_EN (1UL << 24) | ||
45 | #define NIC_CFG_IG_VLAN_STRIP_EN_MASK_FIELD 1UL | ||
46 | #define NIC_CFG_IG_VLAN_STRIP_EN_SHIFT 24 | ||
47 | |||
48 | static inline void vnic_set_nic_cfg(u32 *nic_cfg, | ||
49 | u8 rss_default_cpu, u8 rss_hash_type, | ||
50 | u8 rss_hash_bits, u8 rss_base_cpu, | ||
51 | u8 rss_enable, u8 tso_ipid_split_en, | ||
52 | u8 ig_vlan_strip_en) | ||
53 | { | ||
54 | *nic_cfg = (rss_default_cpu & NIC_CFG_RSS_DEFAULT_CPU_MASK_FIELD) | | ||
55 | ((rss_hash_type & NIC_CFG_RSS_HASH_TYPE_MASK_FIELD) | ||
56 | << NIC_CFG_RSS_HASH_TYPE_SHIFT) | | ||
57 | ((rss_hash_bits & NIC_CFG_RSS_HASH_BITS_MASK_FIELD) | ||
58 | << NIC_CFG_RSS_HASH_BITS_SHIFT) | | ||
59 | ((rss_base_cpu & NIC_CFG_RSS_BASE_CPU_MASK_FIELD) | ||
60 | << NIC_CFG_RSS_BASE_CPU_SHIFT) | | ||
61 | ((rss_enable & NIC_CFG_RSS_ENABLE_MASK_FIELD) | ||
62 | << NIC_CFG_RSS_ENABLE_SHIFT) | | ||
63 | ((tso_ipid_split_en & NIC_CFG_TSO_IPID_SPLIT_EN_MASK_FIELD) | ||
64 | << NIC_CFG_TSO_IPID_SPLIT_EN_SHIFT) | | ||
65 | ((ig_vlan_strip_en & NIC_CFG_IG_VLAN_STRIP_EN_MASK_FIELD) | ||
66 | << NIC_CFG_IG_VLAN_STRIP_EN_SHIFT); | ||
67 | } | ||
68 | |||
69 | #endif /* _VNIC_NIC_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_resource.h b/drivers/scsi/fnic/vnic_resource.h new file mode 100644 index 000000000000..2d842f79d41a --- /dev/null +++ b/drivers/scsi/fnic/vnic_resource.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_RESOURCE_H_ | ||
19 | #define _VNIC_RESOURCE_H_ | ||
20 | |||
21 | #define VNIC_RES_MAGIC 0x766E6963L /* 'vnic' */ | ||
22 | #define VNIC_RES_VERSION 0x00000000L | ||
23 | |||
24 | /* vNIC resource types */ | ||
25 | enum vnic_res_type { | ||
26 | RES_TYPE_EOL, /* End-of-list */ | ||
27 | RES_TYPE_WQ, /* Work queues */ | ||
28 | RES_TYPE_RQ, /* Receive queues */ | ||
29 | RES_TYPE_CQ, /* Completion queues */ | ||
30 | RES_TYPE_RSVD1, | ||
31 | RES_TYPE_NIC_CFG, /* Enet NIC config registers */ | ||
32 | RES_TYPE_RSVD2, | ||
33 | RES_TYPE_RSVD3, | ||
34 | RES_TYPE_RSVD4, | ||
35 | RES_TYPE_RSVD5, | ||
36 | RES_TYPE_INTR_CTRL, /* Interrupt ctrl table */ | ||
37 | RES_TYPE_INTR_TABLE, /* MSI/MSI-X Interrupt table */ | ||
38 | RES_TYPE_INTR_PBA, /* MSI/MSI-X PBA table */ | ||
39 | RES_TYPE_INTR_PBA_LEGACY, /* Legacy intr status */ | ||
40 | RES_TYPE_RSVD6, | ||
41 | RES_TYPE_RSVD7, | ||
42 | RES_TYPE_DEVCMD, /* Device command region */ | ||
43 | RES_TYPE_PASS_THRU_PAGE, /* Pass-thru page */ | ||
44 | |||
45 | RES_TYPE_MAX, /* Count of resource types */ | ||
46 | }; | ||
47 | |||
48 | struct vnic_resource_header { | ||
49 | u32 magic; | ||
50 | u32 version; | ||
51 | }; | ||
52 | |||
53 | struct vnic_resource { | ||
54 | u8 type; | ||
55 | u8 bar; | ||
56 | u8 pad[2]; | ||
57 | u32 bar_offset; | ||
58 | u32 count; | ||
59 | }; | ||
60 | |||
61 | #endif /* _VNIC_RESOURCE_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_rq.c b/drivers/scsi/fnic/vnic_rq.c new file mode 100644 index 000000000000..bedd0d285630 --- /dev/null +++ b/drivers/scsi/fnic/vnic_rq.c | |||
@@ -0,0 +1,196 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <linux/errno.h> | ||
20 | #include <linux/types.h> | ||
21 | #include <linux/pci.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include "vnic_dev.h" | ||
24 | #include "vnic_rq.h" | ||
25 | |||
26 | static int vnic_rq_alloc_bufs(struct vnic_rq *rq) | ||
27 | { | ||
28 | struct vnic_rq_buf *buf; | ||
29 | struct vnic_dev *vdev; | ||
30 | unsigned int i, j, count = rq->ring.desc_count; | ||
31 | unsigned int blks = VNIC_RQ_BUF_BLKS_NEEDED(count); | ||
32 | |||
33 | vdev = rq->vdev; | ||
34 | |||
35 | for (i = 0; i < blks; i++) { | ||
36 | rq->bufs[i] = kzalloc(VNIC_RQ_BUF_BLK_SZ, GFP_ATOMIC); | ||
37 | if (!rq->bufs[i]) { | ||
38 | printk(KERN_ERR "Failed to alloc rq_bufs\n"); | ||
39 | return -ENOMEM; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | for (i = 0; i < blks; i++) { | ||
44 | buf = rq->bufs[i]; | ||
45 | for (j = 0; j < VNIC_RQ_BUF_BLK_ENTRIES; j++) { | ||
46 | buf->index = i * VNIC_RQ_BUF_BLK_ENTRIES + j; | ||
47 | buf->desc = (u8 *)rq->ring.descs + | ||
48 | rq->ring.desc_size * buf->index; | ||
49 | if (buf->index + 1 == count) { | ||
50 | buf->next = rq->bufs[0]; | ||
51 | break; | ||
52 | } else if (j + 1 == VNIC_RQ_BUF_BLK_ENTRIES) { | ||
53 | buf->next = rq->bufs[i + 1]; | ||
54 | } else { | ||
55 | buf->next = buf + 1; | ||
56 | buf++; | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | |||
61 | rq->to_use = rq->to_clean = rq->bufs[0]; | ||
62 | rq->buf_index = 0; | ||
63 | |||
64 | return 0; | ||
65 | } | ||
66 | |||
67 | void vnic_rq_free(struct vnic_rq *rq) | ||
68 | { | ||
69 | struct vnic_dev *vdev; | ||
70 | unsigned int i; | ||
71 | |||
72 | vdev = rq->vdev; | ||
73 | |||
74 | vnic_dev_free_desc_ring(vdev, &rq->ring); | ||
75 | |||
76 | for (i = 0; i < VNIC_RQ_BUF_BLKS_MAX; i++) { | ||
77 | kfree(rq->bufs[i]); | ||
78 | rq->bufs[i] = NULL; | ||
79 | } | ||
80 | |||
81 | rq->ctrl = NULL; | ||
82 | } | ||
83 | |||
84 | int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index, | ||
85 | unsigned int desc_count, unsigned int desc_size) | ||
86 | { | ||
87 | int err; | ||
88 | |||
89 | rq->index = index; | ||
90 | rq->vdev = vdev; | ||
91 | |||
92 | rq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_RQ, index); | ||
93 | if (!rq->ctrl) { | ||
94 | printk(KERN_ERR "Failed to hook RQ[%d] resource\n", index); | ||
95 | return -EINVAL; | ||
96 | } | ||
97 | |||
98 | vnic_rq_disable(rq); | ||
99 | |||
100 | err = vnic_dev_alloc_desc_ring(vdev, &rq->ring, desc_count, desc_size); | ||
101 | if (err) | ||
102 | return err; | ||
103 | |||
104 | err = vnic_rq_alloc_bufs(rq); | ||
105 | if (err) { | ||
106 | vnic_rq_free(rq); | ||
107 | return err; | ||
108 | } | ||
109 | |||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, | ||
114 | unsigned int error_interrupt_enable, | ||
115 | unsigned int error_interrupt_offset) | ||
116 | { | ||
117 | u64 paddr; | ||
118 | u32 fetch_index; | ||
119 | |||
120 | paddr = (u64)rq->ring.base_addr | VNIC_PADDR_TARGET; | ||
121 | writeq(paddr, &rq->ctrl->ring_base); | ||
122 | iowrite32(rq->ring.desc_count, &rq->ctrl->ring_size); | ||
123 | iowrite32(cq_index, &rq->ctrl->cq_index); | ||
124 | iowrite32(error_interrupt_enable, &rq->ctrl->error_interrupt_enable); | ||
125 | iowrite32(error_interrupt_offset, &rq->ctrl->error_interrupt_offset); | ||
126 | iowrite32(0, &rq->ctrl->dropped_packet_count); | ||
127 | iowrite32(0, &rq->ctrl->error_status); | ||
128 | |||
129 | /* Use current fetch_index as the ring starting point */ | ||
130 | fetch_index = ioread32(&rq->ctrl->fetch_index); | ||
131 | rq->to_use = rq->to_clean = | ||
132 | &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES] | ||
133 | [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES]; | ||
134 | iowrite32(fetch_index, &rq->ctrl->posted_index); | ||
135 | |||
136 | rq->buf_index = 0; | ||
137 | } | ||
138 | |||
139 | unsigned int vnic_rq_error_status(struct vnic_rq *rq) | ||
140 | { | ||
141 | return ioread32(&rq->ctrl->error_status); | ||
142 | } | ||
143 | |||
144 | void vnic_rq_enable(struct vnic_rq *rq) | ||
145 | { | ||
146 | iowrite32(1, &rq->ctrl->enable); | ||
147 | } | ||
148 | |||
149 | int vnic_rq_disable(struct vnic_rq *rq) | ||
150 | { | ||
151 | unsigned int wait; | ||
152 | |||
153 | iowrite32(0, &rq->ctrl->enable); | ||
154 | |||
155 | /* Wait for HW to ACK disable request */ | ||
156 | for (wait = 0; wait < 100; wait++) { | ||
157 | if (!(ioread32(&rq->ctrl->running))) | ||
158 | return 0; | ||
159 | udelay(1); | ||
160 | } | ||
161 | |||
162 | printk(KERN_ERR "Failed to disable RQ[%d]\n", rq->index); | ||
163 | |||
164 | return -ETIMEDOUT; | ||
165 | } | ||
166 | |||
167 | void vnic_rq_clean(struct vnic_rq *rq, | ||
168 | void (*buf_clean)(struct vnic_rq *rq, struct vnic_rq_buf *buf)) | ||
169 | { | ||
170 | struct vnic_rq_buf *buf; | ||
171 | u32 fetch_index; | ||
172 | |||
173 | BUG_ON(ioread32(&rq->ctrl->enable)); | ||
174 | |||
175 | buf = rq->to_clean; | ||
176 | |||
177 | while (vnic_rq_desc_used(rq) > 0) { | ||
178 | |||
179 | (*buf_clean)(rq, buf); | ||
180 | |||
181 | buf = rq->to_clean = buf->next; | ||
182 | rq->ring.desc_avail++; | ||
183 | } | ||
184 | |||
185 | /* Use current fetch_index as the ring starting point */ | ||
186 | fetch_index = ioread32(&rq->ctrl->fetch_index); | ||
187 | rq->to_use = rq->to_clean = | ||
188 | &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES] | ||
189 | [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES]; | ||
190 | iowrite32(fetch_index, &rq->ctrl->posted_index); | ||
191 | |||
192 | rq->buf_index = 0; | ||
193 | |||
194 | vnic_dev_clear_desc_ring(&rq->ring); | ||
195 | } | ||
196 | |||
diff --git a/drivers/scsi/fnic/vnic_rq.h b/drivers/scsi/fnic/vnic_rq.h new file mode 100644 index 000000000000..aebdfbd6ad3c --- /dev/null +++ b/drivers/scsi/fnic/vnic_rq.h | |||
@@ -0,0 +1,235 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_RQ_H_ | ||
19 | #define _VNIC_RQ_H_ | ||
20 | |||
21 | #include <linux/pci.h> | ||
22 | #include "vnic_dev.h" | ||
23 | #include "vnic_cq.h" | ||
24 | |||
25 | /* | ||
26 | * These defines avoid symbol clash between fnic and enic (Cisco 10G Eth | ||
27 | * Driver) when both are built with CONFIG options =y | ||
28 | */ | ||
29 | #define vnic_rq_desc_avail fnic_rq_desc_avail | ||
30 | #define vnic_rq_desc_used fnic_rq_desc_used | ||
31 | #define vnic_rq_next_desc fnic_rq_next_desc | ||
32 | #define vnic_rq_next_index fnic_rq_next_index | ||
33 | #define vnic_rq_next_buf_index fnic_rq_next_buf_index | ||
34 | #define vnic_rq_post fnic_rq_post | ||
35 | #define vnic_rq_posting_soon fnic_rq_posting_soon | ||
36 | #define vnic_rq_return_descs fnic_rq_return_descs | ||
37 | #define vnic_rq_service fnic_rq_service | ||
38 | #define vnic_rq_fill fnic_rq_fill | ||
39 | #define vnic_rq_free fnic_rq_free | ||
40 | #define vnic_rq_alloc fnic_rq_alloc | ||
41 | #define vnic_rq_init fnic_rq_init | ||
42 | #define vnic_rq_error_status fnic_rq_error_status | ||
43 | #define vnic_rq_enable fnic_rq_enable | ||
44 | #define vnic_rq_disable fnic_rq_disable | ||
45 | #define vnic_rq_clean fnic_rq_clean | ||
46 | |||
47 | /* Receive queue control */ | ||
48 | struct vnic_rq_ctrl { | ||
49 | u64 ring_base; /* 0x00 */ | ||
50 | u32 ring_size; /* 0x08 */ | ||
51 | u32 pad0; | ||
52 | u32 posted_index; /* 0x10 */ | ||
53 | u32 pad1; | ||
54 | u32 cq_index; /* 0x18 */ | ||
55 | u32 pad2; | ||
56 | u32 enable; /* 0x20 */ | ||
57 | u32 pad3; | ||
58 | u32 running; /* 0x28 */ | ||
59 | u32 pad4; | ||
60 | u32 fetch_index; /* 0x30 */ | ||
61 | u32 pad5; | ||
62 | u32 error_interrupt_enable; /* 0x38 */ | ||
63 | u32 pad6; | ||
64 | u32 error_interrupt_offset; /* 0x40 */ | ||
65 | u32 pad7; | ||
66 | u32 error_status; /* 0x48 */ | ||
67 | u32 pad8; | ||
68 | u32 dropped_packet_count; /* 0x50 */ | ||
69 | u32 pad9; | ||
70 | u32 dropped_packet_count_rc; /* 0x58 */ | ||
71 | u32 pad10; | ||
72 | }; | ||
73 | |||
74 | /* Break the vnic_rq_buf allocations into blocks of 64 entries */ | ||
75 | #define VNIC_RQ_BUF_BLK_ENTRIES 64 | ||
76 | #define VNIC_RQ_BUF_BLK_SZ \ | ||
77 | (VNIC_RQ_BUF_BLK_ENTRIES * sizeof(struct vnic_rq_buf)) | ||
78 | #define VNIC_RQ_BUF_BLKS_NEEDED(entries) \ | ||
79 | DIV_ROUND_UP(entries, VNIC_RQ_BUF_BLK_ENTRIES) | ||
80 | #define VNIC_RQ_BUF_BLKS_MAX VNIC_RQ_BUF_BLKS_NEEDED(4096) | ||
81 | |||
82 | struct vnic_rq_buf { | ||
83 | struct vnic_rq_buf *next; | ||
84 | dma_addr_t dma_addr; | ||
85 | void *os_buf; | ||
86 | unsigned int os_buf_index; | ||
87 | unsigned int len; | ||
88 | unsigned int index; | ||
89 | void *desc; | ||
90 | }; | ||
91 | |||
92 | struct vnic_rq { | ||
93 | unsigned int index; | ||
94 | struct vnic_dev *vdev; | ||
95 | struct vnic_rq_ctrl __iomem *ctrl; /* memory-mapped */ | ||
96 | struct vnic_dev_ring ring; | ||
97 | struct vnic_rq_buf *bufs[VNIC_RQ_BUF_BLKS_MAX]; | ||
98 | struct vnic_rq_buf *to_use; | ||
99 | struct vnic_rq_buf *to_clean; | ||
100 | void *os_buf_head; | ||
101 | unsigned int buf_index; | ||
102 | unsigned int pkts_outstanding; | ||
103 | }; | ||
104 | |||
105 | static inline unsigned int vnic_rq_desc_avail(struct vnic_rq *rq) | ||
106 | { | ||
107 | /* how many does SW own? */ | ||
108 | return rq->ring.desc_avail; | ||
109 | } | ||
110 | |||
111 | static inline unsigned int vnic_rq_desc_used(struct vnic_rq *rq) | ||
112 | { | ||
113 | /* how many does HW own? */ | ||
114 | return rq->ring.desc_count - rq->ring.desc_avail - 1; | ||
115 | } | ||
116 | |||
117 | static inline void *vnic_rq_next_desc(struct vnic_rq *rq) | ||
118 | { | ||
119 | return rq->to_use->desc; | ||
120 | } | ||
121 | |||
122 | static inline unsigned int vnic_rq_next_index(struct vnic_rq *rq) | ||
123 | { | ||
124 | return rq->to_use->index; | ||
125 | } | ||
126 | |||
127 | static inline unsigned int vnic_rq_next_buf_index(struct vnic_rq *rq) | ||
128 | { | ||
129 | return rq->buf_index++; | ||
130 | } | ||
131 | |||
132 | static inline void vnic_rq_post(struct vnic_rq *rq, | ||
133 | void *os_buf, unsigned int os_buf_index, | ||
134 | dma_addr_t dma_addr, unsigned int len) | ||
135 | { | ||
136 | struct vnic_rq_buf *buf = rq->to_use; | ||
137 | |||
138 | buf->os_buf = os_buf; | ||
139 | buf->os_buf_index = os_buf_index; | ||
140 | buf->dma_addr = dma_addr; | ||
141 | buf->len = len; | ||
142 | |||
143 | buf = buf->next; | ||
144 | rq->to_use = buf; | ||
145 | rq->ring.desc_avail--; | ||
146 | |||
147 | /* Move the posted_index every nth descriptor | ||
148 | */ | ||
149 | |||
150 | #ifndef VNIC_RQ_RETURN_RATE | ||
151 | #define VNIC_RQ_RETURN_RATE 0xf /* keep 2^n - 1 */ | ||
152 | #endif | ||
153 | |||
154 | if ((buf->index & VNIC_RQ_RETURN_RATE) == 0) { | ||
155 | /* Adding write memory barrier prevents compiler and/or CPU | ||
156 | * reordering, thus avoiding descriptor posting before | ||
157 | * descriptor is initialized. Otherwise, hardware can read | ||
158 | * stale descriptor fields. | ||
159 | */ | ||
160 | wmb(); | ||
161 | iowrite32(buf->index, &rq->ctrl->posted_index); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | static inline int vnic_rq_posting_soon(struct vnic_rq *rq) | ||
166 | { | ||
167 | return (rq->to_use->index & VNIC_RQ_RETURN_RATE) == 0; | ||
168 | } | ||
169 | |||
170 | static inline void vnic_rq_return_descs(struct vnic_rq *rq, unsigned int count) | ||
171 | { | ||
172 | rq->ring.desc_avail += count; | ||
173 | } | ||
174 | |||
175 | enum desc_return_options { | ||
176 | VNIC_RQ_RETURN_DESC, | ||
177 | VNIC_RQ_DEFER_RETURN_DESC, | ||
178 | }; | ||
179 | |||
180 | static inline void vnic_rq_service(struct vnic_rq *rq, | ||
181 | struct cq_desc *cq_desc, u16 completed_index, | ||
182 | int desc_return, void (*buf_service)(struct vnic_rq *rq, | ||
183 | struct cq_desc *cq_desc, struct vnic_rq_buf *buf, | ||
184 | int skipped, void *opaque), void *opaque) | ||
185 | { | ||
186 | struct vnic_rq_buf *buf; | ||
187 | int skipped; | ||
188 | |||
189 | buf = rq->to_clean; | ||
190 | while (1) { | ||
191 | |||
192 | skipped = (buf->index != completed_index); | ||
193 | |||
194 | (*buf_service)(rq, cq_desc, buf, skipped, opaque); | ||
195 | |||
196 | if (desc_return == VNIC_RQ_RETURN_DESC) | ||
197 | rq->ring.desc_avail++; | ||
198 | |||
199 | rq->to_clean = buf->next; | ||
200 | |||
201 | if (!skipped) | ||
202 | break; | ||
203 | |||
204 | buf = rq->to_clean; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | static inline int vnic_rq_fill(struct vnic_rq *rq, | ||
209 | int (*buf_fill)(struct vnic_rq *rq)) | ||
210 | { | ||
211 | int err; | ||
212 | |||
213 | while (vnic_rq_desc_avail(rq) > 1) { | ||
214 | |||
215 | err = (*buf_fill)(rq); | ||
216 | if (err) | ||
217 | return err; | ||
218 | } | ||
219 | |||
220 | return 0; | ||
221 | } | ||
222 | |||
223 | void vnic_rq_free(struct vnic_rq *rq); | ||
224 | int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index, | ||
225 | unsigned int desc_count, unsigned int desc_size); | ||
226 | void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, | ||
227 | unsigned int error_interrupt_enable, | ||
228 | unsigned int error_interrupt_offset); | ||
229 | unsigned int vnic_rq_error_status(struct vnic_rq *rq); | ||
230 | void vnic_rq_enable(struct vnic_rq *rq); | ||
231 | int vnic_rq_disable(struct vnic_rq *rq); | ||
232 | void vnic_rq_clean(struct vnic_rq *rq, | ||
233 | void (*buf_clean)(struct vnic_rq *rq, struct vnic_rq_buf *buf)); | ||
234 | |||
235 | #endif /* _VNIC_RQ_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_scsi.h b/drivers/scsi/fnic/vnic_scsi.h new file mode 100644 index 000000000000..46baa5254001 --- /dev/null +++ b/drivers/scsi/fnic/vnic_scsi.h | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_SCSI_H_ | ||
19 | #define _VNIC_SCSI_H_ | ||
20 | |||
21 | #define VNIC_FNIC_WQ_COPY_COUNT_MIN 1 | ||
22 | #define VNIC_FNIC_WQ_COPY_COUNT_MAX 1 | ||
23 | |||
24 | #define VNIC_FNIC_WQ_DESCS_MIN 64 | ||
25 | #define VNIC_FNIC_WQ_DESCS_MAX 128 | ||
26 | |||
27 | #define VNIC_FNIC_WQ_COPY_DESCS_MIN 64 | ||
28 | #define VNIC_FNIC_WQ_COPY_DESCS_MAX 512 | ||
29 | |||
30 | #define VNIC_FNIC_RQ_DESCS_MIN 64 | ||
31 | #define VNIC_FNIC_RQ_DESCS_MAX 128 | ||
32 | |||
33 | #define VNIC_FNIC_EDTOV_MIN 1000 | ||
34 | #define VNIC_FNIC_EDTOV_MAX 255000 | ||
35 | #define VNIC_FNIC_EDTOV_DEF 2000 | ||
36 | |||
37 | #define VNIC_FNIC_RATOV_MIN 1000 | ||
38 | #define VNIC_FNIC_RATOV_MAX 255000 | ||
39 | |||
40 | #define VNIC_FNIC_MAXDATAFIELDSIZE_MIN 256 | ||
41 | #define VNIC_FNIC_MAXDATAFIELDSIZE_MAX 2112 | ||
42 | |||
43 | #define VNIC_FNIC_FLOGI_RETRIES_MIN 0 | ||
44 | #define VNIC_FNIC_FLOGI_RETRIES_MAX 0xffffffff | ||
45 | #define VNIC_FNIC_FLOGI_RETRIES_DEF 0xffffffff | ||
46 | |||
47 | #define VNIC_FNIC_FLOGI_TIMEOUT_MIN 1000 | ||
48 | #define VNIC_FNIC_FLOGI_TIMEOUT_MAX 255000 | ||
49 | |||
50 | #define VNIC_FNIC_PLOGI_RETRIES_MIN 0 | ||
51 | #define VNIC_FNIC_PLOGI_RETRIES_MAX 255 | ||
52 | #define VNIC_FNIC_PLOGI_RETRIES_DEF 8 | ||
53 | |||
54 | #define VNIC_FNIC_PLOGI_TIMEOUT_MIN 1000 | ||
55 | #define VNIC_FNIC_PLOGI_TIMEOUT_MAX 255000 | ||
56 | |||
57 | #define VNIC_FNIC_IO_THROTTLE_COUNT_MIN 256 | ||
58 | #define VNIC_FNIC_IO_THROTTLE_COUNT_MAX 4096 | ||
59 | |||
60 | #define VNIC_FNIC_LINK_DOWN_TIMEOUT_MIN 0 | ||
61 | #define VNIC_FNIC_LINK_DOWN_TIMEOUT_MAX 240000 | ||
62 | |||
63 | #define VNIC_FNIC_PORT_DOWN_TIMEOUT_MIN 0 | ||
64 | #define VNIC_FNIC_PORT_DOWN_TIMEOUT_MAX 240000 | ||
65 | |||
66 | #define VNIC_FNIC_PORT_DOWN_IO_RETRIES_MIN 0 | ||
67 | #define VNIC_FNIC_PORT_DOWN_IO_RETRIES_MAX 255 | ||
68 | |||
69 | #define VNIC_FNIC_LUNS_PER_TARGET_MIN 1 | ||
70 | #define VNIC_FNIC_LUNS_PER_TARGET_MAX 1024 | ||
71 | |||
72 | /* Device-specific region: scsi configuration */ | ||
73 | struct vnic_fc_config { | ||
74 | u64 node_wwn; | ||
75 | u64 port_wwn; | ||
76 | u32 flags; | ||
77 | u32 wq_enet_desc_count; | ||
78 | u32 wq_copy_desc_count; | ||
79 | u32 rq_desc_count; | ||
80 | u32 flogi_retries; | ||
81 | u32 flogi_timeout; | ||
82 | u32 plogi_retries; | ||
83 | u32 plogi_timeout; | ||
84 | u32 io_throttle_count; | ||
85 | u32 link_down_timeout; | ||
86 | u32 port_down_timeout; | ||
87 | u32 port_down_io_retries; | ||
88 | u32 luns_per_tgt; | ||
89 | u16 maxdatafieldsize; | ||
90 | u16 ed_tov; | ||
91 | u16 ra_tov; | ||
92 | u16 intr_timer; | ||
93 | u8 intr_timer_type; | ||
94 | }; | ||
95 | |||
96 | #define VFCF_FCP_SEQ_LVL_ERR 0x1 /* Enable FCP-2 Error Recovery */ | ||
97 | #define VFCF_PERBI 0x2 /* persistent binding info available */ | ||
98 | |||
99 | #endif /* _VNIC_SCSI_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_stats.h b/drivers/scsi/fnic/vnic_stats.h new file mode 100644 index 000000000000..5372e23c1cb3 --- /dev/null +++ b/drivers/scsi/fnic/vnic_stats.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_STATS_H_ | ||
19 | #define _VNIC_STATS_H_ | ||
20 | |||
21 | /* Tx statistics */ | ||
22 | struct vnic_tx_stats { | ||
23 | u64 tx_frames_ok; | ||
24 | u64 tx_unicast_frames_ok; | ||
25 | u64 tx_multicast_frames_ok; | ||
26 | u64 tx_broadcast_frames_ok; | ||
27 | u64 tx_bytes_ok; | ||
28 | u64 tx_unicast_bytes_ok; | ||
29 | u64 tx_multicast_bytes_ok; | ||
30 | u64 tx_broadcast_bytes_ok; | ||
31 | u64 tx_drops; | ||
32 | u64 tx_errors; | ||
33 | u64 tx_tso; | ||
34 | u64 rsvd[16]; | ||
35 | }; | ||
36 | |||
37 | /* Rx statistics */ | ||
38 | struct vnic_rx_stats { | ||
39 | u64 rx_frames_ok; | ||
40 | u64 rx_frames_total; | ||
41 | u64 rx_unicast_frames_ok; | ||
42 | u64 rx_multicast_frames_ok; | ||
43 | u64 rx_broadcast_frames_ok; | ||
44 | u64 rx_bytes_ok; | ||
45 | u64 rx_unicast_bytes_ok; | ||
46 | u64 rx_multicast_bytes_ok; | ||
47 | u64 rx_broadcast_bytes_ok; | ||
48 | u64 rx_drop; | ||
49 | u64 rx_no_bufs; | ||
50 | u64 rx_errors; | ||
51 | u64 rx_rss; | ||
52 | u64 rx_crc_errors; | ||
53 | u64 rx_frames_64; | ||
54 | u64 rx_frames_127; | ||
55 | u64 rx_frames_255; | ||
56 | u64 rx_frames_511; | ||
57 | u64 rx_frames_1023; | ||
58 | u64 rx_frames_1518; | ||
59 | u64 rx_frames_to_max; | ||
60 | u64 rsvd[16]; | ||
61 | }; | ||
62 | |||
63 | struct vnic_stats { | ||
64 | struct vnic_tx_stats tx; | ||
65 | struct vnic_rx_stats rx; | ||
66 | }; | ||
67 | |||
68 | #endif /* _VNIC_STATS_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_wq.c b/drivers/scsi/fnic/vnic_wq.c new file mode 100644 index 000000000000..1f9ea790d130 --- /dev/null +++ b/drivers/scsi/fnic/vnic_wq.c | |||
@@ -0,0 +1,182 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <linux/errno.h> | ||
20 | #include <linux/types.h> | ||
21 | #include <linux/pci.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include "vnic_dev.h" | ||
24 | #include "vnic_wq.h" | ||
25 | |||
26 | static int vnic_wq_alloc_bufs(struct vnic_wq *wq) | ||
27 | { | ||
28 | struct vnic_wq_buf *buf; | ||
29 | struct vnic_dev *vdev; | ||
30 | unsigned int i, j, count = wq->ring.desc_count; | ||
31 | unsigned int blks = VNIC_WQ_BUF_BLKS_NEEDED(count); | ||
32 | |||
33 | vdev = wq->vdev; | ||
34 | |||
35 | for (i = 0; i < blks; i++) { | ||
36 | wq->bufs[i] = kzalloc(VNIC_WQ_BUF_BLK_SZ, GFP_ATOMIC); | ||
37 | if (!wq->bufs[i]) { | ||
38 | printk(KERN_ERR "Failed to alloc wq_bufs\n"); | ||
39 | return -ENOMEM; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | for (i = 0; i < blks; i++) { | ||
44 | buf = wq->bufs[i]; | ||
45 | for (j = 0; j < VNIC_WQ_BUF_BLK_ENTRIES; j++) { | ||
46 | buf->index = i * VNIC_WQ_BUF_BLK_ENTRIES + j; | ||
47 | buf->desc = (u8 *)wq->ring.descs + | ||
48 | wq->ring.desc_size * buf->index; | ||
49 | if (buf->index + 1 == count) { | ||
50 | buf->next = wq->bufs[0]; | ||
51 | break; | ||
52 | } else if (j + 1 == VNIC_WQ_BUF_BLK_ENTRIES) { | ||
53 | buf->next = wq->bufs[i + 1]; | ||
54 | } else { | ||
55 | buf->next = buf + 1; | ||
56 | buf++; | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | |||
61 | wq->to_use = wq->to_clean = wq->bufs[0]; | ||
62 | |||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | void vnic_wq_free(struct vnic_wq *wq) | ||
67 | { | ||
68 | struct vnic_dev *vdev; | ||
69 | unsigned int i; | ||
70 | |||
71 | vdev = wq->vdev; | ||
72 | |||
73 | vnic_dev_free_desc_ring(vdev, &wq->ring); | ||
74 | |||
75 | for (i = 0; i < VNIC_WQ_BUF_BLKS_MAX; i++) { | ||
76 | kfree(wq->bufs[i]); | ||
77 | wq->bufs[i] = NULL; | ||
78 | } | ||
79 | |||
80 | wq->ctrl = NULL; | ||
81 | |||
82 | } | ||
83 | |||
84 | int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index, | ||
85 | unsigned int desc_count, unsigned int desc_size) | ||
86 | { | ||
87 | int err; | ||
88 | |||
89 | wq->index = index; | ||
90 | wq->vdev = vdev; | ||
91 | |||
92 | wq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_WQ, index); | ||
93 | if (!wq->ctrl) { | ||
94 | printk(KERN_ERR "Failed to hook WQ[%d] resource\n", index); | ||
95 | return -EINVAL; | ||
96 | } | ||
97 | |||
98 | vnic_wq_disable(wq); | ||
99 | |||
100 | err = vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size); | ||
101 | if (err) | ||
102 | return err; | ||
103 | |||
104 | err = vnic_wq_alloc_bufs(wq); | ||
105 | if (err) { | ||
106 | vnic_wq_free(wq); | ||
107 | return err; | ||
108 | } | ||
109 | |||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, | ||
114 | unsigned int error_interrupt_enable, | ||
115 | unsigned int error_interrupt_offset) | ||
116 | { | ||
117 | u64 paddr; | ||
118 | |||
119 | paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET; | ||
120 | writeq(paddr, &wq->ctrl->ring_base); | ||
121 | iowrite32(wq->ring.desc_count, &wq->ctrl->ring_size); | ||
122 | iowrite32(0, &wq->ctrl->fetch_index); | ||
123 | iowrite32(0, &wq->ctrl->posted_index); | ||
124 | iowrite32(cq_index, &wq->ctrl->cq_index); | ||
125 | iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable); | ||
126 | iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset); | ||
127 | iowrite32(0, &wq->ctrl->error_status); | ||
128 | } | ||
129 | |||
130 | unsigned int vnic_wq_error_status(struct vnic_wq *wq) | ||
131 | { | ||
132 | return ioread32(&wq->ctrl->error_status); | ||
133 | } | ||
134 | |||
135 | void vnic_wq_enable(struct vnic_wq *wq) | ||
136 | { | ||
137 | iowrite32(1, &wq->ctrl->enable); | ||
138 | } | ||
139 | |||
140 | int vnic_wq_disable(struct vnic_wq *wq) | ||
141 | { | ||
142 | unsigned int wait; | ||
143 | |||
144 | iowrite32(0, &wq->ctrl->enable); | ||
145 | |||
146 | /* Wait for HW to ACK disable request */ | ||
147 | for (wait = 0; wait < 100; wait++) { | ||
148 | if (!(ioread32(&wq->ctrl->running))) | ||
149 | return 0; | ||
150 | udelay(1); | ||
151 | } | ||
152 | |||
153 | printk(KERN_ERR "Failed to disable WQ[%d]\n", wq->index); | ||
154 | |||
155 | return -ETIMEDOUT; | ||
156 | } | ||
157 | |||
158 | void vnic_wq_clean(struct vnic_wq *wq, | ||
159 | void (*buf_clean)(struct vnic_wq *wq, struct vnic_wq_buf *buf)) | ||
160 | { | ||
161 | struct vnic_wq_buf *buf; | ||
162 | |||
163 | BUG_ON(ioread32(&wq->ctrl->enable)); | ||
164 | |||
165 | buf = wq->to_clean; | ||
166 | |||
167 | while (vnic_wq_desc_used(wq) > 0) { | ||
168 | |||
169 | (*buf_clean)(wq, buf); | ||
170 | |||
171 | buf = wq->to_clean = buf->next; | ||
172 | wq->ring.desc_avail++; | ||
173 | } | ||
174 | |||
175 | wq->to_use = wq->to_clean = wq->bufs[0]; | ||
176 | |||
177 | iowrite32(0, &wq->ctrl->fetch_index); | ||
178 | iowrite32(0, &wq->ctrl->posted_index); | ||
179 | iowrite32(0, &wq->ctrl->error_status); | ||
180 | |||
181 | vnic_dev_clear_desc_ring(&wq->ring); | ||
182 | } | ||
diff --git a/drivers/scsi/fnic/vnic_wq.h b/drivers/scsi/fnic/vnic_wq.h new file mode 100644 index 000000000000..5cd094f79281 --- /dev/null +++ b/drivers/scsi/fnic/vnic_wq.h | |||
@@ -0,0 +1,175 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_WQ_H_ | ||
19 | #define _VNIC_WQ_H_ | ||
20 | |||
21 | #include <linux/pci.h> | ||
22 | #include "vnic_dev.h" | ||
23 | #include "vnic_cq.h" | ||
24 | |||
25 | /* | ||
26 | * These defines avoid symbol clash between fnic and enic (Cisco 10G Eth | ||
27 | * Driver) when both are built with CONFIG options =y | ||
28 | */ | ||
29 | #define vnic_wq_desc_avail fnic_wq_desc_avail | ||
30 | #define vnic_wq_desc_used fnic_wq_desc_used | ||
31 | #define vnic_wq_next_desc fni_cwq_next_desc | ||
32 | #define vnic_wq_post fnic_wq_post | ||
33 | #define vnic_wq_service fnic_wq_service | ||
34 | #define vnic_wq_free fnic_wq_free | ||
35 | #define vnic_wq_alloc fnic_wq_alloc | ||
36 | #define vnic_wq_init fnic_wq_init | ||
37 | #define vnic_wq_error_status fnic_wq_error_status | ||
38 | #define vnic_wq_enable fnic_wq_enable | ||
39 | #define vnic_wq_disable fnic_wq_disable | ||
40 | #define vnic_wq_clean fnic_wq_clean | ||
41 | |||
42 | /* Work queue control */ | ||
43 | struct vnic_wq_ctrl { | ||
44 | u64 ring_base; /* 0x00 */ | ||
45 | u32 ring_size; /* 0x08 */ | ||
46 | u32 pad0; | ||
47 | u32 posted_index; /* 0x10 */ | ||
48 | u32 pad1; | ||
49 | u32 cq_index; /* 0x18 */ | ||
50 | u32 pad2; | ||
51 | u32 enable; /* 0x20 */ | ||
52 | u32 pad3; | ||
53 | u32 running; /* 0x28 */ | ||
54 | u32 pad4; | ||
55 | u32 fetch_index; /* 0x30 */ | ||
56 | u32 pad5; | ||
57 | u32 dca_value; /* 0x38 */ | ||
58 | u32 pad6; | ||
59 | u32 error_interrupt_enable; /* 0x40 */ | ||
60 | u32 pad7; | ||
61 | u32 error_interrupt_offset; /* 0x48 */ | ||
62 | u32 pad8; | ||
63 | u32 error_status; /* 0x50 */ | ||
64 | u32 pad9; | ||
65 | }; | ||
66 | |||
67 | struct vnic_wq_buf { | ||
68 | struct vnic_wq_buf *next; | ||
69 | dma_addr_t dma_addr; | ||
70 | void *os_buf; | ||
71 | unsigned int len; | ||
72 | unsigned int index; | ||
73 | int sop; | ||
74 | void *desc; | ||
75 | }; | ||
76 | |||
77 | /* Break the vnic_wq_buf allocations into blocks of 64 entries */ | ||
78 | #define VNIC_WQ_BUF_BLK_ENTRIES 64 | ||
79 | #define VNIC_WQ_BUF_BLK_SZ \ | ||
80 | (VNIC_WQ_BUF_BLK_ENTRIES * sizeof(struct vnic_wq_buf)) | ||
81 | #define VNIC_WQ_BUF_BLKS_NEEDED(entries) \ | ||
82 | DIV_ROUND_UP(entries, VNIC_WQ_BUF_BLK_ENTRIES) | ||
83 | #define VNIC_WQ_BUF_BLKS_MAX VNIC_WQ_BUF_BLKS_NEEDED(4096) | ||
84 | |||
85 | struct vnic_wq { | ||
86 | unsigned int index; | ||
87 | struct vnic_dev *vdev; | ||
88 | struct vnic_wq_ctrl __iomem *ctrl; /* memory-mapped */ | ||
89 | struct vnic_dev_ring ring; | ||
90 | struct vnic_wq_buf *bufs[VNIC_WQ_BUF_BLKS_MAX]; | ||
91 | struct vnic_wq_buf *to_use; | ||
92 | struct vnic_wq_buf *to_clean; | ||
93 | unsigned int pkts_outstanding; | ||
94 | }; | ||
95 | |||
96 | static inline unsigned int vnic_wq_desc_avail(struct vnic_wq *wq) | ||
97 | { | ||
98 | /* how many does SW own? */ | ||
99 | return wq->ring.desc_avail; | ||
100 | } | ||
101 | |||
102 | static inline unsigned int vnic_wq_desc_used(struct vnic_wq *wq) | ||
103 | { | ||
104 | /* how many does HW own? */ | ||
105 | return wq->ring.desc_count - wq->ring.desc_avail - 1; | ||
106 | } | ||
107 | |||
108 | static inline void *vnic_wq_next_desc(struct vnic_wq *wq) | ||
109 | { | ||
110 | return wq->to_use->desc; | ||
111 | } | ||
112 | |||
113 | static inline void vnic_wq_post(struct vnic_wq *wq, | ||
114 | void *os_buf, dma_addr_t dma_addr, | ||
115 | unsigned int len, int sop, int eop) | ||
116 | { | ||
117 | struct vnic_wq_buf *buf = wq->to_use; | ||
118 | |||
119 | buf->sop = sop; | ||
120 | buf->os_buf = eop ? os_buf : NULL; | ||
121 | buf->dma_addr = dma_addr; | ||
122 | buf->len = len; | ||
123 | |||
124 | buf = buf->next; | ||
125 | if (eop) { | ||
126 | /* Adding write memory barrier prevents compiler and/or CPU | ||
127 | * reordering, thus avoiding descriptor posting before | ||
128 | * descriptor is initialized. Otherwise, hardware can read | ||
129 | * stale descriptor fields. | ||
130 | */ | ||
131 | wmb(); | ||
132 | iowrite32(buf->index, &wq->ctrl->posted_index); | ||
133 | } | ||
134 | wq->to_use = buf; | ||
135 | |||
136 | wq->ring.desc_avail--; | ||
137 | } | ||
138 | |||
139 | static inline void vnic_wq_service(struct vnic_wq *wq, | ||
140 | struct cq_desc *cq_desc, u16 completed_index, | ||
141 | void (*buf_service)(struct vnic_wq *wq, | ||
142 | struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque), | ||
143 | void *opaque) | ||
144 | { | ||
145 | struct vnic_wq_buf *buf; | ||
146 | |||
147 | buf = wq->to_clean; | ||
148 | while (1) { | ||
149 | |||
150 | (*buf_service)(wq, cq_desc, buf, opaque); | ||
151 | |||
152 | wq->ring.desc_avail++; | ||
153 | |||
154 | wq->to_clean = buf->next; | ||
155 | |||
156 | if (buf->index == completed_index) | ||
157 | break; | ||
158 | |||
159 | buf = wq->to_clean; | ||
160 | } | ||
161 | } | ||
162 | |||
163 | void vnic_wq_free(struct vnic_wq *wq); | ||
164 | int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index, | ||
165 | unsigned int desc_count, unsigned int desc_size); | ||
166 | void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, | ||
167 | unsigned int error_interrupt_enable, | ||
168 | unsigned int error_interrupt_offset); | ||
169 | unsigned int vnic_wq_error_status(struct vnic_wq *wq); | ||
170 | void vnic_wq_enable(struct vnic_wq *wq); | ||
171 | int vnic_wq_disable(struct vnic_wq *wq); | ||
172 | void vnic_wq_clean(struct vnic_wq *wq, | ||
173 | void (*buf_clean)(struct vnic_wq *wq, struct vnic_wq_buf *buf)); | ||
174 | |||
175 | #endif /* _VNIC_WQ_H_ */ | ||
diff --git a/drivers/scsi/fnic/vnic_wq_copy.c b/drivers/scsi/fnic/vnic_wq_copy.c new file mode 100644 index 000000000000..9eab7e7caf38 --- /dev/null +++ b/drivers/scsi/fnic/vnic_wq_copy.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <linux/errno.h> | ||
20 | #include <linux/types.h> | ||
21 | #include <linux/pci.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include "vnic_wq_copy.h" | ||
24 | |||
25 | void vnic_wq_copy_enable(struct vnic_wq_copy *wq) | ||
26 | { | ||
27 | iowrite32(1, &wq->ctrl->enable); | ||
28 | } | ||
29 | |||
30 | int vnic_wq_copy_disable(struct vnic_wq_copy *wq) | ||
31 | { | ||
32 | unsigned int wait; | ||
33 | |||
34 | iowrite32(0, &wq->ctrl->enable); | ||
35 | |||
36 | /* Wait for HW to ACK disable request */ | ||
37 | for (wait = 0; wait < 100; wait++) { | ||
38 | if (!(ioread32(&wq->ctrl->running))) | ||
39 | return 0; | ||
40 | udelay(1); | ||
41 | } | ||
42 | |||
43 | printk(KERN_ERR "Failed to disable Copy WQ[%d]," | ||
44 | " fetch index=%d, posted_index=%d\n", | ||
45 | wq->index, ioread32(&wq->ctrl->fetch_index), | ||
46 | ioread32(&wq->ctrl->posted_index)); | ||
47 | |||
48 | return -ENODEV; | ||
49 | } | ||
50 | |||
51 | void vnic_wq_copy_clean(struct vnic_wq_copy *wq, | ||
52 | void (*q_clean)(struct vnic_wq_copy *wq, | ||
53 | struct fcpio_host_req *wq_desc)) | ||
54 | { | ||
55 | BUG_ON(ioread32(&wq->ctrl->enable)); | ||
56 | |||
57 | if (vnic_wq_copy_desc_in_use(wq)) | ||
58 | vnic_wq_copy_service(wq, -1, q_clean); | ||
59 | |||
60 | wq->to_use_index = wq->to_clean_index = 0; | ||
61 | |||
62 | iowrite32(0, &wq->ctrl->fetch_index); | ||
63 | iowrite32(0, &wq->ctrl->posted_index); | ||
64 | iowrite32(0, &wq->ctrl->error_status); | ||
65 | |||
66 | vnic_dev_clear_desc_ring(&wq->ring); | ||
67 | } | ||
68 | |||
69 | void vnic_wq_copy_free(struct vnic_wq_copy *wq) | ||
70 | { | ||
71 | struct vnic_dev *vdev; | ||
72 | |||
73 | vdev = wq->vdev; | ||
74 | vnic_dev_free_desc_ring(vdev, &wq->ring); | ||
75 | wq->ctrl = NULL; | ||
76 | } | ||
77 | |||
78 | int vnic_wq_copy_alloc(struct vnic_dev *vdev, struct vnic_wq_copy *wq, | ||
79 | unsigned int index, unsigned int desc_count, | ||
80 | unsigned int desc_size) | ||
81 | { | ||
82 | int err; | ||
83 | |||
84 | wq->index = index; | ||
85 | wq->vdev = vdev; | ||
86 | wq->to_use_index = wq->to_clean_index = 0; | ||
87 | wq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_WQ, index); | ||
88 | if (!wq->ctrl) { | ||
89 | printk(KERN_ERR "Failed to hook COPY WQ[%d] resource\n", index); | ||
90 | return -EINVAL; | ||
91 | } | ||
92 | |||
93 | vnic_wq_copy_disable(wq); | ||
94 | |||
95 | err = vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size); | ||
96 | if (err) | ||
97 | return err; | ||
98 | |||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | void vnic_wq_copy_init(struct vnic_wq_copy *wq, unsigned int cq_index, | ||
103 | unsigned int error_interrupt_enable, | ||
104 | unsigned int error_interrupt_offset) | ||
105 | { | ||
106 | u64 paddr; | ||
107 | |||
108 | paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET; | ||
109 | writeq(paddr, &wq->ctrl->ring_base); | ||
110 | iowrite32(wq->ring.desc_count, &wq->ctrl->ring_size); | ||
111 | iowrite32(0, &wq->ctrl->fetch_index); | ||
112 | iowrite32(0, &wq->ctrl->posted_index); | ||
113 | iowrite32(cq_index, &wq->ctrl->cq_index); | ||
114 | iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable); | ||
115 | iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset); | ||
116 | } | ||
117 | |||
diff --git a/drivers/scsi/fnic/vnic_wq_copy.h b/drivers/scsi/fnic/vnic_wq_copy.h new file mode 100644 index 000000000000..6aff9740c3df --- /dev/null +++ b/drivers/scsi/fnic/vnic_wq_copy.h | |||
@@ -0,0 +1,128 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _VNIC_WQ_COPY_H_ | ||
19 | #define _VNIC_WQ_COPY_H_ | ||
20 | |||
21 | #include <linux/pci.h> | ||
22 | #include "vnic_wq.h" | ||
23 | #include "fcpio.h" | ||
24 | |||
25 | #define VNIC_WQ_COPY_MAX 1 | ||
26 | |||
27 | struct vnic_wq_copy { | ||
28 | unsigned int index; | ||
29 | struct vnic_dev *vdev; | ||
30 | struct vnic_wq_ctrl __iomem *ctrl; /* memory-mapped */ | ||
31 | struct vnic_dev_ring ring; | ||
32 | unsigned to_use_index; | ||
33 | unsigned to_clean_index; | ||
34 | }; | ||
35 | |||
36 | static inline unsigned int vnic_wq_copy_desc_avail(struct vnic_wq_copy *wq) | ||
37 | { | ||
38 | return wq->ring.desc_avail; | ||
39 | } | ||
40 | |||
41 | static inline unsigned int vnic_wq_copy_desc_in_use(struct vnic_wq_copy *wq) | ||
42 | { | ||
43 | return wq->ring.desc_count - 1 - wq->ring.desc_avail; | ||
44 | } | ||
45 | |||
46 | static inline void *vnic_wq_copy_next_desc(struct vnic_wq_copy *wq) | ||
47 | { | ||
48 | struct fcpio_host_req *desc = wq->ring.descs; | ||
49 | return &desc[wq->to_use_index]; | ||
50 | } | ||
51 | |||
52 | static inline void vnic_wq_copy_post(struct vnic_wq_copy *wq) | ||
53 | { | ||
54 | |||
55 | ((wq->to_use_index + 1) == wq->ring.desc_count) ? | ||
56 | (wq->to_use_index = 0) : (wq->to_use_index++); | ||
57 | wq->ring.desc_avail--; | ||
58 | |||
59 | /* Adding write memory barrier prevents compiler and/or CPU | ||
60 | * reordering, thus avoiding descriptor posting before | ||
61 | * descriptor is initialized. Otherwise, hardware can read | ||
62 | * stale descriptor fields. | ||
63 | */ | ||
64 | wmb(); | ||
65 | |||
66 | iowrite32(wq->to_use_index, &wq->ctrl->posted_index); | ||
67 | } | ||
68 | |||
69 | static inline void vnic_wq_copy_desc_process(struct vnic_wq_copy *wq, u16 index) | ||
70 | { | ||
71 | unsigned int cnt; | ||
72 | |||
73 | if (wq->to_clean_index <= index) | ||
74 | cnt = (index - wq->to_clean_index) + 1; | ||
75 | else | ||
76 | cnt = wq->ring.desc_count - wq->to_clean_index + index + 1; | ||
77 | |||
78 | wq->to_clean_index = ((index + 1) % wq->ring.desc_count); | ||
79 | wq->ring.desc_avail += cnt; | ||
80 | |||
81 | } | ||
82 | |||
83 | static inline void vnic_wq_copy_service(struct vnic_wq_copy *wq, | ||
84 | u16 completed_index, | ||
85 | void (*q_service)(struct vnic_wq_copy *wq, | ||
86 | struct fcpio_host_req *wq_desc)) | ||
87 | { | ||
88 | struct fcpio_host_req *wq_desc = wq->ring.descs; | ||
89 | unsigned int curr_index; | ||
90 | |||
91 | while (1) { | ||
92 | |||
93 | if (q_service) | ||
94 | (*q_service)(wq, &wq_desc[wq->to_clean_index]); | ||
95 | |||
96 | wq->ring.desc_avail++; | ||
97 | |||
98 | curr_index = wq->to_clean_index; | ||
99 | |||
100 | /* increment the to-clean index so that we start | ||
101 | * with an unprocessed index next time we enter the loop | ||
102 | */ | ||
103 | ((wq->to_clean_index + 1) == wq->ring.desc_count) ? | ||
104 | (wq->to_clean_index = 0) : (wq->to_clean_index++); | ||
105 | |||
106 | if (curr_index == completed_index) | ||
107 | break; | ||
108 | |||
109 | /* we have cleaned all the entries */ | ||
110 | if ((completed_index == (u16)-1) && | ||
111 | (wq->to_clean_index == wq->to_use_index)) | ||
112 | break; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | void vnic_wq_copy_enable(struct vnic_wq_copy *wq); | ||
117 | int vnic_wq_copy_disable(struct vnic_wq_copy *wq); | ||
118 | void vnic_wq_copy_free(struct vnic_wq_copy *wq); | ||
119 | int vnic_wq_copy_alloc(struct vnic_dev *vdev, struct vnic_wq_copy *wq, | ||
120 | unsigned int index, unsigned int desc_count, unsigned int desc_size); | ||
121 | void vnic_wq_copy_init(struct vnic_wq_copy *wq, unsigned int cq_index, | ||
122 | unsigned int error_interrupt_enable, | ||
123 | unsigned int error_interrupt_offset); | ||
124 | void vnic_wq_copy_clean(struct vnic_wq_copy *wq, | ||
125 | void (*q_clean)(struct vnic_wq_copy *wq, | ||
126 | struct fcpio_host_req *wq_desc)); | ||
127 | |||
128 | #endif /* _VNIC_WQ_COPY_H_ */ | ||
diff --git a/drivers/scsi/fnic/wq_enet_desc.h b/drivers/scsi/fnic/wq_enet_desc.h new file mode 100644 index 000000000000..b121cbad18b8 --- /dev/null +++ b/drivers/scsi/fnic/wq_enet_desc.h | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. | ||
3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you may redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; version 2 of the License. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | #ifndef _WQ_ENET_DESC_H_ | ||
19 | #define _WQ_ENET_DESC_H_ | ||
20 | |||
21 | /* Ethernet work queue descriptor: 16B */ | ||
22 | struct wq_enet_desc { | ||
23 | __le64 address; | ||
24 | __le16 length; | ||
25 | __le16 mss_loopback; | ||
26 | __le16 header_length_flags; | ||
27 | __le16 vlan_tag; | ||
28 | }; | ||
29 | |||
30 | #define WQ_ENET_ADDR_BITS 64 | ||
31 | #define WQ_ENET_LEN_BITS 14 | ||
32 | #define WQ_ENET_LEN_MASK ((1 << WQ_ENET_LEN_BITS) - 1) | ||
33 | #define WQ_ENET_MSS_BITS 14 | ||
34 | #define WQ_ENET_MSS_MASK ((1 << WQ_ENET_MSS_BITS) - 1) | ||
35 | #define WQ_ENET_MSS_SHIFT 2 | ||
36 | #define WQ_ENET_LOOPBACK_SHIFT 1 | ||
37 | #define WQ_ENET_HDRLEN_BITS 10 | ||
38 | #define WQ_ENET_HDRLEN_MASK ((1 << WQ_ENET_HDRLEN_BITS) - 1) | ||
39 | #define WQ_ENET_FLAGS_OM_BITS 2 | ||
40 | #define WQ_ENET_FLAGS_OM_MASK ((1 << WQ_ENET_FLAGS_OM_BITS) - 1) | ||
41 | #define WQ_ENET_FLAGS_EOP_SHIFT 12 | ||
42 | #define WQ_ENET_FLAGS_CQ_ENTRY_SHIFT 13 | ||
43 | #define WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT 14 | ||
44 | #define WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT 15 | ||
45 | |||
46 | #define WQ_ENET_OFFLOAD_MODE_CSUM 0 | ||
47 | #define WQ_ENET_OFFLOAD_MODE_RESERVED 1 | ||
48 | #define WQ_ENET_OFFLOAD_MODE_CSUM_L4 2 | ||
49 | #define WQ_ENET_OFFLOAD_MODE_TSO 3 | ||
50 | |||
51 | static inline void wq_enet_desc_enc(struct wq_enet_desc *desc, | ||
52 | u64 address, u16 length, u16 mss, u16 header_length, | ||
53 | u8 offload_mode, u8 eop, u8 cq_entry, u8 fcoe_encap, | ||
54 | u8 vlan_tag_insert, u16 vlan_tag, u8 loopback) | ||
55 | { | ||
56 | desc->address = cpu_to_le64(address); | ||
57 | desc->length = cpu_to_le16(length & WQ_ENET_LEN_MASK); | ||
58 | desc->mss_loopback = cpu_to_le16((mss & WQ_ENET_MSS_MASK) << | ||
59 | WQ_ENET_MSS_SHIFT | (loopback & 1) << WQ_ENET_LOOPBACK_SHIFT); | ||
60 | desc->header_length_flags = cpu_to_le16( | ||
61 | (header_length & WQ_ENET_HDRLEN_MASK) | | ||
62 | (offload_mode & WQ_ENET_FLAGS_OM_MASK) << WQ_ENET_HDRLEN_BITS | | ||
63 | (eop & 1) << WQ_ENET_FLAGS_EOP_SHIFT | | ||
64 | (cq_entry & 1) << WQ_ENET_FLAGS_CQ_ENTRY_SHIFT | | ||
65 | (fcoe_encap & 1) << WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT | | ||
66 | (vlan_tag_insert & 1) << WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT); | ||
67 | desc->vlan_tag = cpu_to_le16(vlan_tag); | ||
68 | } | ||
69 | |||
70 | static inline void wq_enet_desc_dec(struct wq_enet_desc *desc, | ||
71 | u64 *address, u16 *length, u16 *mss, u16 *header_length, | ||
72 | u8 *offload_mode, u8 *eop, u8 *cq_entry, u8 *fcoe_encap, | ||
73 | u8 *vlan_tag_insert, u16 *vlan_tag, u8 *loopback) | ||
74 | { | ||
75 | *address = le64_to_cpu(desc->address); | ||
76 | *length = le16_to_cpu(desc->length) & WQ_ENET_LEN_MASK; | ||
77 | *mss = (le16_to_cpu(desc->mss_loopback) >> WQ_ENET_MSS_SHIFT) & | ||
78 | WQ_ENET_MSS_MASK; | ||
79 | *loopback = (u8)((le16_to_cpu(desc->mss_loopback) >> | ||
80 | WQ_ENET_LOOPBACK_SHIFT) & 1); | ||
81 | *header_length = le16_to_cpu(desc->header_length_flags) & | ||
82 | WQ_ENET_HDRLEN_MASK; | ||
83 | *offload_mode = (u8)((le16_to_cpu(desc->header_length_flags) >> | ||
84 | WQ_ENET_HDRLEN_BITS) & WQ_ENET_FLAGS_OM_MASK); | ||
85 | *eop = (u8)((le16_to_cpu(desc->header_length_flags) >> | ||
86 | WQ_ENET_FLAGS_EOP_SHIFT) & 1); | ||
87 | *cq_entry = (u8)((le16_to_cpu(desc->header_length_flags) >> | ||
88 | WQ_ENET_FLAGS_CQ_ENTRY_SHIFT) & 1); | ||
89 | *fcoe_encap = (u8)((le16_to_cpu(desc->header_length_flags) >> | ||
90 | WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT) & 1); | ||
91 | *vlan_tag_insert = (u8)((le16_to_cpu(desc->header_length_flags) >> | ||
92 | WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT) & 1); | ||
93 | *vlan_tag = le16_to_cpu(desc->vlan_tag); | ||
94 | } | ||
95 | |||
96 | #endif /* _WQ_ENET_DESC_H_ */ | ||
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.h b/drivers/scsi/mpt2sas/mpt2sas_base.h index babd4cc0cb25..36b1d1052ba1 100644 --- a/drivers/scsi/mpt2sas/mpt2sas_base.h +++ b/drivers/scsi/mpt2sas/mpt2sas_base.h | |||
@@ -69,7 +69,7 @@ | |||
69 | #define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>" | 69 | #define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>" |
70 | #define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver" | 70 | #define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver" |
71 | #define MPT2SAS_DRIVER_VERSION "01.100.02.00" | 71 | #define MPT2SAS_DRIVER_VERSION "01.100.02.00" |
72 | #define MPT2SAS_MAJOR_VERSION 00 | 72 | #define MPT2SAS_MAJOR_VERSION 01 |
73 | #define MPT2SAS_MINOR_VERSION 100 | 73 | #define MPT2SAS_MINOR_VERSION 100 |
74 | #define MPT2SAS_BUILD_VERSION 02 | 74 | #define MPT2SAS_BUILD_VERSION 02 |
75 | #define MPT2SAS_RELEASE_VERSION 00 | 75 | #define MPT2SAS_RELEASE_VERSION 00 |
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 6f51ca485f35..e2b50d8f57a8 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c | |||
@@ -425,6 +425,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent, | |||
425 | INIT_LIST_HEAD(&starget->devices); | 425 | INIT_LIST_HEAD(&starget->devices); |
426 | starget->state = STARGET_CREATED; | 426 | starget->state = STARGET_CREATED; |
427 | starget->scsi_level = SCSI_2; | 427 | starget->scsi_level = SCSI_2; |
428 | starget->max_target_blocked = SCSI_DEFAULT_TARGET_BLOCKED; | ||
428 | retry: | 429 | retry: |
429 | spin_lock_irqsave(shost->host_lock, flags); | 430 | spin_lock_irqsave(shost->host_lock, flags); |
430 | 431 | ||
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 094795455293..0a2ce7b6325c 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c | |||
@@ -357,7 +357,7 @@ int iscsi_session_chkready(struct iscsi_cls_session *session) | |||
357 | err = 0; | 357 | err = 0; |
358 | break; | 358 | break; |
359 | case ISCSI_SESSION_FAILED: | 359 | case ISCSI_SESSION_FAILED: |
360 | err = DID_TRANSPORT_DISRUPTED << 16; | 360 | err = DID_IMM_RETRY << 16; |
361 | break; | 361 | break; |
362 | case ISCSI_SESSION_FREE: | 362 | case ISCSI_SESSION_FREE: |
363 | err = DID_TRANSPORT_FAILFAST << 16; | 363 | err = DID_TRANSPORT_FAILFAST << 16; |
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 9bd407fa98e4..8201387b4daa 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c | |||
@@ -1065,6 +1065,7 @@ sg_ioctl(struct inode *inode, struct file *filp, | |||
1065 | return blk_trace_setup(sdp->device->request_queue, | 1065 | return blk_trace_setup(sdp->device->request_queue, |
1066 | sdp->disk->disk_name, | 1066 | sdp->disk->disk_name, |
1067 | MKDEV(SCSI_GENERIC_MAJOR, sdp->index), | 1067 | MKDEV(SCSI_GENERIC_MAJOR, sdp->index), |
1068 | NULL, | ||
1068 | (char *)arg); | 1069 | (char *)arg); |
1069 | case BLKTRACESTART: | 1070 | case BLKTRACESTART: |
1070 | return blk_trace_startstop(sdp->device->request_queue, 1); | 1071 | return blk_trace_startstop(sdp->device->request_queue, 1); |
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c index b4b39811b445..fb867a9f55e9 100644 --- a/drivers/serial/8250.c +++ b/drivers/serial/8250.c | |||
@@ -137,6 +137,7 @@ struct uart_8250_port { | |||
137 | unsigned char mcr; | 137 | unsigned char mcr; |
138 | unsigned char mcr_mask; /* mask of user bits */ | 138 | unsigned char mcr_mask; /* mask of user bits */ |
139 | unsigned char mcr_force; /* mask of forced bits */ | 139 | unsigned char mcr_force; /* mask of forced bits */ |
140 | unsigned char cur_iotype; /* Running I/O type */ | ||
140 | 141 | ||
141 | /* | 142 | /* |
142 | * Some bits in registers are cleared on a read, so they must | 143 | * Some bits in registers are cleared on a read, so they must |
@@ -286,6 +287,13 @@ static const struct serial8250_config uart_config[] = { | |||
286 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, | 287 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, |
287 | .flags = UART_CAP_FIFO, | 288 | .flags = UART_CAP_FIFO, |
288 | }, | 289 | }, |
290 | [PORT_AR7] = { | ||
291 | .name = "AR7", | ||
292 | .fifo_size = 16, | ||
293 | .tx_loadsz = 16, | ||
294 | .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00, | ||
295 | .flags = UART_CAP_FIFO | UART_CAP_AFE, | ||
296 | }, | ||
289 | }; | 297 | }; |
290 | 298 | ||
291 | #if defined (CONFIG_SERIAL_8250_AU1X00) | 299 | #if defined (CONFIG_SERIAL_8250_AU1X00) |
@@ -471,6 +479,7 @@ static void io_serial_out(struct uart_port *p, int offset, int value) | |||
471 | 479 | ||
472 | static void set_io_from_upio(struct uart_port *p) | 480 | static void set_io_from_upio(struct uart_port *p) |
473 | { | 481 | { |
482 | struct uart_8250_port *up = (struct uart_8250_port *)p; | ||
474 | switch (p->iotype) { | 483 | switch (p->iotype) { |
475 | case UPIO_HUB6: | 484 | case UPIO_HUB6: |
476 | p->serial_in = hub6_serial_in; | 485 | p->serial_in = hub6_serial_in; |
@@ -509,6 +518,8 @@ static void set_io_from_upio(struct uart_port *p) | |||
509 | p->serial_out = io_serial_out; | 518 | p->serial_out = io_serial_out; |
510 | break; | 519 | break; |
511 | } | 520 | } |
521 | /* Remember loaded iotype */ | ||
522 | up->cur_iotype = p->iotype; | ||
512 | } | 523 | } |
513 | 524 | ||
514 | static void | 525 | static void |
@@ -1937,6 +1948,9 @@ static int serial8250_startup(struct uart_port *port) | |||
1937 | up->capabilities = uart_config[up->port.type].flags; | 1948 | up->capabilities = uart_config[up->port.type].flags; |
1938 | up->mcr = 0; | 1949 | up->mcr = 0; |
1939 | 1950 | ||
1951 | if (up->port.iotype != up->cur_iotype) | ||
1952 | set_io_from_upio(port); | ||
1953 | |||
1940 | if (up->port.type == PORT_16C950) { | 1954 | if (up->port.type == PORT_16C950) { |
1941 | /* Wake up and initialize UART */ | 1955 | /* Wake up and initialize UART */ |
1942 | up->acr = 0; | 1956 | up->acr = 0; |
@@ -2563,6 +2577,9 @@ static void serial8250_config_port(struct uart_port *port, int flags) | |||
2563 | if (ret < 0) | 2577 | if (ret < 0) |
2564 | probeflags &= ~PROBE_RSA; | 2578 | probeflags &= ~PROBE_RSA; |
2565 | 2579 | ||
2580 | if (up->port.iotype != up->cur_iotype) | ||
2581 | set_io_from_upio(port); | ||
2582 | |||
2566 | if (flags & UART_CONFIG_TYPE) | 2583 | if (flags & UART_CONFIG_TYPE) |
2567 | autoconfig(up, probeflags); | 2584 | autoconfig(up, probeflags); |
2568 | if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) | 2585 | if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) |
@@ -2671,6 +2688,11 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev) | |||
2671 | { | 2688 | { |
2672 | int i; | 2689 | int i; |
2673 | 2690 | ||
2691 | for (i = 0; i < nr_uarts; i++) { | ||
2692 | struct uart_8250_port *up = &serial8250_ports[i]; | ||
2693 | up->cur_iotype = 0xFF; | ||
2694 | } | ||
2695 | |||
2674 | serial8250_isa_init_ports(); | 2696 | serial8250_isa_init_ports(); |
2675 | 2697 | ||
2676 | for (i = 0; i < nr_uarts; i++) { | 2698 | for (i = 0; i < nr_uarts; i++) { |
diff --git a/drivers/serial/8250_gsc.c b/drivers/serial/8250_gsc.c index 418b4fe9a0a1..33149d982e82 100644 --- a/drivers/serial/8250_gsc.c +++ b/drivers/serial/8250_gsc.c | |||
@@ -39,9 +39,9 @@ static int __init serial_init_chip(struct parisc_device *dev) | |||
39 | */ | 39 | */ |
40 | if (parisc_parent(dev)->id.hw_type != HPHW_IOA) | 40 | if (parisc_parent(dev)->id.hw_type != HPHW_IOA) |
41 | printk(KERN_INFO | 41 | printk(KERN_INFO |
42 | "Serial: device 0x%lx not configured.\n" | 42 | "Serial: device 0x%llx not configured.\n" |
43 | "Enable support for Wax, Lasi, Asp or Dino.\n", | 43 | "Enable support for Wax, Lasi, Asp or Dino.\n", |
44 | dev->hpa.start); | 44 | (unsigned long long)dev->hpa.start); |
45 | return -ENODEV; | 45 | return -ENODEV; |
46 | } | 46 | } |
47 | 47 | ||
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c index 938bc1b6c3fa..e371a9c15341 100644 --- a/drivers/serial/8250_pci.c +++ b/drivers/serial/8250_pci.c | |||
@@ -2776,6 +2776,9 @@ static struct pci_device_id serial_pci_tbl[] = { | |||
2776 | { PCI_VENDOR_ID_OXSEMI, 0x950a, | 2776 | { PCI_VENDOR_ID_OXSEMI, 0x950a, |
2777 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 2777 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
2778 | pbn_b0_2_1130000 }, | 2778 | pbn_b0_2_1130000 }, |
2779 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_C950, | ||
2780 | PCI_VENDOR_ID_OXSEMI, PCI_SUBDEVICE_ID_OXSEMI_C950, 0, 0, | ||
2781 | pbn_b0_1_921600 }, | ||
2779 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954, | 2782 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954, |
2780 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 2783 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
2781 | pbn_b0_4_115200 }, | 2784 | pbn_b0_4_115200 }, |
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 343e3a35b6a3..641e800ed693 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig | |||
@@ -833,6 +833,7 @@ config SERIAL_IMX | |||
833 | bool "IMX serial port support" | 833 | bool "IMX serial port support" |
834 | depends on ARM && (ARCH_IMX || ARCH_MXC) | 834 | depends on ARM && (ARCH_IMX || ARCH_MXC) |
835 | select SERIAL_CORE | 835 | select SERIAL_CORE |
836 | select RATIONAL | ||
836 | help | 837 | help |
837 | If you have a machine based on a Motorola IMX CPU you | 838 | If you have a machine based on a Motorola IMX CPU you |
838 | can enable its onboard serial port by enabling this option. | 839 | can enable its onboard serial port by enabling this option. |
@@ -1433,4 +1434,11 @@ config SPORT_BAUD_RATE | |||
1433 | default 19200 if (SERIAL_SPORT_BAUD_RATE_19200) | 1434 | default 19200 if (SERIAL_SPORT_BAUD_RATE_19200) |
1434 | default 9600 if (SERIAL_SPORT_BAUD_RATE_9600) | 1435 | default 9600 if (SERIAL_SPORT_BAUD_RATE_9600) |
1435 | 1436 | ||
1437 | config SERIAL_TIMBERDALE | ||
1438 | tristate "Support for timberdale UART" | ||
1439 | depends on MFD_TIMBERDALE | ||
1440 | select SERIAL_CORE | ||
1441 | ---help--- | ||
1442 | Add support for UART controller on timberdale. | ||
1443 | |||
1436 | endmenu | 1444 | endmenu |
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index d438eb2a73de..45a8658f54d5 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile | |||
@@ -77,3 +77,4 @@ obj-$(CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL) += nwpserial.o | |||
77 | obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o | 77 | obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o |
78 | obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o | 78 | obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o |
79 | obj-$(CONFIG_SERIAL_QE) += ucc_uart.o | 79 | obj-$(CONFIG_SERIAL_QE) += ucc_uart.o |
80 | obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o | ||
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c index d86123e03391..e2f6b1bfac98 100644 --- a/drivers/serial/bfin_5xx.c +++ b/drivers/serial/bfin_5xx.c | |||
@@ -330,6 +330,11 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart) | |||
330 | /* Clear TFI bit */ | 330 | /* Clear TFI bit */ |
331 | UART_PUT_LSR(uart, TFI); | 331 | UART_PUT_LSR(uart, TFI); |
332 | #endif | 332 | #endif |
333 | /* Anomaly notes: | ||
334 | * 05000215 - we always clear ETBEI within last UART TX | ||
335 | * interrupt to end a string. It is always set | ||
336 | * when start a new tx. | ||
337 | */ | ||
333 | UART_CLEAR_IER(uart, ETBEI); | 338 | UART_CLEAR_IER(uart, ETBEI); |
334 | return; | 339 | return; |
335 | } | 340 | } |
@@ -415,6 +420,7 @@ static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart) | |||
415 | set_dma_start_addr(uart->tx_dma_channel, (unsigned long)(xmit->buf+xmit->tail)); | 420 | set_dma_start_addr(uart->tx_dma_channel, (unsigned long)(xmit->buf+xmit->tail)); |
416 | set_dma_x_count(uart->tx_dma_channel, uart->tx_count); | 421 | set_dma_x_count(uart->tx_dma_channel, uart->tx_count); |
417 | set_dma_x_modify(uart->tx_dma_channel, 1); | 422 | set_dma_x_modify(uart->tx_dma_channel, 1); |
423 | SSYNC(); | ||
418 | enable_dma(uart->tx_dma_channel); | 424 | enable_dma(uart->tx_dma_channel); |
419 | 425 | ||
420 | UART_SET_IER(uart, ETBEI); | 426 | UART_SET_IER(uart, ETBEI); |
@@ -473,27 +479,41 @@ static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart) | |||
473 | void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart) | 479 | void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart) |
474 | { | 480 | { |
475 | int x_pos, pos; | 481 | int x_pos, pos; |
476 | unsigned long flags; | ||
477 | |||
478 | spin_lock_irqsave(&uart->port.lock, flags); | ||
479 | 482 | ||
483 | dma_disable_irq(uart->rx_dma_channel); | ||
484 | spin_lock_bh(&uart->port.lock); | ||
485 | |||
486 | /* 2D DMA RX buffer ring is used. Because curr_y_count and | ||
487 | * curr_x_count can't be read as an atomic operation, | ||
488 | * curr_y_count should be read before curr_x_count. When | ||
489 | * curr_x_count is read, curr_y_count may already indicate | ||
490 | * next buffer line. But, the position calculated here is | ||
491 | * still indicate the old line. The wrong position data may | ||
492 | * be smaller than current buffer tail, which cause garbages | ||
493 | * are received if it is not prohibit. | ||
494 | */ | ||
480 | uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel); | 495 | uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel); |
481 | x_pos = get_dma_curr_xcount(uart->rx_dma_channel); | 496 | x_pos = get_dma_curr_xcount(uart->rx_dma_channel); |
482 | uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows; | 497 | uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows; |
483 | if (uart->rx_dma_nrows == DMA_RX_YCOUNT) | 498 | if (uart->rx_dma_nrows == DMA_RX_YCOUNT || x_pos == 0) |
484 | uart->rx_dma_nrows = 0; | 499 | uart->rx_dma_nrows = 0; |
485 | x_pos = DMA_RX_XCOUNT - x_pos; | 500 | x_pos = DMA_RX_XCOUNT - x_pos; |
486 | if (x_pos == DMA_RX_XCOUNT) | 501 | if (x_pos == DMA_RX_XCOUNT) |
487 | x_pos = 0; | 502 | x_pos = 0; |
488 | 503 | ||
489 | pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos; | 504 | pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos; |
490 | if (pos != uart->rx_dma_buf.tail) { | 505 | /* Ignore receiving data if new position is in the same line of |
506 | * current buffer tail and small. | ||
507 | */ | ||
508 | if (pos > uart->rx_dma_buf.tail || | ||
509 | uart->rx_dma_nrows < (uart->rx_dma_buf.tail/DMA_RX_XCOUNT)) { | ||
491 | uart->rx_dma_buf.head = pos; | 510 | uart->rx_dma_buf.head = pos; |
492 | bfin_serial_dma_rx_chars(uart); | 511 | bfin_serial_dma_rx_chars(uart); |
493 | uart->rx_dma_buf.tail = uart->rx_dma_buf.head; | 512 | uart->rx_dma_buf.tail = uart->rx_dma_buf.head; |
494 | } | 513 | } |
495 | 514 | ||
496 | spin_unlock_irqrestore(&uart->port.lock, flags); | 515 | spin_unlock_bh(&uart->port.lock); |
516 | dma_enable_irq(uart->rx_dma_channel); | ||
497 | 517 | ||
498 | mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES); | 518 | mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES); |
499 | } | 519 | } |
@@ -514,6 +534,11 @@ static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id) | |||
514 | if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) { | 534 | if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) { |
515 | disable_dma(uart->tx_dma_channel); | 535 | disable_dma(uart->tx_dma_channel); |
516 | clear_dma_irqstat(uart->tx_dma_channel); | 536 | clear_dma_irqstat(uart->tx_dma_channel); |
537 | /* Anomaly notes: | ||
538 | * 05000215 - we always clear ETBEI within last UART TX | ||
539 | * interrupt to end a string. It is always set | ||
540 | * when start a new tx. | ||
541 | */ | ||
517 | UART_CLEAR_IER(uart, ETBEI); | 542 | UART_CLEAR_IER(uart, ETBEI); |
518 | xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); | 543 | xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); |
519 | uart->port.icount.tx += uart->tx_count; | 544 | uart->port.icount.tx += uart->tx_count; |
@@ -532,11 +557,26 @@ static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id) | |||
532 | { | 557 | { |
533 | struct bfin_serial_port *uart = dev_id; | 558 | struct bfin_serial_port *uart = dev_id; |
534 | unsigned short irqstat; | 559 | unsigned short irqstat; |
560 | int x_pos, pos; | ||
535 | 561 | ||
536 | spin_lock(&uart->port.lock); | 562 | spin_lock(&uart->port.lock); |
537 | irqstat = get_dma_curr_irqstat(uart->rx_dma_channel); | 563 | irqstat = get_dma_curr_irqstat(uart->rx_dma_channel); |
538 | clear_dma_irqstat(uart->rx_dma_channel); | 564 | clear_dma_irqstat(uart->rx_dma_channel); |
539 | bfin_serial_dma_rx_chars(uart); | 565 | |
566 | uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel); | ||
567 | x_pos = get_dma_curr_xcount(uart->rx_dma_channel); | ||
568 | uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows; | ||
569 | if (uart->rx_dma_nrows == DMA_RX_YCOUNT || x_pos == 0) | ||
570 | uart->rx_dma_nrows = 0; | ||
571 | |||
572 | pos = uart->rx_dma_nrows * DMA_RX_XCOUNT; | ||
573 | if (pos > uart->rx_dma_buf.tail || | ||
574 | uart->rx_dma_nrows < (uart->rx_dma_buf.tail/DMA_RX_XCOUNT)) { | ||
575 | uart->rx_dma_buf.head = pos; | ||
576 | bfin_serial_dma_rx_chars(uart); | ||
577 | uart->rx_dma_buf.tail = uart->rx_dma_buf.head; | ||
578 | } | ||
579 | |||
540 | spin_unlock(&uart->port.lock); | 580 | spin_unlock(&uart->port.lock); |
541 | 581 | ||
542 | return IRQ_HANDLED; | 582 | return IRQ_HANDLED; |
@@ -789,8 +829,16 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios, | |||
789 | __func__); | 829 | __func__); |
790 | } | 830 | } |
791 | 831 | ||
792 | if (termios->c_cflag & CSTOPB) | 832 | /* Anomaly notes: |
793 | lcr |= STB; | 833 | * 05000231 - STOP bit is always set to 1 whatever the user is set. |
834 | */ | ||
835 | if (termios->c_cflag & CSTOPB) { | ||
836 | if (ANOMALY_05000231) | ||
837 | printk(KERN_WARNING "STOP bits other than 1 is not " | ||
838 | "supported in case of anomaly 05000231.\n"); | ||
839 | else | ||
840 | lcr |= STB; | ||
841 | } | ||
794 | if (termios->c_cflag & PARENB) | 842 | if (termios->c_cflag & PARENB) |
795 | lcr |= PEN; | 843 | lcr |= PEN; |
796 | if (!(termios->c_cflag & PARODD)) | 844 | if (!(termios->c_cflag & PARODD)) |
@@ -940,6 +988,10 @@ static void bfin_serial_reset_irda(struct uart_port *port) | |||
940 | } | 988 | } |
941 | 989 | ||
942 | #ifdef CONFIG_CONSOLE_POLL | 990 | #ifdef CONFIG_CONSOLE_POLL |
991 | /* Anomaly notes: | ||
992 | * 05000099 - Because we only use THRE in poll_put and DR in poll_get, | ||
993 | * losing other bits of UART_LSR is not a problem here. | ||
994 | */ | ||
943 | static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr) | 995 | static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr) |
944 | { | 996 | { |
945 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; | 997 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
@@ -1245,12 +1297,17 @@ static __init void early_serial_write(struct console *con, const char *s, | |||
1245 | } | 1297 | } |
1246 | } | 1298 | } |
1247 | 1299 | ||
1300 | /* | ||
1301 | * This should have a .setup or .early_setup in it, but then things get called | ||
1302 | * without the command line options, and the baud rate gets messed up - so | ||
1303 | * don't let the common infrastructure play with things. (see calls to setup | ||
1304 | * & earlysetup in ./kernel/printk.c:register_console() | ||
1305 | */ | ||
1248 | static struct __initdata console bfin_early_serial_console = { | 1306 | static struct __initdata console bfin_early_serial_console = { |
1249 | .name = "early_BFuart", | 1307 | .name = "early_BFuart", |
1250 | .write = early_serial_write, | 1308 | .write = early_serial_write, |
1251 | .device = uart_console_device, | 1309 | .device = uart_console_device, |
1252 | .flags = CON_PRINTBUFFER, | 1310 | .flags = CON_PRINTBUFFER, |
1253 | .setup = bfin_serial_console_setup, | ||
1254 | .index = -1, | 1311 | .index = -1, |
1255 | .data = &bfin_serial_reg, | 1312 | .data = &bfin_serial_reg, |
1256 | }; | 1313 | }; |
diff --git a/drivers/serial/bfin_sport_uart.c b/drivers/serial/bfin_sport_uart.c index 529c0ff7952c..34b4ae0fe760 100644 --- a/drivers/serial/bfin_sport_uart.c +++ b/drivers/serial/bfin_sport_uart.c | |||
@@ -101,15 +101,16 @@ static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value) | |||
101 | { | 101 | { |
102 | pr_debug("%s value:%x\n", __func__, value); | 102 | pr_debug("%s value:%x\n", __func__, value); |
103 | /* Place a Start and Stop bit */ | 103 | /* Place a Start and Stop bit */ |
104 | __asm__ volatile ( | 104 | __asm__ __volatile__ ( |
105 | "R2 = b#01111111100;\n\t" | 105 | "R2 = b#01111111100;" |
106 | "R3 = b#10000000001;\n\t" | 106 | "R3 = b#10000000001;" |
107 | "%0 <<= 2;\n\t" | 107 | "%0 <<= 2;" |
108 | "%0 = %0 & R2;\n\t" | 108 | "%0 = %0 & R2;" |
109 | "%0 = %0 | R3;\n\t" | 109 | "%0 = %0 | R3;" |
110 | :"=r"(value) | 110 | : "=d"(value) |
111 | :"0"(value) | 111 | : "d"(value) |
112 | :"R2", "R3"); | 112 | : "ASTAT", "R2", "R3" |
113 | ); | ||
113 | pr_debug("%s value:%x\n", __func__, value); | 114 | pr_debug("%s value:%x\n", __func__, value); |
114 | 115 | ||
115 | SPORT_PUT_TX(up, value); | 116 | SPORT_PUT_TX(up, value); |
@@ -118,27 +119,30 @@ static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value) | |||
118 | static inline unsigned int rx_one_byte(struct sport_uart_port *up) | 119 | static inline unsigned int rx_one_byte(struct sport_uart_port *up) |
119 | { | 120 | { |
120 | unsigned int value, extract; | 121 | unsigned int value, extract; |
122 | u32 tmp_mask1, tmp_mask2, tmp_shift, tmp; | ||
121 | 123 | ||
122 | value = SPORT_GET_RX32(up); | 124 | value = SPORT_GET_RX32(up); |
123 | pr_debug("%s value:%x\n", __func__, value); | 125 | pr_debug("%s value:%x\n", __func__, value); |
124 | 126 | ||
125 | /* Extract 8 bits data */ | 127 | /* Extract 8 bits data */ |
126 | __asm__ volatile ( | 128 | __asm__ __volatile__ ( |
127 | "R5 = 0;\n\t" | 129 | "%[extr] = 0;" |
128 | "P0 = 8;\n\t" | 130 | "%[mask1] = 0x1801(Z);" |
129 | "R1 = 0x1801(Z);\n\t" | 131 | "%[mask2] = 0x0300(Z);" |
130 | "R3 = 0x0300(Z);\n\t" | 132 | "%[shift] = 0;" |
131 | "R4 = 0;\n\t" | 133 | "LSETUP(.Lloop_s, .Lloop_e) LC0 = %[lc];" |
132 | "LSETUP(loop_s, loop_e) LC0 = P0;\nloop_s:\t" | 134 | ".Lloop_s:" |
133 | "R2 = extract(%1, R1.L)(Z);\n\t" | 135 | "%[tmp] = extract(%[val], %[mask1].L)(Z);" |
134 | "R2 <<= R4;\n\t" | 136 | "%[tmp] <<= %[shift];" |
135 | "R5 = R5 | R2;\n\t" | 137 | "%[extr] = %[extr] | %[tmp];" |
136 | "R1 = R1 - R3;\nloop_e:\t" | 138 | "%[mask1] = %[mask1] - %[mask2];" |
137 | "R4 += 1;\n\t" | 139 | ".Lloop_e:" |
138 | "%0 = R5;\n\t" | 140 | "%[shift] += 1;" |
139 | :"=r"(extract) | 141 | : [val]"=d"(value), [extr]"=d"(extract), [shift]"=d"(tmp_shift), [tmp]"=d"(tmp), |
140 | :"r"(value) | 142 | [mask1]"=d"(tmp_mask1), [mask2]"=d"(tmp_mask2) |
141 | :"P0", "R1", "R2","R3","R4", "R5"); | 143 | : "d"(value), [lc]"a"(8) |
144 | : "ASTAT", "LB0", "LC0", "LT0" | ||
145 | ); | ||
142 | 146 | ||
143 | pr_debug(" extract:%x\n", extract); | 147 | pr_debug(" extract:%x\n", extract); |
144 | return extract; | 148 | return extract; |
@@ -149,7 +153,7 @@ static int sport_uart_setup(struct sport_uart_port *up, int sclk, int baud_rate) | |||
149 | int tclkdiv, tfsdiv, rclkdiv; | 153 | int tclkdiv, tfsdiv, rclkdiv; |
150 | 154 | ||
151 | /* Set TCR1 and TCR2 */ | 155 | /* Set TCR1 and TCR2 */ |
152 | SPORT_PUT_TCR1(up, (LTFS | ITFS | TFSR | TLSBIT | ITCLK)); | 156 | SPORT_PUT_TCR1(up, (LATFS | ITFS | TFSR | TLSBIT | ITCLK)); |
153 | SPORT_PUT_TCR2(up, 10); | 157 | SPORT_PUT_TCR2(up, 10); |
154 | pr_debug("%s TCR1:%x, TCR2:%x\n", __func__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up)); | 158 | pr_debug("%s TCR1:%x, TCR2:%x\n", __func__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up)); |
155 | 159 | ||
@@ -419,7 +423,7 @@ static void sport_shutdown(struct uart_port *port) | |||
419 | } | 423 | } |
420 | 424 | ||
421 | static void sport_set_termios(struct uart_port *port, | 425 | static void sport_set_termios(struct uart_port *port, |
422 | struct termios *termios, struct termios *old) | 426 | struct ktermios *termios, struct ktermios *old) |
423 | { | 427 | { |
424 | pr_debug("%s enter, c_cflag:%08x\n", __func__, termios->c_cflag); | 428 | pr_debug("%s enter, c_cflag:%08x\n", __func__, termios->c_cflag); |
425 | uart_update_timeout(port, CS8 ,port->uartclk); | 429 | uart_update_timeout(port, CS8 ,port->uartclk); |
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c index 6579e2be1dd1..9f2891c2c4a2 100644 --- a/drivers/serial/icom.c +++ b/drivers/serial/icom.c | |||
@@ -137,7 +137,12 @@ static LIST_HEAD(icom_adapter_head); | |||
137 | static spinlock_t icom_lock; | 137 | static spinlock_t icom_lock; |
138 | 138 | ||
139 | #ifdef ICOM_TRACE | 139 | #ifdef ICOM_TRACE |
140 | static inline void trace(struct icom_port *, char *, unsigned long) {}; | 140 | static inline void trace(struct icom_port *icom_port, char *trace_pt, |
141 | unsigned long trace_data) | ||
142 | { | ||
143 | dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n", | ||
144 | icom_port->port, trace_pt, trace_data); | ||
145 | } | ||
141 | #else | 146 | #else |
142 | static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {}; | 147 | static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {}; |
143 | #endif | 148 | #endif |
@@ -408,7 +413,7 @@ static void load_code(struct icom_port *icom_port) | |||
408 | release_firmware(fw); | 413 | release_firmware(fw); |
409 | 414 | ||
410 | /* Set Hardware level */ | 415 | /* Set Hardware level */ |
411 | if ((icom_port->adapter->version | ADAPTER_V2) == ADAPTER_V2) | 416 | if (icom_port->adapter->version == ADAPTER_V2) |
412 | writeb(V2_HARDWARE, &(icom_port->dram->misc_flags)); | 417 | writeb(V2_HARDWARE, &(icom_port->dram->misc_flags)); |
413 | 418 | ||
414 | /* Start the processor in Adapter */ | 419 | /* Start the processor in Adapter */ |
@@ -861,7 +866,7 @@ static irqreturn_t icom_interrupt(int irq, void *dev_id) | |||
861 | /* find icom_port for this interrupt */ | 866 | /* find icom_port for this interrupt */ |
862 | icom_adapter = (struct icom_adapter *) dev_id; | 867 | icom_adapter = (struct icom_adapter *) dev_id; |
863 | 868 | ||
864 | if ((icom_adapter->version | ADAPTER_V2) == ADAPTER_V2) { | 869 | if (icom_adapter->version == ADAPTER_V2) { |
865 | int_reg = icom_adapter->base_addr + 0x8024; | 870 | int_reg = icom_adapter->base_addr + 0x8024; |
866 | 871 | ||
867 | adapter_interrupts = readl(int_reg); | 872 | adapter_interrupts = readl(int_reg); |
@@ -1472,8 +1477,8 @@ static void icom_remove_adapter(struct icom_adapter *icom_adapter) | |||
1472 | 1477 | ||
1473 | free_irq(icom_adapter->pci_dev->irq, (void *) icom_adapter); | 1478 | free_irq(icom_adapter->pci_dev->irq, (void *) icom_adapter); |
1474 | iounmap(icom_adapter->base_addr); | 1479 | iounmap(icom_adapter->base_addr); |
1475 | icom_free_adapter(icom_adapter); | ||
1476 | pci_release_regions(icom_adapter->pci_dev); | 1480 | pci_release_regions(icom_adapter->pci_dev); |
1481 | icom_free_adapter(icom_adapter); | ||
1477 | } | 1482 | } |
1478 | 1483 | ||
1479 | static void icom_kref_release(struct kref *kref) | 1484 | static void icom_kref_release(struct kref *kref) |
@@ -1647,15 +1652,6 @@ static void __exit icom_exit(void) | |||
1647 | module_init(icom_init); | 1652 | module_init(icom_init); |
1648 | module_exit(icom_exit); | 1653 | module_exit(icom_exit); |
1649 | 1654 | ||
1650 | #ifdef ICOM_TRACE | ||
1651 | static inline void trace(struct icom_port *icom_port, char *trace_pt, | ||
1652 | unsigned long trace_data) | ||
1653 | { | ||
1654 | dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n", | ||
1655 | icom_port->port, trace_pt, trace_data); | ||
1656 | } | ||
1657 | #endif | ||
1658 | |||
1659 | MODULE_AUTHOR("Michael Anderson <mjanders@us.ibm.com>"); | 1655 | MODULE_AUTHOR("Michael Anderson <mjanders@us.ibm.com>"); |
1660 | MODULE_DESCRIPTION("IBM iSeries Serial IOA driver"); | 1656 | MODULE_DESCRIPTION("IBM iSeries Serial IOA driver"); |
1661 | MODULE_SUPPORTED_DEVICE | 1657 | MODULE_SUPPORTED_DEVICE |
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c index 9f460b175c50..7b5d1de9cfe3 100644 --- a/drivers/serial/imx.c +++ b/drivers/serial/imx.c | |||
@@ -8,6 +8,9 @@ | |||
8 | * Author: Sascha Hauer <sascha@saschahauer.de> | 8 | * Author: Sascha Hauer <sascha@saschahauer.de> |
9 | * Copyright (C) 2004 Pengutronix | 9 | * Copyright (C) 2004 Pengutronix |
10 | * | 10 | * |
11 | * Copyright (C) 2009 emlix GmbH | ||
12 | * Author: Fabian Godehardt (added IrDA support for iMX) | ||
13 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | 14 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by | 15 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or | 16 | * the Free Software Foundation; either version 2 of the License, or |
@@ -41,6 +44,8 @@ | |||
41 | #include <linux/serial_core.h> | 44 | #include <linux/serial_core.h> |
42 | #include <linux/serial.h> | 45 | #include <linux/serial.h> |
43 | #include <linux/clk.h> | 46 | #include <linux/clk.h> |
47 | #include <linux/delay.h> | ||
48 | #include <linux/rational.h> | ||
44 | 49 | ||
45 | #include <asm/io.h> | 50 | #include <asm/io.h> |
46 | #include <asm/irq.h> | 51 | #include <asm/irq.h> |
@@ -148,6 +153,7 @@ | |||
148 | #define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ | 153 | #define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ |
149 | #define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */ | 154 | #define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */ |
150 | #define UFCR_RFDIV (7<<7) /* Reference freq divider mask */ | 155 | #define UFCR_RFDIV (7<<7) /* Reference freq divider mask */ |
156 | #define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7) | ||
151 | #define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */ | 157 | #define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */ |
152 | #define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */ | 158 | #define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */ |
153 | #define USR1_RTSS (1<<14) /* RTS pin status */ | 159 | #define USR1_RTSS (1<<14) /* RTS pin status */ |
@@ -211,10 +217,20 @@ struct imx_port { | |||
211 | struct timer_list timer; | 217 | struct timer_list timer; |
212 | unsigned int old_status; | 218 | unsigned int old_status; |
213 | int txirq,rxirq,rtsirq; | 219 | int txirq,rxirq,rtsirq; |
214 | int have_rtscts:1; | 220 | unsigned int have_rtscts:1; |
221 | unsigned int use_irda:1; | ||
222 | unsigned int irda_inv_rx:1; | ||
223 | unsigned int irda_inv_tx:1; | ||
224 | unsigned short trcv_delay; /* transceiver delay */ | ||
215 | struct clk *clk; | 225 | struct clk *clk; |
216 | }; | 226 | }; |
217 | 227 | ||
228 | #ifdef CONFIG_IRDA | ||
229 | #define USE_IRDA(sport) ((sport)->use_irda) | ||
230 | #else | ||
231 | #define USE_IRDA(sport) (0) | ||
232 | #endif | ||
233 | |||
218 | /* | 234 | /* |
219 | * Handle any change of modem status signal since we were last called. | 235 | * Handle any change of modem status signal since we were last called. |
220 | */ | 236 | */ |
@@ -268,6 +284,48 @@ static void imx_stop_tx(struct uart_port *port) | |||
268 | struct imx_port *sport = (struct imx_port *)port; | 284 | struct imx_port *sport = (struct imx_port *)port; |
269 | unsigned long temp; | 285 | unsigned long temp; |
270 | 286 | ||
287 | if (USE_IRDA(sport)) { | ||
288 | /* half duplex - wait for end of transmission */ | ||
289 | int n = 256; | ||
290 | while ((--n > 0) && | ||
291 | !(readl(sport->port.membase + USR2) & USR2_TXDC)) { | ||
292 | udelay(5); | ||
293 | barrier(); | ||
294 | } | ||
295 | /* | ||
296 | * irda transceiver - wait a bit more to avoid | ||
297 | * cutoff, hardware dependent | ||
298 | */ | ||
299 | udelay(sport->trcv_delay); | ||
300 | |||
301 | /* | ||
302 | * half duplex - reactivate receive mode, | ||
303 | * flush receive pipe echo crap | ||
304 | */ | ||
305 | if (readl(sport->port.membase + USR2) & USR2_TXDC) { | ||
306 | temp = readl(sport->port.membase + UCR1); | ||
307 | temp &= ~(UCR1_TXMPTYEN | UCR1_TRDYEN); | ||
308 | writel(temp, sport->port.membase + UCR1); | ||
309 | |||
310 | temp = readl(sport->port.membase + UCR4); | ||
311 | temp &= ~(UCR4_TCEN); | ||
312 | writel(temp, sport->port.membase + UCR4); | ||
313 | |||
314 | while (readl(sport->port.membase + URXD0) & | ||
315 | URXD_CHARRDY) | ||
316 | barrier(); | ||
317 | |||
318 | temp = readl(sport->port.membase + UCR1); | ||
319 | temp |= UCR1_RRDYEN; | ||
320 | writel(temp, sport->port.membase + UCR1); | ||
321 | |||
322 | temp = readl(sport->port.membase + UCR4); | ||
323 | temp |= UCR4_DREN; | ||
324 | writel(temp, sport->port.membase + UCR4); | ||
325 | } | ||
326 | return; | ||
327 | } | ||
328 | |||
271 | temp = readl(sport->port.membase + UCR1); | 329 | temp = readl(sport->port.membase + UCR1); |
272 | writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1); | 330 | writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1); |
273 | } | 331 | } |
@@ -302,13 +360,15 @@ static inline void imx_transmit_buffer(struct imx_port *sport) | |||
302 | /* send xmit->buf[xmit->tail] | 360 | /* send xmit->buf[xmit->tail] |
303 | * out the port here */ | 361 | * out the port here */ |
304 | writel(xmit->buf[xmit->tail], sport->port.membase + URTX0); | 362 | writel(xmit->buf[xmit->tail], sport->port.membase + URTX0); |
305 | xmit->tail = (xmit->tail + 1) & | 363 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
306 | (UART_XMIT_SIZE - 1); | ||
307 | sport->port.icount.tx++; | 364 | sport->port.icount.tx++; |
308 | if (uart_circ_empty(xmit)) | 365 | if (uart_circ_empty(xmit)) |
309 | break; | 366 | break; |
310 | } | 367 | } |
311 | 368 | ||
369 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) | ||
370 | uart_write_wakeup(&sport->port); | ||
371 | |||
312 | if (uart_circ_empty(xmit)) | 372 | if (uart_circ_empty(xmit)) |
313 | imx_stop_tx(&sport->port); | 373 | imx_stop_tx(&sport->port); |
314 | } | 374 | } |
@@ -321,9 +381,30 @@ static void imx_start_tx(struct uart_port *port) | |||
321 | struct imx_port *sport = (struct imx_port *)port; | 381 | struct imx_port *sport = (struct imx_port *)port; |
322 | unsigned long temp; | 382 | unsigned long temp; |
323 | 383 | ||
384 | if (USE_IRDA(sport)) { | ||
385 | /* half duplex in IrDA mode; have to disable receive mode */ | ||
386 | temp = readl(sport->port.membase + UCR4); | ||
387 | temp &= ~(UCR4_DREN); | ||
388 | writel(temp, sport->port.membase + UCR4); | ||
389 | |||
390 | temp = readl(sport->port.membase + UCR1); | ||
391 | temp &= ~(UCR1_RRDYEN); | ||
392 | writel(temp, sport->port.membase + UCR1); | ||
393 | } | ||
394 | |||
324 | temp = readl(sport->port.membase + UCR1); | 395 | temp = readl(sport->port.membase + UCR1); |
325 | writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1); | 396 | writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1); |
326 | 397 | ||
398 | if (USE_IRDA(sport)) { | ||
399 | temp = readl(sport->port.membase + UCR1); | ||
400 | temp |= UCR1_TRDYEN; | ||
401 | writel(temp, sport->port.membase + UCR1); | ||
402 | |||
403 | temp = readl(sport->port.membase + UCR4); | ||
404 | temp |= UCR4_TCEN; | ||
405 | writel(temp, sport->port.membase + UCR4); | ||
406 | } | ||
407 | |||
327 | if (readl(sport->port.membase + UTS) & UTS_TXEMPTY) | 408 | if (readl(sport->port.membase + UTS) & UTS_TXEMPTY) |
328 | imx_transmit_buffer(sport); | 409 | imx_transmit_buffer(sport); |
329 | } | 410 | } |
@@ -395,8 +476,7 @@ static irqreturn_t imx_rxint(int irq, void *dev_id) | |||
395 | continue; | 476 | continue; |
396 | } | 477 | } |
397 | 478 | ||
398 | if (uart_handle_sysrq_char | 479 | if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx)) |
399 | (&sport->port, (unsigned char)rx)) | ||
400 | continue; | 480 | continue; |
401 | 481 | ||
402 | if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) { | 482 | if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) { |
@@ -471,26 +551,26 @@ static unsigned int imx_tx_empty(struct uart_port *port) | |||
471 | */ | 551 | */ |
472 | static unsigned int imx_get_mctrl(struct uart_port *port) | 552 | static unsigned int imx_get_mctrl(struct uart_port *port) |
473 | { | 553 | { |
474 | struct imx_port *sport = (struct imx_port *)port; | 554 | struct imx_port *sport = (struct imx_port *)port; |
475 | unsigned int tmp = TIOCM_DSR | TIOCM_CAR; | 555 | unsigned int tmp = TIOCM_DSR | TIOCM_CAR; |
476 | 556 | ||
477 | if (readl(sport->port.membase + USR1) & USR1_RTSS) | 557 | if (readl(sport->port.membase + USR1) & USR1_RTSS) |
478 | tmp |= TIOCM_CTS; | 558 | tmp |= TIOCM_CTS; |
479 | 559 | ||
480 | if (readl(sport->port.membase + UCR2) & UCR2_CTS) | 560 | if (readl(sport->port.membase + UCR2) & UCR2_CTS) |
481 | tmp |= TIOCM_RTS; | 561 | tmp |= TIOCM_RTS; |
482 | 562 | ||
483 | return tmp; | 563 | return tmp; |
484 | } | 564 | } |
485 | 565 | ||
486 | static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl) | 566 | static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl) |
487 | { | 567 | { |
488 | struct imx_port *sport = (struct imx_port *)port; | 568 | struct imx_port *sport = (struct imx_port *)port; |
489 | unsigned long temp; | 569 | unsigned long temp; |
490 | 570 | ||
491 | temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS; | 571 | temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS; |
492 | 572 | ||
493 | if (mctrl & TIOCM_RTS) | 573 | if (mctrl & TIOCM_RTS) |
494 | temp |= UCR2_CTS; | 574 | temp |= UCR2_CTS; |
495 | 575 | ||
496 | writel(temp, sport->port.membase + UCR2); | 576 | writel(temp, sport->port.membase + UCR2); |
@@ -534,12 +614,7 @@ static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode) | |||
534 | if(!ufcr_rfdiv) | 614 | if(!ufcr_rfdiv) |
535 | ufcr_rfdiv = 1; | 615 | ufcr_rfdiv = 1; |
536 | 616 | ||
537 | if(ufcr_rfdiv >= 7) | 617 | val |= UFCR_RFDIV_REG(ufcr_rfdiv); |
538 | ufcr_rfdiv = 6; | ||
539 | else | ||
540 | ufcr_rfdiv = 6 - ufcr_rfdiv; | ||
541 | |||
542 | val |= UFCR_RFDIV & (ufcr_rfdiv << 7); | ||
543 | 618 | ||
544 | writel(val, sport->port.membase + UFCR); | 619 | writel(val, sport->port.membase + UFCR); |
545 | 620 | ||
@@ -558,8 +633,24 @@ static int imx_startup(struct uart_port *port) | |||
558 | * requesting IRQs | 633 | * requesting IRQs |
559 | */ | 634 | */ |
560 | temp = readl(sport->port.membase + UCR4); | 635 | temp = readl(sport->port.membase + UCR4); |
636 | |||
637 | if (USE_IRDA(sport)) | ||
638 | temp |= UCR4_IRSC; | ||
639 | |||
561 | writel(temp & ~UCR4_DREN, sport->port.membase + UCR4); | 640 | writel(temp & ~UCR4_DREN, sport->port.membase + UCR4); |
562 | 641 | ||
642 | if (USE_IRDA(sport)) { | ||
643 | /* reset fifo's and state machines */ | ||
644 | int i = 100; | ||
645 | temp = readl(sport->port.membase + UCR2); | ||
646 | temp &= ~UCR2_SRST; | ||
647 | writel(temp, sport->port.membase + UCR2); | ||
648 | while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) && | ||
649 | (--i > 0)) { | ||
650 | udelay(1); | ||
651 | } | ||
652 | } | ||
653 | |||
563 | /* | 654 | /* |
564 | * Allocate the IRQ(s) i.MX1 has three interrupts whereas later | 655 | * Allocate the IRQ(s) i.MX1 has three interrupts whereas later |
565 | * chips only have one interrupt. | 656 | * chips only have one interrupt. |
@@ -575,12 +666,16 @@ static int imx_startup(struct uart_port *port) | |||
575 | if (retval) | 666 | if (retval) |
576 | goto error_out2; | 667 | goto error_out2; |
577 | 668 | ||
578 | retval = request_irq(sport->rtsirq, imx_rtsint, | 669 | /* do not use RTS IRQ on IrDA */ |
579 | (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 : | 670 | if (!USE_IRDA(sport)) { |
580 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, | 671 | retval = request_irq(sport->rtsirq, imx_rtsint, |
581 | DRIVER_NAME, sport); | 672 | (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 : |
582 | if (retval) | 673 | IRQF_TRIGGER_FALLING | |
583 | goto error_out3; | 674 | IRQF_TRIGGER_RISING, |
675 | DRIVER_NAME, sport); | ||
676 | if (retval) | ||
677 | goto error_out3; | ||
678 | } | ||
584 | } else { | 679 | } else { |
585 | retval = request_irq(sport->port.irq, imx_int, 0, | 680 | retval = request_irq(sport->port.irq, imx_int, 0, |
586 | DRIVER_NAME, sport); | 681 | DRIVER_NAME, sport); |
@@ -597,18 +692,49 @@ static int imx_startup(struct uart_port *port) | |||
597 | 692 | ||
598 | temp = readl(sport->port.membase + UCR1); | 693 | temp = readl(sport->port.membase + UCR1); |
599 | temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN; | 694 | temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN; |
695 | |||
696 | if (USE_IRDA(sport)) { | ||
697 | temp |= UCR1_IREN; | ||
698 | temp &= ~(UCR1_RTSDEN); | ||
699 | } | ||
700 | |||
600 | writel(temp, sport->port.membase + UCR1); | 701 | writel(temp, sport->port.membase + UCR1); |
601 | 702 | ||
602 | temp = readl(sport->port.membase + UCR2); | 703 | temp = readl(sport->port.membase + UCR2); |
603 | temp |= (UCR2_RXEN | UCR2_TXEN); | 704 | temp |= (UCR2_RXEN | UCR2_TXEN); |
604 | writel(temp, sport->port.membase + UCR2); | 705 | writel(temp, sport->port.membase + UCR2); |
605 | 706 | ||
707 | if (USE_IRDA(sport)) { | ||
708 | /* clear RX-FIFO */ | ||
709 | int i = 64; | ||
710 | while ((--i > 0) && | ||
711 | (readl(sport->port.membase + URXD0) & URXD_CHARRDY)) { | ||
712 | barrier(); | ||
713 | } | ||
714 | } | ||
715 | |||
606 | #if defined CONFIG_ARCH_MX2 || defined CONFIG_ARCH_MX3 | 716 | #if defined CONFIG_ARCH_MX2 || defined CONFIG_ARCH_MX3 |
607 | temp = readl(sport->port.membase + UCR3); | 717 | temp = readl(sport->port.membase + UCR3); |
608 | temp |= UCR3_RXDMUXSEL; | 718 | temp |= UCR3_RXDMUXSEL; |
609 | writel(temp, sport->port.membase + UCR3); | 719 | writel(temp, sport->port.membase + UCR3); |
610 | #endif | 720 | #endif |
611 | 721 | ||
722 | if (USE_IRDA(sport)) { | ||
723 | temp = readl(sport->port.membase + UCR4); | ||
724 | if (sport->irda_inv_rx) | ||
725 | temp |= UCR4_INVR; | ||
726 | else | ||
727 | temp &= ~(UCR4_INVR); | ||
728 | writel(temp | UCR4_DREN, sport->port.membase + UCR4); | ||
729 | |||
730 | temp = readl(sport->port.membase + UCR3); | ||
731 | if (sport->irda_inv_tx) | ||
732 | temp |= UCR3_INVT; | ||
733 | else | ||
734 | temp &= ~(UCR3_INVT); | ||
735 | writel(temp, sport->port.membase + UCR3); | ||
736 | } | ||
737 | |||
612 | /* | 738 | /* |
613 | * Enable modem status interrupts | 739 | * Enable modem status interrupts |
614 | */ | 740 | */ |
@@ -616,6 +742,16 @@ static int imx_startup(struct uart_port *port) | |||
616 | imx_enable_ms(&sport->port); | 742 | imx_enable_ms(&sport->port); |
617 | spin_unlock_irqrestore(&sport->port.lock,flags); | 743 | spin_unlock_irqrestore(&sport->port.lock,flags); |
618 | 744 | ||
745 | if (USE_IRDA(sport)) { | ||
746 | struct imxuart_platform_data *pdata; | ||
747 | pdata = sport->port.dev->platform_data; | ||
748 | sport->irda_inv_rx = pdata->irda_inv_rx; | ||
749 | sport->irda_inv_tx = pdata->irda_inv_tx; | ||
750 | sport->trcv_delay = pdata->transceiver_delay; | ||
751 | if (pdata->irda_enable) | ||
752 | pdata->irda_enable(1); | ||
753 | } | ||
754 | |||
619 | return 0; | 755 | return 0; |
620 | 756 | ||
621 | error_out3: | 757 | error_out3: |
@@ -633,6 +769,17 @@ static void imx_shutdown(struct uart_port *port) | |||
633 | struct imx_port *sport = (struct imx_port *)port; | 769 | struct imx_port *sport = (struct imx_port *)port; |
634 | unsigned long temp; | 770 | unsigned long temp; |
635 | 771 | ||
772 | temp = readl(sport->port.membase + UCR2); | ||
773 | temp &= ~(UCR2_TXEN); | ||
774 | writel(temp, sport->port.membase + UCR2); | ||
775 | |||
776 | if (USE_IRDA(sport)) { | ||
777 | struct imxuart_platform_data *pdata; | ||
778 | pdata = sport->port.dev->platform_data; | ||
779 | if (pdata->irda_enable) | ||
780 | pdata->irda_enable(0); | ||
781 | } | ||
782 | |||
636 | /* | 783 | /* |
637 | * Stop our timer. | 784 | * Stop our timer. |
638 | */ | 785 | */ |
@@ -642,7 +789,8 @@ static void imx_shutdown(struct uart_port *port) | |||
642 | * Free the interrupts | 789 | * Free the interrupts |
643 | */ | 790 | */ |
644 | if (sport->txirq > 0) { | 791 | if (sport->txirq > 0) { |
645 | free_irq(sport->rtsirq, sport); | 792 | if (!USE_IRDA(sport)) |
793 | free_irq(sport->rtsirq, sport); | ||
646 | free_irq(sport->txirq, sport); | 794 | free_irq(sport->txirq, sport); |
647 | free_irq(sport->rxirq, sport); | 795 | free_irq(sport->rxirq, sport); |
648 | } else | 796 | } else |
@@ -654,6 +802,9 @@ static void imx_shutdown(struct uart_port *port) | |||
654 | 802 | ||
655 | temp = readl(sport->port.membase + UCR1); | 803 | temp = readl(sport->port.membase + UCR1); |
656 | temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); | 804 | temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); |
805 | if (USE_IRDA(sport)) | ||
806 | temp &= ~(UCR1_IREN); | ||
807 | |||
657 | writel(temp, sport->port.membase + UCR1); | 808 | writel(temp, sport->port.membase + UCR1); |
658 | } | 809 | } |
659 | 810 | ||
@@ -665,7 +816,9 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios, | |||
665 | unsigned long flags; | 816 | unsigned long flags; |
666 | unsigned int ucr2, old_ucr1, old_txrxen, baud, quot; | 817 | unsigned int ucr2, old_ucr1, old_txrxen, baud, quot; |
667 | unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; | 818 | unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; |
668 | unsigned int div, num, denom, ufcr; | 819 | unsigned int div, ufcr; |
820 | unsigned long num, denom; | ||
821 | uint64_t tdiv64; | ||
669 | 822 | ||
670 | /* | 823 | /* |
671 | * If we don't support modem control lines, don't allow | 824 | * If we don't support modem control lines, don't allow |
@@ -761,38 +914,39 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios, | |||
761 | sport->port.membase + UCR2); | 914 | sport->port.membase + UCR2); |
762 | old_txrxen &= (UCR2_TXEN | UCR2_RXEN); | 915 | old_txrxen &= (UCR2_TXEN | UCR2_RXEN); |
763 | 916 | ||
764 | div = sport->port.uartclk / (baud * 16); | 917 | if (USE_IRDA(sport)) { |
765 | if (div > 7) | 918 | /* |
766 | div = 7; | 919 | * use maximum available submodule frequency to |
767 | if (!div) | 920 | * avoid missing short pulses due to low sampling rate |
921 | */ | ||
768 | div = 1; | 922 | div = 1; |
769 | 923 | } else { | |
770 | num = baud; | 924 | div = sport->port.uartclk / (baud * 16); |
771 | denom = port->uartclk / div / 16; | 925 | if (div > 7) |
772 | 926 | div = 7; | |
773 | /* shift num and denom right until they fit into 16 bits */ | 927 | if (!div) |
774 | while (num > 0x10000 || denom > 0x10000) { | 928 | div = 1; |
775 | num >>= 1; | ||
776 | denom >>= 1; | ||
777 | } | 929 | } |
778 | if (num > 0) | ||
779 | num -= 1; | ||
780 | if (denom > 0) | ||
781 | denom -= 1; | ||
782 | 930 | ||
783 | writel(num, sport->port.membase + UBIR); | 931 | rational_best_approximation(16 * div * baud, sport->port.uartclk, |
784 | writel(denom, sport->port.membase + UBMR); | 932 | 1 << 16, 1 << 16, &num, &denom); |
785 | 933 | ||
786 | if (div == 7) | 934 | tdiv64 = sport->port.uartclk; |
787 | div = 6; /* 6 in RFDIV means divide by 7 */ | 935 | tdiv64 *= num; |
788 | else | 936 | do_div(tdiv64, denom * 16 * div); |
789 | div = 6 - div; | 937 | tty_encode_baud_rate(sport->port.info->port.tty, |
938 | (speed_t)tdiv64, (speed_t)tdiv64); | ||
939 | |||
940 | num -= 1; | ||
941 | denom -= 1; | ||
790 | 942 | ||
791 | ufcr = readl(sport->port.membase + UFCR); | 943 | ufcr = readl(sport->port.membase + UFCR); |
792 | ufcr = (ufcr & (~UFCR_RFDIV)) | | 944 | ufcr = (ufcr & (~UFCR_RFDIV)) | UFCR_RFDIV_REG(div); |
793 | (div << 7); | ||
794 | writel(ufcr, sport->port.membase + UFCR); | 945 | writel(ufcr, sport->port.membase + UFCR); |
795 | 946 | ||
947 | writel(num, sport->port.membase + UBIR); | ||
948 | writel(denom, sport->port.membase + UBMR); | ||
949 | |||
796 | #ifdef ONEMS | 950 | #ifdef ONEMS |
797 | writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS); | 951 | writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS); |
798 | #endif | 952 | #endif |
@@ -1031,6 +1185,8 @@ imx_console_setup(struct console *co, char *options) | |||
1031 | if (co->index == -1 || co->index >= ARRAY_SIZE(imx_ports)) | 1185 | if (co->index == -1 || co->index >= ARRAY_SIZE(imx_ports)) |
1032 | co->index = 0; | 1186 | co->index = 0; |
1033 | sport = imx_ports[co->index]; | 1187 | sport = imx_ports[co->index]; |
1188 | if(sport == NULL) | ||
1189 | return -ENODEV; | ||
1034 | 1190 | ||
1035 | if (options) | 1191 | if (options) |
1036 | uart_parse_options(options, &baud, &parity, &bits, &flow); | 1192 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
@@ -1070,22 +1226,22 @@ static struct uart_driver imx_reg = { | |||
1070 | 1226 | ||
1071 | static int serial_imx_suspend(struct platform_device *dev, pm_message_t state) | 1227 | static int serial_imx_suspend(struct platform_device *dev, pm_message_t state) |
1072 | { | 1228 | { |
1073 | struct imx_port *sport = platform_get_drvdata(dev); | 1229 | struct imx_port *sport = platform_get_drvdata(dev); |
1074 | 1230 | ||
1075 | if (sport) | 1231 | if (sport) |
1076 | uart_suspend_port(&imx_reg, &sport->port); | 1232 | uart_suspend_port(&imx_reg, &sport->port); |
1077 | 1233 | ||
1078 | return 0; | 1234 | return 0; |
1079 | } | 1235 | } |
1080 | 1236 | ||
1081 | static int serial_imx_resume(struct platform_device *dev) | 1237 | static int serial_imx_resume(struct platform_device *dev) |
1082 | { | 1238 | { |
1083 | struct imx_port *sport = platform_get_drvdata(dev); | 1239 | struct imx_port *sport = platform_get_drvdata(dev); |
1084 | 1240 | ||
1085 | if (sport) | 1241 | if (sport) |
1086 | uart_resume_port(&imx_reg, &sport->port); | 1242 | uart_resume_port(&imx_reg, &sport->port); |
1087 | 1243 | ||
1088 | return 0; | 1244 | return 0; |
1089 | } | 1245 | } |
1090 | 1246 | ||
1091 | static int serial_imx_probe(struct platform_device *pdev) | 1247 | static int serial_imx_probe(struct platform_device *pdev) |
@@ -1141,19 +1297,29 @@ static int serial_imx_probe(struct platform_device *pdev) | |||
1141 | imx_ports[pdev->id] = sport; | 1297 | imx_ports[pdev->id] = sport; |
1142 | 1298 | ||
1143 | pdata = pdev->dev.platform_data; | 1299 | pdata = pdev->dev.platform_data; |
1144 | if(pdata && (pdata->flags & IMXUART_HAVE_RTSCTS)) | 1300 | if (pdata && (pdata->flags & IMXUART_HAVE_RTSCTS)) |
1145 | sport->have_rtscts = 1; | 1301 | sport->have_rtscts = 1; |
1146 | 1302 | ||
1303 | #ifdef CONFIG_IRDA | ||
1304 | if (pdata && (pdata->flags & IMXUART_IRDA)) | ||
1305 | sport->use_irda = 1; | ||
1306 | #endif | ||
1307 | |||
1147 | if (pdata->init) { | 1308 | if (pdata->init) { |
1148 | ret = pdata->init(pdev); | 1309 | ret = pdata->init(pdev); |
1149 | if (ret) | 1310 | if (ret) |
1150 | goto clkput; | 1311 | goto clkput; |
1151 | } | 1312 | } |
1152 | 1313 | ||
1153 | uart_add_one_port(&imx_reg, &sport->port); | 1314 | ret = uart_add_one_port(&imx_reg, &sport->port); |
1315 | if (ret) | ||
1316 | goto deinit; | ||
1154 | platform_set_drvdata(pdev, &sport->port); | 1317 | platform_set_drvdata(pdev, &sport->port); |
1155 | 1318 | ||
1156 | return 0; | 1319 | return 0; |
1320 | deinit: | ||
1321 | if (pdata->exit) | ||
1322 | pdata->exit(pdev); | ||
1157 | clkput: | 1323 | clkput: |
1158 | clk_put(sport->clk); | 1324 | clk_put(sport->clk); |
1159 | clk_disable(sport->clk); | 1325 | clk_disable(sport->clk); |
@@ -1191,13 +1357,13 @@ static int serial_imx_remove(struct platform_device *pdev) | |||
1191 | } | 1357 | } |
1192 | 1358 | ||
1193 | static struct platform_driver serial_imx_driver = { | 1359 | static struct platform_driver serial_imx_driver = { |
1194 | .probe = serial_imx_probe, | 1360 | .probe = serial_imx_probe, |
1195 | .remove = serial_imx_remove, | 1361 | .remove = serial_imx_remove, |
1196 | 1362 | ||
1197 | .suspend = serial_imx_suspend, | 1363 | .suspend = serial_imx_suspend, |
1198 | .resume = serial_imx_resume, | 1364 | .resume = serial_imx_resume, |
1199 | .driver = { | 1365 | .driver = { |
1200 | .name = "imx-uart", | 1366 | .name = "imx-uart", |
1201 | .owner = THIS_MODULE, | 1367 | .owner = THIS_MODULE, |
1202 | }, | 1368 | }, |
1203 | }; | 1369 | }; |
diff --git a/drivers/serial/jsm/jsm.h b/drivers/serial/jsm/jsm.h index c0a3e2734e24..4e5f3bde0461 100644 --- a/drivers/serial/jsm/jsm.h +++ b/drivers/serial/jsm/jsm.h | |||
@@ -61,6 +61,7 @@ enum { | |||
61 | if ((DBG_##nlevel & jsm_debug)) \ | 61 | if ((DBG_##nlevel & jsm_debug)) \ |
62 | dev_printk(KERN_##klevel, pdev->dev, fmt, ## args) | 62 | dev_printk(KERN_##klevel, pdev->dev, fmt, ## args) |
63 | 63 | ||
64 | #define MAXLINES 256 | ||
64 | #define MAXPORTS 8 | 65 | #define MAXPORTS 8 |
65 | #define MAX_STOPS_SENT 5 | 66 | #define MAX_STOPS_SENT 5 |
66 | 67 | ||
diff --git a/drivers/serial/jsm/jsm_tty.c b/drivers/serial/jsm/jsm_tty.c index 31496dc0a0d1..107ce2e187b8 100644 --- a/drivers/serial/jsm/jsm_tty.c +++ b/drivers/serial/jsm/jsm_tty.c | |||
@@ -33,6 +33,8 @@ | |||
33 | 33 | ||
34 | #include "jsm.h" | 34 | #include "jsm.h" |
35 | 35 | ||
36 | static DECLARE_BITMAP(linemap, MAXLINES); | ||
37 | |||
36 | static void jsm_carrier(struct jsm_channel *ch); | 38 | static void jsm_carrier(struct jsm_channel *ch); |
37 | 39 | ||
38 | static inline int jsm_get_mstat(struct jsm_channel *ch) | 40 | static inline int jsm_get_mstat(struct jsm_channel *ch) |
@@ -433,6 +435,7 @@ int __devinit jsm_tty_init(struct jsm_board *brd) | |||
433 | int __devinit jsm_uart_port_init(struct jsm_board *brd) | 435 | int __devinit jsm_uart_port_init(struct jsm_board *brd) |
434 | { | 436 | { |
435 | int i; | 437 | int i; |
438 | unsigned int line; | ||
436 | struct jsm_channel *ch; | 439 | struct jsm_channel *ch; |
437 | 440 | ||
438 | if (!brd) | 441 | if (!brd) |
@@ -459,9 +462,15 @@ int __devinit jsm_uart_port_init(struct jsm_board *brd) | |||
459 | brd->channels[i]->uart_port.membase = brd->re_map_membase; | 462 | brd->channels[i]->uart_port.membase = brd->re_map_membase; |
460 | brd->channels[i]->uart_port.fifosize = 16; | 463 | brd->channels[i]->uart_port.fifosize = 16; |
461 | brd->channels[i]->uart_port.ops = &jsm_ops; | 464 | brd->channels[i]->uart_port.ops = &jsm_ops; |
462 | brd->channels[i]->uart_port.line = brd->channels[i]->ch_portnum + brd->boardnum * 2; | 465 | line = find_first_zero_bit(linemap, MAXLINES); |
466 | if (line >= MAXLINES) { | ||
467 | printk(KERN_INFO "jsm: linemap is full, added device failed\n"); | ||
468 | continue; | ||
469 | } else | ||
470 | set_bit((int)line, linemap); | ||
471 | brd->channels[i]->uart_port.line = line; | ||
463 | if (uart_add_one_port (&jsm_uart_driver, &brd->channels[i]->uart_port)) | 472 | if (uart_add_one_port (&jsm_uart_driver, &brd->channels[i]->uart_port)) |
464 | printk(KERN_INFO "Added device failed\n"); | 473 | printk(KERN_INFO "jsm: add device failed\n"); |
465 | else | 474 | else |
466 | printk(KERN_INFO "Added device \n"); | 475 | printk(KERN_INFO "Added device \n"); |
467 | } | 476 | } |
@@ -494,6 +503,7 @@ int jsm_remove_uart_port(struct jsm_board *brd) | |||
494 | 503 | ||
495 | ch = brd->channels[i]; | 504 | ch = brd->channels[i]; |
496 | 505 | ||
506 | clear_bit((int)(ch->uart_port.line), linemap); | ||
497 | uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port); | 507 | uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port); |
498 | } | 508 | } |
499 | 509 | ||
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c index 7f72f8ceaa6f..b3feb6198d57 100644 --- a/drivers/serial/mpc52xx_uart.c +++ b/drivers/serial/mpc52xx_uart.c | |||
@@ -988,7 +988,7 @@ mpc52xx_console_setup(struct console *co, char *options) | |||
988 | pr_debug("mpc52xx_console_setup co=%p, co->index=%i, options=%s\n", | 988 | pr_debug("mpc52xx_console_setup co=%p, co->index=%i, options=%s\n", |
989 | co, co->index, options); | 989 | co, co->index, options); |
990 | 990 | ||
991 | if ((co->index < 0) || (co->index > MPC52xx_PSC_MAXNUM)) { | 991 | if ((co->index < 0) || (co->index >= MPC52xx_PSC_MAXNUM)) { |
992 | pr_debug("PSC%x out of range\n", co->index); | 992 | pr_debug("PSC%x out of range\n", co->index); |
993 | return -EINVAL; | 993 | return -EINVAL; |
994 | } | 994 | } |
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c index dbf5357a77b3..a4cf1079b312 100644 --- a/drivers/serial/sh-sci.c +++ b/drivers/serial/sh-sci.c | |||
@@ -47,12 +47,17 @@ | |||
47 | #include <linux/clk.h> | 47 | #include <linux/clk.h> |
48 | #include <linux/ctype.h> | 48 | #include <linux/ctype.h> |
49 | #include <linux/err.h> | 49 | #include <linux/err.h> |
50 | #include <linux/list.h> | ||
50 | 51 | ||
51 | #ifdef CONFIG_SUPERH | 52 | #ifdef CONFIG_SUPERH |
52 | #include <asm/clock.h> | 53 | #include <asm/clock.h> |
53 | #include <asm/sh_bios.h> | 54 | #include <asm/sh_bios.h> |
54 | #endif | 55 | #endif |
55 | 56 | ||
57 | #ifdef CONFIG_H8300 | ||
58 | #include <asm/gpio.h> | ||
59 | #endif | ||
60 | |||
56 | #include "sh-sci.h" | 61 | #include "sh-sci.h" |
57 | 62 | ||
58 | struct sci_port { | 63 | struct sci_port { |
@@ -75,14 +80,22 @@ struct sci_port { | |||
75 | int break_flag; | 80 | int break_flag; |
76 | 81 | ||
77 | #ifdef CONFIG_HAVE_CLK | 82 | #ifdef CONFIG_HAVE_CLK |
78 | /* Port clock */ | 83 | /* Interface clock */ |
79 | struct clk *clk; | 84 | struct clk *iclk; |
85 | /* Data clock */ | ||
86 | struct clk *dclk; | ||
80 | #endif | 87 | #endif |
88 | struct list_head node; | ||
81 | }; | 89 | }; |
82 | 90 | ||
83 | #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE | 91 | struct sh_sci_priv { |
84 | static struct sci_port *serial_console_port; | 92 | spinlock_t lock; |
93 | struct list_head ports; | ||
94 | |||
95 | #ifdef CONFIG_HAVE_CLK | ||
96 | struct notifier_block clk_nb; | ||
85 | #endif | 97 | #endif |
98 | }; | ||
86 | 99 | ||
87 | /* Function prototypes */ | 100 | /* Function prototypes */ |
88 | static void sci_stop_tx(struct uart_port *port); | 101 | static void sci_stop_tx(struct uart_port *port); |
@@ -138,9 +151,8 @@ static void sci_poll_put_char(struct uart_port *port, unsigned char c) | |||
138 | status = sci_in(port, SCxSR); | 151 | status = sci_in(port, SCxSR); |
139 | } while (!(status & SCxSR_TDxE(port))); | 152 | } while (!(status & SCxSR_TDxE(port))); |
140 | 153 | ||
141 | sci_in(port, SCxSR); /* Dummy read */ | ||
142 | sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port)); | ||
143 | sci_out(port, SCxTDR, c); | 154 | sci_out(port, SCxTDR, c); |
155 | sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port)); | ||
144 | } | 156 | } |
145 | #endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */ | 157 | #endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */ |
146 | 158 | ||
@@ -159,12 +171,12 @@ static void h8300_sci_config(struct uart_port *port, unsigned int ctrl) | |||
159 | *mstpcrl &= ~mask; | 171 | *mstpcrl &= ~mask; |
160 | } | 172 | } |
161 | 173 | ||
162 | static inline void h8300_sci_enable(struct uart_port *port) | 174 | static void h8300_sci_enable(struct uart_port *port) |
163 | { | 175 | { |
164 | h8300_sci_config(port, sci_enable); | 176 | h8300_sci_config(port, sci_enable); |
165 | } | 177 | } |
166 | 178 | ||
167 | static inline void h8300_sci_disable(struct uart_port *port) | 179 | static void h8300_sci_disable(struct uart_port *port) |
168 | { | 180 | { |
169 | h8300_sci_config(port, sci_disable); | 181 | h8300_sci_config(port, sci_disable); |
170 | } | 182 | } |
@@ -611,7 +623,7 @@ static inline int sci_handle_breaks(struct uart_port *port) | |||
611 | int copied = 0; | 623 | int copied = 0; |
612 | unsigned short status = sci_in(port, SCxSR); | 624 | unsigned short status = sci_in(port, SCxSR); |
613 | struct tty_struct *tty = port->info->port.tty; | 625 | struct tty_struct *tty = port->info->port.tty; |
614 | struct sci_port *s = &sci_ports[port->line]; | 626 | struct sci_port *s = to_sci_port(port); |
615 | 627 | ||
616 | if (uart_handle_break(port)) | 628 | if (uart_handle_break(port)) |
617 | return 0; | 629 | return 0; |
@@ -726,19 +738,43 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr) | |||
726 | static int sci_notifier(struct notifier_block *self, | 738 | static int sci_notifier(struct notifier_block *self, |
727 | unsigned long phase, void *p) | 739 | unsigned long phase, void *p) |
728 | { | 740 | { |
729 | int i; | 741 | struct sh_sci_priv *priv = container_of(self, |
742 | struct sh_sci_priv, clk_nb); | ||
743 | struct sci_port *sci_port; | ||
744 | unsigned long flags; | ||
730 | 745 | ||
731 | if ((phase == CPUFREQ_POSTCHANGE) || | 746 | if ((phase == CPUFREQ_POSTCHANGE) || |
732 | (phase == CPUFREQ_RESUMECHANGE)) | 747 | (phase == CPUFREQ_RESUMECHANGE)) { |
733 | for (i = 0; i < SCI_NPORTS; i++) { | 748 | spin_lock_irqsave(&priv->lock, flags); |
734 | struct sci_port *s = &sci_ports[i]; | 749 | list_for_each_entry(sci_port, &priv->ports, node) |
735 | s->port.uartclk = clk_get_rate(s->clk); | 750 | sci_port->port.uartclk = clk_get_rate(sci_port->dclk); |
736 | } | 751 | |
752 | spin_unlock_irqrestore(&priv->lock, flags); | ||
753 | } | ||
737 | 754 | ||
738 | return NOTIFY_OK; | 755 | return NOTIFY_OK; |
739 | } | 756 | } |
740 | 757 | ||
741 | static struct notifier_block sci_nb = { &sci_notifier, NULL, 0 }; | 758 | static void sci_clk_enable(struct uart_port *port) |
759 | { | ||
760 | struct sci_port *sci_port = to_sci_port(port); | ||
761 | |||
762 | clk_enable(sci_port->dclk); | ||
763 | sci_port->port.uartclk = clk_get_rate(sci_port->dclk); | ||
764 | |||
765 | if (sci_port->iclk) | ||
766 | clk_enable(sci_port->iclk); | ||
767 | } | ||
768 | |||
769 | static void sci_clk_disable(struct uart_port *port) | ||
770 | { | ||
771 | struct sci_port *sci_port = to_sci_port(port); | ||
772 | |||
773 | if (sci_port->iclk) | ||
774 | clk_disable(sci_port->iclk); | ||
775 | |||
776 | clk_disable(sci_port->dclk); | ||
777 | } | ||
742 | #endif | 778 | #endif |
743 | 779 | ||
744 | static int sci_request_irq(struct sci_port *port) | 780 | static int sci_request_irq(struct sci_port *port) |
@@ -865,15 +901,11 @@ static void sci_break_ctl(struct uart_port *port, int break_state) | |||
865 | 901 | ||
866 | static int sci_startup(struct uart_port *port) | 902 | static int sci_startup(struct uart_port *port) |
867 | { | 903 | { |
868 | struct sci_port *s = &sci_ports[port->line]; | 904 | struct sci_port *s = to_sci_port(port); |
869 | 905 | ||
870 | if (s->enable) | 906 | if (s->enable) |
871 | s->enable(port); | 907 | s->enable(port); |
872 | 908 | ||
873 | #ifdef CONFIG_HAVE_CLK | ||
874 | s->clk = clk_get(NULL, "module_clk"); | ||
875 | #endif | ||
876 | |||
877 | sci_request_irq(s); | 909 | sci_request_irq(s); |
878 | sci_start_tx(port); | 910 | sci_start_tx(port); |
879 | sci_start_rx(port, 1); | 911 | sci_start_rx(port, 1); |
@@ -883,7 +915,7 @@ static int sci_startup(struct uart_port *port) | |||
883 | 915 | ||
884 | static void sci_shutdown(struct uart_port *port) | 916 | static void sci_shutdown(struct uart_port *port) |
885 | { | 917 | { |
886 | struct sci_port *s = &sci_ports[port->line]; | 918 | struct sci_port *s = to_sci_port(port); |
887 | 919 | ||
888 | sci_stop_rx(port); | 920 | sci_stop_rx(port); |
889 | sci_stop_tx(port); | 921 | sci_stop_tx(port); |
@@ -891,11 +923,6 @@ static void sci_shutdown(struct uart_port *port) | |||
891 | 923 | ||
892 | if (s->disable) | 924 | if (s->disable) |
893 | s->disable(port); | 925 | s->disable(port); |
894 | |||
895 | #ifdef CONFIG_HAVE_CLK | ||
896 | clk_put(s->clk); | ||
897 | s->clk = NULL; | ||
898 | #endif | ||
899 | } | 926 | } |
900 | 927 | ||
901 | static void sci_set_termios(struct uart_port *port, struct ktermios *termios, | 928 | static void sci_set_termios(struct uart_port *port, struct ktermios *termios, |
@@ -980,25 +1007,31 @@ static int sci_request_port(struct uart_port *port) | |||
980 | 1007 | ||
981 | static void sci_config_port(struct uart_port *port, int flags) | 1008 | static void sci_config_port(struct uart_port *port, int flags) |
982 | { | 1009 | { |
983 | struct sci_port *s = &sci_ports[port->line]; | 1010 | struct sci_port *s = to_sci_port(port); |
984 | 1011 | ||
985 | port->type = s->type; | 1012 | port->type = s->type; |
986 | 1013 | ||
987 | if (port->flags & UPF_IOREMAP && !port->membase) { | 1014 | if (port->membase) |
988 | #if defined(CONFIG_SUPERH64) | 1015 | return; |
989 | port->mapbase = onchip_remap(SCIF_ADDR_SH5, 1024, "SCIF"); | 1016 | |
990 | port->membase = (void __iomem *)port->mapbase; | 1017 | if (port->flags & UPF_IOREMAP) { |
991 | #else | ||
992 | port->membase = ioremap_nocache(port->mapbase, 0x40); | 1018 | port->membase = ioremap_nocache(port->mapbase, 0x40); |
993 | #endif | ||
994 | 1019 | ||
995 | dev_err(port->dev, "can't remap port#%d\n", port->line); | 1020 | if (IS_ERR(port->membase)) |
1021 | dev_err(port->dev, "can't remap port#%d\n", port->line); | ||
1022 | } else { | ||
1023 | /* | ||
1024 | * For the simple (and majority of) cases where we don't | ||
1025 | * need to do any remapping, just cast the cookie | ||
1026 | * directly. | ||
1027 | */ | ||
1028 | port->membase = (void __iomem *)port->mapbase; | ||
996 | } | 1029 | } |
997 | } | 1030 | } |
998 | 1031 | ||
999 | static int sci_verify_port(struct uart_port *port, struct serial_struct *ser) | 1032 | static int sci_verify_port(struct uart_port *port, struct serial_struct *ser) |
1000 | { | 1033 | { |
1001 | struct sci_port *s = &sci_ports[port->line]; | 1034 | struct sci_port *s = to_sci_port(port); |
1002 | 1035 | ||
1003 | if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs) | 1036 | if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs) |
1004 | return -EINVAL; | 1037 | return -EINVAL; |
@@ -1032,63 +1065,60 @@ static struct uart_ops sci_uart_ops = { | |||
1032 | #endif | 1065 | #endif |
1033 | }; | 1066 | }; |
1034 | 1067 | ||
1035 | static void __init sci_init_ports(void) | 1068 | static void __devinit sci_init_single(struct platform_device *dev, |
1069 | struct sci_port *sci_port, | ||
1070 | unsigned int index, | ||
1071 | struct plat_sci_port *p) | ||
1036 | { | 1072 | { |
1037 | static int first = 1; | 1073 | sci_port->port.ops = &sci_uart_ops; |
1038 | int i; | 1074 | sci_port->port.iotype = UPIO_MEM; |
1039 | 1075 | sci_port->port.line = index; | |
1040 | if (!first) | 1076 | sci_port->port.fifosize = 1; |
1041 | return; | ||
1042 | |||
1043 | first = 0; | ||
1044 | |||
1045 | for (i = 0; i < SCI_NPORTS; i++) { | ||
1046 | sci_ports[i].port.ops = &sci_uart_ops; | ||
1047 | sci_ports[i].port.iotype = UPIO_MEM; | ||
1048 | sci_ports[i].port.line = i; | ||
1049 | sci_ports[i].port.fifosize = 1; | ||
1050 | 1077 | ||
1051 | #if defined(__H8300H__) || defined(__H8300S__) | 1078 | #if defined(__H8300H__) || defined(__H8300S__) |
1052 | #ifdef __H8300S__ | 1079 | #ifdef __H8300S__ |
1053 | sci_ports[i].enable = h8300_sci_enable; | 1080 | sci_port->enable = h8300_sci_enable; |
1054 | sci_ports[i].disable = h8300_sci_disable; | 1081 | sci_port->disable = h8300_sci_disable; |
1055 | #endif | 1082 | #endif |
1056 | sci_ports[i].port.uartclk = CONFIG_CPU_CLOCK; | 1083 | sci_port->port.uartclk = CONFIG_CPU_CLOCK; |
1057 | #elif defined(CONFIG_HAVE_CLK) | 1084 | #elif defined(CONFIG_HAVE_CLK) |
1058 | /* | 1085 | sci_port->iclk = p->clk ? clk_get(&dev->dev, p->clk) : NULL; |
1059 | * XXX: We should use a proper SCI/SCIF clock | 1086 | sci_port->dclk = clk_get(&dev->dev, "peripheral_clk"); |
1060 | */ | 1087 | sci_port->enable = sci_clk_enable; |
1061 | { | 1088 | sci_port->disable = sci_clk_disable; |
1062 | struct clk *clk = clk_get(NULL, "module_clk"); | ||
1063 | sci_ports[i].port.uartclk = clk_get_rate(clk); | ||
1064 | clk_put(clk); | ||
1065 | } | ||
1066 | #else | 1089 | #else |
1067 | #error "Need a valid uartclk" | 1090 | #error "Need a valid uartclk" |
1068 | #endif | 1091 | #endif |
1069 | 1092 | ||
1070 | sci_ports[i].break_timer.data = (unsigned long)&sci_ports[i]; | 1093 | sci_port->break_timer.data = (unsigned long)sci_port; |
1071 | sci_ports[i].break_timer.function = sci_break_timer; | 1094 | sci_port->break_timer.function = sci_break_timer; |
1095 | init_timer(&sci_port->break_timer); | ||
1072 | 1096 | ||
1073 | init_timer(&sci_ports[i].break_timer); | 1097 | sci_port->port.mapbase = p->mapbase; |
1074 | } | 1098 | sci_port->port.membase = p->membase; |
1075 | } | ||
1076 | |||
1077 | int __init early_sci_setup(struct uart_port *port) | ||
1078 | { | ||
1079 | if (unlikely(port->line > SCI_NPORTS)) | ||
1080 | return -ENODEV; | ||
1081 | 1099 | ||
1082 | sci_init_ports(); | 1100 | sci_port->port.irq = p->irqs[SCIx_TXI_IRQ]; |
1101 | sci_port->port.flags = p->flags; | ||
1102 | sci_port->port.dev = &dev->dev; | ||
1103 | sci_port->type = sci_port->port.type = p->type; | ||
1083 | 1104 | ||
1084 | sci_ports[port->line].port.membase = port->membase; | 1105 | memcpy(&sci_port->irqs, &p->irqs, sizeof(p->irqs)); |
1085 | sci_ports[port->line].port.mapbase = port->mapbase; | ||
1086 | sci_ports[port->line].port.type = port->type; | ||
1087 | 1106 | ||
1088 | return 0; | ||
1089 | } | 1107 | } |
1090 | 1108 | ||
1091 | #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE | 1109 | #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE |
1110 | static struct tty_driver *serial_console_device(struct console *co, int *index) | ||
1111 | { | ||
1112 | struct uart_driver *p = &sci_uart_driver; | ||
1113 | *index = co->index; | ||
1114 | return p->tty_driver; | ||
1115 | } | ||
1116 | |||
1117 | static void serial_console_putchar(struct uart_port *port, int ch) | ||
1118 | { | ||
1119 | sci_poll_put_char(port, ch); | ||
1120 | } | ||
1121 | |||
1092 | /* | 1122 | /* |
1093 | * Print a string to the serial port trying not to disturb | 1123 | * Print a string to the serial port trying not to disturb |
1094 | * any possible real use of the port... | 1124 | * any possible real use of the port... |
@@ -1096,25 +1126,27 @@ int __init early_sci_setup(struct uart_port *port) | |||
1096 | static void serial_console_write(struct console *co, const char *s, | 1126 | static void serial_console_write(struct console *co, const char *s, |
1097 | unsigned count) | 1127 | unsigned count) |
1098 | { | 1128 | { |
1099 | struct uart_port *port = &serial_console_port->port; | 1129 | struct uart_port *port = co->data; |
1130 | struct sci_port *sci_port = to_sci_port(port); | ||
1100 | unsigned short bits; | 1131 | unsigned short bits; |
1101 | int i; | ||
1102 | 1132 | ||
1103 | for (i = 0; i < count; i++) { | 1133 | if (sci_port->enable) |
1104 | if (*s == 10) | 1134 | sci_port->enable(port); |
1105 | sci_poll_put_char(port, '\r'); | ||
1106 | 1135 | ||
1107 | sci_poll_put_char(port, *s++); | 1136 | uart_console_write(port, s, count, serial_console_putchar); |
1108 | } | ||
1109 | 1137 | ||
1110 | /* wait until fifo is empty and last bit has been transmitted */ | 1138 | /* wait until fifo is empty and last bit has been transmitted */ |
1111 | bits = SCxSR_TDxE(port) | SCxSR_TEND(port); | 1139 | bits = SCxSR_TDxE(port) | SCxSR_TEND(port); |
1112 | while ((sci_in(port, SCxSR) & bits) != bits) | 1140 | while ((sci_in(port, SCxSR) & bits) != bits) |
1113 | cpu_relax(); | 1141 | cpu_relax(); |
1142 | |||
1143 | if (sci_port->disable); | ||
1144 | sci_port->disable(port); | ||
1114 | } | 1145 | } |
1115 | 1146 | ||
1116 | static int __init serial_console_setup(struct console *co, char *options) | 1147 | static int __init serial_console_setup(struct console *co, char *options) |
1117 | { | 1148 | { |
1149 | struct sci_port *sci_port; | ||
1118 | struct uart_port *port; | 1150 | struct uart_port *port; |
1119 | int baud = 115200; | 1151 | int baud = 115200; |
1120 | int bits = 8; | 1152 | int bits = 8; |
@@ -1130,8 +1162,9 @@ static int __init serial_console_setup(struct console *co, char *options) | |||
1130 | if (co->index >= SCI_NPORTS) | 1162 | if (co->index >= SCI_NPORTS) |
1131 | co->index = 0; | 1163 | co->index = 0; |
1132 | 1164 | ||
1133 | serial_console_port = &sci_ports[co->index]; | 1165 | sci_port = &sci_ports[co->index]; |
1134 | port = &serial_console_port->port; | 1166 | port = &sci_port->port; |
1167 | co->data = port; | ||
1135 | 1168 | ||
1136 | /* | 1169 | /* |
1137 | * Also need to check port->type, we don't actually have any | 1170 | * Also need to check port->type, we don't actually have any |
@@ -1141,21 +1174,11 @@ static int __init serial_console_setup(struct console *co, char *options) | |||
1141 | */ | 1174 | */ |
1142 | if (!port->type) | 1175 | if (!port->type) |
1143 | return -ENODEV; | 1176 | return -ENODEV; |
1144 | if (!port->membase || !port->mapbase) | ||
1145 | return -ENODEV; | ||
1146 | |||
1147 | port->type = serial_console_port->type; | ||
1148 | |||
1149 | #ifdef CONFIG_HAVE_CLK | ||
1150 | if (!serial_console_port->clk) | ||
1151 | serial_console_port->clk = clk_get(NULL, "module_clk"); | ||
1152 | #endif | ||
1153 | 1177 | ||
1154 | if (port->flags & UPF_IOREMAP) | 1178 | sci_config_port(port, 0); |
1155 | sci_config_port(port, 0); | ||
1156 | 1179 | ||
1157 | if (serial_console_port->enable) | 1180 | if (sci_port->enable) |
1158 | serial_console_port->enable(port); | 1181 | sci_port->enable(port); |
1159 | 1182 | ||
1160 | if (options) | 1183 | if (options) |
1161 | uart_parse_options(options, &baud, &parity, &bits, &flow); | 1184 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
@@ -1166,22 +1189,21 @@ static int __init serial_console_setup(struct console *co, char *options) | |||
1166 | if (ret == 0) | 1189 | if (ret == 0) |
1167 | sci_stop_rx(port); | 1190 | sci_stop_rx(port); |
1168 | #endif | 1191 | #endif |
1192 | /* TODO: disable clock */ | ||
1169 | return ret; | 1193 | return ret; |
1170 | } | 1194 | } |
1171 | 1195 | ||
1172 | static struct console serial_console = { | 1196 | static struct console serial_console = { |
1173 | .name = "ttySC", | 1197 | .name = "ttySC", |
1174 | .device = uart_console_device, | 1198 | .device = serial_console_device, |
1175 | .write = serial_console_write, | 1199 | .write = serial_console_write, |
1176 | .setup = serial_console_setup, | 1200 | .setup = serial_console_setup, |
1177 | .flags = CON_PRINTBUFFER, | 1201 | .flags = CON_PRINTBUFFER, |
1178 | .index = -1, | 1202 | .index = -1, |
1179 | .data = &sci_uart_driver, | ||
1180 | }; | 1203 | }; |
1181 | 1204 | ||
1182 | static int __init sci_console_init(void) | 1205 | static int __init sci_console_init(void) |
1183 | { | 1206 | { |
1184 | sci_init_ports(); | ||
1185 | register_console(&serial_console); | 1207 | register_console(&serial_console); |
1186 | return 0; | 1208 | return 0; |
1187 | } | 1209 | } |
@@ -1207,6 +1229,61 @@ static struct uart_driver sci_uart_driver = { | |||
1207 | .cons = SCI_CONSOLE, | 1229 | .cons = SCI_CONSOLE, |
1208 | }; | 1230 | }; |
1209 | 1231 | ||
1232 | |||
1233 | static int sci_remove(struct platform_device *dev) | ||
1234 | { | ||
1235 | struct sh_sci_priv *priv = platform_get_drvdata(dev); | ||
1236 | struct sci_port *p; | ||
1237 | unsigned long flags; | ||
1238 | |||
1239 | #ifdef CONFIG_HAVE_CLK | ||
1240 | cpufreq_unregister_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER); | ||
1241 | #endif | ||
1242 | |||
1243 | spin_lock_irqsave(&priv->lock, flags); | ||
1244 | list_for_each_entry(p, &priv->ports, node) | ||
1245 | uart_remove_one_port(&sci_uart_driver, &p->port); | ||
1246 | |||
1247 | spin_unlock_irqrestore(&priv->lock, flags); | ||
1248 | |||
1249 | kfree(priv); | ||
1250 | return 0; | ||
1251 | } | ||
1252 | |||
1253 | static int __devinit sci_probe_single(struct platform_device *dev, | ||
1254 | unsigned int index, | ||
1255 | struct plat_sci_port *p, | ||
1256 | struct sci_port *sciport) | ||
1257 | { | ||
1258 | struct sh_sci_priv *priv = platform_get_drvdata(dev); | ||
1259 | unsigned long flags; | ||
1260 | int ret; | ||
1261 | |||
1262 | /* Sanity check */ | ||
1263 | if (unlikely(index >= SCI_NPORTS)) { | ||
1264 | dev_notice(&dev->dev, "Attempting to register port " | ||
1265 | "%d when only %d are available.\n", | ||
1266 | index+1, SCI_NPORTS); | ||
1267 | dev_notice(&dev->dev, "Consider bumping " | ||
1268 | "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n"); | ||
1269 | return 0; | ||
1270 | } | ||
1271 | |||
1272 | sci_init_single(dev, sciport, index, p); | ||
1273 | |||
1274 | ret = uart_add_one_port(&sci_uart_driver, &sciport->port); | ||
1275 | if (ret) | ||
1276 | return ret; | ||
1277 | |||
1278 | INIT_LIST_HEAD(&sciport->node); | ||
1279 | |||
1280 | spin_lock_irqsave(&priv->lock, flags); | ||
1281 | list_add(&sciport->node, &priv->ports); | ||
1282 | spin_unlock_irqrestore(&priv->lock, flags); | ||
1283 | |||
1284 | return 0; | ||
1285 | } | ||
1286 | |||
1210 | /* | 1287 | /* |
1211 | * Register a set of serial devices attached to a platform device. The | 1288 | * Register a set of serial devices attached to a platform device. The |
1212 | * list is terminated with a zero flags entry, which means we expect | 1289 | * list is terminated with a zero flags entry, which means we expect |
@@ -1216,57 +1293,34 @@ static struct uart_driver sci_uart_driver = { | |||
1216 | static int __devinit sci_probe(struct platform_device *dev) | 1293 | static int __devinit sci_probe(struct platform_device *dev) |
1217 | { | 1294 | { |
1218 | struct plat_sci_port *p = dev->dev.platform_data; | 1295 | struct plat_sci_port *p = dev->dev.platform_data; |
1296 | struct sh_sci_priv *priv; | ||
1219 | int i, ret = -EINVAL; | 1297 | int i, ret = -EINVAL; |
1220 | 1298 | ||
1221 | for (i = 0; p && p->flags != 0; p++, i++) { | 1299 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
1222 | struct sci_port *sciport = &sci_ports[i]; | 1300 | if (!priv) |
1301 | return -ENOMEM; | ||
1223 | 1302 | ||
1224 | /* Sanity check */ | 1303 | INIT_LIST_HEAD(&priv->ports); |
1225 | if (unlikely(i == SCI_NPORTS)) { | 1304 | spin_lock_init(&priv->lock); |
1226 | dev_notice(&dev->dev, "Attempting to register port " | 1305 | platform_set_drvdata(dev, priv); |
1227 | "%d when only %d are available.\n", | ||
1228 | i+1, SCI_NPORTS); | ||
1229 | dev_notice(&dev->dev, "Consider bumping " | ||
1230 | "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n"); | ||
1231 | break; | ||
1232 | } | ||
1233 | 1306 | ||
1234 | sciport->port.mapbase = p->mapbase; | 1307 | #ifdef CONFIG_HAVE_CLK |
1308 | priv->clk_nb.notifier_call = sci_notifier; | ||
1309 | cpufreq_register_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER); | ||
1310 | #endif | ||
1235 | 1311 | ||
1236 | if (p->mapbase && !p->membase) { | 1312 | if (dev->id != -1) { |
1237 | if (p->flags & UPF_IOREMAP) { | 1313 | ret = sci_probe_single(dev, dev->id, p, &sci_ports[dev->id]); |
1238 | p->membase = ioremap_nocache(p->mapbase, 0x40); | 1314 | if (ret) |
1239 | if (IS_ERR(p->membase)) { | 1315 | goto err_unreg; |
1240 | ret = PTR_ERR(p->membase); | 1316 | } else { |
1241 | goto err_unreg; | 1317 | for (i = 0; p && p->flags != 0; p++, i++) { |
1242 | } | 1318 | ret = sci_probe_single(dev, i, p, &sci_ports[i]); |
1243 | } else { | 1319 | if (ret) |
1244 | /* | 1320 | goto err_unreg; |
1245 | * For the simple (and majority of) cases | ||
1246 | * where we don't need to do any remapping, | ||
1247 | * just cast the cookie directly. | ||
1248 | */ | ||
1249 | p->membase = (void __iomem *)p->mapbase; | ||
1250 | } | ||
1251 | } | 1321 | } |
1252 | |||
1253 | sciport->port.membase = p->membase; | ||
1254 | |||
1255 | sciport->port.irq = p->irqs[SCIx_TXI_IRQ]; | ||
1256 | sciport->port.flags = p->flags; | ||
1257 | sciport->port.dev = &dev->dev; | ||
1258 | |||
1259 | sciport->type = sciport->port.type = p->type; | ||
1260 | |||
1261 | memcpy(&sciport->irqs, &p->irqs, sizeof(p->irqs)); | ||
1262 | |||
1263 | uart_add_one_port(&sci_uart_driver, &sciport->port); | ||
1264 | } | 1322 | } |
1265 | 1323 | ||
1266 | #ifdef CONFIG_HAVE_CLK | ||
1267 | cpufreq_register_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER); | ||
1268 | #endif | ||
1269 | |||
1270 | #ifdef CONFIG_SH_STANDARD_BIOS | 1324 | #ifdef CONFIG_SH_STANDARD_BIOS |
1271 | sh_bios_gdb_detach(); | 1325 | sh_bios_gdb_detach(); |
1272 | #endif | 1326 | #endif |
@@ -1274,50 +1328,36 @@ static int __devinit sci_probe(struct platform_device *dev) | |||
1274 | return 0; | 1328 | return 0; |
1275 | 1329 | ||
1276 | err_unreg: | 1330 | err_unreg: |
1277 | for (i = i - 1; i >= 0; i--) | 1331 | sci_remove(dev); |
1278 | uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port); | ||
1279 | |||
1280 | return ret; | 1332 | return ret; |
1281 | } | 1333 | } |
1282 | 1334 | ||
1283 | static int __devexit sci_remove(struct platform_device *dev) | ||
1284 | { | ||
1285 | int i; | ||
1286 | |||
1287 | #ifdef CONFIG_HAVE_CLK | ||
1288 | cpufreq_unregister_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER); | ||
1289 | #endif | ||
1290 | |||
1291 | for (i = 0; i < SCI_NPORTS; i++) | ||
1292 | uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port); | ||
1293 | |||
1294 | return 0; | ||
1295 | } | ||
1296 | |||
1297 | static int sci_suspend(struct platform_device *dev, pm_message_t state) | 1335 | static int sci_suspend(struct platform_device *dev, pm_message_t state) |
1298 | { | 1336 | { |
1299 | int i; | 1337 | struct sh_sci_priv *priv = platform_get_drvdata(dev); |
1338 | struct sci_port *p; | ||
1339 | unsigned long flags; | ||
1300 | 1340 | ||
1301 | for (i = 0; i < SCI_NPORTS; i++) { | 1341 | spin_lock_irqsave(&priv->lock, flags); |
1302 | struct sci_port *p = &sci_ports[i]; | 1342 | list_for_each_entry(p, &priv->ports, node) |
1343 | uart_suspend_port(&sci_uart_driver, &p->port); | ||
1303 | 1344 | ||
1304 | if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev) | 1345 | spin_unlock_irqrestore(&priv->lock, flags); |
1305 | uart_suspend_port(&sci_uart_driver, &p->port); | ||
1306 | } | ||
1307 | 1346 | ||
1308 | return 0; | 1347 | return 0; |
1309 | } | 1348 | } |
1310 | 1349 | ||
1311 | static int sci_resume(struct platform_device *dev) | 1350 | static int sci_resume(struct platform_device *dev) |
1312 | { | 1351 | { |
1313 | int i; | 1352 | struct sh_sci_priv *priv = platform_get_drvdata(dev); |
1353 | struct sci_port *p; | ||
1354 | unsigned long flags; | ||
1314 | 1355 | ||
1315 | for (i = 0; i < SCI_NPORTS; i++) { | 1356 | spin_lock_irqsave(&priv->lock, flags); |
1316 | struct sci_port *p = &sci_ports[i]; | 1357 | list_for_each_entry(p, &priv->ports, node) |
1358 | uart_resume_port(&sci_uart_driver, &p->port); | ||
1317 | 1359 | ||
1318 | if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev) | 1360 | spin_unlock_irqrestore(&priv->lock, flags); |
1319 | uart_resume_port(&sci_uart_driver, &p->port); | ||
1320 | } | ||
1321 | 1361 | ||
1322 | return 0; | 1362 | return 0; |
1323 | } | 1363 | } |
@@ -1339,8 +1379,6 @@ static int __init sci_init(void) | |||
1339 | 1379 | ||
1340 | printk(banner); | 1380 | printk(banner); |
1341 | 1381 | ||
1342 | sci_init_ports(); | ||
1343 | |||
1344 | ret = uart_register_driver(&sci_uart_driver); | 1382 | ret = uart_register_driver(&sci_uart_driver); |
1345 | if (likely(ret == 0)) { | 1383 | if (likely(ret == 0)) { |
1346 | ret = platform_driver_register(&sci_driver); | 1384 | ret = platform_driver_register(&sci_driver); |
diff --git a/drivers/serial/sh-sci.h b/drivers/serial/sh-sci.h index d0aa82d7fce0..38072c15b845 100644 --- a/drivers/serial/sh-sci.h +++ b/drivers/serial/sh-sci.h | |||
@@ -91,6 +91,9 @@ | |||
91 | # define SCSPTR5 0xa4050128 | 91 | # define SCSPTR5 0xa4050128 |
92 | # define SCIF_ORER 0x0001 /* overrun error bit */ | 92 | # define SCIF_ORER 0x0001 /* overrun error bit */ |
93 | # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ | 93 | # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ |
94 | #elif defined(CONFIG_CPU_SUBTYPE_SH7724) | ||
95 | # define SCIF_ORER 0x0001 /* overrun error bit */ | ||
96 | # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ | ||
94 | #elif defined(CONFIG_CPU_SUBTYPE_SH4_202) | 97 | #elif defined(CONFIG_CPU_SUBTYPE_SH4_202) |
95 | # define SCSPTR2 0xffe80020 /* 16 bit SCIF */ | 98 | # define SCSPTR2 0xffe80020 /* 16 bit SCIF */ |
96 | # define SCIF_ORER 0x0001 /* overrun error bit */ | 99 | # define SCIF_ORER 0x0001 /* overrun error bit */ |
@@ -314,7 +317,18 @@ | |||
314 | } \ | 317 | } \ |
315 | } | 318 | } |
316 | 319 | ||
317 | #define CPU_SCIF_FNS(name, scif_offset, scif_size) \ | 320 | #ifdef CONFIG_H8300 |
321 | /* h8300 don't have SCIF */ | ||
322 | #define CPU_SCIF_FNS(name) \ | ||
323 | static inline unsigned int sci_##name##_in(struct uart_port *port) \ | ||
324 | { \ | ||
325 | return 0; \ | ||
326 | } \ | ||
327 | static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \ | ||
328 | { \ | ||
329 | } | ||
330 | #else | ||
331 | #define CPU_SCIF_FNS(name, scif_offset, scif_size) \ | ||
318 | static inline unsigned int sci_##name##_in(struct uart_port *port) \ | 332 | static inline unsigned int sci_##name##_in(struct uart_port *port) \ |
319 | { \ | 333 | { \ |
320 | SCI_IN(scif_size, scif_offset); \ | 334 | SCI_IN(scif_size, scif_offset); \ |
@@ -323,6 +337,7 @@ | |||
323 | { \ | 337 | { \ |
324 | SCI_OUT(scif_size, scif_offset, value); \ | 338 | SCI_OUT(scif_size, scif_offset, value); \ |
325 | } | 339 | } |
340 | #endif | ||
326 | 341 | ||
327 | #define CPU_SCI_FNS(name, sci_offset, sci_size) \ | 342 | #define CPU_SCI_FNS(name, sci_offset, sci_size) \ |
328 | static inline unsigned int sci_##name##_in(struct uart_port* port) \ | 343 | static inline unsigned int sci_##name##_in(struct uart_port* port) \ |
@@ -360,8 +375,10 @@ | |||
360 | sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \ | 375 | sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \ |
361 | h8_sci_offset, h8_sci_size) \ | 376 | h8_sci_offset, h8_sci_size) \ |
362 | CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size) | 377 | CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size) |
363 | #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) | 378 | #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \ |
364 | #elif defined(CONFIG_CPU_SUBTYPE_SH7723) | 379 | CPU_SCIF_FNS(name) |
380 | #elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\ | ||
381 | defined(CONFIG_CPU_SUBTYPE_SH7724) | ||
365 | #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) \ | 382 | #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) \ |
366 | CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) | 383 | CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) |
367 | #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \ | 384 | #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \ |
@@ -390,7 +407,8 @@ SCIF_FNS(SCFDR, 0x1c, 16) | |||
390 | SCIF_FNS(SCxTDR, 0x20, 8) | 407 | SCIF_FNS(SCxTDR, 0x20, 8) |
391 | SCIF_FNS(SCxRDR, 0x24, 8) | 408 | SCIF_FNS(SCxRDR, 0x24, 8) |
392 | SCIF_FNS(SCLSR, 0x24, 16) | 409 | SCIF_FNS(SCLSR, 0x24, 16) |
393 | #elif defined(CONFIG_CPU_SUBTYPE_SH7723) | 410 | #elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\ |
411 | defined(CONFIG_CPU_SUBTYPE_SH7724) | ||
394 | SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16) | 412 | SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16) |
395 | SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8) | 413 | SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8) |
396 | SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16) | 414 | SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16) |
@@ -604,10 +622,21 @@ static inline int sci_rxd_in(struct uart_port *port) | |||
604 | return ctrl_inb(SCSPTR5) & 0x0008 ? 1 : 0; /* SCIF5 */ | 622 | return ctrl_inb(SCSPTR5) & 0x0008 ? 1 : 0; /* SCIF5 */ |
605 | return 1; | 623 | return 1; |
606 | } | 624 | } |
625 | #elif defined(CONFIG_CPU_SUBTYPE_SH7724) | ||
626 | # define SCFSR 0x0010 | ||
627 | # define SCASSR 0x0014 | ||
628 | static inline int sci_rxd_in(struct uart_port *port) | ||
629 | { | ||
630 | if (port->type == PORT_SCIF) | ||
631 | return ctrl_inw((port->mapbase + SCFSR)) & SCIF_BRK ? 1 : 0; | ||
632 | if (port->type == PORT_SCIFA) | ||
633 | return ctrl_inw((port->mapbase + SCASSR)) & SCIF_BRK ? 1 : 0; | ||
634 | return 1; | ||
635 | } | ||
607 | #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103) | 636 | #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103) |
608 | static inline int sci_rxd_in(struct uart_port *port) | 637 | static inline int sci_rxd_in(struct uart_port *port) |
609 | { | 638 | { |
610 | return sci_in(port, SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */ | 639 | return sci_in(port, SCSPTR)&0x0001 ? 1 : 0; /* SCIF */ |
611 | } | 640 | } |
612 | #elif defined(__H8300H__) || defined(__H8300S__) | 641 | #elif defined(__H8300H__) || defined(__H8300S__) |
613 | static inline int sci_rxd_in(struct uart_port *port) | 642 | static inline int sci_rxd_in(struct uart_port *port) |
@@ -757,7 +786,8 @@ static inline int sci_rxd_in(struct uart_port *port) | |||
757 | defined(CONFIG_CPU_SUBTYPE_SH7720) || \ | 786 | defined(CONFIG_CPU_SUBTYPE_SH7720) || \ |
758 | defined(CONFIG_CPU_SUBTYPE_SH7721) | 787 | defined(CONFIG_CPU_SUBTYPE_SH7721) |
759 | #define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1) | 788 | #define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1) |
760 | #elif defined(CONFIG_CPU_SUBTYPE_SH7723) | 789 | #elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\ |
790 | defined(CONFIG_CPU_SUBTYPE_SH7724) | ||
761 | static inline int scbrr_calc(struct uart_port *port, int bps, int clk) | 791 | static inline int scbrr_calc(struct uart_port *port, int bps, int clk) |
762 | { | 792 | { |
763 | if (port->type == PORT_SCIF) | 793 | if (port->type == PORT_SCIF) |
diff --git a/drivers/serial/timbuart.c b/drivers/serial/timbuart.c new file mode 100644 index 000000000000..ac9e5d5f742e --- /dev/null +++ b/drivers/serial/timbuart.c | |||
@@ -0,0 +1,526 @@ | |||
1 | /* | ||
2 | * timbuart.c timberdale FPGA UART driver | ||
3 | * Copyright (c) 2009 Intel Corporation | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | /* Supports: | ||
20 | * Timberdale FPGA UART | ||
21 | */ | ||
22 | |||
23 | #include <linux/pci.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/serial_core.h> | ||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/ioport.h> | ||
29 | |||
30 | #include "timbuart.h" | ||
31 | |||
32 | struct timbuart_port { | ||
33 | struct uart_port port; | ||
34 | struct tasklet_struct tasklet; | ||
35 | int usedma; | ||
36 | u8 last_ier; | ||
37 | struct platform_device *dev; | ||
38 | }; | ||
39 | |||
40 | static int baudrates[] = {9600, 19200, 38400, 57600, 115200, 230400, 460800, | ||
41 | 921600, 1843200, 3250000}; | ||
42 | |||
43 | static void timbuart_mctrl_check(struct uart_port *port, u8 isr, u8 *ier); | ||
44 | |||
45 | static irqreturn_t timbuart_handleinterrupt(int irq, void *devid); | ||
46 | |||
47 | static void timbuart_stop_rx(struct uart_port *port) | ||
48 | { | ||
49 | /* spin lock held by upper layer, disable all RX interrupts */ | ||
50 | u8 ier = ioread8(port->membase + TIMBUART_IER) & ~RXFLAGS; | ||
51 | iowrite8(ier, port->membase + TIMBUART_IER); | ||
52 | } | ||
53 | |||
54 | static void timbuart_stop_tx(struct uart_port *port) | ||
55 | { | ||
56 | /* spinlock held by upper layer, disable TX interrupt */ | ||
57 | u8 ier = ioread8(port->membase + TIMBUART_IER) & ~TXBAE; | ||
58 | iowrite8(ier, port->membase + TIMBUART_IER); | ||
59 | } | ||
60 | |||
61 | static void timbuart_start_tx(struct uart_port *port) | ||
62 | { | ||
63 | struct timbuart_port *uart = | ||
64 | container_of(port, struct timbuart_port, port); | ||
65 | |||
66 | /* do not transfer anything here -> fire off the tasklet */ | ||
67 | tasklet_schedule(&uart->tasklet); | ||
68 | } | ||
69 | |||
70 | static void timbuart_flush_buffer(struct uart_port *port) | ||
71 | { | ||
72 | u8 ctl = ioread8(port->membase + TIMBUART_CTRL) | TIMBUART_CTRL_FLSHTX; | ||
73 | |||
74 | iowrite8(ctl, port->membase + TIMBUART_CTRL); | ||
75 | iowrite8(TXBF, port->membase + TIMBUART_ISR); | ||
76 | } | ||
77 | |||
78 | static void timbuart_rx_chars(struct uart_port *port) | ||
79 | { | ||
80 | struct tty_struct *tty = port->info->port.tty; | ||
81 | |||
82 | while (ioread8(port->membase + TIMBUART_ISR) & RXDP) { | ||
83 | u8 ch = ioread8(port->membase + TIMBUART_RXFIFO); | ||
84 | port->icount.rx++; | ||
85 | tty_insert_flip_char(tty, ch, TTY_NORMAL); | ||
86 | } | ||
87 | |||
88 | spin_unlock(&port->lock); | ||
89 | tty_flip_buffer_push(port->info->port.tty); | ||
90 | spin_lock(&port->lock); | ||
91 | |||
92 | dev_dbg(port->dev, "%s - total read %d bytes\n", | ||
93 | __func__, port->icount.rx); | ||
94 | } | ||
95 | |||
96 | static void timbuart_tx_chars(struct uart_port *port) | ||
97 | { | ||
98 | struct circ_buf *xmit = &port->info->xmit; | ||
99 | |||
100 | while (!(ioread8(port->membase + TIMBUART_ISR) & TXBF) && | ||
101 | !uart_circ_empty(xmit)) { | ||
102 | iowrite8(xmit->buf[xmit->tail], | ||
103 | port->membase + TIMBUART_TXFIFO); | ||
104 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); | ||
105 | port->icount.tx++; | ||
106 | } | ||
107 | |||
108 | dev_dbg(port->dev, | ||
109 | "%s - total written %d bytes, CTL: %x, RTS: %x, baud: %x\n", | ||
110 | __func__, | ||
111 | port->icount.tx, | ||
112 | ioread8(port->membase + TIMBUART_CTRL), | ||
113 | port->mctrl & TIOCM_RTS, | ||
114 | ioread8(port->membase + TIMBUART_BAUDRATE)); | ||
115 | } | ||
116 | |||
117 | static void timbuart_handle_tx_port(struct uart_port *port, u8 isr, u8 *ier) | ||
118 | { | ||
119 | struct timbuart_port *uart = | ||
120 | container_of(port, struct timbuart_port, port); | ||
121 | struct circ_buf *xmit = &port->info->xmit; | ||
122 | |||
123 | if (uart_circ_empty(xmit) || uart_tx_stopped(port)) | ||
124 | return; | ||
125 | |||
126 | if (port->x_char) | ||
127 | return; | ||
128 | |||
129 | if (isr & TXFLAGS) { | ||
130 | timbuart_tx_chars(port); | ||
131 | /* clear all TX interrupts */ | ||
132 | iowrite8(TXFLAGS, port->membase + TIMBUART_ISR); | ||
133 | |||
134 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) | ||
135 | uart_write_wakeup(port); | ||
136 | } else | ||
137 | /* Re-enable any tx interrupt */ | ||
138 | *ier |= uart->last_ier & TXFLAGS; | ||
139 | |||
140 | /* enable interrupts if there are chars in the transmit buffer, | ||
141 | * Or if we delivered some bytes and want the almost empty interrupt | ||
142 | * we wake up the upper layer later when we got the interrupt | ||
143 | * to give it some time to go out... | ||
144 | */ | ||
145 | if (!uart_circ_empty(xmit)) | ||
146 | *ier |= TXBAE; | ||
147 | |||
148 | dev_dbg(port->dev, "%s - leaving\n", __func__); | ||
149 | } | ||
150 | |||
151 | void timbuart_handle_rx_port(struct uart_port *port, u8 isr, u8 *ier) | ||
152 | { | ||
153 | if (isr & RXFLAGS) { | ||
154 | /* Some RX status is set */ | ||
155 | if (isr & RXBF) { | ||
156 | u8 ctl = ioread8(port->membase + TIMBUART_CTRL) | | ||
157 | TIMBUART_CTRL_FLSHRX; | ||
158 | iowrite8(ctl, port->membase + TIMBUART_CTRL); | ||
159 | port->icount.overrun++; | ||
160 | } else if (isr & (RXDP)) | ||
161 | timbuart_rx_chars(port); | ||
162 | |||
163 | /* ack all RX interrupts */ | ||
164 | iowrite8(RXFLAGS, port->membase + TIMBUART_ISR); | ||
165 | } | ||
166 | |||
167 | /* always have the RX interrupts enabled */ | ||
168 | *ier |= RXBAF | RXBF | RXTT; | ||
169 | |||
170 | dev_dbg(port->dev, "%s - leaving\n", __func__); | ||
171 | } | ||
172 | |||
173 | void timbuart_tasklet(unsigned long arg) | ||
174 | { | ||
175 | struct timbuart_port *uart = (struct timbuart_port *)arg; | ||
176 | u8 isr, ier = 0; | ||
177 | |||
178 | spin_lock(&uart->port.lock); | ||
179 | |||
180 | isr = ioread8(uart->port.membase + TIMBUART_ISR); | ||
181 | dev_dbg(uart->port.dev, "%s ISR: %x\n", __func__, isr); | ||
182 | |||
183 | if (!uart->usedma) | ||
184 | timbuart_handle_tx_port(&uart->port, isr, &ier); | ||
185 | |||
186 | timbuart_mctrl_check(&uart->port, isr, &ier); | ||
187 | |||
188 | if (!uart->usedma) | ||
189 | timbuart_handle_rx_port(&uart->port, isr, &ier); | ||
190 | |||
191 | iowrite8(ier, uart->port.membase + TIMBUART_IER); | ||
192 | |||
193 | spin_unlock(&uart->port.lock); | ||
194 | dev_dbg(uart->port.dev, "%s leaving\n", __func__); | ||
195 | } | ||
196 | |||
197 | static unsigned int timbuart_tx_empty(struct uart_port *port) | ||
198 | { | ||
199 | u8 isr = ioread8(port->membase + TIMBUART_ISR); | ||
200 | |||
201 | return (isr & TXBAE) ? TIOCSER_TEMT : 0; | ||
202 | } | ||
203 | |||
204 | static unsigned int timbuart_get_mctrl(struct uart_port *port) | ||
205 | { | ||
206 | u8 cts = ioread8(port->membase + TIMBUART_CTRL); | ||
207 | dev_dbg(port->dev, "%s - cts %x\n", __func__, cts); | ||
208 | |||
209 | if (cts & TIMBUART_CTRL_CTS) | ||
210 | return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; | ||
211 | else | ||
212 | return TIOCM_DSR | TIOCM_CAR; | ||
213 | } | ||
214 | |||
215 | static void timbuart_set_mctrl(struct uart_port *port, unsigned int mctrl) | ||
216 | { | ||
217 | dev_dbg(port->dev, "%s - %x\n", __func__, mctrl); | ||
218 | |||
219 | if (mctrl & TIOCM_RTS) | ||
220 | iowrite8(TIMBUART_CTRL_RTS, port->membase + TIMBUART_CTRL); | ||
221 | else | ||
222 | iowrite8(TIMBUART_CTRL_RTS, port->membase + TIMBUART_CTRL); | ||
223 | } | ||
224 | |||
225 | static void timbuart_mctrl_check(struct uart_port *port, u8 isr, u8 *ier) | ||
226 | { | ||
227 | unsigned int cts; | ||
228 | |||
229 | if (isr & CTS_DELTA) { | ||
230 | /* ack */ | ||
231 | iowrite8(CTS_DELTA, port->membase + TIMBUART_ISR); | ||
232 | cts = timbuart_get_mctrl(port); | ||
233 | uart_handle_cts_change(port, cts & TIOCM_CTS); | ||
234 | wake_up_interruptible(&port->info->delta_msr_wait); | ||
235 | } | ||
236 | |||
237 | *ier |= CTS_DELTA; | ||
238 | } | ||
239 | |||
240 | static void timbuart_enable_ms(struct uart_port *port) | ||
241 | { | ||
242 | /* N/A */ | ||
243 | } | ||
244 | |||
245 | static void timbuart_break_ctl(struct uart_port *port, int ctl) | ||
246 | { | ||
247 | /* N/A */ | ||
248 | } | ||
249 | |||
250 | static int timbuart_startup(struct uart_port *port) | ||
251 | { | ||
252 | struct timbuart_port *uart = | ||
253 | container_of(port, struct timbuart_port, port); | ||
254 | |||
255 | dev_dbg(port->dev, "%s\n", __func__); | ||
256 | |||
257 | iowrite8(TIMBUART_CTRL_FLSHRX, port->membase + TIMBUART_CTRL); | ||
258 | iowrite8(0xff, port->membase + TIMBUART_ISR); | ||
259 | /* Enable all but TX interrupts */ | ||
260 | iowrite8(RXBAF | RXBF | RXTT | CTS_DELTA, | ||
261 | port->membase + TIMBUART_IER); | ||
262 | |||
263 | return request_irq(port->irq, timbuart_handleinterrupt, IRQF_SHARED, | ||
264 | "timb-uart", uart); | ||
265 | } | ||
266 | |||
267 | static void timbuart_shutdown(struct uart_port *port) | ||
268 | { | ||
269 | struct timbuart_port *uart = | ||
270 | container_of(port, struct timbuart_port, port); | ||
271 | dev_dbg(port->dev, "%s\n", __func__); | ||
272 | free_irq(port->irq, uart); | ||
273 | iowrite8(0, port->membase + TIMBUART_IER); | ||
274 | } | ||
275 | |||
276 | static int get_bindex(int baud) | ||
277 | { | ||
278 | int i; | ||
279 | |||
280 | for (i = 0; i < ARRAY_SIZE(baudrates); i++) | ||
281 | if (baud <= baudrates[i]) | ||
282 | return i; | ||
283 | |||
284 | return -1; | ||
285 | } | ||
286 | |||
287 | static void timbuart_set_termios(struct uart_port *port, | ||
288 | struct ktermios *termios, | ||
289 | struct ktermios *old) | ||
290 | { | ||
291 | unsigned int baud; | ||
292 | short bindex; | ||
293 | unsigned long flags; | ||
294 | |||
295 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); | ||
296 | bindex = get_bindex(baud); | ||
297 | dev_dbg(port->dev, "%s - bindex %d\n", __func__, bindex); | ||
298 | |||
299 | if (bindex < 0) | ||
300 | bindex = 0; | ||
301 | baud = baudrates[bindex]; | ||
302 | |||
303 | /* The serial layer calls into this once with old = NULL when setting | ||
304 | up initially */ | ||
305 | if (old) | ||
306 | tty_termios_copy_hw(termios, old); | ||
307 | tty_termios_encode_baud_rate(termios, baud, baud); | ||
308 | |||
309 | spin_lock_irqsave(&port->lock, flags); | ||
310 | iowrite8((u8)bindex, port->membase + TIMBUART_BAUDRATE); | ||
311 | uart_update_timeout(port, termios->c_cflag, baud); | ||
312 | spin_unlock_irqrestore(&port->lock, flags); | ||
313 | } | ||
314 | |||
315 | static const char *timbuart_type(struct uart_port *port) | ||
316 | { | ||
317 | return port->type == PORT_UNKNOWN ? "timbuart" : NULL; | ||
318 | } | ||
319 | |||
320 | /* We do not request/release mappings of the registers here, | ||
321 | * currently it's done in the proble function. | ||
322 | */ | ||
323 | static void timbuart_release_port(struct uart_port *port) | ||
324 | { | ||
325 | struct platform_device *pdev = to_platform_device(port->dev); | ||
326 | int size = | ||
327 | resource_size(platform_get_resource(pdev, IORESOURCE_MEM, 0)); | ||
328 | |||
329 | if (port->flags & UPF_IOREMAP) { | ||
330 | iounmap(port->membase); | ||
331 | port->membase = NULL; | ||
332 | } | ||
333 | |||
334 | release_mem_region(port->mapbase, size); | ||
335 | } | ||
336 | |||
337 | static int timbuart_request_port(struct uart_port *port) | ||
338 | { | ||
339 | struct platform_device *pdev = to_platform_device(port->dev); | ||
340 | int size = | ||
341 | resource_size(platform_get_resource(pdev, IORESOURCE_MEM, 0)); | ||
342 | |||
343 | if (!request_mem_region(port->mapbase, size, "timb-uart")) | ||
344 | return -EBUSY; | ||
345 | |||
346 | if (port->flags & UPF_IOREMAP) { | ||
347 | port->membase = ioremap(port->mapbase, size); | ||
348 | if (port->membase == NULL) { | ||
349 | release_mem_region(port->mapbase, size); | ||
350 | return -ENOMEM; | ||
351 | } | ||
352 | } | ||
353 | |||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | static irqreturn_t timbuart_handleinterrupt(int irq, void *devid) | ||
358 | { | ||
359 | struct timbuart_port *uart = (struct timbuart_port *)devid; | ||
360 | |||
361 | if (ioread8(uart->port.membase + TIMBUART_IPR)) { | ||
362 | uart->last_ier = ioread8(uart->port.membase + TIMBUART_IER); | ||
363 | |||
364 | /* disable interrupts, the tasklet enables them again */ | ||
365 | iowrite8(0, uart->port.membase + TIMBUART_IER); | ||
366 | |||
367 | /* fire off bottom half */ | ||
368 | tasklet_schedule(&uart->tasklet); | ||
369 | |||
370 | return IRQ_HANDLED; | ||
371 | } else | ||
372 | return IRQ_NONE; | ||
373 | } | ||
374 | |||
375 | /* | ||
376 | * Configure/autoconfigure the port. | ||
377 | */ | ||
378 | static void timbuart_config_port(struct uart_port *port, int flags) | ||
379 | { | ||
380 | if (flags & UART_CONFIG_TYPE) { | ||
381 | port->type = PORT_TIMBUART; | ||
382 | timbuart_request_port(port); | ||
383 | } | ||
384 | } | ||
385 | |||
386 | static int timbuart_verify_port(struct uart_port *port, | ||
387 | struct serial_struct *ser) | ||
388 | { | ||
389 | /* we don't want the core code to modify any port params */ | ||
390 | return -EINVAL; | ||
391 | } | ||
392 | |||
393 | static struct uart_ops timbuart_ops = { | ||
394 | .tx_empty = timbuart_tx_empty, | ||
395 | .set_mctrl = timbuart_set_mctrl, | ||
396 | .get_mctrl = timbuart_get_mctrl, | ||
397 | .stop_tx = timbuart_stop_tx, | ||
398 | .start_tx = timbuart_start_tx, | ||
399 | .flush_buffer = timbuart_flush_buffer, | ||
400 | .stop_rx = timbuart_stop_rx, | ||
401 | .enable_ms = timbuart_enable_ms, | ||
402 | .break_ctl = timbuart_break_ctl, | ||
403 | .startup = timbuart_startup, | ||
404 | .shutdown = timbuart_shutdown, | ||
405 | .set_termios = timbuart_set_termios, | ||
406 | .type = timbuart_type, | ||
407 | .release_port = timbuart_release_port, | ||
408 | .request_port = timbuart_request_port, | ||
409 | .config_port = timbuart_config_port, | ||
410 | .verify_port = timbuart_verify_port | ||
411 | }; | ||
412 | |||
413 | static struct uart_driver timbuart_driver = { | ||
414 | .owner = THIS_MODULE, | ||
415 | .driver_name = "timberdale_uart", | ||
416 | .dev_name = "ttyTU", | ||
417 | .major = TIMBUART_MAJOR, | ||
418 | .minor = TIMBUART_MINOR, | ||
419 | .nr = 1 | ||
420 | }; | ||
421 | |||
422 | static int timbuart_probe(struct platform_device *dev) | ||
423 | { | ||
424 | int err; | ||
425 | struct timbuart_port *uart; | ||
426 | struct resource *iomem; | ||
427 | |||
428 | dev_dbg(&dev->dev, "%s\n", __func__); | ||
429 | |||
430 | uart = kzalloc(sizeof(*uart), GFP_KERNEL); | ||
431 | if (!uart) { | ||
432 | err = -EINVAL; | ||
433 | goto err_mem; | ||
434 | } | ||
435 | |||
436 | uart->usedma = 0; | ||
437 | |||
438 | uart->port.uartclk = 3250000 * 16; | ||
439 | uart->port.fifosize = TIMBUART_FIFO_SIZE; | ||
440 | uart->port.regshift = 2; | ||
441 | uart->port.iotype = UPIO_MEM; | ||
442 | uart->port.ops = &timbuart_ops; | ||
443 | uart->port.irq = 0; | ||
444 | uart->port.flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP; | ||
445 | uart->port.line = 0; | ||
446 | uart->port.dev = &dev->dev; | ||
447 | |||
448 | iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
449 | if (!iomem) { | ||
450 | err = -ENOMEM; | ||
451 | goto err_register; | ||
452 | } | ||
453 | uart->port.mapbase = iomem->start; | ||
454 | uart->port.membase = NULL; | ||
455 | |||
456 | uart->port.irq = platform_get_irq(dev, 0); | ||
457 | if (uart->port.irq < 0) { | ||
458 | err = -EINVAL; | ||
459 | goto err_register; | ||
460 | } | ||
461 | |||
462 | tasklet_init(&uart->tasklet, timbuart_tasklet, (unsigned long)uart); | ||
463 | |||
464 | err = uart_register_driver(&timbuart_driver); | ||
465 | if (err) | ||
466 | goto err_register; | ||
467 | |||
468 | err = uart_add_one_port(&timbuart_driver, &uart->port); | ||
469 | if (err) | ||
470 | goto err_add_port; | ||
471 | |||
472 | platform_set_drvdata(dev, uart); | ||
473 | |||
474 | return 0; | ||
475 | |||
476 | err_add_port: | ||
477 | uart_unregister_driver(&timbuart_driver); | ||
478 | err_register: | ||
479 | kfree(uart); | ||
480 | err_mem: | ||
481 | printk(KERN_ERR "timberdale: Failed to register Timberdale UART: %d\n", | ||
482 | err); | ||
483 | |||
484 | return err; | ||
485 | } | ||
486 | |||
487 | static int timbuart_remove(struct platform_device *dev) | ||
488 | { | ||
489 | struct timbuart_port *uart = platform_get_drvdata(dev); | ||
490 | |||
491 | tasklet_kill(&uart->tasklet); | ||
492 | uart_remove_one_port(&timbuart_driver, &uart->port); | ||
493 | uart_unregister_driver(&timbuart_driver); | ||
494 | kfree(uart); | ||
495 | |||
496 | return 0; | ||
497 | } | ||
498 | |||
499 | static struct platform_driver timbuart_platform_driver = { | ||
500 | .driver = { | ||
501 | .name = "timb-uart", | ||
502 | .owner = THIS_MODULE, | ||
503 | }, | ||
504 | .probe = timbuart_probe, | ||
505 | .remove = timbuart_remove, | ||
506 | }; | ||
507 | |||
508 | /*--------------------------------------------------------------------------*/ | ||
509 | |||
510 | static int __init timbuart_init(void) | ||
511 | { | ||
512 | return platform_driver_register(&timbuart_platform_driver); | ||
513 | } | ||
514 | |||
515 | static void __exit timbuart_exit(void) | ||
516 | { | ||
517 | platform_driver_unregister(&timbuart_platform_driver); | ||
518 | } | ||
519 | |||
520 | module_init(timbuart_init); | ||
521 | module_exit(timbuart_exit); | ||
522 | |||
523 | MODULE_DESCRIPTION("Timberdale UART driver"); | ||
524 | MODULE_LICENSE("GPL v2"); | ||
525 | MODULE_ALIAS("platform:timb-uart"); | ||
526 | |||
diff --git a/drivers/serial/timbuart.h b/drivers/serial/timbuart.h new file mode 100644 index 000000000000..7e566766bc43 --- /dev/null +++ b/drivers/serial/timbuart.h | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * timbuart.c timberdale FPGA GPIO driver | ||
3 | * Copyright (c) 2009 Intel Corporation | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | /* Supports: | ||
20 | * Timberdale FPGA UART | ||
21 | */ | ||
22 | |||
23 | #ifndef _TIMBUART_H | ||
24 | #define _TIMBUART_H | ||
25 | |||
26 | #define TIMBUART_FIFO_SIZE 2048 | ||
27 | |||
28 | #define TIMBUART_RXFIFO 0x08 | ||
29 | #define TIMBUART_TXFIFO 0x0c | ||
30 | #define TIMBUART_IER 0x10 | ||
31 | #define TIMBUART_IPR 0x14 | ||
32 | #define TIMBUART_ISR 0x18 | ||
33 | #define TIMBUART_CTRL 0x1c | ||
34 | #define TIMBUART_BAUDRATE 0x20 | ||
35 | |||
36 | #define TIMBUART_CTRL_RTS 0x01 | ||
37 | #define TIMBUART_CTRL_CTS 0x02 | ||
38 | #define TIMBUART_CTRL_FLSHTX 0x40 | ||
39 | #define TIMBUART_CTRL_FLSHRX 0x80 | ||
40 | |||
41 | #define TXBF 0x01 | ||
42 | #define TXBAE 0x02 | ||
43 | #define CTS_DELTA 0x04 | ||
44 | #define RXDP 0x08 | ||
45 | #define RXBAF 0x10 | ||
46 | #define RXBF 0x20 | ||
47 | #define RXTT 0x40 | ||
48 | #define RXBNAE 0x80 | ||
49 | #define TXBE 0x100 | ||
50 | |||
51 | #define RXFLAGS (RXDP | RXBAF | RXBF | RXTT | RXBNAE) | ||
52 | #define TXFLAGS (TXBF | TXBAE) | ||
53 | |||
54 | #define TIMBUART_MAJOR 204 | ||
55 | #define TIMBUART_MINOR 192 | ||
56 | |||
57 | #endif /* _TIMBUART_H */ | ||
58 | |||
diff --git a/drivers/sh/intc.c b/drivers/sh/intc.c index 12d13d99b6f0..d687a9b93d03 100644 --- a/drivers/sh/intc.c +++ b/drivers/sh/intc.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/sh_intc.h> | 24 | #include <linux/sh_intc.h> |
25 | #include <linux/sysdev.h> | 25 | #include <linux/sysdev.h> |
26 | #include <linux/list.h> | 26 | #include <linux/list.h> |
27 | #include <linux/topology.h> | ||
27 | 28 | ||
28 | #define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \ | 29 | #define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \ |
29 | ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \ | 30 | ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \ |
@@ -770,11 +771,19 @@ void __init register_intc_controller(struct intc_desc *desc) | |||
770 | /* register the vectors one by one */ | 771 | /* register the vectors one by one */ |
771 | for (i = 0; i < desc->nr_vectors; i++) { | 772 | for (i = 0; i < desc->nr_vectors; i++) { |
772 | struct intc_vect *vect = desc->vectors + i; | 773 | struct intc_vect *vect = desc->vectors + i; |
774 | unsigned int irq = evt2irq(vect->vect); | ||
775 | struct irq_desc *irq_desc; | ||
773 | 776 | ||
774 | if (!vect->enum_id) | 777 | if (!vect->enum_id) |
775 | continue; | 778 | continue; |
776 | 779 | ||
777 | intc_register_irq(desc, d, vect->enum_id, evt2irq(vect->vect)); | 780 | irq_desc = irq_to_desc_alloc_node(irq, numa_node_id()); |
781 | if (unlikely(!irq_desc)) { | ||
782 | printk(KERN_INFO "can not get irq_desc for %d\n", irq); | ||
783 | continue; | ||
784 | } | ||
785 | |||
786 | intc_register_irq(desc, d, vect->enum_id, irq); | ||
778 | } | 787 | } |
779 | } | 788 | } |
780 | 789 | ||
diff --git a/drivers/ssb/embedded.c b/drivers/ssb/embedded.c index 7dc3a6b41397..a0e0d246b592 100644 --- a/drivers/ssb/embedded.c +++ b/drivers/ssb/embedded.c | |||
@@ -29,6 +29,7 @@ int ssb_watchdog_timer_set(struct ssb_bus *bus, u32 ticks) | |||
29 | } | 29 | } |
30 | return -ENODEV; | 30 | return -ENODEV; |
31 | } | 31 | } |
32 | EXPORT_SYMBOL(ssb_watchdog_timer_set); | ||
32 | 33 | ||
33 | u32 ssb_gpio_in(struct ssb_bus *bus, u32 mask) | 34 | u32 ssb_gpio_in(struct ssb_bus *bus, u32 mask) |
34 | { | 35 | { |
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index 0716cdb44cd8..0a3dc5ece634 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile | |||
@@ -11,7 +11,6 @@ obj-$(CONFIG_USB_MON) += mon/ | |||
11 | obj-$(CONFIG_PCI) += host/ | 11 | obj-$(CONFIG_PCI) += host/ |
12 | obj-$(CONFIG_USB_EHCI_HCD) += host/ | 12 | obj-$(CONFIG_USB_EHCI_HCD) += host/ |
13 | obj-$(CONFIG_USB_ISP116X_HCD) += host/ | 13 | obj-$(CONFIG_USB_ISP116X_HCD) += host/ |
14 | obj-$(CONFIG_USB_ISP1760_HCD) += host/ | ||
15 | obj-$(CONFIG_USB_OHCI_HCD) += host/ | 14 | obj-$(CONFIG_USB_OHCI_HCD) += host/ |
16 | obj-$(CONFIG_USB_UHCI_HCD) += host/ | 15 | obj-$(CONFIG_USB_UHCI_HCD) += host/ |
17 | obj-$(CONFIG_USB_FHCI_HCD) += host/ | 16 | obj-$(CONFIG_USB_FHCI_HCD) += host/ |
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 0a69c0977e3f..ddeb69192537 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c | |||
@@ -16,7 +16,8 @@ | |||
16 | * v0.9 - thorough cleaning, URBification, almost a rewrite | 16 | * v0.9 - thorough cleaning, URBification, almost a rewrite |
17 | * v0.10 - some more cleanups | 17 | * v0.10 - some more cleanups |
18 | * v0.11 - fixed flow control, read error doesn't stop reads | 18 | * v0.11 - fixed flow control, read error doesn't stop reads |
19 | * v0.12 - added TIOCM ioctls, added break handling, made struct acm kmalloced | 19 | * v0.12 - added TIOCM ioctls, added break handling, made struct acm |
20 | * kmalloced | ||
20 | * v0.13 - added termios, added hangup | 21 | * v0.13 - added termios, added hangup |
21 | * v0.14 - sized down struct acm | 22 | * v0.14 - sized down struct acm |
22 | * v0.15 - fixed flow control again - characters could be lost | 23 | * v0.15 - fixed flow control again - characters could be lost |
@@ -62,7 +63,7 @@ | |||
62 | #include <linux/tty_flip.h> | 63 | #include <linux/tty_flip.h> |
63 | #include <linux/module.h> | 64 | #include <linux/module.h> |
64 | #include <linux/mutex.h> | 65 | #include <linux/mutex.h> |
65 | #include <asm/uaccess.h> | 66 | #include <linux/uaccess.h> |
66 | #include <linux/usb.h> | 67 | #include <linux/usb.h> |
67 | #include <linux/usb/cdc.h> | 68 | #include <linux/usb/cdc.h> |
68 | #include <asm/byteorder.h> | 69 | #include <asm/byteorder.h> |
@@ -87,7 +88,10 @@ static struct acm *acm_table[ACM_TTY_MINORS]; | |||
87 | 88 | ||
88 | static DEFINE_MUTEX(open_mutex); | 89 | static DEFINE_MUTEX(open_mutex); |
89 | 90 | ||
90 | #define ACM_READY(acm) (acm && acm->dev && acm->used) | 91 | #define ACM_READY(acm) (acm && acm->dev && acm->port.count) |
92 | |||
93 | static const struct tty_port_operations acm_port_ops = { | ||
94 | }; | ||
91 | 95 | ||
92 | #ifdef VERBOSE_DEBUG | 96 | #ifdef VERBOSE_DEBUG |
93 | #define verbose 1 | 97 | #define verbose 1 |
@@ -99,13 +103,15 @@ static DEFINE_MUTEX(open_mutex); | |||
99 | * Functions for ACM control messages. | 103 | * Functions for ACM control messages. |
100 | */ | 104 | */ |
101 | 105 | ||
102 | static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int len) | 106 | static int acm_ctrl_msg(struct acm *acm, int request, int value, |
107 | void *buf, int len) | ||
103 | { | 108 | { |
104 | int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), | 109 | int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), |
105 | request, USB_RT_ACM, value, | 110 | request, USB_RT_ACM, value, |
106 | acm->control->altsetting[0].desc.bInterfaceNumber, | 111 | acm->control->altsetting[0].desc.bInterfaceNumber, |
107 | buf, len, 5000); | 112 | buf, len, 5000); |
108 | dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", request, value, len, retval); | 113 | dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", |
114 | request, value, len, retval); | ||
109 | return retval < 0 ? retval : 0; | 115 | return retval < 0 ? retval : 0; |
110 | } | 116 | } |
111 | 117 | ||
@@ -150,9 +156,8 @@ static int acm_wb_is_avail(struct acm *acm) | |||
150 | 156 | ||
151 | n = ACM_NW; | 157 | n = ACM_NW; |
152 | spin_lock_irqsave(&acm->write_lock, flags); | 158 | spin_lock_irqsave(&acm->write_lock, flags); |
153 | for (i = 0; i < ACM_NW; i++) { | 159 | for (i = 0; i < ACM_NW; i++) |
154 | n -= acm->wb[i].use; | 160 | n -= acm->wb[i].use; |
155 | } | ||
156 | spin_unlock_irqrestore(&acm->write_lock, flags); | 161 | spin_unlock_irqrestore(&acm->write_lock, flags); |
157 | return n; | 162 | return n; |
158 | } | 163 | } |
@@ -183,7 +188,8 @@ static int acm_start_wb(struct acm *acm, struct acm_wb *wb) | |||
183 | wb->urb->transfer_buffer_length = wb->len; | 188 | wb->urb->transfer_buffer_length = wb->len; |
184 | wb->urb->dev = acm->dev; | 189 | wb->urb->dev = acm->dev; |
185 | 190 | ||
186 | if ((rc = usb_submit_urb(wb->urb, GFP_ATOMIC)) < 0) { | 191 | rc = usb_submit_urb(wb->urb, GFP_ATOMIC); |
192 | if (rc < 0) { | ||
187 | dbg("usb_submit_urb(write bulk) failed: %d", rc); | 193 | dbg("usb_submit_urb(write bulk) failed: %d", rc); |
188 | acm_write_done(acm, wb); | 194 | acm_write_done(acm, wb); |
189 | } | 195 | } |
@@ -262,6 +268,7 @@ static void acm_ctrl_irq(struct urb *urb) | |||
262 | { | 268 | { |
263 | struct acm *acm = urb->context; | 269 | struct acm *acm = urb->context; |
264 | struct usb_cdc_notification *dr = urb->transfer_buffer; | 270 | struct usb_cdc_notification *dr = urb->transfer_buffer; |
271 | struct tty_struct *tty; | ||
265 | unsigned char *data; | 272 | unsigned char *data; |
266 | int newctrl; | 273 | int newctrl; |
267 | int retval; | 274 | int retval; |
@@ -287,40 +294,45 @@ static void acm_ctrl_irq(struct urb *urb) | |||
287 | 294 | ||
288 | data = (unsigned char *)(dr + 1); | 295 | data = (unsigned char *)(dr + 1); |
289 | switch (dr->bNotificationType) { | 296 | switch (dr->bNotificationType) { |
297 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: | ||
298 | dbg("%s network", dr->wValue ? | ||
299 | "connected to" : "disconnected from"); | ||
300 | break; | ||
290 | 301 | ||
291 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: | 302 | case USB_CDC_NOTIFY_SERIAL_STATE: |
292 | 303 | tty = tty_port_tty_get(&acm->port); | |
293 | dbg("%s network", dr->wValue ? "connected to" : "disconnected from"); | 304 | newctrl = get_unaligned_le16(data); |
294 | break; | ||
295 | |||
296 | case USB_CDC_NOTIFY_SERIAL_STATE: | ||
297 | |||
298 | newctrl = get_unaligned_le16(data); | ||
299 | 305 | ||
300 | if (acm->tty && !acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { | 306 | if (tty) { |
307 | if (!acm->clocal && | ||
308 | (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { | ||
301 | dbg("calling hangup"); | 309 | dbg("calling hangup"); |
302 | tty_hangup(acm->tty); | 310 | tty_hangup(tty); |
303 | } | 311 | } |
312 | tty_kref_put(tty); | ||
313 | } | ||
304 | 314 | ||
305 | acm->ctrlin = newctrl; | 315 | acm->ctrlin = newctrl; |
306 | |||
307 | dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c", | ||
308 | acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', | ||
309 | acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', acm->ctrlin & ACM_CTRL_RI ? '+' : '-', | ||
310 | acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-', | ||
311 | acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-'); | ||
312 | 316 | ||
317 | dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c", | ||
318 | acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', | ||
319 | acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', | ||
320 | acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', | ||
321 | acm->ctrlin & ACM_CTRL_RI ? '+' : '-', | ||
322 | acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', | ||
323 | acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-', | ||
324 | acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-'); | ||
313 | break; | 325 | break; |
314 | 326 | ||
315 | default: | 327 | default: |
316 | dbg("unknown notification %d received: index %d len %d data0 %d data1 %d", | 328 | dbg("unknown notification %d received: index %d len %d data0 %d data1 %d", |
317 | dr->bNotificationType, dr->wIndex, | 329 | dr->bNotificationType, dr->wIndex, |
318 | dr->wLength, data[0], data[1]); | 330 | dr->wLength, data[0], data[1]); |
319 | break; | 331 | break; |
320 | } | 332 | } |
321 | exit: | 333 | exit: |
322 | usb_mark_last_busy(acm->dev); | 334 | usb_mark_last_busy(acm->dev); |
323 | retval = usb_submit_urb (urb, GFP_ATOMIC); | 335 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
324 | if (retval) | 336 | if (retval) |
325 | dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with " | 337 | dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with " |
326 | "result %d", __func__, retval); | 338 | "result %d", __func__, retval); |
@@ -371,15 +383,14 @@ static void acm_rx_tasklet(unsigned long _acm) | |||
371 | { | 383 | { |
372 | struct acm *acm = (void *)_acm; | 384 | struct acm *acm = (void *)_acm; |
373 | struct acm_rb *buf; | 385 | struct acm_rb *buf; |
374 | struct tty_struct *tty = acm->tty; | 386 | struct tty_struct *tty; |
375 | struct acm_ru *rcv; | 387 | struct acm_ru *rcv; |
376 | unsigned long flags; | 388 | unsigned long flags; |
377 | unsigned char throttled; | 389 | unsigned char throttled; |
378 | 390 | ||
379 | dbg("Entering acm_rx_tasklet"); | 391 | dbg("Entering acm_rx_tasklet"); |
380 | 392 | ||
381 | if (!ACM_READY(acm)) | 393 | if (!ACM_READY(acm)) { |
382 | { | ||
383 | dbg("acm_rx_tasklet: ACM not ready"); | 394 | dbg("acm_rx_tasklet: ACM not ready"); |
384 | return; | 395 | return; |
385 | } | 396 | } |
@@ -387,12 +398,13 @@ static void acm_rx_tasklet(unsigned long _acm) | |||
387 | spin_lock_irqsave(&acm->throttle_lock, flags); | 398 | spin_lock_irqsave(&acm->throttle_lock, flags); |
388 | throttled = acm->throttle; | 399 | throttled = acm->throttle; |
389 | spin_unlock_irqrestore(&acm->throttle_lock, flags); | 400 | spin_unlock_irqrestore(&acm->throttle_lock, flags); |
390 | if (throttled) | 401 | if (throttled) { |
391 | { | ||
392 | dbg("acm_rx_tasklet: throttled"); | 402 | dbg("acm_rx_tasklet: throttled"); |
393 | return; | 403 | return; |
394 | } | 404 | } |
395 | 405 | ||
406 | tty = tty_port_tty_get(&acm->port); | ||
407 | |||
396 | next_buffer: | 408 | next_buffer: |
397 | spin_lock_irqsave(&acm->read_lock, flags); | 409 | spin_lock_irqsave(&acm->read_lock, flags); |
398 | if (list_empty(&acm->filled_read_bufs)) { | 410 | if (list_empty(&acm->filled_read_bufs)) { |
@@ -406,20 +418,22 @@ next_buffer: | |||
406 | 418 | ||
407 | dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); | 419 | dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); |
408 | 420 | ||
409 | tty_buffer_request_room(tty, buf->size); | 421 | if (tty) { |
410 | spin_lock_irqsave(&acm->throttle_lock, flags); | 422 | spin_lock_irqsave(&acm->throttle_lock, flags); |
411 | throttled = acm->throttle; | 423 | throttled = acm->throttle; |
412 | spin_unlock_irqrestore(&acm->throttle_lock, flags); | 424 | spin_unlock_irqrestore(&acm->throttle_lock, flags); |
413 | if (!throttled) | 425 | if (!throttled) { |
414 | tty_insert_flip_string(tty, buf->base, buf->size); | 426 | tty_buffer_request_room(tty, buf->size); |
415 | tty_flip_buffer_push(tty); | 427 | tty_insert_flip_string(tty, buf->base, buf->size); |
416 | 428 | tty_flip_buffer_push(tty); | |
417 | if (throttled) { | 429 | } else { |
418 | dbg("Throttling noticed"); | 430 | tty_kref_put(tty); |
419 | spin_lock_irqsave(&acm->read_lock, flags); | 431 | dbg("Throttling noticed"); |
420 | list_add(&buf->list, &acm->filled_read_bufs); | 432 | spin_lock_irqsave(&acm->read_lock, flags); |
421 | spin_unlock_irqrestore(&acm->read_lock, flags); | 433 | list_add(&buf->list, &acm->filled_read_bufs); |
422 | return; | 434 | spin_unlock_irqrestore(&acm->read_lock, flags); |
435 | return; | ||
436 | } | ||
423 | } | 437 | } |
424 | 438 | ||
425 | spin_lock_irqsave(&acm->read_lock, flags); | 439 | spin_lock_irqsave(&acm->read_lock, flags); |
@@ -428,6 +442,8 @@ next_buffer: | |||
428 | goto next_buffer; | 442 | goto next_buffer; |
429 | 443 | ||
430 | urbs: | 444 | urbs: |
445 | tty_kref_put(tty); | ||
446 | |||
431 | while (!list_empty(&acm->spare_read_bufs)) { | 447 | while (!list_empty(&acm->spare_read_bufs)) { |
432 | spin_lock_irqsave(&acm->read_lock, flags); | 448 | spin_lock_irqsave(&acm->read_lock, flags); |
433 | if (list_empty(&acm->spare_read_urbs)) { | 449 | if (list_empty(&acm->spare_read_urbs)) { |
@@ -454,10 +470,11 @@ urbs: | |||
454 | rcv->urb->transfer_dma = buf->dma; | 470 | rcv->urb->transfer_dma = buf->dma; |
455 | rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 471 | rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
456 | 472 | ||
457 | /* This shouldn't kill the driver as unsuccessful URBs are returned to the | 473 | /* This shouldn't kill the driver as unsuccessful URBs are |
458 | free-urbs-pool and resubmited ASAP */ | 474 | returned to the free-urbs-pool and resubmited ASAP */ |
459 | spin_lock_irqsave(&acm->read_lock, flags); | 475 | spin_lock_irqsave(&acm->read_lock, flags); |
460 | if (acm->susp_count || usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) { | 476 | if (acm->susp_count || |
477 | usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) { | ||
461 | list_add(&buf->list, &acm->spare_read_bufs); | 478 | list_add(&buf->list, &acm->spare_read_bufs); |
462 | list_add(&rcv->list, &acm->spare_read_urbs); | 479 | list_add(&rcv->list, &acm->spare_read_urbs); |
463 | acm->processing = 0; | 480 | acm->processing = 0; |
@@ -499,11 +516,14 @@ static void acm_write_bulk(struct urb *urb) | |||
499 | static void acm_softint(struct work_struct *work) | 516 | static void acm_softint(struct work_struct *work) |
500 | { | 517 | { |
501 | struct acm *acm = container_of(work, struct acm, work); | 518 | struct acm *acm = container_of(work, struct acm, work); |
519 | struct tty_struct *tty; | ||
502 | 520 | ||
503 | dev_vdbg(&acm->data->dev, "tx work\n"); | 521 | dev_vdbg(&acm->data->dev, "tx work\n"); |
504 | if (!ACM_READY(acm)) | 522 | if (!ACM_READY(acm)) |
505 | return; | 523 | return; |
506 | tty_wakeup(acm->tty); | 524 | tty = tty_port_tty_get(&acm->port); |
525 | tty_wakeup(tty); | ||
526 | tty_kref_put(tty); | ||
507 | } | 527 | } |
508 | 528 | ||
509 | static void acm_waker(struct work_struct *waker) | 529 | static void acm_waker(struct work_struct *waker) |
@@ -543,8 +563,9 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
543 | rv = 0; | 563 | rv = 0; |
544 | 564 | ||
545 | set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); | 565 | set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); |
566 | |||
546 | tty->driver_data = acm; | 567 | tty->driver_data = acm; |
547 | acm->tty = tty; | 568 | tty_port_tty_set(&acm->port, tty); |
548 | 569 | ||
549 | if (usb_autopm_get_interface(acm->control) < 0) | 570 | if (usb_autopm_get_interface(acm->control) < 0) |
550 | goto early_bail; | 571 | goto early_bail; |
@@ -552,11 +573,10 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
552 | acm->control->needs_remote_wakeup = 1; | 573 | acm->control->needs_remote_wakeup = 1; |
553 | 574 | ||
554 | mutex_lock(&acm->mutex); | 575 | mutex_lock(&acm->mutex); |
555 | if (acm->used++) { | 576 | if (acm->port.count++) { |
556 | usb_autopm_put_interface(acm->control); | 577 | usb_autopm_put_interface(acm->control); |
557 | goto done; | 578 | goto done; |
558 | } | 579 | } |
559 | |||
560 | 580 | ||
561 | acm->ctrlurb->dev = acm->dev; | 581 | acm->ctrlurb->dev = acm->dev; |
562 | if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { | 582 | if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { |
@@ -567,22 +587,22 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
567 | if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && | 587 | if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && |
568 | (acm->ctrl_caps & USB_CDC_CAP_LINE)) | 588 | (acm->ctrl_caps & USB_CDC_CAP_LINE)) |
569 | goto full_bailout; | 589 | goto full_bailout; |
590 | |||
570 | usb_autopm_put_interface(acm->control); | 591 | usb_autopm_put_interface(acm->control); |
571 | 592 | ||
572 | INIT_LIST_HEAD(&acm->spare_read_urbs); | 593 | INIT_LIST_HEAD(&acm->spare_read_urbs); |
573 | INIT_LIST_HEAD(&acm->spare_read_bufs); | 594 | INIT_LIST_HEAD(&acm->spare_read_bufs); |
574 | INIT_LIST_HEAD(&acm->filled_read_bufs); | 595 | INIT_LIST_HEAD(&acm->filled_read_bufs); |
575 | for (i = 0; i < acm->rx_buflimit; i++) { | 596 | |
597 | for (i = 0; i < acm->rx_buflimit; i++) | ||
576 | list_add(&(acm->ru[i].list), &acm->spare_read_urbs); | 598 | list_add(&(acm->ru[i].list), &acm->spare_read_urbs); |
577 | } | 599 | for (i = 0; i < acm->rx_buflimit; i++) |
578 | for (i = 0; i < acm->rx_buflimit; i++) { | ||
579 | list_add(&(acm->rb[i].list), &acm->spare_read_bufs); | 600 | list_add(&(acm->rb[i].list), &acm->spare_read_bufs); |
580 | } | ||
581 | 601 | ||
582 | acm->throttle = 0; | 602 | acm->throttle = 0; |
583 | 603 | ||
584 | tasklet_schedule(&acm->urb_task); | 604 | tasklet_schedule(&acm->urb_task); |
585 | 605 | rv = tty_port_block_til_ready(&acm->port, tty, filp); | |
586 | done: | 606 | done: |
587 | mutex_unlock(&acm->mutex); | 607 | mutex_unlock(&acm->mutex); |
588 | err_out: | 608 | err_out: |
@@ -593,16 +613,17 @@ full_bailout: | |||
593 | usb_kill_urb(acm->ctrlurb); | 613 | usb_kill_urb(acm->ctrlurb); |
594 | bail_out: | 614 | bail_out: |
595 | usb_autopm_put_interface(acm->control); | 615 | usb_autopm_put_interface(acm->control); |
596 | acm->used--; | 616 | acm->port.count--; |
597 | mutex_unlock(&acm->mutex); | 617 | mutex_unlock(&acm->mutex); |
598 | early_bail: | 618 | early_bail: |
599 | mutex_unlock(&open_mutex); | 619 | mutex_unlock(&open_mutex); |
620 | tty_port_tty_set(&acm->port, NULL); | ||
600 | return -EIO; | 621 | return -EIO; |
601 | } | 622 | } |
602 | 623 | ||
603 | static void acm_tty_unregister(struct acm *acm) | 624 | static void acm_tty_unregister(struct acm *acm) |
604 | { | 625 | { |
605 | int i,nr; | 626 | int i, nr; |
606 | 627 | ||
607 | nr = acm->rx_buflimit; | 628 | nr = acm->rx_buflimit; |
608 | tty_unregister_device(acm_tty_driver, acm->minor); | 629 | tty_unregister_device(acm_tty_driver, acm->minor); |
@@ -619,41 +640,56 @@ static void acm_tty_unregister(struct acm *acm) | |||
619 | 640 | ||
620 | static int acm_tty_chars_in_buffer(struct tty_struct *tty); | 641 | static int acm_tty_chars_in_buffer(struct tty_struct *tty); |
621 | 642 | ||
643 | static void acm_port_down(struct acm *acm, int drain) | ||
644 | { | ||
645 | int i, nr = acm->rx_buflimit; | ||
646 | mutex_lock(&open_mutex); | ||
647 | if (acm->dev) { | ||
648 | usb_autopm_get_interface(acm->control); | ||
649 | acm_set_control(acm, acm->ctrlout = 0); | ||
650 | /* try letting the last writes drain naturally */ | ||
651 | if (drain) { | ||
652 | wait_event_interruptible_timeout(acm->drain_wait, | ||
653 | (ACM_NW == acm_wb_is_avail(acm)) || !acm->dev, | ||
654 | ACM_CLOSE_TIMEOUT * HZ); | ||
655 | } | ||
656 | usb_kill_urb(acm->ctrlurb); | ||
657 | for (i = 0; i < ACM_NW; i++) | ||
658 | usb_kill_urb(acm->wb[i].urb); | ||
659 | for (i = 0; i < nr; i++) | ||
660 | usb_kill_urb(acm->ru[i].urb); | ||
661 | acm->control->needs_remote_wakeup = 0; | ||
662 | usb_autopm_put_interface(acm->control); | ||
663 | } | ||
664 | mutex_unlock(&open_mutex); | ||
665 | } | ||
666 | |||
667 | static void acm_tty_hangup(struct tty_struct *tty) | ||
668 | { | ||
669 | struct acm *acm = tty->driver_data; | ||
670 | tty_port_hangup(&acm->port); | ||
671 | acm_port_down(acm, 0); | ||
672 | } | ||
673 | |||
622 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) | 674 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) |
623 | { | 675 | { |
624 | struct acm *acm = tty->driver_data; | 676 | struct acm *acm = tty->driver_data; |
625 | int i,nr; | ||
626 | 677 | ||
627 | if (!acm || !acm->used) | 678 | /* Perform the closing process and see if we need to do the hardware |
679 | shutdown */ | ||
680 | if (tty_port_close_start(&acm->port, tty, filp) == 0) | ||
628 | return; | 681 | return; |
629 | 682 | acm_port_down(acm, 0); | |
630 | nr = acm->rx_buflimit; | 683 | tty_port_close_end(&acm->port, tty); |
631 | mutex_lock(&open_mutex); | 684 | mutex_lock(&open_mutex); |
632 | if (!--acm->used) { | 685 | tty_port_tty_set(&acm->port, NULL); |
633 | if (acm->dev) { | 686 | if (!acm->dev) |
634 | usb_autopm_get_interface(acm->control); | 687 | acm_tty_unregister(acm); |
635 | acm_set_control(acm, acm->ctrlout = 0); | ||
636 | |||
637 | /* try letting the last writes drain naturally */ | ||
638 | wait_event_interruptible_timeout(acm->drain_wait, | ||
639 | (ACM_NW == acm_wb_is_avail(acm)) | ||
640 | || !acm->dev, | ||
641 | ACM_CLOSE_TIMEOUT * HZ); | ||
642 | |||
643 | usb_kill_urb(acm->ctrlurb); | ||
644 | for (i = 0; i < ACM_NW; i++) | ||
645 | usb_kill_urb(acm->wb[i].urb); | ||
646 | for (i = 0; i < nr; i++) | ||
647 | usb_kill_urb(acm->ru[i].urb); | ||
648 | acm->control->needs_remote_wakeup = 0; | ||
649 | usb_autopm_put_interface(acm->control); | ||
650 | } else | ||
651 | acm_tty_unregister(acm); | ||
652 | } | ||
653 | mutex_unlock(&open_mutex); | 688 | mutex_unlock(&open_mutex); |
654 | } | 689 | } |
655 | 690 | ||
656 | static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) | 691 | static int acm_tty_write(struct tty_struct *tty, |
692 | const unsigned char *buf, int count) | ||
657 | { | 693 | { |
658 | struct acm *acm = tty->driver_data; | 694 | struct acm *acm = tty->driver_data; |
659 | int stat; | 695 | int stat; |
@@ -669,7 +705,8 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c | |||
669 | return 0; | 705 | return 0; |
670 | 706 | ||
671 | spin_lock_irqsave(&acm->write_lock, flags); | 707 | spin_lock_irqsave(&acm->write_lock, flags); |
672 | if ((wbn = acm_wb_alloc(acm)) < 0) { | 708 | wbn = acm_wb_alloc(acm); |
709 | if (wbn < 0) { | ||
673 | spin_unlock_irqrestore(&acm->write_lock, flags); | 710 | spin_unlock_irqrestore(&acm->write_lock, flags); |
674 | return 0; | 711 | return 0; |
675 | } | 712 | } |
@@ -681,7 +718,8 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c | |||
681 | wb->len = count; | 718 | wb->len = count; |
682 | spin_unlock_irqrestore(&acm->write_lock, flags); | 719 | spin_unlock_irqrestore(&acm->write_lock, flags); |
683 | 720 | ||
684 | if ((stat = acm_write_start(acm, wbn)) < 0) | 721 | stat = acm_write_start(acm, wbn); |
722 | if (stat < 0) | ||
685 | return stat; | 723 | return stat; |
686 | return count; | 724 | return count; |
687 | } | 725 | } |
@@ -767,8 +805,10 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file, | |||
767 | return -EINVAL; | 805 | return -EINVAL; |
768 | 806 | ||
769 | newctrl = acm->ctrlout; | 807 | newctrl = acm->ctrlout; |
770 | set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); | 808 | set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | |
771 | clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); | 809 | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); |
810 | clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | | ||
811 | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); | ||
772 | 812 | ||
773 | newctrl = (newctrl & ~clear) | set; | 813 | newctrl = (newctrl & ~clear) | set; |
774 | 814 | ||
@@ -777,7 +817,8 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file, | |||
777 | return acm_set_control(acm, acm->ctrlout = newctrl); | 817 | return acm_set_control(acm, acm->ctrlout = newctrl); |
778 | } | 818 | } |
779 | 819 | ||
780 | static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) | 820 | static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, |
821 | unsigned int cmd, unsigned long arg) | ||
781 | { | 822 | { |
782 | struct acm *acm = tty->driver_data; | 823 | struct acm *acm = tty->driver_data; |
783 | 824 | ||
@@ -799,7 +840,8 @@ static const __u8 acm_tty_size[] = { | |||
799 | 5, 6, 7, 8 | 840 | 5, 6, 7, 8 |
800 | }; | 841 | }; |
801 | 842 | ||
802 | static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old) | 843 | static void acm_tty_set_termios(struct tty_struct *tty, |
844 | struct ktermios *termios_old) | ||
803 | { | 845 | { |
804 | struct acm *acm = tty->driver_data; | 846 | struct acm *acm = tty->driver_data; |
805 | struct ktermios *termios = tty->termios; | 847 | struct ktermios *termios = tty->termios; |
@@ -809,19 +851,23 @@ static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios | |||
809 | if (!ACM_READY(acm)) | 851 | if (!ACM_READY(acm)) |
810 | return; | 852 | return; |
811 | 853 | ||
854 | /* FIXME: Needs to support the tty_baud interface */ | ||
855 | /* FIXME: Broken on sparc */ | ||
812 | newline.dwDTERate = cpu_to_le32p(acm_tty_speed + | 856 | newline.dwDTERate = cpu_to_le32p(acm_tty_speed + |
813 | (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0)); | 857 | (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0)); |
814 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; | 858 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; |
815 | newline.bParityType = termios->c_cflag & PARENB ? | 859 | newline.bParityType = termios->c_cflag & PARENB ? |
816 | (termios->c_cflag & PARODD ? 1 : 2) + (termios->c_cflag & CMSPAR ? 2 : 0) : 0; | 860 | (termios->c_cflag & PARODD ? 1 : 2) + |
861 | (termios->c_cflag & CMSPAR ? 2 : 0) : 0; | ||
817 | newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4]; | 862 | newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4]; |
818 | 863 | /* FIXME: Needs to clear unsupported bits in the termios */ | |
819 | acm->clocal = ((termios->c_cflag & CLOCAL) != 0); | 864 | acm->clocal = ((termios->c_cflag & CLOCAL) != 0); |
820 | 865 | ||
821 | if (!newline.dwDTERate) { | 866 | if (!newline.dwDTERate) { |
822 | newline.dwDTERate = acm->line.dwDTERate; | 867 | newline.dwDTERate = acm->line.dwDTERate; |
823 | newctrl &= ~ACM_CTRL_DTR; | 868 | newctrl &= ~ACM_CTRL_DTR; |
824 | } else newctrl |= ACM_CTRL_DTR; | 869 | } else |
870 | newctrl |= ACM_CTRL_DTR; | ||
825 | 871 | ||
826 | if (newctrl != acm->ctrlout) | 872 | if (newctrl != acm->ctrlout) |
827 | acm_set_control(acm, acm->ctrlout = newctrl); | 873 | acm_set_control(acm, acm->ctrlout = newctrl); |
@@ -846,9 +892,8 @@ static void acm_write_buffers_free(struct acm *acm) | |||
846 | struct acm_wb *wb; | 892 | struct acm_wb *wb; |
847 | struct usb_device *usb_dev = interface_to_usbdev(acm->control); | 893 | struct usb_device *usb_dev = interface_to_usbdev(acm->control); |
848 | 894 | ||
849 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { | 895 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) |
850 | usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah); | 896 | usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah); |
851 | } | ||
852 | } | 897 | } |
853 | 898 | ||
854 | static void acm_read_buffers_free(struct acm *acm) | 899 | static void acm_read_buffers_free(struct acm *acm) |
@@ -857,7 +902,8 @@ static void acm_read_buffers_free(struct acm *acm) | |||
857 | int i, n = acm->rx_buflimit; | 902 | int i, n = acm->rx_buflimit; |
858 | 903 | ||
859 | for (i = 0; i < n; i++) | 904 | for (i = 0; i < n; i++) |
860 | usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma); | 905 | usb_buffer_free(usb_dev, acm->readsize, |
906 | acm->rb[i].base, acm->rb[i].dma); | ||
861 | } | 907 | } |
862 | 908 | ||
863 | /* Little helper: write buffers allocate */ | 909 | /* Little helper: write buffers allocate */ |
@@ -882,8 +928,8 @@ static int acm_write_buffers_alloc(struct acm *acm) | |||
882 | return 0; | 928 | return 0; |
883 | } | 929 | } |
884 | 930 | ||
885 | static int acm_probe (struct usb_interface *intf, | 931 | static int acm_probe(struct usb_interface *intf, |
886 | const struct usb_device_id *id) | 932 | const struct usb_device_id *id) |
887 | { | 933 | { |
888 | struct usb_cdc_union_desc *union_header = NULL; | 934 | struct usb_cdc_union_desc *union_header = NULL; |
889 | struct usb_cdc_country_functional_desc *cfd = NULL; | 935 | struct usb_cdc_country_functional_desc *cfd = NULL; |
@@ -897,7 +943,7 @@ static int acm_probe (struct usb_interface *intf, | |||
897 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 943 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
898 | struct acm *acm; | 944 | struct acm *acm; |
899 | int minor; | 945 | int minor; |
900 | int ctrlsize,readsize; | 946 | int ctrlsize, readsize; |
901 | u8 *buf; | 947 | u8 *buf; |
902 | u8 ac_management_function = 0; | 948 | u8 ac_management_function = 0; |
903 | u8 call_management_function = 0; | 949 | u8 call_management_function = 0; |
@@ -917,7 +963,7 @@ static int acm_probe (struct usb_interface *intf, | |||
917 | control_interface = usb_ifnum_to_if(usb_dev, 0); | 963 | control_interface = usb_ifnum_to_if(usb_dev, 0); |
918 | goto skip_normal_probe; | 964 | goto skip_normal_probe; |
919 | } | 965 | } |
920 | 966 | ||
921 | /* normal probing*/ | 967 | /* normal probing*/ |
922 | if (!buffer) { | 968 | if (!buffer) { |
923 | dev_err(&intf->dev, "Weird descriptor references\n"); | 969 | dev_err(&intf->dev, "Weird descriptor references\n"); |
@@ -925,8 +971,10 @@ static int acm_probe (struct usb_interface *intf, | |||
925 | } | 971 | } |
926 | 972 | ||
927 | if (!buflen) { | 973 | if (!buflen) { |
928 | if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) { | 974 | if (intf->cur_altsetting->endpoint->extralen && |
929 | dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint\n"); | 975 | intf->cur_altsetting->endpoint->extra) { |
976 | dev_dbg(&intf->dev, | ||
977 | "Seeking extra descriptors on endpoint\n"); | ||
930 | buflen = intf->cur_altsetting->endpoint->extralen; | 978 | buflen = intf->cur_altsetting->endpoint->extralen; |
931 | buffer = intf->cur_altsetting->endpoint->extra; | 979 | buffer = intf->cur_altsetting->endpoint->extra; |
932 | } else { | 980 | } else { |
@@ -937,47 +985,43 @@ static int acm_probe (struct usb_interface *intf, | |||
937 | } | 985 | } |
938 | 986 | ||
939 | while (buflen > 0) { | 987 | while (buflen > 0) { |
940 | if (buffer [1] != USB_DT_CS_INTERFACE) { | 988 | if (buffer[1] != USB_DT_CS_INTERFACE) { |
941 | dev_err(&intf->dev, "skipping garbage\n"); | 989 | dev_err(&intf->dev, "skipping garbage\n"); |
942 | goto next_desc; | 990 | goto next_desc; |
943 | } | 991 | } |
944 | 992 | ||
945 | switch (buffer [2]) { | 993 | switch (buffer[2]) { |
946 | case USB_CDC_UNION_TYPE: /* we've found it */ | 994 | case USB_CDC_UNION_TYPE: /* we've found it */ |
947 | if (union_header) { | 995 | if (union_header) { |
948 | dev_err(&intf->dev, "More than one " | 996 | dev_err(&intf->dev, "More than one " |
949 | "union descriptor, " | 997 | "union descriptor, skipping ...\n"); |
950 | "skipping ...\n"); | 998 | goto next_desc; |
951 | goto next_desc; | ||
952 | } | ||
953 | union_header = (struct usb_cdc_union_desc *) | ||
954 | buffer; | ||
955 | break; | ||
956 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ | ||
957 | cfd = (struct usb_cdc_country_functional_desc *)buffer; | ||
958 | break; | ||
959 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | ||
960 | break; /* for now we ignore it */ | ||
961 | case USB_CDC_ACM_TYPE: | ||
962 | ac_management_function = buffer[3]; | ||
963 | break; | ||
964 | case USB_CDC_CALL_MANAGEMENT_TYPE: | ||
965 | call_management_function = buffer[3]; | ||
966 | call_interface_num = buffer[4]; | ||
967 | if ((call_management_function & 3) != 3) | ||
968 | dev_err(&intf->dev, "This device " | ||
969 | "cannot do calls on its own. " | ||
970 | "It is no modem.\n"); | ||
971 | break; | ||
972 | default: | ||
973 | /* there are LOTS more CDC descriptors that | ||
974 | * could legitimately be found here. | ||
975 | */ | ||
976 | dev_dbg(&intf->dev, "Ignoring descriptor: " | ||
977 | "type %02x, length %d\n", | ||
978 | buffer[2], buffer[0]); | ||
979 | break; | ||
980 | } | 999 | } |
1000 | union_header = (struct usb_cdc_union_desc *)buffer; | ||
1001 | break; | ||
1002 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ | ||
1003 | cfd = (struct usb_cdc_country_functional_desc *)buffer; | ||
1004 | break; | ||
1005 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | ||
1006 | break; /* for now we ignore it */ | ||
1007 | case USB_CDC_ACM_TYPE: | ||
1008 | ac_management_function = buffer[3]; | ||
1009 | break; | ||
1010 | case USB_CDC_CALL_MANAGEMENT_TYPE: | ||
1011 | call_management_function = buffer[3]; | ||
1012 | call_interface_num = buffer[4]; | ||
1013 | if ((call_management_function & 3) != 3) | ||
1014 | dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n"); | ||
1015 | break; | ||
1016 | default: | ||
1017 | /* there are LOTS more CDC descriptors that | ||
1018 | * could legitimately be found here. | ||
1019 | */ | ||
1020 | dev_dbg(&intf->dev, "Ignoring descriptor: " | ||
1021 | "type %02x, length %d\n", | ||
1022 | buffer[2], buffer[0]); | ||
1023 | break; | ||
1024 | } | ||
981 | next_desc: | 1025 | next_desc: |
982 | buflen -= buffer[0]; | 1026 | buflen -= buffer[0]; |
983 | buffer += buffer[0]; | 1027 | buffer += buffer[0]; |
@@ -985,33 +1029,36 @@ next_desc: | |||
985 | 1029 | ||
986 | if (!union_header) { | 1030 | if (!union_header) { |
987 | if (call_interface_num > 0) { | 1031 | if (call_interface_num > 0) { |
988 | dev_dbg(&intf->dev,"No union descriptor, using call management descriptor\n"); | 1032 | dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); |
989 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); | 1033 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); |
990 | control_interface = intf; | 1034 | control_interface = intf; |
991 | } else { | 1035 | } else { |
992 | dev_dbg(&intf->dev,"No union descriptor, giving up\n"); | 1036 | dev_dbg(&intf->dev, |
1037 | "No union descriptor, giving up\n"); | ||
993 | return -ENODEV; | 1038 | return -ENODEV; |
994 | } | 1039 | } |
995 | } else { | 1040 | } else { |
996 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); | 1041 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); |
997 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); | 1042 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); |
998 | if (!control_interface || !data_interface) { | 1043 | if (!control_interface || !data_interface) { |
999 | dev_dbg(&intf->dev,"no interfaces\n"); | 1044 | dev_dbg(&intf->dev, "no interfaces\n"); |
1000 | return -ENODEV; | 1045 | return -ENODEV; |
1001 | } | 1046 | } |
1002 | } | 1047 | } |
1003 | 1048 | ||
1004 | if (data_interface_num != call_interface_num) | 1049 | if (data_interface_num != call_interface_num) |
1005 | dev_dbg(&intf->dev,"Separate call control interface. That is not fully supported.\n"); | 1050 | dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); |
1006 | 1051 | ||
1007 | skip_normal_probe: | 1052 | skip_normal_probe: |
1008 | 1053 | ||
1009 | /*workaround for switched interfaces */ | 1054 | /*workaround for switched interfaces */ |
1010 | if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) { | 1055 | if (data_interface->cur_altsetting->desc.bInterfaceClass |
1011 | if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) { | 1056 | != CDC_DATA_INTERFACE_TYPE) { |
1057 | if (control_interface->cur_altsetting->desc.bInterfaceClass | ||
1058 | == CDC_DATA_INTERFACE_TYPE) { | ||
1012 | struct usb_interface *t; | 1059 | struct usb_interface *t; |
1013 | dev_dbg(&intf->dev,"Your device has switched interfaces.\n"); | 1060 | dev_dbg(&intf->dev, |
1014 | 1061 | "Your device has switched interfaces.\n"); | |
1015 | t = control_interface; | 1062 | t = control_interface; |
1016 | control_interface = data_interface; | 1063 | control_interface = data_interface; |
1017 | data_interface = t; | 1064 | data_interface = t; |
@@ -1023,9 +1070,9 @@ skip_normal_probe: | |||
1023 | /* Accept probe requests only for the control interface */ | 1070 | /* Accept probe requests only for the control interface */ |
1024 | if (intf != control_interface) | 1071 | if (intf != control_interface) |
1025 | return -ENODEV; | 1072 | return -ENODEV; |
1026 | 1073 | ||
1027 | if (usb_interface_claimed(data_interface)) { /* valid in this context */ | 1074 | if (usb_interface_claimed(data_interface)) { /* valid in this context */ |
1028 | dev_dbg(&intf->dev,"The data interface isn't available\n"); | 1075 | dev_dbg(&intf->dev, "The data interface isn't available\n"); |
1029 | return -EBUSY; | 1076 | return -EBUSY; |
1030 | } | 1077 | } |
1031 | 1078 | ||
@@ -1042,8 +1089,8 @@ skip_normal_probe: | |||
1042 | if (!usb_endpoint_dir_in(epread)) { | 1089 | if (!usb_endpoint_dir_in(epread)) { |
1043 | /* descriptors are swapped */ | 1090 | /* descriptors are swapped */ |
1044 | struct usb_endpoint_descriptor *t; | 1091 | struct usb_endpoint_descriptor *t; |
1045 | dev_dbg(&intf->dev,"The data interface has switched endpoints\n"); | 1092 | dev_dbg(&intf->dev, |
1046 | 1093 | "The data interface has switched endpoints\n"); | |
1047 | t = epread; | 1094 | t = epread; |
1048 | epread = epwrite; | 1095 | epread = epwrite; |
1049 | epwrite = t; | 1096 | epwrite = t; |
@@ -1056,13 +1103,15 @@ skip_normal_probe: | |||
1056 | return -ENODEV; | 1103 | return -ENODEV; |
1057 | } | 1104 | } |
1058 | 1105 | ||
1059 | if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) { | 1106 | acm = kzalloc(sizeof(struct acm), GFP_KERNEL); |
1107 | if (acm == NULL) { | ||
1060 | dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); | 1108 | dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); |
1061 | goto alloc_fail; | 1109 | goto alloc_fail; |
1062 | } | 1110 | } |
1063 | 1111 | ||
1064 | ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); | 1112 | ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); |
1065 | readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2); | 1113 | readsize = le16_to_cpu(epread->wMaxPacketSize) * |
1114 | (quirks == SINGLE_RX_URB ? 1 : 2); | ||
1066 | acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; | 1115 | acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; |
1067 | acm->control = control_interface; | 1116 | acm->control = control_interface; |
1068 | acm->data = data_interface; | 1117 | acm->data = data_interface; |
@@ -1082,6 +1131,8 @@ skip_normal_probe: | |||
1082 | spin_lock_init(&acm->read_lock); | 1131 | spin_lock_init(&acm->read_lock); |
1083 | mutex_init(&acm->mutex); | 1132 | mutex_init(&acm->mutex); |
1084 | acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); | 1133 | acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); |
1134 | tty_port_init(&acm->port); | ||
1135 | acm->port.ops = &acm_port_ops; | ||
1085 | 1136 | ||
1086 | buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); | 1137 | buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); |
1087 | if (!buf) { | 1138 | if (!buf) { |
@@ -1103,8 +1154,10 @@ skip_normal_probe: | |||
1103 | for (i = 0; i < num_rx_buf; i++) { | 1154 | for (i = 0; i < num_rx_buf; i++) { |
1104 | struct acm_ru *rcv = &(acm->ru[i]); | 1155 | struct acm_ru *rcv = &(acm->ru[i]); |
1105 | 1156 | ||
1106 | if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { | 1157 | rcv->urb = usb_alloc_urb(0, GFP_KERNEL); |
1107 | dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)\n"); | 1158 | if (rcv->urb == NULL) { |
1159 | dev_dbg(&intf->dev, | ||
1160 | "out of memory (read urbs usb_alloc_urb)\n"); | ||
1108 | goto alloc_fail7; | 1161 | goto alloc_fail7; |
1109 | } | 1162 | } |
1110 | 1163 | ||
@@ -1117,26 +1170,29 @@ skip_normal_probe: | |||
1117 | rb->base = usb_buffer_alloc(acm->dev, readsize, | 1170 | rb->base = usb_buffer_alloc(acm->dev, readsize, |
1118 | GFP_KERNEL, &rb->dma); | 1171 | GFP_KERNEL, &rb->dma); |
1119 | if (!rb->base) { | 1172 | if (!rb->base) { |
1120 | dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)\n"); | 1173 | dev_dbg(&intf->dev, |
1174 | "out of memory (read bufs usb_buffer_alloc)\n"); | ||
1121 | goto alloc_fail7; | 1175 | goto alloc_fail7; |
1122 | } | 1176 | } |
1123 | } | 1177 | } |
1124 | for(i = 0; i < ACM_NW; i++) | 1178 | for (i = 0; i < ACM_NW; i++) { |
1125 | { | ||
1126 | struct acm_wb *snd = &(acm->wb[i]); | 1179 | struct acm_wb *snd = &(acm->wb[i]); |
1127 | 1180 | ||
1128 | if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) { | 1181 | snd->urb = usb_alloc_urb(0, GFP_KERNEL); |
1129 | dev_dbg(&intf->dev, "out of memory (write urbs usb_alloc_urb)"); | 1182 | if (snd->urb == NULL) { |
1183 | dev_dbg(&intf->dev, | ||
1184 | "out of memory (write urbs usb_alloc_urb)"); | ||
1130 | goto alloc_fail7; | 1185 | goto alloc_fail7; |
1131 | } | 1186 | } |
1132 | 1187 | ||
1133 | usb_fill_bulk_urb(snd->urb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), | 1188 | usb_fill_bulk_urb(snd->urb, usb_dev, |
1134 | NULL, acm->writesize, acm_write_bulk, snd); | 1189 | usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), |
1190 | NULL, acm->writesize, acm_write_bulk, snd); | ||
1135 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1191 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1136 | snd->instance = acm; | 1192 | snd->instance = acm; |
1137 | } | 1193 | } |
1138 | 1194 | ||
1139 | usb_set_intfdata (intf, acm); | 1195 | usb_set_intfdata(intf, acm); |
1140 | 1196 | ||
1141 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); | 1197 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); |
1142 | if (i < 0) | 1198 | if (i < 0) |
@@ -1147,7 +1203,8 @@ skip_normal_probe: | |||
1147 | if (!acm->country_codes) | 1203 | if (!acm->country_codes) |
1148 | goto skip_countries; | 1204 | goto skip_countries; |
1149 | acm->country_code_size = cfd->bLength - 4; | 1205 | acm->country_code_size = cfd->bLength - 4; |
1150 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4); | 1206 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, |
1207 | cfd->bLength - 4); | ||
1151 | acm->country_rel_date = cfd->iCountryCodeRelDate; | 1208 | acm->country_rel_date = cfd->iCountryCodeRelDate; |
1152 | 1209 | ||
1153 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); | 1210 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); |
@@ -1156,7 +1213,8 @@ skip_normal_probe: | |||
1156 | goto skip_countries; | 1213 | goto skip_countries; |
1157 | } | 1214 | } |
1158 | 1215 | ||
1159 | i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate); | 1216 | i = device_create_file(&intf->dev, |
1217 | &dev_attr_iCountryCodeRelDate); | ||
1160 | if (i < 0) { | 1218 | if (i < 0) { |
1161 | kfree(acm->country_codes); | 1219 | kfree(acm->country_codes); |
1162 | goto skip_countries; | 1220 | goto skip_countries; |
@@ -1164,8 +1222,10 @@ skip_normal_probe: | |||
1164 | } | 1222 | } |
1165 | 1223 | ||
1166 | skip_countries: | 1224 | skip_countries: |
1167 | usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), | 1225 | usb_fill_int_urb(acm->ctrlurb, usb_dev, |
1168 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval); | 1226 | usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), |
1227 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, | ||
1228 | epctrl->bInterval); | ||
1169 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1229 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1170 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; | 1230 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; |
1171 | 1231 | ||
@@ -1212,7 +1272,7 @@ static void stop_data_traffic(struct acm *acm) | |||
1212 | tasklet_disable(&acm->urb_task); | 1272 | tasklet_disable(&acm->urb_task); |
1213 | 1273 | ||
1214 | usb_kill_urb(acm->ctrlurb); | 1274 | usb_kill_urb(acm->ctrlurb); |
1215 | for(i = 0; i < ACM_NW; i++) | 1275 | for (i = 0; i < ACM_NW; i++) |
1216 | usb_kill_urb(acm->wb[i].urb); | 1276 | usb_kill_urb(acm->wb[i].urb); |
1217 | for (i = 0; i < acm->rx_buflimit; i++) | 1277 | for (i = 0; i < acm->rx_buflimit; i++) |
1218 | usb_kill_urb(acm->ru[i].urb); | 1278 | usb_kill_urb(acm->ru[i].urb); |
@@ -1227,13 +1287,14 @@ static void acm_disconnect(struct usb_interface *intf) | |||
1227 | { | 1287 | { |
1228 | struct acm *acm = usb_get_intfdata(intf); | 1288 | struct acm *acm = usb_get_intfdata(intf); |
1229 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 1289 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
1290 | struct tty_struct *tty; | ||
1230 | 1291 | ||
1231 | /* sibling interface is already cleaning up */ | 1292 | /* sibling interface is already cleaning up */ |
1232 | if (!acm) | 1293 | if (!acm) |
1233 | return; | 1294 | return; |
1234 | 1295 | ||
1235 | mutex_lock(&open_mutex); | 1296 | mutex_lock(&open_mutex); |
1236 | if (acm->country_codes){ | 1297 | if (acm->country_codes) { |
1237 | device_remove_file(&acm->control->dev, | 1298 | device_remove_file(&acm->control->dev, |
1238 | &dev_attr_wCountryCodes); | 1299 | &dev_attr_wCountryCodes); |
1239 | device_remove_file(&acm->control->dev, | 1300 | device_remove_file(&acm->control->dev, |
@@ -1247,22 +1308,25 @@ static void acm_disconnect(struct usb_interface *intf) | |||
1247 | stop_data_traffic(acm); | 1308 | stop_data_traffic(acm); |
1248 | 1309 | ||
1249 | acm_write_buffers_free(acm); | 1310 | acm_write_buffers_free(acm); |
1250 | usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); | 1311 | usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, |
1312 | acm->ctrl_dma); | ||
1251 | acm_read_buffers_free(acm); | 1313 | acm_read_buffers_free(acm); |
1252 | 1314 | ||
1253 | usb_driver_release_interface(&acm_driver, intf == acm->control ? | 1315 | usb_driver_release_interface(&acm_driver, intf == acm->control ? |
1254 | acm->data : acm->control); | 1316 | acm->data : acm->control); |
1255 | 1317 | ||
1256 | if (!acm->used) { | 1318 | if (acm->port.count == 0) { |
1257 | acm_tty_unregister(acm); | 1319 | acm_tty_unregister(acm); |
1258 | mutex_unlock(&open_mutex); | 1320 | mutex_unlock(&open_mutex); |
1259 | return; | 1321 | return; |
1260 | } | 1322 | } |
1261 | 1323 | ||
1262 | mutex_unlock(&open_mutex); | 1324 | mutex_unlock(&open_mutex); |
1263 | 1325 | tty = tty_port_tty_get(&acm->port); | |
1264 | if (acm->tty) | 1326 | if (tty) { |
1265 | tty_hangup(acm->tty); | 1327 | tty_hangup(tty); |
1328 | tty_kref_put(tty); | ||
1329 | } | ||
1266 | } | 1330 | } |
1267 | 1331 | ||
1268 | #ifdef CONFIG_PM | 1332 | #ifdef CONFIG_PM |
@@ -1297,7 +1361,7 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message) | |||
1297 | */ | 1361 | */ |
1298 | mutex_lock(&acm->mutex); | 1362 | mutex_lock(&acm->mutex); |
1299 | 1363 | ||
1300 | if (acm->used) | 1364 | if (acm->port.count) |
1301 | stop_data_traffic(acm); | 1365 | stop_data_traffic(acm); |
1302 | 1366 | ||
1303 | mutex_unlock(&acm->mutex); | 1367 | mutex_unlock(&acm->mutex); |
@@ -1319,7 +1383,7 @@ static int acm_resume(struct usb_interface *intf) | |||
1319 | return 0; | 1383 | return 0; |
1320 | 1384 | ||
1321 | mutex_lock(&acm->mutex); | 1385 | mutex_lock(&acm->mutex); |
1322 | if (acm->used) { | 1386 | if (acm->port.count) { |
1323 | rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); | 1387 | rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); |
1324 | if (rv < 0) | 1388 | if (rv < 0) |
1325 | goto err_out; | 1389 | goto err_out; |
@@ -1375,6 +1439,9 @@ static struct usb_device_id acm_ids[] = { | |||
1375 | { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */ | 1439 | { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */ |
1376 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | 1440 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
1377 | }, | 1441 | }, |
1442 | { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */ | ||
1443 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | ||
1444 | }, | ||
1378 | { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */ | 1445 | { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */ |
1379 | }, | 1446 | }, |
1380 | { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */ | 1447 | { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */ |
@@ -1395,7 +1462,7 @@ static struct usb_device_id acm_ids[] = { | |||
1395 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1462 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1396 | USB_CDC_ACM_PROTO_AT_GSM) }, | 1463 | USB_CDC_ACM_PROTO_AT_GSM) }, |
1397 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1464 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1398 | USB_CDC_ACM_PROTO_AT_3G ) }, | 1465 | USB_CDC_ACM_PROTO_AT_3G) }, |
1399 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1466 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1400 | USB_CDC_ACM_PROTO_AT_CDMA) }, | 1467 | USB_CDC_ACM_PROTO_AT_CDMA) }, |
1401 | 1468 | ||
@@ -1403,7 +1470,7 @@ static struct usb_device_id acm_ids[] = { | |||
1403 | { } | 1470 | { } |
1404 | }; | 1471 | }; |
1405 | 1472 | ||
1406 | MODULE_DEVICE_TABLE (usb, acm_ids); | 1473 | MODULE_DEVICE_TABLE(usb, acm_ids); |
1407 | 1474 | ||
1408 | static struct usb_driver acm_driver = { | 1475 | static struct usb_driver acm_driver = { |
1409 | .name = "cdc_acm", | 1476 | .name = "cdc_acm", |
@@ -1426,6 +1493,7 @@ static struct usb_driver acm_driver = { | |||
1426 | static const struct tty_operations acm_ops = { | 1493 | static const struct tty_operations acm_ops = { |
1427 | .open = acm_tty_open, | 1494 | .open = acm_tty_open, |
1428 | .close = acm_tty_close, | 1495 | .close = acm_tty_close, |
1496 | .hangup = acm_tty_hangup, | ||
1429 | .write = acm_tty_write, | 1497 | .write = acm_tty_write, |
1430 | .write_room = acm_tty_write_room, | 1498 | .write_room = acm_tty_write_room, |
1431 | .ioctl = acm_tty_ioctl, | 1499 | .ioctl = acm_tty_ioctl, |
@@ -1457,7 +1525,8 @@ static int __init acm_init(void) | |||
1457 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, | 1525 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, |
1458 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | 1526 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
1459 | acm_tty_driver->init_termios = tty_std_termios; | 1527 | acm_tty_driver->init_termios = tty_std_termios; |
1460 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 1528 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | |
1529 | HUPCL | CLOCAL; | ||
1461 | tty_set_operations(acm_tty_driver, &acm_ops); | 1530 | tty_set_operations(acm_tty_driver, &acm_ops); |
1462 | 1531 | ||
1463 | retval = tty_register_driver(acm_tty_driver); | 1532 | retval = tty_register_driver(acm_tty_driver); |
@@ -1489,7 +1558,7 @@ static void __exit acm_exit(void) | |||
1489 | module_init(acm_init); | 1558 | module_init(acm_init); |
1490 | module_exit(acm_exit); | 1559 | module_exit(acm_exit); |
1491 | 1560 | ||
1492 | MODULE_AUTHOR( DRIVER_AUTHOR ); | 1561 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1493 | MODULE_DESCRIPTION( DRIVER_DESC ); | 1562 | MODULE_DESCRIPTION(DRIVER_DESC); |
1494 | MODULE_LICENSE("GPL"); | 1563 | MODULE_LICENSE("GPL"); |
1495 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); | 1564 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); |
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h index 1f95e7aa1b66..4c3856420add 100644 --- a/drivers/usb/class/cdc-acm.h +++ b/drivers/usb/class/cdc-acm.h | |||
@@ -89,8 +89,8 @@ struct acm { | |||
89 | struct usb_device *dev; /* the corresponding usb device */ | 89 | struct usb_device *dev; /* the corresponding usb device */ |
90 | struct usb_interface *control; /* control interface */ | 90 | struct usb_interface *control; /* control interface */ |
91 | struct usb_interface *data; /* data interface */ | 91 | struct usb_interface *data; /* data interface */ |
92 | struct tty_struct *tty; /* the corresponding tty */ | 92 | struct tty_port port; /* our tty port data */ |
93 | struct urb *ctrlurb; /* urbs */ | 93 | struct urb *ctrlurb; /* urbs */ |
94 | u8 *ctrl_buffer; /* buffers of urbs */ | 94 | u8 *ctrl_buffer; /* buffers of urbs */ |
95 | dma_addr_t ctrl_dma; /* dma handles of buffers */ | 95 | dma_addr_t ctrl_dma; /* dma handles of buffers */ |
96 | u8 *country_codes; /* country codes from device */ | 96 | u8 *country_codes; /* country codes from device */ |
@@ -120,7 +120,6 @@ struct acm { | |||
120 | unsigned int ctrlout; /* output control lines (DTR, RTS) */ | 120 | unsigned int ctrlout; /* output control lines (DTR, RTS) */ |
121 | unsigned int writesize; /* max packet size for the output bulk endpoint */ | 121 | unsigned int writesize; /* max packet size for the output bulk endpoint */ |
122 | unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ | 122 | unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ |
123 | unsigned int used; /* someone has this acm's device open */ | ||
124 | unsigned int minor; /* acm minor number */ | 123 | unsigned int minor; /* acm minor number */ |
125 | unsigned char throttle; /* throttled by tty layer */ | 124 | unsigned char throttle; /* throttled by tty layer */ |
126 | unsigned char clocal; /* termios CLOCAL */ | 125 | unsigned char clocal; /* termios CLOCAL */ |
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index 563d57275448..05c913cc3658 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c | |||
@@ -794,7 +794,8 @@ usba_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
794 | if (ep->desc) { | 794 | if (ep->desc) { |
795 | list_add_tail(&req->queue, &ep->queue); | 795 | list_add_tail(&req->queue, &ep->queue); |
796 | 796 | ||
797 | if (ep->is_in || (ep_is_control(ep) | 797 | if ((!ep_is_control(ep) && ep->is_in) || |
798 | (ep_is_control(ep) | ||
798 | && (ep->state == DATA_STAGE_IN | 799 | && (ep->state == DATA_STAGE_IN |
799 | || ep->state == STATUS_STAGE_IN))) | 800 | || ep->state == STATUS_STAGE_IN))) |
800 | usba_ep_writel(ep, CTL_ENB, USBA_TX_PK_RDY); | 801 | usba_ep_writel(ep, CTL_ENB, USBA_TX_PK_RDY); |
@@ -1940,7 +1941,7 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
1940 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); | 1941 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); |
1941 | clk_disable(pclk); | 1942 | clk_disable(pclk); |
1942 | 1943 | ||
1943 | usba_ep = kmalloc(sizeof(struct usba_ep) * pdata->num_ep, | 1944 | usba_ep = kzalloc(sizeof(struct usba_ep) * pdata->num_ep, |
1944 | GFP_KERNEL); | 1945 | GFP_KERNEL); |
1945 | if (!usba_ep) | 1946 | if (!usba_ep) |
1946 | goto err_alloc_ep; | 1947 | goto err_alloc_ep; |
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c index cd07ea3f0c63..15438469f21a 100644 --- a/drivers/usb/host/isp1760-hcd.c +++ b/drivers/usb/host/isp1760-hcd.c | |||
@@ -1658,6 +1658,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | |||
1658 | u32 reg_base, or_reg, skip_reg; | 1658 | u32 reg_base, or_reg, skip_reg; |
1659 | unsigned long flags; | 1659 | unsigned long flags; |
1660 | struct ptd ptd; | 1660 | struct ptd ptd; |
1661 | packet_enqueue *pe; | ||
1661 | 1662 | ||
1662 | switch (usb_pipetype(urb->pipe)) { | 1663 | switch (usb_pipetype(urb->pipe)) { |
1663 | case PIPE_ISOCHRONOUS: | 1664 | case PIPE_ISOCHRONOUS: |
@@ -1669,6 +1670,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | |||
1669 | reg_base = INT_REGS_OFFSET; | 1670 | reg_base = INT_REGS_OFFSET; |
1670 | or_reg = HC_INT_IRQ_MASK_OR_REG; | 1671 | or_reg = HC_INT_IRQ_MASK_OR_REG; |
1671 | skip_reg = HC_INT_PTD_SKIPMAP_REG; | 1672 | skip_reg = HC_INT_PTD_SKIPMAP_REG; |
1673 | pe = enqueue_an_INT_packet; | ||
1672 | break; | 1674 | break; |
1673 | 1675 | ||
1674 | default: | 1676 | default: |
@@ -1676,6 +1678,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | |||
1676 | reg_base = ATL_REGS_OFFSET; | 1678 | reg_base = ATL_REGS_OFFSET; |
1677 | or_reg = HC_ATL_IRQ_MASK_OR_REG; | 1679 | or_reg = HC_ATL_IRQ_MASK_OR_REG; |
1678 | skip_reg = HC_ATL_PTD_SKIPMAP_REG; | 1680 | skip_reg = HC_ATL_PTD_SKIPMAP_REG; |
1681 | pe = enqueue_an_ATL_packet; | ||
1679 | break; | 1682 | break; |
1680 | } | 1683 | } |
1681 | 1684 | ||
@@ -1687,6 +1690,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | |||
1687 | u32 skip_map; | 1690 | u32 skip_map; |
1688 | u32 or_map; | 1691 | u32 or_map; |
1689 | struct isp1760_qtd *qtd; | 1692 | struct isp1760_qtd *qtd; |
1693 | struct isp1760_qh *qh = ints->qh; | ||
1690 | 1694 | ||
1691 | skip_map = isp1760_readl(hcd->regs + skip_reg); | 1695 | skip_map = isp1760_readl(hcd->regs + skip_reg); |
1692 | skip_map |= 1 << i; | 1696 | skip_map |= 1 << i; |
@@ -1699,8 +1703,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | |||
1699 | priv_write_copy(priv, (u32 *)&ptd, hcd->regs + reg_base | 1703 | priv_write_copy(priv, (u32 *)&ptd, hcd->regs + reg_base |
1700 | + i * sizeof(ptd), sizeof(ptd)); | 1704 | + i * sizeof(ptd), sizeof(ptd)); |
1701 | qtd = ints->qtd; | 1705 | qtd = ints->qtd; |
1702 | 1706 | qtd = clean_up_qtdlist(qtd); | |
1703 | clean_up_qtdlist(qtd); | ||
1704 | 1707 | ||
1705 | free_mem(priv, ints->payload); | 1708 | free_mem(priv, ints->payload); |
1706 | 1709 | ||
@@ -1711,7 +1714,24 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | |||
1711 | ints->payload = 0; | 1714 | ints->payload = 0; |
1712 | 1715 | ||
1713 | isp1760_urb_done(priv, urb, status); | 1716 | isp1760_urb_done(priv, urb, status); |
1717 | if (qtd) | ||
1718 | pe(hcd, qh, qtd); | ||
1714 | break; | 1719 | break; |
1720 | |||
1721 | } else if (ints->qtd) { | ||
1722 | struct isp1760_qtd *qtd, *prev_qtd = ints->qtd; | ||
1723 | |||
1724 | for (qtd = ints->qtd->hw_next; qtd; qtd = qtd->hw_next) { | ||
1725 | if (qtd->urb == urb) { | ||
1726 | prev_qtd->hw_next = clean_up_qtdlist(qtd); | ||
1727 | isp1760_urb_done(priv, urb, status); | ||
1728 | break; | ||
1729 | } | ||
1730 | prev_qtd = qtd; | ||
1731 | } | ||
1732 | /* we found the urb before the end of the list */ | ||
1733 | if (qtd) | ||
1734 | break; | ||
1715 | } | 1735 | } |
1716 | ints++; | 1736 | ints++; |
1717 | } | 1737 | } |
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c index b7eacad4d48c..2bfd6dd85b5a 100644 --- a/drivers/usb/serial/belkin_sa.c +++ b/drivers/usb/serial/belkin_sa.c | |||
@@ -93,8 +93,7 @@ static int belkin_sa_startup(struct usb_serial *serial); | |||
93 | static void belkin_sa_shutdown(struct usb_serial *serial); | 93 | static void belkin_sa_shutdown(struct usb_serial *serial); |
94 | static int belkin_sa_open(struct tty_struct *tty, | 94 | static int belkin_sa_open(struct tty_struct *tty, |
95 | struct usb_serial_port *port, struct file *filp); | 95 | struct usb_serial_port *port, struct file *filp); |
96 | static void belkin_sa_close(struct tty_struct *tty, | 96 | static void belkin_sa_close(struct usb_serial_port *port); |
97 | struct usb_serial_port *port, struct file *filp); | ||
98 | static void belkin_sa_read_int_callback(struct urb *urb); | 97 | static void belkin_sa_read_int_callback(struct urb *urb); |
99 | static void belkin_sa_set_termios(struct tty_struct *tty, | 98 | static void belkin_sa_set_termios(struct tty_struct *tty, |
100 | struct usb_serial_port *port, struct ktermios * old); | 99 | struct usb_serial_port *port, struct ktermios * old); |
@@ -244,8 +243,7 @@ exit: | |||
244 | } /* belkin_sa_open */ | 243 | } /* belkin_sa_open */ |
245 | 244 | ||
246 | 245 | ||
247 | static void belkin_sa_close(struct tty_struct *tty, | 246 | static void belkin_sa_close(struct usb_serial_port *port) |
248 | struct usb_serial_port *port, struct file *filp) | ||
249 | { | 247 | { |
250 | dbg("%s port %d", __func__, port->number); | 248 | dbg("%s port %d", __func__, port->number); |
251 | 249 | ||
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c index ab4cc277aa65..2830766f5b39 100644 --- a/drivers/usb/serial/ch341.c +++ b/drivers/usb/serial/ch341.c | |||
@@ -262,32 +262,40 @@ error: kfree(priv); | |||
262 | return r; | 262 | return r; |
263 | } | 263 | } |
264 | 264 | ||
265 | static void ch341_close(struct tty_struct *tty, struct usb_serial_port *port, | 265 | static int ch341_carrier_raised(struct usb_serial_port *port) |
266 | struct file *filp) | 266 | { |
267 | struct ch341_private *priv = usb_get_serial_port_data(port); | ||
268 | if (priv->line_status & CH341_BIT_DCD) | ||
269 | return 1; | ||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | static void ch341_dtr_rts(struct usb_serial_port *port, int on) | ||
267 | { | 274 | { |
268 | struct ch341_private *priv = usb_get_serial_port_data(port); | 275 | struct ch341_private *priv = usb_get_serial_port_data(port); |
269 | unsigned long flags; | 276 | unsigned long flags; |
270 | unsigned int c_cflag; | ||
271 | 277 | ||
272 | dbg("%s - port %d", __func__, port->number); | 278 | dbg("%s - port %d", __func__, port->number); |
279 | /* drop DTR and RTS */ | ||
280 | spin_lock_irqsave(&priv->lock, flags); | ||
281 | if (on) | ||
282 | priv->line_control |= CH341_BIT_RTS | CH341_BIT_DTR; | ||
283 | else | ||
284 | priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR); | ||
285 | spin_unlock_irqrestore(&priv->lock, flags); | ||
286 | ch341_set_handshake(port->serial->dev, priv->line_control); | ||
287 | wake_up_interruptible(&priv->delta_msr_wait); | ||
288 | } | ||
289 | |||
290 | static void ch341_close(struct usb_serial_port *port) | ||
291 | { | ||
292 | dbg("%s - port %d", __func__, port->number); | ||
273 | 293 | ||
274 | /* shutdown our urbs */ | 294 | /* shutdown our urbs */ |
275 | dbg("%s - shutting down urbs", __func__); | 295 | dbg("%s - shutting down urbs", __func__); |
276 | usb_kill_urb(port->write_urb); | 296 | usb_kill_urb(port->write_urb); |
277 | usb_kill_urb(port->read_urb); | 297 | usb_kill_urb(port->read_urb); |
278 | usb_kill_urb(port->interrupt_in_urb); | 298 | usb_kill_urb(port->interrupt_in_urb); |
279 | |||
280 | if (tty) { | ||
281 | c_cflag = tty->termios->c_cflag; | ||
282 | if (c_cflag & HUPCL) { | ||
283 | /* drop DTR and RTS */ | ||
284 | spin_lock_irqsave(&priv->lock, flags); | ||
285 | priv->line_control = 0; | ||
286 | spin_unlock_irqrestore(&priv->lock, flags); | ||
287 | ch341_set_handshake(port->serial->dev, 0); | ||
288 | } | ||
289 | } | ||
290 | wake_up_interruptible(&priv->delta_msr_wait); | ||
291 | } | 299 | } |
292 | 300 | ||
293 | 301 | ||
@@ -302,7 +310,6 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
302 | dbg("ch341_open()"); | 310 | dbg("ch341_open()"); |
303 | 311 | ||
304 | priv->baud_rate = DEFAULT_BAUD_RATE; | 312 | priv->baud_rate = DEFAULT_BAUD_RATE; |
305 | priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR; | ||
306 | 313 | ||
307 | r = ch341_configure(serial->dev, priv); | 314 | r = ch341_configure(serial->dev, priv); |
308 | if (r) | 315 | if (r) |
@@ -322,7 +329,7 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
322 | if (r) { | 329 | if (r) { |
323 | dev_err(&port->dev, "%s - failed submitting interrupt urb," | 330 | dev_err(&port->dev, "%s - failed submitting interrupt urb," |
324 | " error %d\n", __func__, r); | 331 | " error %d\n", __func__, r); |
325 | ch341_close(tty, port, NULL); | 332 | ch341_close(port); |
326 | return -EPROTO; | 333 | return -EPROTO; |
327 | } | 334 | } |
328 | 335 | ||
@@ -343,9 +350,6 @@ static void ch341_set_termios(struct tty_struct *tty, | |||
343 | 350 | ||
344 | dbg("ch341_set_termios()"); | 351 | dbg("ch341_set_termios()"); |
345 | 352 | ||
346 | if (!tty || !tty->termios) | ||
347 | return; | ||
348 | |||
349 | baud_rate = tty_get_baud_rate(tty); | 353 | baud_rate = tty_get_baud_rate(tty); |
350 | 354 | ||
351 | priv->baud_rate = baud_rate; | 355 | priv->baud_rate = baud_rate; |
@@ -568,6 +572,8 @@ static struct usb_serial_driver ch341_device = { | |||
568 | .usb_driver = &ch341_driver, | 572 | .usb_driver = &ch341_driver, |
569 | .num_ports = 1, | 573 | .num_ports = 1, |
570 | .open = ch341_open, | 574 | .open = ch341_open, |
575 | .dtr_rts = ch341_dtr_rts, | ||
576 | .carrier_raised = ch341_carrier_raised, | ||
571 | .close = ch341_close, | 577 | .close = ch341_close, |
572 | .ioctl = ch341_ioctl, | 578 | .ioctl = ch341_ioctl, |
573 | .set_termios = ch341_set_termios, | 579 | .set_termios = ch341_set_termios, |
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c index 19e24045b137..247b61bfb7f4 100644 --- a/drivers/usb/serial/console.c +++ b/drivers/usb/serial/console.c | |||
@@ -169,7 +169,9 @@ static int usb_console_setup(struct console *co, char *options) | |||
169 | kfree(tty); | 169 | kfree(tty); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | /* So we know not to kill the hardware on a hangup on this | |
173 | port. We have also bumped the use count by one so it won't go | ||
174 | idle */ | ||
173 | port->console = 1; | 175 | port->console = 1; |
174 | retval = 0; | 176 | retval = 0; |
175 | 177 | ||
@@ -182,7 +184,7 @@ free_tty: | |||
182 | kfree(tty); | 184 | kfree(tty); |
183 | reset_open_count: | 185 | reset_open_count: |
184 | port->port.count = 0; | 186 | port->port.count = 0; |
185 | goto out; | 187 | goto out; |
186 | } | 188 | } |
187 | 189 | ||
188 | static void usb_console_write(struct console *co, | 190 | static void usb_console_write(struct console *co, |
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index e8d5133ce9c8..16a154d3b2fe 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Silicon Laboratories CP2101/CP2102 USB to RS232 serial adaptor driver | 2 | * Silicon Laboratories CP210x USB to RS232 serial adaptor driver |
3 | * | 3 | * |
4 | * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) | 4 | * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) |
5 | * | 5 | * |
@@ -27,44 +27,46 @@ | |||
27 | /* | 27 | /* |
28 | * Version Information | 28 | * Version Information |
29 | */ | 29 | */ |
30 | #define DRIVER_VERSION "v0.08" | 30 | #define DRIVER_VERSION "v0.09" |
31 | #define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver" | 31 | #define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver" |
32 | 32 | ||
33 | /* | 33 | /* |
34 | * Function Prototypes | 34 | * Function Prototypes |
35 | */ | 35 | */ |
36 | static int cp2101_open(struct tty_struct *, struct usb_serial_port *, | 36 | static int cp210x_open(struct tty_struct *, struct usb_serial_port *, |
37 | struct file *); | 37 | struct file *); |
38 | static void cp2101_cleanup(struct usb_serial_port *); | 38 | static void cp210x_cleanup(struct usb_serial_port *); |
39 | static void cp2101_close(struct tty_struct *, struct usb_serial_port *, | 39 | static void cp210x_close(struct usb_serial_port *); |
40 | struct file*); | 40 | static void cp210x_get_termios(struct tty_struct *, |
41 | static void cp2101_get_termios(struct tty_struct *, | ||
42 | struct usb_serial_port *port); | 41 | struct usb_serial_port *port); |
43 | static void cp2101_get_termios_port(struct usb_serial_port *port, | 42 | static void cp210x_get_termios_port(struct usb_serial_port *port, |
44 | unsigned int *cflagp, unsigned int *baudp); | 43 | unsigned int *cflagp, unsigned int *baudp); |
45 | static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *, | 44 | static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *, |
46 | struct ktermios*); | 45 | struct ktermios*); |
47 | static int cp2101_tiocmget(struct tty_struct *, struct file *); | 46 | static int cp210x_tiocmget(struct tty_struct *, struct file *); |
48 | static int cp2101_tiocmset(struct tty_struct *, struct file *, | 47 | static int cp210x_tiocmset(struct tty_struct *, struct file *, |
49 | unsigned int, unsigned int); | 48 | unsigned int, unsigned int); |
50 | static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *, | 49 | static int cp210x_tiocmset_port(struct usb_serial_port *port, struct file *, |
51 | unsigned int, unsigned int); | 50 | unsigned int, unsigned int); |
52 | static void cp2101_break_ctl(struct tty_struct *, int); | 51 | static void cp210x_break_ctl(struct tty_struct *, int); |
53 | static int cp2101_startup(struct usb_serial *); | 52 | static int cp210x_startup(struct usb_serial *); |
54 | static void cp2101_shutdown(struct usb_serial *); | 53 | static void cp210x_shutdown(struct usb_serial *); |
55 | 54 | ||
56 | static int debug; | 55 | static int debug; |
57 | 56 | ||
58 | static struct usb_device_id id_table [] = { | 57 | static struct usb_device_id id_table [] = { |
59 | { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */ | 58 | { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */ |
60 | { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ | 59 | { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ |
60 | { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */ | ||
61 | { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */ | 61 | { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */ |
62 | { USB_DEVICE(0x08FD, 0x000A) }, /* Digianswer A/S , ZigBee/802.15.4 MAC Device */ | ||
62 | { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */ | 63 | { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */ |
63 | { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */ | 64 | { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */ |
64 | { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */ | 65 | { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */ |
65 | { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ | 66 | { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ |
66 | { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ | 67 | { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ |
67 | { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ | 68 | { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ |
69 | { USB_DEVICE(0x10C4, 0x0F91) }, /* Vstabi */ | ||
68 | { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */ | 70 | { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */ |
69 | { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ | 71 | { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ |
70 | { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */ | 72 | { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */ |
@@ -85,10 +87,12 @@ static struct usb_device_id id_table [] = { | |||
85 | { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ | 87 | { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ |
86 | { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ | 88 | { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ |
87 | { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */ | 89 | { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */ |
90 | { USB_DEVICE(0x10C4, 0x81F2) }, /* C1007 HF band RFID controller */ | ||
88 | { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ | 91 | { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ |
89 | { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */ | 92 | { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */ |
90 | { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demostration module */ | 93 | { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demostration module */ |
91 | { USB_DEVICE(0x10c4, 0x8293) }, /* Telegesys ETRX2USB */ | 94 | { USB_DEVICE(0x10c4, 0x8293) }, /* Telegesys ETRX2USB */ |
95 | { USB_DEVICE(0x10C4, 0x82F9) }, /* Procyon AVS */ | ||
92 | { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */ | 96 | { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */ |
93 | { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */ | 97 | { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */ |
94 | { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */ | 98 | { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */ |
@@ -99,7 +103,9 @@ static struct usb_device_id id_table [] = { | |||
99 | { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */ | 103 | { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */ |
100 | { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */ | 104 | { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */ |
101 | { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */ | 105 | { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */ |
106 | { USB_DEVICE(0x10CE, 0xEA6A) }, /* Silicon Labs MobiData GPRS USB Modem 100EU */ | ||
102 | { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ | 107 | { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ |
108 | { USB_DEVICE(0x1555, 0x0004) }, /* Owen AC4 USB-RS485 Converter */ | ||
103 | { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */ | 109 | { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */ |
104 | { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ | 110 | { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ |
105 | { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ | 111 | { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ |
@@ -108,53 +114,70 @@ static struct usb_device_id id_table [] = { | |||
108 | 114 | ||
109 | MODULE_DEVICE_TABLE(usb, id_table); | 115 | MODULE_DEVICE_TABLE(usb, id_table); |
110 | 116 | ||
111 | static struct usb_driver cp2101_driver = { | 117 | static struct usb_driver cp210x_driver = { |
112 | .name = "cp2101", | 118 | .name = "cp210x", |
113 | .probe = usb_serial_probe, | 119 | .probe = usb_serial_probe, |
114 | .disconnect = usb_serial_disconnect, | 120 | .disconnect = usb_serial_disconnect, |
115 | .id_table = id_table, | 121 | .id_table = id_table, |
116 | .no_dynamic_id = 1, | 122 | .no_dynamic_id = 1, |
117 | }; | 123 | }; |
118 | 124 | ||
119 | static struct usb_serial_driver cp2101_device = { | 125 | static struct usb_serial_driver cp210x_device = { |
120 | .driver = { | 126 | .driver = { |
121 | .owner = THIS_MODULE, | 127 | .owner = THIS_MODULE, |
122 | .name = "cp2101", | 128 | .name = "cp210x", |
123 | }, | 129 | }, |
124 | .usb_driver = &cp2101_driver, | 130 | .usb_driver = &cp210x_driver, |
125 | .id_table = id_table, | 131 | .id_table = id_table, |
126 | .num_ports = 1, | 132 | .num_ports = 1, |
127 | .open = cp2101_open, | 133 | .open = cp210x_open, |
128 | .close = cp2101_close, | 134 | .close = cp210x_close, |
129 | .break_ctl = cp2101_break_ctl, | 135 | .break_ctl = cp210x_break_ctl, |
130 | .set_termios = cp2101_set_termios, | 136 | .set_termios = cp210x_set_termios, |
131 | .tiocmget = cp2101_tiocmget, | 137 | .tiocmget = cp210x_tiocmget, |
132 | .tiocmset = cp2101_tiocmset, | 138 | .tiocmset = cp210x_tiocmset, |
133 | .attach = cp2101_startup, | 139 | .attach = cp210x_startup, |
134 | .shutdown = cp2101_shutdown, | 140 | .shutdown = cp210x_shutdown, |
135 | }; | 141 | }; |
136 | 142 | ||
137 | /* Config request types */ | 143 | /* Config request types */ |
138 | #define REQTYPE_HOST_TO_DEVICE 0x41 | 144 | #define REQTYPE_HOST_TO_DEVICE 0x41 |
139 | #define REQTYPE_DEVICE_TO_HOST 0xc1 | 145 | #define REQTYPE_DEVICE_TO_HOST 0xc1 |
140 | 146 | ||
141 | /* Config SET requests. To GET, add 1 to the request number */ | 147 | /* Config request codes */ |
142 | #define CP2101_UART 0x00 /* Enable / Disable */ | 148 | #define CP210X_IFC_ENABLE 0x00 |
143 | #define CP2101_BAUDRATE 0x01 /* (BAUD_RATE_GEN_FREQ / baudrate) */ | 149 | #define CP210X_SET_BAUDDIV 0x01 |
144 | #define CP2101_BITS 0x03 /* 0x(0)(databits)(parity)(stopbits) */ | 150 | #define CP210X_GET_BAUDDIV 0x02 |
145 | #define CP2101_BREAK 0x05 /* On / Off */ | 151 | #define CP210X_SET_LINE_CTL 0x03 |
146 | #define CP2101_CONTROL 0x07 /* Flow control line states */ | 152 | #define CP210X_GET_LINE_CTL 0x04 |
147 | #define CP2101_MODEMCTL 0x13 /* Modem controls */ | 153 | #define CP210X_SET_BREAK 0x05 |
148 | #define CP2101_CONFIG_6 0x19 /* 6 bytes of config data ??? */ | 154 | #define CP210X_IMM_CHAR 0x06 |
149 | 155 | #define CP210X_SET_MHS 0x07 | |
150 | /* CP2101_UART */ | 156 | #define CP210X_GET_MDMSTS 0x08 |
157 | #define CP210X_SET_XON 0x09 | ||
158 | #define CP210X_SET_XOFF 0x0A | ||
159 | #define CP210X_SET_EVENTMASK 0x0B | ||
160 | #define CP210X_GET_EVENTMASK 0x0C | ||
161 | #define CP210X_SET_CHAR 0x0D | ||
162 | #define CP210X_GET_CHARS 0x0E | ||
163 | #define CP210X_GET_PROPS 0x0F | ||
164 | #define CP210X_GET_COMM_STATUS 0x10 | ||
165 | #define CP210X_RESET 0x11 | ||
166 | #define CP210X_PURGE 0x12 | ||
167 | #define CP210X_SET_FLOW 0x13 | ||
168 | #define CP210X_GET_FLOW 0x14 | ||
169 | #define CP210X_EMBED_EVENTS 0x15 | ||
170 | #define CP210X_GET_EVENTSTATE 0x16 | ||
171 | #define CP210X_SET_CHARS 0x19 | ||
172 | |||
173 | /* CP210X_IFC_ENABLE */ | ||
151 | #define UART_ENABLE 0x0001 | 174 | #define UART_ENABLE 0x0001 |
152 | #define UART_DISABLE 0x0000 | 175 | #define UART_DISABLE 0x0000 |
153 | 176 | ||
154 | /* CP2101_BAUDRATE */ | 177 | /* CP210X_(SET|GET)_BAUDDIV */ |
155 | #define BAUD_RATE_GEN_FREQ 0x384000 | 178 | #define BAUD_RATE_GEN_FREQ 0x384000 |
156 | 179 | ||
157 | /* CP2101_BITS */ | 180 | /* CP210X_(SET|GET)_LINE_CTL */ |
158 | #define BITS_DATA_MASK 0X0f00 | 181 | #define BITS_DATA_MASK 0X0f00 |
159 | #define BITS_DATA_5 0X0500 | 182 | #define BITS_DATA_5 0X0500 |
160 | #define BITS_DATA_6 0X0600 | 183 | #define BITS_DATA_6 0X0600 |
@@ -174,11 +197,11 @@ static struct usb_serial_driver cp2101_device = { | |||
174 | #define BITS_STOP_1_5 0x0001 | 197 | #define BITS_STOP_1_5 0x0001 |
175 | #define BITS_STOP_2 0x0002 | 198 | #define BITS_STOP_2 0x0002 |
176 | 199 | ||
177 | /* CP2101_BREAK */ | 200 | /* CP210X_SET_BREAK */ |
178 | #define BREAK_ON 0x0000 | 201 | #define BREAK_ON 0x0000 |
179 | #define BREAK_OFF 0x0001 | 202 | #define BREAK_OFF 0x0001 |
180 | 203 | ||
181 | /* CP2101_CONTROL */ | 204 | /* CP210X_(SET_MHS|GET_MDMSTS) */ |
182 | #define CONTROL_DTR 0x0001 | 205 | #define CONTROL_DTR 0x0001 |
183 | #define CONTROL_RTS 0x0002 | 206 | #define CONTROL_RTS 0x0002 |
184 | #define CONTROL_CTS 0x0010 | 207 | #define CONTROL_CTS 0x0010 |
@@ -189,13 +212,13 @@ static struct usb_serial_driver cp2101_device = { | |||
189 | #define CONTROL_WRITE_RTS 0x0200 | 212 | #define CONTROL_WRITE_RTS 0x0200 |
190 | 213 | ||
191 | /* | 214 | /* |
192 | * cp2101_get_config | 215 | * cp210x_get_config |
193 | * Reads from the CP2101 configuration registers | 216 | * Reads from the CP210x configuration registers |
194 | * 'size' is specified in bytes. | 217 | * 'size' is specified in bytes. |
195 | * 'data' is a pointer to a pre-allocated array of integers large | 218 | * 'data' is a pointer to a pre-allocated array of integers large |
196 | * enough to hold 'size' bytes (with 4 bytes to each integer) | 219 | * enough to hold 'size' bytes (with 4 bytes to each integer) |
197 | */ | 220 | */ |
198 | static int cp2101_get_config(struct usb_serial_port *port, u8 request, | 221 | static int cp210x_get_config(struct usb_serial_port *port, u8 request, |
199 | unsigned int *data, int size) | 222 | unsigned int *data, int size) |
200 | { | 223 | { |
201 | struct usb_serial *serial = port->serial; | 224 | struct usb_serial *serial = port->serial; |
@@ -211,9 +234,6 @@ static int cp2101_get_config(struct usb_serial_port *port, u8 request, | |||
211 | return -ENOMEM; | 234 | return -ENOMEM; |
212 | } | 235 | } |
213 | 236 | ||
214 | /* For get requests, the request number must be incremented */ | ||
215 | request++; | ||
216 | |||
217 | /* Issue the request, attempting to read 'size' bytes */ | 237 | /* Issue the request, attempting to read 'size' bytes */ |
218 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 238 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
219 | request, REQTYPE_DEVICE_TO_HOST, 0x0000, | 239 | request, REQTYPE_DEVICE_TO_HOST, 0x0000, |
@@ -236,12 +256,12 @@ static int cp2101_get_config(struct usb_serial_port *port, u8 request, | |||
236 | } | 256 | } |
237 | 257 | ||
238 | /* | 258 | /* |
239 | * cp2101_set_config | 259 | * cp210x_set_config |
240 | * Writes to the CP2101 configuration registers | 260 | * Writes to the CP210x configuration registers |
241 | * Values less than 16 bits wide are sent directly | 261 | * Values less than 16 bits wide are sent directly |
242 | * 'size' is specified in bytes. | 262 | * 'size' is specified in bytes. |
243 | */ | 263 | */ |
244 | static int cp2101_set_config(struct usb_serial_port *port, u8 request, | 264 | static int cp210x_set_config(struct usb_serial_port *port, u8 request, |
245 | unsigned int *data, int size) | 265 | unsigned int *data, int size) |
246 | { | 266 | { |
247 | struct usb_serial *serial = port->serial; | 267 | struct usb_serial *serial = port->serial; |
@@ -292,21 +312,21 @@ static int cp2101_set_config(struct usb_serial_port *port, u8 request, | |||
292 | } | 312 | } |
293 | 313 | ||
294 | /* | 314 | /* |
295 | * cp2101_set_config_single | 315 | * cp210x_set_config_single |
296 | * Convenience function for calling cp2101_set_config on single data values | 316 | * Convenience function for calling cp210x_set_config on single data values |
297 | * without requiring an integer pointer | 317 | * without requiring an integer pointer |
298 | */ | 318 | */ |
299 | static inline int cp2101_set_config_single(struct usb_serial_port *port, | 319 | static inline int cp210x_set_config_single(struct usb_serial_port *port, |
300 | u8 request, unsigned int data) | 320 | u8 request, unsigned int data) |
301 | { | 321 | { |
302 | return cp2101_set_config(port, request, &data, 2); | 322 | return cp210x_set_config(port, request, &data, 2); |
303 | } | 323 | } |
304 | 324 | ||
305 | /* | 325 | /* |
306 | * cp2101_quantise_baudrate | 326 | * cp210x_quantise_baudrate |
307 | * Quantises the baud rate as per AN205 Table 1 | 327 | * Quantises the baud rate as per AN205 Table 1 |
308 | */ | 328 | */ |
309 | static unsigned int cp2101_quantise_baudrate(unsigned int baud) { | 329 | static unsigned int cp210x_quantise_baudrate(unsigned int baud) { |
310 | if (baud <= 56) baud = 0; | 330 | if (baud <= 56) baud = 0; |
311 | else if (baud <= 300) baud = 300; | 331 | else if (baud <= 300) baud = 300; |
312 | else if (baud <= 600) baud = 600; | 332 | else if (baud <= 600) baud = 600; |
@@ -343,7 +363,7 @@ static unsigned int cp2101_quantise_baudrate(unsigned int baud) { | |||
343 | return baud; | 363 | return baud; |
344 | } | 364 | } |
345 | 365 | ||
346 | static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port, | 366 | static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port, |
347 | struct file *filp) | 367 | struct file *filp) |
348 | { | 368 | { |
349 | struct usb_serial *serial = port->serial; | 369 | struct usb_serial *serial = port->serial; |
@@ -351,7 +371,7 @@ static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
351 | 371 | ||
352 | dbg("%s - port %d", __func__, port->number); | 372 | dbg("%s - port %d", __func__, port->number); |
353 | 373 | ||
354 | if (cp2101_set_config_single(port, CP2101_UART, UART_ENABLE)) { | 374 | if (cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_ENABLE)) { |
355 | dev_err(&port->dev, "%s - Unable to enable UART\n", | 375 | dev_err(&port->dev, "%s - Unable to enable UART\n", |
356 | __func__); | 376 | __func__); |
357 | return -EPROTO; | 377 | return -EPROTO; |
@@ -373,17 +393,17 @@ static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
373 | } | 393 | } |
374 | 394 | ||
375 | /* Configure the termios structure */ | 395 | /* Configure the termios structure */ |
376 | cp2101_get_termios(tty, port); | 396 | cp210x_get_termios(tty, port); |
377 | 397 | ||
378 | /* Set the DTR and RTS pins low */ | 398 | /* Set the DTR and RTS pins low */ |
379 | cp2101_tiocmset_port(tty ? (struct usb_serial_port *) tty->driver_data | 399 | cp210x_tiocmset_port(tty ? (struct usb_serial_port *) tty->driver_data |
380 | : port, | 400 | : port, |
381 | NULL, TIOCM_DTR | TIOCM_RTS, 0); | 401 | NULL, TIOCM_DTR | TIOCM_RTS, 0); |
382 | 402 | ||
383 | return 0; | 403 | return 0; |
384 | } | 404 | } |
385 | 405 | ||
386 | static void cp2101_cleanup(struct usb_serial_port *port) | 406 | static void cp210x_cleanup(struct usb_serial_port *port) |
387 | { | 407 | { |
388 | struct usb_serial *serial = port->serial; | 408 | struct usb_serial *serial = port->serial; |
389 | 409 | ||
@@ -398,8 +418,7 @@ static void cp2101_cleanup(struct usb_serial_port *port) | |||
398 | } | 418 | } |
399 | } | 419 | } |
400 | 420 | ||
401 | static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port, | 421 | static void cp210x_close(struct usb_serial_port *port) |
402 | struct file *filp) | ||
403 | { | 422 | { |
404 | dbg("%s - port %d", __func__, port->number); | 423 | dbg("%s - port %d", __func__, port->number); |
405 | 424 | ||
@@ -410,23 +429,23 @@ static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port, | |||
410 | 429 | ||
411 | mutex_lock(&port->serial->disc_mutex); | 430 | mutex_lock(&port->serial->disc_mutex); |
412 | if (!port->serial->disconnected) | 431 | if (!port->serial->disconnected) |
413 | cp2101_set_config_single(port, CP2101_UART, UART_DISABLE); | 432 | cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE); |
414 | mutex_unlock(&port->serial->disc_mutex); | 433 | mutex_unlock(&port->serial->disc_mutex); |
415 | } | 434 | } |
416 | 435 | ||
417 | /* | 436 | /* |
418 | * cp2101_get_termios | 437 | * cp210x_get_termios |
419 | * Reads the baud rate, data bits, parity, stop bits and flow control mode | 438 | * Reads the baud rate, data bits, parity, stop bits and flow control mode |
420 | * from the device, corrects any unsupported values, and configures the | 439 | * from the device, corrects any unsupported values, and configures the |
421 | * termios structure to reflect the state of the device | 440 | * termios structure to reflect the state of the device |
422 | */ | 441 | */ |
423 | static void cp2101_get_termios(struct tty_struct *tty, | 442 | static void cp210x_get_termios(struct tty_struct *tty, |
424 | struct usb_serial_port *port) | 443 | struct usb_serial_port *port) |
425 | { | 444 | { |
426 | unsigned int baud; | 445 | unsigned int baud; |
427 | 446 | ||
428 | if (tty) { | 447 | if (tty) { |
429 | cp2101_get_termios_port(tty->driver_data, | 448 | cp210x_get_termios_port(tty->driver_data, |
430 | &tty->termios->c_cflag, &baud); | 449 | &tty->termios->c_cflag, &baud); |
431 | tty_encode_baud_rate(tty, baud, baud); | 450 | tty_encode_baud_rate(tty, baud, baud); |
432 | } | 451 | } |
@@ -434,15 +453,15 @@ static void cp2101_get_termios(struct tty_struct *tty, | |||
434 | else { | 453 | else { |
435 | unsigned int cflag; | 454 | unsigned int cflag; |
436 | cflag = 0; | 455 | cflag = 0; |
437 | cp2101_get_termios_port(port, &cflag, &baud); | 456 | cp210x_get_termios_port(port, &cflag, &baud); |
438 | } | 457 | } |
439 | } | 458 | } |
440 | 459 | ||
441 | /* | 460 | /* |
442 | * cp2101_get_termios_port | 461 | * cp210x_get_termios_port |
443 | * This is the heart of cp2101_get_termios which always uses a &usb_serial_port. | 462 | * This is the heart of cp210x_get_termios which always uses a &usb_serial_port. |
444 | */ | 463 | */ |
445 | static void cp2101_get_termios_port(struct usb_serial_port *port, | 464 | static void cp210x_get_termios_port(struct usb_serial_port *port, |
446 | unsigned int *cflagp, unsigned int *baudp) | 465 | unsigned int *cflagp, unsigned int *baudp) |
447 | { | 466 | { |
448 | unsigned int cflag, modem_ctl[4]; | 467 | unsigned int cflag, modem_ctl[4]; |
@@ -451,17 +470,17 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
451 | 470 | ||
452 | dbg("%s - port %d", __func__, port->number); | 471 | dbg("%s - port %d", __func__, port->number); |
453 | 472 | ||
454 | cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2); | 473 | cp210x_get_config(port, CP210X_GET_BAUDDIV, &baud, 2); |
455 | /* Convert to baudrate */ | 474 | /* Convert to baudrate */ |
456 | if (baud) | 475 | if (baud) |
457 | baud = cp2101_quantise_baudrate((BAUD_RATE_GEN_FREQ + baud/2)/ baud); | 476 | baud = cp210x_quantise_baudrate((BAUD_RATE_GEN_FREQ + baud/2)/ baud); |
458 | 477 | ||
459 | dbg("%s - baud rate = %d", __func__, baud); | 478 | dbg("%s - baud rate = %d", __func__, baud); |
460 | *baudp = baud; | 479 | *baudp = baud; |
461 | 480 | ||
462 | cflag = *cflagp; | 481 | cflag = *cflagp; |
463 | 482 | ||
464 | cp2101_get_config(port, CP2101_BITS, &bits, 2); | 483 | cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); |
465 | cflag &= ~CSIZE; | 484 | cflag &= ~CSIZE; |
466 | switch (bits & BITS_DATA_MASK) { | 485 | switch (bits & BITS_DATA_MASK) { |
467 | case BITS_DATA_5: | 486 | case BITS_DATA_5: |
@@ -486,14 +505,14 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
486 | cflag |= CS8; | 505 | cflag |= CS8; |
487 | bits &= ~BITS_DATA_MASK; | 506 | bits &= ~BITS_DATA_MASK; |
488 | bits |= BITS_DATA_8; | 507 | bits |= BITS_DATA_8; |
489 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 508 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
490 | break; | 509 | break; |
491 | default: | 510 | default: |
492 | dbg("%s - Unknown number of data bits, using 8", __func__); | 511 | dbg("%s - Unknown number of data bits, using 8", __func__); |
493 | cflag |= CS8; | 512 | cflag |= CS8; |
494 | bits &= ~BITS_DATA_MASK; | 513 | bits &= ~BITS_DATA_MASK; |
495 | bits |= BITS_DATA_8; | 514 | bits |= BITS_DATA_8; |
496 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 515 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
497 | break; | 516 | break; |
498 | } | 517 | } |
499 | 518 | ||
@@ -516,20 +535,20 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
516 | __func__); | 535 | __func__); |
517 | cflag &= ~PARENB; | 536 | cflag &= ~PARENB; |
518 | bits &= ~BITS_PARITY_MASK; | 537 | bits &= ~BITS_PARITY_MASK; |
519 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 538 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
520 | break; | 539 | break; |
521 | case BITS_PARITY_SPACE: | 540 | case BITS_PARITY_SPACE: |
522 | dbg("%s - parity = SPACE (not supported, disabling parity)", | 541 | dbg("%s - parity = SPACE (not supported, disabling parity)", |
523 | __func__); | 542 | __func__); |
524 | cflag &= ~PARENB; | 543 | cflag &= ~PARENB; |
525 | bits &= ~BITS_PARITY_MASK; | 544 | bits &= ~BITS_PARITY_MASK; |
526 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 545 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
527 | break; | 546 | break; |
528 | default: | 547 | default: |
529 | dbg("%s - Unknown parity mode, disabling parity", __func__); | 548 | dbg("%s - Unknown parity mode, disabling parity", __func__); |
530 | cflag &= ~PARENB; | 549 | cflag &= ~PARENB; |
531 | bits &= ~BITS_PARITY_MASK; | 550 | bits &= ~BITS_PARITY_MASK; |
532 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 551 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
533 | break; | 552 | break; |
534 | } | 553 | } |
535 | 554 | ||
@@ -542,7 +561,7 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
542 | dbg("%s - stop bits = 1.5 (not supported, using 1 stop bit)", | 561 | dbg("%s - stop bits = 1.5 (not supported, using 1 stop bit)", |
543 | __func__); | 562 | __func__); |
544 | bits &= ~BITS_STOP_MASK; | 563 | bits &= ~BITS_STOP_MASK; |
545 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 564 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
546 | break; | 565 | break; |
547 | case BITS_STOP_2: | 566 | case BITS_STOP_2: |
548 | dbg("%s - stop bits = 2", __func__); | 567 | dbg("%s - stop bits = 2", __func__); |
@@ -552,11 +571,11 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
552 | dbg("%s - Unknown number of stop bits, using 1 stop bit", | 571 | dbg("%s - Unknown number of stop bits, using 1 stop bit", |
553 | __func__); | 572 | __func__); |
554 | bits &= ~BITS_STOP_MASK; | 573 | bits &= ~BITS_STOP_MASK; |
555 | cp2101_set_config(port, CP2101_BITS, &bits, 2); | 574 | cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2); |
556 | break; | 575 | break; |
557 | } | 576 | } |
558 | 577 | ||
559 | cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); | 578 | cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16); |
560 | if (modem_ctl[0] & 0x0008) { | 579 | if (modem_ctl[0] & 0x0008) { |
561 | dbg("%s - flow control = CRTSCTS", __func__); | 580 | dbg("%s - flow control = CRTSCTS", __func__); |
562 | cflag |= CRTSCTS; | 581 | cflag |= CRTSCTS; |
@@ -568,7 +587,7 @@ static void cp2101_get_termios_port(struct usb_serial_port *port, | |||
568 | *cflagp = cflag; | 587 | *cflagp = cflag; |
569 | } | 588 | } |
570 | 589 | ||
571 | static void cp2101_set_termios(struct tty_struct *tty, | 590 | static void cp210x_set_termios(struct tty_struct *tty, |
572 | struct usb_serial_port *port, struct ktermios *old_termios) | 591 | struct usb_serial_port *port, struct ktermios *old_termios) |
573 | { | 592 | { |
574 | unsigned int cflag, old_cflag; | 593 | unsigned int cflag, old_cflag; |
@@ -583,13 +602,13 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
583 | tty->termios->c_cflag &= ~CMSPAR; | 602 | tty->termios->c_cflag &= ~CMSPAR; |
584 | cflag = tty->termios->c_cflag; | 603 | cflag = tty->termios->c_cflag; |
585 | old_cflag = old_termios->c_cflag; | 604 | old_cflag = old_termios->c_cflag; |
586 | baud = cp2101_quantise_baudrate(tty_get_baud_rate(tty)); | 605 | baud = cp210x_quantise_baudrate(tty_get_baud_rate(tty)); |
587 | 606 | ||
588 | /* If the baud rate is to be updated*/ | 607 | /* If the baud rate is to be updated*/ |
589 | if (baud != tty_termios_baud_rate(old_termios) && baud != 0) { | 608 | if (baud != tty_termios_baud_rate(old_termios) && baud != 0) { |
590 | dbg("%s - Setting baud rate to %d baud", __func__, | 609 | dbg("%s - Setting baud rate to %d baud", __func__, |
591 | baud); | 610 | baud); |
592 | if (cp2101_set_config_single(port, CP2101_BAUDRATE, | 611 | if (cp210x_set_config_single(port, CP210X_SET_BAUDDIV, |
593 | ((BAUD_RATE_GEN_FREQ + baud/2) / baud))) { | 612 | ((BAUD_RATE_GEN_FREQ + baud/2) / baud))) { |
594 | dbg("Baud rate requested not supported by device\n"); | 613 | dbg("Baud rate requested not supported by device\n"); |
595 | baud = tty_termios_baud_rate(old_termios); | 614 | baud = tty_termios_baud_rate(old_termios); |
@@ -600,7 +619,7 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
600 | 619 | ||
601 | /* If the number of data bits is to be updated */ | 620 | /* If the number of data bits is to be updated */ |
602 | if ((cflag & CSIZE) != (old_cflag & CSIZE)) { | 621 | if ((cflag & CSIZE) != (old_cflag & CSIZE)) { |
603 | cp2101_get_config(port, CP2101_BITS, &bits, 2); | 622 | cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); |
604 | bits &= ~BITS_DATA_MASK; | 623 | bits &= ~BITS_DATA_MASK; |
605 | switch (cflag & CSIZE) { | 624 | switch (cflag & CSIZE) { |
606 | case CS5: | 625 | case CS5: |
@@ -624,19 +643,19 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
624 | dbg("%s - data bits = 9", __func__); | 643 | dbg("%s - data bits = 9", __func__); |
625 | break;*/ | 644 | break;*/ |
626 | default: | 645 | default: |
627 | dbg("cp2101 driver does not " | 646 | dbg("cp210x driver does not " |
628 | "support the number of bits requested," | 647 | "support the number of bits requested," |
629 | " using 8 bit mode\n"); | 648 | " using 8 bit mode\n"); |
630 | bits |= BITS_DATA_8; | 649 | bits |= BITS_DATA_8; |
631 | break; | 650 | break; |
632 | } | 651 | } |
633 | if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) | 652 | if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) |
634 | dbg("Number of data bits requested " | 653 | dbg("Number of data bits requested " |
635 | "not supported by device\n"); | 654 | "not supported by device\n"); |
636 | } | 655 | } |
637 | 656 | ||
638 | if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) { | 657 | if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) { |
639 | cp2101_get_config(port, CP2101_BITS, &bits, 2); | 658 | cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); |
640 | bits &= ~BITS_PARITY_MASK; | 659 | bits &= ~BITS_PARITY_MASK; |
641 | if (cflag & PARENB) { | 660 | if (cflag & PARENB) { |
642 | if (cflag & PARODD) { | 661 | if (cflag & PARODD) { |
@@ -647,13 +666,13 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
647 | dbg("%s - parity = EVEN", __func__); | 666 | dbg("%s - parity = EVEN", __func__); |
648 | } | 667 | } |
649 | } | 668 | } |
650 | if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) | 669 | if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) |
651 | dbg("Parity mode not supported " | 670 | dbg("Parity mode not supported " |
652 | "by device\n"); | 671 | "by device\n"); |
653 | } | 672 | } |
654 | 673 | ||
655 | if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { | 674 | if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { |
656 | cp2101_get_config(port, CP2101_BITS, &bits, 2); | 675 | cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); |
657 | bits &= ~BITS_STOP_MASK; | 676 | bits &= ~BITS_STOP_MASK; |
658 | if (cflag & CSTOPB) { | 677 | if (cflag & CSTOPB) { |
659 | bits |= BITS_STOP_2; | 678 | bits |= BITS_STOP_2; |
@@ -662,13 +681,13 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
662 | bits |= BITS_STOP_1; | 681 | bits |= BITS_STOP_1; |
663 | dbg("%s - stop bits = 1", __func__); | 682 | dbg("%s - stop bits = 1", __func__); |
664 | } | 683 | } |
665 | if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) | 684 | if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) |
666 | dbg("Number of stop bits requested " | 685 | dbg("Number of stop bits requested " |
667 | "not supported by device\n"); | 686 | "not supported by device\n"); |
668 | } | 687 | } |
669 | 688 | ||
670 | if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { | 689 | if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { |
671 | cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); | 690 | cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16); |
672 | dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", | 691 | dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", |
673 | __func__, modem_ctl[0], modem_ctl[1], | 692 | __func__, modem_ctl[0], modem_ctl[1], |
674 | modem_ctl[2], modem_ctl[3]); | 693 | modem_ctl[2], modem_ctl[3]); |
@@ -688,19 +707,19 @@ static void cp2101_set_termios(struct tty_struct *tty, | |||
688 | dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", | 707 | dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", |
689 | __func__, modem_ctl[0], modem_ctl[1], | 708 | __func__, modem_ctl[0], modem_ctl[1], |
690 | modem_ctl[2], modem_ctl[3]); | 709 | modem_ctl[2], modem_ctl[3]); |
691 | cp2101_set_config(port, CP2101_MODEMCTL, modem_ctl, 16); | 710 | cp210x_set_config(port, CP210X_SET_FLOW, modem_ctl, 16); |
692 | } | 711 | } |
693 | 712 | ||
694 | } | 713 | } |
695 | 714 | ||
696 | static int cp2101_tiocmset (struct tty_struct *tty, struct file *file, | 715 | static int cp210x_tiocmset (struct tty_struct *tty, struct file *file, |
697 | unsigned int set, unsigned int clear) | 716 | unsigned int set, unsigned int clear) |
698 | { | 717 | { |
699 | struct usb_serial_port *port = tty->driver_data; | 718 | struct usb_serial_port *port = tty->driver_data; |
700 | return cp2101_tiocmset_port(port, file, set, clear); | 719 | return cp210x_tiocmset_port(port, file, set, clear); |
701 | } | 720 | } |
702 | 721 | ||
703 | static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *file, | 722 | static int cp210x_tiocmset_port(struct usb_serial_port *port, struct file *file, |
704 | unsigned int set, unsigned int clear) | 723 | unsigned int set, unsigned int clear) |
705 | { | 724 | { |
706 | unsigned int control = 0; | 725 | unsigned int control = 0; |
@@ -726,10 +745,10 @@ static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *file, | |||
726 | 745 | ||
727 | dbg("%s - control = 0x%.4x", __func__, control); | 746 | dbg("%s - control = 0x%.4x", __func__, control); |
728 | 747 | ||
729 | return cp2101_set_config(port, CP2101_CONTROL, &control, 2); | 748 | return cp210x_set_config(port, CP210X_SET_MHS, &control, 2); |
730 | } | 749 | } |
731 | 750 | ||
732 | static int cp2101_tiocmget (struct tty_struct *tty, struct file *file) | 751 | static int cp210x_tiocmget (struct tty_struct *tty, struct file *file) |
733 | { | 752 | { |
734 | struct usb_serial_port *port = tty->driver_data; | 753 | struct usb_serial_port *port = tty->driver_data; |
735 | unsigned int control; | 754 | unsigned int control; |
@@ -737,7 +756,7 @@ static int cp2101_tiocmget (struct tty_struct *tty, struct file *file) | |||
737 | 756 | ||
738 | dbg("%s - port %d", __func__, port->number); | 757 | dbg("%s - port %d", __func__, port->number); |
739 | 758 | ||
740 | cp2101_get_config(port, CP2101_CONTROL, &control, 1); | 759 | cp210x_get_config(port, CP210X_GET_MDMSTS, &control, 1); |
741 | 760 | ||
742 | result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) | 761 | result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) |
743 | |((control & CONTROL_RTS) ? TIOCM_RTS : 0) | 762 | |((control & CONTROL_RTS) ? TIOCM_RTS : 0) |
@@ -751,7 +770,7 @@ static int cp2101_tiocmget (struct tty_struct *tty, struct file *file) | |||
751 | return result; | 770 | return result; |
752 | } | 771 | } |
753 | 772 | ||
754 | static void cp2101_break_ctl (struct tty_struct *tty, int break_state) | 773 | static void cp210x_break_ctl (struct tty_struct *tty, int break_state) |
755 | { | 774 | { |
756 | struct usb_serial_port *port = tty->driver_data; | 775 | struct usb_serial_port *port = tty->driver_data; |
757 | unsigned int state; | 776 | unsigned int state; |
@@ -763,17 +782,17 @@ static void cp2101_break_ctl (struct tty_struct *tty, int break_state) | |||
763 | state = BREAK_ON; | 782 | state = BREAK_ON; |
764 | dbg("%s - turning break %s", __func__, | 783 | dbg("%s - turning break %s", __func__, |
765 | state == BREAK_OFF ? "off" : "on"); | 784 | state == BREAK_OFF ? "off" : "on"); |
766 | cp2101_set_config(port, CP2101_BREAK, &state, 2); | 785 | cp210x_set_config(port, CP210X_SET_BREAK, &state, 2); |
767 | } | 786 | } |
768 | 787 | ||
769 | static int cp2101_startup(struct usb_serial *serial) | 788 | static int cp210x_startup(struct usb_serial *serial) |
770 | { | 789 | { |
771 | /* CP2101 buffers behave strangely unless device is reset */ | 790 | /* cp210x buffers behave strangely unless device is reset */ |
772 | usb_reset_device(serial->dev); | 791 | usb_reset_device(serial->dev); |
773 | return 0; | 792 | return 0; |
774 | } | 793 | } |
775 | 794 | ||
776 | static void cp2101_shutdown(struct usb_serial *serial) | 795 | static void cp210x_shutdown(struct usb_serial *serial) |
777 | { | 796 | { |
778 | int i; | 797 | int i; |
779 | 798 | ||
@@ -781,21 +800,21 @@ static void cp2101_shutdown(struct usb_serial *serial) | |||
781 | 800 | ||
782 | /* Stop reads and writes on all ports */ | 801 | /* Stop reads and writes on all ports */ |
783 | for (i = 0; i < serial->num_ports; ++i) | 802 | for (i = 0; i < serial->num_ports; ++i) |
784 | cp2101_cleanup(serial->port[i]); | 803 | cp210x_cleanup(serial->port[i]); |
785 | } | 804 | } |
786 | 805 | ||
787 | static int __init cp2101_init(void) | 806 | static int __init cp210x_init(void) |
788 | { | 807 | { |
789 | int retval; | 808 | int retval; |
790 | 809 | ||
791 | retval = usb_serial_register(&cp2101_device); | 810 | retval = usb_serial_register(&cp210x_device); |
792 | if (retval) | 811 | if (retval) |
793 | return retval; /* Failed to register */ | 812 | return retval; /* Failed to register */ |
794 | 813 | ||
795 | retval = usb_register(&cp2101_driver); | 814 | retval = usb_register(&cp210x_driver); |
796 | if (retval) { | 815 | if (retval) { |
797 | /* Failed to register */ | 816 | /* Failed to register */ |
798 | usb_serial_deregister(&cp2101_device); | 817 | usb_serial_deregister(&cp210x_device); |
799 | return retval; | 818 | return retval; |
800 | } | 819 | } |
801 | 820 | ||
@@ -805,14 +824,14 @@ static int __init cp2101_init(void) | |||
805 | return 0; | 824 | return 0; |
806 | } | 825 | } |
807 | 826 | ||
808 | static void __exit cp2101_exit(void) | 827 | static void __exit cp210x_exit(void) |
809 | { | 828 | { |
810 | usb_deregister(&cp2101_driver); | 829 | usb_deregister(&cp210x_driver); |
811 | usb_serial_deregister(&cp2101_device); | 830 | usb_serial_deregister(&cp210x_device); |
812 | } | 831 | } |
813 | 832 | ||
814 | module_init(cp2101_init); | 833 | module_init(cp210x_init); |
815 | module_exit(cp2101_exit); | 834 | module_exit(cp210x_exit); |
816 | 835 | ||
817 | MODULE_DESCRIPTION(DRIVER_DESC); | 836 | MODULE_DESCRIPTION(DRIVER_DESC); |
818 | MODULE_VERSION(DRIVER_VERSION); | 837 | MODULE_VERSION(DRIVER_VERSION); |
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c index dd501bb63ed6..933ba913e66c 100644 --- a/drivers/usb/serial/cyberjack.c +++ b/drivers/usb/serial/cyberjack.c | |||
@@ -61,8 +61,7 @@ static int cyberjack_startup(struct usb_serial *serial); | |||
61 | static void cyberjack_shutdown(struct usb_serial *serial); | 61 | static void cyberjack_shutdown(struct usb_serial *serial); |
62 | static int cyberjack_open(struct tty_struct *tty, | 62 | static int cyberjack_open(struct tty_struct *tty, |
63 | struct usb_serial_port *port, struct file *filp); | 63 | struct usb_serial_port *port, struct file *filp); |
64 | static void cyberjack_close(struct tty_struct *tty, | 64 | static void cyberjack_close(struct usb_serial_port *port); |
65 | struct usb_serial_port *port, struct file *filp); | ||
66 | static int cyberjack_write(struct tty_struct *tty, | 65 | static int cyberjack_write(struct tty_struct *tty, |
67 | struct usb_serial_port *port, const unsigned char *buf, int count); | 66 | struct usb_serial_port *port, const unsigned char *buf, int count); |
68 | static int cyberjack_write_room(struct tty_struct *tty); | 67 | static int cyberjack_write_room(struct tty_struct *tty); |
@@ -185,8 +184,7 @@ static int cyberjack_open(struct tty_struct *tty, | |||
185 | return result; | 184 | return result; |
186 | } | 185 | } |
187 | 186 | ||
188 | static void cyberjack_close(struct tty_struct *tty, | 187 | static void cyberjack_close(struct usb_serial_port *port) |
189 | struct usb_serial_port *port, struct file *filp) | ||
190 | { | 188 | { |
191 | dbg("%s - port %d", __func__, port->number); | 189 | dbg("%s - port %d", __func__, port->number); |
192 | 190 | ||
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index e568710b263f..669f93848539 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c | |||
@@ -174,8 +174,8 @@ static int cypress_ca42v2_startup(struct usb_serial *serial); | |||
174 | static void cypress_shutdown(struct usb_serial *serial); | 174 | static void cypress_shutdown(struct usb_serial *serial); |
175 | static int cypress_open(struct tty_struct *tty, | 175 | static int cypress_open(struct tty_struct *tty, |
176 | struct usb_serial_port *port, struct file *filp); | 176 | struct usb_serial_port *port, struct file *filp); |
177 | static void cypress_close(struct tty_struct *tty, | 177 | static void cypress_close(struct usb_serial_port *port); |
178 | struct usb_serial_port *port, struct file *filp); | 178 | static void cypress_dtr_rts(struct usb_serial_port *port, int on); |
179 | static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, | 179 | static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, |
180 | const unsigned char *buf, int count); | 180 | const unsigned char *buf, int count); |
181 | static void cypress_send(struct usb_serial_port *port); | 181 | static void cypress_send(struct usb_serial_port *port); |
@@ -218,6 +218,7 @@ static struct usb_serial_driver cypress_earthmate_device = { | |||
218 | .shutdown = cypress_shutdown, | 218 | .shutdown = cypress_shutdown, |
219 | .open = cypress_open, | 219 | .open = cypress_open, |
220 | .close = cypress_close, | 220 | .close = cypress_close, |
221 | .dtr_rts = cypress_dtr_rts, | ||
221 | .write = cypress_write, | 222 | .write = cypress_write, |
222 | .write_room = cypress_write_room, | 223 | .write_room = cypress_write_room, |
223 | .ioctl = cypress_ioctl, | 224 | .ioctl = cypress_ioctl, |
@@ -244,6 +245,7 @@ static struct usb_serial_driver cypress_hidcom_device = { | |||
244 | .shutdown = cypress_shutdown, | 245 | .shutdown = cypress_shutdown, |
245 | .open = cypress_open, | 246 | .open = cypress_open, |
246 | .close = cypress_close, | 247 | .close = cypress_close, |
248 | .dtr_rts = cypress_dtr_rts, | ||
247 | .write = cypress_write, | 249 | .write = cypress_write, |
248 | .write_room = cypress_write_room, | 250 | .write_room = cypress_write_room, |
249 | .ioctl = cypress_ioctl, | 251 | .ioctl = cypress_ioctl, |
@@ -270,6 +272,7 @@ static struct usb_serial_driver cypress_ca42v2_device = { | |||
270 | .shutdown = cypress_shutdown, | 272 | .shutdown = cypress_shutdown, |
271 | .open = cypress_open, | 273 | .open = cypress_open, |
272 | .close = cypress_close, | 274 | .close = cypress_close, |
275 | .dtr_rts = cypress_dtr_rts, | ||
273 | .write = cypress_write, | 276 | .write = cypress_write, |
274 | .write_room = cypress_write_room, | 277 | .write_room = cypress_write_room, |
275 | .ioctl = cypress_ioctl, | 278 | .ioctl = cypress_ioctl, |
@@ -656,11 +659,7 @@ static int cypress_open(struct tty_struct *tty, | |||
656 | priv->rx_flags = 0; | 659 | priv->rx_flags = 0; |
657 | spin_unlock_irqrestore(&priv->lock, flags); | 660 | spin_unlock_irqrestore(&priv->lock, flags); |
658 | 661 | ||
659 | /* raise both lines and set termios */ | 662 | /* Set termios */ |
660 | spin_lock_irqsave(&priv->lock, flags); | ||
661 | priv->line_control = CONTROL_DTR | CONTROL_RTS; | ||
662 | priv->cmd_ctrl = 1; | ||
663 | spin_unlock_irqrestore(&priv->lock, flags); | ||
664 | result = cypress_write(tty, port, NULL, 0); | 663 | result = cypress_write(tty, port, NULL, 0); |
665 | 664 | ||
666 | if (result) { | 665 | if (result) { |
@@ -694,76 +693,42 @@ static int cypress_open(struct tty_struct *tty, | |||
694 | __func__, result); | 693 | __func__, result); |
695 | cypress_set_dead(port); | 694 | cypress_set_dead(port); |
696 | } | 695 | } |
697 | 696 | port->port.drain_delay = 256; | |
698 | return result; | 697 | return result; |
699 | } /* cypress_open */ | 698 | } /* cypress_open */ |
700 | 699 | ||
700 | static void cypress_dtr_rts(struct usb_serial_port *port, int on) | ||
701 | { | ||
702 | struct cypress_private *priv = usb_get_serial_port_data(port); | ||
703 | /* drop dtr and rts */ | ||
704 | priv = usb_get_serial_port_data(port); | ||
705 | spin_lock_irq(&priv->lock); | ||
706 | if (on == 0) | ||
707 | priv->line_control = 0; | ||
708 | else | ||
709 | priv->line_control = CONTROL_DTR | CONTROL_RTS; | ||
710 | priv->cmd_ctrl = 1; | ||
711 | spin_unlock_irq(&priv->lock); | ||
712 | cypress_write(NULL, port, NULL, 0); | ||
713 | } | ||
701 | 714 | ||
702 | static void cypress_close(struct tty_struct *tty, | 715 | static void cypress_close(struct usb_serial_port *port) |
703 | struct usb_serial_port *port, struct file *filp) | ||
704 | { | 716 | { |
705 | struct cypress_private *priv = usb_get_serial_port_data(port); | 717 | struct cypress_private *priv = usb_get_serial_port_data(port); |
706 | unsigned int c_cflag; | ||
707 | int bps; | ||
708 | long timeout; | ||
709 | wait_queue_t wait; | ||
710 | 718 | ||
711 | dbg("%s - port %d", __func__, port->number); | 719 | dbg("%s - port %d", __func__, port->number); |
712 | 720 | ||
713 | /* wait for data to drain from buffer */ | ||
714 | spin_lock_irq(&priv->lock); | ||
715 | timeout = CYPRESS_CLOSING_WAIT; | ||
716 | init_waitqueue_entry(&wait, current); | ||
717 | add_wait_queue(&tty->write_wait, &wait); | ||
718 | for (;;) { | ||
719 | set_current_state(TASK_INTERRUPTIBLE); | ||
720 | if (cypress_buf_data_avail(priv->buf) == 0 | ||
721 | || timeout == 0 || signal_pending(current) | ||
722 | /* without mutex, allowed due to harmless failure mode */ | ||
723 | || port->serial->disconnected) | ||
724 | break; | ||
725 | spin_unlock_irq(&priv->lock); | ||
726 | timeout = schedule_timeout(timeout); | ||
727 | spin_lock_irq(&priv->lock); | ||
728 | } | ||
729 | set_current_state(TASK_RUNNING); | ||
730 | remove_wait_queue(&tty->write_wait, &wait); | ||
731 | /* clear out any remaining data in the buffer */ | ||
732 | cypress_buf_clear(priv->buf); | ||
733 | spin_unlock_irq(&priv->lock); | ||
734 | |||
735 | /* writing is potentially harmful, lock must be taken */ | 721 | /* writing is potentially harmful, lock must be taken */ |
736 | mutex_lock(&port->serial->disc_mutex); | 722 | mutex_lock(&port->serial->disc_mutex); |
737 | if (port->serial->disconnected) { | 723 | if (port->serial->disconnected) { |
738 | mutex_unlock(&port->serial->disc_mutex); | 724 | mutex_unlock(&port->serial->disc_mutex); |
739 | return; | 725 | return; |
740 | } | 726 | } |
741 | /* wait for characters to drain from device */ | 727 | cypress_buf_clear(priv->buf); |
742 | if (tty) { | ||
743 | bps = tty_get_baud_rate(tty); | ||
744 | if (bps > 1200) | ||
745 | timeout = max((HZ * 2560) / bps, HZ / 10); | ||
746 | else | ||
747 | timeout = 2 * HZ; | ||
748 | schedule_timeout_interruptible(timeout); | ||
749 | } | ||
750 | |||
751 | dbg("%s - stopping urbs", __func__); | 728 | dbg("%s - stopping urbs", __func__); |
752 | usb_kill_urb(port->interrupt_in_urb); | 729 | usb_kill_urb(port->interrupt_in_urb); |
753 | usb_kill_urb(port->interrupt_out_urb); | 730 | usb_kill_urb(port->interrupt_out_urb); |
754 | 731 | ||
755 | if (tty) { | ||
756 | c_cflag = tty->termios->c_cflag; | ||
757 | if (c_cflag & HUPCL) { | ||
758 | /* drop dtr and rts */ | ||
759 | priv = usb_get_serial_port_data(port); | ||
760 | spin_lock_irq(&priv->lock); | ||
761 | priv->line_control = 0; | ||
762 | priv->cmd_ctrl = 1; | ||
763 | spin_unlock_irq(&priv->lock); | ||
764 | cypress_write(tty, port, NULL, 0); | ||
765 | } | ||
766 | } | ||
767 | 732 | ||
768 | if (stats) | 733 | if (stats) |
769 | dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", | 734 | dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", |
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 38ba4ea8b6bf..30f5140eff03 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c | |||
@@ -422,7 +422,6 @@ struct digi_port { | |||
422 | int dp_throttled; | 422 | int dp_throttled; |
423 | int dp_throttle_restart; | 423 | int dp_throttle_restart; |
424 | wait_queue_head_t dp_flush_wait; | 424 | wait_queue_head_t dp_flush_wait; |
425 | int dp_in_close; /* close in progress */ | ||
426 | wait_queue_head_t dp_close_wait; /* wait queue for close */ | 425 | wait_queue_head_t dp_close_wait; /* wait queue for close */ |
427 | struct work_struct dp_wakeup_work; | 426 | struct work_struct dp_wakeup_work; |
428 | struct usb_serial_port *dp_port; | 427 | struct usb_serial_port *dp_port; |
@@ -456,8 +455,9 @@ static int digi_write_room(struct tty_struct *tty); | |||
456 | static int digi_chars_in_buffer(struct tty_struct *tty); | 455 | static int digi_chars_in_buffer(struct tty_struct *tty); |
457 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | 456 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, |
458 | struct file *filp); | 457 | struct file *filp); |
459 | static void digi_close(struct tty_struct *tty, struct usb_serial_port *port, | 458 | static void digi_close(struct usb_serial_port *port); |
460 | struct file *filp); | 459 | static int digi_carrier_raised(struct usb_serial_port *port); |
460 | static void digi_dtr_rts(struct usb_serial_port *port, int on); | ||
461 | static int digi_startup_device(struct usb_serial *serial); | 461 | static int digi_startup_device(struct usb_serial *serial); |
462 | static int digi_startup(struct usb_serial *serial); | 462 | static int digi_startup(struct usb_serial *serial); |
463 | static void digi_shutdown(struct usb_serial *serial); | 463 | static void digi_shutdown(struct usb_serial *serial); |
@@ -510,6 +510,8 @@ static struct usb_serial_driver digi_acceleport_2_device = { | |||
510 | .num_ports = 3, | 510 | .num_ports = 3, |
511 | .open = digi_open, | 511 | .open = digi_open, |
512 | .close = digi_close, | 512 | .close = digi_close, |
513 | .dtr_rts = digi_dtr_rts, | ||
514 | .carrier_raised = digi_carrier_raised, | ||
513 | .write = digi_write, | 515 | .write = digi_write, |
514 | .write_room = digi_write_room, | 516 | .write_room = digi_write_room, |
515 | .write_bulk_callback = digi_write_bulk_callback, | 517 | .write_bulk_callback = digi_write_bulk_callback, |
@@ -1328,6 +1330,19 @@ static int digi_chars_in_buffer(struct tty_struct *tty) | |||
1328 | 1330 | ||
1329 | } | 1331 | } |
1330 | 1332 | ||
1333 | static void digi_dtr_rts(struct usb_serial_port *port, int on) | ||
1334 | { | ||
1335 | /* Adjust DTR and RTS */ | ||
1336 | digi_set_modem_signals(port, on * (TIOCM_DTR|TIOCM_RTS), 1); | ||
1337 | } | ||
1338 | |||
1339 | static int digi_carrier_raised(struct usb_serial_port *port) | ||
1340 | { | ||
1341 | struct digi_port *priv = usb_get_serial_port_data(port); | ||
1342 | if (priv->dp_modem_signals & TIOCM_CD) | ||
1343 | return 1; | ||
1344 | return 0; | ||
1345 | } | ||
1331 | 1346 | ||
1332 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | 1347 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, |
1333 | struct file *filp) | 1348 | struct file *filp) |
@@ -1336,7 +1351,6 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
1336 | unsigned char buf[32]; | 1351 | unsigned char buf[32]; |
1337 | struct digi_port *priv = usb_get_serial_port_data(port); | 1352 | struct digi_port *priv = usb_get_serial_port_data(port); |
1338 | struct ktermios not_termios; | 1353 | struct ktermios not_termios; |
1339 | unsigned long flags = 0; | ||
1340 | 1354 | ||
1341 | dbg("digi_open: TOP: port=%d, open_count=%d", | 1355 | dbg("digi_open: TOP: port=%d, open_count=%d", |
1342 | priv->dp_port_num, port->port.count); | 1356 | priv->dp_port_num, port->port.count); |
@@ -1345,26 +1359,6 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
1345 | if (digi_startup_device(port->serial) != 0) | 1359 | if (digi_startup_device(port->serial) != 0) |
1346 | return -ENXIO; | 1360 | return -ENXIO; |
1347 | 1361 | ||
1348 | spin_lock_irqsave(&priv->dp_port_lock, flags); | ||
1349 | |||
1350 | /* don't wait on a close in progress for non-blocking opens */ | ||
1351 | if (priv->dp_in_close && (filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) { | ||
1352 | spin_unlock_irqrestore(&priv->dp_port_lock, flags); | ||
1353 | return -EAGAIN; | ||
1354 | } | ||
1355 | |||
1356 | /* wait for a close in progress to finish */ | ||
1357 | while (priv->dp_in_close) { | ||
1358 | cond_wait_interruptible_timeout_irqrestore( | ||
1359 | &priv->dp_close_wait, DIGI_RETRY_TIMEOUT, | ||
1360 | &priv->dp_port_lock, flags); | ||
1361 | if (signal_pending(current)) | ||
1362 | return -EINTR; | ||
1363 | spin_lock_irqsave(&priv->dp_port_lock, flags); | ||
1364 | } | ||
1365 | |||
1366 | spin_unlock_irqrestore(&priv->dp_port_lock, flags); | ||
1367 | |||
1368 | /* read modem signals automatically whenever they change */ | 1362 | /* read modem signals automatically whenever they change */ |
1369 | buf[0] = DIGI_CMD_READ_INPUT_SIGNALS; | 1363 | buf[0] = DIGI_CMD_READ_INPUT_SIGNALS; |
1370 | buf[1] = priv->dp_port_num; | 1364 | buf[1] = priv->dp_port_num; |
@@ -1387,16 +1381,11 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
1387 | not_termios.c_iflag = ~tty->termios->c_iflag; | 1381 | not_termios.c_iflag = ~tty->termios->c_iflag; |
1388 | digi_set_termios(tty, port, ¬_termios); | 1382 | digi_set_termios(tty, port, ¬_termios); |
1389 | } | 1383 | } |
1390 | |||
1391 | /* set DTR and RTS */ | ||
1392 | digi_set_modem_signals(port, TIOCM_DTR|TIOCM_RTS, 1); | ||
1393 | |||
1394 | return 0; | 1384 | return 0; |
1395 | } | 1385 | } |
1396 | 1386 | ||
1397 | 1387 | ||
1398 | static void digi_close(struct tty_struct *tty, struct usb_serial_port *port, | 1388 | static void digi_close(struct usb_serial_port *port) |
1399 | struct file *filp) | ||
1400 | { | 1389 | { |
1401 | DEFINE_WAIT(wait); | 1390 | DEFINE_WAIT(wait); |
1402 | int ret; | 1391 | int ret; |
@@ -1411,28 +1400,9 @@ static void digi_close(struct tty_struct *tty, struct usb_serial_port *port, | |||
1411 | if (port->serial->disconnected) | 1400 | if (port->serial->disconnected) |
1412 | goto exit; | 1401 | goto exit; |
1413 | 1402 | ||
1414 | /* do cleanup only after final close on this port */ | ||
1415 | spin_lock_irq(&priv->dp_port_lock); | ||
1416 | priv->dp_in_close = 1; | ||
1417 | spin_unlock_irq(&priv->dp_port_lock); | ||
1418 | |||
1419 | /* tell line discipline to process only XON/XOFF */ | ||
1420 | tty->closing = 1; | ||
1421 | |||
1422 | /* wait for output to drain */ | ||
1423 | if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) | ||
1424 | tty_wait_until_sent(tty, DIGI_CLOSE_TIMEOUT); | ||
1425 | |||
1426 | /* flush driver and line discipline buffers */ | ||
1427 | tty_driver_flush_buffer(tty); | ||
1428 | tty_ldisc_flush(tty); | ||
1429 | |||
1430 | if (port->serial->dev) { | 1403 | if (port->serial->dev) { |
1431 | /* wait for transmit idle */ | 1404 | /* FIXME: Transmit idle belongs in the wait_unti_sent path */ |
1432 | if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) | 1405 | digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT); |
1433 | digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT); | ||
1434 | /* drop DTR and RTS */ | ||
1435 | digi_set_modem_signals(port, 0, 0); | ||
1436 | 1406 | ||
1437 | /* disable input flow control */ | 1407 | /* disable input flow control */ |
1438 | buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL; | 1408 | buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL; |
@@ -1477,11 +1447,9 @@ static void digi_close(struct tty_struct *tty, struct usb_serial_port *port, | |||
1477 | /* shutdown any outstanding bulk writes */ | 1447 | /* shutdown any outstanding bulk writes */ |
1478 | usb_kill_urb(port->write_urb); | 1448 | usb_kill_urb(port->write_urb); |
1479 | } | 1449 | } |
1480 | tty->closing = 0; | ||
1481 | exit: | 1450 | exit: |
1482 | spin_lock_irq(&priv->dp_port_lock); | 1451 | spin_lock_irq(&priv->dp_port_lock); |
1483 | priv->dp_write_urb_in_use = 0; | 1452 | priv->dp_write_urb_in_use = 0; |
1484 | priv->dp_in_close = 0; | ||
1485 | wake_up_interruptible(&priv->dp_close_wait); | 1453 | wake_up_interruptible(&priv->dp_close_wait); |
1486 | spin_unlock_irq(&priv->dp_port_lock); | 1454 | spin_unlock_irq(&priv->dp_port_lock); |
1487 | mutex_unlock(&port->serial->disc_mutex); | 1455 | mutex_unlock(&port->serial->disc_mutex); |
@@ -1560,7 +1528,6 @@ static int digi_startup(struct usb_serial *serial) | |||
1560 | priv->dp_throttled = 0; | 1528 | priv->dp_throttled = 0; |
1561 | priv->dp_throttle_restart = 0; | 1529 | priv->dp_throttle_restart = 0; |
1562 | init_waitqueue_head(&priv->dp_flush_wait); | 1530 | init_waitqueue_head(&priv->dp_flush_wait); |
1563 | priv->dp_in_close = 0; | ||
1564 | init_waitqueue_head(&priv->dp_close_wait); | 1531 | init_waitqueue_head(&priv->dp_close_wait); |
1565 | INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock); | 1532 | INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock); |
1566 | priv->dp_port = serial->port[i]; | 1533 | priv->dp_port = serial->port[i]; |
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c index c709ec474a80..2b141ccb0cd9 100644 --- a/drivers/usb/serial/empeg.c +++ b/drivers/usb/serial/empeg.c | |||
@@ -81,8 +81,7 @@ static int debug; | |||
81 | /* function prototypes for an empeg-car player */ | 81 | /* function prototypes for an empeg-car player */ |
82 | static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port, | 82 | static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port, |
83 | struct file *filp); | 83 | struct file *filp); |
84 | static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port, | 84 | static void empeg_close(struct usb_serial_port *port); |
85 | struct file *filp); | ||
86 | static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port, | 85 | static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port, |
87 | const unsigned char *buf, | 86 | const unsigned char *buf, |
88 | int count); | 87 | int count); |
@@ -181,8 +180,7 @@ static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
181 | } | 180 | } |
182 | 181 | ||
183 | 182 | ||
184 | static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port, | 183 | static void empeg_close(struct usb_serial_port *port) |
185 | struct file *filp) | ||
186 | { | 184 | { |
187 | dbg("%s - port %d", __func__, port->number); | 185 | dbg("%s - port %d", __func__, port->number); |
188 | 186 | ||
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index d9fcdaedf389..683304d60615 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -89,6 +89,7 @@ struct ftdi_private { | |||
89 | int force_rtscts; /* if non-zero, force RTS-CTS to always | 89 | int force_rtscts; /* if non-zero, force RTS-CTS to always |
90 | be enabled */ | 90 | be enabled */ |
91 | 91 | ||
92 | unsigned int latency; /* latency setting in use */ | ||
92 | spinlock_t tx_lock; /* spinlock for transmit state */ | 93 | spinlock_t tx_lock; /* spinlock for transmit state */ |
93 | unsigned long tx_bytes; | 94 | unsigned long tx_bytes; |
94 | unsigned long tx_outstanding_bytes; | 95 | unsigned long tx_outstanding_bytes; |
@@ -719,8 +720,8 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port); | |||
719 | static int ftdi_sio_port_remove(struct usb_serial_port *port); | 720 | static int ftdi_sio_port_remove(struct usb_serial_port *port); |
720 | static int ftdi_open(struct tty_struct *tty, | 721 | static int ftdi_open(struct tty_struct *tty, |
721 | struct usb_serial_port *port, struct file *filp); | 722 | struct usb_serial_port *port, struct file *filp); |
722 | static void ftdi_close(struct tty_struct *tty, | 723 | static void ftdi_close(struct usb_serial_port *port); |
723 | struct usb_serial_port *port, struct file *filp); | 724 | static void ftdi_dtr_rts(struct usb_serial_port *port, int on); |
724 | static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port, | 725 | static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port, |
725 | const unsigned char *buf, int count); | 726 | const unsigned char *buf, int count); |
726 | static int ftdi_write_room(struct tty_struct *tty); | 727 | static int ftdi_write_room(struct tty_struct *tty); |
@@ -758,6 +759,7 @@ static struct usb_serial_driver ftdi_sio_device = { | |||
758 | .port_remove = ftdi_sio_port_remove, | 759 | .port_remove = ftdi_sio_port_remove, |
759 | .open = ftdi_open, | 760 | .open = ftdi_open, |
760 | .close = ftdi_close, | 761 | .close = ftdi_close, |
762 | .dtr_rts = ftdi_dtr_rts, | ||
761 | .throttle = ftdi_throttle, | 763 | .throttle = ftdi_throttle, |
762 | .unthrottle = ftdi_unthrottle, | 764 | .unthrottle = ftdi_unthrottle, |
763 | .write = ftdi_write, | 765 | .write = ftdi_write, |
@@ -1037,7 +1039,54 @@ static int change_speed(struct tty_struct *tty, struct usb_serial_port *port) | |||
1037 | return rv; | 1039 | return rv; |
1038 | } | 1040 | } |
1039 | 1041 | ||
1042 | static int write_latency_timer(struct usb_serial_port *port) | ||
1043 | { | ||
1044 | struct ftdi_private *priv = usb_get_serial_port_data(port); | ||
1045 | struct usb_device *udev = port->serial->dev; | ||
1046 | char buf[1]; | ||
1047 | int rv = 0; | ||
1048 | int l = priv->latency; | ||
1049 | |||
1050 | if (priv->flags & ASYNC_LOW_LATENCY) | ||
1051 | l = 1; | ||
1052 | |||
1053 | dbg("%s: setting latency timer = %i", __func__, l); | ||
1054 | |||
1055 | rv = usb_control_msg(udev, | ||
1056 | usb_sndctrlpipe(udev, 0), | ||
1057 | FTDI_SIO_SET_LATENCY_TIMER_REQUEST, | ||
1058 | FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE, | ||
1059 | l, priv->interface, | ||
1060 | buf, 0, WDR_TIMEOUT); | ||
1061 | |||
1062 | if (rv < 0) | ||
1063 | dev_err(&port->dev, "Unable to write latency timer: %i\n", rv); | ||
1064 | return rv; | ||
1065 | } | ||
1066 | |||
1067 | static int read_latency_timer(struct usb_serial_port *port) | ||
1068 | { | ||
1069 | struct ftdi_private *priv = usb_get_serial_port_data(port); | ||
1070 | struct usb_device *udev = port->serial->dev; | ||
1071 | unsigned short latency = 0; | ||
1072 | int rv = 0; | ||
1073 | |||
1040 | 1074 | ||
1075 | dbg("%s", __func__); | ||
1076 | |||
1077 | rv = usb_control_msg(udev, | ||
1078 | usb_rcvctrlpipe(udev, 0), | ||
1079 | FTDI_SIO_GET_LATENCY_TIMER_REQUEST, | ||
1080 | FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, | ||
1081 | 0, priv->interface, | ||
1082 | (char *) &latency, 1, WDR_TIMEOUT); | ||
1083 | |||
1084 | if (rv < 0) { | ||
1085 | dev_err(&port->dev, "Unable to read latency timer: %i\n", rv); | ||
1086 | return -EIO; | ||
1087 | } | ||
1088 | return latency; | ||
1089 | } | ||
1041 | 1090 | ||
1042 | static int get_serial_info(struct usb_serial_port *port, | 1091 | static int get_serial_info(struct usb_serial_port *port, |
1043 | struct serial_struct __user *retinfo) | 1092 | struct serial_struct __user *retinfo) |
@@ -1097,6 +1146,7 @@ static int set_serial_info(struct tty_struct *tty, | |||
1097 | priv->custom_divisor = new_serial.custom_divisor; | 1146 | priv->custom_divisor = new_serial.custom_divisor; |
1098 | 1147 | ||
1099 | tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; | 1148 | tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
1149 | write_latency_timer(port); | ||
1100 | 1150 | ||
1101 | check_and_exit: | 1151 | check_and_exit: |
1102 | if ((old_priv.flags & ASYNC_SPD_MASK) != | 1152 | if ((old_priv.flags & ASYNC_SPD_MASK) != |
@@ -1192,27 +1242,13 @@ static ssize_t show_latency_timer(struct device *dev, | |||
1192 | { | 1242 | { |
1193 | struct usb_serial_port *port = to_usb_serial_port(dev); | 1243 | struct usb_serial_port *port = to_usb_serial_port(dev); |
1194 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1244 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1195 | struct usb_device *udev = port->serial->dev; | 1245 | if (priv->flags & ASYNC_LOW_LATENCY) |
1196 | unsigned short latency = 0; | 1246 | return sprintf(buf, "1\n"); |
1197 | int rv = 0; | 1247 | else |
1198 | 1248 | return sprintf(buf, "%i\n", priv->latency); | |
1199 | |||
1200 | dbg("%s", __func__); | ||
1201 | |||
1202 | rv = usb_control_msg(udev, | ||
1203 | usb_rcvctrlpipe(udev, 0), | ||
1204 | FTDI_SIO_GET_LATENCY_TIMER_REQUEST, | ||
1205 | FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, | ||
1206 | 0, priv->interface, | ||
1207 | (char *) &latency, 1, WDR_TIMEOUT); | ||
1208 | |||
1209 | if (rv < 0) { | ||
1210 | dev_err(dev, "Unable to read latency timer: %i\n", rv); | ||
1211 | return -EIO; | ||
1212 | } | ||
1213 | return sprintf(buf, "%i\n", latency); | ||
1214 | } | 1249 | } |
1215 | 1250 | ||
1251 | |||
1216 | /* Write a new value of the latency timer, in units of milliseconds. */ | 1252 | /* Write a new value of the latency timer, in units of milliseconds. */ |
1217 | static ssize_t store_latency_timer(struct device *dev, | 1253 | static ssize_t store_latency_timer(struct device *dev, |
1218 | struct device_attribute *attr, const char *valbuf, | 1254 | struct device_attribute *attr, const char *valbuf, |
@@ -1220,25 +1256,13 @@ static ssize_t store_latency_timer(struct device *dev, | |||
1220 | { | 1256 | { |
1221 | struct usb_serial_port *port = to_usb_serial_port(dev); | 1257 | struct usb_serial_port *port = to_usb_serial_port(dev); |
1222 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1258 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1223 | struct usb_device *udev = port->serial->dev; | ||
1224 | char buf[1]; | ||
1225 | int v = simple_strtoul(valbuf, NULL, 10); | 1259 | int v = simple_strtoul(valbuf, NULL, 10); |
1226 | int rv = 0; | 1260 | int rv = 0; |
1227 | 1261 | ||
1228 | dbg("%s: setting latency timer = %i", __func__, v); | 1262 | priv->latency = v; |
1229 | 1263 | rv = write_latency_timer(port); | |
1230 | rv = usb_control_msg(udev, | 1264 | if (rv < 0) |
1231 | usb_sndctrlpipe(udev, 0), | ||
1232 | FTDI_SIO_SET_LATENCY_TIMER_REQUEST, | ||
1233 | FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE, | ||
1234 | v, priv->interface, | ||
1235 | buf, 0, WDR_TIMEOUT); | ||
1236 | |||
1237 | if (rv < 0) { | ||
1238 | dev_err(dev, "Unable to write latency timer: %i\n", rv); | ||
1239 | return -EIO; | 1265 | return -EIO; |
1240 | } | ||
1241 | |||
1242 | return count; | 1266 | return count; |
1243 | } | 1267 | } |
1244 | 1268 | ||
@@ -1392,6 +1416,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port) | |||
1392 | usb_set_serial_port_data(port, priv); | 1416 | usb_set_serial_port_data(port, priv); |
1393 | 1417 | ||
1394 | ftdi_determine_type(port); | 1418 | ftdi_determine_type(port); |
1419 | read_latency_timer(port); | ||
1395 | create_sysfs_attrs(port); | 1420 | create_sysfs_attrs(port); |
1396 | return 0; | 1421 | return 0; |
1397 | } | 1422 | } |
@@ -1514,6 +1539,8 @@ static int ftdi_open(struct tty_struct *tty, | |||
1514 | if (tty) | 1539 | if (tty) |
1515 | tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; | 1540 | tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
1516 | 1541 | ||
1542 | write_latency_timer(port); | ||
1543 | |||
1517 | /* No error checking for this (will get errors later anyway) */ | 1544 | /* No error checking for this (will get errors later anyway) */ |
1518 | /* See ftdi_sio.h for description of what is reset */ | 1545 | /* See ftdi_sio.h for description of what is reset */ |
1519 | usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 1546 | usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
@@ -1529,11 +1556,6 @@ static int ftdi_open(struct tty_struct *tty, | |||
1529 | if (tty) | 1556 | if (tty) |
1530 | ftdi_set_termios(tty, port, tty->termios); | 1557 | ftdi_set_termios(tty, port, tty->termios); |
1531 | 1558 | ||
1532 | /* FIXME: Flow control might be enabled, so it should be checked - | ||
1533 | we have no control of defaults! */ | ||
1534 | /* Turn on RTS and DTR since we are not flow controlling by default */ | ||
1535 | set_mctrl(port, TIOCM_DTR | TIOCM_RTS); | ||
1536 | |||
1537 | /* Not throttled */ | 1559 | /* Not throttled */ |
1538 | spin_lock_irqsave(&priv->rx_lock, flags); | 1560 | spin_lock_irqsave(&priv->rx_lock, flags); |
1539 | priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); | 1561 | priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); |
@@ -1558,6 +1580,30 @@ static int ftdi_open(struct tty_struct *tty, | |||
1558 | } /* ftdi_open */ | 1580 | } /* ftdi_open */ |
1559 | 1581 | ||
1560 | 1582 | ||
1583 | static void ftdi_dtr_rts(struct usb_serial_port *port, int on) | ||
1584 | { | ||
1585 | struct ftdi_private *priv = usb_get_serial_port_data(port); | ||
1586 | char buf[1]; | ||
1587 | |||
1588 | mutex_lock(&port->serial->disc_mutex); | ||
1589 | if (!port->serial->disconnected) { | ||
1590 | /* Disable flow control */ | ||
1591 | if (!on && usb_control_msg(port->serial->dev, | ||
1592 | usb_sndctrlpipe(port->serial->dev, 0), | ||
1593 | FTDI_SIO_SET_FLOW_CTRL_REQUEST, | ||
1594 | FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, | ||
1595 | 0, priv->interface, buf, 0, | ||
1596 | WDR_TIMEOUT) < 0) { | ||
1597 | dev_err(&port->dev, "error from flowcontrol urb\n"); | ||
1598 | } | ||
1599 | /* drop RTS and DTR */ | ||
1600 | if (on) | ||
1601 | set_mctrl(port, TIOCM_DTR | TIOCM_RTS); | ||
1602 | else | ||
1603 | clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); | ||
1604 | } | ||
1605 | mutex_unlock(&port->serial->disc_mutex); | ||
1606 | } | ||
1561 | 1607 | ||
1562 | /* | 1608 | /* |
1563 | * usbserial:__serial_close only calls ftdi_close if the point is open | 1609 | * usbserial:__serial_close only calls ftdi_close if the point is open |
@@ -1567,31 +1613,12 @@ static int ftdi_open(struct tty_struct *tty, | |||
1567 | * | 1613 | * |
1568 | */ | 1614 | */ |
1569 | 1615 | ||
1570 | static void ftdi_close(struct tty_struct *tty, | 1616 | static void ftdi_close(struct usb_serial_port *port) |
1571 | struct usb_serial_port *port, struct file *filp) | ||
1572 | { /* ftdi_close */ | 1617 | { /* ftdi_close */ |
1573 | unsigned int c_cflag = tty->termios->c_cflag; | ||
1574 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1618 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1575 | char buf[1]; | ||
1576 | 1619 | ||
1577 | dbg("%s", __func__); | 1620 | dbg("%s", __func__); |
1578 | 1621 | ||
1579 | mutex_lock(&port->serial->disc_mutex); | ||
1580 | if (c_cflag & HUPCL && !port->serial->disconnected) { | ||
1581 | /* Disable flow control */ | ||
1582 | if (usb_control_msg(port->serial->dev, | ||
1583 | usb_sndctrlpipe(port->serial->dev, 0), | ||
1584 | FTDI_SIO_SET_FLOW_CTRL_REQUEST, | ||
1585 | FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, | ||
1586 | 0, priv->interface, buf, 0, | ||
1587 | WDR_TIMEOUT) < 0) { | ||
1588 | dev_err(&port->dev, "error from flowcontrol urb\n"); | ||
1589 | } | ||
1590 | |||
1591 | /* drop RTS and DTR */ | ||
1592 | clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); | ||
1593 | } /* Note change no line if hupcl is off */ | ||
1594 | mutex_unlock(&port->serial->disc_mutex); | ||
1595 | 1622 | ||
1596 | /* cancel any scheduled reading */ | 1623 | /* cancel any scheduled reading */ |
1597 | cancel_delayed_work_sync(&priv->rx_work); | 1624 | cancel_delayed_work_sync(&priv->rx_work); |
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 586d30ff450b..ee25a3fe3b09 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c | |||
@@ -993,8 +993,7 @@ static int garmin_open(struct tty_struct *tty, | |||
993 | } | 993 | } |
994 | 994 | ||
995 | 995 | ||
996 | static void garmin_close(struct tty_struct *tty, | 996 | static void garmin_close(struct usb_serial_port *port) |
997 | struct usb_serial_port *port, struct file *filp) | ||
998 | { | 997 | { |
999 | struct usb_serial *serial = port->serial; | 998 | struct usb_serial *serial = port->serial; |
1000 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); | 999 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index 4cec9906ccf3..be82ea956720 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c | |||
@@ -184,8 +184,7 @@ int usb_serial_generic_resume(struct usb_serial *serial) | |||
184 | } | 184 | } |
185 | EXPORT_SYMBOL_GPL(usb_serial_generic_resume); | 185 | EXPORT_SYMBOL_GPL(usb_serial_generic_resume); |
186 | 186 | ||
187 | void usb_serial_generic_close(struct tty_struct *tty, | 187 | void usb_serial_generic_close(struct usb_serial_port *port) |
188 | struct usb_serial_port *port, struct file *filp) | ||
189 | { | 188 | { |
190 | dbg("%s - port %d", __func__, port->number); | 189 | dbg("%s - port %d", __func__, port->number); |
191 | generic_cleanup(port); | 190 | generic_cleanup(port); |
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index fb4a73d090f6..53ef5996e33d 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c | |||
@@ -207,8 +207,7 @@ static void edge_bulk_out_cmd_callback(struct urb *urb); | |||
207 | /* function prototypes for the usbserial callbacks */ | 207 | /* function prototypes for the usbserial callbacks */ |
208 | static int edge_open(struct tty_struct *tty, struct usb_serial_port *port, | 208 | static int edge_open(struct tty_struct *tty, struct usb_serial_port *port, |
209 | struct file *filp); | 209 | struct file *filp); |
210 | static void edge_close(struct tty_struct *tty, struct usb_serial_port *port, | 210 | static void edge_close(struct usb_serial_port *port); |
211 | struct file *filp); | ||
212 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, | 211 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, |
213 | const unsigned char *buf, int count); | 212 | const unsigned char *buf, int count); |
214 | static int edge_write_room(struct tty_struct *tty); | 213 | static int edge_write_room(struct tty_struct *tty); |
@@ -965,7 +964,7 @@ static int edge_open(struct tty_struct *tty, | |||
965 | 964 | ||
966 | if (!edge_port->txfifo.fifo) { | 965 | if (!edge_port->txfifo.fifo) { |
967 | dbg("%s - no memory", __func__); | 966 | dbg("%s - no memory", __func__); |
968 | edge_close(tty, port, filp); | 967 | edge_close(port); |
969 | return -ENOMEM; | 968 | return -ENOMEM; |
970 | } | 969 | } |
971 | 970 | ||
@@ -975,7 +974,7 @@ static int edge_open(struct tty_struct *tty, | |||
975 | 974 | ||
976 | if (!edge_port->write_urb) { | 975 | if (!edge_port->write_urb) { |
977 | dbg("%s - no memory", __func__); | 976 | dbg("%s - no memory", __func__); |
978 | edge_close(tty, port, filp); | 977 | edge_close(port); |
979 | return -ENOMEM; | 978 | return -ENOMEM; |
980 | } | 979 | } |
981 | 980 | ||
@@ -1099,8 +1098,7 @@ static void block_until_tx_empty(struct edgeport_port *edge_port) | |||
1099 | * edge_close | 1098 | * edge_close |
1100 | * this function is called by the tty driver when a port is closed | 1099 | * this function is called by the tty driver when a port is closed |
1101 | *****************************************************************************/ | 1100 | *****************************************************************************/ |
1102 | static void edge_close(struct tty_struct *tty, | 1101 | static void edge_close(struct usb_serial_port *port) |
1103 | struct usb_serial_port *port, struct file *filp) | ||
1104 | { | 1102 | { |
1105 | struct edgeport_serial *edge_serial; | 1103 | struct edgeport_serial *edge_serial; |
1106 | struct edgeport_port *edge_port; | 1104 | struct edgeport_port *edge_port; |
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index 513b25e044c1..eabf20eeb370 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c | |||
@@ -2009,8 +2009,7 @@ release_es_lock: | |||
2009 | return status; | 2009 | return status; |
2010 | } | 2010 | } |
2011 | 2011 | ||
2012 | static void edge_close(struct tty_struct *tty, | 2012 | static void edge_close(struct usb_serial_port *port) |
2013 | struct usb_serial_port *port, struct file *filp) | ||
2014 | { | 2013 | { |
2015 | struct edgeport_serial *edge_serial; | 2014 | struct edgeport_serial *edge_serial; |
2016 | struct edgeport_port *edge_port; | 2015 | struct edgeport_port *edge_port; |
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c index cd62825a9ac3..c610a99fa477 100644 --- a/drivers/usb/serial/ipaq.c +++ b/drivers/usb/serial/ipaq.c | |||
@@ -76,8 +76,7 @@ static int initial_wait; | |||
76 | /* Function prototypes for an ipaq */ | 76 | /* Function prototypes for an ipaq */ |
77 | static int ipaq_open(struct tty_struct *tty, | 77 | static int ipaq_open(struct tty_struct *tty, |
78 | struct usb_serial_port *port, struct file *filp); | 78 | struct usb_serial_port *port, struct file *filp); |
79 | static void ipaq_close(struct tty_struct *tty, | 79 | static void ipaq_close(struct usb_serial_port *port); |
80 | struct usb_serial_port *port, struct file *filp); | ||
81 | static int ipaq_calc_num_ports(struct usb_serial *serial); | 80 | static int ipaq_calc_num_ports(struct usb_serial *serial); |
82 | static int ipaq_startup(struct usb_serial *serial); | 81 | static int ipaq_startup(struct usb_serial *serial); |
83 | static void ipaq_shutdown(struct usb_serial *serial); | 82 | static void ipaq_shutdown(struct usb_serial *serial); |
@@ -714,8 +713,7 @@ error: | |||
714 | } | 713 | } |
715 | 714 | ||
716 | 715 | ||
717 | static void ipaq_close(struct tty_struct *tty, | 716 | static void ipaq_close(struct usb_serial_port *port) |
718 | struct usb_serial_port *port, struct file *filp) | ||
719 | { | 717 | { |
720 | struct ipaq_private *priv = usb_get_serial_port_data(port); | 718 | struct ipaq_private *priv = usb_get_serial_port_data(port); |
721 | 719 | ||
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c index da2a2b46644a..29ad038b9c8d 100644 --- a/drivers/usb/serial/ipw.c +++ b/drivers/usb/serial/ipw.c | |||
@@ -302,23 +302,17 @@ static int ipw_open(struct tty_struct *tty, | |||
302 | return 0; | 302 | return 0; |
303 | } | 303 | } |
304 | 304 | ||
305 | static void ipw_close(struct tty_struct *tty, | 305 | static void ipw_dtr_rts(struct usb_serial_port *port, int on) |
306 | struct usb_serial_port *port, struct file *filp) | ||
307 | { | 306 | { |
308 | struct usb_device *dev = port->serial->dev; | 307 | struct usb_device *dev = port->serial->dev; |
309 | int result; | 308 | int result; |
310 | 309 | ||
311 | if (tty_hung_up_p(filp)) { | ||
312 | dbg("%s: tty_hung_up_p ...", __func__); | ||
313 | return; | ||
314 | } | ||
315 | |||
316 | /*--1: drop the dtr */ | 310 | /*--1: drop the dtr */ |
317 | dbg("%s:dropping dtr", __func__); | 311 | dbg("%s:dropping dtr", __func__); |
318 | result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 312 | result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
319 | IPW_SIO_SET_PIN, | 313 | IPW_SIO_SET_PIN, |
320 | USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, | 314 | USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, |
321 | IPW_PIN_CLRDTR, | 315 | on ? IPW_PIN_SETDTR : IPW_PIN_CLRDTR, |
322 | 0, | 316 | 0, |
323 | NULL, | 317 | NULL, |
324 | 0, | 318 | 0, |
@@ -332,7 +326,7 @@ static void ipw_close(struct tty_struct *tty, | |||
332 | result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 326 | result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
333 | IPW_SIO_SET_PIN, USB_TYPE_VENDOR | | 327 | IPW_SIO_SET_PIN, USB_TYPE_VENDOR | |
334 | USB_RECIP_INTERFACE | USB_DIR_OUT, | 328 | USB_RECIP_INTERFACE | USB_DIR_OUT, |
335 | IPW_PIN_CLRRTS, | 329 | on ? IPW_PIN_SETRTS : IPW_PIN_CLRRTS, |
336 | 0, | 330 | 0, |
337 | NULL, | 331 | NULL, |
338 | 0, | 332 | 0, |
@@ -340,7 +334,12 @@ static void ipw_close(struct tty_struct *tty, | |||
340 | if (result < 0) | 334 | if (result < 0) |
341 | dev_err(&port->dev, | 335 | dev_err(&port->dev, |
342 | "dropping rts failed (error = %d)\n", result); | 336 | "dropping rts failed (error = %d)\n", result); |
337 | } | ||
343 | 338 | ||
339 | static void ipw_close(struct usb_serial_port *port) | ||
340 | { | ||
341 | struct usb_device *dev = port->serial->dev; | ||
342 | int result; | ||
344 | 343 | ||
345 | /*--3: purge */ | 344 | /*--3: purge */ |
346 | dbg("%s:sending purge", __func__); | 345 | dbg("%s:sending purge", __func__); |
@@ -461,6 +460,7 @@ static struct usb_serial_driver ipw_device = { | |||
461 | .num_ports = 1, | 460 | .num_ports = 1, |
462 | .open = ipw_open, | 461 | .open = ipw_open, |
463 | .close = ipw_close, | 462 | .close = ipw_close, |
463 | .dtr_rts = ipw_dtr_rts, | ||
464 | .port_probe = ipw_probe, | 464 | .port_probe = ipw_probe, |
465 | .port_remove = ipw_disconnect, | 465 | .port_remove = ipw_disconnect, |
466 | .write = ipw_write, | 466 | .write = ipw_write, |
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 4e2cda93da59..66009b6b763a 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c | |||
@@ -88,8 +88,7 @@ static int xbof = -1; | |||
88 | static int ir_startup (struct usb_serial *serial); | 88 | static int ir_startup (struct usb_serial *serial); |
89 | static int ir_open(struct tty_struct *tty, struct usb_serial_port *port, | 89 | static int ir_open(struct tty_struct *tty, struct usb_serial_port *port, |
90 | struct file *filep); | 90 | struct file *filep); |
91 | static void ir_close(struct tty_struct *tty, struct usb_serial_port *port, | 91 | static void ir_close(struct usb_serial_port *port); |
92 | struct file *filep); | ||
93 | static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, | 92 | static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, |
94 | const unsigned char *buf, int count); | 93 | const unsigned char *buf, int count); |
95 | static void ir_write_bulk_callback (struct urb *urb); | 94 | static void ir_write_bulk_callback (struct urb *urb); |
@@ -346,8 +345,7 @@ static int ir_open(struct tty_struct *tty, | |||
346 | return result; | 345 | return result; |
347 | } | 346 | } |
348 | 347 | ||
349 | static void ir_close(struct tty_struct *tty, | 348 | static void ir_close(struct usb_serial_port *port) |
350 | struct usb_serial_port *port, struct file * filp) | ||
351 | { | 349 | { |
352 | dbg("%s - port %d", __func__, port->number); | 350 | dbg("%s - port %d", __func__, port->number); |
353 | 351 | ||
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c index 4473d442b2aa..76a3cc327bb9 100644 --- a/drivers/usb/serial/iuu_phoenix.c +++ b/drivers/usb/serial/iuu_phoenix.c | |||
@@ -40,7 +40,7 @@ static int debug; | |||
40 | /* | 40 | /* |
41 | * Version Information | 41 | * Version Information |
42 | */ | 42 | */ |
43 | #define DRIVER_VERSION "v0.5" | 43 | #define DRIVER_VERSION "v0.10" |
44 | #define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" | 44 | #define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" |
45 | 45 | ||
46 | static struct usb_device_id id_table[] = { | 46 | static struct usb_device_id id_table[] = { |
@@ -70,7 +70,6 @@ static void read_rxcmd_callback(struct urb *urb); | |||
70 | struct iuu_private { | 70 | struct iuu_private { |
71 | spinlock_t lock; /* store irq state */ | 71 | spinlock_t lock; /* store irq state */ |
72 | wait_queue_head_t delta_msr_wait; | 72 | wait_queue_head_t delta_msr_wait; |
73 | u8 line_control; | ||
74 | u8 line_status; | 73 | u8 line_status; |
75 | u8 termios_initialized; | 74 | u8 termios_initialized; |
76 | int tiostatus; /* store IUART SIGNAL for tiocmget call */ | 75 | int tiostatus; /* store IUART SIGNAL for tiocmget call */ |
@@ -651,32 +650,33 @@ static int iuu_bulk_write(struct usb_serial_port *port) | |||
651 | unsigned long flags; | 650 | unsigned long flags; |
652 | int result; | 651 | int result; |
653 | int i; | 652 | int i; |
653 | int buf_len; | ||
654 | char *buf_ptr = port->write_urb->transfer_buffer; | 654 | char *buf_ptr = port->write_urb->transfer_buffer; |
655 | dbg("%s - enter", __func__); | 655 | dbg("%s - enter", __func__); |
656 | 656 | ||
657 | spin_lock_irqsave(&priv->lock, flags); | ||
657 | *buf_ptr++ = IUU_UART_ESC; | 658 | *buf_ptr++ = IUU_UART_ESC; |
658 | *buf_ptr++ = IUU_UART_TX; | 659 | *buf_ptr++ = IUU_UART_TX; |
659 | *buf_ptr++ = priv->writelen; | 660 | *buf_ptr++ = priv->writelen; |
660 | 661 | ||
661 | memcpy(buf_ptr, priv->writebuf, | 662 | memcpy(buf_ptr, priv->writebuf, priv->writelen); |
662 | priv->writelen); | 663 | buf_len = priv->writelen; |
664 | priv->writelen = 0; | ||
665 | spin_unlock_irqrestore(&priv->lock, flags); | ||
663 | if (debug == 1) { | 666 | if (debug == 1) { |
664 | for (i = 0; i < priv->writelen; i++) | 667 | for (i = 0; i < buf_len; i++) |
665 | sprintf(priv->dbgbuf + i*2 , | 668 | sprintf(priv->dbgbuf + i*2 , |
666 | "%02X", priv->writebuf[i]); | 669 | "%02X", priv->writebuf[i]); |
667 | priv->dbgbuf[priv->writelen+i*2] = 0; | 670 | priv->dbgbuf[buf_len+i*2] = 0; |
668 | dbg("%s - writing %i chars : %s", __func__, | 671 | dbg("%s - writing %i chars : %s", __func__, |
669 | priv->writelen, priv->dbgbuf); | 672 | buf_len, priv->dbgbuf); |
670 | } | 673 | } |
671 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, | 674 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, |
672 | usb_sndbulkpipe(port->serial->dev, | 675 | usb_sndbulkpipe(port->serial->dev, |
673 | port->bulk_out_endpointAddress), | 676 | port->bulk_out_endpointAddress), |
674 | port->write_urb->transfer_buffer, priv->writelen + 3, | 677 | port->write_urb->transfer_buffer, buf_len + 3, |
675 | iuu_rxcmd, port); | 678 | iuu_rxcmd, port); |
676 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | 679 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
677 | spin_lock_irqsave(&priv->lock, flags); | ||
678 | priv->writelen = 0; | ||
679 | spin_unlock_irqrestore(&priv->lock, flags); | ||
680 | usb_serial_port_softint(port); | 680 | usb_serial_port_softint(port); |
681 | return result; | 681 | return result; |
682 | } | 682 | } |
@@ -770,14 +770,10 @@ static int iuu_uart_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
770 | return -ENOMEM; | 770 | return -ENOMEM; |
771 | 771 | ||
772 | spin_lock_irqsave(&priv->lock, flags); | 772 | spin_lock_irqsave(&priv->lock, flags); |
773 | if (priv->writelen > 0) { | 773 | |
774 | /* buffer already filled but not commited */ | ||
775 | spin_unlock_irqrestore(&priv->lock, flags); | ||
776 | return 0; | ||
777 | } | ||
778 | /* fill the buffer */ | 774 | /* fill the buffer */ |
779 | memcpy(priv->writebuf, buf, count); | 775 | memcpy(priv->writebuf + priv->writelen, buf, count); |
780 | priv->writelen = count; | 776 | priv->writelen += count; |
781 | spin_unlock_irqrestore(&priv->lock, flags); | 777 | spin_unlock_irqrestore(&priv->lock, flags); |
782 | 778 | ||
783 | return count; | 779 | return count; |
@@ -819,7 +815,7 @@ static int iuu_uart_on(struct usb_serial_port *port) | |||
819 | buf[0] = IUU_UART_ENABLE; | 815 | buf[0] = IUU_UART_ENABLE; |
820 | buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF); | 816 | buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF); |
821 | buf[2] = (u8) (0x00FF & IUU_BAUD_9600); | 817 | buf[2] = (u8) (0x00FF & IUU_BAUD_9600); |
822 | buf[3] = (u8) (0x0F0 & IUU_TWO_STOP_BITS) | (0x07 & IUU_PARITY_EVEN); | 818 | buf[3] = (u8) (0x0F0 & IUU_ONE_STOP_BIT) | (0x07 & IUU_PARITY_EVEN); |
823 | 819 | ||
824 | status = bulk_immediate(port, buf, 4); | 820 | status = bulk_immediate(port, buf, 4); |
825 | if (status != IUU_OPERATION_OK) { | 821 | if (status != IUU_OPERATION_OK) { |
@@ -946,19 +942,59 @@ static int iuu_uart_baud(struct usb_serial_port *port, u32 baud, | |||
946 | return status; | 942 | return status; |
947 | } | 943 | } |
948 | 944 | ||
949 | static int set_control_lines(struct usb_device *dev, u8 value) | 945 | static void iuu_set_termios(struct tty_struct *tty, |
946 | struct usb_serial_port *port, struct ktermios *old_termios) | ||
950 | { | 947 | { |
951 | return 0; | 948 | const u32 supported_mask = CMSPAR|PARENB|PARODD; |
949 | |||
950 | unsigned int cflag = tty->termios->c_cflag; | ||
951 | int status; | ||
952 | u32 actual; | ||
953 | u32 parity; | ||
954 | int csize = CS7; | ||
955 | int baud = 9600; /* Fixed for the moment */ | ||
956 | u32 newval = cflag & supported_mask; | ||
957 | |||
958 | /* compute the parity parameter */ | ||
959 | parity = 0; | ||
960 | if (cflag & CMSPAR) { /* Using mark space */ | ||
961 | if (cflag & PARODD) | ||
962 | parity |= IUU_PARITY_SPACE; | ||
963 | else | ||
964 | parity |= IUU_PARITY_MARK; | ||
965 | } else if (!(cflag & PARENB)) { | ||
966 | parity |= IUU_PARITY_NONE; | ||
967 | csize = CS8; | ||
968 | } else if (cflag & PARODD) | ||
969 | parity |= IUU_PARITY_ODD; | ||
970 | else | ||
971 | parity |= IUU_PARITY_EVEN; | ||
972 | |||
973 | parity |= (cflag & CSTOPB ? IUU_TWO_STOP_BITS : IUU_ONE_STOP_BIT); | ||
974 | |||
975 | /* set it */ | ||
976 | status = iuu_uart_baud(port, | ||
977 | (clockmode == 2) ? 16457 : 9600 * boost / 100, | ||
978 | &actual, parity); | ||
979 | |||
980 | /* set the termios value to the real one, so the user now what has | ||
981 | * changed. We support few fields so its easies to copy the old hw | ||
982 | * settings back over and then adjust them | ||
983 | */ | ||
984 | if (old_termios) | ||
985 | tty_termios_copy_hw(tty->termios, old_termios); | ||
986 | if (status != 0) /* Set failed - return old bits */ | ||
987 | return; | ||
988 | /* Re-encode speed, parity and csize */ | ||
989 | tty_encode_baud_rate(tty, baud, baud); | ||
990 | tty->termios->c_cflag &= ~(supported_mask|CSIZE); | ||
991 | tty->termios->c_cflag |= newval | csize; | ||
952 | } | 992 | } |
953 | 993 | ||
954 | static void iuu_close(struct tty_struct *tty, | 994 | static void iuu_close(struct usb_serial_port *port) |
955 | struct usb_serial_port *port, struct file *filp) | ||
956 | { | 995 | { |
957 | /* iuu_led (port,255,0,0,0); */ | 996 | /* iuu_led (port,255,0,0,0); */ |
958 | struct usb_serial *serial; | 997 | struct usb_serial *serial; |
959 | struct iuu_private *priv = usb_get_serial_port_data(port); | ||
960 | unsigned long flags; | ||
961 | unsigned int c_cflag; | ||
962 | 998 | ||
963 | serial = port->serial; | 999 | serial = port->serial; |
964 | if (!serial) | 1000 | if (!serial) |
@@ -968,17 +1004,6 @@ static void iuu_close(struct tty_struct *tty, | |||
968 | 1004 | ||
969 | iuu_uart_off(port); | 1005 | iuu_uart_off(port); |
970 | if (serial->dev) { | 1006 | if (serial->dev) { |
971 | if (tty) { | ||
972 | c_cflag = tty->termios->c_cflag; | ||
973 | if (c_cflag & HUPCL) { | ||
974 | /* drop DTR and RTS */ | ||
975 | priv = usb_get_serial_port_data(port); | ||
976 | spin_lock_irqsave(&priv->lock, flags); | ||
977 | priv->line_control = 0; | ||
978 | spin_unlock_irqrestore(&priv->lock, flags); | ||
979 | set_control_lines(port->serial->dev, 0); | ||
980 | } | ||
981 | } | ||
982 | /* free writebuf */ | 1007 | /* free writebuf */ |
983 | /* shutdown our urbs */ | 1008 | /* shutdown our urbs */ |
984 | dbg("%s - shutting down urbs", __func__); | 1009 | dbg("%s - shutting down urbs", __func__); |
@@ -1154,7 +1179,7 @@ static int iuu_open(struct tty_struct *tty, | |||
1154 | if (result) { | 1179 | if (result) { |
1155 | dev_err(&port->dev, "%s - failed submitting read urb," | 1180 | dev_err(&port->dev, "%s - failed submitting read urb," |
1156 | " error %d\n", __func__, result); | 1181 | " error %d\n", __func__, result); |
1157 | iuu_close(tty, port, NULL); | 1182 | iuu_close(port); |
1158 | return -EPROTO; | 1183 | return -EPROTO; |
1159 | } else { | 1184 | } else { |
1160 | dbg("%s - rxcmd OK", __func__); | 1185 | dbg("%s - rxcmd OK", __func__); |
@@ -1175,6 +1200,7 @@ static struct usb_serial_driver iuu_device = { | |||
1175 | .read_bulk_callback = iuu_uart_read_callback, | 1200 | .read_bulk_callback = iuu_uart_read_callback, |
1176 | .tiocmget = iuu_tiocmget, | 1201 | .tiocmget = iuu_tiocmget, |
1177 | .tiocmset = iuu_tiocmset, | 1202 | .tiocmset = iuu_tiocmset, |
1203 | .set_termios = iuu_set_termios, | ||
1178 | .attach = iuu_startup, | 1204 | .attach = iuu_startup, |
1179 | .shutdown = iuu_shutdown, | 1205 | .shutdown = iuu_shutdown, |
1180 | }; | 1206 | }; |
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c index 00daa8f7759a..f1195a98f316 100644 --- a/drivers/usb/serial/keyspan.c +++ b/drivers/usb/serial/keyspan.c | |||
@@ -1298,8 +1298,16 @@ static inline void stop_urb(struct urb *urb) | |||
1298 | usb_kill_urb(urb); | 1298 | usb_kill_urb(urb); |
1299 | } | 1299 | } |
1300 | 1300 | ||
1301 | static void keyspan_close(struct tty_struct *tty, | 1301 | static void keyspan_dtr_rts(struct usb_serial_port *port, int on) |
1302 | struct usb_serial_port *port, struct file *filp) | 1302 | { |
1303 | struct keyspan_port_private *p_priv = usb_get_serial_port_data(port); | ||
1304 | |||
1305 | p_priv->rts_state = on; | ||
1306 | p_priv->dtr_state = on; | ||
1307 | keyspan_send_setup(port, 0); | ||
1308 | } | ||
1309 | |||
1310 | static void keyspan_close(struct usb_serial_port *port) | ||
1303 | { | 1311 | { |
1304 | int i; | 1312 | int i; |
1305 | struct usb_serial *serial = port->serial; | 1313 | struct usb_serial *serial = port->serial; |
@@ -1336,7 +1344,6 @@ static void keyspan_close(struct tty_struct *tty, | |||
1336 | stop_urb(p_priv->out_urbs[i]); | 1344 | stop_urb(p_priv->out_urbs[i]); |
1337 | } | 1345 | } |
1338 | } | 1346 | } |
1339 | tty_port_tty_set(&port->port, NULL); | ||
1340 | } | 1347 | } |
1341 | 1348 | ||
1342 | /* download the firmware to a pre-renumeration device */ | 1349 | /* download the firmware to a pre-renumeration device */ |
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h index 38b4582e0734..0d4569b60768 100644 --- a/drivers/usb/serial/keyspan.h +++ b/drivers/usb/serial/keyspan.h | |||
@@ -38,9 +38,8 @@ | |||
38 | static int keyspan_open (struct tty_struct *tty, | 38 | static int keyspan_open (struct tty_struct *tty, |
39 | struct usb_serial_port *port, | 39 | struct usb_serial_port *port, |
40 | struct file *filp); | 40 | struct file *filp); |
41 | static void keyspan_close (struct tty_struct *tty, | 41 | static void keyspan_close (struct usb_serial_port *port); |
42 | struct usb_serial_port *port, | 42 | static void keyspan_dtr_rts (struct usb_serial_port *port, int on); |
43 | struct file *filp); | ||
44 | static int keyspan_startup (struct usb_serial *serial); | 43 | static int keyspan_startup (struct usb_serial *serial); |
45 | static void keyspan_shutdown (struct usb_serial *serial); | 44 | static void keyspan_shutdown (struct usb_serial *serial); |
46 | static int keyspan_write_room (struct tty_struct *tty); | 45 | static int keyspan_write_room (struct tty_struct *tty); |
@@ -562,6 +561,7 @@ static struct usb_serial_driver keyspan_1port_device = { | |||
562 | .num_ports = 1, | 561 | .num_ports = 1, |
563 | .open = keyspan_open, | 562 | .open = keyspan_open, |
564 | .close = keyspan_close, | 563 | .close = keyspan_close, |
564 | .dtr_rts = keyspan_dtr_rts, | ||
565 | .write = keyspan_write, | 565 | .write = keyspan_write, |
566 | .write_room = keyspan_write_room, | 566 | .write_room = keyspan_write_room, |
567 | .set_termios = keyspan_set_termios, | 567 | .set_termios = keyspan_set_termios, |
@@ -582,6 +582,7 @@ static struct usb_serial_driver keyspan_2port_device = { | |||
582 | .num_ports = 2, | 582 | .num_ports = 2, |
583 | .open = keyspan_open, | 583 | .open = keyspan_open, |
584 | .close = keyspan_close, | 584 | .close = keyspan_close, |
585 | .dtr_rts = keyspan_dtr_rts, | ||
585 | .write = keyspan_write, | 586 | .write = keyspan_write, |
586 | .write_room = keyspan_write_room, | 587 | .write_room = keyspan_write_room, |
587 | .set_termios = keyspan_set_termios, | 588 | .set_termios = keyspan_set_termios, |
@@ -602,6 +603,7 @@ static struct usb_serial_driver keyspan_4port_device = { | |||
602 | .num_ports = 4, | 603 | .num_ports = 4, |
603 | .open = keyspan_open, | 604 | .open = keyspan_open, |
604 | .close = keyspan_close, | 605 | .close = keyspan_close, |
606 | .dtr_rts = keyspan_dtr_rts, | ||
605 | .write = keyspan_write, | 607 | .write = keyspan_write, |
606 | .write_room = keyspan_write_room, | 608 | .write_room = keyspan_write_room, |
607 | .set_termios = keyspan_set_termios, | 609 | .set_termios = keyspan_set_termios, |
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index bf1ae247da66..ab769dbea1b3 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c | |||
@@ -651,6 +651,35 @@ static int keyspan_pda_chars_in_buffer(struct tty_struct *tty) | |||
651 | } | 651 | } |
652 | 652 | ||
653 | 653 | ||
654 | static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on) | ||
655 | { | ||
656 | struct usb_serial *serial = port->serial; | ||
657 | |||
658 | if (serial->dev) { | ||
659 | if (on) | ||
660 | keyspan_pda_set_modem_info(serial, (1<<7) | (1<< 2)); | ||
661 | else | ||
662 | keyspan_pda_set_modem_info(serial, 0); | ||
663 | } | ||
664 | } | ||
665 | |||
666 | static int keyspan_pda_carrier_raised(struct usb_serial_port *port) | ||
667 | { | ||
668 | struct usb_serial *serial = port->serial; | ||
669 | unsigned char modembits; | ||
670 | |||
671 | /* If we can read the modem status and the DCD is low then | ||
672 | carrier is not raised yet */ | ||
673 | if (keyspan_pda_get_modem_info(serial, &modembits) >= 0) { | ||
674 | if (!(modembits & (1>>6))) | ||
675 | return 0; | ||
676 | } | ||
677 | /* Carrier raised, or we failed (eg disconnected) so | ||
678 | progress accordingly */ | ||
679 | return 1; | ||
680 | } | ||
681 | |||
682 | |||
654 | static int keyspan_pda_open(struct tty_struct *tty, | 683 | static int keyspan_pda_open(struct tty_struct *tty, |
655 | struct usb_serial_port *port, struct file *filp) | 684 | struct usb_serial_port *port, struct file *filp) |
656 | { | 685 | { |
@@ -682,13 +711,6 @@ static int keyspan_pda_open(struct tty_struct *tty, | |||
682 | priv->tx_room = room; | 711 | priv->tx_room = room; |
683 | priv->tx_throttled = room ? 0 : 1; | 712 | priv->tx_throttled = room ? 0 : 1; |
684 | 713 | ||
685 | /* the normal serial device seems to always turn on DTR and RTS here, | ||
686 | so do the same */ | ||
687 | if (tty && (tty->termios->c_cflag & CBAUD)) | ||
688 | keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2)); | ||
689 | else | ||
690 | keyspan_pda_set_modem_info(serial, 0); | ||
691 | |||
692 | /*Start reading from the device*/ | 714 | /*Start reading from the device*/ |
693 | port->interrupt_in_urb->dev = serial->dev; | 715 | port->interrupt_in_urb->dev = serial->dev; |
694 | rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | 716 | rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
@@ -700,19 +722,11 @@ static int keyspan_pda_open(struct tty_struct *tty, | |||
700 | error: | 722 | error: |
701 | return rc; | 723 | return rc; |
702 | } | 724 | } |
703 | 725 | static void keyspan_pda_close(struct usb_serial_port *port) | |
704 | |||
705 | static void keyspan_pda_close(struct tty_struct *tty, | ||
706 | struct usb_serial_port *port, struct file *filp) | ||
707 | { | 726 | { |
708 | struct usb_serial *serial = port->serial; | 727 | struct usb_serial *serial = port->serial; |
709 | 728 | ||
710 | if (serial->dev) { | 729 | if (serial->dev) { |
711 | /* the normal serial device seems to always shut | ||
712 | off DTR and RTS now */ | ||
713 | if (tty->termios->c_cflag & HUPCL) | ||
714 | keyspan_pda_set_modem_info(serial, 0); | ||
715 | |||
716 | /* shutdown our bulk reads and writes */ | 730 | /* shutdown our bulk reads and writes */ |
717 | usb_kill_urb(port->write_urb); | 731 | usb_kill_urb(port->write_urb); |
718 | usb_kill_urb(port->interrupt_in_urb); | 732 | usb_kill_urb(port->interrupt_in_urb); |
@@ -839,6 +853,8 @@ static struct usb_serial_driver keyspan_pda_device = { | |||
839 | .usb_driver = &keyspan_pda_driver, | 853 | .usb_driver = &keyspan_pda_driver, |
840 | .id_table = id_table_std, | 854 | .id_table = id_table_std, |
841 | .num_ports = 1, | 855 | .num_ports = 1, |
856 | .dtr_rts = keyspan_pda_dtr_rts, | ||
857 | .carrier_raised = keyspan_pda_carrier_raised, | ||
842 | .open = keyspan_pda_open, | 858 | .open = keyspan_pda_open, |
843 | .close = keyspan_pda_close, | 859 | .close = keyspan_pda_close, |
844 | .write = keyspan_pda_write, | 860 | .write = keyspan_pda_write, |
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index fcd9082f3e7f..fa817c66b3e8 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c | |||
@@ -76,8 +76,7 @@ static int klsi_105_startup(struct usb_serial *serial); | |||
76 | static void klsi_105_shutdown(struct usb_serial *serial); | 76 | static void klsi_105_shutdown(struct usb_serial *serial); |
77 | static int klsi_105_open(struct tty_struct *tty, | 77 | static int klsi_105_open(struct tty_struct *tty, |
78 | struct usb_serial_port *port, struct file *filp); | 78 | struct usb_serial_port *port, struct file *filp); |
79 | static void klsi_105_close(struct tty_struct *tty, | 79 | static void klsi_105_close(struct usb_serial_port *port); |
80 | struct usb_serial_port *port, struct file *filp); | ||
81 | static int klsi_105_write(struct tty_struct *tty, | 80 | static int klsi_105_write(struct tty_struct *tty, |
82 | struct usb_serial_port *port, const unsigned char *buf, int count); | 81 | struct usb_serial_port *port, const unsigned char *buf, int count); |
83 | static void klsi_105_write_bulk_callback(struct urb *urb); | 82 | static void klsi_105_write_bulk_callback(struct urb *urb); |
@@ -447,8 +446,7 @@ exit: | |||
447 | } /* klsi_105_open */ | 446 | } /* klsi_105_open */ |
448 | 447 | ||
449 | 448 | ||
450 | static void klsi_105_close(struct tty_struct *tty, | 449 | static void klsi_105_close(struct usb_serial_port *port) |
451 | struct usb_serial_port *port, struct file *filp) | ||
452 | { | 450 | { |
453 | struct klsi_105_private *priv = usb_get_serial_port_data(port); | 451 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
454 | int rc; | 452 | int rc; |
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c index c148544953b3..6b570498287f 100644 --- a/drivers/usb/serial/kobil_sct.c +++ b/drivers/usb/serial/kobil_sct.c | |||
@@ -72,8 +72,7 @@ static int kobil_startup(struct usb_serial *serial); | |||
72 | static void kobil_shutdown(struct usb_serial *serial); | 72 | static void kobil_shutdown(struct usb_serial *serial); |
73 | static int kobil_open(struct tty_struct *tty, | 73 | static int kobil_open(struct tty_struct *tty, |
74 | struct usb_serial_port *port, struct file *filp); | 74 | struct usb_serial_port *port, struct file *filp); |
75 | static void kobil_close(struct tty_struct *tty, struct usb_serial_port *port, | 75 | static void kobil_close(struct usb_serial_port *port); |
76 | struct file *filp); | ||
77 | static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, | 76 | static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, |
78 | const unsigned char *buf, int count); | 77 | const unsigned char *buf, int count); |
79 | static int kobil_write_room(struct tty_struct *tty); | 78 | static int kobil_write_room(struct tty_struct *tty); |
@@ -209,7 +208,7 @@ static void kobil_shutdown(struct usb_serial *serial) | |||
209 | 208 | ||
210 | for (i = 0; i < serial->num_ports; ++i) { | 209 | for (i = 0; i < serial->num_ports; ++i) { |
211 | while (serial->port[i]->port.count > 0) | 210 | while (serial->port[i]->port.count > 0) |
212 | kobil_close(NULL, serial->port[i], NULL); | 211 | kobil_close(serial->port[i]); |
213 | kfree(usb_get_serial_port_data(serial->port[i])); | 212 | kfree(usb_get_serial_port_data(serial->port[i])); |
214 | usb_set_serial_port_data(serial->port[i], NULL); | 213 | usb_set_serial_port_data(serial->port[i], NULL); |
215 | } | 214 | } |
@@ -346,11 +345,11 @@ static int kobil_open(struct tty_struct *tty, | |||
346 | } | 345 | } |
347 | 346 | ||
348 | 347 | ||
349 | static void kobil_close(struct tty_struct *tty, | 348 | static void kobil_close(struct usb_serial_port *port) |
350 | struct usb_serial_port *port, struct file *filp) | ||
351 | { | 349 | { |
352 | dbg("%s - port %d", __func__, port->number); | 350 | dbg("%s - port %d", __func__, port->number); |
353 | 351 | ||
352 | /* FIXME: Add rts/dtr methods */ | ||
354 | if (port->write_urb) { | 353 | if (port->write_urb) { |
355 | usb_kill_urb(port->write_urb); | 354 | usb_kill_urb(port->write_urb); |
356 | usb_free_urb(port->write_urb); | 355 | usb_free_urb(port->write_urb); |
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c index 82930a7d5093..873795548fc0 100644 --- a/drivers/usb/serial/mct_u232.c +++ b/drivers/usb/serial/mct_u232.c | |||
@@ -95,8 +95,8 @@ static int mct_u232_startup(struct usb_serial *serial); | |||
95 | static void mct_u232_shutdown(struct usb_serial *serial); | 95 | static void mct_u232_shutdown(struct usb_serial *serial); |
96 | static int mct_u232_open(struct tty_struct *tty, | 96 | static int mct_u232_open(struct tty_struct *tty, |
97 | struct usb_serial_port *port, struct file *filp); | 97 | struct usb_serial_port *port, struct file *filp); |
98 | static void mct_u232_close(struct tty_struct *tty, | 98 | static void mct_u232_close(struct usb_serial_port *port); |
99 | struct usb_serial_port *port, struct file *filp); | 99 | static void mct_u232_dtr_rts(struct usb_serial_port *port, int on); |
100 | static void mct_u232_read_int_callback(struct urb *urb); | 100 | static void mct_u232_read_int_callback(struct urb *urb); |
101 | static void mct_u232_set_termios(struct tty_struct *tty, | 101 | static void mct_u232_set_termios(struct tty_struct *tty, |
102 | struct usb_serial_port *port, struct ktermios *old); | 102 | struct usb_serial_port *port, struct ktermios *old); |
@@ -140,6 +140,7 @@ static struct usb_serial_driver mct_u232_device = { | |||
140 | .num_ports = 1, | 140 | .num_ports = 1, |
141 | .open = mct_u232_open, | 141 | .open = mct_u232_open, |
142 | .close = mct_u232_close, | 142 | .close = mct_u232_close, |
143 | .dtr_rts = mct_u232_dtr_rts, | ||
143 | .throttle = mct_u232_throttle, | 144 | .throttle = mct_u232_throttle, |
144 | .unthrottle = mct_u232_unthrottle, | 145 | .unthrottle = mct_u232_unthrottle, |
145 | .read_int_callback = mct_u232_read_int_callback, | 146 | .read_int_callback = mct_u232_read_int_callback, |
@@ -496,29 +497,29 @@ error: | |||
496 | return retval; | 497 | return retval; |
497 | } /* mct_u232_open */ | 498 | } /* mct_u232_open */ |
498 | 499 | ||
499 | 500 | static void mct_u232_dtr_rts(struct usb_serial_port *port, int on) | |
500 | static void mct_u232_close(struct tty_struct *tty, | ||
501 | struct usb_serial_port *port, struct file *filp) | ||
502 | { | 501 | { |
503 | unsigned int c_cflag; | ||
504 | unsigned int control_state; | 502 | unsigned int control_state; |
505 | struct mct_u232_private *priv = usb_get_serial_port_data(port); | 503 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
506 | dbg("%s port %d", __func__, port->number); | ||
507 | 504 | ||
508 | if (tty) { | 505 | mutex_lock(&port->serial->disc_mutex); |
509 | c_cflag = tty->termios->c_cflag; | 506 | if (!port->serial->disconnected) { |
510 | mutex_lock(&port->serial->disc_mutex); | 507 | /* drop DTR and RTS */ |
511 | if (c_cflag & HUPCL && !port->serial->disconnected) { | 508 | spin_lock_irq(&priv->lock); |
512 | /* drop DTR and RTS */ | 509 | if (on) |
513 | spin_lock_irq(&priv->lock); | 510 | priv->control_state |= TIOCM_DTR | TIOCM_RTS; |
511 | else | ||
514 | priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); | 512 | priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); |
515 | control_state = priv->control_state; | 513 | control_state = priv->control_state; |
516 | spin_unlock_irq(&priv->lock); | 514 | spin_unlock_irq(&priv->lock); |
517 | mct_u232_set_modem_ctrl(port->serial, control_state); | 515 | mct_u232_set_modem_ctrl(port->serial, control_state); |
518 | } | ||
519 | mutex_unlock(&port->serial->disc_mutex); | ||
520 | } | 516 | } |
517 | mutex_unlock(&port->serial->disc_mutex); | ||
518 | } | ||
521 | 519 | ||
520 | static void mct_u232_close(struct usb_serial_port *port) | ||
521 | { | ||
522 | dbg("%s port %d", __func__, port->number); | ||
522 | 523 | ||
523 | if (port->serial->dev) { | 524 | if (port->serial->dev) { |
524 | /* shutdown our urbs */ | 525 | /* shutdown our urbs */ |
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index 24e3b5d4b4d4..9e1a013ee7f6 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c | |||
@@ -533,8 +533,7 @@ static int mos7720_chars_in_buffer(struct tty_struct *tty) | |||
533 | return chars; | 533 | return chars; |
534 | } | 534 | } |
535 | 535 | ||
536 | static void mos7720_close(struct tty_struct *tty, | 536 | static void mos7720_close(struct usb_serial_port *port) |
537 | struct usb_serial_port *port, struct file *filp) | ||
538 | { | 537 | { |
539 | struct usb_serial *serial; | 538 | struct usb_serial *serial; |
540 | struct moschip_port *mos7720_port; | 539 | struct moschip_port *mos7720_port; |
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 84fb1dcd30dc..10b78a37214f 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c | |||
@@ -1135,54 +1135,12 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty) | |||
1135 | 1135 | ||
1136 | } | 1136 | } |
1137 | 1137 | ||
1138 | /************************************************************************ | ||
1139 | * | ||
1140 | * mos7840_block_until_tx_empty | ||
1141 | * | ||
1142 | * This function will block the close until one of the following: | ||
1143 | * 1. TX count are 0 | ||
1144 | * 2. The mos7840 has stopped | ||
1145 | * 3. A timeout of 3 seconds without activity has expired | ||
1146 | * | ||
1147 | ************************************************************************/ | ||
1148 | static void mos7840_block_until_tx_empty(struct tty_struct *tty, | ||
1149 | struct moschip_port *mos7840_port) | ||
1150 | { | ||
1151 | int timeout = HZ / 10; | ||
1152 | int wait = 30; | ||
1153 | int count; | ||
1154 | |||
1155 | while (1) { | ||
1156 | |||
1157 | count = mos7840_chars_in_buffer(tty); | ||
1158 | |||
1159 | /* Check for Buffer status */ | ||
1160 | if (count <= 0) | ||
1161 | return; | ||
1162 | |||
1163 | /* Block the thread for a while */ | ||
1164 | interruptible_sleep_on_timeout(&mos7840_port->wait_chase, | ||
1165 | timeout); | ||
1166 | |||
1167 | /* No activity.. count down section */ | ||
1168 | wait--; | ||
1169 | if (wait == 0) { | ||
1170 | dbg("%s - TIMEOUT", __func__); | ||
1171 | return; | ||
1172 | } else { | ||
1173 | /* Reset timeout value back to seconds */ | ||
1174 | wait = 30; | ||
1175 | } | ||
1176 | } | ||
1177 | } | ||
1178 | |||
1179 | /***************************************************************************** | 1138 | /***************************************************************************** |
1180 | * mos7840_close | 1139 | * mos7840_close |
1181 | * this function is called by the tty driver when a port is closed | 1140 | * this function is called by the tty driver when a port is closed |
1182 | *****************************************************************************/ | 1141 | *****************************************************************************/ |
1183 | 1142 | ||
1184 | static void mos7840_close(struct tty_struct *tty, | 1143 | static void mos7840_close(struct usb_serial_port *port) |
1185 | struct usb_serial_port *port, struct file *filp) | ||
1186 | { | 1144 | { |
1187 | struct usb_serial *serial; | 1145 | struct usb_serial *serial; |
1188 | struct moschip_port *mos7840_port; | 1146 | struct moschip_port *mos7840_port; |
@@ -1223,10 +1181,6 @@ static void mos7840_close(struct tty_struct *tty, | |||
1223 | } | 1181 | } |
1224 | } | 1182 | } |
1225 | 1183 | ||
1226 | if (serial->dev) | ||
1227 | /* flush and block until tx is empty */ | ||
1228 | mos7840_block_until_tx_empty(tty, mos7840_port); | ||
1229 | |||
1230 | /* While closing port, shutdown all bulk read, write * | 1184 | /* While closing port, shutdown all bulk read, write * |
1231 | * and interrupt read if they exists */ | 1185 | * and interrupt read if they exists */ |
1232 | if (serial->dev) { | 1186 | if (serial->dev) { |
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c index bcdcbb822705..f5f3751a888c 100644 --- a/drivers/usb/serial/navman.c +++ b/drivers/usb/serial/navman.c | |||
@@ -98,8 +98,7 @@ static int navman_open(struct tty_struct *tty, | |||
98 | return result; | 98 | return result; |
99 | } | 99 | } |
100 | 100 | ||
101 | static void navman_close(struct tty_struct *tty, | 101 | static void navman_close(struct usb_serial_port *port) |
102 | struct usb_serial_port *port, struct file *filp) | ||
103 | { | 102 | { |
104 | dbg("%s - port %d", __func__, port->number); | 103 | dbg("%s - port %d", __func__, port->number); |
105 | 104 | ||
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c index df6539712726..1104617334f5 100644 --- a/drivers/usb/serial/omninet.c +++ b/drivers/usb/serial/omninet.c | |||
@@ -66,8 +66,7 @@ static int debug; | |||
66 | /* function prototypes */ | 66 | /* function prototypes */ |
67 | static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port, | 67 | static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port, |
68 | struct file *filp); | 68 | struct file *filp); |
69 | static void omninet_close(struct tty_struct *tty, struct usb_serial_port *port, | 69 | static void omninet_close(struct usb_serial_port *port); |
70 | struct file *filp); | ||
71 | static void omninet_read_bulk_callback(struct urb *urb); | 70 | static void omninet_read_bulk_callback(struct urb *urb); |
72 | static void omninet_write_bulk_callback(struct urb *urb); | 71 | static void omninet_write_bulk_callback(struct urb *urb); |
73 | static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, | 72 | static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, |
@@ -189,8 +188,7 @@ static int omninet_open(struct tty_struct *tty, | |||
189 | return result; | 188 | return result; |
190 | } | 189 | } |
191 | 190 | ||
192 | static void omninet_close(struct tty_struct *tty, | 191 | static void omninet_close(struct usb_serial_port *port) |
193 | struct usb_serial_port *port, struct file *filp) | ||
194 | { | 192 | { |
195 | dbg("%s - port %d", __func__, port->number); | 193 | dbg("%s - port %d", __func__, port->number); |
196 | usb_kill_urb(port->read_urb); | 194 | usb_kill_urb(port->read_urb); |
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c index b500ad10b758..c20480aa9755 100644 --- a/drivers/usb/serial/opticon.c +++ b/drivers/usb/serial/opticon.c | |||
@@ -173,8 +173,7 @@ static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
173 | return result; | 173 | return result; |
174 | } | 174 | } |
175 | 175 | ||
176 | static void opticon_close(struct tty_struct *tty, struct usb_serial_port *port, | 176 | static void opticon_close(struct usb_serial_port *port) |
177 | struct file *filp) | ||
178 | { | 177 | { |
179 | struct opticon_private *priv = usb_get_serial_data(port->serial); | 178 | struct opticon_private *priv = usb_get_serial_data(port->serial); |
180 | 179 | ||
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index 7817b82889ca..a16d69fadba1 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -45,8 +45,9 @@ | |||
45 | /* Function prototypes */ | 45 | /* Function prototypes */ |
46 | static int option_open(struct tty_struct *tty, struct usb_serial_port *port, | 46 | static int option_open(struct tty_struct *tty, struct usb_serial_port *port, |
47 | struct file *filp); | 47 | struct file *filp); |
48 | static void option_close(struct tty_struct *tty, struct usb_serial_port *port, | 48 | static void option_close(struct usb_serial_port *port); |
49 | struct file *filp); | 49 | static void option_dtr_rts(struct usb_serial_port *port, int on); |
50 | |||
50 | static int option_startup(struct usb_serial *serial); | 51 | static int option_startup(struct usb_serial *serial); |
51 | static void option_shutdown(struct usb_serial *serial); | 52 | static void option_shutdown(struct usb_serial *serial); |
52 | static int option_write_room(struct tty_struct *tty); | 53 | static int option_write_room(struct tty_struct *tty); |
@@ -61,7 +62,7 @@ static void option_set_termios(struct tty_struct *tty, | |||
61 | static int option_tiocmget(struct tty_struct *tty, struct file *file); | 62 | static int option_tiocmget(struct tty_struct *tty, struct file *file); |
62 | static int option_tiocmset(struct tty_struct *tty, struct file *file, | 63 | static int option_tiocmset(struct tty_struct *tty, struct file *file, |
63 | unsigned int set, unsigned int clear); | 64 | unsigned int set, unsigned int clear); |
64 | static int option_send_setup(struct tty_struct *tty, struct usb_serial_port *port); | 65 | static int option_send_setup(struct usb_serial_port *port); |
65 | static int option_suspend(struct usb_serial *serial, pm_message_t message); | 66 | static int option_suspend(struct usb_serial *serial, pm_message_t message); |
66 | static int option_resume(struct usb_serial *serial); | 67 | static int option_resume(struct usb_serial *serial); |
67 | 68 | ||
@@ -551,6 +552,7 @@ static struct usb_serial_driver option_1port_device = { | |||
551 | .num_ports = 1, | 552 | .num_ports = 1, |
552 | .open = option_open, | 553 | .open = option_open, |
553 | .close = option_close, | 554 | .close = option_close, |
555 | .dtr_rts = option_dtr_rts, | ||
554 | .write = option_write, | 556 | .write = option_write, |
555 | .write_room = option_write_room, | 557 | .write_room = option_write_room, |
556 | .chars_in_buffer = option_chars_in_buffer, | 558 | .chars_in_buffer = option_chars_in_buffer, |
@@ -630,7 +632,7 @@ static void option_set_termios(struct tty_struct *tty, | |||
630 | dbg("%s", __func__); | 632 | dbg("%s", __func__); |
631 | /* Doesn't support option setting */ | 633 | /* Doesn't support option setting */ |
632 | tty_termios_copy_hw(tty->termios, old_termios); | 634 | tty_termios_copy_hw(tty->termios, old_termios); |
633 | option_send_setup(tty, port); | 635 | option_send_setup(port); |
634 | } | 636 | } |
635 | 637 | ||
636 | static int option_tiocmget(struct tty_struct *tty, struct file *file) | 638 | static int option_tiocmget(struct tty_struct *tty, struct file *file) |
@@ -669,7 +671,7 @@ static int option_tiocmset(struct tty_struct *tty, struct file *file, | |||
669 | portdata->rts_state = 0; | 671 | portdata->rts_state = 0; |
670 | if (clear & TIOCM_DTR) | 672 | if (clear & TIOCM_DTR) |
671 | portdata->dtr_state = 0; | 673 | portdata->dtr_state = 0; |
672 | return option_send_setup(tty, port); | 674 | return option_send_setup(port); |
673 | } | 675 | } |
674 | 676 | ||
675 | /* Write */ | 677 | /* Write */ |
@@ -897,10 +899,6 @@ static int option_open(struct tty_struct *tty, | |||
897 | 899 | ||
898 | dbg("%s", __func__); | 900 | dbg("%s", __func__); |
899 | 901 | ||
900 | /* Set some sane defaults */ | ||
901 | portdata->rts_state = 1; | ||
902 | portdata->dtr_state = 1; | ||
903 | |||
904 | /* Reset low level data toggle and start reading from endpoints */ | 902 | /* Reset low level data toggle and start reading from endpoints */ |
905 | for (i = 0; i < N_IN_URB; i++) { | 903 | for (i = 0; i < N_IN_URB; i++) { |
906 | urb = portdata->in_urbs[i]; | 904 | urb = portdata->in_urbs[i]; |
@@ -936,37 +934,43 @@ static int option_open(struct tty_struct *tty, | |||
936 | usb_pipeout(urb->pipe), 0); */ | 934 | usb_pipeout(urb->pipe), 0); */ |
937 | } | 935 | } |
938 | 936 | ||
939 | option_send_setup(tty, port); | 937 | option_send_setup(port); |
940 | 938 | ||
941 | return 0; | 939 | return 0; |
942 | } | 940 | } |
943 | 941 | ||
944 | static void option_close(struct tty_struct *tty, | 942 | static void option_dtr_rts(struct usb_serial_port *port, int on) |
945 | struct usb_serial_port *port, struct file *filp) | ||
946 | { | 943 | { |
947 | int i; | ||
948 | struct usb_serial *serial = port->serial; | 944 | struct usb_serial *serial = port->serial; |
949 | struct option_port_private *portdata; | 945 | struct option_port_private *portdata; |
950 | 946 | ||
951 | dbg("%s", __func__); | 947 | dbg("%s", __func__); |
952 | portdata = usb_get_serial_port_data(port); | 948 | portdata = usb_get_serial_port_data(port); |
949 | mutex_lock(&serial->disc_mutex); | ||
950 | portdata->rts_state = on; | ||
951 | portdata->dtr_state = on; | ||
952 | if (serial->dev) | ||
953 | option_send_setup(port); | ||
954 | mutex_unlock(&serial->disc_mutex); | ||
955 | } | ||
953 | 956 | ||
954 | portdata->rts_state = 0; | ||
955 | portdata->dtr_state = 0; | ||
956 | 957 | ||
957 | if (serial->dev) { | 958 | static void option_close(struct usb_serial_port *port) |
958 | mutex_lock(&serial->disc_mutex); | 959 | { |
959 | if (!serial->disconnected) | 960 | int i; |
960 | option_send_setup(tty, port); | 961 | struct usb_serial *serial = port->serial; |
961 | mutex_unlock(&serial->disc_mutex); | 962 | struct option_port_private *portdata; |
963 | |||
964 | dbg("%s", __func__); | ||
965 | portdata = usb_get_serial_port_data(port); | ||
962 | 966 | ||
967 | if (serial->dev) { | ||
963 | /* Stop reading/writing urbs */ | 968 | /* Stop reading/writing urbs */ |
964 | for (i = 0; i < N_IN_URB; i++) | 969 | for (i = 0; i < N_IN_URB; i++) |
965 | usb_kill_urb(portdata->in_urbs[i]); | 970 | usb_kill_urb(portdata->in_urbs[i]); |
966 | for (i = 0; i < N_OUT_URB; i++) | 971 | for (i = 0; i < N_OUT_URB; i++) |
967 | usb_kill_urb(portdata->out_urbs[i]); | 972 | usb_kill_urb(portdata->out_urbs[i]); |
968 | } | 973 | } |
969 | tty_port_tty_set(&port->port, NULL); | ||
970 | } | 974 | } |
971 | 975 | ||
972 | /* Helper functions used by option_setup_urbs */ | 976 | /* Helper functions used by option_setup_urbs */ |
@@ -1032,28 +1036,24 @@ static void option_setup_urbs(struct usb_serial *serial) | |||
1032 | * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN | 1036 | * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN |
1033 | * CDC. | 1037 | * CDC. |
1034 | */ | 1038 | */ |
1035 | static int option_send_setup(struct tty_struct *tty, | 1039 | static int option_send_setup(struct usb_serial_port *port) |
1036 | struct usb_serial_port *port) | ||
1037 | { | 1040 | { |
1038 | struct usb_serial *serial = port->serial; | 1041 | struct usb_serial *serial = port->serial; |
1039 | struct option_port_private *portdata; | 1042 | struct option_port_private *portdata; |
1040 | int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber; | 1043 | int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber; |
1044 | int val = 0; | ||
1041 | dbg("%s", __func__); | 1045 | dbg("%s", __func__); |
1042 | 1046 | ||
1043 | portdata = usb_get_serial_port_data(port); | 1047 | portdata = usb_get_serial_port_data(port); |
1044 | 1048 | ||
1045 | if (tty) { | 1049 | if (portdata->dtr_state) |
1046 | int val = 0; | 1050 | val |= 0x01; |
1047 | if (portdata->dtr_state) | 1051 | if (portdata->rts_state) |
1048 | val |= 0x01; | 1052 | val |= 0x02; |
1049 | if (portdata->rts_state) | ||
1050 | val |= 0x02; | ||
1051 | 1053 | ||
1052 | return usb_control_msg(serial->dev, | 1054 | return usb_control_msg(serial->dev, |
1053 | usb_rcvctrlpipe(serial->dev, 0), | 1055 | usb_rcvctrlpipe(serial->dev, 0), |
1054 | 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT); | 1056 | 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT); |
1055 | } | ||
1056 | return 0; | ||
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | static int option_startup(struct usb_serial *serial) | 1059 | static int option_startup(struct usb_serial *serial) |
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index ba551f00f16f..7de54781fe61 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c | |||
@@ -143,8 +143,7 @@ struct oti6858_control_pkt { | |||
143 | /* function prototypes */ | 143 | /* function prototypes */ |
144 | static int oti6858_open(struct tty_struct *tty, | 144 | static int oti6858_open(struct tty_struct *tty, |
145 | struct usb_serial_port *port, struct file *filp); | 145 | struct usb_serial_port *port, struct file *filp); |
146 | static void oti6858_close(struct tty_struct *tty, | 146 | static void oti6858_close(struct usb_serial_port *port); |
147 | struct usb_serial_port *port, struct file *filp); | ||
148 | static void oti6858_set_termios(struct tty_struct *tty, | 147 | static void oti6858_set_termios(struct tty_struct *tty, |
149 | struct usb_serial_port *port, struct ktermios *old); | 148 | struct usb_serial_port *port, struct ktermios *old); |
150 | static int oti6858_ioctl(struct tty_struct *tty, struct file *file, | 149 | static int oti6858_ioctl(struct tty_struct *tty, struct file *file, |
@@ -622,67 +621,30 @@ static int oti6858_open(struct tty_struct *tty, | |||
622 | if (result != 0) { | 621 | if (result != 0) { |
623 | dev_err(&port->dev, "%s(): usb_submit_urb() failed" | 622 | dev_err(&port->dev, "%s(): usb_submit_urb() failed" |
624 | " with error %d\n", __func__, result); | 623 | " with error %d\n", __func__, result); |
625 | oti6858_close(tty, port, NULL); | 624 | oti6858_close(port); |
626 | return -EPROTO; | 625 | return -EPROTO; |
627 | } | 626 | } |
628 | 627 | ||
629 | /* setup termios */ | 628 | /* setup termios */ |
630 | if (tty) | 629 | if (tty) |
631 | oti6858_set_termios(tty, port, &tmp_termios); | 630 | oti6858_set_termios(tty, port, &tmp_termios); |
632 | 631 | port->port.drain_delay = 256; /* FIXME: check the FIFO length */ | |
633 | return 0; | 632 | return 0; |
634 | } | 633 | } |
635 | 634 | ||
636 | static void oti6858_close(struct tty_struct *tty, | 635 | static void oti6858_close(struct usb_serial_port *port) |
637 | struct usb_serial_port *port, struct file *filp) | ||
638 | { | 636 | { |
639 | struct oti6858_private *priv = usb_get_serial_port_data(port); | 637 | struct oti6858_private *priv = usb_get_serial_port_data(port); |
640 | unsigned long flags; | 638 | unsigned long flags; |
641 | long timeout; | ||
642 | wait_queue_t wait; | ||
643 | 639 | ||
644 | dbg("%s(port = %d)", __func__, port->number); | 640 | dbg("%s(port = %d)", __func__, port->number); |
645 | 641 | ||
646 | /* wait for data to drain from the buffer */ | ||
647 | spin_lock_irqsave(&priv->lock, flags); | 642 | spin_lock_irqsave(&priv->lock, flags); |
648 | timeout = 30 * HZ; /* PL2303_CLOSING_WAIT */ | ||
649 | init_waitqueue_entry(&wait, current); | ||
650 | add_wait_queue(&tty->write_wait, &wait); | ||
651 | dbg("%s(): entering wait loop", __func__); | ||
652 | for (;;) { | ||
653 | set_current_state(TASK_INTERRUPTIBLE); | ||
654 | if (oti6858_buf_data_avail(priv->buf) == 0 | ||
655 | || timeout == 0 || signal_pending(current) | ||
656 | || port->serial->disconnected) | ||
657 | break; | ||
658 | spin_unlock_irqrestore(&priv->lock, flags); | ||
659 | timeout = schedule_timeout(timeout); | ||
660 | spin_lock_irqsave(&priv->lock, flags); | ||
661 | } | ||
662 | set_current_state(TASK_RUNNING); | ||
663 | remove_wait_queue(&tty->write_wait, &wait); | ||
664 | dbg("%s(): after wait loop", __func__); | ||
665 | |||
666 | /* clear out any remaining data in the buffer */ | 643 | /* clear out any remaining data in the buffer */ |
667 | oti6858_buf_clear(priv->buf); | 644 | oti6858_buf_clear(priv->buf); |
668 | spin_unlock_irqrestore(&priv->lock, flags); | 645 | spin_unlock_irqrestore(&priv->lock, flags); |
669 | 646 | ||
670 | /* wait for characters to drain from the device */ | 647 | dbg("%s(): after buf_clear()", __func__); |
671 | /* (this is long enough for the entire 256 byte */ | ||
672 | /* pl2303 hardware buffer to drain with no flow */ | ||
673 | /* control for data rates of 1200 bps or more, */ | ||
674 | /* for lower rates we should really know how much */ | ||
675 | /* data is in the buffer to compute a delay */ | ||
676 | /* that is not unnecessarily long) */ | ||
677 | /* FIXME | ||
678 | bps = tty_get_baud_rate(tty); | ||
679 | if (bps > 1200) | ||
680 | timeout = max((HZ*2560)/bps,HZ/10); | ||
681 | else | ||
682 | */ | ||
683 | timeout = 2*HZ; | ||
684 | schedule_timeout_interruptible(timeout); | ||
685 | dbg("%s(): after schedule_timeout_interruptible()", __func__); | ||
686 | 648 | ||
687 | /* cancel scheduled setup */ | 649 | /* cancel scheduled setup */ |
688 | cancel_delayed_work(&priv->delayed_setup_work); | 650 | cancel_delayed_work(&priv->delayed_setup_work); |
@@ -694,15 +656,6 @@ static void oti6858_close(struct tty_struct *tty, | |||
694 | usb_kill_urb(port->write_urb); | 656 | usb_kill_urb(port->write_urb); |
695 | usb_kill_urb(port->read_urb); | 657 | usb_kill_urb(port->read_urb); |
696 | usb_kill_urb(port->interrupt_in_urb); | 658 | usb_kill_urb(port->interrupt_in_urb); |
697 | |||
698 | /* | ||
699 | if (tty && (tty->termios->c_cflag) & HUPCL) { | ||
700 | // drop DTR and RTS | ||
701 | spin_lock_irqsave(&priv->lock, flags); | ||
702 | priv->pending_setup.control &= ~CONTROL_MASK; | ||
703 | spin_unlock_irqrestore(&priv->lock, flags); | ||
704 | } | ||
705 | */ | ||
706 | } | 659 | } |
707 | 660 | ||
708 | static int oti6858_tiocmset(struct tty_struct *tty, struct file *file, | 661 | static int oti6858_tiocmset(struct tty_struct *tty, struct file *file, |
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 751a533a4347..e02dc3d643c7 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
@@ -652,69 +652,41 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
652 | kfree(buf); | 652 | kfree(buf); |
653 | } | 653 | } |
654 | 654 | ||
655 | static void pl2303_close(struct tty_struct *tty, | 655 | static void pl2303_dtr_rts(struct usb_serial_port *port, int on) |
656 | struct usb_serial_port *port, struct file *filp) | 656 | { |
657 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
658 | unsigned long flags; | ||
659 | u8 control; | ||
660 | |||
661 | spin_lock_irqsave(&priv->lock, flags); | ||
662 | /* Change DTR and RTS */ | ||
663 | if (on) | ||
664 | priv->line_control |= (CONTROL_DTR | CONTROL_RTS); | ||
665 | else | ||
666 | priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); | ||
667 | control = priv->line_control; | ||
668 | spin_unlock_irqrestore(&priv->lock, flags); | ||
669 | set_control_lines(port->serial->dev, control); | ||
670 | } | ||
671 | |||
672 | static void pl2303_close(struct usb_serial_port *port) | ||
657 | { | 673 | { |
658 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 674 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
659 | unsigned long flags; | 675 | unsigned long flags; |
660 | unsigned int c_cflag; | ||
661 | int bps; | ||
662 | long timeout; | ||
663 | wait_queue_t wait; | ||
664 | 676 | ||
665 | dbg("%s - port %d", __func__, port->number); | 677 | dbg("%s - port %d", __func__, port->number); |
666 | 678 | ||
667 | /* wait for data to drain from the buffer */ | ||
668 | spin_lock_irqsave(&priv->lock, flags); | 679 | spin_lock_irqsave(&priv->lock, flags); |
669 | timeout = PL2303_CLOSING_WAIT; | ||
670 | init_waitqueue_entry(&wait, current); | ||
671 | add_wait_queue(&tty->write_wait, &wait); | ||
672 | for (;;) { | ||
673 | set_current_state(TASK_INTERRUPTIBLE); | ||
674 | if (pl2303_buf_data_avail(priv->buf) == 0 || | ||
675 | timeout == 0 || signal_pending(current) || | ||
676 | port->serial->disconnected) | ||
677 | break; | ||
678 | spin_unlock_irqrestore(&priv->lock, flags); | ||
679 | timeout = schedule_timeout(timeout); | ||
680 | spin_lock_irqsave(&priv->lock, flags); | ||
681 | } | ||
682 | set_current_state(TASK_RUNNING); | ||
683 | remove_wait_queue(&tty->write_wait, &wait); | ||
684 | /* clear out any remaining data in the buffer */ | 680 | /* clear out any remaining data in the buffer */ |
685 | pl2303_buf_clear(priv->buf); | 681 | pl2303_buf_clear(priv->buf); |
686 | spin_unlock_irqrestore(&priv->lock, flags); | 682 | spin_unlock_irqrestore(&priv->lock, flags); |
687 | 683 | ||
688 | /* wait for characters to drain from the device */ | ||
689 | /* (this is long enough for the entire 256 byte */ | ||
690 | /* pl2303 hardware buffer to drain with no flow */ | ||
691 | /* control for data rates of 1200 bps or more, */ | ||
692 | /* for lower rates we should really know how much */ | ||
693 | /* data is in the buffer to compute a delay */ | ||
694 | /* that is not unnecessarily long) */ | ||
695 | bps = tty_get_baud_rate(tty); | ||
696 | if (bps > 1200) | ||
697 | timeout = max((HZ*2560)/bps, HZ/10); | ||
698 | else | ||
699 | timeout = 2*HZ; | ||
700 | schedule_timeout_interruptible(timeout); | ||
701 | |||
702 | /* shutdown our urbs */ | 684 | /* shutdown our urbs */ |
703 | dbg("%s - shutting down urbs", __func__); | 685 | dbg("%s - shutting down urbs", __func__); |
704 | usb_kill_urb(port->write_urb); | 686 | usb_kill_urb(port->write_urb); |
705 | usb_kill_urb(port->read_urb); | 687 | usb_kill_urb(port->read_urb); |
706 | usb_kill_urb(port->interrupt_in_urb); | 688 | usb_kill_urb(port->interrupt_in_urb); |
707 | 689 | ||
708 | if (tty) { | ||
709 | c_cflag = tty->termios->c_cflag; | ||
710 | if (c_cflag & HUPCL) { | ||
711 | /* drop DTR and RTS */ | ||
712 | spin_lock_irqsave(&priv->lock, flags); | ||
713 | priv->line_control = 0; | ||
714 | spin_unlock_irqrestore(&priv->lock, flags); | ||
715 | set_control_lines(port->serial->dev, 0); | ||
716 | } | ||
717 | } | ||
718 | } | 690 | } |
719 | 691 | ||
720 | static int pl2303_open(struct tty_struct *tty, | 692 | static int pl2303_open(struct tty_struct *tty, |
@@ -748,7 +720,7 @@ static int pl2303_open(struct tty_struct *tty, | |||
748 | if (result) { | 720 | if (result) { |
749 | dev_err(&port->dev, "%s - failed submitting read urb," | 721 | dev_err(&port->dev, "%s - failed submitting read urb," |
750 | " error %d\n", __func__, result); | 722 | " error %d\n", __func__, result); |
751 | pl2303_close(tty, port, NULL); | 723 | pl2303_close(port); |
752 | return -EPROTO; | 724 | return -EPROTO; |
753 | } | 725 | } |
754 | 726 | ||
@@ -758,9 +730,10 @@ static int pl2303_open(struct tty_struct *tty, | |||
758 | if (result) { | 730 | if (result) { |
759 | dev_err(&port->dev, "%s - failed submitting interrupt urb," | 731 | dev_err(&port->dev, "%s - failed submitting interrupt urb," |
760 | " error %d\n", __func__, result); | 732 | " error %d\n", __func__, result); |
761 | pl2303_close(tty, port, NULL); | 733 | pl2303_close(port); |
762 | return -EPROTO; | 734 | return -EPROTO; |
763 | } | 735 | } |
736 | port->port.drain_delay = 256; | ||
764 | return 0; | 737 | return 0; |
765 | } | 738 | } |
766 | 739 | ||
@@ -821,6 +794,14 @@ static int pl2303_tiocmget(struct tty_struct *tty, struct file *file) | |||
821 | return result; | 794 | return result; |
822 | } | 795 | } |
823 | 796 | ||
797 | static int pl2303_carrier_raised(struct usb_serial_port *port) | ||
798 | { | ||
799 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
800 | if (priv->line_status & UART_DCD) | ||
801 | return 1; | ||
802 | return 0; | ||
803 | } | ||
804 | |||
824 | static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) | 805 | static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) |
825 | { | 806 | { |
826 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 807 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
@@ -1125,6 +1106,8 @@ static struct usb_serial_driver pl2303_device = { | |||
1125 | .num_ports = 1, | 1106 | .num_ports = 1, |
1126 | .open = pl2303_open, | 1107 | .open = pl2303_open, |
1127 | .close = pl2303_close, | 1108 | .close = pl2303_close, |
1109 | .dtr_rts = pl2303_dtr_rts, | ||
1110 | .carrier_raised = pl2303_carrier_raised, | ||
1128 | .write = pl2303_write, | 1111 | .write = pl2303_write, |
1129 | .ioctl = pl2303_ioctl, | 1112 | .ioctl = pl2303_ioctl, |
1130 | .break_ctl = pl2303_break_ctl, | 1113 | .break_ctl = pl2303_break_ctl, |
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index 913225c61610..17ac34f4d668 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c | |||
@@ -26,12 +26,10 @@ | |||
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/usb.h> | 27 | #include <linux/usb.h> |
28 | #include <linux/usb/serial.h> | 28 | #include <linux/usb/serial.h> |
29 | #include <linux/usb/ch9.h> | ||
30 | 29 | ||
31 | #define SWIMS_USB_REQUEST_SetPower 0x00 | 30 | #define SWIMS_USB_REQUEST_SetPower 0x00 |
32 | #define SWIMS_USB_REQUEST_SetNmea 0x07 | 31 | #define SWIMS_USB_REQUEST_SetNmea 0x07 |
33 | 32 | ||
34 | /* per port private data */ | ||
35 | #define N_IN_URB 4 | 33 | #define N_IN_URB 4 |
36 | #define N_OUT_URB 4 | 34 | #define N_OUT_URB 4 |
37 | #define IN_BUFLEN 4096 | 35 | #define IN_BUFLEN 4096 |
@@ -39,6 +37,12 @@ | |||
39 | static int debug; | 37 | static int debug; |
40 | static int nmea; | 38 | static int nmea; |
41 | 39 | ||
40 | /* Used in interface blacklisting */ | ||
41 | struct sierra_iface_info { | ||
42 | const u32 infolen; /* number of interface numbers on blacklist */ | ||
43 | const u8 *ifaceinfo; /* pointer to the array holding the numbers */ | ||
44 | }; | ||
45 | |||
42 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) | 46 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) |
43 | { | 47 | { |
44 | int result; | 48 | int result; |
@@ -85,6 +89,23 @@ static int sierra_calc_num_ports(struct usb_serial *serial) | |||
85 | return result; | 89 | return result; |
86 | } | 90 | } |
87 | 91 | ||
92 | static int is_blacklisted(const u8 ifnum, | ||
93 | const struct sierra_iface_info *blacklist) | ||
94 | { | ||
95 | const u8 *info; | ||
96 | int i; | ||
97 | |||
98 | if (blacklist) { | ||
99 | info = blacklist->ifaceinfo; | ||
100 | |||
101 | for (i = 0; i < blacklist->infolen; i++) { | ||
102 | if (info[i] == ifnum) | ||
103 | return 1; | ||
104 | } | ||
105 | } | ||
106 | return 0; | ||
107 | } | ||
108 | |||
88 | static int sierra_calc_interface(struct usb_serial *serial) | 109 | static int sierra_calc_interface(struct usb_serial *serial) |
89 | { | 110 | { |
90 | int interface; | 111 | int interface; |
@@ -153,9 +174,25 @@ static int sierra_probe(struct usb_serial *serial, | |||
153 | */ | 174 | */ |
154 | usb_set_serial_data(serial, (void *)num_ports); | 175 | usb_set_serial_data(serial, (void *)num_ports); |
155 | 176 | ||
177 | /* ifnum could have changed - by calling usb_set_interface */ | ||
178 | ifnum = sierra_calc_interface(serial); | ||
179 | |||
180 | if (is_blacklisted(ifnum, | ||
181 | (struct sierra_iface_info *)id->driver_info)) { | ||
182 | dev_dbg(&serial->dev->dev, | ||
183 | "Ignoring blacklisted interface #%d\n", ifnum); | ||
184 | return -ENODEV; | ||
185 | } | ||
186 | |||
156 | return result; | 187 | return result; |
157 | } | 188 | } |
158 | 189 | ||
190 | static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 }; | ||
191 | static const struct sierra_iface_info direct_ip_interface_blacklist = { | ||
192 | .infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces), | ||
193 | .ifaceinfo = direct_ip_non_serial_ifaces, | ||
194 | }; | ||
195 | |||
159 | static struct usb_device_id id_table [] = { | 196 | static struct usb_device_id id_table [] = { |
160 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ | 197 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ |
161 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ | 198 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ |
@@ -188,9 +225,11 @@ static struct usb_device_id id_table [] = { | |||
188 | { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */ | 225 | { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */ |
189 | { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ | 226 | { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ |
190 | { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ | 227 | { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ |
191 | { USB_DEVICE(0x1199, 0x683C) }, /* Sierra Wireless MC8790 */ | 228 | /* Sierra Wireless MC8790, MC8791, MC8792 Composite */ |
192 | { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8790 */ | 229 | { USB_DEVICE(0x1199, 0x683C) }, |
193 | { USB_DEVICE(0x1199, 0x683E) }, /* Sierra Wireless MC8790 */ | 230 | { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8791 Composite */ |
231 | /* Sierra Wireless MC8790, MC8791, MC8792 */ | ||
232 | { USB_DEVICE(0x1199, 0x683E) }, | ||
194 | { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ | 233 | { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ |
195 | { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ | 234 | { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ |
196 | { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ | 235 | { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ |
@@ -211,6 +250,10 @@ static struct usb_device_id id_table [] = { | |||
211 | { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ | 250 | { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ |
212 | { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ | 251 | { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ |
213 | 252 | ||
253 | { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */ | ||
254 | .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist | ||
255 | }, | ||
256 | |||
214 | { } | 257 | { } |
215 | }; | 258 | }; |
216 | MODULE_DEVICE_TABLE(usb, id_table); | 259 | MODULE_DEVICE_TABLE(usb, id_table); |
@@ -229,7 +272,6 @@ struct sierra_port_private { | |||
229 | 272 | ||
230 | /* Input endpoints and buffers for this port */ | 273 | /* Input endpoints and buffers for this port */ |
231 | struct urb *in_urbs[N_IN_URB]; | 274 | struct urb *in_urbs[N_IN_URB]; |
232 | char *in_buffer[N_IN_URB]; | ||
233 | 275 | ||
234 | /* Settings for the port */ | 276 | /* Settings for the port */ |
235 | int rts_state; /* Handshaking pins (outputs) */ | 277 | int rts_state; /* Handshaking pins (outputs) */ |
@@ -240,57 +282,50 @@ struct sierra_port_private { | |||
240 | int ri_state; | 282 | int ri_state; |
241 | }; | 283 | }; |
242 | 284 | ||
243 | static int sierra_send_setup(struct tty_struct *tty, | 285 | static int sierra_send_setup(struct usb_serial_port *port) |
244 | struct usb_serial_port *port) | ||
245 | { | 286 | { |
246 | struct usb_serial *serial = port->serial; | 287 | struct usb_serial *serial = port->serial; |
247 | struct sierra_port_private *portdata; | 288 | struct sierra_port_private *portdata; |
248 | __u16 interface = 0; | 289 | __u16 interface = 0; |
290 | int val = 0; | ||
249 | 291 | ||
250 | dev_dbg(&port->dev, "%s", __func__); | 292 | dev_dbg(&port->dev, "%s", __func__); |
251 | 293 | ||
252 | portdata = usb_get_serial_port_data(port); | 294 | portdata = usb_get_serial_port_data(port); |
253 | 295 | ||
254 | if (tty) { | 296 | if (portdata->dtr_state) |
255 | int val = 0; | 297 | val |= 0x01; |
256 | if (portdata->dtr_state) | 298 | if (portdata->rts_state) |
257 | val |= 0x01; | 299 | val |= 0x02; |
258 | if (portdata->rts_state) | ||
259 | val |= 0x02; | ||
260 | |||
261 | /* If composite device then properly report interface */ | ||
262 | if (serial->num_ports == 1) { | ||
263 | interface = sierra_calc_interface(serial); | ||
264 | |||
265 | /* Control message is sent only to interfaces with | ||
266 | * interrupt_in endpoints | ||
267 | */ | ||
268 | if (port->interrupt_in_urb) { | ||
269 | /* send control message */ | ||
270 | return usb_control_msg(serial->dev, | ||
271 | usb_rcvctrlpipe(serial->dev, 0), | ||
272 | 0x22, 0x21, val, interface, | ||
273 | NULL, 0, USB_CTRL_SET_TIMEOUT); | ||
274 | } | ||
275 | } | ||
276 | |||
277 | /* Otherwise the need to do non-composite mapping */ | ||
278 | else { | ||
279 | if (port->bulk_out_endpointAddress == 2) | ||
280 | interface = 0; | ||
281 | else if (port->bulk_out_endpointAddress == 4) | ||
282 | interface = 1; | ||
283 | else if (port->bulk_out_endpointAddress == 5) | ||
284 | interface = 2; | ||
285 | 300 | ||
301 | /* If composite device then properly report interface */ | ||
302 | if (serial->num_ports == 1) { | ||
303 | interface = sierra_calc_interface(serial); | ||
304 | /* Control message is sent only to interfaces with | ||
305 | * interrupt_in endpoints | ||
306 | */ | ||
307 | if (port->interrupt_in_urb) { | ||
308 | /* send control message */ | ||
286 | return usb_control_msg(serial->dev, | 309 | return usb_control_msg(serial->dev, |
287 | usb_rcvctrlpipe(serial->dev, 0), | 310 | usb_rcvctrlpipe(serial->dev, 0), |
288 | 0x22, 0x21, val, interface, | 311 | 0x22, 0x21, val, interface, |
289 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 312 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
290 | |||
291 | } | 313 | } |
292 | } | 314 | } |
293 | 315 | ||
316 | /* Otherwise the need to do non-composite mapping */ | ||
317 | else { | ||
318 | if (port->bulk_out_endpointAddress == 2) | ||
319 | interface = 0; | ||
320 | else if (port->bulk_out_endpointAddress == 4) | ||
321 | interface = 1; | ||
322 | else if (port->bulk_out_endpointAddress == 5) | ||
323 | interface = 2; | ||
324 | return usb_control_msg(serial->dev, | ||
325 | usb_rcvctrlpipe(serial->dev, 0), | ||
326 | 0x22, 0x21, val, interface, | ||
327 | NULL, 0, USB_CTRL_SET_TIMEOUT); | ||
328 | } | ||
294 | return 0; | 329 | return 0; |
295 | } | 330 | } |
296 | 331 | ||
@@ -299,7 +334,7 @@ static void sierra_set_termios(struct tty_struct *tty, | |||
299 | { | 334 | { |
300 | dev_dbg(&port->dev, "%s", __func__); | 335 | dev_dbg(&port->dev, "%s", __func__); |
301 | tty_termios_copy_hw(tty->termios, old_termios); | 336 | tty_termios_copy_hw(tty->termios, old_termios); |
302 | sierra_send_setup(tty, port); | 337 | sierra_send_setup(port); |
303 | } | 338 | } |
304 | 339 | ||
305 | static int sierra_tiocmget(struct tty_struct *tty, struct file *file) | 340 | static int sierra_tiocmget(struct tty_struct *tty, struct file *file) |
@@ -338,7 +373,18 @@ static int sierra_tiocmset(struct tty_struct *tty, struct file *file, | |||
338 | portdata->rts_state = 0; | 373 | portdata->rts_state = 0; |
339 | if (clear & TIOCM_DTR) | 374 | if (clear & TIOCM_DTR) |
340 | portdata->dtr_state = 0; | 375 | portdata->dtr_state = 0; |
341 | return sierra_send_setup(tty, port); | 376 | return sierra_send_setup(port); |
377 | } | ||
378 | |||
379 | static void sierra_release_urb(struct urb *urb) | ||
380 | { | ||
381 | struct usb_serial_port *port; | ||
382 | if (urb) { | ||
383 | port = urb->context; | ||
384 | dev_dbg(&port->dev, "%s: %p\n", __func__, urb); | ||
385 | kfree(urb->transfer_buffer); | ||
386 | usb_free_urb(urb); | ||
387 | } | ||
342 | } | 388 | } |
343 | 389 | ||
344 | static void sierra_outdat_callback(struct urb *urb) | 390 | static void sierra_outdat_callback(struct urb *urb) |
@@ -465,7 +511,7 @@ static void sierra_indat_callback(struct urb *urb) | |||
465 | " received", __func__); | 511 | " received", __func__); |
466 | 512 | ||
467 | /* Resubmit urb so we continue receiving */ | 513 | /* Resubmit urb so we continue receiving */ |
468 | if (port->port.count && status != -ESHUTDOWN) { | 514 | if (port->port.count && status != -ESHUTDOWN && status != -EPERM) { |
469 | err = usb_submit_urb(urb, GFP_ATOMIC); | 515 | err = usb_submit_urb(urb, GFP_ATOMIC); |
470 | if (err) | 516 | if (err) |
471 | dev_err(&port->dev, "resubmit read urb failed." | 517 | dev_err(&port->dev, "resubmit read urb failed." |
@@ -557,67 +603,99 @@ static int sierra_write_room(struct tty_struct *tty) | |||
557 | return 2048; | 603 | return 2048; |
558 | } | 604 | } |
559 | 605 | ||
560 | static int sierra_open(struct tty_struct *tty, | 606 | static void sierra_stop_rx_urbs(struct usb_serial_port *port) |
561 | struct usb_serial_port *port, struct file *filp) | ||
562 | { | 607 | { |
563 | struct sierra_port_private *portdata; | ||
564 | struct usb_serial *serial = port->serial; | ||
565 | int i; | 608 | int i; |
566 | struct urb *urb; | 609 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
567 | int result; | ||
568 | 610 | ||
569 | portdata = usb_get_serial_port_data(port); | 611 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) |
612 | usb_kill_urb(portdata->in_urbs[i]); | ||
570 | 613 | ||
571 | dev_dbg(&port->dev, "%s", __func__); | 614 | usb_kill_urb(port->interrupt_in_urb); |
615 | } | ||
572 | 616 | ||
573 | /* Set some sane defaults */ | 617 | static int sierra_submit_rx_urbs(struct usb_serial_port *port, gfp_t mem_flags) |
574 | portdata->rts_state = 1; | 618 | { |
575 | portdata->dtr_state = 1; | 619 | int ok_cnt; |
620 | int err = -EINVAL; | ||
621 | int i; | ||
622 | struct urb *urb; | ||
623 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); | ||
576 | 624 | ||
577 | /* Reset low level data toggle and start reading from endpoints */ | 625 | ok_cnt = 0; |
578 | for (i = 0; i < N_IN_URB; i++) { | 626 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { |
579 | urb = portdata->in_urbs[i]; | 627 | urb = portdata->in_urbs[i]; |
580 | if (!urb) | 628 | if (!urb) |
581 | continue; | 629 | continue; |
582 | if (urb->dev != serial->dev) { | 630 | err = usb_submit_urb(urb, mem_flags); |
583 | dev_dbg(&port->dev, "%s: dev %p != %p", | 631 | if (err) { |
584 | __func__, urb->dev, serial->dev); | 632 | dev_err(&port->dev, "%s: submit urb failed: %d\n", |
585 | continue; | 633 | __func__, err); |
634 | } else { | ||
635 | ok_cnt++; | ||
586 | } | 636 | } |
637 | } | ||
587 | 638 | ||
588 | /* | 639 | if (ok_cnt && port->interrupt_in_urb) { |
589 | * make sure endpoint data toggle is synchronized with the | 640 | err = usb_submit_urb(port->interrupt_in_urb, mem_flags); |
590 | * device | 641 | if (err) { |
591 | */ | 642 | dev_err(&port->dev, "%s: submit intr urb failed: %d\n", |
592 | usb_clear_halt(urb->dev, urb->pipe); | 643 | __func__, err); |
593 | |||
594 | result = usb_submit_urb(urb, GFP_KERNEL); | ||
595 | if (result) { | ||
596 | dev_err(&port->dev, "submit urb %d failed (%d) %d\n", | ||
597 | i, result, urb->transfer_buffer_length); | ||
598 | } | 644 | } |
599 | } | 645 | } |
600 | 646 | ||
601 | sierra_send_setup(tty, port); | 647 | if (ok_cnt > 0) /* at least one rx urb submitted */ |
648 | return 0; | ||
649 | else | ||
650 | return err; | ||
651 | } | ||
652 | |||
653 | static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, | ||
654 | int dir, void *ctx, int len, | ||
655 | gfp_t mem_flags, | ||
656 | usb_complete_t callback) | ||
657 | { | ||
658 | struct urb *urb; | ||
659 | u8 *buf; | ||
660 | |||
661 | if (endpoint == -1) | ||
662 | return NULL; | ||
602 | 663 | ||
603 | /* start up the interrupt endpoint if we have one */ | 664 | urb = usb_alloc_urb(0, mem_flags); |
604 | if (port->interrupt_in_urb) { | 665 | if (urb == NULL) { |
605 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | 666 | dev_dbg(&serial->dev->dev, "%s: alloc for endpoint %d failed\n", |
606 | if (result) | 667 | __func__, endpoint); |
607 | dev_err(&port->dev, "submit irq_in urb failed %d\n", | 668 | return NULL; |
608 | result); | ||
609 | } | 669 | } |
610 | return 0; | 670 | |
671 | buf = kmalloc(len, mem_flags); | ||
672 | if (buf) { | ||
673 | /* Fill URB using supplied data */ | ||
674 | usb_fill_bulk_urb(urb, serial->dev, | ||
675 | usb_sndbulkpipe(serial->dev, endpoint) | dir, | ||
676 | buf, len, callback, ctx); | ||
677 | |||
678 | /* debug */ | ||
679 | dev_dbg(&serial->dev->dev, "%s %c u : %p d:%p\n", __func__, | ||
680 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); | ||
681 | } else { | ||
682 | dev_dbg(&serial->dev->dev, "%s %c u:%p d:%p\n", __func__, | ||
683 | dir == USB_DIR_IN ? 'i' : 'o', urb, buf); | ||
684 | |||
685 | sierra_release_urb(urb); | ||
686 | urb = NULL; | ||
687 | } | ||
688 | |||
689 | return urb; | ||
611 | } | 690 | } |
612 | 691 | ||
613 | static void sierra_close(struct tty_struct *tty, | 692 | static void sierra_close(struct usb_serial_port *port) |
614 | struct usb_serial_port *port, struct file *filp) | ||
615 | { | 693 | { |
616 | int i; | 694 | int i; |
617 | struct usb_serial *serial = port->serial; | 695 | struct usb_serial *serial = port->serial; |
618 | struct sierra_port_private *portdata; | 696 | struct sierra_port_private *portdata; |
619 | 697 | ||
620 | dev_dbg(&port->dev, "%s", __func__); | 698 | dev_dbg(&port->dev, "%s\n", __func__); |
621 | portdata = usb_get_serial_port_data(port); | 699 | portdata = usb_get_serial_port_data(port); |
622 | 700 | ||
623 | portdata->rts_state = 0; | 701 | portdata->rts_state = 0; |
@@ -626,25 +704,83 @@ static void sierra_close(struct tty_struct *tty, | |||
626 | if (serial->dev) { | 704 | if (serial->dev) { |
627 | mutex_lock(&serial->disc_mutex); | 705 | mutex_lock(&serial->disc_mutex); |
628 | if (!serial->disconnected) | 706 | if (!serial->disconnected) |
629 | sierra_send_setup(tty, port); | 707 | sierra_send_setup(port); |
630 | mutex_unlock(&serial->disc_mutex); | 708 | mutex_unlock(&serial->disc_mutex); |
631 | 709 | ||
632 | /* Stop reading/writing urbs */ | 710 | /* Stop reading urbs */ |
633 | for (i = 0; i < N_IN_URB; i++) | 711 | sierra_stop_rx_urbs(port); |
634 | usb_kill_urb(portdata->in_urbs[i]); | 712 | /* .. and release them */ |
713 | for (i = 0; i < N_IN_URB; i++) { | ||
714 | sierra_release_urb(portdata->in_urbs[i]); | ||
715 | portdata->in_urbs[i] = NULL; | ||
716 | } | ||
635 | } | 717 | } |
718 | } | ||
636 | 719 | ||
637 | usb_kill_urb(port->interrupt_in_urb); | 720 | static int sierra_open(struct tty_struct *tty, |
638 | tty_port_tty_set(&port->port, NULL); | 721 | struct usb_serial_port *port, struct file *filp) |
722 | { | ||
723 | struct sierra_port_private *portdata; | ||
724 | struct usb_serial *serial = port->serial; | ||
725 | int i; | ||
726 | int err; | ||
727 | int endpoint; | ||
728 | struct urb *urb; | ||
729 | |||
730 | portdata = usb_get_serial_port_data(port); | ||
731 | |||
732 | dev_dbg(&port->dev, "%s", __func__); | ||
733 | |||
734 | /* Set some sane defaults */ | ||
735 | portdata->rts_state = 1; | ||
736 | portdata->dtr_state = 1; | ||
737 | |||
738 | |||
739 | endpoint = port->bulk_in_endpointAddress; | ||
740 | for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { | ||
741 | urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, | ||
742 | IN_BUFLEN, GFP_KERNEL, | ||
743 | sierra_indat_callback); | ||
744 | portdata->in_urbs[i] = urb; | ||
745 | } | ||
746 | /* clear halt condition */ | ||
747 | usb_clear_halt(serial->dev, | ||
748 | usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN); | ||
749 | |||
750 | err = sierra_submit_rx_urbs(port, GFP_KERNEL); | ||
751 | if (err) { | ||
752 | /* get rid of everything as in close */ | ||
753 | sierra_close(port); | ||
754 | return err; | ||
755 | } | ||
756 | sierra_send_setup(port); | ||
757 | |||
758 | return 0; | ||
759 | } | ||
760 | |||
761 | |||
762 | static void sierra_dtr_rts(struct usb_serial_port *port, int on) | ||
763 | { | ||
764 | struct usb_serial *serial = port->serial; | ||
765 | struct sierra_port_private *portdata; | ||
766 | |||
767 | portdata = usb_get_serial_port_data(port); | ||
768 | portdata->rts_state = on; | ||
769 | portdata->dtr_state = on; | ||
770 | |||
771 | if (serial->dev) { | ||
772 | mutex_lock(&serial->disc_mutex); | ||
773 | if (!serial->disconnected) | ||
774 | sierra_send_setup(port); | ||
775 | mutex_unlock(&serial->disc_mutex); | ||
776 | } | ||
639 | } | 777 | } |
640 | 778 | ||
641 | static int sierra_startup(struct usb_serial *serial) | 779 | static int sierra_startup(struct usb_serial *serial) |
642 | { | 780 | { |
643 | struct usb_serial_port *port; | 781 | struct usb_serial_port *port; |
644 | struct sierra_port_private *portdata; | 782 | struct sierra_port_private *portdata; |
645 | struct urb *urb; | ||
646 | int i; | 783 | int i; |
647 | int j; | ||
648 | 784 | ||
649 | dev_dbg(&serial->dev->dev, "%s", __func__); | 785 | dev_dbg(&serial->dev->dev, "%s", __func__); |
650 | 786 | ||
@@ -666,34 +802,8 @@ static int sierra_startup(struct usb_serial *serial) | |||
666 | return -ENOMEM; | 802 | return -ENOMEM; |
667 | } | 803 | } |
668 | spin_lock_init(&portdata->lock); | 804 | spin_lock_init(&portdata->lock); |
669 | for (j = 0; j < N_IN_URB; j++) { | 805 | /* Set the port private data pointer */ |
670 | portdata->in_buffer[j] = kmalloc(IN_BUFLEN, GFP_KERNEL); | ||
671 | if (!portdata->in_buffer[j]) { | ||
672 | for (--j; j >= 0; j--) | ||
673 | kfree(portdata->in_buffer[j]); | ||
674 | kfree(portdata); | ||
675 | return -ENOMEM; | ||
676 | } | ||
677 | } | ||
678 | |||
679 | usb_set_serial_port_data(port, portdata); | 806 | usb_set_serial_port_data(port, portdata); |
680 | |||
681 | /* initialize the in urbs */ | ||
682 | for (j = 0; j < N_IN_URB; ++j) { | ||
683 | urb = usb_alloc_urb(0, GFP_KERNEL); | ||
684 | if (urb == NULL) { | ||
685 | dev_dbg(&port->dev, "%s: alloc for in " | ||
686 | "port failed.", __func__); | ||
687 | continue; | ||
688 | } | ||
689 | /* Fill URB using supplied data. */ | ||
690 | usb_fill_bulk_urb(urb, serial->dev, | ||
691 | usb_rcvbulkpipe(serial->dev, | ||
692 | port->bulk_in_endpointAddress), | ||
693 | portdata->in_buffer[j], IN_BUFLEN, | ||
694 | sierra_indat_callback, port); | ||
695 | portdata->in_urbs[j] = urb; | ||
696 | } | ||
697 | } | 807 | } |
698 | 808 | ||
699 | return 0; | 809 | return 0; |
@@ -701,7 +811,7 @@ static int sierra_startup(struct usb_serial *serial) | |||
701 | 811 | ||
702 | static void sierra_shutdown(struct usb_serial *serial) | 812 | static void sierra_shutdown(struct usb_serial *serial) |
703 | { | 813 | { |
704 | int i, j; | 814 | int i; |
705 | struct usb_serial_port *port; | 815 | struct usb_serial_port *port; |
706 | struct sierra_port_private *portdata; | 816 | struct sierra_port_private *portdata; |
707 | 817 | ||
@@ -714,12 +824,6 @@ static void sierra_shutdown(struct usb_serial *serial) | |||
714 | portdata = usb_get_serial_port_data(port); | 824 | portdata = usb_get_serial_port_data(port); |
715 | if (!portdata) | 825 | if (!portdata) |
716 | continue; | 826 | continue; |
717 | |||
718 | for (j = 0; j < N_IN_URB; j++) { | ||
719 | usb_kill_urb(portdata->in_urbs[j]); | ||
720 | usb_free_urb(portdata->in_urbs[j]); | ||
721 | kfree(portdata->in_buffer[j]); | ||
722 | } | ||
723 | kfree(portdata); | 827 | kfree(portdata); |
724 | usb_set_serial_port_data(port, NULL); | 828 | usb_set_serial_port_data(port, NULL); |
725 | } | 829 | } |
@@ -737,6 +841,7 @@ static struct usb_serial_driver sierra_device = { | |||
737 | .probe = sierra_probe, | 841 | .probe = sierra_probe, |
738 | .open = sierra_open, | 842 | .open = sierra_open, |
739 | .close = sierra_close, | 843 | .close = sierra_close, |
844 | .dtr_rts = sierra_dtr_rts, | ||
740 | .write = sierra_write, | 845 | .write = sierra_write, |
741 | .write_room = sierra_write_room, | 846 | .write_room = sierra_write_room, |
742 | .set_termios = sierra_set_termios, | 847 | .set_termios = sierra_set_termios, |
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c index 5e7528cc81a8..8f7ed8f13996 100644 --- a/drivers/usb/serial/spcp8x5.c +++ b/drivers/usb/serial/spcp8x5.c | |||
@@ -446,66 +446,47 @@ static void spcp8x5_set_workMode(struct usb_device *dev, u16 value, | |||
446 | "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret); | 446 | "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret); |
447 | } | 447 | } |
448 | 448 | ||
449 | static int spcp8x5_carrier_raised(struct usb_serial_port *port) | ||
450 | { | ||
451 | struct spcp8x5_private *priv = usb_get_serial_port_data(port); | ||
452 | if (priv->line_status & MSR_STATUS_LINE_DCD) | ||
453 | return 1; | ||
454 | return 0; | ||
455 | } | ||
456 | |||
457 | static void spcp8x5_dtr_rts(struct usb_serial_port *port, int on) | ||
458 | { | ||
459 | struct spcp8x5_private *priv = usb_get_serial_port_data(port); | ||
460 | unsigned long flags; | ||
461 | u8 control; | ||
462 | |||
463 | spin_lock_irqsave(&priv->lock, flags); | ||
464 | if (on) | ||
465 | priv->line_control = MCR_CONTROL_LINE_DTR | ||
466 | | MCR_CONTROL_LINE_RTS; | ||
467 | else | ||
468 | priv->line_control &= ~ (MCR_CONTROL_LINE_DTR | ||
469 | | MCR_CONTROL_LINE_RTS); | ||
470 | control = priv->line_control; | ||
471 | spin_unlock_irqrestore(&priv->lock, flags); | ||
472 | spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); | ||
473 | } | ||
474 | |||
449 | /* close the serial port. We should wait for data sending to device 1st and | 475 | /* close the serial port. We should wait for data sending to device 1st and |
450 | * then kill all urb. */ | 476 | * then kill all urb. */ |
451 | static void spcp8x5_close(struct tty_struct *tty, | 477 | static void spcp8x5_close(struct usb_serial_port *port) |
452 | struct usb_serial_port *port, struct file *filp) | ||
453 | { | 478 | { |
454 | struct spcp8x5_private *priv = usb_get_serial_port_data(port); | 479 | struct spcp8x5_private *priv = usb_get_serial_port_data(port); |
455 | unsigned long flags; | 480 | unsigned long flags; |
456 | unsigned int c_cflag; | ||
457 | int bps; | ||
458 | long timeout; | ||
459 | wait_queue_t wait; | ||
460 | int result; | 481 | int result; |
461 | 482 | ||
462 | dbg("%s - port %d", __func__, port->number); | 483 | dbg("%s - port %d", __func__, port->number); |
463 | 484 | ||
464 | /* wait for data to drain from the buffer */ | ||
465 | spin_lock_irqsave(&priv->lock, flags); | 485 | spin_lock_irqsave(&priv->lock, flags); |
466 | timeout = SPCP8x5_CLOSING_WAIT; | ||
467 | init_waitqueue_entry(&wait, current); | ||
468 | add_wait_queue(&tty->write_wait, &wait); | ||
469 | for (;;) { | ||
470 | set_current_state(TASK_INTERRUPTIBLE); | ||
471 | if (ringbuf_avail_data(priv->buf) == 0 || | ||
472 | timeout == 0 || signal_pending(current)) | ||
473 | break; | ||
474 | spin_unlock_irqrestore(&priv->lock, flags); | ||
475 | timeout = schedule_timeout(timeout); | ||
476 | spin_lock_irqsave(&priv->lock, flags); | ||
477 | } | ||
478 | set_current_state(TASK_RUNNING); | ||
479 | remove_wait_queue(&tty->write_wait, &wait); | ||
480 | |||
481 | /* clear out any remaining data in the buffer */ | 486 | /* clear out any remaining data in the buffer */ |
482 | clear_ringbuf(priv->buf); | 487 | clear_ringbuf(priv->buf); |
483 | spin_unlock_irqrestore(&priv->lock, flags); | 488 | spin_unlock_irqrestore(&priv->lock, flags); |
484 | 489 | ||
485 | /* wait for characters to drain from the device (this is long enough | ||
486 | * for the entire all byte spcp8x5 hardware buffer to drain with no | ||
487 | * flow control for data rates of 1200 bps or more, for lower rates we | ||
488 | * should really know how much data is in the buffer to compute a delay | ||
489 | * that is not unnecessarily long) */ | ||
490 | bps = tty_get_baud_rate(tty); | ||
491 | if (bps > 1200) | ||
492 | timeout = max((HZ*2560) / bps, HZ/10); | ||
493 | else | ||
494 | timeout = 2*HZ; | ||
495 | set_current_state(TASK_INTERRUPTIBLE); | ||
496 | schedule_timeout(timeout); | ||
497 | |||
498 | /* clear control lines */ | ||
499 | if (tty) { | ||
500 | c_cflag = tty->termios->c_cflag; | ||
501 | if (c_cflag & HUPCL) { | ||
502 | spin_lock_irqsave(&priv->lock, flags); | ||
503 | priv->line_control = 0; | ||
504 | spin_unlock_irqrestore(&priv->lock, flags); | ||
505 | spcp8x5_set_ctrlLine(port->serial->dev, 0 , priv->type); | ||
506 | } | ||
507 | } | ||
508 | |||
509 | /* kill urb */ | 490 | /* kill urb */ |
510 | if (port->write_urb != NULL) { | 491 | if (port->write_urb != NULL) { |
511 | result = usb_unlink_urb(port->write_urb); | 492 | result = usb_unlink_urb(port->write_urb); |
@@ -665,13 +646,6 @@ static int spcp8x5_open(struct tty_struct *tty, | |||
665 | if (ret) | 646 | if (ret) |
666 | return ret; | 647 | return ret; |
667 | 648 | ||
668 | spin_lock_irqsave(&priv->lock, flags); | ||
669 | if (tty && (tty->termios->c_cflag & CBAUD)) | ||
670 | priv->line_control = MCR_DTR | MCR_RTS; | ||
671 | else | ||
672 | priv->line_control = 0; | ||
673 | spin_unlock_irqrestore(&priv->lock, flags); | ||
674 | |||
675 | spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type); | 649 | spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type); |
676 | 650 | ||
677 | /* Setup termios */ | 651 | /* Setup termios */ |
@@ -691,9 +665,10 @@ static int spcp8x5_open(struct tty_struct *tty, | |||
691 | port->read_urb->dev = serial->dev; | 665 | port->read_urb->dev = serial->dev; |
692 | ret = usb_submit_urb(port->read_urb, GFP_KERNEL); | 666 | ret = usb_submit_urb(port->read_urb, GFP_KERNEL); |
693 | if (ret) { | 667 | if (ret) { |
694 | spcp8x5_close(tty, port, NULL); | 668 | spcp8x5_close(port); |
695 | return -EPROTO; | 669 | return -EPROTO; |
696 | } | 670 | } |
671 | port->port.drain_delay = 256; | ||
697 | return 0; | 672 | return 0; |
698 | } | 673 | } |
699 | 674 | ||
@@ -1033,6 +1008,8 @@ static struct usb_serial_driver spcp8x5_device = { | |||
1033 | .num_ports = 1, | 1008 | .num_ports = 1, |
1034 | .open = spcp8x5_open, | 1009 | .open = spcp8x5_open, |
1035 | .close = spcp8x5_close, | 1010 | .close = spcp8x5_close, |
1011 | .dtr_rts = spcp8x5_dtr_rts, | ||
1012 | .carrier_raised = spcp8x5_carrier_raised, | ||
1036 | .write = spcp8x5_write, | 1013 | .write = spcp8x5_write, |
1037 | .set_termios = spcp8x5_set_termios, | 1014 | .set_termios = spcp8x5_set_termios, |
1038 | .ioctl = spcp8x5_ioctl, | 1015 | .ioctl = spcp8x5_ioctl, |
diff --git a/drivers/usb/serial/symbolserial.c b/drivers/usb/serial/symbolserial.c index 69879e437940..8b07ebc6baeb 100644 --- a/drivers/usb/serial/symbolserial.c +++ b/drivers/usb/serial/symbolserial.c | |||
@@ -152,8 +152,7 @@ static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
152 | return result; | 152 | return result; |
153 | } | 153 | } |
154 | 154 | ||
155 | static void symbol_close(struct tty_struct *tty, struct usb_serial_port *port, | 155 | static void symbol_close(struct usb_serial_port *port) |
156 | struct file *filp) | ||
157 | { | 156 | { |
158 | struct symbol_private *priv = usb_get_serial_data(port->serial); | 157 | struct symbol_private *priv = usb_get_serial_data(port->serial); |
159 | 158 | ||
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index 0a64bac306ee..42cb04c403be 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c | |||
@@ -100,8 +100,7 @@ static int ti_startup(struct usb_serial *serial); | |||
100 | static void ti_shutdown(struct usb_serial *serial); | 100 | static void ti_shutdown(struct usb_serial *serial); |
101 | static int ti_open(struct tty_struct *tty, struct usb_serial_port *port, | 101 | static int ti_open(struct tty_struct *tty, struct usb_serial_port *port, |
102 | struct file *file); | 102 | struct file *file); |
103 | static void ti_close(struct tty_struct *tty, struct usb_serial_port *port, | 103 | static void ti_close(struct usb_serial_port *port); |
104 | struct file *file); | ||
105 | static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, | 104 | static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, |
106 | const unsigned char *data, int count); | 105 | const unsigned char *data, int count); |
107 | static int ti_write_room(struct tty_struct *tty); | 106 | static int ti_write_room(struct tty_struct *tty); |
@@ -647,8 +646,7 @@ release_lock: | |||
647 | } | 646 | } |
648 | 647 | ||
649 | 648 | ||
650 | static void ti_close(struct tty_struct *tty, struct usb_serial_port *port, | 649 | static void ti_close(struct usb_serial_port *port) |
651 | struct file *file) | ||
652 | { | 650 | { |
653 | struct ti_device *tdev; | 651 | struct ti_device *tdev; |
654 | struct ti_port *tport; | 652 | struct ti_port *tport; |
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 0a566eea49c0..1967a7edc10c 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -238,9 +238,11 @@ static int serial_open (struct tty_struct *tty, struct file *filp) | |||
238 | goto bailout_interface_put; | 238 | goto bailout_interface_put; |
239 | mutex_unlock(&serial->disc_mutex); | 239 | mutex_unlock(&serial->disc_mutex); |
240 | } | 240 | } |
241 | |||
242 | mutex_unlock(&port->mutex); | 241 | mutex_unlock(&port->mutex); |
243 | return 0; | 242 | /* Now do the correct tty layer semantics */ |
243 | retval = tty_port_block_til_ready(&port->port, tty, filp); | ||
244 | if (retval == 0) | ||
245 | return 0; | ||
244 | 246 | ||
245 | bailout_interface_put: | 247 | bailout_interface_put: |
246 | usb_autopm_put_interface(serial->interface); | 248 | usb_autopm_put_interface(serial->interface); |
@@ -259,64 +261,89 @@ bailout_serial_put: | |||
259 | return retval; | 261 | return retval; |
260 | } | 262 | } |
261 | 263 | ||
262 | static void serial_close(struct tty_struct *tty, struct file *filp) | 264 | /** |
265 | * serial_do_down - shut down hardware | ||
266 | * @port: port to shut down | ||
267 | * | ||
268 | * Shut down a USB port unless it is the console. We never shut down the | ||
269 | * console hardware as it will always be in use. | ||
270 | * | ||
271 | * Don't free any resources at this point | ||
272 | */ | ||
273 | static void serial_do_down(struct usb_serial_port *port) | ||
263 | { | 274 | { |
264 | struct usb_serial_port *port = tty->driver_data; | 275 | struct usb_serial_driver *drv = port->serial->type; |
265 | struct usb_serial *serial; | 276 | struct usb_serial *serial; |
266 | struct module *owner; | 277 | struct module *owner; |
267 | int count; | ||
268 | 278 | ||
269 | if (!port) | 279 | /* The console is magical, do not hang up the console hardware |
280 | or there will be tears */ | ||
281 | if (port->console) | ||
270 | return; | 282 | return; |
271 | 283 | ||
272 | dbg("%s - port %d", __func__, port->number); | ||
273 | |||
274 | mutex_lock(&port->mutex); | 284 | mutex_lock(&port->mutex); |
275 | serial = port->serial; | 285 | serial = port->serial; |
276 | owner = serial->type->driver.owner; | 286 | owner = serial->type->driver.owner; |
277 | 287 | ||
278 | if (port->port.count == 0) { | 288 | if (drv->close) |
279 | mutex_unlock(&port->mutex); | 289 | drv->close(port); |
280 | return; | ||
281 | } | ||
282 | |||
283 | if (port->port.count == 1) | ||
284 | /* only call the device specific close if this | ||
285 | * port is being closed by the last owner. Ensure we do | ||
286 | * this before we drop the port count. The call is protected | ||
287 | * by the port mutex | ||
288 | */ | ||
289 | serial->type->close(tty, port, filp); | ||
290 | |||
291 | if (port->port.count == (port->console ? 2 : 1)) { | ||
292 | struct tty_struct *tty = tty_port_tty_get(&port->port); | ||
293 | if (tty) { | ||
294 | /* We must do this before we drop the port count to | ||
295 | zero. */ | ||
296 | if (tty->driver_data) | ||
297 | tty->driver_data = NULL; | ||
298 | tty_port_tty_set(&port->port, NULL); | ||
299 | tty_kref_put(tty); | ||
300 | } | ||
301 | } | ||
302 | 290 | ||
303 | --port->port.count; | ||
304 | count = port->port.count; | ||
305 | mutex_unlock(&port->mutex); | 291 | mutex_unlock(&port->mutex); |
306 | put_device(&port->dev); | 292 | } |
293 | |||
294 | /** | ||
295 | * serial_do_free - free resources post close/hangup | ||
296 | * @port: port to free up | ||
297 | * | ||
298 | * Do the resource freeing and refcount dropping for the port. We must | ||
299 | * be careful about ordering and we must avoid freeing up the console. | ||
300 | */ | ||
307 | 301 | ||
302 | static void serial_do_free(struct usb_serial_port *port) | ||
303 | { | ||
304 | struct usb_serial *serial; | ||
305 | struct module *owner; | ||
306 | |||
307 | /* The console is magical, do not hang up the console hardware | ||
308 | or there will be tears */ | ||
309 | if (port->console) | ||
310 | return; | ||
311 | |||
312 | serial = port->serial; | ||
313 | owner = serial->type->driver.owner; | ||
314 | put_device(&port->dev); | ||
308 | /* Mustn't dereference port any more */ | 315 | /* Mustn't dereference port any more */ |
309 | if (count == 0) { | 316 | mutex_lock(&serial->disc_mutex); |
310 | mutex_lock(&serial->disc_mutex); | 317 | if (!serial->disconnected) |
311 | if (!serial->disconnected) | 318 | usb_autopm_put_interface(serial->interface); |
312 | usb_autopm_put_interface(serial->interface); | 319 | mutex_unlock(&serial->disc_mutex); |
313 | mutex_unlock(&serial->disc_mutex); | ||
314 | } | ||
315 | usb_serial_put(serial); | 320 | usb_serial_put(serial); |
316 | |||
317 | /* Mustn't dereference serial any more */ | 321 | /* Mustn't dereference serial any more */ |
318 | if (count == 0) | 322 | module_put(owner); |
319 | module_put(owner); | 323 | } |
324 | |||
325 | static void serial_close(struct tty_struct *tty, struct file *filp) | ||
326 | { | ||
327 | struct usb_serial_port *port = tty->driver_data; | ||
328 | |||
329 | dbg("%s - port %d", __func__, port->number); | ||
330 | |||
331 | |||
332 | if (tty_port_close_start(&port->port, tty, filp) == 0) | ||
333 | return; | ||
334 | |||
335 | serial_do_down(port); | ||
336 | tty_port_close_end(&port->port, tty); | ||
337 | tty_port_tty_set(&port->port, NULL); | ||
338 | serial_do_free(port); | ||
339 | } | ||
340 | |||
341 | static void serial_hangup(struct tty_struct *tty) | ||
342 | { | ||
343 | struct usb_serial_port *port = tty->driver_data; | ||
344 | serial_do_down(port); | ||
345 | tty_port_hangup(&port->port); | ||
346 | serial_do_free(port); | ||
320 | } | 347 | } |
321 | 348 | ||
322 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, | 349 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, |
@@ -648,6 +675,29 @@ static struct usb_serial_driver *search_serial_device( | |||
648 | return NULL; | 675 | return NULL; |
649 | } | 676 | } |
650 | 677 | ||
678 | static int serial_carrier_raised(struct tty_port *port) | ||
679 | { | ||
680 | struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); | ||
681 | struct usb_serial_driver *drv = p->serial->type; | ||
682 | if (drv->carrier_raised) | ||
683 | return drv->carrier_raised(p); | ||
684 | /* No carrier control - don't block */ | ||
685 | return 1; | ||
686 | } | ||
687 | |||
688 | static void serial_dtr_rts(struct tty_port *port, int on) | ||
689 | { | ||
690 | struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); | ||
691 | struct usb_serial_driver *drv = p->serial->type; | ||
692 | if (drv->dtr_rts) | ||
693 | drv->dtr_rts(p, on); | ||
694 | } | ||
695 | |||
696 | static const struct tty_port_operations serial_port_ops = { | ||
697 | .carrier_raised = serial_carrier_raised, | ||
698 | .dtr_rts = serial_dtr_rts, | ||
699 | }; | ||
700 | |||
651 | int usb_serial_probe(struct usb_interface *interface, | 701 | int usb_serial_probe(struct usb_interface *interface, |
652 | const struct usb_device_id *id) | 702 | const struct usb_device_id *id) |
653 | { | 703 | { |
@@ -841,6 +891,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
841 | if (!port) | 891 | if (!port) |
842 | goto probe_error; | 892 | goto probe_error; |
843 | tty_port_init(&port->port); | 893 | tty_port_init(&port->port); |
894 | port->port.ops = &serial_port_ops; | ||
844 | port->serial = serial; | 895 | port->serial = serial; |
845 | spin_lock_init(&port->lock); | 896 | spin_lock_init(&port->lock); |
846 | mutex_init(&port->mutex); | 897 | mutex_init(&port->mutex); |
@@ -974,6 +1025,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
974 | if (retval > 0) { | 1025 | if (retval > 0) { |
975 | /* quietly accept this device, but don't bind to a | 1026 | /* quietly accept this device, but don't bind to a |
976 | serial port as it's about to disappear */ | 1027 | serial port as it's about to disappear */ |
1028 | serial->num_ports = 0; | ||
977 | goto exit; | 1029 | goto exit; |
978 | } | 1030 | } |
979 | } | 1031 | } |
@@ -1070,6 +1122,9 @@ void usb_serial_disconnect(struct usb_interface *interface) | |||
1070 | if (port) { | 1122 | if (port) { |
1071 | struct tty_struct *tty = tty_port_tty_get(&port->port); | 1123 | struct tty_struct *tty = tty_port_tty_get(&port->port); |
1072 | if (tty) { | 1124 | if (tty) { |
1125 | /* The hangup will occur asynchronously but | ||
1126 | the object refcounts will sort out all the | ||
1127 | cleanup */ | ||
1073 | tty_hangup(tty); | 1128 | tty_hangup(tty); |
1074 | tty_kref_put(tty); | 1129 | tty_kref_put(tty); |
1075 | } | 1130 | } |
@@ -1134,6 +1189,7 @@ static const struct tty_operations serial_ops = { | |||
1134 | .open = serial_open, | 1189 | .open = serial_open, |
1135 | .close = serial_close, | 1190 | .close = serial_close, |
1136 | .write = serial_write, | 1191 | .write = serial_write, |
1192 | .hangup = serial_hangup, | ||
1137 | .write_room = serial_write_room, | 1193 | .write_room = serial_write_room, |
1138 | .ioctl = serial_ioctl, | 1194 | .ioctl = serial_ioctl, |
1139 | .set_termios = serial_set_termios, | 1195 | .set_termios = serial_set_termios, |
@@ -1146,6 +1202,7 @@ static const struct tty_operations serial_ops = { | |||
1146 | .proc_fops = &serial_proc_fops, | 1202 | .proc_fops = &serial_proc_fops, |
1147 | }; | 1203 | }; |
1148 | 1204 | ||
1205 | |||
1149 | struct tty_driver *usb_serial_tty_driver; | 1206 | struct tty_driver *usb_serial_tty_driver; |
1150 | 1207 | ||
1151 | static int __init usb_serial_init(void) | 1208 | static int __init usb_serial_init(void) |
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c index 5ac414bda718..b15f1c0e1d4a 100644 --- a/drivers/usb/serial/visor.c +++ b/drivers/usb/serial/visor.c | |||
@@ -38,8 +38,7 @@ | |||
38 | /* function prototypes for a handspring visor */ | 38 | /* function prototypes for a handspring visor */ |
39 | static int visor_open(struct tty_struct *tty, struct usb_serial_port *port, | 39 | static int visor_open(struct tty_struct *tty, struct usb_serial_port *port, |
40 | struct file *filp); | 40 | struct file *filp); |
41 | static void visor_close(struct tty_struct *tty, struct usb_serial_port *port, | 41 | static void visor_close(struct usb_serial_port *port); |
42 | struct file *filp); | ||
43 | static int visor_write(struct tty_struct *tty, struct usb_serial_port *port, | 42 | static int visor_write(struct tty_struct *tty, struct usb_serial_port *port, |
44 | const unsigned char *buf, int count); | 43 | const unsigned char *buf, int count); |
45 | static int visor_write_room(struct tty_struct *tty); | 44 | static int visor_write_room(struct tty_struct *tty); |
@@ -324,8 +323,7 @@ exit: | |||
324 | } | 323 | } |
325 | 324 | ||
326 | 325 | ||
327 | static void visor_close(struct tty_struct *tty, | 326 | static void visor_close(struct usb_serial_port *port) |
328 | struct usb_serial_port *port, struct file *filp) | ||
329 | { | 327 | { |
330 | struct visor_private *priv = usb_get_serial_port_data(port); | 328 | struct visor_private *priv = usb_get_serial_port_data(port); |
331 | unsigned char *transfer_buffer; | 329 | unsigned char *transfer_buffer; |
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c index 5335d3211c07..7c7295d09f34 100644 --- a/drivers/usb/serial/whiteheat.c +++ b/drivers/usb/serial/whiteheat.c | |||
@@ -147,8 +147,7 @@ static int whiteheat_attach(struct usb_serial *serial); | |||
147 | static void whiteheat_shutdown(struct usb_serial *serial); | 147 | static void whiteheat_shutdown(struct usb_serial *serial); |
148 | static int whiteheat_open(struct tty_struct *tty, | 148 | static int whiteheat_open(struct tty_struct *tty, |
149 | struct usb_serial_port *port, struct file *filp); | 149 | struct usb_serial_port *port, struct file *filp); |
150 | static void whiteheat_close(struct tty_struct *tty, | 150 | static void whiteheat_close(struct usb_serial_port *port); |
151 | struct usb_serial_port *port, struct file *filp); | ||
152 | static int whiteheat_write(struct tty_struct *tty, | 151 | static int whiteheat_write(struct tty_struct *tty, |
153 | struct usb_serial_port *port, | 152 | struct usb_serial_port *port, |
154 | const unsigned char *buf, int count); | 153 | const unsigned char *buf, int count); |
@@ -712,8 +711,7 @@ exit: | |||
712 | } | 711 | } |
713 | 712 | ||
714 | 713 | ||
715 | static void whiteheat_close(struct tty_struct *tty, | 714 | static void whiteheat_close(struct usb_serial_port *port) |
716 | struct usb_serial_port *port, struct file *filp) | ||
717 | { | 715 | { |
718 | struct whiteheat_private *info = usb_get_serial_port_data(port); | 716 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
719 | struct whiteheat_urb_wrap *wrap; | 717 | struct whiteheat_urb_wrap *wrap; |
@@ -723,31 +721,7 @@ static void whiteheat_close(struct tty_struct *tty, | |||
723 | 721 | ||
724 | dbg("%s - port %d", __func__, port->number); | 722 | dbg("%s - port %d", __func__, port->number); |
725 | 723 | ||
726 | mutex_lock(&port->serial->disc_mutex); | ||
727 | /* filp is NULL when called from usb_serial_disconnect */ | ||
728 | if ((filp && (tty_hung_up_p(filp))) || port->serial->disconnected) { | ||
729 | mutex_unlock(&port->serial->disc_mutex); | ||
730 | return; | ||
731 | } | ||
732 | mutex_unlock(&port->serial->disc_mutex); | ||
733 | |||
734 | tty->closing = 1; | ||
735 | |||
736 | /* | ||
737 | * Not currently in use; tty_wait_until_sent() calls | ||
738 | * serial_chars_in_buffer() which deadlocks on the second semaphore | ||
739 | * acquisition. This should be fixed at some point. Greg's been | ||
740 | * notified. | ||
741 | if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) { | ||
742 | tty_wait_until_sent(tty, CLOSING_DELAY); | ||
743 | } | ||
744 | */ | ||
745 | |||
746 | tty_driver_flush_buffer(tty); | ||
747 | tty_ldisc_flush(tty); | ||
748 | |||
749 | firm_report_tx_done(port); | 724 | firm_report_tx_done(port); |
750 | |||
751 | firm_close(port); | 725 | firm_close(port); |
752 | 726 | ||
753 | /* shutdown our bulk reads and writes */ | 727 | /* shutdown our bulk reads and writes */ |
@@ -775,10 +749,7 @@ static void whiteheat_close(struct tty_struct *tty, | |||
775 | } | 749 | } |
776 | spin_unlock_irq(&info->lock); | 750 | spin_unlock_irq(&info->lock); |
777 | mutex_unlock(&info->deathwarrant); | 751 | mutex_unlock(&info->deathwarrant); |
778 | |||
779 | stop_command_port(port->serial); | 752 | stop_command_port(port->serial); |
780 | |||
781 | tty->closing = 0; | ||
782 | } | 753 | } |
783 | 754 | ||
784 | 755 | ||
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c index 9a577a800db5..2fb63f6ea2f1 100644 --- a/drivers/video/atmel_lcdfb.c +++ b/drivers/video/atmel_lcdfb.c | |||
@@ -29,14 +29,8 @@ | |||
29 | 29 | ||
30 | /* configurable parameters */ | 30 | /* configurable parameters */ |
31 | #define ATMEL_LCDC_CVAL_DEFAULT 0xc8 | 31 | #define ATMEL_LCDC_CVAL_DEFAULT 0xc8 |
32 | #define ATMEL_LCDC_DMA_BURST_LEN 8 | 32 | #define ATMEL_LCDC_DMA_BURST_LEN 8 /* words */ |
33 | 33 | #define ATMEL_LCDC_FIFO_SIZE 512 /* words */ | |
34 | #if defined(CONFIG_ARCH_AT91SAM9263) || defined(CONFIG_ARCH_AT91CAP9) || \ | ||
35 | defined(CONFIG_ARCH_AT91SAM9RL) | ||
36 | #define ATMEL_LCDC_FIFO_SIZE 2048 | ||
37 | #else | ||
38 | #define ATMEL_LCDC_FIFO_SIZE 512 | ||
39 | #endif | ||
40 | 34 | ||
41 | #if defined(CONFIG_ARCH_AT91) | 35 | #if defined(CONFIG_ARCH_AT91) |
42 | #define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \ | 36 | #define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \ |
diff --git a/drivers/video/hitfb.c b/drivers/video/hitfb.c index e6467cf9f19f..020db7fc9153 100644 --- a/drivers/video/hitfb.c +++ b/drivers/video/hitfb.c | |||
@@ -335,9 +335,9 @@ static int __init hitfb_probe(struct platform_device *dev) | |||
335 | if (fb_get_options("hitfb", NULL)) | 335 | if (fb_get_options("hitfb", NULL)) |
336 | return -ENODEV; | 336 | return -ENODEV; |
337 | 337 | ||
338 | hitfb_fix.mmio_start = CONFIG_HD64461_IOBASE+0x1000; | 338 | hitfb_fix.mmio_start = HD64461_IO_OFFSET(0x1000); |
339 | hitfb_fix.mmio_len = 0x1000; | 339 | hitfb_fix.mmio_len = 0x1000; |
340 | hitfb_fix.smem_start = CONFIG_HD64461_IOBASE + 0x02000000; | 340 | hitfb_fix.smem_start = HD64461_IO_OFFSET(0x02000000); |
341 | hitfb_fix.smem_len = 512 * 1024; | 341 | hitfb_fix.smem_len = 512 * 1024; |
342 | 342 | ||
343 | lcdclor = fb_readw(HD64461_LCDCLOR); | 343 | lcdclor = fb_readw(HD64461_LCDCLOR); |
diff --git a/drivers/video/s3c-fb.c b/drivers/video/s3c-fb.c index 5e9c6302433b..d3a568e6b169 100644 --- a/drivers/video/s3c-fb.c +++ b/drivers/video/s3c-fb.c | |||
@@ -947,7 +947,8 @@ static int __devexit s3c_fb_remove(struct platform_device *pdev) | |||
947 | int win; | 947 | int win; |
948 | 948 | ||
949 | for (win = 0; win <= S3C_FB_MAX_WIN; win++) | 949 | for (win = 0; win <= S3C_FB_MAX_WIN; win++) |
950 | s3c_fb_release_win(sfb, sfb->windows[win]); | 950 | if (sfb->windows[win]) |
951 | s3c_fb_release_win(sfb, sfb->windows[win]); | ||
951 | 952 | ||
952 | iounmap(sfb->regs); | 953 | iounmap(sfb->regs); |
953 | 954 | ||
@@ -985,11 +986,20 @@ static int s3c_fb_suspend(struct platform_device *pdev, pm_message_t state) | |||
985 | static int s3c_fb_resume(struct platform_device *pdev) | 986 | static int s3c_fb_resume(struct platform_device *pdev) |
986 | { | 987 | { |
987 | struct s3c_fb *sfb = platform_get_drvdata(pdev); | 988 | struct s3c_fb *sfb = platform_get_drvdata(pdev); |
989 | struct s3c_fb_platdata *pd = sfb->pdata; | ||
988 | struct s3c_fb_win *win; | 990 | struct s3c_fb_win *win; |
989 | int win_no; | 991 | int win_no; |
990 | 992 | ||
991 | clk_enable(sfb->bus_clk); | 993 | clk_enable(sfb->bus_clk); |
992 | 994 | ||
995 | /* setup registers */ | ||
996 | writel(pd->vidcon1, sfb->regs + VIDCON1); | ||
997 | |||
998 | /* zero all windows before we do anything */ | ||
999 | for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) | ||
1000 | s3c_fb_clear_win(sfb, win_no); | ||
1001 | |||
1002 | /* restore framebuffers */ | ||
993 | for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) { | 1003 | for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) { |
994 | win = sfb->windows[win_no]; | 1004 | win = sfb->windows[win_no]; |
995 | if (!win) | 1005 | if (!win) |
diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig index 8ac9cddac575..cab100acf983 100644 --- a/drivers/xen/Kconfig +++ b/drivers/xen/Kconfig | |||
@@ -18,6 +18,16 @@ config XEN_SCRUB_PAGES | |||
18 | secure, but slightly less efficient. | 18 | secure, but slightly less efficient. |
19 | If in doubt, say yes. | 19 | If in doubt, say yes. |
20 | 20 | ||
21 | config XEN_DEV_EVTCHN | ||
22 | tristate "Xen /dev/xen/evtchn device" | ||
23 | depends on XEN | ||
24 | default y | ||
25 | help | ||
26 | The evtchn driver allows a userspace process to triger event | ||
27 | channels and to receive notification of an event channel | ||
28 | firing. | ||
29 | If in doubt, say yes. | ||
30 | |||
21 | config XENFS | 31 | config XENFS |
22 | tristate "Xen filesystem" | 32 | tristate "Xen filesystem" |
23 | depends on XEN | 33 | depends on XEN |
@@ -41,3 +51,13 @@ config XEN_COMPAT_XENFS | |||
41 | a xen platform. | 51 | a xen platform. |
42 | If in doubt, say yes. | 52 | If in doubt, say yes. |
43 | 53 | ||
54 | config XEN_SYS_HYPERVISOR | ||
55 | bool "Create xen entries under /sys/hypervisor" | ||
56 | depends on XEN && SYSFS | ||
57 | select SYS_HYPERVISOR | ||
58 | default y | ||
59 | help | ||
60 | Create entries under /sys/hypervisor describing the Xen | ||
61 | hypervisor environment. When running native or in another | ||
62 | virtual environment, /sys/hypervisor will still be present, | ||
63 | but will have no xen contents. \ No newline at end of file | ||
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile index ff8accc9e103..ec2a39b1e26f 100644 --- a/drivers/xen/Makefile +++ b/drivers/xen/Makefile | |||
@@ -4,4 +4,6 @@ obj-y += xenbus/ | |||
4 | obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o | 4 | obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o |
5 | obj-$(CONFIG_XEN_XENCOMM) += xencomm.o | 5 | obj-$(CONFIG_XEN_XENCOMM) += xencomm.o |
6 | obj-$(CONFIG_XEN_BALLOON) += balloon.o | 6 | obj-$(CONFIG_XEN_BALLOON) += balloon.o |
7 | obj-$(CONFIG_XENFS) += xenfs/ \ No newline at end of file | 7 | obj-$(CONFIG_XEN_DEV_EVTCHN) += evtchn.o |
8 | obj-$(CONFIG_XENFS) += xenfs/ | ||
9 | obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o \ No newline at end of file | ||
diff --git a/drivers/xen/events.c b/drivers/xen/events.c index 30963af5dba0..891d2e90753a 100644 --- a/drivers/xen/events.c +++ b/drivers/xen/events.c | |||
@@ -151,6 +151,12 @@ static unsigned int evtchn_from_irq(unsigned irq) | |||
151 | return info_for_irq(irq)->evtchn; | 151 | return info_for_irq(irq)->evtchn; |
152 | } | 152 | } |
153 | 153 | ||
154 | unsigned irq_from_evtchn(unsigned int evtchn) | ||
155 | { | ||
156 | return evtchn_to_irq[evtchn]; | ||
157 | } | ||
158 | EXPORT_SYMBOL_GPL(irq_from_evtchn); | ||
159 | |||
154 | static enum ipi_vector ipi_from_irq(unsigned irq) | 160 | static enum ipi_vector ipi_from_irq(unsigned irq) |
155 | { | 161 | { |
156 | struct irq_info *info = info_for_irq(irq); | 162 | struct irq_info *info = info_for_irq(irq); |
@@ -335,7 +341,7 @@ static int find_unbound_irq(void) | |||
335 | if (irq == nr_irqs) | 341 | if (irq == nr_irqs) |
336 | panic("No available IRQ to bind to: increase nr_irqs!\n"); | 342 | panic("No available IRQ to bind to: increase nr_irqs!\n"); |
337 | 343 | ||
338 | desc = irq_to_desc_alloc_cpu(irq, 0); | 344 | desc = irq_to_desc_alloc_node(irq, 0); |
339 | if (WARN_ON(desc == NULL)) | 345 | if (WARN_ON(desc == NULL)) |
340 | return -1; | 346 | return -1; |
341 | 347 | ||
@@ -688,13 +694,13 @@ void rebind_evtchn_irq(int evtchn, int irq) | |||
688 | } | 694 | } |
689 | 695 | ||
690 | /* Rebind an evtchn so that it gets delivered to a specific cpu */ | 696 | /* Rebind an evtchn so that it gets delivered to a specific cpu */ |
691 | static void rebind_irq_to_cpu(unsigned irq, unsigned tcpu) | 697 | static int rebind_irq_to_cpu(unsigned irq, unsigned tcpu) |
692 | { | 698 | { |
693 | struct evtchn_bind_vcpu bind_vcpu; | 699 | struct evtchn_bind_vcpu bind_vcpu; |
694 | int evtchn = evtchn_from_irq(irq); | 700 | int evtchn = evtchn_from_irq(irq); |
695 | 701 | ||
696 | if (!VALID_EVTCHN(evtchn)) | 702 | if (!VALID_EVTCHN(evtchn)) |
697 | return; | 703 | return -1; |
698 | 704 | ||
699 | /* Send future instances of this interrupt to other vcpu. */ | 705 | /* Send future instances of this interrupt to other vcpu. */ |
700 | bind_vcpu.port = evtchn; | 706 | bind_vcpu.port = evtchn; |
@@ -707,13 +713,15 @@ static void rebind_irq_to_cpu(unsigned irq, unsigned tcpu) | |||
707 | */ | 713 | */ |
708 | if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >= 0) | 714 | if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >= 0) |
709 | bind_evtchn_to_cpu(evtchn, tcpu); | 715 | bind_evtchn_to_cpu(evtchn, tcpu); |
710 | } | ||
711 | 716 | ||
717 | return 0; | ||
718 | } | ||
712 | 719 | ||
713 | static void set_affinity_irq(unsigned irq, const struct cpumask *dest) | 720 | static int set_affinity_irq(unsigned irq, const struct cpumask *dest) |
714 | { | 721 | { |
715 | unsigned tcpu = cpumask_first(dest); | 722 | unsigned tcpu = cpumask_first(dest); |
716 | rebind_irq_to_cpu(irq, tcpu); | 723 | |
724 | return rebind_irq_to_cpu(irq, tcpu); | ||
717 | } | 725 | } |
718 | 726 | ||
719 | int resend_irq_on_evtchn(unsigned int irq) | 727 | int resend_irq_on_evtchn(unsigned int irq) |
diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c new file mode 100644 index 000000000000..af031950f9b1 --- /dev/null +++ b/drivers/xen/evtchn.c | |||
@@ -0,0 +1,507 @@ | |||
1 | /****************************************************************************** | ||
2 | * evtchn.c | ||
3 | * | ||
4 | * Driver for receiving and demuxing event-channel signals. | ||
5 | * | ||
6 | * Copyright (c) 2004-2005, K A Fraser | ||
7 | * Multi-process extensions Copyright (c) 2004, Steven Smith | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License version 2 | ||
11 | * as published by the Free Software Foundation; or, when distributed | ||
12 | * separately from the Linux kernel or incorporated into other | ||
13 | * software packages, subject to the following license: | ||
14 | * | ||
15 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
16 | * of this source file (the "Software"), to deal in the Software without | ||
17 | * restriction, including without limitation the rights to use, copy, modify, | ||
18 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
19 | * and to permit persons to whom the Software is furnished to do so, subject to | ||
20 | * the following conditions: | ||
21 | * | ||
22 | * The above copyright notice and this permission notice shall be included in | ||
23 | * all copies or substantial portions of the Software. | ||
24 | * | ||
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
30 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
31 | * IN THE SOFTWARE. | ||
32 | */ | ||
33 | |||
34 | #include <linux/module.h> | ||
35 | #include <linux/kernel.h> | ||
36 | #include <linux/sched.h> | ||
37 | #include <linux/slab.h> | ||
38 | #include <linux/string.h> | ||
39 | #include <linux/errno.h> | ||
40 | #include <linux/fs.h> | ||
41 | #include <linux/errno.h> | ||
42 | #include <linux/miscdevice.h> | ||
43 | #include <linux/major.h> | ||
44 | #include <linux/proc_fs.h> | ||
45 | #include <linux/stat.h> | ||
46 | #include <linux/poll.h> | ||
47 | #include <linux/irq.h> | ||
48 | #include <linux/init.h> | ||
49 | #include <linux/gfp.h> | ||
50 | #include <linux/mutex.h> | ||
51 | #include <linux/cpu.h> | ||
52 | #include <xen/events.h> | ||
53 | #include <xen/evtchn.h> | ||
54 | #include <asm/xen/hypervisor.h> | ||
55 | |||
56 | struct per_user_data { | ||
57 | struct mutex bind_mutex; /* serialize bind/unbind operations */ | ||
58 | |||
59 | /* Notification ring, accessed via /dev/xen/evtchn. */ | ||
60 | #define EVTCHN_RING_SIZE (PAGE_SIZE / sizeof(evtchn_port_t)) | ||
61 | #define EVTCHN_RING_MASK(_i) ((_i)&(EVTCHN_RING_SIZE-1)) | ||
62 | evtchn_port_t *ring; | ||
63 | unsigned int ring_cons, ring_prod, ring_overflow; | ||
64 | struct mutex ring_cons_mutex; /* protect against concurrent readers */ | ||
65 | |||
66 | /* Processes wait on this queue when ring is empty. */ | ||
67 | wait_queue_head_t evtchn_wait; | ||
68 | struct fasync_struct *evtchn_async_queue; | ||
69 | const char *name; | ||
70 | }; | ||
71 | |||
72 | /* Who's bound to each port? */ | ||
73 | static struct per_user_data *port_user[NR_EVENT_CHANNELS]; | ||
74 | static DEFINE_SPINLOCK(port_user_lock); /* protects port_user[] and ring_prod */ | ||
75 | |||
76 | irqreturn_t evtchn_interrupt(int irq, void *data) | ||
77 | { | ||
78 | unsigned int port = (unsigned long)data; | ||
79 | struct per_user_data *u; | ||
80 | |||
81 | spin_lock(&port_user_lock); | ||
82 | |||
83 | u = port_user[port]; | ||
84 | |||
85 | disable_irq_nosync(irq); | ||
86 | |||
87 | if ((u->ring_prod - u->ring_cons) < EVTCHN_RING_SIZE) { | ||
88 | u->ring[EVTCHN_RING_MASK(u->ring_prod)] = port; | ||
89 | wmb(); /* Ensure ring contents visible */ | ||
90 | if (u->ring_cons == u->ring_prod++) { | ||
91 | wake_up_interruptible(&u->evtchn_wait); | ||
92 | kill_fasync(&u->evtchn_async_queue, | ||
93 | SIGIO, POLL_IN); | ||
94 | } | ||
95 | } else { | ||
96 | u->ring_overflow = 1; | ||
97 | } | ||
98 | |||
99 | spin_unlock(&port_user_lock); | ||
100 | |||
101 | return IRQ_HANDLED; | ||
102 | } | ||
103 | |||
104 | static ssize_t evtchn_read(struct file *file, char __user *buf, | ||
105 | size_t count, loff_t *ppos) | ||
106 | { | ||
107 | int rc; | ||
108 | unsigned int c, p, bytes1 = 0, bytes2 = 0; | ||
109 | struct per_user_data *u = file->private_data; | ||
110 | |||
111 | /* Whole number of ports. */ | ||
112 | count &= ~(sizeof(evtchn_port_t)-1); | ||
113 | |||
114 | if (count == 0) | ||
115 | return 0; | ||
116 | |||
117 | if (count > PAGE_SIZE) | ||
118 | count = PAGE_SIZE; | ||
119 | |||
120 | for (;;) { | ||
121 | mutex_lock(&u->ring_cons_mutex); | ||
122 | |||
123 | rc = -EFBIG; | ||
124 | if (u->ring_overflow) | ||
125 | goto unlock_out; | ||
126 | |||
127 | c = u->ring_cons; | ||
128 | p = u->ring_prod; | ||
129 | if (c != p) | ||
130 | break; | ||
131 | |||
132 | mutex_unlock(&u->ring_cons_mutex); | ||
133 | |||
134 | if (file->f_flags & O_NONBLOCK) | ||
135 | return -EAGAIN; | ||
136 | |||
137 | rc = wait_event_interruptible(u->evtchn_wait, | ||
138 | u->ring_cons != u->ring_prod); | ||
139 | if (rc) | ||
140 | return rc; | ||
141 | } | ||
142 | |||
143 | /* Byte lengths of two chunks. Chunk split (if any) is at ring wrap. */ | ||
144 | if (((c ^ p) & EVTCHN_RING_SIZE) != 0) { | ||
145 | bytes1 = (EVTCHN_RING_SIZE - EVTCHN_RING_MASK(c)) * | ||
146 | sizeof(evtchn_port_t); | ||
147 | bytes2 = EVTCHN_RING_MASK(p) * sizeof(evtchn_port_t); | ||
148 | } else { | ||
149 | bytes1 = (p - c) * sizeof(evtchn_port_t); | ||
150 | bytes2 = 0; | ||
151 | } | ||
152 | |||
153 | /* Truncate chunks according to caller's maximum byte count. */ | ||
154 | if (bytes1 > count) { | ||
155 | bytes1 = count; | ||
156 | bytes2 = 0; | ||
157 | } else if ((bytes1 + bytes2) > count) { | ||
158 | bytes2 = count - bytes1; | ||
159 | } | ||
160 | |||
161 | rc = -EFAULT; | ||
162 | rmb(); /* Ensure that we see the port before we copy it. */ | ||
163 | if (copy_to_user(buf, &u->ring[EVTCHN_RING_MASK(c)], bytes1) || | ||
164 | ((bytes2 != 0) && | ||
165 | copy_to_user(&buf[bytes1], &u->ring[0], bytes2))) | ||
166 | goto unlock_out; | ||
167 | |||
168 | u->ring_cons += (bytes1 + bytes2) / sizeof(evtchn_port_t); | ||
169 | rc = bytes1 + bytes2; | ||
170 | |||
171 | unlock_out: | ||
172 | mutex_unlock(&u->ring_cons_mutex); | ||
173 | return rc; | ||
174 | } | ||
175 | |||
176 | static ssize_t evtchn_write(struct file *file, const char __user *buf, | ||
177 | size_t count, loff_t *ppos) | ||
178 | { | ||
179 | int rc, i; | ||
180 | evtchn_port_t *kbuf = (evtchn_port_t *)__get_free_page(GFP_KERNEL); | ||
181 | struct per_user_data *u = file->private_data; | ||
182 | |||
183 | if (kbuf == NULL) | ||
184 | return -ENOMEM; | ||
185 | |||
186 | /* Whole number of ports. */ | ||
187 | count &= ~(sizeof(evtchn_port_t)-1); | ||
188 | |||
189 | rc = 0; | ||
190 | if (count == 0) | ||
191 | goto out; | ||
192 | |||
193 | if (count > PAGE_SIZE) | ||
194 | count = PAGE_SIZE; | ||
195 | |||
196 | rc = -EFAULT; | ||
197 | if (copy_from_user(kbuf, buf, count) != 0) | ||
198 | goto out; | ||
199 | |||
200 | spin_lock_irq(&port_user_lock); | ||
201 | for (i = 0; i < (count/sizeof(evtchn_port_t)); i++) | ||
202 | if ((kbuf[i] < NR_EVENT_CHANNELS) && (port_user[kbuf[i]] == u)) | ||
203 | enable_irq(irq_from_evtchn(kbuf[i])); | ||
204 | spin_unlock_irq(&port_user_lock); | ||
205 | |||
206 | rc = count; | ||
207 | |||
208 | out: | ||
209 | free_page((unsigned long)kbuf); | ||
210 | return rc; | ||
211 | } | ||
212 | |||
213 | static int evtchn_bind_to_user(struct per_user_data *u, int port) | ||
214 | { | ||
215 | int rc = 0; | ||
216 | |||
217 | /* | ||
218 | * Ports are never reused, so every caller should pass in a | ||
219 | * unique port. | ||
220 | * | ||
221 | * (Locking not necessary because we haven't registered the | ||
222 | * interrupt handler yet, and our caller has already | ||
223 | * serialized bind operations.) | ||
224 | */ | ||
225 | BUG_ON(port_user[port] != NULL); | ||
226 | port_user[port] = u; | ||
227 | |||
228 | rc = bind_evtchn_to_irqhandler(port, evtchn_interrupt, IRQF_DISABLED, | ||
229 | u->name, (void *)(unsigned long)port); | ||
230 | if (rc >= 0) | ||
231 | rc = 0; | ||
232 | |||
233 | return rc; | ||
234 | } | ||
235 | |||
236 | static void evtchn_unbind_from_user(struct per_user_data *u, int port) | ||
237 | { | ||
238 | int irq = irq_from_evtchn(port); | ||
239 | |||
240 | unbind_from_irqhandler(irq, (void *)(unsigned long)port); | ||
241 | |||
242 | /* make sure we unbind the irq handler before clearing the port */ | ||
243 | barrier(); | ||
244 | |||
245 | port_user[port] = NULL; | ||
246 | } | ||
247 | |||
248 | static long evtchn_ioctl(struct file *file, | ||
249 | unsigned int cmd, unsigned long arg) | ||
250 | { | ||
251 | int rc; | ||
252 | struct per_user_data *u = file->private_data; | ||
253 | void __user *uarg = (void __user *) arg; | ||
254 | |||
255 | /* Prevent bind from racing with unbind */ | ||
256 | mutex_lock(&u->bind_mutex); | ||
257 | |||
258 | switch (cmd) { | ||
259 | case IOCTL_EVTCHN_BIND_VIRQ: { | ||
260 | struct ioctl_evtchn_bind_virq bind; | ||
261 | struct evtchn_bind_virq bind_virq; | ||
262 | |||
263 | rc = -EFAULT; | ||
264 | if (copy_from_user(&bind, uarg, sizeof(bind))) | ||
265 | break; | ||
266 | |||
267 | bind_virq.virq = bind.virq; | ||
268 | bind_virq.vcpu = 0; | ||
269 | rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, | ||
270 | &bind_virq); | ||
271 | if (rc != 0) | ||
272 | break; | ||
273 | |||
274 | rc = evtchn_bind_to_user(u, bind_virq.port); | ||
275 | if (rc == 0) | ||
276 | rc = bind_virq.port; | ||
277 | break; | ||
278 | } | ||
279 | |||
280 | case IOCTL_EVTCHN_BIND_INTERDOMAIN: { | ||
281 | struct ioctl_evtchn_bind_interdomain bind; | ||
282 | struct evtchn_bind_interdomain bind_interdomain; | ||
283 | |||
284 | rc = -EFAULT; | ||
285 | if (copy_from_user(&bind, uarg, sizeof(bind))) | ||
286 | break; | ||
287 | |||
288 | bind_interdomain.remote_dom = bind.remote_domain; | ||
289 | bind_interdomain.remote_port = bind.remote_port; | ||
290 | rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, | ||
291 | &bind_interdomain); | ||
292 | if (rc != 0) | ||
293 | break; | ||
294 | |||
295 | rc = evtchn_bind_to_user(u, bind_interdomain.local_port); | ||
296 | if (rc == 0) | ||
297 | rc = bind_interdomain.local_port; | ||
298 | break; | ||
299 | } | ||
300 | |||
301 | case IOCTL_EVTCHN_BIND_UNBOUND_PORT: { | ||
302 | struct ioctl_evtchn_bind_unbound_port bind; | ||
303 | struct evtchn_alloc_unbound alloc_unbound; | ||
304 | |||
305 | rc = -EFAULT; | ||
306 | if (copy_from_user(&bind, uarg, sizeof(bind))) | ||
307 | break; | ||
308 | |||
309 | alloc_unbound.dom = DOMID_SELF; | ||
310 | alloc_unbound.remote_dom = bind.remote_domain; | ||
311 | rc = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, | ||
312 | &alloc_unbound); | ||
313 | if (rc != 0) | ||
314 | break; | ||
315 | |||
316 | rc = evtchn_bind_to_user(u, alloc_unbound.port); | ||
317 | if (rc == 0) | ||
318 | rc = alloc_unbound.port; | ||
319 | break; | ||
320 | } | ||
321 | |||
322 | case IOCTL_EVTCHN_UNBIND: { | ||
323 | struct ioctl_evtchn_unbind unbind; | ||
324 | |||
325 | rc = -EFAULT; | ||
326 | if (copy_from_user(&unbind, uarg, sizeof(unbind))) | ||
327 | break; | ||
328 | |||
329 | rc = -EINVAL; | ||
330 | if (unbind.port >= NR_EVENT_CHANNELS) | ||
331 | break; | ||
332 | |||
333 | spin_lock_irq(&port_user_lock); | ||
334 | |||
335 | rc = -ENOTCONN; | ||
336 | if (port_user[unbind.port] != u) { | ||
337 | spin_unlock_irq(&port_user_lock); | ||
338 | break; | ||
339 | } | ||
340 | |||
341 | evtchn_unbind_from_user(u, unbind.port); | ||
342 | |||
343 | spin_unlock_irq(&port_user_lock); | ||
344 | |||
345 | rc = 0; | ||
346 | break; | ||
347 | } | ||
348 | |||
349 | case IOCTL_EVTCHN_NOTIFY: { | ||
350 | struct ioctl_evtchn_notify notify; | ||
351 | |||
352 | rc = -EFAULT; | ||
353 | if (copy_from_user(¬ify, uarg, sizeof(notify))) | ||
354 | break; | ||
355 | |||
356 | if (notify.port >= NR_EVENT_CHANNELS) { | ||
357 | rc = -EINVAL; | ||
358 | } else if (port_user[notify.port] != u) { | ||
359 | rc = -ENOTCONN; | ||
360 | } else { | ||
361 | notify_remote_via_evtchn(notify.port); | ||
362 | rc = 0; | ||
363 | } | ||
364 | break; | ||
365 | } | ||
366 | |||
367 | case IOCTL_EVTCHN_RESET: { | ||
368 | /* Initialise the ring to empty. Clear errors. */ | ||
369 | mutex_lock(&u->ring_cons_mutex); | ||
370 | spin_lock_irq(&port_user_lock); | ||
371 | u->ring_cons = u->ring_prod = u->ring_overflow = 0; | ||
372 | spin_unlock_irq(&port_user_lock); | ||
373 | mutex_unlock(&u->ring_cons_mutex); | ||
374 | rc = 0; | ||
375 | break; | ||
376 | } | ||
377 | |||
378 | default: | ||
379 | rc = -ENOSYS; | ||
380 | break; | ||
381 | } | ||
382 | mutex_unlock(&u->bind_mutex); | ||
383 | |||
384 | return rc; | ||
385 | } | ||
386 | |||
387 | static unsigned int evtchn_poll(struct file *file, poll_table *wait) | ||
388 | { | ||
389 | unsigned int mask = POLLOUT | POLLWRNORM; | ||
390 | struct per_user_data *u = file->private_data; | ||
391 | |||
392 | poll_wait(file, &u->evtchn_wait, wait); | ||
393 | if (u->ring_cons != u->ring_prod) | ||
394 | mask |= POLLIN | POLLRDNORM; | ||
395 | if (u->ring_overflow) | ||
396 | mask = POLLERR; | ||
397 | return mask; | ||
398 | } | ||
399 | |||
400 | static int evtchn_fasync(int fd, struct file *filp, int on) | ||
401 | { | ||
402 | struct per_user_data *u = filp->private_data; | ||
403 | return fasync_helper(fd, filp, on, &u->evtchn_async_queue); | ||
404 | } | ||
405 | |||
406 | static int evtchn_open(struct inode *inode, struct file *filp) | ||
407 | { | ||
408 | struct per_user_data *u; | ||
409 | |||
410 | u = kzalloc(sizeof(*u), GFP_KERNEL); | ||
411 | if (u == NULL) | ||
412 | return -ENOMEM; | ||
413 | |||
414 | u->name = kasprintf(GFP_KERNEL, "evtchn:%s", current->comm); | ||
415 | if (u->name == NULL) { | ||
416 | kfree(u); | ||
417 | return -ENOMEM; | ||
418 | } | ||
419 | |||
420 | init_waitqueue_head(&u->evtchn_wait); | ||
421 | |||
422 | u->ring = (evtchn_port_t *)__get_free_page(GFP_KERNEL); | ||
423 | if (u->ring == NULL) { | ||
424 | kfree(u->name); | ||
425 | kfree(u); | ||
426 | return -ENOMEM; | ||
427 | } | ||
428 | |||
429 | mutex_init(&u->bind_mutex); | ||
430 | mutex_init(&u->ring_cons_mutex); | ||
431 | |||
432 | filp->private_data = u; | ||
433 | |||
434 | return 0; | ||
435 | } | ||
436 | |||
437 | static int evtchn_release(struct inode *inode, struct file *filp) | ||
438 | { | ||
439 | int i; | ||
440 | struct per_user_data *u = filp->private_data; | ||
441 | |||
442 | spin_lock_irq(&port_user_lock); | ||
443 | |||
444 | free_page((unsigned long)u->ring); | ||
445 | |||
446 | for (i = 0; i < NR_EVENT_CHANNELS; i++) { | ||
447 | if (port_user[i] != u) | ||
448 | continue; | ||
449 | |||
450 | evtchn_unbind_from_user(port_user[i], i); | ||
451 | } | ||
452 | |||
453 | spin_unlock_irq(&port_user_lock); | ||
454 | |||
455 | kfree(u->name); | ||
456 | kfree(u); | ||
457 | |||
458 | return 0; | ||
459 | } | ||
460 | |||
461 | static const struct file_operations evtchn_fops = { | ||
462 | .owner = THIS_MODULE, | ||
463 | .read = evtchn_read, | ||
464 | .write = evtchn_write, | ||
465 | .unlocked_ioctl = evtchn_ioctl, | ||
466 | .poll = evtchn_poll, | ||
467 | .fasync = evtchn_fasync, | ||
468 | .open = evtchn_open, | ||
469 | .release = evtchn_release, | ||
470 | }; | ||
471 | |||
472 | static struct miscdevice evtchn_miscdev = { | ||
473 | .minor = MISC_DYNAMIC_MINOR, | ||
474 | .name = "evtchn", | ||
475 | .fops = &evtchn_fops, | ||
476 | }; | ||
477 | static int __init evtchn_init(void) | ||
478 | { | ||
479 | int err; | ||
480 | |||
481 | if (!xen_domain()) | ||
482 | return -ENODEV; | ||
483 | |||
484 | spin_lock_init(&port_user_lock); | ||
485 | memset(port_user, 0, sizeof(port_user)); | ||
486 | |||
487 | /* Create '/dev/misc/evtchn'. */ | ||
488 | err = misc_register(&evtchn_miscdev); | ||
489 | if (err != 0) { | ||
490 | printk(KERN_ALERT "Could not register /dev/misc/evtchn\n"); | ||
491 | return err; | ||
492 | } | ||
493 | |||
494 | printk(KERN_INFO "Event-channel device installed.\n"); | ||
495 | |||
496 | return 0; | ||
497 | } | ||
498 | |||
499 | static void __exit evtchn_cleanup(void) | ||
500 | { | ||
501 | misc_deregister(&evtchn_miscdev); | ||
502 | } | ||
503 | |||
504 | module_init(evtchn_init); | ||
505 | module_exit(evtchn_cleanup); | ||
506 | |||
507 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index 4b5b84837ee1..fddc2025dece 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c | |||
@@ -98,9 +98,8 @@ static void do_suspend(void) | |||
98 | goto out; | 98 | goto out; |
99 | } | 99 | } |
100 | 100 | ||
101 | printk("suspending xenbus...\n"); | 101 | printk(KERN_DEBUG "suspending xenstore...\n"); |
102 | /* XXX use normal device tree? */ | 102 | xs_suspend(); |
103 | xenbus_suspend(); | ||
104 | 103 | ||
105 | err = device_power_down(PMSG_SUSPEND); | 104 | err = device_power_down(PMSG_SUSPEND); |
106 | if (err) { | 105 | if (err) { |
@@ -116,9 +115,9 @@ static void do_suspend(void) | |||
116 | 115 | ||
117 | if (!cancelled) { | 116 | if (!cancelled) { |
118 | xen_arch_resume(); | 117 | xen_arch_resume(); |
119 | xenbus_resume(); | 118 | xs_resume(); |
120 | } else | 119 | } else |
121 | xenbus_suspend_cancel(); | 120 | xs_suspend_cancel(); |
122 | 121 | ||
123 | device_power_up(PMSG_RESUME); | 122 | device_power_up(PMSG_RESUME); |
124 | 123 | ||
diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c new file mode 100644 index 000000000000..88a60e03ccf0 --- /dev/null +++ b/drivers/xen/sys-hypervisor.c | |||
@@ -0,0 +1,445 @@ | |||
1 | /* | ||
2 | * copyright (c) 2006 IBM Corporation | ||
3 | * Authored by: Mike D. Day <ncmike@us.ibm.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/kobject.h> | ||
13 | |||
14 | #include <asm/xen/hypervisor.h> | ||
15 | #include <asm/xen/hypercall.h> | ||
16 | |||
17 | #include <xen/xenbus.h> | ||
18 | #include <xen/interface/xen.h> | ||
19 | #include <xen/interface/version.h> | ||
20 | |||
21 | #define HYPERVISOR_ATTR_RO(_name) \ | ||
22 | static struct hyp_sysfs_attr _name##_attr = __ATTR_RO(_name) | ||
23 | |||
24 | #define HYPERVISOR_ATTR_RW(_name) \ | ||
25 | static struct hyp_sysfs_attr _name##_attr = \ | ||
26 | __ATTR(_name, 0644, _name##_show, _name##_store) | ||
27 | |||
28 | struct hyp_sysfs_attr { | ||
29 | struct attribute attr; | ||
30 | ssize_t (*show)(struct hyp_sysfs_attr *, char *); | ||
31 | ssize_t (*store)(struct hyp_sysfs_attr *, const char *, size_t); | ||
32 | void *hyp_attr_data; | ||
33 | }; | ||
34 | |||
35 | static ssize_t type_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
36 | { | ||
37 | return sprintf(buffer, "xen\n"); | ||
38 | } | ||
39 | |||
40 | HYPERVISOR_ATTR_RO(type); | ||
41 | |||
42 | static int __init xen_sysfs_type_init(void) | ||
43 | { | ||
44 | return sysfs_create_file(hypervisor_kobj, &type_attr.attr); | ||
45 | } | ||
46 | |||
47 | static void xen_sysfs_type_destroy(void) | ||
48 | { | ||
49 | sysfs_remove_file(hypervisor_kobj, &type_attr.attr); | ||
50 | } | ||
51 | |||
52 | /* xen version attributes */ | ||
53 | static ssize_t major_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
54 | { | ||
55 | int version = HYPERVISOR_xen_version(XENVER_version, NULL); | ||
56 | if (version) | ||
57 | return sprintf(buffer, "%d\n", version >> 16); | ||
58 | return -ENODEV; | ||
59 | } | ||
60 | |||
61 | HYPERVISOR_ATTR_RO(major); | ||
62 | |||
63 | static ssize_t minor_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
64 | { | ||
65 | int version = HYPERVISOR_xen_version(XENVER_version, NULL); | ||
66 | if (version) | ||
67 | return sprintf(buffer, "%d\n", version & 0xff); | ||
68 | return -ENODEV; | ||
69 | } | ||
70 | |||
71 | HYPERVISOR_ATTR_RO(minor); | ||
72 | |||
73 | static ssize_t extra_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
74 | { | ||
75 | int ret = -ENOMEM; | ||
76 | char *extra; | ||
77 | |||
78 | extra = kmalloc(XEN_EXTRAVERSION_LEN, GFP_KERNEL); | ||
79 | if (extra) { | ||
80 | ret = HYPERVISOR_xen_version(XENVER_extraversion, extra); | ||
81 | if (!ret) | ||
82 | ret = sprintf(buffer, "%s\n", extra); | ||
83 | kfree(extra); | ||
84 | } | ||
85 | |||
86 | return ret; | ||
87 | } | ||
88 | |||
89 | HYPERVISOR_ATTR_RO(extra); | ||
90 | |||
91 | static struct attribute *version_attrs[] = { | ||
92 | &major_attr.attr, | ||
93 | &minor_attr.attr, | ||
94 | &extra_attr.attr, | ||
95 | NULL | ||
96 | }; | ||
97 | |||
98 | static struct attribute_group version_group = { | ||
99 | .name = "version", | ||
100 | .attrs = version_attrs, | ||
101 | }; | ||
102 | |||
103 | static int __init xen_sysfs_version_init(void) | ||
104 | { | ||
105 | return sysfs_create_group(hypervisor_kobj, &version_group); | ||
106 | } | ||
107 | |||
108 | static void xen_sysfs_version_destroy(void) | ||
109 | { | ||
110 | sysfs_remove_group(hypervisor_kobj, &version_group); | ||
111 | } | ||
112 | |||
113 | /* UUID */ | ||
114 | |||
115 | static ssize_t uuid_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
116 | { | ||
117 | char *vm, *val; | ||
118 | int ret; | ||
119 | extern int xenstored_ready; | ||
120 | |||
121 | if (!xenstored_ready) | ||
122 | return -EBUSY; | ||
123 | |||
124 | vm = xenbus_read(XBT_NIL, "vm", "", NULL); | ||
125 | if (IS_ERR(vm)) | ||
126 | return PTR_ERR(vm); | ||
127 | val = xenbus_read(XBT_NIL, vm, "uuid", NULL); | ||
128 | kfree(vm); | ||
129 | if (IS_ERR(val)) | ||
130 | return PTR_ERR(val); | ||
131 | ret = sprintf(buffer, "%s\n", val); | ||
132 | kfree(val); | ||
133 | return ret; | ||
134 | } | ||
135 | |||
136 | HYPERVISOR_ATTR_RO(uuid); | ||
137 | |||
138 | static int __init xen_sysfs_uuid_init(void) | ||
139 | { | ||
140 | return sysfs_create_file(hypervisor_kobj, &uuid_attr.attr); | ||
141 | } | ||
142 | |||
143 | static void xen_sysfs_uuid_destroy(void) | ||
144 | { | ||
145 | sysfs_remove_file(hypervisor_kobj, &uuid_attr.attr); | ||
146 | } | ||
147 | |||
148 | /* xen compilation attributes */ | ||
149 | |||
150 | static ssize_t compiler_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
151 | { | ||
152 | int ret = -ENOMEM; | ||
153 | struct xen_compile_info *info; | ||
154 | |||
155 | info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); | ||
156 | if (info) { | ||
157 | ret = HYPERVISOR_xen_version(XENVER_compile_info, info); | ||
158 | if (!ret) | ||
159 | ret = sprintf(buffer, "%s\n", info->compiler); | ||
160 | kfree(info); | ||
161 | } | ||
162 | |||
163 | return ret; | ||
164 | } | ||
165 | |||
166 | HYPERVISOR_ATTR_RO(compiler); | ||
167 | |||
168 | static ssize_t compiled_by_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
169 | { | ||
170 | int ret = -ENOMEM; | ||
171 | struct xen_compile_info *info; | ||
172 | |||
173 | info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); | ||
174 | if (info) { | ||
175 | ret = HYPERVISOR_xen_version(XENVER_compile_info, info); | ||
176 | if (!ret) | ||
177 | ret = sprintf(buffer, "%s\n", info->compile_by); | ||
178 | kfree(info); | ||
179 | } | ||
180 | |||
181 | return ret; | ||
182 | } | ||
183 | |||
184 | HYPERVISOR_ATTR_RO(compiled_by); | ||
185 | |||
186 | static ssize_t compile_date_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
187 | { | ||
188 | int ret = -ENOMEM; | ||
189 | struct xen_compile_info *info; | ||
190 | |||
191 | info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); | ||
192 | if (info) { | ||
193 | ret = HYPERVISOR_xen_version(XENVER_compile_info, info); | ||
194 | if (!ret) | ||
195 | ret = sprintf(buffer, "%s\n", info->compile_date); | ||
196 | kfree(info); | ||
197 | } | ||
198 | |||
199 | return ret; | ||
200 | } | ||
201 | |||
202 | HYPERVISOR_ATTR_RO(compile_date); | ||
203 | |||
204 | static struct attribute *xen_compile_attrs[] = { | ||
205 | &compiler_attr.attr, | ||
206 | &compiled_by_attr.attr, | ||
207 | &compile_date_attr.attr, | ||
208 | NULL | ||
209 | }; | ||
210 | |||
211 | static struct attribute_group xen_compilation_group = { | ||
212 | .name = "compilation", | ||
213 | .attrs = xen_compile_attrs, | ||
214 | }; | ||
215 | |||
216 | int __init static xen_compilation_init(void) | ||
217 | { | ||
218 | return sysfs_create_group(hypervisor_kobj, &xen_compilation_group); | ||
219 | } | ||
220 | |||
221 | static void xen_compilation_destroy(void) | ||
222 | { | ||
223 | sysfs_remove_group(hypervisor_kobj, &xen_compilation_group); | ||
224 | } | ||
225 | |||
226 | /* xen properties info */ | ||
227 | |||
228 | static ssize_t capabilities_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
229 | { | ||
230 | int ret = -ENOMEM; | ||
231 | char *caps; | ||
232 | |||
233 | caps = kmalloc(XEN_CAPABILITIES_INFO_LEN, GFP_KERNEL); | ||
234 | if (caps) { | ||
235 | ret = HYPERVISOR_xen_version(XENVER_capabilities, caps); | ||
236 | if (!ret) | ||
237 | ret = sprintf(buffer, "%s\n", caps); | ||
238 | kfree(caps); | ||
239 | } | ||
240 | |||
241 | return ret; | ||
242 | } | ||
243 | |||
244 | HYPERVISOR_ATTR_RO(capabilities); | ||
245 | |||
246 | static ssize_t changeset_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
247 | { | ||
248 | int ret = -ENOMEM; | ||
249 | char *cset; | ||
250 | |||
251 | cset = kmalloc(XEN_CHANGESET_INFO_LEN, GFP_KERNEL); | ||
252 | if (cset) { | ||
253 | ret = HYPERVISOR_xen_version(XENVER_changeset, cset); | ||
254 | if (!ret) | ||
255 | ret = sprintf(buffer, "%s\n", cset); | ||
256 | kfree(cset); | ||
257 | } | ||
258 | |||
259 | return ret; | ||
260 | } | ||
261 | |||
262 | HYPERVISOR_ATTR_RO(changeset); | ||
263 | |||
264 | static ssize_t virtual_start_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
265 | { | ||
266 | int ret = -ENOMEM; | ||
267 | struct xen_platform_parameters *parms; | ||
268 | |||
269 | parms = kmalloc(sizeof(struct xen_platform_parameters), GFP_KERNEL); | ||
270 | if (parms) { | ||
271 | ret = HYPERVISOR_xen_version(XENVER_platform_parameters, | ||
272 | parms); | ||
273 | if (!ret) | ||
274 | ret = sprintf(buffer, "%lx\n", parms->virt_start); | ||
275 | kfree(parms); | ||
276 | } | ||
277 | |||
278 | return ret; | ||
279 | } | ||
280 | |||
281 | HYPERVISOR_ATTR_RO(virtual_start); | ||
282 | |||
283 | static ssize_t pagesize_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
284 | { | ||
285 | int ret; | ||
286 | |||
287 | ret = HYPERVISOR_xen_version(XENVER_pagesize, NULL); | ||
288 | if (ret > 0) | ||
289 | ret = sprintf(buffer, "%x\n", ret); | ||
290 | |||
291 | return ret; | ||
292 | } | ||
293 | |||
294 | HYPERVISOR_ATTR_RO(pagesize); | ||
295 | |||
296 | static ssize_t xen_feature_show(int index, char *buffer) | ||
297 | { | ||
298 | ssize_t ret; | ||
299 | struct xen_feature_info info; | ||
300 | |||
301 | info.submap_idx = index; | ||
302 | ret = HYPERVISOR_xen_version(XENVER_get_features, &info); | ||
303 | if (!ret) | ||
304 | ret = sprintf(buffer, "%08x", info.submap); | ||
305 | |||
306 | return ret; | ||
307 | } | ||
308 | |||
309 | static ssize_t features_show(struct hyp_sysfs_attr *attr, char *buffer) | ||
310 | { | ||
311 | ssize_t len; | ||
312 | int i; | ||
313 | |||
314 | len = 0; | ||
315 | for (i = XENFEAT_NR_SUBMAPS-1; i >= 0; i--) { | ||
316 | int ret = xen_feature_show(i, buffer + len); | ||
317 | if (ret < 0) { | ||
318 | if (len == 0) | ||
319 | len = ret; | ||
320 | break; | ||
321 | } | ||
322 | len += ret; | ||
323 | } | ||
324 | if (len > 0) | ||
325 | buffer[len++] = '\n'; | ||
326 | |||
327 | return len; | ||
328 | } | ||
329 | |||
330 | HYPERVISOR_ATTR_RO(features); | ||
331 | |||
332 | static struct attribute *xen_properties_attrs[] = { | ||
333 | &capabilities_attr.attr, | ||
334 | &changeset_attr.attr, | ||
335 | &virtual_start_attr.attr, | ||
336 | &pagesize_attr.attr, | ||
337 | &features_attr.attr, | ||
338 | NULL | ||
339 | }; | ||
340 | |||
341 | static struct attribute_group xen_properties_group = { | ||
342 | .name = "properties", | ||
343 | .attrs = xen_properties_attrs, | ||
344 | }; | ||
345 | |||
346 | static int __init xen_properties_init(void) | ||
347 | { | ||
348 | return sysfs_create_group(hypervisor_kobj, &xen_properties_group); | ||
349 | } | ||
350 | |||
351 | static void xen_properties_destroy(void) | ||
352 | { | ||
353 | sysfs_remove_group(hypervisor_kobj, &xen_properties_group); | ||
354 | } | ||
355 | |||
356 | static int __init hyper_sysfs_init(void) | ||
357 | { | ||
358 | int ret; | ||
359 | |||
360 | if (!xen_domain()) | ||
361 | return -ENODEV; | ||
362 | |||
363 | ret = xen_sysfs_type_init(); | ||
364 | if (ret) | ||
365 | goto out; | ||
366 | ret = xen_sysfs_version_init(); | ||
367 | if (ret) | ||
368 | goto version_out; | ||
369 | ret = xen_compilation_init(); | ||
370 | if (ret) | ||
371 | goto comp_out; | ||
372 | ret = xen_sysfs_uuid_init(); | ||
373 | if (ret) | ||
374 | goto uuid_out; | ||
375 | ret = xen_properties_init(); | ||
376 | if (ret) | ||
377 | goto prop_out; | ||
378 | |||
379 | goto out; | ||
380 | |||
381 | prop_out: | ||
382 | xen_sysfs_uuid_destroy(); | ||
383 | uuid_out: | ||
384 | xen_compilation_destroy(); | ||
385 | comp_out: | ||
386 | xen_sysfs_version_destroy(); | ||
387 | version_out: | ||
388 | xen_sysfs_type_destroy(); | ||
389 | out: | ||
390 | return ret; | ||
391 | } | ||
392 | |||
393 | static void __exit hyper_sysfs_exit(void) | ||
394 | { | ||
395 | xen_properties_destroy(); | ||
396 | xen_compilation_destroy(); | ||
397 | xen_sysfs_uuid_destroy(); | ||
398 | xen_sysfs_version_destroy(); | ||
399 | xen_sysfs_type_destroy(); | ||
400 | |||
401 | } | ||
402 | module_init(hyper_sysfs_init); | ||
403 | module_exit(hyper_sysfs_exit); | ||
404 | |||
405 | static ssize_t hyp_sysfs_show(struct kobject *kobj, | ||
406 | struct attribute *attr, | ||
407 | char *buffer) | ||
408 | { | ||
409 | struct hyp_sysfs_attr *hyp_attr; | ||
410 | hyp_attr = container_of(attr, struct hyp_sysfs_attr, attr); | ||
411 | if (hyp_attr->show) | ||
412 | return hyp_attr->show(hyp_attr, buffer); | ||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | static ssize_t hyp_sysfs_store(struct kobject *kobj, | ||
417 | struct attribute *attr, | ||
418 | const char *buffer, | ||
419 | size_t len) | ||
420 | { | ||
421 | struct hyp_sysfs_attr *hyp_attr; | ||
422 | hyp_attr = container_of(attr, struct hyp_sysfs_attr, attr); | ||
423 | if (hyp_attr->store) | ||
424 | return hyp_attr->store(hyp_attr, buffer, len); | ||
425 | return 0; | ||
426 | } | ||
427 | |||
428 | static struct sysfs_ops hyp_sysfs_ops = { | ||
429 | .show = hyp_sysfs_show, | ||
430 | .store = hyp_sysfs_store, | ||
431 | }; | ||
432 | |||
433 | static struct kobj_type hyp_sysfs_kobj_type = { | ||
434 | .sysfs_ops = &hyp_sysfs_ops, | ||
435 | }; | ||
436 | |||
437 | static int __init hypervisor_subsys_init(void) | ||
438 | { | ||
439 | if (!xen_domain()) | ||
440 | return -ENODEV; | ||
441 | |||
442 | hypervisor_kobj->ktype = &hyp_sysfs_kobj_type; | ||
443 | return 0; | ||
444 | } | ||
445 | device_initcall(hypervisor_subsys_init); | ||
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c index 773d1cf23283..d42e25d5968d 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c | |||
@@ -71,6 +71,9 @@ static int xenbus_probe_frontend(const char *type, const char *name); | |||
71 | 71 | ||
72 | static void xenbus_dev_shutdown(struct device *_dev); | 72 | static void xenbus_dev_shutdown(struct device *_dev); |
73 | 73 | ||
74 | static int xenbus_dev_suspend(struct device *dev, pm_message_t state); | ||
75 | static int xenbus_dev_resume(struct device *dev); | ||
76 | |||
74 | /* If something in array of ids matches this device, return it. */ | 77 | /* If something in array of ids matches this device, return it. */ |
75 | static const struct xenbus_device_id * | 78 | static const struct xenbus_device_id * |
76 | match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev) | 79 | match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev) |
@@ -188,6 +191,9 @@ static struct xen_bus_type xenbus_frontend = { | |||
188 | .remove = xenbus_dev_remove, | 191 | .remove = xenbus_dev_remove, |
189 | .shutdown = xenbus_dev_shutdown, | 192 | .shutdown = xenbus_dev_shutdown, |
190 | .dev_attrs = xenbus_dev_attrs, | 193 | .dev_attrs = xenbus_dev_attrs, |
194 | |||
195 | .suspend = xenbus_dev_suspend, | ||
196 | .resume = xenbus_dev_resume, | ||
191 | }, | 197 | }, |
192 | }; | 198 | }; |
193 | 199 | ||
@@ -654,6 +660,7 @@ void xenbus_dev_changed(const char *node, struct xen_bus_type *bus) | |||
654 | 660 | ||
655 | kfree(root); | 661 | kfree(root); |
656 | } | 662 | } |
663 | EXPORT_SYMBOL_GPL(xenbus_dev_changed); | ||
657 | 664 | ||
658 | static void frontend_changed(struct xenbus_watch *watch, | 665 | static void frontend_changed(struct xenbus_watch *watch, |
659 | const char **vec, unsigned int len) | 666 | const char **vec, unsigned int len) |
@@ -669,7 +676,7 @@ static struct xenbus_watch fe_watch = { | |||
669 | .callback = frontend_changed, | 676 | .callback = frontend_changed, |
670 | }; | 677 | }; |
671 | 678 | ||
672 | static int suspend_dev(struct device *dev, void *data) | 679 | static int xenbus_dev_suspend(struct device *dev, pm_message_t state) |
673 | { | 680 | { |
674 | int err = 0; | 681 | int err = 0; |
675 | struct xenbus_driver *drv; | 682 | struct xenbus_driver *drv; |
@@ -682,35 +689,14 @@ static int suspend_dev(struct device *dev, void *data) | |||
682 | drv = to_xenbus_driver(dev->driver); | 689 | drv = to_xenbus_driver(dev->driver); |
683 | xdev = container_of(dev, struct xenbus_device, dev); | 690 | xdev = container_of(dev, struct xenbus_device, dev); |
684 | if (drv->suspend) | 691 | if (drv->suspend) |
685 | err = drv->suspend(xdev); | 692 | err = drv->suspend(xdev, state); |
686 | if (err) | 693 | if (err) |
687 | printk(KERN_WARNING | 694 | printk(KERN_WARNING |
688 | "xenbus: suspend %s failed: %i\n", dev_name(dev), err); | 695 | "xenbus: suspend %s failed: %i\n", dev_name(dev), err); |
689 | return 0; | 696 | return 0; |
690 | } | 697 | } |
691 | 698 | ||
692 | static int suspend_cancel_dev(struct device *dev, void *data) | 699 | static int xenbus_dev_resume(struct device *dev) |
693 | { | ||
694 | int err = 0; | ||
695 | struct xenbus_driver *drv; | ||
696 | struct xenbus_device *xdev; | ||
697 | |||
698 | DPRINTK(""); | ||
699 | |||
700 | if (dev->driver == NULL) | ||
701 | return 0; | ||
702 | drv = to_xenbus_driver(dev->driver); | ||
703 | xdev = container_of(dev, struct xenbus_device, dev); | ||
704 | if (drv->suspend_cancel) | ||
705 | err = drv->suspend_cancel(xdev); | ||
706 | if (err) | ||
707 | printk(KERN_WARNING | ||
708 | "xenbus: suspend_cancel %s failed: %i\n", | ||
709 | dev_name(dev), err); | ||
710 | return 0; | ||
711 | } | ||
712 | |||
713 | static int resume_dev(struct device *dev, void *data) | ||
714 | { | 700 | { |
715 | int err; | 701 | int err; |
716 | struct xenbus_driver *drv; | 702 | struct xenbus_driver *drv; |
@@ -755,33 +741,6 @@ static int resume_dev(struct device *dev, void *data) | |||
755 | return 0; | 741 | return 0; |
756 | } | 742 | } |
757 | 743 | ||
758 | void xenbus_suspend(void) | ||
759 | { | ||
760 | DPRINTK(""); | ||
761 | |||
762 | bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, suspend_dev); | ||
763 | xenbus_backend_suspend(suspend_dev); | ||
764 | xs_suspend(); | ||
765 | } | ||
766 | EXPORT_SYMBOL_GPL(xenbus_suspend); | ||
767 | |||
768 | void xenbus_resume(void) | ||
769 | { | ||
770 | xb_init_comms(); | ||
771 | xs_resume(); | ||
772 | bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, resume_dev); | ||
773 | xenbus_backend_resume(resume_dev); | ||
774 | } | ||
775 | EXPORT_SYMBOL_GPL(xenbus_resume); | ||
776 | |||
777 | void xenbus_suspend_cancel(void) | ||
778 | { | ||
779 | xs_suspend_cancel(); | ||
780 | bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, suspend_cancel_dev); | ||
781 | xenbus_backend_resume(suspend_cancel_dev); | ||
782 | } | ||
783 | EXPORT_SYMBOL_GPL(xenbus_suspend_cancel); | ||
784 | |||
785 | /* A flag to determine if xenstored is 'ready' (i.e. has started) */ | 744 | /* A flag to determine if xenstored is 'ready' (i.e. has started) */ |
786 | int xenstored_ready = 0; | 745 | int xenstored_ready = 0; |
787 | 746 | ||
diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c index e325eab4724d..eab33f1dbdf7 100644 --- a/drivers/xen/xenbus/xenbus_xs.c +++ b/drivers/xen/xenbus/xenbus_xs.c | |||
@@ -673,6 +673,8 @@ void xs_resume(void) | |||
673 | struct xenbus_watch *watch; | 673 | struct xenbus_watch *watch; |
674 | char token[sizeof(watch) * 2 + 1]; | 674 | char token[sizeof(watch) * 2 + 1]; |
675 | 675 | ||
676 | xb_init_comms(); | ||
677 | |||
676 | mutex_unlock(&xs_state.response_mutex); | 678 | mutex_unlock(&xs_state.response_mutex); |
677 | mutex_unlock(&xs_state.request_mutex); | 679 | mutex_unlock(&xs_state.request_mutex); |
678 | up_write(&xs_state.transaction_mutex); | 680 | up_write(&xs_state.transaction_mutex); |
diff --git a/drivers/xen/xenfs/super.c b/drivers/xen/xenfs/super.c index 515741a8e6b8..6559e0c752ce 100644 --- a/drivers/xen/xenfs/super.c +++ b/drivers/xen/xenfs/super.c | |||
@@ -20,10 +20,27 @@ | |||
20 | MODULE_DESCRIPTION("Xen filesystem"); | 20 | MODULE_DESCRIPTION("Xen filesystem"); |
21 | MODULE_LICENSE("GPL"); | 21 | MODULE_LICENSE("GPL"); |
22 | 22 | ||
23 | static ssize_t capabilities_read(struct file *file, char __user *buf, | ||
24 | size_t size, loff_t *off) | ||
25 | { | ||
26 | char *tmp = ""; | ||
27 | |||
28 | if (xen_initial_domain()) | ||
29 | tmp = "control_d\n"; | ||
30 | |||
31 | return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp)); | ||
32 | } | ||
33 | |||
34 | static const struct file_operations capabilities_file_ops = { | ||
35 | .read = capabilities_read, | ||
36 | }; | ||
37 | |||
23 | static int xenfs_fill_super(struct super_block *sb, void *data, int silent) | 38 | static int xenfs_fill_super(struct super_block *sb, void *data, int silent) |
24 | { | 39 | { |
25 | static struct tree_descr xenfs_files[] = { | 40 | static struct tree_descr xenfs_files[] = { |
26 | [2] = {"xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR}, | 41 | [1] = {}, |
42 | { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR }, | ||
43 | { "capabilities", &capabilities_file_ops, S_IRUGO }, | ||
27 | {""}, | 44 | {""}, |
28 | }; | 45 | }; |
29 | 46 | ||