Skip to contentSkip to conversation

porting IDE patches to PATA driver

DISCUSSION Andrei Martynov 4 participants 16 messages Jun 25, 2009 – Jul 4, 2009 libata

lore
Share & tools
lore
#0 lore raw

Hi,

I'm porting Sigma IDE driver for EM85XX chipset from 2.4.17 to 2.6 kernel for an open-source project. Is there any upgrade guide available? If not, what are the modern ATA equivalents for old ide_dma_off, ide_dma_off_quietly and ide_dma_test_irq commands?

Signature · 2 lines
Best regards,
 Andrei                          mailto:[email protected]
#1 lore raw
Quoted 6 lines · On Thu, 25 Jun 2009 10:09:56 +0200 Andrei Martynov <[email protected]>…

Hi,

I'm porting Sigma IDE driver for EM85XX chipset from 2.4.17 to 2.6 kernel for an open-source project. Is there any upgrade guide available? If not, what are the modern ATA equivalents for old ide_dma_off, ide_dma_off_quietly and ide_dma_test_irq commands?

Are you trying to port it to the legacy IDE code in 2.6 or to libata ?

#2 lore raw

Hi Alan,

Quoted 3 lines · you
Quoted 1 line

I'm porting Sigma IDE driver for EM85XX chipset from 2.4.17 to 2.6

Are you trying to port it to the legacy IDE code in 2.6 or to libata ?

I'm trying to port it to libata. My PATA driver already supports EM8511 chipset but I constantly get errors on EM8500 chipset.

Signature · 2 lines
Best regards,
 Andrei                            mailto:[email protected]
#3 lore raw
Quoted 10 lines · On Thu, 25 Jun 2009 10:38:34 +0200 Andrei Martynov <[email protected]>…

Hi Alan,

Quoted 3 lines · you
Quoted 1 line

I'm porting Sigma IDE driver for EM85XX chipset from 2.4.17 to 2.6

Are you trying to port it to the legacy IDE code in 2.6 or to libata ?

I'm trying to port it to libata. My PATA driver already supports EM8511 chipset but I constantly get errors on EM8500 chipset.

Assuming you are using the standard qc_issue (ie you've not overridden it) then:

bmdma_setup is called at the start of the DMA command bmdma_start is called to begin a DMA transfer bmdma_stop is called to end one

For ATA you get

bmdma_setup
bmdma_start
DMA
bmdma_stop

for ATAPI

bmdma_setup
PIO CDB
bmdma_start
bmdma_stop

Also related to this is check_atapi_dma which is passed a potential ATAPI command and you can return zero for OK for DMA or an error to make the kernel switch that command to PIO.

#4 lore raw

Hi Alan,

Quoted 3 lines · you

bmdma_setup is called at the start of the DMA command bmdma_start is called to begin a DMA transfer bmdma_stop is called to end one

thank you for the hint. Maybe I misunderstand something, but this functions do not look like equivalents of old ide_dma_off, ide_dma_off_quietly and ide_dma_on commands. The logic implemented in the old code is "stop DMA transfer but do not disable DMA in case of errors".

I've implemented UDMA support for EM8511 but cannot get MW-DMA working on EM8500. Either it is as slow as PIO mode or kernel complains about unhandled IRQ:

platform: Probing driver pata_jasper with device pata_jasper JASPER PATA (IDE) chipset 8500: UDMA is not supported scsi0 : pata_jasper
DEV: registering device: ID = 'host0'
CLASS: registering class device: ID = 'host0'
ata1: PATA max MWDMA2 irq 11
jasper_tune_chipset: slave = 0 speed = 0x08
jasper_tune_chipset: slave = 1 speed = 0x08
ata1.00: ATAPI: 9929D05E59V1.500P3311077, , max MWDMA2
jasper_tune_chipset: slave = 0 speed = 0x0c
jasper_tune_chipset: slave = 0 speed = 0x22
ata1.00: configured for MWDMA2
DEV: registering device: ID = 'target0:0:0'
scsi 0:0:0:0: CD-ROM 9929D05E 59V1.500P3311077 3311 PQ: 0 ANSI: 5
DEV: registering device: ID = '0:0:0:0'
bus scsi: add device 0:0:0:0
scsi: Matched Device 0:0:0:0 with Driver sd
scsi: Probing driver sd with device 0:0:0:0
scsi: Matched Device 0:0:0:0 with Driver sr
scsi: Probing driver sr with device 0:0:0:0
irq 11: nobody cared (try booting with the "irqpoll" option) Function entered at [<011545e0>] from [<01046c98>] Function entered at [<01046c60>] from [<01046f24>]

Signature · 2 lines
Best regards,
 Andrei                            mailto:[email protected]
#5 lore raw
Quoted 2 lines

ide_dma_off_quietly and ide_dma_on commands. The logic implemented in the old code is "stop DMA transfer but do not disable DMA in case of errors".

The two layers don't line up 1:1. In the event of a timeout then libata layer calls the ->lost_interrupt() which if you inherit from bmdma checks controller status in the taskfiles to see if the command finished fine by the IRQ was lost before deciding an error situation occurs

If we get an error we quiesce the channel entirely and then recover it.

It would be useful I think if you posted the current code, and also to know if you see the same problem (lost IRQ etc) with ATAPI as well as ATA

#6 lore raw

Hi Alan,

Quoted 2 lines · you

It would be useful I think if you posted the current code, and also to know if you see the same problem (lost IRQ etc) with ATAPI as well as ATA

I've attached the current driver and reduced set of patches I'm trying to port. Truly speaking I have very little knowledge about IDE / ATAPI interfaces and simply try to reproduce the original logic using modern libata functions. As you can see the new pata driver redefines set_piomode / set_dmamode to tune chipset and bmdma_start to flush CPU cache. It works fine in UDMA mode on a newer chipset but I cannot get MW-DMA working on an older chipset.

The complete patch for the EM85XX architecture can be found at
http://mg35tools.svn.sourceforge.net/viewvc/mg35tools/trunk/sources/linux-2.6/

original 2.4.17 kernel for Sigma EM8500 is published at
http://www.uclinux.org/pub/uClinux/ports/arm/EM8500/

Signature · 2 lines
Best regards,
 Andrei                            mailto:[email protected]
include/asm-armnommu/arch-jasper/ide.h new file +73 -0
diff -r 1e6ff995c4ef include/asm-armnommu/arch-jasper/ide.h
@@ -0,0 +1,73 @@
+/*
+ * linux/include/asm-armnommu/arch-jasper/ide.h
+ *
+ */
+ 
+#include <linux/config.h>
+#include <asm/irq.h>
+#include <asm/hardware.h>
+
+#define HAVE_ARCH_IN_BYTE
+#define HAVE_ARCH_OUT_BYTE
+
+#define OUT_BYTE(b,p)                \
+do {                                 \
+   int _tmp_;                        \
+   outb((b),(p));                    \
+   for(_tmp_=0; _tmp_<1000; _tmp_++);  \
+} while(0) 
+
+static inline byte jasper_ide_in_byte(int p)
+{
+	byte b; int _tmp;
+
+	b = (byte)inb(p);
+	for(_tmp=0; _tmp<1000; _tmp++);
+	return b;
+}
+
+#define IN_BYTE(p) jasper_ide_in_byte(p)
+
+
+/*
+ * Set up a hw structure for a specified data port, control port and IRQ.
+ * This should follow whatever the default interface uses.
+ */
+static __inline__ void
+ide_init_hwif_ports(hw_regs_t *hw, int data_port, int ctrl_port, int *irq)
+{
+	ide_ioreg_t reg;
+	int i;
+	int regincr = 1;
+	
+	memset(hw, 0, sizeof(*hw));
+
+	reg = (ide_ioreg_t)data_port;
+
+	for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
+		hw->io_ports[i] = reg;
+		reg += regincr;
+	}
+	
+	hw->io_ports[IDE_CONTROL_OFFSET] = (ide_ioreg_t) ctrl_port;
+	
+	if (irq)
+		*irq = 0;
+}
+
+
+/*
+ * This registers the standard ports for this architecture with the IDE
+ * driver.
+ */
+static __inline__ void
+ide_init_default_hwifs(void)
+{
+    hw_regs_t hw;
+
+    ide_init_hwif_ports(&hw, JASPER_IDE_BASE + IDE_PRI_DATA, JASPER_IDE_BASE + IDE_PRI_DEVICE_CONTROL, NULL);
+    hw.irq = IDE_IRQ;
+    ide_register_hw(&hw, NULL);
+}
+
+
drivers/ide/ide-cd.c +71 -3

124 lines not on this page · raw message

drivers/ide/ide-cd.h +1 -0
diff -r 1e6ff995c4ef drivers/ide/ide-cd.h
@@ -109,6 +109,7 @@ struct packet_command {
 	int quiet;
 	int timeout;
 	struct request_sense *sense;
+	int do_dma;
 	unsigned char c[12];
 };
 
drivers/ide/ide-dma.c +115 -14

238 lines not on this page · raw message

drivers/ide/ide-features.c +6 -3
diff -r 1e6ff995c4ef drivers/ide/ide-features.c
@@ -285,10 +285,11 @@ int ide_config_drive_speed (ide_drive_t 
 	int	i, error = 1;
 	byte stat;
 
-#if defined(CONFIG_BLK_DEV_IDEDMA) && !defined(CONFIG_DMA_NONPCI)
+#if 0//defined(CONFIG_BLK_DEV_IDEDMA) && !defined(CONFIG_DMA_NONPCI)
 	byte unit = (drive->select.b.unit & 0x01);
-	outb(inb(hwif->dma_base+2) & ~(1<<(5+unit)), hwif->dma_base+2);
+	outb(inb(hwif->dma_base+4) & ~(1<<(5+unit)), hwif->dma_base+4);
 #endif /* (CONFIG_BLK_DEV_IDEDMA) && !(CONFIG_DMA_NONPCI) */
+
 
 	/*
 	 * Don't use ide_wait_cmd here - it will
@@ -355,13 +356,15 @@ int ide_config_drive_speed (ide_drive_t 
 	drive->id->dma_mword &= ~0x0F00;
 	drive->id->dma_1word &= ~0x0F00;
 
-#if defined(CONFIG_BLK_DEV_IDEDMA) && !defined(CONFIG_DMA_NONPCI)
+
+#if 0 //defined(CONFIG_BLK_DEV_IDEDMA) && !defined(CONFIG_DMA_NONPCI)
 	if (speed > XFER_PIO_4) {
 		outb(inb(hwif->dma_base+2)|(1<<(5+unit)), hwif->dma_base+2);
 	} else {
 		outb(inb(hwif->dma_base+2) & ~(1<<(5+unit)), hwif->dma_base+2);
 	}
 #endif /* (CONFIG_BLK_DEV_IDEDMA) && !(CONFIG_DMA_NONPCI) */
+
 
 	switch(speed) {
 		case XFER_UDMA_7:   drive->id->dma_ultra |= 0x8080; break;
drivers/ide/ide-jasper.c new file +197 -0

197 lines not on this page · raw message

drivers/ide/ide-probe.c +26 -1
diff -r 1e6ff995c4ef drivers/ide/ide-probe.c
@@ -193,6 +193,7 @@ static int actual_try_to_identify (ide_d
 	ide_ioreg_t hd_status;
 	unsigned long timeout;
 	byte s, a;
+//	int i;
 
 	if (IDE_CONTROL_REG) {
 		/* take a deep breath */
@@ -209,11 +210,14 @@ static int actual_try_to_identify (ide_d
 		ide_delay_50ms();
 		hd_status = IDE_STATUS_REG;
 	}
+/*	for(i=0; i<10; i++)*/
+		ide_delay_50ms();
 
 	/* set features register for atapi identify command to be sure of reply */
 	if ((cmd == WIN_PIDENTIFY))
 		OUT_BYTE(0,IDE_FEATURE_REG);	/* disable dma & overlap */
-
+/*	for(i=0; i<10; i++)*/
+		ide_delay_50ms();
 #if CONFIG_BLK_DEV_PDC4030
 	if (HWIF(drive)->chipset == ide_pdc4030) {
 		/* DC4030 hosted drives need their own identify... */
@@ -224,6 +228,8 @@ static int actual_try_to_identify (ide_d
 	} else
 #endif /* CONFIG_BLK_DEV_PDC4030 */
 		OUT_BYTE(cmd,IDE_COMMAND_REG);		/* ask drive for ID */
+//	for(i=0; i<10; i++)
+		ide_delay_50ms();
 	timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
 	timeout += jiffies;
 	do {
@@ -319,6 +325,25 @@ static int do_probe (ide_drive_t *drive,
 	ide_delay_50ms();	/* needed for some systems (e.g. crw9624 as drive0 with disk as slave) */
 	SELECT_DRIVE(hwif,drive);
 	ide_delay_50ms();
+
+#ifdef CONFIG_COLDFIRE
+	    /*
+		 *  ColdFire platforms boot up so quick that most hard drives
+		 *  have not completed there own self tests. Pause here for
+		 *  a couple of seconds if it looks like there is a drive
+		 *  present...
+		 */
+	    if (IN_BYTE(IDE_SELECT_REG) != drive->select.all) {
+			printk("IDE: waiting for drives to settle...\n");
+			for (rc = 0; (rc < 400); rc++) {
+				SELECT_DRIVE(hwif,drive);
+				ide_delay_50ms();
+				if (IN_BYTE(IDE_SELECT_REG) == drive->select.all)
+					break;
+			}
+		}
+#endif
+
 	if (IN_BYTE(IDE_SELECT_REG) != drive->select.all && !drive->present) {
 		if (drive->select.b.unit != 0) {
 			SELECT_DRIVE(hwif,&hwif->drives[0]);	/* exit with drive0 selected */
drivers/ide/ide-tape.c +1 -1
diff -r 1e6ff995c4ef drivers/ide/ide-tape.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1995 - 1999 Gadi Oxman <[email protected]>
  *
- * $Header$
+ * $Header: /EM85xx/uClinux-2.4/drivers/ide/ide-tape.c 1     6/07/02 12:43p Fabrice $
  *
  * This driver was constructed as a student project in the software laboratory
  * of the faculty of electrical engineering in the Technion - Israel's
drivers/ide/ide.c +17 -6
diff -r 1e6ff995c4ef drivers/ide/ide.c
@@ -430,11 +431,18 @@ void ide_input_data (ide_drive_t *drive,
 			insl(IDE_DATA_REG, buffer, wcount);
 	} else {
 #if SUPPORT_SLOW_DATA_PORTS
-		if (drive->slow) {
-			unsigned short *ptr = (unsigned short *) buffer;
+		if (1) { // drive->slow) { // we cant use insw with any alignement also
+			unsigned char *ptr = (unsigned char *) buffer;
+			unsigned short w;
 			while (wcount--) {
-				*ptr++ = inw_p(IDE_DATA_REG);
-				*ptr++ = inw_p(IDE_DATA_REG);
+//				tmp = 100; while(tmp--);
+				w = inw_p(IDE_DATA_REG);
+				*ptr++ = (unsigned char)(w & 0xFF);
+				*ptr++ = (unsigned char)(w >> 8);
+//				tmp = 100; while(tmp--);
+				w = inw_p(IDE_DATA_REG);
+				*ptr++ = w&0xFF;
+				*ptr++ = w>>8;
 			}
 		} else
 #endif /* SUPPORT_SLOW_DATA_PORTS */
@@ -448,6 +456,7 @@ void ide_output_data (ide_drive_t *drive
 void ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
 {
 	byte io_32bit;
+	int tmp;
 
 	if(HWIF(drive)->ideproc) {
 		HWIF(drive)->ideproc(ideproc_ide_output_data,
@@ -471,10 +480,12 @@ void ide_output_data (ide_drive_t *drive
 			outsl(IDE_DATA_REG, buffer, wcount);
 	} else {
 #if SUPPORT_SLOW_DATA_PORTS
-		if (drive->slow) {
+		if (1) { // *hack* drive->slow) { 
 			unsigned short *ptr = (unsigned short *) buffer;
 			while (wcount--) {
+				tmp = 10; while(tmp--);
 				outw_p(*ptr++, IDE_DATA_REG);
+				tmp = 10; while(tmp--);
 				outw_p(*ptr++, IDE_DATA_REG);
 			}
 		} else
@@ -1600,7 +1611,8 @@ void ide_timer_expiry (unsigned long dat
 			} else {
 				if (drive->waiting_for_dma) {
 					startstop = ide_stopped;
-					ide_dma_timeout_retry(drive);
+					// XXX sigma do not retry
+					//ide_dma_timeout_retry(drive);
 				} else
 					startstop = ide_error(drive, "irq timeout", GET_STAT());
 			}

/* ide-jasper.c */

/* jasper specific initialization stuff for ide */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/blkdev.h>
#include <linux/delay.h>
#include <scsi/scsi_host.h>
#include <linux/libata.h>
#include <linux/platform_device.h>

#define DRV_NAME "pata_jasper"
#define DRV_VERSION "0.1"

#include <asm/io.h>
#include <asm/hardware.h>
#include <asm/arch/quasar.h>

// updated to match stock ide driver firmware 1.5.2 static int jasper_tune_chipset(int slave, u8 speed)

{
	unsigned short reg54, reg58;

	speed = speed & 0xFF;

	printk("jasper_tune_chipset: speed = %02x\n", speed);

	/*unsigned int */reg54 = inw(JASPER_IDE_BASE + IDE_UDMACTL);
	/*unsigned int */reg58 = inw(JASPER_IDE_BASE + IDE_UDMATIM);

	if (speed>=XFER_UDMA_0 && speed<=XFER_UDMA_5) {
		if(slave != 0) {
			reg54 |= 0x2;
			reg58 |= (speed-XFER_UDMA_0)<<4;
		}else {
			reg54 |= 0x1;
			reg58 |= (speed-XFER_UDMA_0);
		}

		if (speed == XFER_UDMA_0) {
			outl(0x11100009 + 0x10C00, JASPER_IDE_BASE + IDE_UDMATIM);
			outl(5, JASPER_IDE_BASE + 0x5C);
		} 
			else if (speed == XFER_UDMA_1)
		{
			outl(0x11110A06, JASPER_IDE_BASE + IDE_UDMATIM);
			outl(3, JASPER_IDE_BASE + 0x5C);
		}
			else 
		{
			outl(0x11100004 + 0x10800, JASPER_IDE_BASE + IDE_UDMATIM);
			outl(2, JASPER_IDE_BASE + 0x5C);
		}
	}
		else
	{
		if (!(speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2)) {
			if (slave != 0) {
				reg54 &= ~0x2;
			} else {
				reg54 &= ~0x1;
			}
		}
	}
	outl(0x89000110, JASPER_IDE_BASE + 0x44);
	outw(reg54, JASPER_IDE_BASE + IDE_UDMACTL);
	outw(reg58, JASPER_IDE_BASE + IDE_UDMATIM);
	return 0; //ide_config_drive_speed(drive, speed);
}

static void jasper_set_dmamode (struct ata_port *ap, struct ata_device *adev) {

//	int slave = adev->devno;
	jasper_tune_chipset(0/*slave*/, adev->dma_mode);
}

static void jasper_set_piomode(struct ata_port *ap, struct ata_device *adev) {

//	int slave = adev->devno;
	jasper_tune_chipset(0/*slave*/, adev->pio_mode);
}

// standard is 2 (!)
#define JASPER_ATA_DMA_STATUS 4
// standard is 4
#define JASPER_ATA_DMA_TABLE_OFS 8

static void jasper_bmdma_start(struct ata_queued_cmd *qc)

{
	__asm__(
		"mcr	p15, 0, %0, c7, c10, 0\n"		// write-back data cache
		: : "r" (0)
	);
	ata_bmdma_start(qc);
}
static struct scsi_host_template jasper_sht = {
	.module			= THIS_MODULE,
	.name			= DRV_NAME,
	.ioctl			= ata_scsi_ioctl,
	.queuecommand		= ata_scsi_queuecmd,
	.can_queue		= ATA_DEF_QUEUE,
	.this_id		= ATA_SHT_THIS_ID,
	.sg_tablesize		= LIBATA_DUMB_MAX_PRD,
	.cmd_per_lun		= ATA_SHT_CMD_PER_LUN,
	.emulated		= ATA_SHT_EMULATED,
	.use_clustering		= ATA_SHT_USE_CLUSTERING,
	.proc_name		= DRV_NAME,
	.dma_boundary		= ATA_DMA_BOUNDARY,
	.slave_configure	= ata_scsi_slave_config,
	.slave_destroy		= ata_scsi_slave_destroy,
	.bios_param		= ata_std_bios_param,
};
static struct ata_port_operations jasper_port_ops = {
	.set_piomode		= jasper_set_piomode,
	.set_dmamode		= jasper_set_dmamode,

	.tf_load		= ata_tf_load,
	.tf_read		= ata_tf_read,
	.check_status		= ata_check_status,
	.exec_command		= ata_exec_command,
	.dev_select		= ata_std_dev_select,

	.freeze			= ata_bmdma_freeze,
	.thaw			= ata_bmdma_thaw,
	.error_handler		= ata_bmdma_error_handler,
	.post_internal_cmd	= ata_bmdma_post_internal_cmd,
	.cable_detect		= ata_cable_40wire,

	.bmdma_setup		= ata_bmdma_setup,

	.bmdma_start		= jasper_bmdma_start,
	.bmdma_stop		= ata_bmdma_stop,
	.bmdma_status		= ata_bmdma_status,

	.qc_prep		= ata_dumb_qc_prep,
	.qc_issue		= ata_qc_issue_prot,
	.data_xfer		= ata_data_xfer,

	.irq_clear		= ata_bmdma_irq_clear,
	.irq_on			= ata_irq_on,

	.port_start		= ata_port_start/*ata_sff_port_start*/,
};

static int __devinit jasper_atapi_probe(struct platform_device *pdev)

{
	struct ata_host *host;
	struct ata_ioports *ioaddr;

	struct ata_port_info pi = {
		.sht		= &jasper_sht,
		.flags		= ATA_FLAG_SLAVE_POSS,
		.pio_mask	= 0x1f,
		.port_ops	= &jasper_port_ops,
#ifdef CONFIG_JASPER_IDE_UDMA
		.mwdma_mask = 0x07,
		.udma_mask = 0x07,
#endif
	};
	const struct ata_port_info *ppi[] = { &pi, NULL };

	int can_udma;

	int chipsetID = __raw_readl(JASPER_SYSCTRL_BASE + SYSCTRL_CHIP_ID);
	can_udma = chipsetID > 0x8500;
	printk("JASPER PATA (IDE) chipset %x: UDMA is %ssupported\n", chipsetID, can_udma ? "" : "not ");
	//	choose ide over dvd loader (DVD_AV_CONTROL)
	//	write 0x8000 to IDETIM

	outl(/*R1*/ 0xffffff - 0xef0000, /*R0*/ JASPER_PIO0_BASE + PIO_DIR);
	outl(/*R1*/ 0xffffff - 0xef0000, /* R3 */ JASPER_PIO0_BASE + PIO_DATA);
	//	choose ide over dvd loader (DVD_AV_CONTROL)
	outl(0x00, JASPER_DVD_BASE + DVD_AV_CTRL);	//0x00 select IDE over DVD-loader
	outw(0x00, JASPER_IDE_BASE + 0x34);
	outl(0x8400+0xF, JASPER_IDE_BASE + IDE_TIM);
//	ppi[0] = ppi[1] = &pi;
	host = ata_host_alloc_pinfo(&pdev->dev, ppi, 1);
	if (!host)
		return -ENOMEM;
	ioaddr = &host->ports[0]->ioaddr;

	ioaddr->cmd_addr = __io(JASPER_IDE_BASE + IDE_PRI_DATA);
	ioaddr->ctl_addr = __io(JASPER_IDE_BASE + IDE_PRI_DEVICE_CONTROL);
	ioaddr->altstatus_addr = __io(JASPER_IDE_BASE + IDE_PRI_DEVICE_CONTROL);
	ioaddr->bmdma_addr = __io(JASPER_IDE_DMA_BASE);

	ata_std_ports(ioaddr); // sets other regs based on cmd_addr

	return ata_host_activate(host, IDE_IRQ, ata_interrupt, IRQF_SHARED,
				 &jasper_sht);
}

/**
* jasper_atapi_remove - unplug a jasper atapi interface
* @pdev: platform device
*
* A jasper atapi device has been unplugged. Perform the needed
* cleanup. Also called on module unload for any active devices.
*/
static int __devexit jasper_atapi_remove(struct platform_device *pdev)

{
	struct device *dev = &pdev->dev;
	struct ata_host *host = dev_get_drvdata(dev);

	ata_host_detach(host);

// peripheral_free_list(atapi_io_port);

	return 0;
}
static struct platform_driver jasper_atapi_driver = {
	.probe			= jasper_atapi_probe,
	.remove			= __devexit_p(jasper_atapi_remove),
	.driver = {
		.name		= DRV_NAME,
		.owner		= THIS_MODULE,
#ifdef CONFIG_PM
		.suspend	= jasper_atapi_suspend,
		.resume		= jasper_atapi_resume,
#endif
	},
};

static int __init jasper_atapi_init(void)

{
	return platform_driver_register(&jasper_atapi_driver);
}

static void __exit jasper_atapi_exit(void)

{
	platform_driver_unregister(&jasper_atapi_driver);
}

module_init(jasper_atapi_init);
module_exit(jasper_atapi_exit);

MODULE_AUTHOR("Anonymous");
MODULE_DESCRIPTION("JASPER IDE driver");
MODULE_LICENSE("GPL");

#7 lore raw
Quoted 2 lines

libata functions. As you can see the new pata driver redefines set_piomode / set_dmamode to tune chipset and bmdma_start to flush CPU cache. It

The bmdma_start shouldn't be needed. Libata knows about using the cache coherency dma interfaces and uses them.

The bmdma end is no standard and polls the status up to 100 times until it gives a sensible looking answer. That may be needed but its hard to guess from just horrible code if that was someone's random debug hacks or a real chip erratum.

Quoted 2 lines

works fine in UDMA mode on a newer chipset but I cannot get MW-DMA working on an older chipset.

I notice the 2.4.17 patches you are referencing don't enable MWDMA either (#undef EBABLE_BMDMA) so does MWDMA actually work on the hardware ?

Alan

#8 lore raw

Hello Alan,

Quoted 2 lines · you

The bmdma_start shouldn't be needed. Libata knows about using the cache coherency dma interfaces and uses them.

Correct, libata does call corresponding interface and the functions are defined for the cpu. But this architecture is buggy. It is necessary to clean (write back) complete cache before DMA write operation even if the corresponding range is already cleaned, otherwise few bytes in the written block are corrupted at random offset. I've spent many days playing with dma interface and even calculating md5sum of every written block before I had to accept this fact.

Quoted 4 lines

The bmdma end is no standard and polls the status up to 100 times until it gives a sensible looking answer. That may be needed but its hard to guess from just horrible code if that was someone's random debug hacks or a real chip erratum.

Chip is really weird. A group of enthusiasts implemented slave device support for it. As I could understand from their explanation the controller switches to a specific DVD-LOADER mode as soon as kernel sends any command to the slave device, so they had to patch sources and add a strange looking command

OUT_BYTE((head|drive->select.all) & ~(1<<4), IDE_SELECT_REG);

everywhere the slave device is accessed to cheat the controller and let it believe it talks to the master. Slave device remains active because it was already selected but the controller assumes we are talking to the master and does not switch to DVD-LOADER mode.

Quoted 2 lines

I notice the 2.4.17 patches you are referencing don't enable MWDMA either (#undef EBABLE_BMDMA) so does MWDMA actually work on the hardware ?

Here is a part of the boot log with 2.4.17 kernel. Speed is set to 0x22 (XFER_MW_DMA_2), that's why I assume it should work. I can limit allowed modes to PIO-only in 2.6 kernel, the driver is working but it is too slow.

Uniform Multi-Platform E-IDE driver Revision: 6.31
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx JASPER ide controller activated
ide0: BM-DMA at 0x500e00-0x500e0f, BIOS settings: hda:pio, hdb:pio
hda: IDE_SELECT Reg = 000000a0
hda: IDE_SIDETIM Reg = 00000000
hda: IDE_SELECT Reg = 000000a0
hda: IDE_SIDETIM Reg = 00000000
hda: 9929D05E59V1.500P3311077, ATAPI CD/DVD-ROM drive
IDE: waiting for drives to settle...
hdb: IDE_SELECT Reg = 000000b0
hdb: IDE_SIDETIM Reg = 00000000
hdb: SAMSUNG HD300LD, ATA DISK drive
ide0 at 0x500bf0-0x500bf7,0x500be6 on irq 11
hdb: ignore DMA off message.
model = SAMSUNG HD300LD
firmware version = WK100-12
jasper_config_drive_for_dma:
capability = 0x002f
field_valid = 0x0007
dma_ultra = 0x003f
dma_1word (s) = 0x0000
dma_mword (m) = 0x0407
autodma = 0x0001
jasper_tune_chipset: speed = 22
***** init_idedisk_capacity: set_max_ext=15647024, capacity_2=586070255
hdb: 586070255 sectors (300068 MB) w/8192KiB Cache, CHS=36481/255/63, (U)DMA
hda: ignore DMA off message.
model = 9929D05E59V1.500P3311077
firmware version =
jasper_config_drive_for_dma:
capability = 0x000b
field_valid = 0x0002
dma_ultra = 0x0000
dma_1word (s) = 0x0000
dma_mword (m) = 0x0407
autodma = 0x0001
jasper_tune_chipset: speed = 22
hda: ATAPI 32X DVD-ROM drive, 256kB Cache, DMA
Uniform CD-ROM driver Revision: 3.12
Partition check:
/dev/ide/host0/bus0/target1/lun0: p1 < p5 p6 >

Signature · 2 lines
Best regards,
 Andrei                            mailto:[email protected]
#9 lore raw
Quoted 8 lines

Correct, libata does call corresponding interface and the functions are defined for the cpu. But this architecture is buggy. It is necessary to clean (write back) complete cache before DMA write operation even if the corresponding range is already cleaned, otherwise few bytes in the written block are corrupted at random offset. I've spent many days playing with dma interface and even calculating md5sum of every written block before I had to accept this fact.

In which case you ultimately want to fix the architecture defintions for the DMA cohrency really but thats a side issue as it doesn't explain the MWDMA problem. The source you posted has MWDMA undefined which makes me wonder if it matches the binary your dmesg is from. It's also possible some of the other fixes in that code are relevant to MWDMA - certainly your driver looks sane.

Quoted 10 lines

controller switches to a specific DVD-LOADER mode as soon as kernel sends any command to the slave device, so they had to patch sources and add a strange looking command

OUT_BYTE((head|drive->select.all) & ~(1<<4), IDE_SELECT_REG);

everywhere the slave device is accessed to cheat the controller and let it believe it talks to the master. Slave device remains active because it was already selected but the controller assumes we are talking to the master and does not switch to DVD-LOADER mode.

That can be done in a libata driver by providing your own exec_command functions but again could wait. Try something like

static void my_sff_exec_command(struct ata_port *ap, const struct
ata_taskfile *tf)

{
	iowrite8(tf->command, ap->ioaddr.command_addr);
	if (tf->flags & ATA_TFLAG_DEVICE)
		iowrite8(tf->device & ~ATA_DEV1, ap->ioaddr.device_addr);
	ata_sff_pause(ap);
}

.sff_exec_command = my_sff_exec_command,

#10 lore raw

Hello.

Quoted 15 lines · Alan Cox
Quoted 11 lines

controller switches to a specific DVD-LOADER mode as soon as kernel sends any command to the slave device, so they had to patch sources and add a strange looking command

OUT_BYTE((head|drive->select.all) & ~(1<<4), IDE_SELECT_REG);

everywhere the slave device is accessed to cheat the controller and let it believe it talks to the master. Slave device remains active because it was already selected but the controller assumes we are talking to the master and does not switch to DVD-LOADER mode.

That can be done in a libata driver by providing your own exec_command functions but again could wait. Try something like

Quoted 7 lines

static void my_sff_exec_command(struct ata_port *ap, const struct
ata_taskfile *tf)

{
	iowrite8(tf->command, ap->ioaddr.command_addr);
	if (tf->flags & ATA_TFLAG_DEVICE)
		iowrite8(tf->device & ~ATA_DEV1, ap->ioaddr.device_addr);

Note that this possibly violates ATA specs that forbid writing to any
register with BSY set -- which might well be after wroiting a command, despite 400 ns couldn't have passed yet. IOW, I don't advice such trickery -- your write may well be ignored.

Quoted 2 lines
	ata_sff_pause(ap);
}

MBR, Sergei

#12 lore raw
In reply to Alan Cox
Quoted 5 lines · Alan

The source you posted has MWDMA undefined which makes me wonder if it matches the binary your dmesg is from.

It's also possible some of the other fixes in that code are relevant to MWDMA - certainly your driver looks sane.

you are right. I'm working with multiple sources from different sites and missed the fact the original driver ide-jasper.c published at uclinux.org has BMDMA undefined. Dmegs output was produced using a slightly modified version of the file that has BMDMA defined, but there are no other changes in it that would explain unexpected DMA interrupt mystery, it should be one of the patches done to ide and cdrom subsystem.

Here is an updated patch, could you please check it? I don't see anything unusual except the "never disable DMA" logic in ide_dma.c.

Signature · 2 lines
Best regards,
 Andrei                            mailto:[email protected]
#11 lore raw
In reply to Sergei Shtylyov
Quoted 9 lines
Quoted 4 lines
	iowrite8(tf->command, ap->ioaddr.command_addr);
	if (tf->flags & ATA_TFLAG_DEVICE)
		iowrite8(tf->device & ~ATA_DEV1, ap->ioaddr.device_addr);

Note that this possibly violates ATA specs that forbid writing to any
register with BSY set -- which might well be after wroiting a command, despite 400 ns couldn't have passed yet. IOW, I don't advice such trickery -- your write may well be ignored.

As far as I can make out from the discussion of the device that write goes to the magic hardware and puts it back into normal ATA mode not to the device. I guess it may be going to both though.

Wacky hacks for wacky hardware

#13 lore raw
In reply to Andrei Martynov
Quoted 7 lines

you are right. I'm working with multiple sources from different sites and missed the fact the original driver ide-jasper.c published at uclinux.org has BMDMA undefined. Dmegs output was produced using a slightly modified version of the file that has BMDMA defined, but there are no other changes in it that would explain unexpected DMA interrupt mystery, it should be one of the patches done to ide and cdrom subsystem.

Still odd as it never sets the timings for anything but UDMA mode. I guess it could be that the hardware snoops for MWDMA and PIO modes

Quoted 2 lines

Here is an updated patch, could you please check it? I don't see anything unusual except the "never disable DMA" logic in ide_dma.c.

Which itself appears to be ignored !

The only other thing I can see is the way it hangs around waiting a bit for the DMA to finish after the DMA completion event occurs - that might be your problem if they goofed and reported DMA complete too early.

Hard to tell as the original vendor driver is such a mess.

#14 lore raw
Quoted 3 lines · Alan Cox

The only other thing I can see is the way it hangs around waiting a bit for the DMA to finish after the DMA completion event occurs - that might be your problem if they goofed and reported DMA complete too early.

Thank you very much for your advices. Reading from disk works fine now but writing attempt results in a series of similar error messages. What is the meaning of this error? Is there any documentation that may be useful to understand libata error messages?

~ # cp /hdd/c/Test/test.dat /hdd/d
ata1.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x0 ata1.00: BMDMA stat 0x6
ata1.00: cmd 35/00:98:40:6f:fe/00:01:20:00:00/e0 tag 0 dma 208896 out

         res 50/00:00:d7:70:fe/00:00:20:00:00/e0 Emask 0x20 (host bus error)

ata1.00: status: { DRDY }
jasper_set_piomode: devno = 0
jasper_tune_chipset: slave = 0 speed = 0x0c
jasper_set_dmamode: devno = 0
jasper_tune_chipset: slave = 0 speed = 0x22
ata1.00: configured for MWDMA2
ata1: EH complete
sd 0:0:0:0: [sda] 586070255 512-byte hardware sectors (300068 MB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA ata1.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x0
ata1.00: BMDMA stat 0x6
ata1.00: cmd 35/00:a0:b0:72:fe/00:01:20:00:00/e0 tag 0 dma 212992 out

         res 50/00:00:4f:74:fe/00:00:20:00:00/e0 Emask 0x20 (host bus error)

ata1.00: status: { DRDY }
jasper_set_piomode: devno = 0
jasper_tune_chipset: slave = 0 speed = 0x0c
jasper_set_dmamode: devno = 0
jasper_tune_chipset: slave = 0 speed = 0x22
ata1.00: configured for MWDMA2
ata1: EH complete

Signature · 2 lines
Best regards,
 Andrei                            mailto:[email protected]
#15 lore raw
Quoted 6 lines · Andrei Martynov
Quoted 3 lines · Alan Cox

The only other thing I can see is the way it hangs around waiting a bit for the DMA to finish after the DMA completion event occurs - that might be your problem if they goofed and reported DMA complete too early.

Quoted 8 lines

Thank you very much for your advices. Reading from disk works fine now but writing attempt results in a series of similar error messages. What is the meaning of this error? Is there any documentation that may be useful to understand libata error messages?

~ # cp /hdd/c/Test/test.dat /hdd/d
ata1.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x0 ata1.00: BMDMA stat 0x6

BMDMA status 0x6 means DMA failed because the adapter encountered an error transferring data to/from host memory (from the PCI ATA host adapter spec). Some problem in the adapter setup?

Quoted 26 lines

ata1.00: cmd 35/00:98:40:6f:fe/00:01:20:00:00/e0 tag 0 dma 208896 out

          res 50/00:00:d7:70:fe/00:00:20:00:00/e0 Emask 0x20 (host bus error)

ata1.00: status: { DRDY }
jasper_set_piomode: devno = 0
jasper_tune_chipset: slave = 0 speed = 0x0c
jasper_set_dmamode: devno = 0
jasper_tune_chipset: slave = 0 speed = 0x22
ata1.00: configured for MWDMA2
ata1: EH complete
sd 0:0:0:0: [sda] 586070255 512-byte hardware sectors (300068 MB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA ata1.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x0
ata1.00: BMDMA stat 0x6
ata1.00: cmd 35/00:a0:b0:72:fe/00:01:20:00:00/e0 tag 0 dma 212992 out

          res 50/00:00:4f:74:fe/00:00:20:00:00/e0 Emask 0x20 (host bus error)

ata1.00: status: { DRDY }
jasper_set_piomode: devno = 0
jasper_tune_chipset: slave = 0 speed = 0x0c
jasper_set_dmamode: devno = 0
jasper_tune_chipset: slave = 0 speed = 0x22
ata1.00: configured for MWDMA2
ata1: EH complete