ahcisata(4) and siisata(4) use similar SATA FIS functions, share them.

This commit is contained in:
jakllsch 2009-06-17 03:07:51 +00:00
parent cb90fdddc4
commit e5e3060059
5 changed files with 266 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files,v 1.946 2009/05/06 02:52:13 cube Exp $
# $NetBSD: files,v 1.947 2009/06/17 03:07:51 jakllsch Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20090313
@ -277,6 +277,7 @@ define midisyn
define videobus { }
define ata {[channel = -1]}
define sata
define sata_fis
define scsi_core
define scsi {[channel = -1]}: scsi_core
define ata_hl {[drive = -1]}

View File

@ -1,4 +1,4 @@
# $NetBSD: files.ata,v 1.20 2008/09/16 11:45:30 tron Exp $
# $NetBSD: files.ata,v 1.21 2009/06/17 03:07:51 jakllsch Exp $
#
# Config file and device description for machine-independent devices
# which attach to ATA busses. Included by ports that need it. Ports
@ -31,3 +31,6 @@ file dev/ata/ld_ataraid.c ld_ataraid
# Common SATA subroutines
file dev/ata/sata_subr.c sata needs-flag
# Common SATA FIS subroutines
file dev/ata/satafis_subr.c sata_fis

151
sys/dev/ata/satafis_subr.c Normal file
View File

@ -0,0 +1,151 @@
/* $NetBSD: satafis_subr.c,v 1.1 2009/06/17 03:07:51 jakllsch Exp $ */
/*-
* Copyright (c) 2009 Jonathan A. Kollasch.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 2006 Manuel Bouyer.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Manuel Bouyer.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: satafis_subr.c,v 1.1 2009/06/17 03:07:51 jakllsch Exp $");
#include <sys/param.h>
#include <sys/disklabel.h>
#include <dev/ata/atareg.h>
#include <dev/ata/atavar.h>
#include <dev/ata/satafisreg.h>
#include <dev/ata/satafisvar.h>
#include <dev/ic/wdcreg.h> /* for WDCTL_4BIT */
#include "atapibus.h"
void
satafis_rhd_construct_cmd(struct ata_command *ata_c, uint8_t *fis)
{
fis[fis_type] = RHD_FISTYPE;
fis[rhd_cdpmp] = 0x80; /* xxx magic */
fis[rhd_command] = ata_c->r_command;
fis[rhd_features] = ata_c->r_features;
fis[rhd_sector] = ata_c->r_sector;
fis[rhd_cyl_lo] = ata_c->r_cyl & 0xff;
fis[rhd_cyl_hi] = (ata_c->r_cyl >> 8) & 0xff;
fis[rhd_dh] = ata_c->r_head & 0x0f;
fis[rhd_seccnt] = ata_c->r_count;
fis[rhd_control] = WDCTL_4BIT;
return;
}
void
satafis_rhd_construct_bio(struct ata_xfer *xfer, uint8_t *fis)
{
struct ata_bio *ata_bio = xfer->c_cmd;
int nblks;
nblks = xfer->c_bcount / ata_bio->lp->d_secsize;
fis[fis_type] = RHD_FISTYPE;
fis[rhd_cdpmp] = 0x80; /* xxx magic */
if (ata_bio->flags & ATA_LBA48) {
fis[rhd_command] = (ata_bio->flags & ATA_READ) ?
WDCC_READDMA_EXT : WDCC_WRITEDMA_EXT;
} else {
fis[rhd_command] =
(ata_bio->flags & ATA_READ) ? WDCC_READDMA : WDCC_WRITEDMA;
}
fis[rhd_sector] = ata_bio->blkno & 0xff;
fis[rhd_cyl_lo] = (ata_bio->blkno >> 8) & 0xff;
fis[rhd_cyl_hi] = (ata_bio->blkno >> 16) & 0xff;
if (ata_bio->flags & ATA_LBA48) {
fis[rhd_dh] = WDSD_LBA;
fis[rhd_sector_exp] = (ata_bio->blkno >> 24) & 0xff;
fis[rhd_cyl_lo_exp] = (ata_bio->blkno >> 32) & 0xff;
fis[rhd_cyl_hi_exp] = (ata_bio->blkno >> 40) & 0xff;
} else {
fis[rhd_dh] = ((ata_bio->blkno >> 24) & 0x0f) | WDSD_LBA;
}
fis[rhd_seccnt] = nblks & 0xff;
fis[rhd_seccnt_exp] = (ata_bio->flags & ATA_LBA48) ?
((nblks >> 8) & 0xff) : 0;
fis[rhd_control] = WDCTL_4BIT;
return;
}
#if NATAPIBUS > 0
void
satafis_rhd_construct_atapi(struct ata_xfer *xfer, uint8_t *fis)
{
fis[fis_type] = RHD_FISTYPE;
fis[rhd_cdpmp] = 0x80; /* xxx magic */
fis[rhd_command] = ATAPI_PKT_CMD;
fis[rhd_features] = (xfer->c_flags & C_DMA) ?
ATAPI_PKT_CMD_FTRE_DMA : 0;
fis[rhd_dh] = WDSD_IBM; /* XXX or WDSD_LBA? */
fis[rhd_control] = WDCTL_4BIT;
return;
}
#endif /* NATAPIBUS */
void
satafis_sdb_parse(struct ata_channel *chp, uint8_t *fis)
{
KASSERT(fis[fis_type] != SDB_FISTYPE);
chp->ch_status = fis[sdb_status];
chp->ch_error = fis[sdb_error];
return;
}

71
sys/dev/ata/satafisreg.h Normal file
View File

@ -0,0 +1,71 @@
/* $NetBSD: satafisreg.h,v 1.1 2009/06/17 03:07:51 jakllsch Exp $ */
/*-
* Copyright (c) 2009 Jonathan A. Kollasch.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _DEV_ATA_FISREG_H_
#define _DEV_ATA_FISREG_H_
#define fis_type 0
#define RHD_FISTYPE 0x27
#define RHD_FISLEN 20
#define rhd_cdpmp 1 /* Command bit and PM port */
#define rhd_command 2 /* wd_command */
#define rhd_features 3 /* wd_precomp */
#define rhd_sector 4 /* wd_sector */
#define rhd_cyl_lo 5 /* wd_cyl_lo */
#define rhd_cyl_hi 6 /* wd_cyl_hi */
#define rhd_dh 7 /* wd_sdh */
#define rhd_sector_exp 8
#define rhd_cyl_lo_exp 9
#define rhd_cyl_hi_exp 10
#define rhd_features_exp 11
#define rhd_seccnt 12
#define rhd_seccnt_exp 13
#define rhd_control 15
#define RDH_FISTYPE 0x34
#define RDH_FISLEN 20
#define rdh_i 1
#define rdh_status 2
#define rdh_error 3
#define rdh_sector 4 /* wd_sector */
#define rdh_cyl_lo 5 /* wd_cyl_lo */
#define rdh_cyl_hi 6 /* wd_cyl_hi */
#define rdh_dh 7 /* wd_sdh */
#define rhd_sector_exp 8
#define rhd_cyl_lo_exp 9
#define rhd_cyl_hi_exp 10
#define rhd_seccnt 12
#define rhd_seccnt_exp 13
#define SDB_FISTYPE 0xA1
#define SDB_FISLEN 8
#define sdb_i 1
#define sdb_status 2
#define sdb_error 3
#endif /* _DEV_ATA_FISREG_H_ */

38
sys/dev/ata/satafisvar.h Normal file
View File

@ -0,0 +1,38 @@
/* $NetBSD: satafisvar.h,v 1.1 2009/06/17 03:07:51 jakllsch Exp $ */
/*-
* Copyright (c) 2009 Jonathan A. Kollasch.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _DEV_ATA_FISVAR_H_
#define _DEV_ATA_FISVAR_H_
#include <dev/ata/atavar.h>
void satafis_rhd_construct_cmd(struct ata_command *, uint8_t *);
void satafis_rhd_construct_bio(struct ata_xfer *, uint8_t *);
void satafis_rhd_construct_atapi(struct ata_xfer *, uint8_t *);
void satafis_sdb_parse(struct ata_channel *, uint8_t *);
#endif /* _DEV_ATA_FISVAR_H_ */