nv_sata.h revision 193974072f41a843678abf5f61979c748687e66b
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * CDDL HEADER START
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The contents of this file are subject to the terms of the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Common Development and Distribution License (the "License").
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * You may not use this file except in compliance with the License.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * or http://www.opensolaris.org/os/licensing.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * See the License for the specific language governing permissions
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * and limitations under the License.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * When distributing Covered Code, include this CDDL HEADER in each
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * If applicable, add the following below this CDDL HEADER, with the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * fields enclosed by brackets "[]" replaced with your own identifying
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * information: Portions Copyright [yyyy] [name of copyright owner]
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * CDDL HEADER END
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Use is subject to license terms.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifndef _NV_SATA_H
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define _NV_SATA_H
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#ifdef __cplusplus
4bff34e37def8a90f9194d81bc345c52ba20086athurlowextern "C" {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#endif
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * SGPIO Support
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Enable SGPIO support only on x86/x64, because it is implemented using
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * functions that are only available on x86/x64.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_MAX_PORTS(nvc) nvc->nvc_sata_hba_tran.sata_tran_hba_num_cports
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowtypedef struct nv_port nv_port_t;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifdef SGPIO_SUPPORT
4bff34e37def8a90f9194d81bc345c52ba20086athurlowtypedef struct nv_sgp_cmn nv_sgp_cmn_t;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#endif
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowtypedef struct nv_ctl {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Each of these are specific to the chipset in use.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint_t (*nvc_interrupt)(caddr_t arg1, caddr_t arg2);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow void (*nvc_reg_init)(struct nv_ctl *nvc,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ddi_acc_handle_t pci_conf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow dev_info_t *nvc_dip; /* devinfo pointer of controller */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow struct nv_port *nvc_port; /* array of pointers to port struct */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * handle and base address to register space.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 0: port 0 task file
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 1: port 0 status
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 2: port 1 task file
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 3: port 1 status
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 4: bus master for both ports
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 5: extended registers for SATA features
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ddi_acc_handle_t nvc_bar_hdl[6];
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvc_bar_addr[6];
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * sata registers in bar 5 which are shared on all devices
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * on the channel.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t *nvc_mcp55_ctl;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t *nvc_mcp55_ncq; /* NCQ status control bits */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow kmutex_t nvc_mutex; /* ctrl level lock */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ddi_intr_handle_t *nvc_htable; /* For array of interrupts */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nvc_intr_type; /* What type of interrupt */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nvc_intr_cnt; /* # of intrs count returned */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow size_t nvc_intr_size; /* Size of intr array to */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint_t nvc_intr_pri; /* Interrupt priority */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nvc_intr_cap; /* Interrupt capabilities */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t *nvc_mcp04_int_status; /* interrupt status mcp04 */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sata_hba_tran_t nvc_sata_hba_tran; /* sata_hba_tran for ctrl */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * enable/disable interrupts, controller specific
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow void (*nvc_set_intr)(nv_port_t *nvp, int flag);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nvc_state; /* state flags of ctrl see below */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t nvc_revid; /* PCI revid of device */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifdef SGPIO_SUPPORT
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nvc_mcp55_flag; /* is the controller MCP55 or CK804 */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t nvc_ctlr_num; /* controller number within the part */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t nvc_sgp_csr; /* SGPIO CSR i/o address */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow volatile nv_sgp_cb_t *nvc_sgp_cbp; /* SGPIO Command Block */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow nv_sgp_cmn_t *nvc_sgp_cmn; /* SGPIO shared data */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#endif
4bff34e37def8a90f9194d81bc345c52ba20086athurlow} nv_ctl_t;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstruct nv_port {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow struct nv_ctl *nvp_ctlp; /* back pointer to controller */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t nvp_port_num; /* port number, ie 1 or 2 */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t nvp_type; /* SATA_DTYPE_{NONE,ATADISK,UNKNOWN} */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t nvp_signature; /* sig acquired from task file regs */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_cmd_addr; /* base addr for cmd regs for port */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_bm_addr; /* base addr for bus master for port */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_ctl_addr; /* base addr for ctrl regs for port */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ddi_acc_handle_t nvp_cmd_hdl;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_data; /* data register */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_error; /* error register (read) */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_feature; /* features (write) */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_count; /* sector count */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_sect; /* sector number */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_lcyl; /* cylinder low byte */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_hcyl; /* cylinder high byte */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_drvhd; /* drive/head register */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_status; /* status/command register */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_cmd; /* status/command register */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ddi_acc_handle_t nvp_ctl_hdl;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_altstatus; /* alternate status (read) */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_devctl; /* device control (write) */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ddi_acc_handle_t nvp_bm_hdl;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_bmisx;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t *nvp_bmidtpx;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uchar_t *nvp_bmicx;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ddi_dma_handle_t *nvp_sg_dma_hdl; /* dma handle to prd table */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow caddr_t *nvp_sg_addr; /* virtual addr of prd table */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t *nvp_sg_paddr; /* physical address of prd table */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ddi_acc_handle_t *nvp_sg_acc_hdl; /* mem acc handle to the prd table */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t *nvp_sstatus;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t *nvp_serror;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t *nvp_sctrl;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t *nvp_sactive;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow kmutex_t nvp_mutex; /* main per port mutex */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow kcondvar_t nvp_poll_cv; /* handshake cv between poll & isr */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * nvp_slot is a pointer to an array of nv_slot
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow struct nv_slot *nvp_slot;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t nvp_sactive_cache; /* cache of SACTIVE */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t nvp_queue_depth;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * NCQ flow control. During NCQ operation, no other commands
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * allowed. The following are used to enforce this.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nvp_ncq_run;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nvp_non_ncq_run;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow timeout_id_t nvp_timeout_id;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow clock_t nvp_reset_time; /* time of last reset */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow clock_t nvp_probe_time; /* time when probe began */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow clock_t nvp_link_lost_time; /* time link lost was noticed */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nvp_state; /* state of port. flags defined below */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint16_t *nvp_mcp55_int_status;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint16_t *nvp_mcp55_int_ctl;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifdef SGPIO_SUPPORT
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t nvp_sgp_ioctl_mod; /* LEDs modified by ioctl */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#endif
4bff34e37def8a90f9194d81bc345c52ba20086athurlow};
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowtypedef struct nv_device_table {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ushort_t vendor_id; /* vendor id */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ushort_t device_id; /* device id */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ushort_t type; /* chipset type, mcp04 or mcp55 */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow} nv_device_table_t;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowtypedef struct nv_slot {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow caddr_t nvslot_v_addr; /* I/O buffer address */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow size_t nvslot_byte_count; /* # bytes left to read/write */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sata_pkt_t *nvslot_spkt;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t nvslot_rqsense_buff[SATA_ATAPI_RQSENSE_LEN];
4bff34e37def8a90f9194d81bc345c52ba20086athurlow clock_t nvslot_stime;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int (*nvslot_start)(nv_port_t *nvp, int queue);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow void (*nvslot_intr)(nv_port_t *nvp,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow struct nv_slot *nv_slotp);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t nvslot_flags;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow} nv_slot_t;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifdef SGPIO_SUPPORT
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstruct nv_sgp_cmn {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint16_t nvs_magic; /* verification of valid structure */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t nvs_in_use; /* bit-field of active ctlrs */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t nvs_connected; /* port connected bit-field flag */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross uint8_t nvs_activity; /* port usage bit-field flag */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nvs_taskq_delay; /* rest time for activity LED taskq */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow kmutex_t nvs_slock; /* lock for shared data */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow kmutex_t nvs_tlock; /* lock for taskq */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow kcondvar_t nvs_cv; /* condition variable for taskq wait */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ddi_taskq_t *nvs_taskq; /* activity LED taskq */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow};
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#endif
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * nvslot_flags
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVSLOT_COMPLETE 0x01
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVSLOT_NCQ 0x02 /* NCQ is active */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVSLOT_RQSENSE 0x04 /* processing request sense */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * state values for nv_attach
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define ATTACH_PROGRESS_NONE (1 << 0)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define ATTACH_PROGRESS_STATEP_ALLOC (1 << 1)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define ATTACH_PROGRESS_PCI_HANDLE (1 << 2)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define ATTACH_PROGRESS_BARS (1 << 3)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define ATTACH_PROGRESS_INTR_ADDED (1 << 4)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define ATTACH_PROGRESS_MUTEX_INIT (1 << 5)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define ATTACH_PROGRESS_CTL_SETUP (1 << 6)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define ATTACH_PROGRESS_TRAN_SETUP (1 << 7)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define ATTACH_PROGRESS_COUNT (1 << 8)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define ATTACH_PROGRESS_CONF_HANDLE (1 << 9)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define ATTACH_PROGRESS_SATA_MODULE (1 << 10)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#ifdef DEBUG
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_DEBUG 1
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#endif /* DEBUG */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross/*
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * nv_debug_flags
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NVDBG_ALWAYS 0x0001
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NVDBG_INIT 0x0002
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NVDBG_ENTRY 0x0004
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_DELIVER 0x0008
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_EVENT 0x0010
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_SYNC 0x0020
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_PKTCOMP 0x0040
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_TIMEOUT 0x0080
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_INFO 0x0100
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_VERBOSE 0x0200
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_INTR 0x0400
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_ERRS 0x0800
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_COOKIES 0x1000
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_HOT 0x2000
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NVDBG_PROBE 0x4000
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NVDBG_ATAPI 0x8000
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifdef DEBUG
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NVLOG(a) nv_log a
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#else
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NVLOG(a)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#endif
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_SUCCESS 0
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_FAILURE -1
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross/*
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * indicates whether nv_wait functions can sleep or not.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_SLEEP 1
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_NOSLEEP 2
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross/*
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * port offsets from base address ioaddr1
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_DATA 0x00 /* data register */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_ERROR 0x01 /* error register (read) */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_FEATURE 0x01 /* features (write) */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_COUNT 0x02 /* sector count */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_SECT 0x03 /* sector number */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define NV_LCYL 0x04 /* cylinder low byte */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_HCYL 0x05 /* cylinder high byte */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_DRVHD 0x06 /* drive/head register */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_STATUS 0x07 /* status/command register */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_CMD 0x07 /* status/command register */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * port offsets from base address ioaddr2
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_ALTSTATUS 0x02 /* alternate status (read) */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_DEVCTL 0x02 /* device control (write) */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * device control register
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define ATDC_NIEN 0x02 /* disable interrupts */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define ATDC_SRST 0x04 /* controller reset */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define ATDC_D3 0x08 /* mysterious bit */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define ATDC_HOB 0x80 /* high order byte to read 48-bit values */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_CTL 0x400 /* queuing control */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_STATUS 0x440 /* status bits for interrupt */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_CTL 0x444 /* enable bits for interrupt */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_NCQ 0x448 /* NCQ status and ctrl bits */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * if either of these bits are set, when using NCQ, if no other commands are
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * active while a new command is started, DMA engine can be programmed ahead
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * of time to save extra interrupt. Presumably pre-programming is discarded
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * if a subsequent command ends up finishing first.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define MCP_SATA_AE_NCQ_PDEV_FIRST_CMD (1 << 7)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#define MCP_SATA_AE_NCQ_SDEV_FIRST_CMD (1 << 23)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bit definitions to indicate which NCQ command requires
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * DMA setup.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP_SATA_AE_NCQ_PDEV_DMA_SETUP_TAG_SHIFT 2
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP_SATA_AE_NCQ_SDEV_DMA_SETUP_TAG_SHIFT 18
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP_SATA_AE_NCQ_DMA_SETUP_TAG_MASK 0x1f
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Bits for NV_MCP55_INT_CTL and NV_MCP55_INT_STATUS
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_SNOTIFY 0x200 /* snotification set */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_SERROR 0x100 /* serror set */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_DMA_SETUP 0x80 /* DMA to be programmed */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_DH_REGFIS 0x40 /* REGFIS received */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_SDB_FIS 0x20 /* SDB FIS */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_TX_BACKOUT 0x10 /* TX backout */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_REM 0x08 /* device removed */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_ADD 0x04 /* device added */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_PM 0x02 /* power changed */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_COMPLETE 0x01 /* device interrupt */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Bits above that are not used for now.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP55_INT_IGNORE (MCP55_INT_DMA_SETUP|MCP55_INT_DH_REGFIS|\
4bff34e37def8a90f9194d81bc345c52ba20086athurlow MCP55_INT_SDB_FIS|MCP55_INT_TX_BACKOUT|MCP55_INT_PM|\
4bff34e37def8a90f9194d81bc345c52ba20086athurlow MCP55_INT_SNOTIFY|MCP55_INT_SERROR)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Bits for MCP_SATA_AE_CTL
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP_SATA_AE_CTL_PRI_SWNCQ (1 << 1) /* software NCQ chan 0 */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP_SATA_AE_CTL_SEC_SWNCQ (1 << 2) /* software NCQ chan 1 */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_DELAY_NSEC(wait_ns) \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{ \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow hrtime_t start, end; \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow start = end = gethrtime(); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow while ((end - start) < wait_ns) \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow end = gethrtime(); \
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * signatures in task file registers after device reset
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SIG_DISK 0x00000101
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SIG_ATAPI 0xeb140101
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SIG_PM 0x96690101
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SIG_NOTREADY 0x00000000
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * These bar5 offsets are common to mcp55/mcp04 and thus
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * prefixed with NV.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SSTATUS 0x00
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SERROR 0x04
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SCTRL 0x08
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SACTIVE 0x0c
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SNOTIFICATION 0x10
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define CH0_SREG_OFFSET 0x0
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define CH1_SREG_OFFSET 0x40
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The following config space offsets are needed to enable
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bar 5 register access in mcp04/mcp55
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SATA_CFG_20 0x50
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_BAR5_SPACE_EN 0x04
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_40BIT_PRD 0x20
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * mcp04 interrupt status register
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * offsets to bar 5 registers
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_SATA_INT_STATUS 0x440
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_SATA_INT_EN 0x441
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bit fields for int status and int enable
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * registers
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_PDEV_INT 0x01 /* completion interrupt */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_PDEV_PM 0x02 /* power change */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_PDEV_ADD 0x04 /* hot plug */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_PDEV_REM 0x08 /* hot remove */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_PDEV_HOT MCP04_INT_PDEV_ADD|MCP04_INT_PDEV_REM
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_SDEV_INT 0x10 /* completion interrupt */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_SDEV_PM 0x20 /* power change */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_SDEV_ADD 0x40 /* hot plug */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_SDEV_REM 0x80 /* hot remove */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_SDEV_HOT MCP04_INT_SDEV_ADD|MCP04_INT_SDEV_REM
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_PDEV_ALL MCP04_INT_PDEV_INT|MCP04_INT_PDEV_HOT|\
4bff34e37def8a90f9194d81bc345c52ba20086athurlow MCP04_INT_PDEV_PM
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_INT_SDEV_ALL MCP04_INT_SDEV_INT|MCP04_INT_SDEV_HOT|\
4bff34e37def8a90f9194d81bc345c52ba20086athurlow MCP04_INT_SDEV_PM
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * config space offset 42
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SATA_CFG_42 0xac
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bit in CFG_42 which delays hotplug interrupt until
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * PHY ready
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CFG_DELAY_HOTPLUG_INTR (0x1 << 12)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bar 5 offsets for SATA registers in ck804
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CH1_SSTATUS 0x00
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CH1_SERROR 0x04
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CH1_SCTRL 0x08
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CH1_SACTIVE 0x0c
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CH1_SNOTIFICATION 0x10
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CH2_SSTATUS 0x40
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CH2_SERROR 0x44
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CH2_SCTRL 0x48
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CH2_SACTIVE 0x4c
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_CH2_SNOTIFICATION 0x50
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bar 5 offsets for ADMACTL settings for both mcp04/mcp55
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_ADMACTL_X 0x4C0
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_ADMACTL_Y 0x5C0
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Bits for NV_ADMACTL_X and NV_ADMACTL_Y
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_HIRQ_EN 0x01 /* hot plug/unplug interrupt enable */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_CH_RST 0x04 /* reset channel */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bar 5 offset for ADMASTAT regs for mcp04
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_ADMASTAT_X 0x4C4
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_ADMASTAT_Y 0x5C4
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Bits for MCP04_ADMASTAT_X and MCP04_ADMASTAT_Y
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP04_HPIRQ 0x4
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define MCP05_HUIRQ 0x2
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bar 4 offset to bus master command registers
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMICX_REG 0
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bit definitions for BMICX_REG
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMICX_SSBM 0x01 /* Start/Stop Bus Master */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* 1=Start (Enable) */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* 0=Start (Disable) */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * NOTE: "read" and "write" are the actions of the DMA engine
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * on the PCI bus, not the SATA bus. Therefore for a ATA READ
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * command, program the DMA engine to "write to memory" mode
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * (and vice versa).
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMICX_RWCON 0x08 /* Read/Write Control */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMICX_RWCON_WRITE_TO_MEMORY 0x08 /* 1=Write (dev to host) */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMICX_RWCON_READ_FROM_MEMORY 0x00 /* 0=Read (host to dev) */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * BMICX bits to preserve during updates
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMICX_MASK (~(BMICX_SSBM | BMICX_RWCON))
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bar 4 offset to bus master status register
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMISX_REG 2
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bit fields for bus master status register
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMISX_BMIDEA 0x01 /* Bus Master IDE Active */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMISX_IDERR 0x02 /* IDE DMA Error */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMISX_IDEINTS 0x04 /* IDE Interrupt Status */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bus master status register bits to preserve
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMISX_MASK 0xf8
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * bar4 offset to bus master PRD descriptor table
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define BMIDTPX_REG 4
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * structure for a single entry in the PRD table
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * (physical region descriptor table)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowtypedef struct prde {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t p_address; /* physical address */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint32_t p_count; /* byte count, EOT in high order bit */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow} prde_t;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define PRDE_EOT ((uint_t)0x80000000)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_DMA_NSEGS 256 /* XXX DEBUG TEST change back to 257 */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * ck804 and mcp55 both have 2 ports per controller
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_NUM_CPORTS 2
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Number of slots to allocate in data nv_sata structures to handle
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * multiple commands at once. This does not reflect the capability of
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * the drive or the hardware, and in many cases will not match.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 1 or 32 slots are allocated, so in cases where the driver has NCQ
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * enabled but the drive doesn't support it, or supports fewer than
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 32 slots, here may be an over allocation of memory.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifdef NCQ
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_QUEUE_SLOTS 32
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#else
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_QUEUE_SLOTS 1
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#endif
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * wait 30 seconds for signature
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_SIG_TIMEOUT 45
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_BM_64K_BOUNDARY 0x10000ull
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * every 1 second
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_ONE_SEC 1000000
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * the amount of time link can be down during
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * reset without taking action.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_LINK_LOST_OK 2
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * nv_reset() flags
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_RESET_SEND_EVENT 0x1 /* send reset event to sata module */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_RESET_WAIT 0x2 /* OK to block waiting for reset */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_RESET_ATTEMPTS 3
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * nvp_state flags
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_PORT_INACTIVE 0x001
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_PORT_ABORTING 0x002
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_PORT_HOTREMOVED 0x004
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_PORT_INIT 0x008
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_PORT_FAILED 0x010
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_PORT_RESET 0x020
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_PORT_RESET_PROBE 0x040
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_PORT_RESTORE 0x080
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * nvc_state flags
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#define NV_CTRL_SUSPEND 0x1
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
/*
* flags for mcp04_set_intr/mcp55_set_intr
*/
#define NV_INTR_DISABLE 0x1
#define NV_INTR_ENABLE 0x2
#define NV_INTR_CLEAR_ALL 0x4
#define NV_INTR_DISABLE_NON_BLOCKING 0x8
/*
* sizes of strings to allocate
*/
#define NV_STRING_10 10
#define NV_STRING_512 512
#define NV_BYTES_PER_SEC 512
#define NV_WAIT_REG_CHECK 10 /* 10 microseconds */
#define NV_ATA_NUM_CMDS 256 /* max num ATA cmds possible, 8 bits */
#define NV_PRINT_INTERVAL 40 /* throttle debug msg from flooding */
#define MCP55_INT_CLEAR 0xffff /* clear all interrupts */
/*
* definition labels for the BAR registers
*/
#define NV_BAR_0 0 /* chan 0 task file regs */
#define NV_BAR_1 1 /* chan 0 status reg */
#define NV_BAR_2 2 /* chan 1 task file regs */
#define NV_BAR_3 3 /* chan 1 status reg */
#define NV_BAR_4 4 /* bus master regs */
#define NV_BAR_5 5 /* extra regs mostly SATA related */
/*
* transform seconds to microseconds
*/
#define NV_SEC2USEC(x) x * MICROSEC
/*
* ck804 maps in task file regs into bar 5. These are
* only used to identify ck804, therefore only this reg is
* listed here.
*/
#define NV_BAR5_TRAN_LEN_CH_X 0x518
/*
* if after this many iterations through the interrupt
* processing loop, declare the interrupt wedged and
* disable.
*/
#define NV_MAX_INTR_LOOP 10
/*
* flag values for nv_copy_regs_out
*/
#define NV_COPY_COMPLETE 0x01 /* normal command completion */
#define NV_COPY_ERROR 0x02 /* error, did not complete ok */
#define NV_COPY_SSREGS 0x04 /* SS port registers */
#ifdef SGPIO_SUPPORT
#define SGPIO_MAGIC 0x39da /* verifies good sgpio struct */
#define SGPIO_LOOP_WAIT_USECS 62500 /* 1/16 second (in usecs) */
#define SGPIO_TQ_NAME_LEN 32
/*
* The drive number format is ccp (binary).
* cc is the controller number (0-based number)
* p is the port number (0 or 1)
*/
#define SGP_DRV_TO_PORT(d) ((d) & 1)
#define SGP_DRV_TO_CTLR(d) ((d) >> 1)
#define SGP_CTLR_PORT_TO_DRV(c, p) (((c) << 1) | ((p) & 1))
#endif
#ifdef __cplusplus
}
#endif
#endif /* _NV_SATA_H */