VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
ba6d10ab8014a (Linus Torvalds    2019-07-11 15:14:01 -0700   1) /* SPDX-License-Identifier: GPL-2.0-only */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500   2) /*
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500   3)  * SAS host prototypes and structures header file
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500   4)  *
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500   5)  * Copyright (C) 2005 Adaptec, Inc.  All rights reserved.
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500   6)  * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500   7)  */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500   8) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500   9) #ifndef _LIBSAS_H_
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  10) #define _LIBSAS_H_
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  11) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  12) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  13) #include <linux/timer.h>
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  14) #include <linux/pci.h>
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  15) #include <scsi/sas.h>
fa1c1e8f1ece4 (Darrick J. Wong   2006-08-10 19:19:47 -0700  16) #include <linux/libata.h>
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  17) #include <linux/list.h>
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  18) #include <scsi/scsi_device.h>
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  19) #include <scsi/scsi_cmnd.h>
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  20) #include <scsi/scsi_transport_sas.h>
87ae9afdcada2 (Adrian Bunk       2007-10-30 10:35:04 +0100  21) #include <linux/scatterlist.h>
5a0e3ad6af866 (Tejun Heo         2010-03-24 17:04:11 +0900  22) #include <linux/slab.h>
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  23) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  24) struct block_device;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  25) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  26) enum sas_class {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  27) 	SAS,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  28) 	EXPANDER
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  29) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  30) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  31) enum sas_phy_role {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  32) 	PHY_ROLE_NONE = 0,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  33) 	PHY_ROLE_TARGET = 0x40,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  34) 	PHY_ROLE_INITIATOR = 0x80,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  35) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  36) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  37) enum sas_phy_type {
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800  38) 	PHY_TYPE_PHYSICAL,
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800  39) 	PHY_TYPE_VIRTUAL
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  40) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  41) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  42) /* The events are mnemonically described in sas_dump.c
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  43)  * so when updating/adding events here, please also
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  44)  * update the other file too.
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  45)  */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  46) enum port_event {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  47) 	PORTE_BYTES_DMAED     = 0U,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  48) 	PORTE_BROADCAST_RCVD,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  49) 	PORTE_LINK_RESET_ERR,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  50) 	PORTE_TIMER_EVENT,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  51) 	PORTE_HARD_RESET,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  52) 	PORT_NUM_EVENTS,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  53) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  54) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  55) enum phy_event {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  56) 	PHYE_LOSS_OF_SIGNAL   = 0U,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  57) 	PHYE_OOB_DONE,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  58) 	PHYE_OOB_ERROR,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  59) 	PHYE_SPINUP_HOLD,             /* hot plug SATA, no COMWAKE sent */
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  60) 	PHYE_RESUME_TIMEOUT,
f12486e06ae87 (Jason Yan         2017-12-08 17:42:05 +0800  61) 	PHYE_SHUTDOWN,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  62) 	PHY_NUM_EVENTS,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  63) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  64) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  65) enum discover_event {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  66) 	DISCE_DISCOVER_DOMAIN   = 0U,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  67) 	DISCE_REVALIDATE_DOMAIN,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  68) 	DISCE_SUSPEND,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  69) 	DISCE_RESUME,
0d78f969b10f2 (Jason Yan         2017-09-06 17:15:05 +0800  70) 	DISC_NUM_EVENTS,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  71) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  72) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  73) /* ---------- Expander Devices ---------- */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  74) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  75) #define to_dom_device(_obj) container_of(_obj, struct domain_device, dev_obj)
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  76) #define to_dev_attr(_attr)  container_of(_attr, struct domain_dev_attribute,\
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800  77) 					 attr)
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  78) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  79) enum routing_attribute {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  80) 	DIRECT_ROUTING,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  81) 	SUBTRACTIVE_ROUTING,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  82) 	TABLE_ROUTING,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  83) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  84) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  85) enum ex_phy_state {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  86) 	PHY_EMPTY,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  87) 	PHY_VACANT,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  88) 	PHY_NOT_PRESENT,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  89) 	PHY_DEVICE_DISCOVERED
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  90) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  91) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  92) struct ex_phy {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  93) 	int    phy_id;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  94) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  95) 	enum ex_phy_state phy_state;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  96) 
aa9f8328fc514 (James Bottomley   2013-05-07 14:44:06 -0700  97) 	enum sas_device_type attached_dev_type;
88edf74610bd8 (James Bottomley   2006-09-06 17:36:13 -0500  98) 	enum sas_linkrate linkrate;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500  99) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 100) 	u8   attached_sata_host:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 101) 	u8   attached_sata_dev:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 102) 	u8   attached_sata_ps:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 103) 
5929faf3334f4 (Darrick J. Wong   2007-11-05 11:51:17 -0800 104) 	enum sas_protocol attached_tproto;
5929faf3334f4 (Darrick J. Wong   2007-11-05 11:51:17 -0800 105) 	enum sas_protocol attached_iproto;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 106) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 107) 	u8   attached_sas_addr[SAS_ADDR_SIZE];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 108) 	u8   attached_phy_id;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 109) 
303694eeee5ea (Dan Williams      2012-06-21 23:41:51 -0700 110) 	int phy_change_count;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 111) 	enum routing_attribute routing_attr;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 112) 	u8   virtual:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 113) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 114) 	int  last_da_index;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 115) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 116) 	struct sas_phy *phy;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 117) 	struct sas_port *port;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 118) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 119) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 120) struct expander_device {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 121) 	struct list_head children;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 122) 
303694eeee5ea (Dan Williams      2012-06-21 23:41:51 -0700 123) 	int    ex_change_count;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 124) 	u16    max_route_indexes;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 125) 	u8     num_phys;
ffaac8f45bfb2 (Luben Tuikov      2011-09-22 09:41:36 -0700 126) 
ffaac8f45bfb2 (Luben Tuikov      2011-09-22 09:41:36 -0700 127) 	u8     t2t_supp:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 128) 	u8     configuring:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 129) 	u8     conf_route_table:1;
ffaac8f45bfb2 (Luben Tuikov      2011-09-22 09:41:36 -0700 130) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 131) 	u8     enclosure_logical_id[8];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 132) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 133) 	struct ex_phy *ex_phy;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 134) 	struct sas_port *parent_port;
89d3cf6ac3cdc (Jeff Skirvin      2011-11-16 09:44:13 +0000 135) 
89d3cf6ac3cdc (Jeff Skirvin      2011-11-16 09:44:13 +0000 136) 	struct mutex cmd_mutex;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 137) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 138) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 139) /* ---------- SATA device ---------- */
6ef1b512f4e6f (Dan Williams      2012-06-22 10:52:34 -0700 140) #define ATA_RESP_FIS_SIZE 24
6ef1b512f4e6f (Dan Williams      2012-06-22 10:52:34 -0700 141) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 142) struct sata_device {
1cbd772d9aaf6 (Hannes Reinecke   2014-11-05 13:08:20 +0100 143) 	unsigned int class;
1cbd772d9aaf6 (Hannes Reinecke   2014-11-05 13:08:20 +0100 144) 	u8     port_no;        /* port number, if this is a PM (Port) */
fa1c1e8f1ece4 (Darrick J. Wong   2006-08-10 19:19:47 -0700 145) 
fa1c1e8f1ece4 (Darrick J. Wong   2006-08-10 19:19:47 -0700 146) 	struct ata_port *ap;
2fa4a32613c91 (Jason Yan         2018-05-10 11:05:16 +0800 147) 	struct ata_host *ata_host;
c2e8fbf908afd (Huacai Chen       2017-11-21 14:23:39 +0100 148) 	struct smp_resp rps_resp ____cacheline_aligned; /* report_phy_sata_resp */
6ef1b512f4e6f (Dan Williams      2012-06-22 10:52:34 -0700 149) 	u8     fis[ATA_RESP_FIS_SIZE];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 150) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 151) 
5db45bdc87ce4 (Dan Williams      2012-06-21 23:30:48 -0700 152) struct ssp_device {
5db45bdc87ce4 (Dan Williams      2012-06-21 23:30:48 -0700 153) 	struct list_head eh_list_node; /* pending a user requested eh action */
5db45bdc87ce4 (Dan Williams      2012-06-21 23:30:48 -0700 154) 	struct scsi_lun reset_lun;
5db45bdc87ce4 (Dan Williams      2012-06-21 23:30:48 -0700 155) };
5db45bdc87ce4 (Dan Williams      2012-06-21 23:30:48 -0700 156) 
e139942d77a6e (Dan Williams      2012-01-07 08:52:39 +0000 157) enum {
e139942d77a6e (Dan Williams      2012-01-07 08:52:39 +0000 158) 	SAS_DEV_GONE,
303694eeee5ea (Dan Williams      2012-06-21 23:41:51 -0700 159) 	SAS_DEV_FOUND, /* device notified to lldd */
87c8331fcf72e (Dan Williams      2011-11-17 17:59:51 -0800 160) 	SAS_DEV_DESTROY,
e4a9c3732cea3 (Dan Williams      2012-06-21 23:25:27 -0700 161) 	SAS_DEV_EH_PENDING,
5db45bdc87ce4 (Dan Williams      2012-06-21 23:30:48 -0700 162) 	SAS_DEV_LU_RESET,
5db45bdc87ce4 (Dan Williams      2012-06-21 23:30:48 -0700 163) 	SAS_DEV_RESET,
e139942d77a6e (Dan Williams      2012-01-07 08:52:39 +0000 164) };
e139942d77a6e (Dan Williams      2012-01-07 08:52:39 +0000 165) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 166) struct domain_device {
9095a64a9aead (Dan Williams      2011-11-28 11:29:20 -0800 167) 	spinlock_t done_lock;
aa9f8328fc514 (James Bottomley   2013-05-07 14:44:06 -0700 168) 	enum sas_device_type dev_type;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 169) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 170) 	enum sas_linkrate linkrate;
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 171) 	enum sas_linkrate min_linkrate;
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 172) 	enum sas_linkrate max_linkrate;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 173) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 174) 	int  pathways;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 175) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 176) 	struct domain_device *parent;
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 177) 	struct list_head siblings; /* devices on the same level */
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 178) 	struct asd_sas_port *port;        /* shortcut to root of the tree */
f41a0c441c3fe (Dan Williams      2011-12-21 21:33:17 -0800 179) 	struct sas_phy *phy;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 180) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 181) 	struct list_head dev_list_node;
87c8331fcf72e (Dan Williams      2011-11-17 17:59:51 -0800 182) 	struct list_head disco_list_node; /* awaiting probe or destruct */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 183) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 184) 	enum sas_protocol    iproto;
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 185) 	enum sas_protocol    tproto;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 186) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 187) 	struct sas_rphy *rphy;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 188) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 189) 	u8  sas_addr[SAS_ADDR_SIZE];
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 190) 	u8  hashed_sas_addr[HASHED_SAS_ADDR_SIZE];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 191) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 192) 	u8  frame_rcvd[32];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 193) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 194) 	union {
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 195) 		struct expander_device ex_dev;
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 196) 		struct sata_device     sata_dev; /* STP & directly attached */
5db45bdc87ce4 (Dan Williams      2012-06-21 23:30:48 -0700 197) 		struct ssp_device      ssp_dev;
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 198) 	};
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 199) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 200) 	void *lldd_dev;
e139942d77a6e (Dan Williams      2012-01-07 08:52:39 +0000 201) 	unsigned long state;
735f7d2fedf57 (Dan Williams      2011-11-17 17:59:47 -0800 202) 	struct kref kref;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 203) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 204) 
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 205) struct sas_work {
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 206) 	struct list_head drain_node;
c4028958b6eca (David Howells     2006-11-22 14:57:56 +0000 207) 	struct work_struct work;
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 208) };
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 209) 
924a3541eab0d (John Garry        2019-06-10 20:41:41 +0800 210) static inline bool dev_is_expander(enum sas_device_type type)
085f104a83d56 (John Garry        2019-04-12 16:57:55 +0800 211) {
085f104a83d56 (John Garry        2019-04-12 16:57:55 +0800 212) 	return type == SAS_EDGE_EXPANDER_DEVICE ||
085f104a83d56 (John Garry        2019-04-12 16:57:55 +0800 213) 	       type == SAS_FANOUT_EXPANDER_DEVICE;
085f104a83d56 (John Garry        2019-04-12 16:57:55 +0800 214) }
085f104a83d56 (John Garry        2019-04-12 16:57:55 +0800 215) 
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 216) static inline void INIT_SAS_WORK(struct sas_work *sw, void (*fn)(struct work_struct *))
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 217) {
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 218) 	INIT_WORK(&sw->work, fn);
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 219) 	INIT_LIST_HEAD(&sw->drain_node);
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 220) }
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 221) 
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 222) struct sas_discovery_event {
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 223) 	struct sas_work work;
c4028958b6eca (David Howells     2006-11-22 14:57:56 +0000 224) 	struct asd_sas_port *port;
c4028958b6eca (David Howells     2006-11-22 14:57:56 +0000 225) };
c4028958b6eca (David Howells     2006-11-22 14:57:56 +0000 226) 
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 227) static inline struct sas_discovery_event *to_sas_discovery_event(struct work_struct *work)
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 228) {
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 229) 	struct sas_discovery_event *ev = container_of(work, typeof(*ev), work.work);
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 230) 
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 231) 	return ev;
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 232) }
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 233) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 234) struct sas_discovery {
c4028958b6eca (David Howells     2006-11-22 14:57:56 +0000 235) 	struct sas_discovery_event disc_work[DISC_NUM_EVENTS];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 236) 	unsigned long    pending;
7b27c5fe247b4 (John Garry        2019-04-12 16:57:52 +0800 237) 	u8     fanout_sas_addr[SAS_ADDR_SIZE];
7b27c5fe247b4 (John Garry        2019-04-12 16:57:52 +0800 238) 	u8     eeds_a[SAS_ADDR_SIZE];
7b27c5fe247b4 (John Garry        2019-04-12 16:57:52 +0800 239) 	u8     eeds_b[SAS_ADDR_SIZE];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 240) 	int    max_level;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 241) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 242) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 243) /* The port struct is Class:RW, driver:RO */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 244) struct asd_sas_port {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 245) /* private: */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 246) 	struct sas_discovery disc;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 247) 	struct domain_device *port_dev;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 248) 	spinlock_t dev_list_lock;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 249) 	struct list_head dev_list;
87c8331fcf72e (Dan Williams      2011-11-17 17:59:51 -0800 250) 	struct list_head disco_list;
87c8331fcf72e (Dan Williams      2011-11-17 17:59:51 -0800 251) 	struct list_head destroy_list;
0558f33c06bb9 (Jason Yan         2017-12-08 17:42:09 +0800 252) 	struct list_head sas_port_del_list;
88edf74610bd8 (James Bottomley   2006-09-06 17:36:13 -0500 253) 	enum   sas_linkrate linkrate;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 254) 
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 255) 	struct sas_work work;
303694eeee5ea (Dan Williams      2012-06-21 23:41:51 -0700 256) 	int suspended;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 257) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 258) /* public: */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 259) 	int id;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 260) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 261) 	enum sas_class   class;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 262) 	u8               sas_addr[SAS_ADDR_SIZE];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 263) 	u8               attached_sas_addr[SAS_ADDR_SIZE];
5929faf3334f4 (Darrick J. Wong   2007-11-05 11:51:17 -0800 264) 	enum sas_protocol   iproto;
5929faf3334f4 (Darrick J. Wong   2007-11-05 11:51:17 -0800 265) 	enum sas_protocol   tproto;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 266) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 267) 	enum sas_oob_mode oob_mode;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 268) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 269) 	spinlock_t       phy_list_lock;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 270) 	struct list_head phy_list;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 271) 	int              num_phys;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 272) 	u32              phy_mask;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 273) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 274) 	struct sas_ha_struct *ha;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 275) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 276) 	struct sas_port	*port;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 277) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 278) 	void *lldd_port;	  /* not touched by the sas class code */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 279) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 280) 
c4028958b6eca (David Howells     2006-11-22 14:57:56 +0000 281) struct asd_sas_event {
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 282) 	struct sas_work work;
c4028958b6eca (David Howells     2006-11-22 14:57:56 +0000 283) 	struct asd_sas_phy *phy;
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 284) 	int event;
c4028958b6eca (David Howells     2006-11-22 14:57:56 +0000 285) };
c4028958b6eca (David Howells     2006-11-22 14:57:56 +0000 286) 
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 287) static inline struct asd_sas_event *to_asd_sas_event(struct work_struct *work)
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 288) {
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 289) 	struct asd_sas_event *ev = container_of(work, typeof(*ev), work.work);
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 290) 
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 291) 	return ev;
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 292) }
22b9153faa226 (Dan Williams      2012-03-09 11:00:06 -0800 293) 
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 294) static inline void INIT_SAS_EVENT(struct asd_sas_event *ev,
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 295) 		void (*fn)(struct work_struct *),
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 296) 		struct asd_sas_phy *phy, int event)
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 297) {
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 298) 	INIT_SAS_WORK(&ev->work, fn);
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 299) 	ev->phy = phy;
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 300) 	ev->event = event;
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 301) }
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 302) 
f12486e06ae87 (Jason Yan         2017-12-08 17:42:05 +0800 303) #define SAS_PHY_SHUTDOWN_THRES   1024
1c393b970e0f4 (Jason Yan         2017-12-08 17:42:04 +0800 304) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 305) /* The phy pretty much is controlled by the LLDD.
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 306)  * The class only reads those fields.
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 307)  */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 308) struct asd_sas_phy {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 309) /* private: */
f12486e06ae87 (Jason Yan         2017-12-08 17:42:05 +0800 310) 	atomic_t event_nr;
f12486e06ae87 (Jason Yan         2017-12-08 17:42:05 +0800 311) 	int in_shutdown;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 312) 	int error;
303694eeee5ea (Dan Williams      2012-06-21 23:41:51 -0700 313) 	int suspended;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 314) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 315) 	struct sas_phy *phy;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 316) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 317) /* public: */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 318) 	/* The following are class:RO, driver:R/W */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 319) 	int            enabled;	  /* must be set */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 320) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 321) 	int            id;	  /* must be set */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 322) 	enum sas_class class;
5929faf3334f4 (Darrick J. Wong   2007-11-05 11:51:17 -0800 323) 	enum sas_protocol iproto;
5929faf3334f4 (Darrick J. Wong   2007-11-05 11:51:17 -0800 324) 	enum sas_protocol tproto;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 325) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 326) 	enum sas_phy_type  type;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 327) 	enum sas_phy_role  role;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 328) 	enum sas_oob_mode  oob_mode;
88edf74610bd8 (James Bottomley   2006-09-06 17:36:13 -0500 329) 	enum sas_linkrate linkrate;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 330) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 331) 	u8   *sas_addr;		  /* must be set */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 332) 	u8   attached_sas_addr[SAS_ADDR_SIZE]; /* class:RO, driver: R/W */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 333) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 334) 	spinlock_t     frame_rcvd_lock;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 335) 	u8             *frame_rcvd; /* must be set */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 336) 	int            frame_rcvd_size;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 337) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 338) 	spinlock_t     sas_prim_lock;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 339) 	u32            sas_prim;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 340) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 341) 	struct list_head port_phy_el; /* driver:RO */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 342) 	struct asd_sas_port      *port; /* Class:RW, driver: RO */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 343) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 344) 	struct sas_ha_struct *ha; /* may be set; the class sets it anyway */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 345) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 346) 	void *lldd_phy;		  /* not touched by the sas_class_code */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 347) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 348) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 349) struct scsi_core {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 350) 	struct Scsi_Host *shost;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 351) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 352) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 353) 
6b0efb8516a52 (Darrick J. Wong   2007-01-11 14:15:43 -0800 354) enum sas_ha_state {
6b0efb8516a52 (Darrick J. Wong   2007-01-11 14:15:43 -0800 355) 	SAS_HA_REGISTERED,
b1124cd3ec974 (Dan Williams      2011-12-19 16:42:34 -0800 356) 	SAS_HA_DRAINING,
87c8331fcf72e (Dan Williams      2011-11-17 17:59:51 -0800 357) 	SAS_HA_ATA_EH_ACTIVE,
9095a64a9aead (Dan Williams      2011-11-28 11:29:20 -0800 358) 	SAS_HA_FROZEN,
6b0efb8516a52 (Darrick J. Wong   2007-01-11 14:15:43 -0800 359) };
6b0efb8516a52 (Darrick J. Wong   2007-01-11 14:15:43 -0800 360) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 361) struct sas_ha_struct {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 362) /* private: */
b1124cd3ec974 (Dan Williams      2011-12-19 16:42:34 -0800 363) 	struct list_head  defer_q; /* work queued while draining */
b1124cd3ec974 (Dan Williams      2011-12-19 16:42:34 -0800 364) 	struct mutex	  drain_mutex;
f8daa6e6d83f6 (Dan Williams      2011-12-19 17:02:25 -0800 365) 	unsigned long	  state;
e4a9c3732cea3 (Dan Williams      2012-06-21 23:25:27 -0700 366) 	spinlock_t	  lock;
e4a9c3732cea3 (Dan Williams      2012-06-21 23:25:27 -0700 367) 	int		  eh_active;
5db45bdc87ce4 (Dan Williams      2012-06-21 23:30:48 -0700 368) 	wait_queue_head_t eh_wait_q;
5db45bdc87ce4 (Dan Williams      2012-06-21 23:30:48 -0700 369) 	struct list_head  eh_dev_q;
6b0efb8516a52 (Darrick J. Wong   2007-01-11 14:15:43 -0800 370) 
87c8331fcf72e (Dan Williams      2011-11-17 17:59:51 -0800 371) 	struct mutex disco_mutex;
87c8331fcf72e (Dan Williams      2011-11-17 17:59:51 -0800 372) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 373) 	struct scsi_core core;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 374) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 375) /* public: */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 376) 	char *sas_ha_name;
1d1bbee61e4ec (Jeff Garzik       2007-07-26 09:28:37 -0400 377) 	struct device *dev;	  /* should be set */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 378) 	struct module *lldd_module; /* should be set */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 379) 
93bdbd06b1644 (Jason Yan         2017-12-08 17:42:07 +0800 380) 	struct workqueue_struct *event_q;
93bdbd06b1644 (Jason Yan         2017-12-08 17:42:07 +0800 381) 	struct workqueue_struct *disco_q;
93bdbd06b1644 (Jason Yan         2017-12-08 17:42:07 +0800 382) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 383) 	u8 *sas_addr;		  /* must be set */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 384) 	u8 hashed_sas_addr[HASHED_SAS_ADDR_SIZE];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 385) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 386) 	spinlock_t      phy_port_lock;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 387) 	struct asd_sas_phy  **sas_phy; /* array of valid pointers, must be set */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 388) 	struct asd_sas_port **sas_port; /* array of valid pointers, must be set */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 389) 	int             num_phys; /* must be set, gt 0, static */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 390) 
00f0254ed9b19 (Dan Williams      2010-10-01 13:55:52 -0700 391) 	int strict_wide_ports; /* both sas_addr and attached_sas_addr must match
00f0254ed9b19 (Dan Williams      2010-10-01 13:55:52 -0700 392) 				* their siblings when forming wide ports */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 393) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 394) 	void *lldd_ha;		  /* not touched by sas class code */
f456393e195e0 (Darrick J. Wong   2006-10-30 15:18:39 -0800 395) 
3944f50995f94 (Dan Williams      2011-11-29 12:08:50 -0800 396) 	struct list_head eh_done_q;  /* complete via scsi_eh_flush_done_q */
3944f50995f94 (Dan Williams      2011-11-29 12:08:50 -0800 397) 	struct list_head eh_ata_q; /* scmds to promote from sas to ata eh */
f12486e06ae87 (Jason Yan         2017-12-08 17:42:05 +0800 398) 
f12486e06ae87 (Jason Yan         2017-12-08 17:42:05 +0800 399) 	int event_thres;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 400) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 401) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 402) #define SHOST_TO_SAS_HA(_shost) (*(struct sas_ha_struct **)(_shost)->hostdata)
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 403) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 404) static inline struct domain_device *
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 405) starget_to_domain_dev(struct scsi_target *starget) {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 406) 	return starget->hostdata;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 407) }
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 408) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 409) static inline struct domain_device *
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 410) sdev_to_domain_dev(struct scsi_device *sdev) {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 411) 	return starget_to_domain_dev(sdev->sdev_target);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 412) }
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 413) 
b50102d3e9a43 (Dan Williams      2011-09-30 18:52:19 -0700 414) static inline struct ata_device *sas_to_ata_dev(struct domain_device *dev)
b50102d3e9a43 (Dan Williams      2011-09-30 18:52:19 -0700 415) {
b50102d3e9a43 (Dan Williams      2011-09-30 18:52:19 -0700 416) 	return &dev->sata_dev.ap->link.device[0];
b50102d3e9a43 (Dan Williams      2011-09-30 18:52:19 -0700 417) }
b50102d3e9a43 (Dan Williams      2011-09-30 18:52:19 -0700 418) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 419) static inline struct domain_device *
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 420) cmd_to_domain_dev(struct scsi_cmnd *cmd)
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 421) {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 422) 	return sdev_to_domain_dev(cmd->device);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 423) }
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 424) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 425) void sas_hash_addr(u8 *hashed, const u8 *sas_addr);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 426) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 427) /* Before calling a notify event, LLDD should use this function
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 428)  * when the link is severed (possibly from its tasklet).
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 429)  * The idea is that the Class only reads those, while the LLDD,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 430)  * can R/W these (thus avoiding a race).
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 431)  */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 432) static inline void sas_phy_disconnected(struct asd_sas_phy *phy)
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 433) {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 434) 	phy->oob_mode = OOB_NOT_CONNECTED;
88edf74610bd8 (James Bottomley   2006-09-06 17:36:13 -0500 435) 	phy->linkrate = SAS_LINK_RATE_UNKNOWN;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 436) }
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 437) 
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 438) static inline unsigned int to_sas_gpio_od(int device, int bit)
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 439) {
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 440) 	return 3 * device + bit;
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 441) }
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 442) 
f41a0c441c3fe (Dan Williams      2011-12-21 21:33:17 -0800 443) static inline void sas_put_local_phy(struct sas_phy *phy)
f41a0c441c3fe (Dan Williams      2011-12-21 21:33:17 -0800 444) {
f41a0c441c3fe (Dan Williams      2011-12-21 21:33:17 -0800 445) 	put_device(&phy->dev);
f41a0c441c3fe (Dan Williams      2011-12-21 21:33:17 -0800 446) }
f41a0c441c3fe (Dan Williams      2011-12-21 21:33:17 -0800 447) 
d962480e9a061 (Dan Williams      2011-09-23 16:43:45 -0700 448) #ifdef CONFIG_SCSI_SAS_HOST_SMP
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 449) int try_test_sas_gpio_gp_bit(unsigned int od, u8 *data, u8 index, u8 count);
d962480e9a061 (Dan Williams      2011-09-23 16:43:45 -0700 450) #else
d962480e9a061 (Dan Williams      2011-09-23 16:43:45 -0700 451) static inline int try_test_sas_gpio_gp_bit(unsigned int od, u8 *data, u8 index, u8 count)
d962480e9a061 (Dan Williams      2011-09-23 16:43:45 -0700 452) {
d962480e9a061 (Dan Williams      2011-09-23 16:43:45 -0700 453) 	return -1;
d962480e9a061 (Dan Williams      2011-09-23 16:43:45 -0700 454) }
d962480e9a061 (Dan Williams      2011-09-23 16:43:45 -0700 455) #endif
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 456) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 457) /* ---------- Tasks ---------- */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 458) /*
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 459)       service_response |  SAS_TASK_COMPLETE  |  SAS_TASK_UNDELIVERED |
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 460)   exec_status          |                     |                       |
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 461)   ---------------------+---------------------+-----------------------+
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 462)        SAM_...         |         X           |                       |
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 463)        DEV_NO_RESPONSE |         X           |           X           |
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 464)        INTERRUPTED     |         X           |                       |
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 465)        QUEUE_FULL      |                     |           X           |
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 466)        DEVICE_UNKNOWN  |                     |           X           |
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 467)        SG_ERR          |                     |           X           |
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 468)   ---------------------+---------------------+-----------------------+
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 469)  */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 470) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 471) enum service_response {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 472) 	SAS_TASK_COMPLETE,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 473) 	SAS_TASK_UNDELIVERED = -1,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 474) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 475) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 476) enum exec_status {
d377f415dddc1 (Bart Van Assche   2021-05-23 19:54:55 -0700 477) 	/*
d377f415dddc1 (Bart Van Assche   2021-05-23 19:54:55 -0700 478) 	 * Values 0..0x7f are used to return the SAM_STAT_* codes.  To avoid
d377f415dddc1 (Bart Van Assche   2021-05-23 19:54:55 -0700 479) 	 * 'case value not in enumerated type' compiler warnings every value
d377f415dddc1 (Bart Van Assche   2021-05-23 19:54:55 -0700 480) 	 * returned through the exec_status enum needs an alias with the SAS_
d377f415dddc1 (Bart Van Assche   2021-05-23 19:54:55 -0700 481) 	 * prefix here.
a3a142524aa4b (Dan Williams      2011-12-06 23:24:42 -0800 482) 	 */
d377f415dddc1 (Bart Van Assche   2021-05-23 19:54:55 -0700 483) 	SAS_SAM_STAT_GOOD = SAM_STAT_GOOD,
d377f415dddc1 (Bart Van Assche   2021-05-23 19:54:55 -0700 484) 	SAS_SAM_STAT_BUSY = SAM_STAT_BUSY,
d377f415dddc1 (Bart Van Assche   2021-05-23 19:54:55 -0700 485) 	SAS_SAM_STAT_TASK_ABORTED = SAM_STAT_TASK_ABORTED,
d377f415dddc1 (Bart Van Assche   2021-05-23 19:54:55 -0700 486) 	SAS_SAM_STAT_CHECK_CONDITION = SAM_STAT_CHECK_CONDITION,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 487) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 488) 	SAS_DEV_NO_RESPONSE = 0x80,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 489) 	SAS_DATA_UNDERRUN,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 490) 	SAS_DATA_OVERRUN,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 491) 	SAS_INTERRUPTED,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 492) 	SAS_QUEUE_FULL,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 493) 	SAS_DEVICE_UNKNOWN,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 494) 	SAS_SG_ERR,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 495) 	SAS_OPEN_REJECT,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 496) 	SAS_OPEN_TO,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 497) 	SAS_PROTO_RESPONSE,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 498) 	SAS_PHY_DOWN,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 499) 	SAS_NAK_R_ERR,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 500) 	SAS_PENDING,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 501) 	SAS_ABORTED_TASK,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 502) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 503) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 504) /* When a task finishes with a response, the LLDD examines the
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 505)  * response:
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 506)  *	- For an ATA task task_status_struct::stat is set to
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 507)  * SAS_PROTO_RESPONSE, and the task_status_struct::buf is set to the
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 508)  * contents of struct ata_task_resp.
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 509)  *	- For SSP tasks, if no data is present or status/TMF response
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 510)  * is valid, task_status_struct::stat is set.  If data is present
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 511)  * (SENSE data), the LLDD copies up to SAS_STATUS_BUF_SIZE, sets
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 512)  * task_status_struct::buf_valid_size, and task_status_struct::stat is
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 513)  * set to SAM_CHECK_COND.
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 514)  *
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 515)  * "buf" has format SCSI Sense for SSP task, or struct ata_task_resp
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 516)  * for ATA task.
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 517)  *
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 518)  * "frame_len" is the total frame length, which could be more or less
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 519)  * than actually copied.
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 520)  *
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 521)  * Tasks ending with response, always set the residual field.
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 522)  */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 523) struct ata_task_resp {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 524) 	u16  frame_len;
6ef1b512f4e6f (Dan Williams      2012-06-22 10:52:34 -0700 525) 	u8   ending_fis[ATA_RESP_FIS_SIZE];	  /* dev to host or data-in */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 526) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 527) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 528) #define SAS_STATUS_BUF_SIZE 96
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 529) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 530) struct task_status_struct {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 531) 	enum service_response resp;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 532) 	enum exec_status      stat;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 533) 	int  buf_valid_size;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 534) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 535) 	u8   buf[SAS_STATUS_BUF_SIZE];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 536) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 537) 	u32  residual;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 538) 	enum sas_open_rej_reason open_rej_reason;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 539) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 540) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 541) /* ATA and ATAPI task queuable to a SAS LLDD.
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 542)  */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 543) struct sas_ata_task {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 544) 	struct host_to_dev_fis fis;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 545) 	u8     atapi_packet[16];  /* 0 if not ATAPI task */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 546) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 547) 	u8     retry_count;	  /* hardware retry, should be > 0 */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 548) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 549) 	u8     dma_xfer:1;	  /* PIO:0 or DMA:1 */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 550) 	u8     use_ncq:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 551) 	u8     set_affil_pol:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 552) 	u8     stp_affil_pol:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 553) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 554) 	u8     device_control_reg_update:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 555) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 556) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 557) struct sas_smp_task {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 558) 	struct scatterlist smp_req;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 559) 	struct scatterlist smp_resp;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 560) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 561) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 562) enum task_attribute {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 563) 	TASK_ATTR_SIMPLE = 0,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 564) 	TASK_ATTR_HOQ    = 1,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 565) 	TASK_ATTR_ORDERED= 2,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 566) 	TASK_ATTR_ACA    = 4,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 567) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 568) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 569) struct sas_ssp_task {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 570) 	u8     retry_count;	  /* hardware retry, should be > 0 */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 571) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 572) 	u8     LUN[8];
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 573) 	u8     enable_first_burst:1;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 574) 	enum   task_attribute task_attr;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 575) 	u8     task_prio;
e73823f7a2c92 (James Bottomley   2013-05-07 15:38:18 -0700 576) 	struct scsi_cmnd *cmd;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 577) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 578) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 579) struct sas_task {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 580) 	struct domain_device *dev;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 581) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 582) 	spinlock_t   task_state_lock;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 583) 	unsigned     task_state_flags;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 584) 
5929faf3334f4 (Darrick J. Wong   2007-11-05 11:51:17 -0800 585) 	enum   sas_protocol      task_proto;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 586) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 587) 	union {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 588) 		struct sas_ata_task ata_task;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 589) 		struct sas_smp_task smp_task;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 590) 		struct sas_ssp_task ssp_task;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 591) 	};
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 592) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 593) 	struct scatterlist *scatter;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 594) 	int    num_scatter;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 595) 	u32    total_xfer_len;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 596) 	u8     data_dir:2;	  /* Use PCI_DMA_... */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 597) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 598) 	struct task_status_struct task_status;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 599) 	void   (*task_done)(struct sas_task *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 600) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 601) 	void   *lldd_task;	  /* for use by LLDDs */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 602) 	void   *uldd_task;
f0bf750c2d25c (Dan Williams      2012-06-21 23:36:30 -0700 603) 	struct sas_task_slow *slow_task;
f0bf750c2d25c (Dan Williams      2012-06-21 23:36:30 -0700 604) };
79a5eb609b74e (Darrick J. Wong   2006-10-30 15:18:50 -0800 605) 
f0bf750c2d25c (Dan Williams      2012-06-21 23:36:30 -0700 606) struct sas_task_slow {
f0bf750c2d25c (Dan Williams      2012-06-21 23:36:30 -0700 607) 	/* standard/extra infrastructure for slow path commands (SMP and
f0bf750c2d25c (Dan Williams      2012-06-21 23:36:30 -0700 608) 	 * internal lldd commands
f0bf750c2d25c (Dan Williams      2012-06-21 23:36:30 -0700 609) 	 */
f0bf750c2d25c (Dan Williams      2012-06-21 23:36:30 -0700 610) 	struct timer_list     timer;
f0bf750c2d25c (Dan Williams      2012-06-21 23:36:30 -0700 611) 	struct completion     completion;
77570eedd92ad (Kees Cook         2017-08-22 16:05:14 -0700 612) 	struct sas_task       *task;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 613) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 614) 
f456393e195e0 (Darrick J. Wong   2006-10-30 15:18:39 -0800 615) #define SAS_TASK_STATE_PENDING      1
f456393e195e0 (Darrick J. Wong   2006-10-30 15:18:39 -0800 616) #define SAS_TASK_STATE_DONE         2
f456393e195e0 (Darrick J. Wong   2006-10-30 15:18:39 -0800 617) #define SAS_TASK_STATE_ABORTED      4
3ebf6922b0833 (Darrick J. Wong   2007-01-11 14:15:17 -0800 618) #define SAS_TASK_NEED_DEV_RESET     8
b218a0d8e250e (Darrick J. Wong   2007-01-11 14:14:55 -0800 619) #define SAS_TASK_AT_INITIATOR       16
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 620) 
4fcf812ca3923 (Dan Williams      2011-07-29 17:26:39 -0700 621) extern struct sas_task *sas_alloc_task(gfp_t flags);
f0bf750c2d25c (Dan Williams      2012-06-21 23:36:30 -0700 622) extern struct sas_task *sas_alloc_slow_task(gfp_t flags);
4fcf812ca3923 (Dan Williams      2011-07-29 17:26:39 -0700 623) extern void sas_free_task(struct sas_task *task);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 624) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 625) struct sas_domain_function_template {
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 626) 	/* The class calls these to notify the LLDD of an event. */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 627) 	void (*lldd_port_formed)(struct asd_sas_phy *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 628) 	void (*lldd_port_deformed)(struct asd_sas_phy *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 629) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 630) 	/* The class calls these when a device is found or gone. */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 631) 	int  (*lldd_dev_found)(struct domain_device *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 632) 	void (*lldd_dev_gone)(struct domain_device *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 633) 
79855d178557c (Christoph Hellwig 2014-11-05 10:36:28 +0100 634) 	int (*lldd_execute_task)(struct sas_task *, gfp_t gfp_flags);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 635) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 636) 	/* Task Management Functions. Must be called from process context. */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 637) 	int (*lldd_abort_task)(struct sas_task *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 638) 	int (*lldd_abort_task_set)(struct domain_device *, u8 *lun);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 639) 	int (*lldd_clear_aca)(struct domain_device *, u8 *lun);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 640) 	int (*lldd_clear_task_set)(struct domain_device *, u8 *lun);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 641) 	int (*lldd_I_T_nexus_reset)(struct domain_device *);
36a399473902a (Dan Williams      2011-11-17 17:59:54 -0800 642) 	int (*lldd_ata_check_ready)(struct domain_device *);
b91bb29618811 (Dan Williams      2011-11-17 17:59:52 -0800 643) 	void (*lldd_ata_set_dmamode)(struct domain_device *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 644) 	int (*lldd_lu_reset)(struct domain_device *, u8 *lun);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 645) 	int (*lldd_query_task)(struct sas_task *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 646) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 647) 	/* Port and Adapter management */
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 648) 	int (*lldd_clear_nexus_port)(struct asd_sas_port *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 649) 	int (*lldd_clear_nexus_ha)(struct sas_ha_struct *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 650) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 651) 	/* Phy management */
a01e70e570a72 (James Bottomley   2006-09-06 19:28:07 -0500 652) 	int (*lldd_control_phy)(struct asd_sas_phy *, enum phy_func, void *);
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 653) 
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 654) 	/* GPIO support */
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 655) 	int (*lldd_write_gpio)(struct sas_ha_struct *, u8 reg_type,
8ec6552f4a77d (Dan Williams      2011-09-01 21:18:20 -0700 656) 			       u8 reg_index, u8 reg_count, u8 *write_data);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 657) };
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 658) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 659) extern int sas_register_ha(struct sas_ha_struct *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 660) extern int sas_unregister_ha(struct sas_ha_struct *);
303694eeee5ea (Dan Williams      2012-06-21 23:41:51 -0700 661) extern void sas_prep_resume_ha(struct sas_ha_struct *sas_ha);
303694eeee5ea (Dan Williams      2012-06-21 23:41:51 -0700 662) extern void sas_resume_ha(struct sas_ha_struct *sas_ha);
303694eeee5ea (Dan Williams      2012-06-21 23:41:51 -0700 663) extern void sas_suspend_ha(struct sas_ha_struct *sas_ha);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 664) 
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 665) int sas_set_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates);
dea22214790d1 (Darrick J. Wong   2006-11-07 17:28:55 -0800 666) int sas_phy_reset(struct sas_phy *phy, int hard_reset);
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 667) extern int sas_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 668) extern int sas_target_alloc(struct scsi_target *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 669) extern int sas_slave_configure(struct scsi_device *);
db5ed4dfd5dd0 (Christoph Hellwig 2014-11-13 15:08:42 +0100 670) extern int sas_change_queue_depth(struct scsi_device *, int new_depth);
ff525b6e2d301 (John Garry        2019-01-05 00:01:26 +0800 671) extern int sas_bios_param(struct scsi_device *, struct block_device *,
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 672) 			  sector_t capacity, int *hsc);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 673) extern struct scsi_transport_template *
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 674) sas_domain_attach_transport(struct sas_domain_function_template *);
8eea9dd84e450 (Jason Yan         2017-12-08 17:42:06 +0800 675) extern struct device_attribute dev_attr_phy_event_threshold;
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 676) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 677) int  sas_discover_root_expander(struct domain_device *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 678) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 679) void sas_init_ex_attr(void);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 680) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 681) int  sas_ex_revalidate_domain(struct domain_device *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 682) 
7d05919aad080 (Dan Williams      2012-01-10 14:39:13 -0800 683) void sas_unregister_domain_devices(struct asd_sas_port *port, int gone);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 684) void sas_init_disc(struct sas_discovery *disc, struct asd_sas_port *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 685) int  sas_discover_event(struct asd_sas_port *, enum discover_event ev);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 686) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 687) int  sas_discover_sata(struct domain_device *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 688) int  sas_discover_end_dev(struct domain_device *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 689) 
1a34c0640137e (Dan Williams      2011-09-21 22:05:34 -0700 690) void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 691) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 692) void sas_init_dev(struct domain_device *);
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 693) 
396819fba821a (Darrick J. Wong   2007-01-11 14:15:20 -0800 694) void sas_task_abort(struct sas_task *);
9524c6821849b (Dan Williams      2012-06-21 23:30:53 -0700 695) int sas_eh_abort_handler(struct scsi_cmnd *cmd);
ad689233bee85 (Darrick J. Wong   2007-01-26 14:08:52 -0800 696) int sas_eh_device_reset_handler(struct scsi_cmnd *cmd);
cc199e7846056 (Hannes Reinecke   2017-08-25 13:57:02 +0200 697) int sas_eh_target_reset_handler(struct scsi_cmnd *cmd);
79a5eb609b74e (Darrick J. Wong   2006-10-30 15:18:50 -0800 698) 
fa1c1e8f1ece4 (Darrick J. Wong   2006-08-10 19:19:47 -0700 699) extern void sas_target_destroy(struct scsi_target *);
fa1c1e8f1ece4 (Darrick J. Wong   2006-08-10 19:19:47 -0700 700) extern int sas_slave_alloc(struct scsi_device *);
6f4e626fb0cc9 (Nathan Chancellor 2019-02-07 09:07:20 -0700 701) extern int sas_ioctl(struct scsi_device *sdev, unsigned int cmd,
6f4e626fb0cc9 (Nathan Chancellor 2019-02-07 09:07:20 -0700 702) 		     void __user *arg);
b1124cd3ec974 (Dan Williams      2011-12-19 16:42:34 -0800 703) extern int sas_drain_work(struct sas_ha_struct *ha);
fa1c1e8f1ece4 (Darrick J. Wong   2006-08-10 19:19:47 -0700 704) 
366ca51f30de1 (James Bottomley   2008-01-18 10:47:01 -0600 705) extern void sas_ssp_task_response(struct device *dev, struct sas_task *task,
366ca51f30de1 (James Bottomley   2008-01-18 10:47:01 -0600 706) 				  struct ssp_response_iu *iu);
f41a0c441c3fe (Dan Williams      2011-12-21 21:33:17 -0800 707) struct sas_phy *sas_get_local_phy(struct domain_device *dev);
366ca51f30de1 (James Bottomley   2008-01-18 10:47:01 -0600 708) 
45e6cdf41437c (Darrick J. Wong   2008-02-19 10:49:40 -0800 709) int sas_request_addr(struct Scsi_Host *shost, u8 *addr);
45e6cdf41437c (Darrick J. Wong   2008-02-19 10:49:40 -0800 710) 
5d6a75a1edf63 (Ahmed S. Darwish  2021-01-18 11:09:48 +0100 711) int sas_notify_port_event(struct asd_sas_phy *phy, enum port_event event,
5d6a75a1edf63 (Ahmed S. Darwish  2021-01-18 11:09:48 +0100 712) 			  gfp_t gfp_flags);
5d6a75a1edf63 (Ahmed S. Darwish  2021-01-18 11:09:48 +0100 713) int sas_notify_phy_event(struct asd_sas_phy *phy, enum phy_event event,
5d6a75a1edf63 (Ahmed S. Darwish  2021-01-18 11:09:48 +0100 714) 			 gfp_t gfp_flags);
121181f3f839c (John Garry        2021-01-18 11:09:38 +0100 715) 
2908d778ab3e2 (James Bottomley   2006-08-29 09:22:51 -0500 716) #endif /* _SASLIB_H_ */