Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  sata_promise.h - Promise SATA common definitions and inline funcs
0004  *
0005  *  Copyright 2003-2004 Red Hat, Inc.
0006  *
0007  *  libata documentation is available via 'make {ps|pdf}docs',
0008  *  as Documentation/driver-api/libata.rst
0009  */
0010 
0011 #ifndef __SATA_PROMISE_H__
0012 #define __SATA_PROMISE_H__
0013 
0014 #include <linux/ata.h>
0015 
0016 enum pdc_packet_bits {
0017     PDC_PKT_READ        = (1 << 2),
0018     PDC_PKT_NODATA      = (1 << 3),
0019 
0020     PDC_PKT_SIZEMASK    = (1 << 7) | (1 << 6) | (1 << 5),
0021     PDC_PKT_CLEAR_BSY   = (1 << 4),
0022     PDC_PKT_WAIT_DRDY   = (1 << 3) | (1 << 4),
0023     PDC_LAST_REG        = (1 << 3),
0024 
0025     PDC_REG_DEVCTL      = (1 << 3) | (1 << 2) | (1 << 1),
0026 };
0027 
0028 static inline unsigned int pdc_pkt_header(struct ata_taskfile *tf,
0029                       dma_addr_t sg_table,
0030                       unsigned int devno, u8 *buf)
0031 {
0032     u8 dev_reg;
0033     __le32 *buf32 = (__le32 *) buf;
0034 
0035     /* set control bits (byte 0), zero delay seq id (byte 3),
0036      * and seq id (byte 2)
0037      */
0038     switch (tf->protocol) {
0039     case ATA_PROT_DMA:
0040         if (!(tf->flags & ATA_TFLAG_WRITE))
0041             buf32[0] = cpu_to_le32(PDC_PKT_READ);
0042         else
0043             buf32[0] = 0;
0044         break;
0045 
0046     case ATA_PROT_NODATA:
0047         buf32[0] = cpu_to_le32(PDC_PKT_NODATA);
0048         break;
0049 
0050     default:
0051         BUG();
0052         break;
0053     }
0054 
0055     buf32[1] = cpu_to_le32(sg_table);   /* S/G table addr */
0056     buf32[2] = 0;               /* no next-packet */
0057 
0058     if (devno == 0)
0059         dev_reg = ATA_DEVICE_OBS;
0060     else
0061         dev_reg = ATA_DEVICE_OBS | ATA_DEV1;
0062 
0063     /* select device */
0064     buf[12] = (1 << 5) | PDC_PKT_CLEAR_BSY | ATA_REG_DEVICE;
0065     buf[13] = dev_reg;
0066 
0067     /* device control register */
0068     buf[14] = (1 << 5) | PDC_REG_DEVCTL;
0069     buf[15] = tf->ctl;
0070 
0071     return 16;  /* offset of next byte */
0072 }
0073 
0074 static inline unsigned int pdc_pkt_footer(struct ata_taskfile *tf, u8 *buf,
0075                   unsigned int i)
0076 {
0077     if (tf->flags & ATA_TFLAG_DEVICE) {
0078         buf[i++] = (1 << 5) | ATA_REG_DEVICE;
0079         buf[i++] = tf->device;
0080     }
0081 
0082     /* and finally the command itself; also includes end-of-pkt marker */
0083     buf[i++] = (1 << 5) | PDC_LAST_REG | ATA_REG_CMD;
0084     buf[i++] = tf->command;
0085 
0086     return i;
0087 }
0088 
0089 static inline unsigned int pdc_prep_lba28(struct ata_taskfile *tf, u8 *buf, unsigned int i)
0090 {
0091     /* the "(1 << 5)" should be read "(count << 5)" */
0092 
0093     /* ATA command block registers */
0094     buf[i++] = (1 << 5) | ATA_REG_FEATURE;
0095     buf[i++] = tf->feature;
0096 
0097     buf[i++] = (1 << 5) | ATA_REG_NSECT;
0098     buf[i++] = tf->nsect;
0099 
0100     buf[i++] = (1 << 5) | ATA_REG_LBAL;
0101     buf[i++] = tf->lbal;
0102 
0103     buf[i++] = (1 << 5) | ATA_REG_LBAM;
0104     buf[i++] = tf->lbam;
0105 
0106     buf[i++] = (1 << 5) | ATA_REG_LBAH;
0107     buf[i++] = tf->lbah;
0108 
0109     return i;
0110 }
0111 
0112 static inline unsigned int pdc_prep_lba48(struct ata_taskfile *tf, u8 *buf, unsigned int i)
0113 {
0114     /* the "(2 << 5)" should be read "(count << 5)" */
0115 
0116     /* ATA command block registers */
0117     buf[i++] = (2 << 5) | ATA_REG_FEATURE;
0118     buf[i++] = tf->hob_feature;
0119     buf[i++] = tf->feature;
0120 
0121     buf[i++] = (2 << 5) | ATA_REG_NSECT;
0122     buf[i++] = tf->hob_nsect;
0123     buf[i++] = tf->nsect;
0124 
0125     buf[i++] = (2 << 5) | ATA_REG_LBAL;
0126     buf[i++] = tf->hob_lbal;
0127     buf[i++] = tf->lbal;
0128 
0129     buf[i++] = (2 << 5) | ATA_REG_LBAM;
0130     buf[i++] = tf->hob_lbam;
0131     buf[i++] = tf->lbam;
0132 
0133     buf[i++] = (2 << 5) | ATA_REG_LBAH;
0134     buf[i++] = tf->hob_lbah;
0135     buf[i++] = tf->lbah;
0136 
0137     return i;
0138 }
0139 
0140 
0141 #endif /* __SATA_PROMISE_H__ */