Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Copyright (C) 2000-2002	Andre Hedrick <andre@linux-ide.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (C) 2003		Red Hat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/genhd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/blkpg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) void SELECT_MASK(ide_drive_t *drive, int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	const struct ide_port_ops *port_ops = drive->hwif->port_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (port_ops && port_ops->maskproc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		port_ops->maskproc(drive, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) u8 ide_read_error(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct ide_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return tf.error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) EXPORT_SYMBOL_GPL(ide_read_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) void ide_fix_driveid(u16 *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #ifndef __LITTLE_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) # ifdef __BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	for (i = 0; i < 256; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		id[i] = __le16_to_cpu(id[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) # else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #  error "Please fix <asm/byteorder.h>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * removing leading/trailing blanks and compressing internal blanks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * It is primarily used to tidy up the model name/number fields as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * returned by the ATA_CMD_ID_ATA[PI] commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) void ide_fixstring(u8 *s, const int bytecount, const int byteswap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	u8 *p, *end = &s[bytecount & ~1]; /* bytecount must be even */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (byteswap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		/* convert from big-endian to host byte order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		for (p = s ; p != end ; p += 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			be16_to_cpus((u16 *) p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	/* strip leading blanks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	p = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	while (s != end && *s == ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		++s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	/* compress internal blanks and strip trailing blanks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	while (s != end && *s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		if (*s++ != ' ' || (s != end && *s && *s != ' '))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			*p++ = *(s-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	/* wipe out trailing garbage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	while (p != end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		*p++ = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) EXPORT_SYMBOL(ide_fixstring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * This routine busy-waits for the drive status to be not "busy".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * It then checks the status for all of the "good" bits and none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * of the "bad" bits, and if all is okay it returns 0.  All other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * cases return error -- caller may then invoke ide_error().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * This routine should get fixed to not hog the cpu during extra long waits..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * That could be done by busy-waiting for the first jiffy or two, and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * setting a timer to wake up at half second intervals thereafter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * until timeout is achieved, before timing out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		    unsigned long timeout, u8 *rstat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	const struct ide_tp_ops *tp_ops = hwif->tp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	bool irqs_threaded = force_irqthreads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	u8 stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	udelay(1);	/* spec allows drive 400ns to assert "BUSY" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	stat = tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (stat & ATA_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if (!irqs_threaded) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			local_save_flags(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			local_irq_enable_in_hardirq();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		timeout += jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		while ((stat = tp_ops->read_status(hwif)) & ATA_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			if (time_after(jiffies, timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 				 * One last read after the timeout in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				 * heavy interrupt load made us not make any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 				 * progress during the timeout..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 				stat = tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				if ((stat & ATA_BUSY) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 				if (!irqs_threaded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 					local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 				*rstat = stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		if (!irqs_threaded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 * Allow status to settle, then read it again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 * A few rare drives vastly violate the 400ns spec here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 * so we'll wait up to 10usec for a "good" status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 * rather than expensively fail things immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 * This fix courtesy of Matthew Faupel & Niccolo Rigacci.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	for (i = 0; i < 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		stat = tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		if (OK_STAT(stat, good, bad)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			*rstat = stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	*rstat = stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  * In case of error returns error value after doing "*startstop = ide_error()".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * The caller should return the updated value of "startstop" in this case,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  * "startstop" is unchanged when the function returns 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int ide_wait_stat(ide_startstop_t *startstop, ide_drive_t *drive, u8 good,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		  u8 bad, unsigned long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	u8 stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	/* bail early if we've exceeded max_failures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (drive->max_failures && (drive->failures > drive->max_failures)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		*startstop = ide_stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	err = __ide_wait_stat(drive, good, bad, timeout, &stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		char *s = (err == -EBUSY) ? "status timeout" : "status error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		*startstop = ide_error(drive, s, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) EXPORT_SYMBOL(ide_wait_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  *	ide_in_drive_list	-	look for drive in black/white list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  *	@id: drive identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  *	@table: list to inspect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  *	Look for a drive in the blacklist and the whitelist tables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  *	Returns 1 if the drive is found in the table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int ide_in_drive_list(u16 *id, const struct drive_list_entry *table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	for ( ; table->id_model; table++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		if ((!strcmp(table->id_model, (char *)&id[ATA_ID_PROD])) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		    (!table->id_firmware ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		     strstr((char *)&id[ATA_ID_FW_REV], table->id_firmware)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) EXPORT_SYMBOL_GPL(ide_in_drive_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * Early UDMA66 devices don't set bit14 to 1, only bit13 is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * Some optical devices with the buggy firmwares have the same problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static const struct drive_list_entry ivb_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	{ "QUANTUM FIREBALLlct10 05"	, "A03.0900"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	{ "QUANTUM FIREBALLlct20 30"	, "APL.0900"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	{ "TSSTcorp CDDVDW SH-S202J"	, "SB00"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	{ "TSSTcorp CDDVDW SH-S202J"	, "SB01"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	{ "TSSTcorp CDDVDW SH-S202N"	, "SB00"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	{ "TSSTcorp CDDVDW SH-S202N"	, "SB01"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	{ "TSSTcorp CDDVDW SH-S202H"	, "SB00"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	{ "TSSTcorp CDDVDW SH-S202H"	, "SB01"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	{ "SAMSUNG SP0822N"		, "WA100-10"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	{ NULL				, NULL		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  *  All hosts that use the 80c ribbon must use!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  *  The name is derived from upper byte of word 93 and the 80c ribbon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) u8 eighty_ninty_three(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	u16 *id = drive->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	int ivb = ide_in_drive_list(id, ivb_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (hwif->cbl == ATA_CBL_SATA || hwif->cbl == ATA_CBL_PATA40_SHORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (ivb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		printk(KERN_DEBUG "%s: skipping word 93 validity check\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				  drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (ata_id_is_sata(id) && !ivb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (hwif->cbl != ATA_CBL_PATA80 && !ivb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		goto no_80w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	 * FIXME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	 * - change master/slave IDENTIFY order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	 * - force bit13 (80c cable present) check also for !ivb devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	 *   (unless the slave device is pre-ATA3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (id[ATA_ID_HW_CONFIG] & 0x4000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (ivb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		const char *model = (char *)&id[ATA_ID_PROD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		if (strstr(model, "TSSTcorp CDDVDW SH-S202")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			 * These ATAPI devices always report 80c cable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			 * so we have to depend on the host in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			if (hwif->cbl == ATA_CBL_PATA80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			/* Depend on the device side cable detection. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			if (id[ATA_ID_HW_CONFIG] & 0x2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 				return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) no_80w:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (drive->dev_flags & IDE_DFLAG_UDMA33_WARNED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			    "limiting max speed to UDMA33\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			    drive->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			    hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	drive->dev_flags |= IDE_DFLAG_UDMA33_WARNED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static const char *nien_quirk_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	"QUANTUM FIREBALLlct08 08",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	"QUANTUM FIREBALLP KA6.4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	"QUANTUM FIREBALLP KA9.1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	"QUANTUM FIREBALLP KX13.6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	"QUANTUM FIREBALLP KX20.5",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	"QUANTUM FIREBALLP KX27.3",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	"QUANTUM FIREBALLP LM20.4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	"QUANTUM FIREBALLP LM20.5",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	"FUJITSU MHZ2160BH G2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) void ide_check_nien_quirk_list(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	const char **list, *m = (char *)&drive->id[ATA_ID_PROD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	for (list = nien_quirk_list; *list != NULL; list++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		if (strstr(m, *list) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			drive->dev_flags |= IDE_DFLAG_NIEN_QUIRK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) int ide_driveid_update(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	u16 *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	id = kmalloc(SECTOR_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (id == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	SELECT_MASK(drive, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	rc = ide_dev_read_id(drive, ATA_CMD_ID_ATA, id, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	SELECT_MASK(drive, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	drive->id[ATA_ID_UDMA_MODES]  = id[ATA_ID_UDMA_MODES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	drive->id[ATA_ID_MWDMA_MODES] = id[ATA_ID_MWDMA_MODES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	drive->id[ATA_ID_SWDMA_MODES] = id[ATA_ID_SWDMA_MODES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	drive->id[ATA_ID_CFA_MODES]   = id[ATA_ID_CFA_MODES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	/* anything more ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	kfree(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	if (rc == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		printk(KERN_ERR "%s: %s: bad status\n", drive->name, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	kfree(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	const struct ide_tp_ops *tp_ops = hwif->tp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	struct ide_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	u16 *id = drive->id, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	u8 stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) #ifdef CONFIG_BLK_DEV_IDEDMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (hwif->dma_ops)	/* check if host supports DMA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		hwif->dma_ops->dma_host_set(drive, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	/* Skip setting PIO flow-control modes on pre-EIDE drives */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if ((speed & 0xf8) == XFER_PIO_0 && ata_id_has_iordy(drive->id) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	 * Don't use ide_wait_cmd here - it will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	 * attempt to set_geometry and recalibrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	 * but for some reason these don't work at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	 * this point (lost interrupt).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	tp_ops->dev_select(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	SELECT_MASK(drive, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	tp_ops->write_devctl(hwif, ATA_NIEN | ATA_DEVCTL_OBS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	memset(&tf, 0, sizeof(tf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	tf.feature = SETFEATURES_XFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	tf.nsect   = speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	tp_ops->tf_load(drive, &tf, IDE_VALID_FEATURE | IDE_VALID_NSECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	tp_ops->exec_command(hwif, ATA_CMD_SET_FEATURES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (drive->dev_flags & IDE_DFLAG_NIEN_QUIRK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	error = __ide_wait_stat(drive, drive->ready_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 				ATA_BUSY | ATA_DRQ | ATA_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 				WAIT_CMD, &stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	SELECT_MASK(drive, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		(void) ide_dump_status(drive, "set_drive_speed_status", stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	if (speed >= XFER_SW_DMA_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		id[ATA_ID_UDMA_MODES]  &= ~0xFF00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		id[ATA_ID_MWDMA_MODES] &= ~0x0700;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		id[ATA_ID_SWDMA_MODES] &= ~0x0700;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		if (ata_id_is_cfa(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			id[ATA_ID_CFA_MODES] &= ~0x0E00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	} else	if (ata_id_is_cfa(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		id[ATA_ID_CFA_MODES] &= ~0x01C0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  skip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #ifdef CONFIG_BLK_DEV_IDEDMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (speed >= XFER_SW_DMA_0 && (drive->dev_flags & IDE_DFLAG_USING_DMA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		hwif->dma_ops->dma_host_set(drive, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	else if (hwif->dma_ops)	/* check if host supports DMA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		ide_dma_off_quietly(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (speed >= XFER_UDMA_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		i = 1 << (speed - XFER_UDMA_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		id[ATA_ID_UDMA_MODES] |= (i << 8 | i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	} else if (ata_id_is_cfa(id) && speed >= XFER_MW_DMA_3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		i = speed - XFER_MW_DMA_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		id[ATA_ID_CFA_MODES] |= i << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	} else if (speed >= XFER_MW_DMA_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		i = 1 << (speed - XFER_MW_DMA_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		id[ATA_ID_MWDMA_MODES] |= (i << 8 | i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	} else if (speed >= XFER_SW_DMA_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		i = 1 << (speed - XFER_SW_DMA_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		id[ATA_ID_SWDMA_MODES] |= (i << 8 | i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	} else if (ata_id_is_cfa(id) && speed >= XFER_PIO_5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		i = speed - XFER_PIO_4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		id[ATA_ID_CFA_MODES] |= i << 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	if (!drive->init_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		drive->init_speed = speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	drive->current_speed = speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * This should get invoked any time we exit the driver to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  * wait for an interrupt response from a drive.  handler() points
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  * at the appropriate code to handle the next interrupt, and a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  * timer is started to prevent us from waiting forever in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  * something goes wrong (see the ide_timer_expiry() handler later on).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  * See also ide_execute_command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) void __ide_set_handler(ide_drive_t *drive, ide_handler_t *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		       unsigned int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	BUG_ON(hwif->handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	hwif->handler		= handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	hwif->timer.expires	= jiffies + timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	hwif->req_gen_timer	= hwif->req_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	add_timer(&hwif->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) void ide_set_handler(ide_drive_t *drive, ide_handler_t *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		     unsigned int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	spin_lock_irqsave(&hwif->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	__ide_set_handler(drive, handler, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	spin_unlock_irqrestore(&hwif->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) EXPORT_SYMBOL(ide_set_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)  *	ide_execute_command	-	execute an IDE command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)  *	@drive: IDE drive to issue the command against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  *	@cmd: command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  *	@handler: handler for next phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  *	@timeout: timeout for command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)  *	Helper function to issue an IDE command. This handles the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)  *	atomicity requirements, command timing and ensures that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)  *	handler and IRQ setup do not race. All IDE command kick off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)  *	should go via this function or do equivalent locking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) void ide_execute_command(ide_drive_t *drive, struct ide_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			 ide_handler_t *handler, unsigned timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	ide_hwif_t *hwif = drive->hwif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	spin_lock_irqsave(&hwif->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	if ((cmd->protocol != ATAPI_PROT_DMA &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	     cmd->protocol != ATAPI_PROT_PIO) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	    (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		__ide_set_handler(drive, handler, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	hwif->tp_ops->exec_command(hwif, cmd->tf.command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	 * Drive takes 400nS to respond, we must avoid the IRQ being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	 * serviced before that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	 * FIXME: we could skip this delay with care on non shared devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	ndelay(400);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	spin_unlock_irqrestore(&hwif->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)  * ide_wait_not_busy() waits for the currently selected device on the hwif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)  * to report a non-busy status, see comments in ide_probe_port().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	u8 stat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	while (timeout--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		 * Turn this into a schedule() sleep once I'm sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		 * about locking issues (2.5 work ?).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		stat = hwif->tp_ops->read_status(hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		if ((stat & ATA_BUSY) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		 * Assume a value of 0xff means nothing is connected to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		 * the interface and it doesn't implement the pull-down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		 * resistor on D7.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		if (stat == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		touch_nmi_watchdog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }