aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/ahci.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2008-03-24 23:22:49 -0400
committerJeff Garzik <jgarzik@redhat.com>2008-04-17 15:44:17 -0400
commit029cfd6b74fc5c517865fad78cf4a3ea8d9b664a (patch)
tree4a40f44f29321e433497a51d2f6cfe1922ae1d58 /drivers/ata/ahci.c
parent68d1d07b510bb57a504588adc2bd2758adea0965 (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/ahci.c')
-rw-r--r--drivers/ata/ahci.c94
1 files changed, 11 insertions, 83 deletions
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 8862595cb2c..dacb3ef0c3e 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -280,118 +280,46 @@ static struct scsi_host_template ahci_sht = {
280 .shost_attrs = ahci_shost_attrs, 280 .shost_attrs = ahci_shost_attrs,
281}; 281};
282 282
283static const struct ata_port_operations ahci_ops = { 283static struct ata_port_operations ahci_ops = {
284 .inherits = &sata_pmp_port_ops,
285
284 .check_status = ahci_check_status, 286 .check_status = ahci_check_status,
285 .check_altstatus = ahci_check_status, 287 .check_altstatus = ahci_check_status,
286 .dev_select = ata_noop_dev_select,
287
288 .dev_config = ahci_dev_config,
289 288
290 .tf_read = ahci_tf_read, 289 .tf_read = ahci_tf_read,
291
292 .qc_defer = sata_pmp_qc_defer_cmd_switch, 290 .qc_defer = sata_pmp_qc_defer_cmd_switch,
293 .qc_prep = ahci_qc_prep, 291 .qc_prep = ahci_qc_prep,
294 .qc_issue = ahci_qc_issue, 292 .qc_issue = ahci_qc_issue,
295 293
296 .irq_clear = ata_noop_irq_clear,
297
298 .scr_read = ahci_scr_read,
299 .scr_write = ahci_scr_write,
300
301 .freeze = ahci_freeze, 294 .freeze = ahci_freeze,
302 .thaw = ahci_thaw, 295 .thaw = ahci_thaw,
303
304 .error_handler = ahci_error_handler, 296 .error_handler = ahci_error_handler,
305 .post_internal_cmd = ahci_post_internal_cmd, 297 .post_internal_cmd = ahci_post_internal_cmd,
306
307 .pmp_attach = ahci_pmp_attach,
308 .pmp_detach = ahci_pmp_detach,
309
310#ifdef CONFIG_PM
311 .port_suspend = ahci_port_suspend,
312 .port_resume = ahci_port_resume,
313#endif
314 .enable_pm = ahci_enable_alpm,
315 .disable_pm = ahci_disable_alpm,
316
317 .port_start = ahci_port_start,
318 .port_stop = ahci_port_stop,
319};
320
321static const struct ata_port_operations ahci_vt8251_ops = {
322 .check_status = ahci_check_status,
323 .check_altstatus = ahci_check_status,
324 .dev_select = ata_noop_dev_select,
325
326 .dev_config = ahci_dev_config, 298 .dev_config = ahci_dev_config,
327 299
328 .tf_read = ahci_tf_read,
329
330 .qc_defer = sata_pmp_qc_defer_cmd_switch,
331 .qc_prep = ahci_qc_prep,
332 .qc_issue = ahci_qc_issue,
333
334 .irq_clear = ata_noop_irq_clear,
335
336 .scr_read = ahci_scr_read, 300 .scr_read = ahci_scr_read,
337 .scr_write = ahci_scr_write, 301 .scr_write = ahci_scr_write,
338
339 .freeze = ahci_freeze,
340 .thaw = ahci_thaw,
341
342 .error_handler = ahci_vt8251_error_handler,
343 .post_internal_cmd = ahci_post_internal_cmd,
344
345 .pmp_attach = ahci_pmp_attach, 302 .pmp_attach = ahci_pmp_attach,
346 .pmp_detach = ahci_pmp_detach, 303 .pmp_detach = ahci_pmp_detach,
347 304
305 .enable_pm = ahci_enable_alpm,
306 .disable_pm = ahci_disable_alpm,
348#ifdef CONFIG_PM 307#ifdef CONFIG_PM
349 .port_suspend = ahci_port_suspend, 308 .port_suspend = ahci_port_suspend,
350 .port_resume = ahci_port_resume, 309 .port_resume = ahci_port_resume,
351#endif 310#endif
352 .enable_pm = ahci_enable_alpm,
353 .disable_pm = ahci_disable_alpm,
354
355 .port_start = ahci_port_start, 311 .port_start = ahci_port_start,
356 .port_stop = ahci_port_stop, 312 .port_stop = ahci_port_stop,
357}; 313};
358 314
359static const struct ata_port_operations ahci_p5wdh_ops = { 315static struct ata_port_operations ahci_vt8251_ops = {
360 .check_status = ahci_check_status, 316 .inherits = &ahci_ops,
361 .check_altstatus = ahci_check_status, 317 .error_handler = ahci_vt8251_error_handler,
362 .dev_select = ata_noop_dev_select, 318};
363
364 .dev_config = ahci_dev_config,
365
366 .tf_read = ahci_tf_read,
367
368 .qc_defer = sata_pmp_qc_defer_cmd_switch,
369 .qc_prep = ahci_qc_prep,
370 .qc_issue = ahci_qc_issue,
371
372 .irq_clear = ata_noop_irq_clear,
373
374 .scr_read = ahci_scr_read,
375 .scr_write = ahci_scr_write,
376
377 .freeze = ahci_freeze,
378 .thaw = ahci_thaw,
379 319
320static struct ata_port_operations ahci_p5wdh_ops = {
321 .inherits = &ahci_ops,
380 .error_handler = ahci_p5wdh_error_handler, 322 .error_handler = ahci_p5wdh_error_handler,
381 .post_internal_cmd = ahci_post_internal_cmd,
382
383 .pmp_attach = ahci_pmp_attach,
384 .pmp_detach = ahci_pmp_detach,
385
386#ifdef CONFIG_PM
387 .port_suspend = ahci_port_suspend,
388 .port_resume = ahci_port_resume,
389#endif
390 .enable_pm = ahci_enable_alpm,
391 .disable_pm = ahci_disable_alpm,
392
393 .port_start = ahci_port_start,
394 .port_stop = ahci_port_stop,
395}; 323};
396 324
397#define AHCI_HFLAGS(flags) .private_data = (void *)(flags) 325#define AHCI_HFLAGS(flags) .private_data = (void *)(flags)