18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  ahci.h - Common AHCI SATA definitions and declarations
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Maintained by:  Tejun Heo <tj@kernel.org>
68c2ecf20Sopenharmony_ci *    		    Please ALWAYS copy linux-ide@vger.kernel.org
78c2ecf20Sopenharmony_ci *		    on emails.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci *  Copyright 2004-2005 Red Hat, Inc.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * libata documentation is available via 'make {ps|pdf}docs',
128c2ecf20Sopenharmony_ci * as Documentation/driver-api/libata.rst
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * AHCI hardware documentation:
158c2ecf20Sopenharmony_ci * http://www.intel.com/technology/serialata/pdf/rev1_0.pdf
168c2ecf20Sopenharmony_ci * http://www.intel.com/technology/serialata/pdf/rev1_1.pdf
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#ifndef _AHCI_H
208c2ecf20Sopenharmony_ci#define _AHCI_H
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include <linux/pci.h>
238c2ecf20Sopenharmony_ci#include <linux/clk.h>
248c2ecf20Sopenharmony_ci#include <linux/libata.h>
258c2ecf20Sopenharmony_ci#include <linux/phy/phy.h>
268c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h>
278c2ecf20Sopenharmony_ci#include <linux/bits.h>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* Enclosure Management Control */
308c2ecf20Sopenharmony_ci#define EM_CTRL_MSG_TYPE              0x000f0000
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* Enclosure Management LED Message Type */
338c2ecf20Sopenharmony_ci#define EM_MSG_LED_HBA_PORT           0x0000000f
348c2ecf20Sopenharmony_ci#define EM_MSG_LED_PMP_SLOT           0x0000ff00
358c2ecf20Sopenharmony_ci#define EM_MSG_LED_VALUE              0xffff0000
368c2ecf20Sopenharmony_ci#define EM_MSG_LED_VALUE_ACTIVITY     0x00070000
378c2ecf20Sopenharmony_ci#define EM_MSG_LED_VALUE_OFF          0xfff80000
388c2ecf20Sopenharmony_ci#define EM_MSG_LED_VALUE_ON           0x00010000
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cienum {
418c2ecf20Sopenharmony_ci	AHCI_MAX_PORTS		= 32,
428c2ecf20Sopenharmony_ci	AHCI_MAX_CLKS		= 5,
438c2ecf20Sopenharmony_ci	AHCI_MAX_SG		= 168, /* hardware max is 64K */
448c2ecf20Sopenharmony_ci	AHCI_DMA_BOUNDARY	= 0xffffffff,
458c2ecf20Sopenharmony_ci	AHCI_MAX_CMDS		= 32,
468c2ecf20Sopenharmony_ci	AHCI_CMD_SZ		= 32,
478c2ecf20Sopenharmony_ci	AHCI_CMD_SLOT_SZ	= AHCI_MAX_CMDS * AHCI_CMD_SZ,
488c2ecf20Sopenharmony_ci	AHCI_RX_FIS_SZ		= 256,
498c2ecf20Sopenharmony_ci	AHCI_CMD_TBL_CDB	= 0x40,
508c2ecf20Sopenharmony_ci	AHCI_CMD_TBL_HDR_SZ	= 0x80,
518c2ecf20Sopenharmony_ci	AHCI_CMD_TBL_SZ		= AHCI_CMD_TBL_HDR_SZ + (AHCI_MAX_SG * 16),
528c2ecf20Sopenharmony_ci	AHCI_CMD_TBL_AR_SZ	= AHCI_CMD_TBL_SZ * AHCI_MAX_CMDS,
538c2ecf20Sopenharmony_ci	AHCI_PORT_PRIV_DMA_SZ	= AHCI_CMD_SLOT_SZ + AHCI_CMD_TBL_AR_SZ +
548c2ecf20Sopenharmony_ci				  AHCI_RX_FIS_SZ,
558c2ecf20Sopenharmony_ci	AHCI_PORT_PRIV_FBS_DMA_SZ	= AHCI_CMD_SLOT_SZ +
568c2ecf20Sopenharmony_ci					  AHCI_CMD_TBL_AR_SZ +
578c2ecf20Sopenharmony_ci					  (AHCI_RX_FIS_SZ * 16),
588c2ecf20Sopenharmony_ci	AHCI_IRQ_ON_SG		= BIT(31),
598c2ecf20Sopenharmony_ci	AHCI_CMD_ATAPI		= BIT(5),
608c2ecf20Sopenharmony_ci	AHCI_CMD_WRITE		= BIT(6),
618c2ecf20Sopenharmony_ci	AHCI_CMD_PREFETCH	= BIT(7),
628c2ecf20Sopenharmony_ci	AHCI_CMD_RESET		= BIT(8),
638c2ecf20Sopenharmony_ci	AHCI_CMD_CLR_BUSY	= BIT(10),
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	RX_FIS_PIO_SETUP	= 0x20,	/* offset of PIO Setup FIS data */
668c2ecf20Sopenharmony_ci	RX_FIS_D2H_REG		= 0x40,	/* offset of D2H Register FIS data */
678c2ecf20Sopenharmony_ci	RX_FIS_SDB		= 0x58, /* offset of SDB FIS data */
688c2ecf20Sopenharmony_ci	RX_FIS_UNK		= 0x60, /* offset of Unknown FIS data */
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	/* global controller registers */
718c2ecf20Sopenharmony_ci	HOST_CAP		= 0x00, /* host capabilities */
728c2ecf20Sopenharmony_ci	HOST_CTL		= 0x04, /* global host control */
738c2ecf20Sopenharmony_ci	HOST_IRQ_STAT		= 0x08, /* interrupt status */
748c2ecf20Sopenharmony_ci	HOST_PORTS_IMPL		= 0x0c, /* bitmap of implemented ports */
758c2ecf20Sopenharmony_ci	HOST_VERSION		= 0x10, /* AHCI spec. version compliancy */
768c2ecf20Sopenharmony_ci	HOST_EM_LOC		= 0x1c, /* Enclosure Management location */
778c2ecf20Sopenharmony_ci	HOST_EM_CTL		= 0x20, /* Enclosure Management Control */
788c2ecf20Sopenharmony_ci	HOST_CAP2		= 0x24, /* host capabilities, extended */
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	/* HOST_CTL bits */
818c2ecf20Sopenharmony_ci	HOST_RESET		= BIT(0),  /* reset controller; self-clear */
828c2ecf20Sopenharmony_ci	HOST_IRQ_EN		= BIT(1),  /* global IRQ enable */
838c2ecf20Sopenharmony_ci	HOST_MRSM		= BIT(2),  /* MSI Revert to Single Message */
848c2ecf20Sopenharmony_ci	HOST_AHCI_EN		= BIT(31), /* AHCI enabled */
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	/* HOST_CAP bits */
878c2ecf20Sopenharmony_ci	HOST_CAP_SXS		= BIT(5),  /* Supports External SATA */
888c2ecf20Sopenharmony_ci	HOST_CAP_EMS		= BIT(6),  /* Enclosure Management support */
898c2ecf20Sopenharmony_ci	HOST_CAP_CCC		= BIT(7),  /* Command Completion Coalescing */
908c2ecf20Sopenharmony_ci	HOST_CAP_PART		= BIT(13), /* Partial state capable */
918c2ecf20Sopenharmony_ci	HOST_CAP_SSC		= BIT(14), /* Slumber state capable */
928c2ecf20Sopenharmony_ci	HOST_CAP_PIO_MULTI	= BIT(15), /* PIO multiple DRQ support */
938c2ecf20Sopenharmony_ci	HOST_CAP_FBS		= BIT(16), /* FIS-based switching support */
948c2ecf20Sopenharmony_ci	HOST_CAP_PMP		= BIT(17), /* Port Multiplier support */
958c2ecf20Sopenharmony_ci	HOST_CAP_ONLY		= BIT(18), /* Supports AHCI mode only */
968c2ecf20Sopenharmony_ci	HOST_CAP_CLO		= BIT(24), /* Command List Override support */
978c2ecf20Sopenharmony_ci	HOST_CAP_LED		= BIT(25), /* Supports activity LED */
988c2ecf20Sopenharmony_ci	HOST_CAP_ALPM		= BIT(26), /* Aggressive Link PM support */
998c2ecf20Sopenharmony_ci	HOST_CAP_SSS		= BIT(27), /* Staggered Spin-up */
1008c2ecf20Sopenharmony_ci	HOST_CAP_MPS		= BIT(28), /* Mechanical presence switch */
1018c2ecf20Sopenharmony_ci	HOST_CAP_SNTF		= BIT(29), /* SNotification register */
1028c2ecf20Sopenharmony_ci	HOST_CAP_NCQ		= BIT(30), /* Native Command Queueing */
1038c2ecf20Sopenharmony_ci	HOST_CAP_64		= BIT(31), /* PCI DAC (64-bit DMA) support */
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	/* HOST_CAP2 bits */
1068c2ecf20Sopenharmony_ci	HOST_CAP2_BOH		= BIT(0),  /* BIOS/OS handoff supported */
1078c2ecf20Sopenharmony_ci	HOST_CAP2_NVMHCI	= BIT(1),  /* NVMHCI supported */
1088c2ecf20Sopenharmony_ci	HOST_CAP2_APST		= BIT(2),  /* Automatic partial to slumber */
1098c2ecf20Sopenharmony_ci	HOST_CAP2_SDS		= BIT(3),  /* Support device sleep */
1108c2ecf20Sopenharmony_ci	HOST_CAP2_SADM		= BIT(4),  /* Support aggressive DevSlp */
1118c2ecf20Sopenharmony_ci	HOST_CAP2_DESO		= BIT(5),  /* DevSlp from slumber only */
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	/* registers for each SATA port */
1148c2ecf20Sopenharmony_ci	PORT_LST_ADDR		= 0x00, /* command list DMA addr */
1158c2ecf20Sopenharmony_ci	PORT_LST_ADDR_HI	= 0x04, /* command list DMA addr hi */
1168c2ecf20Sopenharmony_ci	PORT_FIS_ADDR		= 0x08, /* FIS rx buf addr */
1178c2ecf20Sopenharmony_ci	PORT_FIS_ADDR_HI	= 0x0c, /* FIS rx buf addr hi */
1188c2ecf20Sopenharmony_ci	PORT_IRQ_STAT		= 0x10, /* interrupt status */
1198c2ecf20Sopenharmony_ci	PORT_IRQ_MASK		= 0x14, /* interrupt enable/disable mask */
1208c2ecf20Sopenharmony_ci	PORT_CMD		= 0x18, /* port command */
1218c2ecf20Sopenharmony_ci	PORT_TFDATA		= 0x20,	/* taskfile data */
1228c2ecf20Sopenharmony_ci	PORT_SIG		= 0x24,	/* device TF signature */
1238c2ecf20Sopenharmony_ci	PORT_CMD_ISSUE		= 0x38, /* command issue */
1248c2ecf20Sopenharmony_ci	PORT_SCR_STAT		= 0x28, /* SATA phy register: SStatus */
1258c2ecf20Sopenharmony_ci	PORT_SCR_CTL		= 0x2c, /* SATA phy register: SControl */
1268c2ecf20Sopenharmony_ci	PORT_SCR_ERR		= 0x30, /* SATA phy register: SError */
1278c2ecf20Sopenharmony_ci	PORT_SCR_ACT		= 0x34, /* SATA phy register: SActive */
1288c2ecf20Sopenharmony_ci	PORT_SCR_NTF		= 0x3c, /* SATA phy register: SNotification */
1298c2ecf20Sopenharmony_ci	PORT_FBS		= 0x40, /* FIS-based Switching */
1308c2ecf20Sopenharmony_ci	PORT_DEVSLP		= 0x44, /* device sleep */
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	/* PORT_IRQ_{STAT,MASK} bits */
1338c2ecf20Sopenharmony_ci	PORT_IRQ_COLD_PRES	= BIT(31), /* cold presence detect */
1348c2ecf20Sopenharmony_ci	PORT_IRQ_TF_ERR		= BIT(30), /* task file error */
1358c2ecf20Sopenharmony_ci	PORT_IRQ_HBUS_ERR	= BIT(29), /* host bus fatal error */
1368c2ecf20Sopenharmony_ci	PORT_IRQ_HBUS_DATA_ERR	= BIT(28), /* host bus data error */
1378c2ecf20Sopenharmony_ci	PORT_IRQ_IF_ERR		= BIT(27), /* interface fatal error */
1388c2ecf20Sopenharmony_ci	PORT_IRQ_IF_NONFATAL	= BIT(26), /* interface non-fatal error */
1398c2ecf20Sopenharmony_ci	PORT_IRQ_OVERFLOW	= BIT(24), /* xfer exhausted available S/G */
1408c2ecf20Sopenharmony_ci	PORT_IRQ_BAD_PMP	= BIT(23), /* incorrect port multiplier */
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	PORT_IRQ_PHYRDY		= BIT(22), /* PhyRdy changed */
1438c2ecf20Sopenharmony_ci	PORT_IRQ_DEV_ILCK	= BIT(7),  /* device interlock */
1448c2ecf20Sopenharmony_ci	PORT_IRQ_CONNECT	= BIT(6),  /* port connect change status */
1458c2ecf20Sopenharmony_ci	PORT_IRQ_SG_DONE	= BIT(5),  /* descriptor processed */
1468c2ecf20Sopenharmony_ci	PORT_IRQ_UNK_FIS	= BIT(4),  /* unknown FIS rx'd */
1478c2ecf20Sopenharmony_ci	PORT_IRQ_SDB_FIS	= BIT(3),  /* Set Device Bits FIS rx'd */
1488c2ecf20Sopenharmony_ci	PORT_IRQ_DMAS_FIS	= BIT(2),  /* DMA Setup FIS rx'd */
1498c2ecf20Sopenharmony_ci	PORT_IRQ_PIOS_FIS	= BIT(1),  /* PIO Setup FIS rx'd */
1508c2ecf20Sopenharmony_ci	PORT_IRQ_D2H_REG_FIS	= BIT(0),  /* D2H Register FIS rx'd */
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	PORT_IRQ_FREEZE		= PORT_IRQ_HBUS_ERR |
1538c2ecf20Sopenharmony_ci				  PORT_IRQ_IF_ERR |
1548c2ecf20Sopenharmony_ci				  PORT_IRQ_CONNECT |
1558c2ecf20Sopenharmony_ci				  PORT_IRQ_PHYRDY |
1568c2ecf20Sopenharmony_ci				  PORT_IRQ_UNK_FIS |
1578c2ecf20Sopenharmony_ci				  PORT_IRQ_BAD_PMP,
1588c2ecf20Sopenharmony_ci	PORT_IRQ_ERROR		= PORT_IRQ_FREEZE |
1598c2ecf20Sopenharmony_ci				  PORT_IRQ_TF_ERR |
1608c2ecf20Sopenharmony_ci				  PORT_IRQ_HBUS_DATA_ERR,
1618c2ecf20Sopenharmony_ci	DEF_PORT_IRQ		= PORT_IRQ_ERROR | PORT_IRQ_SG_DONE |
1628c2ecf20Sopenharmony_ci				  PORT_IRQ_SDB_FIS | PORT_IRQ_DMAS_FIS |
1638c2ecf20Sopenharmony_ci				  PORT_IRQ_PIOS_FIS | PORT_IRQ_D2H_REG_FIS,
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci	/* PORT_CMD bits */
1668c2ecf20Sopenharmony_ci	PORT_CMD_ASP		= BIT(27), /* Aggressive Slumber/Partial */
1678c2ecf20Sopenharmony_ci	PORT_CMD_ALPE		= BIT(26), /* Aggressive Link PM enable */
1688c2ecf20Sopenharmony_ci	PORT_CMD_ATAPI		= BIT(24), /* Device is ATAPI */
1698c2ecf20Sopenharmony_ci	PORT_CMD_FBSCP		= BIT(22), /* FBS Capable Port */
1708c2ecf20Sopenharmony_ci	PORT_CMD_ESP		= BIT(21), /* External Sata Port */
1718c2ecf20Sopenharmony_ci	PORT_CMD_HPCP		= BIT(18), /* HotPlug Capable Port */
1728c2ecf20Sopenharmony_ci	PORT_CMD_PMP		= BIT(17), /* PMP attached */
1738c2ecf20Sopenharmony_ci	PORT_CMD_LIST_ON	= BIT(15), /* cmd list DMA engine running */
1748c2ecf20Sopenharmony_ci	PORT_CMD_FIS_ON		= BIT(14), /* FIS DMA engine running */
1758c2ecf20Sopenharmony_ci	PORT_CMD_FIS_RX		= BIT(4),  /* Enable FIS receive DMA engine */
1768c2ecf20Sopenharmony_ci	PORT_CMD_CLO		= BIT(3),  /* Command list override */
1778c2ecf20Sopenharmony_ci	PORT_CMD_POWER_ON	= BIT(2),  /* Power up device */
1788c2ecf20Sopenharmony_ci	PORT_CMD_SPIN_UP	= BIT(1),  /* Spin up device */
1798c2ecf20Sopenharmony_ci	PORT_CMD_START		= BIT(0),  /* Enable port DMA engine */
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci	PORT_CMD_ICC_MASK	= (0xfu << 28), /* i/f ICC state mask */
1828c2ecf20Sopenharmony_ci	PORT_CMD_ICC_ACTIVE	= (0x1u << 28), /* Put i/f in active state */
1838c2ecf20Sopenharmony_ci	PORT_CMD_ICC_PARTIAL	= (0x2u << 28), /* Put i/f in partial state */
1848c2ecf20Sopenharmony_ci	PORT_CMD_ICC_SLUMBER	= (0x6u << 28), /* Put i/f in slumber state */
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci	/* PORT_FBS bits */
1878c2ecf20Sopenharmony_ci	PORT_FBS_DWE_OFFSET	= 16, /* FBS device with error offset */
1888c2ecf20Sopenharmony_ci	PORT_FBS_ADO_OFFSET	= 12, /* FBS active dev optimization offset */
1898c2ecf20Sopenharmony_ci	PORT_FBS_DEV_OFFSET	= 8,  /* FBS device to issue offset */
1908c2ecf20Sopenharmony_ci	PORT_FBS_DEV_MASK	= (0xf << PORT_FBS_DEV_OFFSET),  /* FBS.DEV */
1918c2ecf20Sopenharmony_ci	PORT_FBS_SDE		= BIT(2), /* FBS single device error */
1928c2ecf20Sopenharmony_ci	PORT_FBS_DEC		= BIT(1), /* FBS device error clear */
1938c2ecf20Sopenharmony_ci	PORT_FBS_EN		= BIT(0), /* Enable FBS */
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci	/* PORT_DEVSLP bits */
1968c2ecf20Sopenharmony_ci	PORT_DEVSLP_DM_OFFSET	= 25,             /* DITO multiplier offset */
1978c2ecf20Sopenharmony_ci	PORT_DEVSLP_DM_MASK	= (0xf << 25),    /* DITO multiplier mask */
1988c2ecf20Sopenharmony_ci	PORT_DEVSLP_DITO_OFFSET	= 15,             /* DITO offset */
1998c2ecf20Sopenharmony_ci	PORT_DEVSLP_MDAT_OFFSET	= 10,             /* Minimum assertion time */
2008c2ecf20Sopenharmony_ci	PORT_DEVSLP_DETO_OFFSET	= 2,              /* DevSlp exit timeout */
2018c2ecf20Sopenharmony_ci	PORT_DEVSLP_DSP		= BIT(1),         /* DevSlp present */
2028c2ecf20Sopenharmony_ci	PORT_DEVSLP_ADSE	= BIT(0),         /* Aggressive DevSlp enable */
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	/* hpriv->flags bits */
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci#define AHCI_HFLAGS(flags)		.private_data	= (void *)(flags)
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	AHCI_HFLAG_NO_NCQ		= BIT(0),
2098c2ecf20Sopenharmony_ci	AHCI_HFLAG_IGN_IRQ_IF_ERR	= BIT(1), /* ignore IRQ_IF_ERR */
2108c2ecf20Sopenharmony_ci	AHCI_HFLAG_IGN_SERR_INTERNAL	= BIT(2), /* ignore SERR_INTERNAL */
2118c2ecf20Sopenharmony_ci	AHCI_HFLAG_32BIT_ONLY		= BIT(3), /* force 32bit */
2128c2ecf20Sopenharmony_ci	AHCI_HFLAG_MV_PATA		= BIT(4), /* PATA port */
2138c2ecf20Sopenharmony_ci	AHCI_HFLAG_NO_MSI		= BIT(5), /* no PCI MSI */
2148c2ecf20Sopenharmony_ci	AHCI_HFLAG_NO_PMP		= BIT(6), /* no PMP */
2158c2ecf20Sopenharmony_ci	AHCI_HFLAG_SECT255		= BIT(8), /* max 255 sectors */
2168c2ecf20Sopenharmony_ci	AHCI_HFLAG_YES_NCQ		= BIT(9), /* force NCQ cap on */
2178c2ecf20Sopenharmony_ci	AHCI_HFLAG_NO_SUSPEND		= BIT(10), /* don't suspend */
2188c2ecf20Sopenharmony_ci	AHCI_HFLAG_SRST_TOUT_IS_OFFLINE	= BIT(11), /* treat SRST timeout as
2198c2ecf20Sopenharmony_ci						      link offline */
2208c2ecf20Sopenharmony_ci	AHCI_HFLAG_NO_SNTF		= BIT(12), /* no sntf */
2218c2ecf20Sopenharmony_ci	AHCI_HFLAG_NO_FPDMA_AA		= BIT(13), /* no FPDMA AA */
2228c2ecf20Sopenharmony_ci	AHCI_HFLAG_YES_FBS		= BIT(14), /* force FBS cap on */
2238c2ecf20Sopenharmony_ci	AHCI_HFLAG_DELAY_ENGINE		= BIT(15), /* do not start engine on
2248c2ecf20Sopenharmony_ci						      port start (wait until
2258c2ecf20Sopenharmony_ci						      error-handling stage) */
2268c2ecf20Sopenharmony_ci	AHCI_HFLAG_NO_DEVSLP		= BIT(17), /* no device sleep */
2278c2ecf20Sopenharmony_ci	AHCI_HFLAG_NO_FBS		= BIT(18), /* no FBS */
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_MSI
2308c2ecf20Sopenharmony_ci	AHCI_HFLAG_MULTI_MSI		= BIT(20), /* per-port MSI(-X) */
2318c2ecf20Sopenharmony_ci#else
2328c2ecf20Sopenharmony_ci	/* compile out MSI infrastructure */
2338c2ecf20Sopenharmony_ci	AHCI_HFLAG_MULTI_MSI		= 0,
2348c2ecf20Sopenharmony_ci#endif
2358c2ecf20Sopenharmony_ci	AHCI_HFLAG_WAKE_BEFORE_STOP	= BIT(22), /* wake before DMA stop */
2368c2ecf20Sopenharmony_ci	AHCI_HFLAG_YES_ALPM		= BIT(23), /* force ALPM cap on */
2378c2ecf20Sopenharmony_ci	AHCI_HFLAG_NO_WRITE_TO_RO	= BIT(24), /* don't write to read
2388c2ecf20Sopenharmony_ci						      only registers */
2398c2ecf20Sopenharmony_ci	AHCI_HFLAG_IS_MOBILE            = BIT(25), /* mobile chipset, use
2408c2ecf20Sopenharmony_ci						      SATA_MOBILE_LPM_POLICY
2418c2ecf20Sopenharmony_ci						      as default lpm_policy */
2428c2ecf20Sopenharmony_ci	AHCI_HFLAG_SUSPEND_PHYS		= BIT(26), /* handle PHYs during
2438c2ecf20Sopenharmony_ci						      suspend/resume */
2448c2ecf20Sopenharmony_ci	AHCI_HFLAG_IGN_NOTSUPP_POWER_ON	= BIT(27), /* ignore -EOPNOTSUPP
2458c2ecf20Sopenharmony_ci						      from phy_power_on() */
2468c2ecf20Sopenharmony_ci	AHCI_HFLAG_NO_SXS		= BIT(28), /* SXS not supported */
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	/* ap->flags bits */
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	AHCI_FLAG_COMMON		= ATA_FLAG_SATA | ATA_FLAG_PIO_DMA |
2518c2ecf20Sopenharmony_ci					  ATA_FLAG_ACPI_SATA | ATA_FLAG_AN,
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	ICH_MAP				= 0x90, /* ICH MAP register */
2548c2ecf20Sopenharmony_ci	PCS_6				= 0x92, /* 6 port PCS */
2558c2ecf20Sopenharmony_ci	PCS_7				= 0x94, /* 7+ port PCS (Denverton) */
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	/* em constants */
2588c2ecf20Sopenharmony_ci	EM_MAX_SLOTS			= SATA_PMP_MAX_PORTS,
2598c2ecf20Sopenharmony_ci	EM_MAX_RETRY			= 5,
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	/* em_ctl bits */
2628c2ecf20Sopenharmony_ci	EM_CTL_RST		= BIT(9), /* Reset */
2638c2ecf20Sopenharmony_ci	EM_CTL_TM		= BIT(8), /* Transmit Message */
2648c2ecf20Sopenharmony_ci	EM_CTL_MR		= BIT(0), /* Message Received */
2658c2ecf20Sopenharmony_ci	EM_CTL_ALHD		= BIT(26), /* Activity LED */
2668c2ecf20Sopenharmony_ci	EM_CTL_XMT		= BIT(25), /* Transmit Only */
2678c2ecf20Sopenharmony_ci	EM_CTL_SMB		= BIT(24), /* Single Message Buffer */
2688c2ecf20Sopenharmony_ci	EM_CTL_SGPIO		= BIT(19), /* SGPIO messages supported */
2698c2ecf20Sopenharmony_ci	EM_CTL_SES		= BIT(18), /* SES-2 messages supported */
2708c2ecf20Sopenharmony_ci	EM_CTL_SAFTE		= BIT(17), /* SAF-TE messages supported */
2718c2ecf20Sopenharmony_ci	EM_CTL_LED		= BIT(16), /* LED messages supported */
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	/* em message type */
2748c2ecf20Sopenharmony_ci	EM_MSG_TYPE_LED		= BIT(0), /* LED */
2758c2ecf20Sopenharmony_ci	EM_MSG_TYPE_SAFTE	= BIT(1), /* SAF-TE */
2768c2ecf20Sopenharmony_ci	EM_MSG_TYPE_SES2	= BIT(2), /* SES-2 */
2778c2ecf20Sopenharmony_ci	EM_MSG_TYPE_SGPIO	= BIT(3), /* SGPIO */
2788c2ecf20Sopenharmony_ci};
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_cistruct ahci_cmd_hdr {
2818c2ecf20Sopenharmony_ci	__le32			opts;
2828c2ecf20Sopenharmony_ci	__le32			status;
2838c2ecf20Sopenharmony_ci	__le32			tbl_addr;
2848c2ecf20Sopenharmony_ci	__le32			tbl_addr_hi;
2858c2ecf20Sopenharmony_ci	__le32			reserved[4];
2868c2ecf20Sopenharmony_ci};
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cistruct ahci_sg {
2898c2ecf20Sopenharmony_ci	__le32			addr;
2908c2ecf20Sopenharmony_ci	__le32			addr_hi;
2918c2ecf20Sopenharmony_ci	__le32			reserved;
2928c2ecf20Sopenharmony_ci	__le32			flags_size;
2938c2ecf20Sopenharmony_ci};
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_cistruct ahci_em_priv {
2968c2ecf20Sopenharmony_ci	enum sw_activity blink_policy;
2978c2ecf20Sopenharmony_ci	struct timer_list timer;
2988c2ecf20Sopenharmony_ci	unsigned long saved_activity;
2998c2ecf20Sopenharmony_ci	unsigned long activity;
3008c2ecf20Sopenharmony_ci	unsigned long led_state;
3018c2ecf20Sopenharmony_ci	struct ata_link *link;
3028c2ecf20Sopenharmony_ci};
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_cistruct ahci_port_priv {
3058c2ecf20Sopenharmony_ci	struct ata_link		*active_link;
3068c2ecf20Sopenharmony_ci	struct ahci_cmd_hdr	*cmd_slot;
3078c2ecf20Sopenharmony_ci	dma_addr_t		cmd_slot_dma;
3088c2ecf20Sopenharmony_ci	void			*cmd_tbl;
3098c2ecf20Sopenharmony_ci	dma_addr_t		cmd_tbl_dma;
3108c2ecf20Sopenharmony_ci	void			*rx_fis;
3118c2ecf20Sopenharmony_ci	dma_addr_t		rx_fis_dma;
3128c2ecf20Sopenharmony_ci	/* for NCQ spurious interrupt analysis */
3138c2ecf20Sopenharmony_ci	unsigned int		ncq_saw_d2h:1;
3148c2ecf20Sopenharmony_ci	unsigned int		ncq_saw_dmas:1;
3158c2ecf20Sopenharmony_ci	unsigned int		ncq_saw_sdb:1;
3168c2ecf20Sopenharmony_ci	spinlock_t		lock;		/* protects parent ata_port */
3178c2ecf20Sopenharmony_ci	u32 			intr_mask;	/* interrupts to enable */
3188c2ecf20Sopenharmony_ci	bool			fbs_supported;	/* set iff FBS is supported */
3198c2ecf20Sopenharmony_ci	bool			fbs_enabled;	/* set iff FBS is enabled */
3208c2ecf20Sopenharmony_ci	int			fbs_last_dev;	/* save FBS.DEV of last FIS */
3218c2ecf20Sopenharmony_ci	/* enclosure management info per PM slot */
3228c2ecf20Sopenharmony_ci	struct ahci_em_priv	em_priv[EM_MAX_SLOTS];
3238c2ecf20Sopenharmony_ci	char			*irq_desc;	/* desc in /proc/interrupts */
3248c2ecf20Sopenharmony_ci};
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_cistruct ahci_host_priv {
3278c2ecf20Sopenharmony_ci	/* Input fields */
3288c2ecf20Sopenharmony_ci	unsigned int		flags;		/* AHCI_HFLAG_* */
3298c2ecf20Sopenharmony_ci	u32			force_port_map;	/* force port map */
3308c2ecf20Sopenharmony_ci	u32			mask_port_map;	/* mask out particular bits */
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	void __iomem *		mmio;		/* bus-independent mem map */
3338c2ecf20Sopenharmony_ci	u32			cap;		/* cap to use */
3348c2ecf20Sopenharmony_ci	u32			cap2;		/* cap2 to use */
3358c2ecf20Sopenharmony_ci	u32			version;	/* cached version */
3368c2ecf20Sopenharmony_ci	u32			port_map;	/* port map to use */
3378c2ecf20Sopenharmony_ci	u32			saved_cap;	/* saved initial cap */
3388c2ecf20Sopenharmony_ci	u32			saved_cap2;	/* saved initial cap2 */
3398c2ecf20Sopenharmony_ci	u32			saved_port_map;	/* saved initial port_map */
3408c2ecf20Sopenharmony_ci	u32 			em_loc; /* enclosure management location */
3418c2ecf20Sopenharmony_ci	u32			em_buf_sz;	/* EM buffer size in byte */
3428c2ecf20Sopenharmony_ci	u32			em_msg_type;	/* EM message type */
3438c2ecf20Sopenharmony_ci	u32			remapped_nvme;	/* NVMe remapped device count */
3448c2ecf20Sopenharmony_ci	bool			got_runtime_pm; /* Did we do pm_runtime_get? */
3458c2ecf20Sopenharmony_ci	struct clk		*clks[AHCI_MAX_CLKS]; /* Optional */
3468c2ecf20Sopenharmony_ci	struct reset_control	*rsts;		/* Optional */
3478c2ecf20Sopenharmony_ci	struct regulator	**target_pwrs;	/* Optional */
3488c2ecf20Sopenharmony_ci	struct regulator	*ahci_regulator;/* Optional */
3498c2ecf20Sopenharmony_ci	struct regulator	*phy_regulator;/* Optional */
3508c2ecf20Sopenharmony_ci	/*
3518c2ecf20Sopenharmony_ci	 * If platform uses PHYs. There is a 1:1 relation between the port number and
3528c2ecf20Sopenharmony_ci	 * the PHY position in this array.
3538c2ecf20Sopenharmony_ci	 */
3548c2ecf20Sopenharmony_ci	struct phy		**phys;
3558c2ecf20Sopenharmony_ci	unsigned		nports;		/* Number of ports */
3568c2ecf20Sopenharmony_ci	void			*plat_data;	/* Other platform data */
3578c2ecf20Sopenharmony_ci	unsigned int		irq;		/* interrupt line */
3588c2ecf20Sopenharmony_ci	/*
3598c2ecf20Sopenharmony_ci	 * Optional ahci_start_engine override, if not set this gets set to the
3608c2ecf20Sopenharmony_ci	 * default ahci_start_engine during ahci_save_initial_config, this can
3618c2ecf20Sopenharmony_ci	 * be overridden anytime before the host is activated.
3628c2ecf20Sopenharmony_ci	 */
3638c2ecf20Sopenharmony_ci	void			(*start_engine)(struct ata_port *ap);
3648c2ecf20Sopenharmony_ci	/*
3658c2ecf20Sopenharmony_ci	 * Optional ahci_stop_engine override, if not set this gets set to the
3668c2ecf20Sopenharmony_ci	 * default ahci_stop_engine during ahci_save_initial_config, this can
3678c2ecf20Sopenharmony_ci	 * be overridden anytime before the host is activated.
3688c2ecf20Sopenharmony_ci	 */
3698c2ecf20Sopenharmony_ci	int			(*stop_engine)(struct ata_port *ap);
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	irqreturn_t 		(*irq_handler)(int irq, void *dev_instance);
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	/* only required for per-port MSI(-X) support */
3748c2ecf20Sopenharmony_ci	int			(*get_irq_vector)(struct ata_host *host,
3758c2ecf20Sopenharmony_ci						  int port);
3768c2ecf20Sopenharmony_ci};
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ciextern int ahci_ignore_sss;
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ciextern struct device_attribute *ahci_shost_attrs[];
3818c2ecf20Sopenharmony_ciextern struct device_attribute *ahci_sdev_attrs[];
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci/*
3848c2ecf20Sopenharmony_ci * This must be instantiated by the edge drivers.  Read the comments
3858c2ecf20Sopenharmony_ci * for ATA_BASE_SHT
3868c2ecf20Sopenharmony_ci */
3878c2ecf20Sopenharmony_ci#define AHCI_SHT(drv_name)						\
3888c2ecf20Sopenharmony_ci	ATA_NCQ_SHT(drv_name),						\
3898c2ecf20Sopenharmony_ci	.can_queue		= AHCI_MAX_CMDS,			\
3908c2ecf20Sopenharmony_ci	.sg_tablesize		= AHCI_MAX_SG,				\
3918c2ecf20Sopenharmony_ci	.dma_boundary		= AHCI_DMA_BOUNDARY,			\
3928c2ecf20Sopenharmony_ci	.shost_attrs		= ahci_shost_attrs,			\
3938c2ecf20Sopenharmony_ci	.sdev_attrs		= ahci_sdev_attrs
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ciextern struct ata_port_operations ahci_ops;
3968c2ecf20Sopenharmony_ciextern struct ata_port_operations ahci_platform_ops;
3978c2ecf20Sopenharmony_ciextern struct ata_port_operations ahci_pmp_retry_srst_ops;
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ciunsigned int ahci_dev_classify(struct ata_port *ap);
4008c2ecf20Sopenharmony_civoid ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
4018c2ecf20Sopenharmony_ci			u32 opts);
4028c2ecf20Sopenharmony_civoid ahci_save_initial_config(struct device *dev,
4038c2ecf20Sopenharmony_ci			      struct ahci_host_priv *hpriv);
4048c2ecf20Sopenharmony_civoid ahci_init_controller(struct ata_host *host);
4058c2ecf20Sopenharmony_ciint ahci_reset_controller(struct ata_host *host);
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ciint ahci_do_softreset(struct ata_link *link, unsigned int *class,
4088c2ecf20Sopenharmony_ci		      int pmp, unsigned long deadline,
4098c2ecf20Sopenharmony_ci		      int (*check_ready)(struct ata_link *link));
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ciint ahci_do_hardreset(struct ata_link *link, unsigned int *class,
4128c2ecf20Sopenharmony_ci		      unsigned long deadline, bool *online);
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ciunsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
4158c2ecf20Sopenharmony_ciint ahci_stop_engine(struct ata_port *ap);
4168c2ecf20Sopenharmony_civoid ahci_start_fis_rx(struct ata_port *ap);
4178c2ecf20Sopenharmony_civoid ahci_start_engine(struct ata_port *ap);
4188c2ecf20Sopenharmony_ciint ahci_check_ready(struct ata_link *link);
4198c2ecf20Sopenharmony_ciint ahci_kick_engine(struct ata_port *ap);
4208c2ecf20Sopenharmony_ciint ahci_port_resume(struct ata_port *ap);
4218c2ecf20Sopenharmony_civoid ahci_set_em_messages(struct ahci_host_priv *hpriv,
4228c2ecf20Sopenharmony_ci			  struct ata_port_info *pi);
4238c2ecf20Sopenharmony_ciint ahci_reset_em(struct ata_host *host);
4248c2ecf20Sopenharmony_civoid ahci_print_info(struct ata_host *host, const char *scc_s);
4258c2ecf20Sopenharmony_ciint ahci_host_activate(struct ata_host *host, struct scsi_host_template *sht);
4268c2ecf20Sopenharmony_civoid ahci_error_handler(struct ata_port *ap);
4278c2ecf20Sopenharmony_ciu32 ahci_handle_port_intr(struct ata_host *host, u32 irq_masked);
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_cistatic inline void __iomem *__ahci_port_base(struct ata_host *host,
4308c2ecf20Sopenharmony_ci					     unsigned int port_no)
4318c2ecf20Sopenharmony_ci{
4328c2ecf20Sopenharmony_ci	struct ahci_host_priv *hpriv = host->private_data;
4338c2ecf20Sopenharmony_ci	void __iomem *mmio = hpriv->mmio;
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	return mmio + 0x100 + (port_no * 0x80);
4368c2ecf20Sopenharmony_ci}
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_cistatic inline void __iomem *ahci_port_base(struct ata_port *ap)
4398c2ecf20Sopenharmony_ci{
4408c2ecf20Sopenharmony_ci	return __ahci_port_base(ap->host, ap->port_no);
4418c2ecf20Sopenharmony_ci}
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_cistatic inline int ahci_nr_ports(u32 cap)
4448c2ecf20Sopenharmony_ci{
4458c2ecf20Sopenharmony_ci	return (cap & 0x1f) + 1;
4468c2ecf20Sopenharmony_ci}
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci#endif /* _AHCI_H */
449