Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ata: separate PATA timings code from libata-core.c

Separate PATA timings code from libata-core.c:

* add PATA_TIMINGS config option and make corresponding PATA
host drivers (and ATA ACPI code) select it

* move following PATA timings code to libata-pata-timings.c:
- ata_timing_quantize()
- ata_timing_merge()
- ata_timing_find_mode()
- ata_timing_compute()

* group above functions together in <linux/libata.h>

* include libata-pata-timings.c in the build when PATA_TIMINGS
config option is enabled

* cover ata_timing_cycle2mode() with CONFIG_ATA_ACPI ifdef (it
depends on code from libata-core.c and libata-pata-timings.c
while its only user is ATA ACPI)

Code size savings on m68k arch using (modified) atari_defconfig:

text data bss dec hex filename
before:
39688 573 40 40301 9d6d drivers/ata/libata-core.o
after:
37820 572 40 38432 9620 drivers/ata/libata-core.o

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Bartlomiej Zolnierkiewicz and committed by
Jens Axboe
a9b2c120 4e168187

+226 -187
+21
drivers/ata/Kconfig
··· 37 37 config SATA_HOST 38 38 bool 39 39 40 + config PATA_TIMINGS 41 + bool 42 + 40 43 config ATA_VERBOSE_ERROR 41 44 bool "Verbose ATA error reporting" 42 45 default y ··· 54 51 config ATA_ACPI 55 52 bool "ATA ACPI Support" 56 53 depends on ACPI 54 + select PATA_TIMINGS 57 55 default y 58 56 help 59 57 This option adds support for ATA-related ACPI objects. ··· 345 341 config PATA_OCTEON_CF 346 342 tristate "OCTEON Boot Bus Compact Flash support" 347 343 depends on CAVIUM_OCTEON_SOC 344 + select PATA_TIMINGS 348 345 help 349 346 This option enables a polled compact flash driver for use with 350 347 compact flash cards attached to the OCTEON boot bus. ··· 541 536 config PATA_ALI 542 537 tristate "ALi PATA support" 543 538 depends on PCI 539 + select PATA_TIMINGS 544 540 help 545 541 This option enables support for the ALi ATA interfaces 546 542 found on the many ALi chipsets. ··· 551 545 config PATA_AMD 552 546 tristate "AMD/NVidia PATA support" 553 547 depends on PCI 548 + select PATA_TIMINGS 554 549 help 555 550 This option enables support for the AMD and NVidia PATA 556 551 interfaces found on the chipsets for Athlon/Athlon64. ··· 586 579 config PATA_ATP867X 587 580 tristate "ARTOP/Acard ATP867X PATA support" 588 581 depends on PCI 582 + select PATA_TIMINGS 589 583 help 590 584 This option enables support for ARTOP/Acard ATP867X PATA 591 585 controllers. ··· 596 588 config PATA_BK3710 597 589 tristate "Palmchip BK3710 PATA support" 598 590 depends on ARCH_DAVINCI 591 + select PATA_TIMINGS 599 592 help 600 593 This option enables support for the integrated IDE controller on 601 594 the TI DaVinci SoC. ··· 606 597 config PATA_CMD64X 607 598 tristate "CMD64x PATA support" 608 599 depends on PCI 600 + select PATA_TIMINGS 609 601 help 610 602 This option enables support for the CMD64x series chips 611 603 except for the CMD640. ··· 652 642 config PATA_CYPRESS 653 643 tristate "Cypress CY82C693 PATA support (Very Experimental)" 654 644 depends on PCI 645 + select PATA_TIMINGS 655 646 help 656 647 This option enables support for the Cypress/Contaq CY82C693 657 648 chipset found in some Alpha systems ··· 671 660 config PATA_EP93XX 672 661 tristate "Cirrus Logic EP93xx PATA support" 673 662 depends on ARCH_EP93XX 663 + select PATA_TIMINGS 674 664 help 675 665 This option enables support for the PATA controller in 676 666 the Cirrus Logic EP9312 and EP9315 ARM CPU. ··· 736 724 config PATA_ICSIDE 737 725 tristate "Acorn ICS PATA support" 738 726 depends on ARM && ARCH_ACORN 727 + select PATA_TIMINGS 739 728 help 740 729 On Acorn systems, say Y here if you wish to use the ICS PATA 741 730 interface card. This is not required for ICS partition support. ··· 745 732 config PATA_IMX 746 733 tristate "PATA support for Freescale iMX" 747 734 depends on ARCH_MXC 735 + select PATA_TIMINGS 748 736 help 749 737 This option enables support for the PATA host available on Freescale 750 738 iMX SoCs. ··· 831 817 config PATA_NS87415 832 818 tristate "Nat Semi NS87415 PATA support" 833 819 depends on PCI 820 + select PATA_TIMINGS 834 821 help 835 822 This option enables support for the National Semiconductor 836 823 NS87415 PCI-IDE controller. ··· 956 941 config PATA_VIA 957 942 tristate "VIA PATA support" 958 943 depends on PCI 944 + select PATA_TIMINGS 959 945 help 960 946 This option enables support for the VIA PATA interfaces 961 947 found on the many VIA chipsets. ··· 990 974 config PATA_CMD640_PCI 991 975 tristate "CMD640 PCI PATA support (Experimental)" 992 976 depends on PCI 977 + select PATA_TIMINGS 993 978 help 994 979 This option enables support for the CMD640 PCI IDE 995 980 interface chip. Only the primary channel is currently ··· 1061 1044 config PATA_NS87410 1062 1045 tristate "Nat Semi NS87410 PATA support" 1063 1046 depends on PCI 1047 + select PATA_TIMINGS 1064 1048 help 1065 1049 This option enables support for the National Semiconductor 1066 1050 NS87410 PCI-IDE controller. ··· 1142 1124 config PATA_SAMSUNG_CF 1143 1125 tristate "Samsung SoC PATA support" 1144 1126 depends on SAMSUNG_DEV_IDE 1127 + select PATA_TIMINGS 1145 1128 help 1146 1129 This option enables basic support for Samsung's S3C/S5P board 1147 1130 PATA controllers via the new ATA layer ··· 1162 1143 config PATA_ACPI 1163 1144 tristate "ACPI firmware driver for PATA" 1164 1145 depends on ATA_ACPI && ATA_BMDMA && PCI 1146 + select PATA_TIMINGS 1165 1147 help 1166 1148 This option enables an ACPI method driver which drives 1167 1149 motherboard PATA controller interfaces through the ACPI ··· 1182 1162 config PATA_LEGACY 1183 1163 tristate "Legacy ISA PATA support (Experimental)" 1184 1164 depends on (ISA || PCI) 1165 + select PATA_TIMINGS 1185 1166 help 1186 1167 This option enables support for ISA/VLB/PCI bus legacy PATA 1187 1168 ports and allows them to be accessed via the new ATA layer.
+1
drivers/ata/Makefile
··· 127 127 libata-$(CONFIG_SATA_PMP) += libata-pmp.o 128 128 libata-$(CONFIG_ATA_ACPI) += libata-acpi.o 129 129 libata-$(CONFIG_SATA_ZPODD) += libata-zpodd.o 130 + libata-$(CONFIG_PATA_TIMINGS) += libata-pata-timings.o
+2 -181
drivers/ata/libata-core.c
··· 3204 3204 } 3205 3205 EXPORT_SYMBOL_GPL(sata_set_spd); 3206 3206 3207 - /* 3208 - * This mode timing computation functionality is ported over from 3209 - * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik 3210 - */ 3211 - /* 3212 - * PIO 0-4, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds). 3213 - * These were taken from ATA/ATAPI-6 standard, rev 0a, except 3214 - * for UDMA6, which is currently supported only by Maxtor drives. 3215 - * 3216 - * For PIO 5/6 MWDMA 3/4 see the CFA specification 3.0. 3217 - */ 3218 - 3219 - static const struct ata_timing ata_timing[] = { 3220 - /* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 0, 960, 0 }, */ 3221 - { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 0, 600, 0 }, 3222 - { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 0, 383, 0 }, 3223 - { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 0, 240, 0 }, 3224 - { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 0, 180, 0 }, 3225 - { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 0, 120, 0 }, 3226 - { XFER_PIO_5, 15, 65, 25, 100, 65, 25, 0, 100, 0 }, 3227 - { XFER_PIO_6, 10, 55, 20, 80, 55, 20, 0, 80, 0 }, 3228 - 3229 - { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 50, 960, 0 }, 3230 - { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 30, 480, 0 }, 3231 - { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 20, 240, 0 }, 3232 - 3233 - { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 20, 480, 0 }, 3234 - { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 5, 150, 0 }, 3235 - { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 5, 120, 0 }, 3236 - { XFER_MW_DMA_3, 25, 0, 0, 0, 65, 25, 5, 100, 0 }, 3237 - { XFER_MW_DMA_4, 25, 0, 0, 0, 55, 20, 5, 80, 0 }, 3238 - 3239 - /* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 0, 150 }, */ 3240 - { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 0, 120 }, 3241 - { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 0, 80 }, 3242 - { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 0, 60 }, 3243 - { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 0, 45 }, 3244 - { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 0, 30 }, 3245 - { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 0, 20 }, 3246 - { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 0, 15 }, 3247 - 3248 - { 0xFF } 3249 - }; 3250 - 3251 - #define ENOUGH(v, unit) (((v)-1)/(unit)+1) 3252 - #define EZ(v, unit) ((v)?ENOUGH(((v) * 1000), unit):0) 3253 - 3254 - static void ata_timing_quantize(const struct ata_timing *t, 3255 - struct ata_timing *q, int T, int UT) 3256 - { 3257 - q->setup = EZ(t->setup, T); 3258 - q->act8b = EZ(t->act8b, T); 3259 - q->rec8b = EZ(t->rec8b, T); 3260 - q->cyc8b = EZ(t->cyc8b, T); 3261 - q->active = EZ(t->active, T); 3262 - q->recover = EZ(t->recover, T); 3263 - q->dmack_hold = EZ(t->dmack_hold, T); 3264 - q->cycle = EZ(t->cycle, T); 3265 - q->udma = EZ(t->udma, UT); 3266 - } 3267 - 3268 - void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b, 3269 - struct ata_timing *m, unsigned int what) 3270 - { 3271 - if (what & ATA_TIMING_SETUP) 3272 - m->setup = max(a->setup, b->setup); 3273 - if (what & ATA_TIMING_ACT8B) 3274 - m->act8b = max(a->act8b, b->act8b); 3275 - if (what & ATA_TIMING_REC8B) 3276 - m->rec8b = max(a->rec8b, b->rec8b); 3277 - if (what & ATA_TIMING_CYC8B) 3278 - m->cyc8b = max(a->cyc8b, b->cyc8b); 3279 - if (what & ATA_TIMING_ACTIVE) 3280 - m->active = max(a->active, b->active); 3281 - if (what & ATA_TIMING_RECOVER) 3282 - m->recover = max(a->recover, b->recover); 3283 - if (what & ATA_TIMING_DMACK_HOLD) 3284 - m->dmack_hold = max(a->dmack_hold, b->dmack_hold); 3285 - if (what & ATA_TIMING_CYCLE) 3286 - m->cycle = max(a->cycle, b->cycle); 3287 - if (what & ATA_TIMING_UDMA) 3288 - m->udma = max(a->udma, b->udma); 3289 - } 3290 - EXPORT_SYMBOL_GPL(ata_timing_merge); 3291 - 3292 - const struct ata_timing *ata_timing_find_mode(u8 xfer_mode) 3293 - { 3294 - const struct ata_timing *t = ata_timing; 3295 - 3296 - while (xfer_mode > t->mode) 3297 - t++; 3298 - 3299 - if (xfer_mode == t->mode) 3300 - return t; 3301 - 3302 - WARN_ONCE(true, "%s: unable to find timing for xfer_mode 0x%x\n", 3303 - __func__, xfer_mode); 3304 - 3305 - return NULL; 3306 - } 3307 - EXPORT_SYMBOL_GPL(ata_timing_find_mode); 3308 - 3309 - int ata_timing_compute(struct ata_device *adev, unsigned short speed, 3310 - struct ata_timing *t, int T, int UT) 3311 - { 3312 - const u16 *id = adev->id; 3313 - const struct ata_timing *s; 3314 - struct ata_timing p; 3315 - 3316 - /* 3317 - * Find the mode. 3318 - */ 3319 - s = ata_timing_find_mode(speed); 3320 - if (!s) 3321 - return -EINVAL; 3322 - 3323 - memcpy(t, s, sizeof(*s)); 3324 - 3325 - /* 3326 - * If the drive is an EIDE drive, it can tell us it needs extended 3327 - * PIO/MW_DMA cycle timing. 3328 - */ 3329 - 3330 - if (id[ATA_ID_FIELD_VALID] & 2) { /* EIDE drive */ 3331 - memset(&p, 0, sizeof(p)); 3332 - 3333 - if (speed >= XFER_PIO_0 && speed < XFER_SW_DMA_0) { 3334 - if (speed <= XFER_PIO_2) 3335 - p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO]; 3336 - else if ((speed <= XFER_PIO_4) || 3337 - (speed == XFER_PIO_5 && !ata_id_is_cfa(id))) 3338 - p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO_IORDY]; 3339 - } else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) 3340 - p.cycle = id[ATA_ID_EIDE_DMA_MIN]; 3341 - 3342 - ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B); 3343 - } 3344 - 3345 - /* 3346 - * Convert the timing to bus clock counts. 3347 - */ 3348 - 3349 - ata_timing_quantize(t, t, T, UT); 3350 - 3351 - /* 3352 - * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, 3353 - * S.M.A.R.T * and some other commands. We have to ensure that the 3354 - * DMA cycle timing is slower/equal than the fastest PIO timing. 3355 - */ 3356 - 3357 - if (speed > XFER_PIO_6) { 3358 - ata_timing_compute(adev, adev->pio_mode, &p, T, UT); 3359 - ata_timing_merge(&p, t, t, ATA_TIMING_ALL); 3360 - } 3361 - 3362 - /* 3363 - * Lengthen active & recovery time so that cycle time is correct. 3364 - */ 3365 - 3366 - if (t->act8b + t->rec8b < t->cyc8b) { 3367 - t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2; 3368 - t->rec8b = t->cyc8b - t->act8b; 3369 - } 3370 - 3371 - if (t->active + t->recover < t->cycle) { 3372 - t->active += (t->cycle - (t->active + t->recover)) / 2; 3373 - t->recover = t->cycle - t->active; 3374 - } 3375 - 3376 - /* 3377 - * In a few cases quantisation may produce enough errors to 3378 - * leave t->cycle too low for the sum of active and recovery 3379 - * if so we must correct this. 3380 - */ 3381 - if (t->active + t->recover > t->cycle) 3382 - t->cycle = t->active + t->recover; 3383 - 3384 - return 0; 3385 - } 3386 - EXPORT_SYMBOL_GPL(ata_timing_compute); 3387 - 3207 + #ifdef CONFIG_ATA_ACPI 3388 3208 /** 3389 3209 * ata_timing_cycle2mode - find xfer mode for the specified cycle duration 3390 3210 * @xfer_shift: ATA_SHIFT_* value for transfer type to examine. ··· 3255 3435 3256 3436 return last_mode; 3257 3437 } 3438 + #endif 3258 3439 3259 3440 /** 3260 3441 * ata_down_xfermask_limit - adjust dev xfer masks downward
+192
drivers/ata/libata-pata-timings.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Helper library for PATA timings 4 + * 5 + * Copyright 2003-2004 Red Hat, Inc. All rights reserved. 6 + * Copyright 2003-2004 Jeff Garzik 7 + */ 8 + 9 + #include <linux/kernel.h> 10 + #include <linux/module.h> 11 + #include <linux/libata.h> 12 + 13 + /* 14 + * This mode timing computation functionality is ported over from 15 + * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik 16 + */ 17 + /* 18 + * PIO 0-4, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds). 19 + * These were taken from ATA/ATAPI-6 standard, rev 0a, except 20 + * for UDMA6, which is currently supported only by Maxtor drives. 21 + * 22 + * For PIO 5/6 MWDMA 3/4 see the CFA specification 3.0. 23 + */ 24 + 25 + static const struct ata_timing ata_timing[] = { 26 + /* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 0, 960, 0 }, */ 27 + { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 0, 600, 0 }, 28 + { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 0, 383, 0 }, 29 + { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 0, 240, 0 }, 30 + { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 0, 180, 0 }, 31 + { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 0, 120, 0 }, 32 + { XFER_PIO_5, 15, 65, 25, 100, 65, 25, 0, 100, 0 }, 33 + { XFER_PIO_6, 10, 55, 20, 80, 55, 20, 0, 80, 0 }, 34 + 35 + { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 50, 960, 0 }, 36 + { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 30, 480, 0 }, 37 + { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 20, 240, 0 }, 38 + 39 + { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 20, 480, 0 }, 40 + { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 5, 150, 0 }, 41 + { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 5, 120, 0 }, 42 + { XFER_MW_DMA_3, 25, 0, 0, 0, 65, 25, 5, 100, 0 }, 43 + { XFER_MW_DMA_4, 25, 0, 0, 0, 55, 20, 5, 80, 0 }, 44 + 45 + /* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 0, 150 }, */ 46 + { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 0, 120 }, 47 + { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 0, 80 }, 48 + { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 0, 60 }, 49 + { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 0, 45 }, 50 + { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 0, 30 }, 51 + { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 0, 20 }, 52 + { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 0, 15 }, 53 + 54 + { 0xFF } 55 + }; 56 + 57 + #define ENOUGH(v, unit) (((v)-1)/(unit)+1) 58 + #define EZ(v, unit) ((v)?ENOUGH(((v) * 1000), unit):0) 59 + 60 + static void ata_timing_quantize(const struct ata_timing *t, 61 + struct ata_timing *q, int T, int UT) 62 + { 63 + q->setup = EZ(t->setup, T); 64 + q->act8b = EZ(t->act8b, T); 65 + q->rec8b = EZ(t->rec8b, T); 66 + q->cyc8b = EZ(t->cyc8b, T); 67 + q->active = EZ(t->active, T); 68 + q->recover = EZ(t->recover, T); 69 + q->dmack_hold = EZ(t->dmack_hold, T); 70 + q->cycle = EZ(t->cycle, T); 71 + q->udma = EZ(t->udma, UT); 72 + } 73 + 74 + void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b, 75 + struct ata_timing *m, unsigned int what) 76 + { 77 + if (what & ATA_TIMING_SETUP) 78 + m->setup = max(a->setup, b->setup); 79 + if (what & ATA_TIMING_ACT8B) 80 + m->act8b = max(a->act8b, b->act8b); 81 + if (what & ATA_TIMING_REC8B) 82 + m->rec8b = max(a->rec8b, b->rec8b); 83 + if (what & ATA_TIMING_CYC8B) 84 + m->cyc8b = max(a->cyc8b, b->cyc8b); 85 + if (what & ATA_TIMING_ACTIVE) 86 + m->active = max(a->active, b->active); 87 + if (what & ATA_TIMING_RECOVER) 88 + m->recover = max(a->recover, b->recover); 89 + if (what & ATA_TIMING_DMACK_HOLD) 90 + m->dmack_hold = max(a->dmack_hold, b->dmack_hold); 91 + if (what & ATA_TIMING_CYCLE) 92 + m->cycle = max(a->cycle, b->cycle); 93 + if (what & ATA_TIMING_UDMA) 94 + m->udma = max(a->udma, b->udma); 95 + } 96 + EXPORT_SYMBOL_GPL(ata_timing_merge); 97 + 98 + const struct ata_timing *ata_timing_find_mode(u8 xfer_mode) 99 + { 100 + const struct ata_timing *t = ata_timing; 101 + 102 + while (xfer_mode > t->mode) 103 + t++; 104 + 105 + if (xfer_mode == t->mode) 106 + return t; 107 + 108 + WARN_ONCE(true, "%s: unable to find timing for xfer_mode 0x%x\n", 109 + __func__, xfer_mode); 110 + 111 + return NULL; 112 + } 113 + EXPORT_SYMBOL_GPL(ata_timing_find_mode); 114 + 115 + int ata_timing_compute(struct ata_device *adev, unsigned short speed, 116 + struct ata_timing *t, int T, int UT) 117 + { 118 + const u16 *id = adev->id; 119 + const struct ata_timing *s; 120 + struct ata_timing p; 121 + 122 + /* 123 + * Find the mode. 124 + */ 125 + s = ata_timing_find_mode(speed); 126 + if (!s) 127 + return -EINVAL; 128 + 129 + memcpy(t, s, sizeof(*s)); 130 + 131 + /* 132 + * If the drive is an EIDE drive, it can tell us it needs extended 133 + * PIO/MW_DMA cycle timing. 134 + */ 135 + 136 + if (id[ATA_ID_FIELD_VALID] & 2) { /* EIDE drive */ 137 + memset(&p, 0, sizeof(p)); 138 + 139 + if (speed >= XFER_PIO_0 && speed < XFER_SW_DMA_0) { 140 + if (speed <= XFER_PIO_2) 141 + p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO]; 142 + else if ((speed <= XFER_PIO_4) || 143 + (speed == XFER_PIO_5 && !ata_id_is_cfa(id))) 144 + p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO_IORDY]; 145 + } else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) 146 + p.cycle = id[ATA_ID_EIDE_DMA_MIN]; 147 + 148 + ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B); 149 + } 150 + 151 + /* 152 + * Convert the timing to bus clock counts. 153 + */ 154 + 155 + ata_timing_quantize(t, t, T, UT); 156 + 157 + /* 158 + * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, 159 + * S.M.A.R.T * and some other commands. We have to ensure that the 160 + * DMA cycle timing is slower/equal than the fastest PIO timing. 161 + */ 162 + 163 + if (speed > XFER_PIO_6) { 164 + ata_timing_compute(adev, adev->pio_mode, &p, T, UT); 165 + ata_timing_merge(&p, t, t, ATA_TIMING_ALL); 166 + } 167 + 168 + /* 169 + * Lengthen active & recovery time so that cycle time is correct. 170 + */ 171 + 172 + if (t->act8b + t->rec8b < t->cyc8b) { 173 + t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2; 174 + t->rec8b = t->cyc8b - t->act8b; 175 + } 176 + 177 + if (t->active + t->recover < t->cycle) { 178 + t->active += (t->cycle - (t->active + t->recover)) / 2; 179 + t->recover = t->cycle - t->active; 180 + } 181 + 182 + /* 183 + * In a few cases quantisation may produce enough errors to 184 + * leave t->cycle too low for the sum of active and recovery 185 + * if so we must correct this. 186 + */ 187 + if (t->active + t->recover > t->cycle) 188 + t->cycle = t->active + t->recover; 189 + 190 + return 0; 191 + } 192 + EXPORT_SYMBOL_GPL(ata_timing_compute);
+10 -6
include/linux/libata.h
··· 1205 1205 1206 1206 /* Timing helpers */ 1207 1207 extern unsigned int ata_pio_need_iordy(const struct ata_device *); 1208 - extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode); 1209 - extern int ata_timing_compute(struct ata_device *, unsigned short, 1210 - struct ata_timing *, int, int); 1211 - extern void ata_timing_merge(const struct ata_timing *, 1212 - const struct ata_timing *, struct ata_timing *, 1213 - unsigned int); 1214 1208 extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle); 1215 1209 1216 1210 /* PCI */ ··· 1800 1806 { 1801 1807 return (adev->dma_mode == 0xFF ? 0 : 1); 1802 1808 } 1809 + 1810 + /************************************************************************** 1811 + * PATA timings - drivers/ata/libata-pata-timings.c 1812 + */ 1813 + extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode); 1814 + extern int ata_timing_compute(struct ata_device *, unsigned short, 1815 + struct ata_timing *, int, int); 1816 + extern void ata_timing_merge(const struct ata_timing *, 1817 + const struct ata_timing *, struct ata_timing *, 1818 + unsigned int); 1803 1819 1804 1820 /************************************************************************** 1805 1821 * PMP - drivers/ata/libata-pmp.c