Home | History | Annotate | Line # | Download | only in ata
satafis_subr.c revision 1.4.2.1
      1  1.4.2.1  uebayasi /* $NetBSD: satafis_subr.c,v 1.4.2.1 2010/04/30 14:43:08 uebayasi Exp $ */
      2      1.1  jakllsch 
      3      1.1  jakllsch /*-
      4      1.1  jakllsch  * Copyright (c) 2009 Jonathan A. Kollasch.
      5      1.1  jakllsch  * All rights reserved.
      6      1.1  jakllsch  *
      7      1.1  jakllsch  * Redistribution and use in source and binary forms, with or without
      8      1.1  jakllsch  * modification, are permitted provided that the following conditions
      9      1.1  jakllsch  * are met:
     10      1.1  jakllsch  * 1. Redistributions of source code must retain the above copyright
     11      1.1  jakllsch  *    notice, this list of conditions and the following disclaimer.
     12      1.1  jakllsch  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  jakllsch  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  jakllsch  *    documentation and/or other materials provided with the distribution.
     15      1.1  jakllsch  *
     16      1.1  jakllsch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17      1.1  jakllsch  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18      1.1  jakllsch  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19      1.1  jakllsch  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20      1.1  jakllsch  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21      1.1  jakllsch  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22      1.1  jakllsch  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23      1.1  jakllsch  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24      1.1  jakllsch  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25      1.1  jakllsch  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26      1.1  jakllsch  */
     27      1.1  jakllsch 
     28      1.1  jakllsch /*
     29      1.1  jakllsch  * Copyright (c) 2006 Manuel Bouyer.
     30      1.1  jakllsch  *
     31      1.1  jakllsch  * Redistribution and use in source and binary forms, with or without
     32      1.1  jakllsch  * modification, are permitted provided that the following conditions
     33      1.1  jakllsch  * are met:
     34      1.1  jakllsch  * 1. Redistributions of source code must retain the above copyright
     35      1.1  jakllsch  *    notice, this list of conditions and the following disclaimer.
     36      1.1  jakllsch  * 2. Redistributions in binary form must reproduce the above copyright
     37      1.1  jakllsch  *    notice, this list of conditions and the following disclaimer in the
     38      1.1  jakllsch  *    documentation and/or other materials provided with the distribution.
     39      1.1  jakllsch  *
     40      1.1  jakllsch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     41      1.1  jakllsch  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     42      1.1  jakllsch  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     43      1.1  jakllsch  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     44      1.1  jakllsch  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     45      1.1  jakllsch  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     46      1.1  jakllsch  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     47      1.1  jakllsch  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     48      1.1  jakllsch  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     49      1.1  jakllsch  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     50      1.1  jakllsch  *
     51      1.1  jakllsch  */
     52      1.1  jakllsch 
     53      1.1  jakllsch #include <sys/cdefs.h>
     54  1.4.2.1  uebayasi __KERNEL_RCSID(0, "$NetBSD: satafis_subr.c,v 1.4.2.1 2010/04/30 14:43:08 uebayasi Exp $");
     55      1.1  jakllsch 
     56      1.1  jakllsch #include <sys/param.h>
     57      1.2  jakllsch #include <sys/systm.h>
     58      1.1  jakllsch 
     59      1.1  jakllsch #include <sys/disklabel.h>
     60      1.1  jakllsch 
     61      1.1  jakllsch #include <dev/ata/atareg.h>
     62      1.1  jakllsch #include <dev/ata/atavar.h>
     63      1.1  jakllsch 
     64      1.1  jakllsch #include <dev/ata/satafisreg.h>
     65      1.1  jakllsch #include <dev/ata/satafisvar.h>
     66      1.1  jakllsch 
     67      1.1  jakllsch #include "atapibus.h"
     68      1.1  jakllsch 
     69      1.1  jakllsch void
     70      1.1  jakllsch satafis_rhd_construct_cmd(struct ata_command *ata_c, uint8_t *fis)
     71      1.1  jakllsch {
     72      1.2  jakllsch 	memset(fis, 0, RHD_FISLEN);
     73      1.2  jakllsch 
     74      1.1  jakllsch 	fis[fis_type] = RHD_FISTYPE;
     75  1.4.2.1  uebayasi 	fis[rhd_c] = RHD_C;
     76      1.1  jakllsch 	fis[rhd_command] = ata_c->r_command;
     77      1.1  jakllsch 	fis[rhd_features] = ata_c->r_features;
     78      1.1  jakllsch 	fis[rhd_sector] = ata_c->r_sector;
     79      1.1  jakllsch 	fis[rhd_cyl_lo] = ata_c->r_cyl & 0xff;
     80      1.1  jakllsch 	fis[rhd_cyl_hi] = (ata_c->r_cyl >> 8) & 0xff;
     81      1.1  jakllsch 	fis[rhd_dh] = ata_c->r_head & 0x0f;
     82      1.1  jakllsch 	fis[rhd_seccnt] = ata_c->r_count;
     83      1.1  jakllsch }
     84      1.1  jakllsch 
     85      1.1  jakllsch void
     86      1.1  jakllsch satafis_rhd_construct_bio(struct ata_xfer *xfer, uint8_t *fis)
     87      1.1  jakllsch {
     88      1.1  jakllsch 	struct ata_bio *ata_bio = xfer->c_cmd;
     89      1.1  jakllsch 	int nblks;
     90      1.1  jakllsch 
     91      1.1  jakllsch 	nblks = xfer->c_bcount / ata_bio->lp->d_secsize;
     92      1.1  jakllsch 
     93      1.2  jakllsch 	memset(fis, 0, RHD_FISLEN);
     94      1.2  jakllsch 
     95      1.1  jakllsch 	fis[fis_type] = RHD_FISTYPE;
     96  1.4.2.1  uebayasi 	fis[rhd_c] = RHD_C;
     97      1.1  jakllsch 	if (ata_bio->flags & ATA_LBA48) {
     98      1.1  jakllsch 		fis[rhd_command] = (ata_bio->flags & ATA_READ) ?
     99      1.1  jakllsch 		    WDCC_READDMA_EXT : WDCC_WRITEDMA_EXT;
    100      1.1  jakllsch 	} else {
    101      1.1  jakllsch 		fis[rhd_command] =
    102      1.1  jakllsch 		    (ata_bio->flags & ATA_READ) ? WDCC_READDMA : WDCC_WRITEDMA;
    103      1.1  jakllsch 	}
    104      1.1  jakllsch 	fis[rhd_sector] = ata_bio->blkno & 0xff;
    105      1.1  jakllsch 	fis[rhd_cyl_lo] = (ata_bio->blkno >> 8) & 0xff;
    106      1.1  jakllsch 	fis[rhd_cyl_hi] = (ata_bio->blkno >> 16) & 0xff;
    107      1.1  jakllsch 	if (ata_bio->flags & ATA_LBA48) {
    108      1.1  jakllsch 		fis[rhd_dh] = WDSD_LBA;
    109      1.1  jakllsch 		fis[rhd_sector_exp] = (ata_bio->blkno >> 24) & 0xff;
    110      1.1  jakllsch 		fis[rhd_cyl_lo_exp] = (ata_bio->blkno >> 32) & 0xff;
    111      1.1  jakllsch 		fis[rhd_cyl_hi_exp] = (ata_bio->blkno >> 40) & 0xff;
    112      1.1  jakllsch 	} else {
    113      1.1  jakllsch 		fis[rhd_dh] = ((ata_bio->blkno >> 24) & 0x0f) | WDSD_LBA;
    114      1.1  jakllsch 	}
    115      1.1  jakllsch 	fis[rhd_seccnt] = nblks & 0xff;
    116      1.1  jakllsch 	fis[rhd_seccnt_exp] = (ata_bio->flags & ATA_LBA48) ?
    117      1.1  jakllsch 	    ((nblks >> 8) & 0xff) : 0;
    118      1.1  jakllsch }
    119      1.1  jakllsch 
    120      1.1  jakllsch #if NATAPIBUS > 0
    121      1.1  jakllsch void
    122      1.1  jakllsch satafis_rhd_construct_atapi(struct ata_xfer *xfer, uint8_t *fis)
    123      1.1  jakllsch {
    124      1.2  jakllsch 	memset(fis, 0, RHD_FISLEN);
    125      1.2  jakllsch 
    126      1.1  jakllsch 	fis[fis_type] = RHD_FISTYPE;
    127  1.4.2.1  uebayasi 	fis[rhd_c] = RHD_C;
    128      1.1  jakllsch 	fis[rhd_command] = ATAPI_PKT_CMD;
    129      1.1  jakllsch 	fis[rhd_features] = (xfer->c_flags & C_DMA) ?
    130      1.1  jakllsch 	    ATAPI_PKT_CMD_FTRE_DMA : 0;
    131      1.1  jakllsch 
    132      1.1  jakllsch 	return;
    133      1.1  jakllsch }
    134      1.1  jakllsch #endif /* NATAPIBUS */
    135      1.1  jakllsch 
    136      1.1  jakllsch void
    137  1.4.2.1  uebayasi satafis_rdh_parse(struct ata_channel *chp, const uint8_t *fis)
    138      1.1  jakllsch {
    139      1.3  jakllsch 	chp->ch_status = fis[rdh_status];
    140      1.3  jakllsch 	chp->ch_error = fis[rdh_error];
    141  1.4.2.1  uebayasi }
    142      1.1  jakllsch 
    143  1.4.2.1  uebayasi void
    144  1.4.2.1  uebayasi satafis_rdh_cmd_readreg(struct ata_command *ata_c, const uint8_t *fis)
    145  1.4.2.1  uebayasi {
    146  1.4.2.1  uebayasi 	ata_c->r_command = fis[rdh_status];
    147  1.4.2.1  uebayasi 	ata_c->r_features = fis[rdh_error];
    148  1.4.2.1  uebayasi 	ata_c->r_error = fis[rdh_error];
    149  1.4.2.1  uebayasi 	ata_c->r_sector = fis[rdh_sector];
    150  1.4.2.1  uebayasi 	ata_c->r_cyl = fis[rdh_cyl_hi] << 8 | fis[rdh_cyl_lo];
    151  1.4.2.1  uebayasi 	ata_c->r_head = fis[rdh_dh];
    152  1.4.2.1  uebayasi 	ata_c->r_count = fis[rdh_seccnt];
    153      1.1  jakllsch }
    154