diff options
author | Tejun Heo <htejun@gmail.com> | 2008-03-24 23:22:49 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2008-04-17 15:44:17 -0400 |
commit | 029cfd6b74fc5c517865fad78cf4a3ea8d9b664a (patch) | |
tree | 4a40f44f29321e433497a51d2f6cfe1922ae1d58 /drivers/ata/pata_ali.c | |
parent | 68d1d07b510bb57a504588adc2bd2758adea0965 (diff) |
libata: implement and use ops inheritance
libata lets low level drivers build ata_port_operations table and
register it with libata core layer. This allows low level drivers
high level of flexibility but also burdens them with lots of
boilerplate entries.
This becomes worse for drivers which support related similar
controllers which differ slightly. They share most of the operations
except for a few. However, the driver still needs to list all
operations for each variant. This results in large number of
duplicate entries, which is not only inefficient but also error-prone
as it becomes very difficult to tell what the actual differences are.
This duplicate boilerplates all over the low level drivers also make
updating the core layer exteremely difficult and error-prone. When
compounded with multi-branched development model, it ends up
accumulating inconsistencies over time. Some of those inconsistencies
cause immediate problems and fixed. Others just remain there dormant
making maintenance increasingly difficult.
To rectify the problem, this patch implements ata_port_operations
inheritance. To allow LLDs to easily re-use their own ops tables
overriding only specific methods, this patch implements poor man's
class inheritance. An ops table has ->inherits field which can be set
to any ops table as long as it doesn't create a loop. When the host
is started, the inheritance chain is followed and any operation which
isn't specified is taken from the nearest ancestor which has it
specified. This operation is called finalization and done only once
per an ops table and the LLD doesn't have to do anything special about
it other than making the ops table non-const such that libata can
update it.
libata provides four base ops tables lower drivers can inherit from -
base, sata, pmp, sff and bmdma. To avoid overriding these ops
accidentaly, these ops are declared const and LLDs should always
inherit these instead of using them directly.
After finalization, all the ops table are identical before and after
the patch except for setting .irq_handler to ata_interrupt in drivers
which didn't use to. The .irq_handler doesn't have any actual effect
and the field will soon be removed by later patch.
* sata_sx4 is still using old style EH and currently doesn't take
advantage of ops inheritance.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Diffstat (limited to 'drivers/ata/pata_ali.c')
-rw-r--r-- | drivers/ata/pata_ali.c | 122 |
1 files changed, 12 insertions, 110 deletions
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c index f3d6d9b345ba..b00a9cf72c31 100644 --- a/drivers/ata/pata_ali.c +++ b/drivers/ata/pata_ali.c | |||
@@ -347,29 +347,15 @@ static struct scsi_host_template ali_sht = { | |||
347 | */ | 347 | */ |
348 | 348 | ||
349 | static struct ata_port_operations ali_early_port_ops = { | 349 | static struct ata_port_operations ali_early_port_ops = { |
350 | .set_piomode = ali_set_piomode, | 350 | .inherits = &ata_sff_port_ops, |
351 | .tf_load = ata_tf_load, | ||
352 | .tf_read = ata_tf_read, | ||
353 | .check_status = ata_check_status, | ||
354 | .exec_command = ata_exec_command, | ||
355 | .dev_select = ata_std_dev_select, | ||
356 | |||
357 | .freeze = ata_bmdma_freeze, | ||
358 | .thaw = ata_bmdma_thaw, | ||
359 | .error_handler = ata_bmdma_error_handler, | ||
360 | .post_internal_cmd = ata_bmdma_post_internal_cmd, | ||
361 | .cable_detect = ata_cable_40wire, | 351 | .cable_detect = ata_cable_40wire, |
352 | .set_piomode = ali_set_piomode, | ||
353 | }; | ||
362 | 354 | ||
363 | .qc_prep = ata_qc_prep, | 355 | static const struct ata_port_operations ali_dma_base_ops = { |
364 | .qc_issue = ata_qc_issue_prot, | 356 | .inherits = &ata_bmdma_port_ops, |
365 | 357 | .set_piomode = ali_set_piomode, | |
366 | .data_xfer = ata_data_xfer, | 358 | .set_dmamode = ali_set_dmamode, |
367 | |||
368 | .irq_handler = ata_interrupt, | ||
369 | .irq_clear = ata_noop_irq_clear, | ||
370 | .irq_on = ata_irq_on, | ||
371 | |||
372 | .port_start = ata_sff_port_start, | ||
373 | }; | 359 | }; |
374 | 360 | ||
375 | /* | 361 | /* |
@@ -377,115 +363,31 @@ static struct ata_port_operations ali_early_port_ops = { | |||
377 | * detect | 363 | * detect |
378 | */ | 364 | */ |
379 | static struct ata_port_operations ali_20_port_ops = { | 365 | static struct ata_port_operations ali_20_port_ops = { |
380 | .set_piomode = ali_set_piomode, | 366 | .inherits = &ali_dma_base_ops, |
381 | .set_dmamode = ali_set_dmamode, | 367 | .cable_detect = ata_cable_40wire, |
382 | .mode_filter = ali_20_filter, | 368 | .mode_filter = ali_20_filter, |
383 | |||
384 | .tf_load = ata_tf_load, | ||
385 | .tf_read = ata_tf_read, | ||
386 | .check_atapi_dma = ali_check_atapi_dma, | 369 | .check_atapi_dma = ali_check_atapi_dma, |
387 | .check_status = ata_check_status, | ||
388 | .exec_command = ata_exec_command, | ||
389 | .dev_select = ata_std_dev_select, | ||
390 | .dev_config = ali_lock_sectors, | 370 | .dev_config = ali_lock_sectors, |
391 | |||
392 | .freeze = ata_bmdma_freeze, | ||
393 | .thaw = ata_bmdma_thaw, | ||
394 | .error_handler = ata_bmdma_error_handler, | ||
395 | .post_internal_cmd = ata_bmdma_post_internal_cmd, | ||
396 | .cable_detect = ata_cable_40wire, | ||
397 | |||
398 | .bmdma_setup = ata_bmdma_setup, | ||
399 | .bmdma_start = ata_bmdma_start, | ||
400 | .bmdma_stop = ata_bmdma_stop, | ||
401 | .bmdma_status = ata_bmdma_status, | ||
402 | |||
403 | .qc_prep = ata_qc_prep, | ||
404 | .qc_issue = ata_qc_issue_prot, | ||
405 | |||
406 | .data_xfer = ata_data_xfer, | ||
407 | |||
408 | .irq_handler = ata_interrupt, | ||
409 | .irq_clear = ata_bmdma_irq_clear, | ||
410 | .irq_on = ata_irq_on, | ||
411 | |||
412 | .port_start = ata_sff_port_start, | ||
413 | }; | 371 | }; |
414 | 372 | ||
415 | /* | 373 | /* |
416 | * Port operations for DMA capable ALi with cable detect | 374 | * Port operations for DMA capable ALi with cable detect |
417 | */ | 375 | */ |
418 | static struct ata_port_operations ali_c2_port_ops = { | 376 | static struct ata_port_operations ali_c2_port_ops = { |
419 | .set_piomode = ali_set_piomode, | 377 | .inherits = &ali_dma_base_ops, |
420 | .set_dmamode = ali_set_dmamode, | ||
421 | .mode_filter = ata_pci_default_filter, | ||
422 | .tf_load = ata_tf_load, | ||
423 | .tf_read = ata_tf_read, | ||
424 | .check_atapi_dma = ali_check_atapi_dma, | 378 | .check_atapi_dma = ali_check_atapi_dma, |
425 | .check_status = ata_check_status, | ||
426 | .exec_command = ata_exec_command, | ||
427 | .dev_select = ata_std_dev_select, | ||
428 | .dev_config = ali_lock_sectors, | ||
429 | |||
430 | .freeze = ata_bmdma_freeze, | ||
431 | .thaw = ata_bmdma_thaw, | ||
432 | .error_handler = ata_bmdma_error_handler, | ||
433 | .post_internal_cmd = ata_bmdma_post_internal_cmd, | ||
434 | .cable_detect = ali_c2_cable_detect, | 379 | .cable_detect = ali_c2_cable_detect, |
435 | 380 | .dev_config = ali_lock_sectors, | |
436 | .bmdma_setup = ata_bmdma_setup, | ||
437 | .bmdma_start = ata_bmdma_start, | ||
438 | .bmdma_stop = ata_bmdma_stop, | ||
439 | .bmdma_status = ata_bmdma_status, | ||
440 | |||
441 | .qc_prep = ata_qc_prep, | ||
442 | .qc_issue = ata_qc_issue_prot, | ||
443 | |||
444 | .data_xfer = ata_data_xfer, | ||
445 | |||
446 | .irq_handler = ata_interrupt, | ||
447 | .irq_clear = ata_bmdma_irq_clear, | ||
448 | .irq_on = ata_irq_on, | ||
449 | |||
450 | .port_start = ata_sff_port_start, | ||
451 | }; | 381 | }; |
452 | 382 | ||
453 | /* | 383 | /* |
454 | * Port operations for DMA capable ALi with cable detect and LBA48 | 384 | * Port operations for DMA capable ALi with cable detect and LBA48 |
455 | */ | 385 | */ |
456 | static struct ata_port_operations ali_c5_port_ops = { | 386 | static struct ata_port_operations ali_c5_port_ops = { |
457 | .set_piomode = ali_set_piomode, | 387 | .inherits = &ali_dma_base_ops, |
458 | .set_dmamode = ali_set_dmamode, | ||
459 | .mode_filter = ata_pci_default_filter, | ||
460 | .tf_load = ata_tf_load, | ||
461 | .tf_read = ata_tf_read, | ||
462 | .check_atapi_dma = ali_check_atapi_dma, | 388 | .check_atapi_dma = ali_check_atapi_dma, |
463 | .check_status = ata_check_status, | ||
464 | .exec_command = ata_exec_command, | ||
465 | .dev_select = ata_std_dev_select, | ||
466 | .dev_config = ali_warn_atapi_dma, | 389 | .dev_config = ali_warn_atapi_dma, |
467 | |||
468 | .freeze = ata_bmdma_freeze, | ||
469 | .thaw = ata_bmdma_thaw, | ||
470 | .error_handler = ata_bmdma_error_handler, | ||
471 | .post_internal_cmd = ata_bmdma_post_internal_cmd, | ||
472 | .cable_detect = ali_c2_cable_detect, | 390 | .cable_detect = ali_c2_cable_detect, |
473 | |||
474 | .bmdma_setup = ata_bmdma_setup, | ||
475 | .bmdma_start = ata_bmdma_start, | ||
476 | .bmdma_stop = ata_bmdma_stop, | ||
477 | .bmdma_status = ata_bmdma_status, | ||
478 | |||
479 | .qc_prep = ata_qc_prep, | ||
480 | .qc_issue = ata_qc_issue_prot, | ||
481 | |||
482 | .data_xfer = ata_data_xfer, | ||
483 | |||
484 | .irq_handler = ata_interrupt, | ||
485 | .irq_clear = ata_bmdma_irq_clear, | ||
486 | .irq_on = ata_irq_on, | ||
487 | |||
488 | .port_start = ata_sff_port_start, | ||
489 | }; | 391 | }; |
490 | 392 | ||
491 | 393 | ||