xref: /openbmc/linux/drivers/scsi/aic94xx/aic94xx_dev.c (revision 81e56ded878aeb8730f18c1d0a70d5face788be3)
12908d778SJames Bottomley /*
22908d778SJames Bottomley  * Aic94xx SAS/SATA DDB management
32908d778SJames Bottomley  *
42908d778SJames Bottomley  * Copyright (C) 2005 Adaptec, Inc.  All rights reserved.
52908d778SJames Bottomley  * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
62908d778SJames Bottomley  *
72908d778SJames Bottomley  * This file is licensed under GPLv2.
82908d778SJames Bottomley  *
92908d778SJames Bottomley  * This file is part of the aic94xx driver.
102908d778SJames Bottomley  *
112908d778SJames Bottomley  * The aic94xx driver is free software; you can redistribute it and/or
122908d778SJames Bottomley  * modify it under the terms of the GNU General Public License as
132908d778SJames Bottomley  * published by the Free Software Foundation; version 2 of the
142908d778SJames Bottomley  * License.
152908d778SJames Bottomley  *
162908d778SJames Bottomley  * The aic94xx driver is distributed in the hope that it will be useful,
172908d778SJames Bottomley  * but WITHOUT ANY WARRANTY; without even the implied warranty of
182908d778SJames Bottomley  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
192908d778SJames Bottomley  * General Public License for more details.
202908d778SJames Bottomley  *
212908d778SJames Bottomley  * You should have received a copy of the GNU General Public License
222908d778SJames Bottomley  * along with the aic94xx driver; if not, write to the Free Software
232908d778SJames Bottomley  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
242908d778SJames Bottomley  *
252908d778SJames Bottomley  * $Id: //depot/aic94xx/aic94xx_dev.c#21 $
262908d778SJames Bottomley  */
272908d778SJames Bottomley 
282908d778SJames Bottomley #include "aic94xx.h"
292908d778SJames Bottomley #include "aic94xx_hwi.h"
302908d778SJames Bottomley #include "aic94xx_reg.h"
312908d778SJames Bottomley #include "aic94xx_sas.h"
322908d778SJames Bottomley 
332908d778SJames Bottomley #define FIND_FREE_DDB(_ha) find_first_zero_bit((_ha)->hw_prof.ddb_bitmap, \
342908d778SJames Bottomley 					       (_ha)->hw_prof.max_ddbs)
352908d778SJames Bottomley #define SET_DDB(_ddb, _ha) set_bit(_ddb, (_ha)->hw_prof.ddb_bitmap)
362908d778SJames Bottomley #define CLEAR_DDB(_ddb, _ha) clear_bit(_ddb, (_ha)->hw_prof.ddb_bitmap)
372908d778SJames Bottomley 
38*81e56dedSAdrian Bunk static int asd_get_ddb(struct asd_ha_struct *asd_ha)
392908d778SJames Bottomley {
402908d778SJames Bottomley 	int ddb, i;
412908d778SJames Bottomley 
422908d778SJames Bottomley 	ddb = FIND_FREE_DDB(asd_ha);
432908d778SJames Bottomley 	if (ddb >= asd_ha->hw_prof.max_ddbs) {
442908d778SJames Bottomley 		ddb = -ENOMEM;
452908d778SJames Bottomley 		goto out;
462908d778SJames Bottomley 	}
472908d778SJames Bottomley 	SET_DDB(ddb, asd_ha);
482908d778SJames Bottomley 
492908d778SJames Bottomley 	for (i = 0; i < sizeof(struct asd_ddb_ssp_smp_target_port); i+= 4)
502908d778SJames Bottomley 		asd_ddbsite_write_dword(asd_ha, ddb, i, 0);
512908d778SJames Bottomley out:
522908d778SJames Bottomley 	return ddb;
532908d778SJames Bottomley }
542908d778SJames Bottomley 
552908d778SJames Bottomley #define INIT_CONN_TAG   offsetof(struct asd_ddb_ssp_smp_target_port, init_conn_tag)
562908d778SJames Bottomley #define DEST_SAS_ADDR   offsetof(struct asd_ddb_ssp_smp_target_port, dest_sas_addr)
572908d778SJames Bottomley #define SEND_QUEUE_HEAD offsetof(struct asd_ddb_ssp_smp_target_port, send_queue_head)
582908d778SJames Bottomley #define DDB_TYPE        offsetof(struct asd_ddb_ssp_smp_target_port, ddb_type)
592908d778SJames Bottomley #define CONN_MASK       offsetof(struct asd_ddb_ssp_smp_target_port, conn_mask)
602908d778SJames Bottomley #define DDB_TARG_FLAGS  offsetof(struct asd_ddb_ssp_smp_target_port, flags)
612908d778SJames Bottomley #define DDB_TARG_FLAGS2 offsetof(struct asd_ddb_stp_sata_target_port, flags2)
622908d778SJames Bottomley #define EXEC_QUEUE_TAIL offsetof(struct asd_ddb_ssp_smp_target_port, exec_queue_tail)
632908d778SJames Bottomley #define SEND_QUEUE_TAIL offsetof(struct asd_ddb_ssp_smp_target_port, send_queue_tail)
642908d778SJames Bottomley #define SISTER_DDB      offsetof(struct asd_ddb_ssp_smp_target_port, sister_ddb)
652908d778SJames Bottomley #define MAX_CCONN       offsetof(struct asd_ddb_ssp_smp_target_port, max_concurrent_conn)
662908d778SJames Bottomley #define NUM_CTX         offsetof(struct asd_ddb_ssp_smp_target_port, num_contexts)
672908d778SJames Bottomley #define ATA_CMD_SCBPTR  offsetof(struct asd_ddb_stp_sata_target_port, ata_cmd_scbptr)
682908d778SJames Bottomley #define SATA_TAG_ALLOC_MASK offsetof(struct asd_ddb_stp_sata_target_port, sata_tag_alloc_mask)
692908d778SJames Bottomley #define NUM_SATA_TAGS   offsetof(struct asd_ddb_stp_sata_target_port, num_sata_tags)
702908d778SJames Bottomley #define SATA_STATUS     offsetof(struct asd_ddb_stp_sata_target_port, sata_status)
712908d778SJames Bottomley #define NCQ_DATA_SCB_PTR offsetof(struct asd_ddb_stp_sata_target_port, ncq_data_scb_ptr)
722908d778SJames Bottomley #define ITNL_TIMEOUT    offsetof(struct asd_ddb_ssp_smp_target_port, itnl_timeout)
732908d778SJames Bottomley 
74*81e56dedSAdrian Bunk static void asd_free_ddb(struct asd_ha_struct *asd_ha, int ddb)
752908d778SJames Bottomley {
762908d778SJames Bottomley 	if (!ddb || ddb >= 0xFFFF)
772908d778SJames Bottomley 		return;
782908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, DDB_TYPE, DDB_TYPE_UNUSED);
792908d778SJames Bottomley 	CLEAR_DDB(ddb, asd_ha);
802908d778SJames Bottomley }
812908d778SJames Bottomley 
82*81e56dedSAdrian Bunk static void asd_set_ddb_type(struct domain_device *dev)
832908d778SJames Bottomley {
842908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
852908d778SJames Bottomley 	int ddb = (int) (unsigned long) dev->lldd_dev;
862908d778SJames Bottomley 
872908d778SJames Bottomley 	if (dev->dev_type == SATA_PM_PORT)
882908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha,ddb, DDB_TYPE, DDB_TYPE_PM_PORT);
892908d778SJames Bottomley 	else if (dev->tproto)
902908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha,ddb, DDB_TYPE, DDB_TYPE_TARGET);
912908d778SJames Bottomley 	else
922908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha,ddb,DDB_TYPE,DDB_TYPE_INITIATOR);
932908d778SJames Bottomley }
942908d778SJames Bottomley 
952908d778SJames Bottomley static int asd_init_sata_tag_ddb(struct domain_device *dev)
962908d778SJames Bottomley {
972908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
982908d778SJames Bottomley 	int ddb, i;
992908d778SJames Bottomley 
1002908d778SJames Bottomley 	ddb = asd_get_ddb(asd_ha);
1012908d778SJames Bottomley 	if (ddb < 0)
1022908d778SJames Bottomley 		return ddb;
1032908d778SJames Bottomley 
1042908d778SJames Bottomley 	for (i = 0; i < sizeof(struct asd_ddb_sata_tag); i += 2)
1052908d778SJames Bottomley 		asd_ddbsite_write_word(asd_ha, ddb, i, 0xFFFF);
1062908d778SJames Bottomley 
1072908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, (int) (unsigned long) dev->lldd_dev,
1082908d778SJames Bottomley 			       SISTER_DDB, ddb);
1092908d778SJames Bottomley 	return 0;
1102908d778SJames Bottomley }
1112908d778SJames Bottomley 
112*81e56dedSAdrian Bunk static int asd_init_sata(struct domain_device *dev)
1132908d778SJames Bottomley {
1142908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
1152908d778SJames Bottomley 	int ddb = (int) (unsigned long) dev->lldd_dev;
1162908d778SJames Bottomley 	u32 qdepth = 0;
1172908d778SJames Bottomley 	int res = 0;
1182908d778SJames Bottomley 
1192908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, ATA_CMD_SCBPTR, 0xFFFF);
1202908d778SJames Bottomley 	if ((dev->dev_type == SATA_DEV || dev->dev_type == SATA_PM_PORT) &&
1212908d778SJames Bottomley 	    dev->sata_dev.identify_device &&
1222908d778SJames Bottomley 	    dev->sata_dev.identify_device[10] != 0) {
1232908d778SJames Bottomley 		u16 w75 = le16_to_cpu(dev->sata_dev.identify_device[75]);
1242908d778SJames Bottomley 		u16 w76 = le16_to_cpu(dev->sata_dev.identify_device[76]);
1252908d778SJames Bottomley 
1262908d778SJames Bottomley 		if (w76 & 0x100) /* NCQ? */
1272908d778SJames Bottomley 			qdepth = (w75 & 0x1F) + 1;
1282908d778SJames Bottomley 		asd_ddbsite_write_dword(asd_ha, ddb, SATA_TAG_ALLOC_MASK,
129797f49deSDarrick J. Wong 					(1ULL<<qdepth)-1);
1302908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha, ddb, NUM_SATA_TAGS, qdepth);
1312908d778SJames Bottomley 	}
1322908d778SJames Bottomley 	if (dev->dev_type == SATA_DEV || dev->dev_type == SATA_PM ||
1332908d778SJames Bottomley 	    dev->dev_type == SATA_PM_PORT) {
1342908d778SJames Bottomley 		struct dev_to_host_fis *fis = (struct dev_to_host_fis *)
1352908d778SJames Bottomley 			dev->frame_rcvd;
1362908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha, ddb, SATA_STATUS, fis->status);
1372908d778SJames Bottomley 	}
1382908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, NCQ_DATA_SCB_PTR, 0xFFFF);
1392908d778SJames Bottomley 	if (qdepth > 0)
1402908d778SJames Bottomley 		res = asd_init_sata_tag_ddb(dev);
1412908d778SJames Bottomley 	return res;
1422908d778SJames Bottomley }
1432908d778SJames Bottomley 
1442908d778SJames Bottomley static int asd_init_target_ddb(struct domain_device *dev)
1452908d778SJames Bottomley {
1462908d778SJames Bottomley 	int ddb, i;
1472908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
1482908d778SJames Bottomley 	u8 flags = 0;
1492908d778SJames Bottomley 
1502908d778SJames Bottomley 	ddb = asd_get_ddb(asd_ha);
1512908d778SJames Bottomley 	if (ddb < 0)
1522908d778SJames Bottomley 		return ddb;
1532908d778SJames Bottomley 
1542908d778SJames Bottomley 	dev->lldd_dev = (void *) (unsigned long) ddb;
1552908d778SJames Bottomley 
1562908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, 0, DDB_TP_CONN_TYPE);
1572908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, 1, 0);
1582908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, INIT_CONN_TAG, 0xFFFF);
1592908d778SJames Bottomley 	for (i = 0; i < SAS_ADDR_SIZE; i++)
1602908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha, ddb, DEST_SAS_ADDR+i,
1612908d778SJames Bottomley 				       dev->sas_addr[i]);
1622908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, SEND_QUEUE_HEAD, 0xFFFF);
1632908d778SJames Bottomley 	asd_set_ddb_type(dev);
1642908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, CONN_MASK, dev->port->phy_mask);
1652908d778SJames Bottomley 	if (dev->port->oob_mode != SATA_OOB_MODE) {
1662908d778SJames Bottomley 		flags |= OPEN_REQUIRED;
1672908d778SJames Bottomley 		if ((dev->dev_type == SATA_DEV) ||
1685929faf3SDarrick J. Wong 		    (dev->tproto & SAS_PROTOCOL_STP)) {
1692908d778SJames Bottomley 			struct smp_resp *rps_resp = &dev->sata_dev.rps_resp;
1702908d778SJames Bottomley 			if (rps_resp->frame_type == SMP_RESPONSE &&
1712908d778SJames Bottomley 			    rps_resp->function == SMP_REPORT_PHY_SATA &&
1722908d778SJames Bottomley 			    rps_resp->result == SMP_RESP_FUNC_ACC) {
1732908d778SJames Bottomley 				if (rps_resp->rps.affil_valid)
1742908d778SJames Bottomley 					flags |= STP_AFFIL_POL;
1752908d778SJames Bottomley 				if (rps_resp->rps.affil_supp)
1762908d778SJames Bottomley 					flags |= SUPPORTS_AFFIL;
1772908d778SJames Bottomley 			}
1782908d778SJames Bottomley 		} else {
1792908d778SJames Bottomley 			flags |= CONCURRENT_CONN_SUPP;
1802908d778SJames Bottomley 			if (!dev->parent &&
1812908d778SJames Bottomley 			    (dev->dev_type == EDGE_DEV ||
1822908d778SJames Bottomley 			     dev->dev_type == FANOUT_DEV))
1832908d778SJames Bottomley 				asd_ddbsite_write_byte(asd_ha, ddb, MAX_CCONN,
1842908d778SJames Bottomley 						       4);
1852908d778SJames Bottomley 			else
1862908d778SJames Bottomley 				asd_ddbsite_write_byte(asd_ha, ddb, MAX_CCONN,
1872908d778SJames Bottomley 						       dev->pathways);
1882908d778SJames Bottomley 			asd_ddbsite_write_byte(asd_ha, ddb, NUM_CTX, 1);
1892908d778SJames Bottomley 		}
1902908d778SJames Bottomley 	}
1912908d778SJames Bottomley 	if (dev->dev_type == SATA_PM)
1922908d778SJames Bottomley 		flags |= SATA_MULTIPORT;
1932908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, DDB_TARG_FLAGS, flags);
1942908d778SJames Bottomley 
1952908d778SJames Bottomley 	flags = 0;
1965929faf3SDarrick J. Wong 	if (dev->tproto & SAS_PROTOCOL_STP)
1972908d778SJames Bottomley 		flags |= STP_CL_POL_NO_TX;
1982908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, DDB_TARG_FLAGS2, flags);
1992908d778SJames Bottomley 
2002908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, EXEC_QUEUE_TAIL, 0xFFFF);
2012908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, SEND_QUEUE_TAIL, 0xFFFF);
2022908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, SISTER_DDB, 0xFFFF);
2032908d778SJames Bottomley 
2045929faf3SDarrick J. Wong 	if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
2052908d778SJames Bottomley 		i = asd_init_sata(dev);
2062908d778SJames Bottomley 		if (i < 0) {
2072908d778SJames Bottomley 			asd_free_ddb(asd_ha, ddb);
2082908d778SJames Bottomley 			return i;
2092908d778SJames Bottomley 		}
2102908d778SJames Bottomley 	}
2112908d778SJames Bottomley 
2122908d778SJames Bottomley 	if (dev->dev_type == SAS_END_DEV) {
2132908d778SJames Bottomley 		struct sas_end_device *rdev = rphy_to_end_device(dev->rphy);
2142908d778SJames Bottomley 		if (rdev->I_T_nexus_loss_timeout > 0)
2152908d778SJames Bottomley 			asd_ddbsite_write_word(asd_ha, ddb, ITNL_TIMEOUT,
2162908d778SJames Bottomley 					       min(rdev->I_T_nexus_loss_timeout,
2172908d778SJames Bottomley 						   (u16)ITNL_TIMEOUT_CONST));
2182908d778SJames Bottomley 		else
2192908d778SJames Bottomley 			asd_ddbsite_write_word(asd_ha, ddb, ITNL_TIMEOUT,
2202908d778SJames Bottomley 					       (u16)ITNL_TIMEOUT_CONST);
2212908d778SJames Bottomley 	}
2222908d778SJames Bottomley 	return 0;
2232908d778SJames Bottomley }
2242908d778SJames Bottomley 
2252908d778SJames Bottomley static int asd_init_sata_pm_table_ddb(struct domain_device *dev)
2262908d778SJames Bottomley {
2272908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
2282908d778SJames Bottomley 	int ddb, i;
2292908d778SJames Bottomley 
2302908d778SJames Bottomley 	ddb = asd_get_ddb(asd_ha);
2312908d778SJames Bottomley 	if (ddb < 0)
2322908d778SJames Bottomley 		return ddb;
2332908d778SJames Bottomley 
2342908d778SJames Bottomley 	for (i = 0; i < 32; i += 2)
2352908d778SJames Bottomley 		asd_ddbsite_write_word(asd_ha, ddb, i, 0xFFFF);
2362908d778SJames Bottomley 
2372908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, (int) (unsigned long) dev->lldd_dev,
2382908d778SJames Bottomley 			       SISTER_DDB, ddb);
2392908d778SJames Bottomley 
2402908d778SJames Bottomley 	return 0;
2412908d778SJames Bottomley }
2422908d778SJames Bottomley 
2432908d778SJames Bottomley #define PM_PORT_FLAGS offsetof(struct asd_ddb_sata_pm_port, pm_port_flags)
2442908d778SJames Bottomley #define PARENT_DDB    offsetof(struct asd_ddb_sata_pm_port, parent_ddb)
2452908d778SJames Bottomley 
2462908d778SJames Bottomley /**
2472908d778SJames Bottomley  * asd_init_sata_pm_port_ddb -- SATA Port Multiplier Port
2482908d778SJames Bottomley  * dev: pointer to domain device
2492908d778SJames Bottomley  *
2502908d778SJames Bottomley  * For SATA Port Multiplier Ports we need to allocate one SATA Port
2512908d778SJames Bottomley  * Multiplier Port DDB and depending on whether the target on it
2522908d778SJames Bottomley  * supports SATA II NCQ, one SATA Tag DDB.
2532908d778SJames Bottomley  */
2542908d778SJames Bottomley static int asd_init_sata_pm_port_ddb(struct domain_device *dev)
2552908d778SJames Bottomley {
2562908d778SJames Bottomley 	int ddb, i, parent_ddb, pmtable_ddb;
2572908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
2582908d778SJames Bottomley 	u8  flags;
2592908d778SJames Bottomley 
2602908d778SJames Bottomley 	ddb = asd_get_ddb(asd_ha);
2612908d778SJames Bottomley 	if (ddb < 0)
2622908d778SJames Bottomley 		return ddb;
2632908d778SJames Bottomley 
2642908d778SJames Bottomley 	asd_set_ddb_type(dev);
2652908d778SJames Bottomley 	flags = (dev->sata_dev.port_no << 4) | PM_PORT_SET;
2662908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, PM_PORT_FLAGS, flags);
2672908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, SISTER_DDB, 0xFFFF);
2682908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, ATA_CMD_SCBPTR, 0xFFFF);
2692908d778SJames Bottomley 	asd_init_sata(dev);
2702908d778SJames Bottomley 
2712908d778SJames Bottomley 	parent_ddb = (int) (unsigned long) dev->parent->lldd_dev;
2722908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, PARENT_DDB, parent_ddb);
2732908d778SJames Bottomley 	pmtable_ddb = asd_ddbsite_read_word(asd_ha, parent_ddb, SISTER_DDB);
2742908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, pmtable_ddb, dev->sata_dev.port_no,ddb);
2752908d778SJames Bottomley 
2762908d778SJames Bottomley 	if (asd_ddbsite_read_byte(asd_ha, ddb, NUM_SATA_TAGS) > 0) {
2772908d778SJames Bottomley 		i = asd_init_sata_tag_ddb(dev);
2782908d778SJames Bottomley 		if (i < 0) {
2792908d778SJames Bottomley 			asd_free_ddb(asd_ha, ddb);
2802908d778SJames Bottomley 			return i;
2812908d778SJames Bottomley 		}
2822908d778SJames Bottomley 	}
2832908d778SJames Bottomley 	return 0;
2842908d778SJames Bottomley }
2852908d778SJames Bottomley 
2862908d778SJames Bottomley static int asd_init_initiator_ddb(struct domain_device *dev)
2872908d778SJames Bottomley {
2882908d778SJames Bottomley 	return -ENODEV;
2892908d778SJames Bottomley }
2902908d778SJames Bottomley 
2912908d778SJames Bottomley /**
2922908d778SJames Bottomley  * asd_init_sata_pm_ddb -- SATA Port Multiplier
2932908d778SJames Bottomley  * dev: pointer to domain device
2942908d778SJames Bottomley  *
2952908d778SJames Bottomley  * For STP and direct-attached SATA Port Multipliers we need
2962908d778SJames Bottomley  * one target port DDB entry and one SATA PM table DDB entry.
2972908d778SJames Bottomley  */
2982908d778SJames Bottomley static int asd_init_sata_pm_ddb(struct domain_device *dev)
2992908d778SJames Bottomley {
3002908d778SJames Bottomley 	int res = 0;
3012908d778SJames Bottomley 
3022908d778SJames Bottomley 	res = asd_init_target_ddb(dev);
3032908d778SJames Bottomley 	if (res)
3042908d778SJames Bottomley 		goto out;
3052908d778SJames Bottomley 	res = asd_init_sata_pm_table_ddb(dev);
3062908d778SJames Bottomley 	if (res)
3072908d778SJames Bottomley 		asd_free_ddb(dev->port->ha->lldd_ha,
3082908d778SJames Bottomley 			     (int) (unsigned long) dev->lldd_dev);
3092908d778SJames Bottomley out:
3102908d778SJames Bottomley 	return res;
3112908d778SJames Bottomley }
3122908d778SJames Bottomley 
3132908d778SJames Bottomley int asd_dev_found(struct domain_device *dev)
3142908d778SJames Bottomley {
31557ba07dcSDarrick J. Wong 	unsigned long flags;
3162908d778SJames Bottomley 	int res = 0;
31757ba07dcSDarrick J. Wong 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
3182908d778SJames Bottomley 
31957ba07dcSDarrick J. Wong 	spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
3202908d778SJames Bottomley 	switch (dev->dev_type) {
3212908d778SJames Bottomley 	case SATA_PM:
3222908d778SJames Bottomley 		res = asd_init_sata_pm_ddb(dev);
3232908d778SJames Bottomley 		break;
3242908d778SJames Bottomley 	case SATA_PM_PORT:
3252908d778SJames Bottomley 		res = asd_init_sata_pm_port_ddb(dev);
3262908d778SJames Bottomley 		break;
3272908d778SJames Bottomley 	default:
3282908d778SJames Bottomley 		if (dev->tproto)
3292908d778SJames Bottomley 			res = asd_init_target_ddb(dev);
3302908d778SJames Bottomley 		else
3312908d778SJames Bottomley 			res = asd_init_initiator_ddb(dev);
3322908d778SJames Bottomley 	}
33357ba07dcSDarrick J. Wong 	spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
33457ba07dcSDarrick J. Wong 
3352908d778SJames Bottomley 	return res;
3362908d778SJames Bottomley }
3372908d778SJames Bottomley 
3382908d778SJames Bottomley void asd_dev_gone(struct domain_device *dev)
3392908d778SJames Bottomley {
3402908d778SJames Bottomley 	int ddb, sister_ddb;
34157ba07dcSDarrick J. Wong 	unsigned long flags;
3422908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
3432908d778SJames Bottomley 
34457ba07dcSDarrick J. Wong 	spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
3452908d778SJames Bottomley 	ddb = (int) (unsigned long) dev->lldd_dev;
3462908d778SJames Bottomley 	sister_ddb = asd_ddbsite_read_word(asd_ha, ddb, SISTER_DDB);
3472908d778SJames Bottomley 
3482908d778SJames Bottomley 	if (sister_ddb != 0xFFFF)
3492908d778SJames Bottomley 		asd_free_ddb(asd_ha, sister_ddb);
3502908d778SJames Bottomley 	asd_free_ddb(asd_ha, ddb);
3512908d778SJames Bottomley 	dev->lldd_dev = NULL;
35257ba07dcSDarrick J. Wong 	spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
3532908d778SJames Bottomley }
354