aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/pata_cmd64x.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/pata_cmd64x.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/pata_cmd64x.c')
-rw-r--r--drivers/ata/pata_cmd64x.c96
1 files changed, 10 insertions, 86 deletions
diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index 6aea05cc0940..1ac8ecfb97e2 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -269,103 +269,27 @@ static struct scsi_host_template cmd64x_sht = {
269 ATA_BMDMA_SHT(DRV_NAME), 269 ATA_BMDMA_SHT(DRV_NAME),
270}; 270};
271 271
272static struct ata_port_operations cmd64x_port_ops = { 272static const struct ata_port_operations cmd64x_base_ops = {
273 .inherits = &ata_bmdma_port_ops,
273 .set_piomode = cmd64x_set_piomode, 274 .set_piomode = cmd64x_set_piomode,
274 .set_dmamode = cmd64x_set_dmamode, 275 .set_dmamode = cmd64x_set_dmamode,
275 .mode_filter = ata_pci_default_filter,
276 .tf_load = ata_tf_load,
277 .tf_read = ata_tf_read,
278 .check_status = ata_check_status,
279 .exec_command = ata_exec_command,
280 .dev_select = ata_std_dev_select,
281
282 .freeze = ata_bmdma_freeze,
283 .thaw = ata_bmdma_thaw,
284 .error_handler = ata_bmdma_error_handler,
285 .post_internal_cmd = ata_bmdma_post_internal_cmd,
286 .cable_detect = ata_cable_40wire,
287
288 .bmdma_setup = ata_bmdma_setup,
289 .bmdma_start = ata_bmdma_start,
290 .bmdma_stop = ata_bmdma_stop,
291 .bmdma_status = ata_bmdma_status,
292
293 .qc_prep = ata_qc_prep,
294 .qc_issue = ata_qc_issue_prot,
295
296 .data_xfer = ata_data_xfer,
297
298 .irq_handler = ata_interrupt,
299 .irq_clear = ata_bmdma_irq_clear,
300 .irq_on = ata_irq_on,
301
302 .port_start = ata_sff_port_start,
303}; 276};
304 277
305static struct ata_port_operations cmd646r1_port_ops = { 278static struct ata_port_operations cmd64x_port_ops = {
306 .set_piomode = cmd64x_set_piomode, 279 .inherits = &cmd64x_base_ops,
307 .set_dmamode = cmd64x_set_dmamode,
308 .mode_filter = ata_pci_default_filter,
309 .tf_load = ata_tf_load,
310 .tf_read = ata_tf_read,
311 .check_status = ata_check_status,
312 .exec_command = ata_exec_command,
313 .dev_select = ata_std_dev_select,
314
315 .freeze = ata_bmdma_freeze,
316 .thaw = ata_bmdma_thaw,
317 .error_handler = ata_bmdma_error_handler,
318 .post_internal_cmd = ata_bmdma_post_internal_cmd,
319 .cable_detect = ata_cable_40wire, 280 .cable_detect = ata_cable_40wire,
281};
320 282
321 .bmdma_setup = ata_bmdma_setup, 283static struct ata_port_operations cmd646r1_port_ops = {
322 .bmdma_start = ata_bmdma_start, 284 .inherits = &cmd64x_base_ops,
323 .bmdma_stop = cmd646r1_bmdma_stop, 285 .bmdma_stop = cmd646r1_bmdma_stop,
324 .bmdma_status = ata_bmdma_status, 286 .cable_detect = ata_cable_40wire,
325
326 .qc_prep = ata_qc_prep,
327 .qc_issue = ata_qc_issue_prot,
328
329 .data_xfer = ata_data_xfer,
330
331 .irq_handler = ata_interrupt,
332 .irq_clear = ata_bmdma_irq_clear,
333 .irq_on = ata_irq_on,
334
335 .port_start = ata_sff_port_start,
336}; 287};
337 288
338static struct ata_port_operations cmd648_port_ops = { 289static struct ata_port_operations cmd648_port_ops = {
339 .set_piomode = cmd64x_set_piomode, 290 .inherits = &cmd64x_base_ops,
340 .set_dmamode = cmd64x_set_dmamode,
341 .mode_filter = ata_pci_default_filter,
342 .tf_load = ata_tf_load,
343 .tf_read = ata_tf_read,
344 .check_status = ata_check_status,
345 .exec_command = ata_exec_command,
346 .dev_select = ata_std_dev_select,
347
348 .freeze = ata_bmdma_freeze,
349 .thaw = ata_bmdma_thaw,
350 .error_handler = ata_bmdma_error_handler,
351 .post_internal_cmd = ata_bmdma_post_internal_cmd,
352 .cable_detect = cmd648_cable_detect,
353
354 .bmdma_setup = ata_bmdma_setup,
355 .bmdma_start = ata_bmdma_start,
356 .bmdma_stop = cmd648_bmdma_stop, 291 .bmdma_stop = cmd648_bmdma_stop,
357 .bmdma_status = ata_bmdma_status, 292 .cable_detect = cmd648_cable_detect,
358
359 .qc_prep = ata_qc_prep,
360 .qc_issue = ata_qc_issue_prot,
361
362 .data_xfer = ata_data_xfer,
363
364 .irq_handler = ata_interrupt,
365 .irq_clear = ata_bmdma_irq_clear,
366 .irq_on = ata_irq_on,
367
368 .port_start = ata_sff_port_start,
369}; 293};
370 294
371static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 295static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)