xref: /linux/drivers/scsi/aic94xx/aic94xx_dev.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
165c85c83SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
22908d778SJames Bottomley /*
32908d778SJames Bottomley  * Aic94xx SAS/SATA DDB management
42908d778SJames Bottomley  *
52908d778SJames Bottomley  * Copyright (C) 2005 Adaptec, Inc.  All rights reserved.
62908d778SJames Bottomley  * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
72908d778SJames Bottomley  *
82908d778SJames Bottomley  * $Id: //depot/aic94xx/aic94xx_dev.c#21 $
92908d778SJames Bottomley  */
102908d778SJames Bottomley 
112908d778SJames Bottomley #include "aic94xx.h"
122908d778SJames Bottomley #include "aic94xx_hwi.h"
132908d778SJames Bottomley #include "aic94xx_reg.h"
142908d778SJames Bottomley #include "aic94xx_sas.h"
152908d778SJames Bottomley 
162908d778SJames Bottomley #define FIND_FREE_DDB(_ha) find_first_zero_bit((_ha)->hw_prof.ddb_bitmap, \
172908d778SJames Bottomley 					       (_ha)->hw_prof.max_ddbs)
182908d778SJames Bottomley #define SET_DDB(_ddb, _ha) set_bit(_ddb, (_ha)->hw_prof.ddb_bitmap)
192908d778SJames Bottomley #define CLEAR_DDB(_ddb, _ha) clear_bit(_ddb, (_ha)->hw_prof.ddb_bitmap)
202908d778SJames Bottomley 
asd_get_ddb(struct asd_ha_struct * asd_ha)2181e56dedSAdrian Bunk static int asd_get_ddb(struct asd_ha_struct *asd_ha)
222908d778SJames Bottomley {
232908d778SJames Bottomley 	int ddb, i;
242908d778SJames Bottomley 
252908d778SJames Bottomley 	ddb = FIND_FREE_DDB(asd_ha);
262908d778SJames Bottomley 	if (ddb >= asd_ha->hw_prof.max_ddbs) {
272908d778SJames Bottomley 		ddb = -ENOMEM;
282908d778SJames Bottomley 		goto out;
292908d778SJames Bottomley 	}
302908d778SJames Bottomley 	SET_DDB(ddb, asd_ha);
312908d778SJames Bottomley 
322908d778SJames Bottomley 	for (i = 0; i < sizeof(struct asd_ddb_ssp_smp_target_port); i+= 4)
332908d778SJames Bottomley 		asd_ddbsite_write_dword(asd_ha, ddb, i, 0);
342908d778SJames Bottomley out:
352908d778SJames Bottomley 	return ddb;
362908d778SJames Bottomley }
372908d778SJames Bottomley 
382908d778SJames Bottomley #define INIT_CONN_TAG   offsetof(struct asd_ddb_ssp_smp_target_port, init_conn_tag)
392908d778SJames Bottomley #define DEST_SAS_ADDR   offsetof(struct asd_ddb_ssp_smp_target_port, dest_sas_addr)
402908d778SJames Bottomley #define SEND_QUEUE_HEAD offsetof(struct asd_ddb_ssp_smp_target_port, send_queue_head)
412908d778SJames Bottomley #define DDB_TYPE        offsetof(struct asd_ddb_ssp_smp_target_port, ddb_type)
422908d778SJames Bottomley #define CONN_MASK       offsetof(struct asd_ddb_ssp_smp_target_port, conn_mask)
432908d778SJames Bottomley #define DDB_TARG_FLAGS  offsetof(struct asd_ddb_ssp_smp_target_port, flags)
442908d778SJames Bottomley #define DDB_TARG_FLAGS2 offsetof(struct asd_ddb_stp_sata_target_port, flags2)
452908d778SJames Bottomley #define EXEC_QUEUE_TAIL offsetof(struct asd_ddb_ssp_smp_target_port, exec_queue_tail)
462908d778SJames Bottomley #define SEND_QUEUE_TAIL offsetof(struct asd_ddb_ssp_smp_target_port, send_queue_tail)
472908d778SJames Bottomley #define SISTER_DDB      offsetof(struct asd_ddb_ssp_smp_target_port, sister_ddb)
482908d778SJames Bottomley #define MAX_CCONN       offsetof(struct asd_ddb_ssp_smp_target_port, max_concurrent_conn)
492908d778SJames Bottomley #define NUM_CTX         offsetof(struct asd_ddb_ssp_smp_target_port, num_contexts)
502908d778SJames Bottomley #define ATA_CMD_SCBPTR  offsetof(struct asd_ddb_stp_sata_target_port, ata_cmd_scbptr)
512908d778SJames Bottomley #define SATA_TAG_ALLOC_MASK offsetof(struct asd_ddb_stp_sata_target_port, sata_tag_alloc_mask)
522908d778SJames Bottomley #define NUM_SATA_TAGS   offsetof(struct asd_ddb_stp_sata_target_port, num_sata_tags)
532908d778SJames Bottomley #define SATA_STATUS     offsetof(struct asd_ddb_stp_sata_target_port, sata_status)
542908d778SJames Bottomley #define NCQ_DATA_SCB_PTR offsetof(struct asd_ddb_stp_sata_target_port, ncq_data_scb_ptr)
552908d778SJames Bottomley #define ITNL_TIMEOUT    offsetof(struct asd_ddb_ssp_smp_target_port, itnl_timeout)
562908d778SJames Bottomley 
asd_free_ddb(struct asd_ha_struct * asd_ha,int ddb)5781e56dedSAdrian Bunk static void asd_free_ddb(struct asd_ha_struct *asd_ha, int ddb)
582908d778SJames Bottomley {
592908d778SJames Bottomley 	if (!ddb || ddb >= 0xFFFF)
602908d778SJames Bottomley 		return;
612908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, DDB_TYPE, DDB_TYPE_UNUSED);
622908d778SJames Bottomley 	CLEAR_DDB(ddb, asd_ha);
632908d778SJames Bottomley }
642908d778SJames Bottomley 
asd_set_ddb_type(struct domain_device * dev)6581e56dedSAdrian Bunk static void asd_set_ddb_type(struct domain_device *dev)
662908d778SJames Bottomley {
672908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
682908d778SJames Bottomley 	int ddb = (int) (unsigned long) dev->lldd_dev;
692908d778SJames Bottomley 
70aa9f8328SJames Bottomley 	if (dev->dev_type == SAS_SATA_PM_PORT)
712908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha,ddb, DDB_TYPE, DDB_TYPE_PM_PORT);
722908d778SJames Bottomley 	else if (dev->tproto)
732908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha,ddb, DDB_TYPE, DDB_TYPE_TARGET);
742908d778SJames Bottomley 	else
752908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha,ddb,DDB_TYPE,DDB_TYPE_INITIATOR);
762908d778SJames Bottomley }
772908d778SJames Bottomley 
asd_init_sata_tag_ddb(struct domain_device * dev)782908d778SJames Bottomley static int asd_init_sata_tag_ddb(struct domain_device *dev)
792908d778SJames Bottomley {
802908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
812908d778SJames Bottomley 	int ddb, i;
822908d778SJames Bottomley 
832908d778SJames Bottomley 	ddb = asd_get_ddb(asd_ha);
842908d778SJames Bottomley 	if (ddb < 0)
852908d778SJames Bottomley 		return ddb;
862908d778SJames Bottomley 
872908d778SJames Bottomley 	for (i = 0; i < sizeof(struct asd_ddb_sata_tag); i += 2)
882908d778SJames Bottomley 		asd_ddbsite_write_word(asd_ha, ddb, i, 0xFFFF);
892908d778SJames Bottomley 
902908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, (int) (unsigned long) dev->lldd_dev,
912908d778SJames Bottomley 			       SISTER_DDB, ddb);
922908d778SJames Bottomley 	return 0;
932908d778SJames Bottomley }
942908d778SJames Bottomley 
asd_set_dmamode(struct domain_device * dev)95b91bb296SDan Williams void asd_set_dmamode(struct domain_device *dev)
962908d778SJames Bottomley {
972908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
98b91bb296SDan Williams 	struct ata_device *ata_dev = sas_to_ata_dev(dev);
992908d778SJames Bottomley 	int ddb = (int) (unsigned long) dev->lldd_dev;
1002908d778SJames Bottomley 	u32 qdepth = 0;
1012908d778SJames Bottomley 
102aa9f8328SJames Bottomley 	if (dev->dev_type == SAS_SATA_DEV || dev->dev_type == SAS_SATA_PM_PORT) {
103b91bb296SDan Williams 		if (ata_id_has_ncq(ata_dev->id))
104b91bb296SDan Williams 			qdepth = ata_id_queue_depth(ata_dev->id);
1052908d778SJames Bottomley 		asd_ddbsite_write_dword(asd_ha, ddb, SATA_TAG_ALLOC_MASK,
106797f49deSDarrick J. Wong 					(1ULL<<qdepth)-1);
1072908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha, ddb, NUM_SATA_TAGS, qdepth);
1082908d778SJames Bottomley 	}
109b91bb296SDan Williams 
110b91bb296SDan Williams 	if (qdepth > 0)
111b91bb296SDan Williams 		if (asd_init_sata_tag_ddb(dev) != 0) {
112b91bb296SDan Williams 			unsigned long flags;
113b91bb296SDan Williams 
114b91bb296SDan Williams 			spin_lock_irqsave(dev->sata_dev.ap->lock, flags);
115b91bb296SDan Williams 			ata_dev->flags |= ATA_DFLAG_NCQ_OFF;
116b91bb296SDan Williams 			spin_unlock_irqrestore(dev->sata_dev.ap->lock, flags);
117b91bb296SDan Williams 		}
118b91bb296SDan Williams }
119b91bb296SDan Williams 
asd_init_sata(struct domain_device * dev)120b91bb296SDan Williams static int asd_init_sata(struct domain_device *dev)
121b91bb296SDan Williams {
122b91bb296SDan Williams 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
123b91bb296SDan Williams 	int ddb = (int) (unsigned long) dev->lldd_dev;
124b91bb296SDan Williams 
125b91bb296SDan Williams 	asd_ddbsite_write_word(asd_ha, ddb, ATA_CMD_SCBPTR, 0xFFFF);
126aa9f8328SJames Bottomley 	if (dev->dev_type == SAS_SATA_DEV || dev->dev_type == SAS_SATA_PM ||
127aa9f8328SJames Bottomley 	    dev->dev_type == SAS_SATA_PM_PORT) {
1282908d778SJames Bottomley 		struct dev_to_host_fis *fis = (struct dev_to_host_fis *)
1292908d778SJames Bottomley 			dev->frame_rcvd;
1302908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha, ddb, SATA_STATUS, fis->status);
1312908d778SJames Bottomley 	}
1322908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, NCQ_DATA_SCB_PTR, 0xFFFF);
133b91bb296SDan Williams 
134b91bb296SDan Williams 	return 0;
1352908d778SJames Bottomley }
1362908d778SJames Bottomley 
asd_init_target_ddb(struct domain_device * dev)1372908d778SJames Bottomley static int asd_init_target_ddb(struct domain_device *dev)
1382908d778SJames Bottomley {
1392908d778SJames Bottomley 	int ddb, i;
1402908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
1412908d778SJames Bottomley 	u8 flags = 0;
1422908d778SJames Bottomley 
1432908d778SJames Bottomley 	ddb = asd_get_ddb(asd_ha);
1442908d778SJames Bottomley 	if (ddb < 0)
1452908d778SJames Bottomley 		return ddb;
1462908d778SJames Bottomley 
1472908d778SJames Bottomley 	dev->lldd_dev = (void *) (unsigned long) ddb;
1482908d778SJames Bottomley 
1492908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, 0, DDB_TP_CONN_TYPE);
1502908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, 1, 0);
1512908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, INIT_CONN_TAG, 0xFFFF);
1522908d778SJames Bottomley 	for (i = 0; i < SAS_ADDR_SIZE; i++)
1532908d778SJames Bottomley 		asd_ddbsite_write_byte(asd_ha, ddb, DEST_SAS_ADDR+i,
1542908d778SJames Bottomley 				       dev->sas_addr[i]);
1552908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, SEND_QUEUE_HEAD, 0xFFFF);
1562908d778SJames Bottomley 	asd_set_ddb_type(dev);
1572908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, CONN_MASK, dev->port->phy_mask);
1582908d778SJames Bottomley 	if (dev->port->oob_mode != SATA_OOB_MODE) {
1592908d778SJames Bottomley 		flags |= OPEN_REQUIRED;
160aa9f8328SJames Bottomley 		if ((dev->dev_type == SAS_SATA_DEV) ||
1615929faf3SDarrick J. Wong 		    (dev->tproto & SAS_PROTOCOL_STP)) {
162*3dafe064SDamien Le Moal 			struct smp_rps_resp *rps_resp = &dev->sata_dev.rps_resp;
1632908d778SJames Bottomley 			if (rps_resp->frame_type == SMP_RESPONSE &&
1642908d778SJames Bottomley 			    rps_resp->function == SMP_REPORT_PHY_SATA &&
1652908d778SJames Bottomley 			    rps_resp->result == SMP_RESP_FUNC_ACC) {
1662908d778SJames Bottomley 				if (rps_resp->rps.affil_valid)
1672908d778SJames Bottomley 					flags |= STP_AFFIL_POL;
1682908d778SJames Bottomley 				if (rps_resp->rps.affil_supp)
1692908d778SJames Bottomley 					flags |= SUPPORTS_AFFIL;
1702908d778SJames Bottomley 			}
1712908d778SJames Bottomley 		} else {
1722908d778SJames Bottomley 			flags |= CONCURRENT_CONN_SUPP;
173924a3541SJohn Garry 			if (!dev->parent && dev_is_expander(dev->dev_type))
1742908d778SJames Bottomley 				asd_ddbsite_write_byte(asd_ha, ddb, MAX_CCONN,
1752908d778SJames Bottomley 						       4);
1762908d778SJames Bottomley 			else
1772908d778SJames Bottomley 				asd_ddbsite_write_byte(asd_ha, ddb, MAX_CCONN,
1782908d778SJames Bottomley 						       dev->pathways);
1792908d778SJames Bottomley 			asd_ddbsite_write_byte(asd_ha, ddb, NUM_CTX, 1);
1802908d778SJames Bottomley 		}
1812908d778SJames Bottomley 	}
182aa9f8328SJames Bottomley 	if (dev->dev_type == SAS_SATA_PM)
1832908d778SJames Bottomley 		flags |= SATA_MULTIPORT;
1842908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, DDB_TARG_FLAGS, flags);
1852908d778SJames Bottomley 
1862908d778SJames Bottomley 	flags = 0;
1875929faf3SDarrick J. Wong 	if (dev->tproto & SAS_PROTOCOL_STP)
1882908d778SJames Bottomley 		flags |= STP_CL_POL_NO_TX;
1892908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, DDB_TARG_FLAGS2, flags);
1902908d778SJames Bottomley 
1912908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, EXEC_QUEUE_TAIL, 0xFFFF);
1922908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, SEND_QUEUE_TAIL, 0xFFFF);
1932908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, SISTER_DDB, 0xFFFF);
1942908d778SJames Bottomley 
195aa9f8328SJames Bottomley 	if (dev->dev_type == SAS_SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
1962908d778SJames Bottomley 		i = asd_init_sata(dev);
1972908d778SJames Bottomley 		if (i < 0) {
1982908d778SJames Bottomley 			asd_free_ddb(asd_ha, ddb);
1992908d778SJames Bottomley 			return i;
2002908d778SJames Bottomley 		}
2012908d778SJames Bottomley 	}
2022908d778SJames Bottomley 
203aa9f8328SJames Bottomley 	if (dev->dev_type == SAS_END_DEVICE) {
2042908d778SJames Bottomley 		struct sas_end_device *rdev = rphy_to_end_device(dev->rphy);
2052908d778SJames Bottomley 		if (rdev->I_T_nexus_loss_timeout > 0)
2062908d778SJames Bottomley 			asd_ddbsite_write_word(asd_ha, ddb, ITNL_TIMEOUT,
2072908d778SJames Bottomley 					       min(rdev->I_T_nexus_loss_timeout,
2082908d778SJames Bottomley 						   (u16)ITNL_TIMEOUT_CONST));
2092908d778SJames Bottomley 		else
2102908d778SJames Bottomley 			asd_ddbsite_write_word(asd_ha, ddb, ITNL_TIMEOUT,
2112908d778SJames Bottomley 					       (u16)ITNL_TIMEOUT_CONST);
2122908d778SJames Bottomley 	}
2132908d778SJames Bottomley 	return 0;
2142908d778SJames Bottomley }
2152908d778SJames Bottomley 
asd_init_sata_pm_table_ddb(struct domain_device * dev)2162908d778SJames Bottomley static int asd_init_sata_pm_table_ddb(struct domain_device *dev)
2172908d778SJames Bottomley {
2182908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
2192908d778SJames Bottomley 	int ddb, i;
2202908d778SJames Bottomley 
2212908d778SJames Bottomley 	ddb = asd_get_ddb(asd_ha);
2222908d778SJames Bottomley 	if (ddb < 0)
2232908d778SJames Bottomley 		return ddb;
2242908d778SJames Bottomley 
2252908d778SJames Bottomley 	for (i = 0; i < 32; i += 2)
2262908d778SJames Bottomley 		asd_ddbsite_write_word(asd_ha, ddb, i, 0xFFFF);
2272908d778SJames Bottomley 
2282908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, (int) (unsigned long) dev->lldd_dev,
2292908d778SJames Bottomley 			       SISTER_DDB, ddb);
2302908d778SJames Bottomley 
2312908d778SJames Bottomley 	return 0;
2322908d778SJames Bottomley }
2332908d778SJames Bottomley 
2342908d778SJames Bottomley #define PM_PORT_FLAGS offsetof(struct asd_ddb_sata_pm_port, pm_port_flags)
2352908d778SJames Bottomley #define PARENT_DDB    offsetof(struct asd_ddb_sata_pm_port, parent_ddb)
2362908d778SJames Bottomley 
2372908d778SJames Bottomley /**
2382908d778SJames Bottomley  * asd_init_sata_pm_port_ddb -- SATA Port Multiplier Port
239ee37a6e6SLee Jones  * @dev: pointer to domain device
2402908d778SJames Bottomley  *
2412908d778SJames Bottomley  * For SATA Port Multiplier Ports we need to allocate one SATA Port
2422908d778SJames Bottomley  * Multiplier Port DDB and depending on whether the target on it
2432908d778SJames Bottomley  * supports SATA II NCQ, one SATA Tag DDB.
2442908d778SJames Bottomley  */
asd_init_sata_pm_port_ddb(struct domain_device * dev)2452908d778SJames Bottomley static int asd_init_sata_pm_port_ddb(struct domain_device *dev)
2462908d778SJames Bottomley {
2472908d778SJames Bottomley 	int ddb, i, parent_ddb, pmtable_ddb;
2482908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
2492908d778SJames Bottomley 	u8  flags;
2502908d778SJames Bottomley 
2512908d778SJames Bottomley 	ddb = asd_get_ddb(asd_ha);
2522908d778SJames Bottomley 	if (ddb < 0)
2532908d778SJames Bottomley 		return ddb;
2542908d778SJames Bottomley 
2552908d778SJames Bottomley 	asd_set_ddb_type(dev);
2562908d778SJames Bottomley 	flags = (dev->sata_dev.port_no << 4) | PM_PORT_SET;
2572908d778SJames Bottomley 	asd_ddbsite_write_byte(asd_ha, ddb, PM_PORT_FLAGS, flags);
2582908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, SISTER_DDB, 0xFFFF);
2592908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, ATA_CMD_SCBPTR, 0xFFFF);
2602908d778SJames Bottomley 	asd_init_sata(dev);
2612908d778SJames Bottomley 
2622908d778SJames Bottomley 	parent_ddb = (int) (unsigned long) dev->parent->lldd_dev;
2632908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, ddb, PARENT_DDB, parent_ddb);
2642908d778SJames Bottomley 	pmtable_ddb = asd_ddbsite_read_word(asd_ha, parent_ddb, SISTER_DDB);
2652908d778SJames Bottomley 	asd_ddbsite_write_word(asd_ha, pmtable_ddb, dev->sata_dev.port_no,ddb);
2662908d778SJames Bottomley 
2672908d778SJames Bottomley 	if (asd_ddbsite_read_byte(asd_ha, ddb, NUM_SATA_TAGS) > 0) {
2682908d778SJames Bottomley 		i = asd_init_sata_tag_ddb(dev);
2692908d778SJames Bottomley 		if (i < 0) {
2702908d778SJames Bottomley 			asd_free_ddb(asd_ha, ddb);
2712908d778SJames Bottomley 			return i;
2722908d778SJames Bottomley 		}
2732908d778SJames Bottomley 	}
2742908d778SJames Bottomley 	return 0;
2752908d778SJames Bottomley }
2762908d778SJames Bottomley 
asd_init_initiator_ddb(struct domain_device * dev)2772908d778SJames Bottomley static int asd_init_initiator_ddb(struct domain_device *dev)
2782908d778SJames Bottomley {
2792908d778SJames Bottomley 	return -ENODEV;
2802908d778SJames Bottomley }
2812908d778SJames Bottomley 
2822908d778SJames Bottomley /**
2832908d778SJames Bottomley  * asd_init_sata_pm_ddb -- SATA Port Multiplier
284ee37a6e6SLee Jones  * @dev: pointer to domain device
2852908d778SJames Bottomley  *
2862908d778SJames Bottomley  * For STP and direct-attached SATA Port Multipliers we need
2872908d778SJames Bottomley  * one target port DDB entry and one SATA PM table DDB entry.
2882908d778SJames Bottomley  */
asd_init_sata_pm_ddb(struct domain_device * dev)2892908d778SJames Bottomley static int asd_init_sata_pm_ddb(struct domain_device *dev)
2902908d778SJames Bottomley {
2912908d778SJames Bottomley 	int res = 0;
2922908d778SJames Bottomley 
2932908d778SJames Bottomley 	res = asd_init_target_ddb(dev);
2942908d778SJames Bottomley 	if (res)
2952908d778SJames Bottomley 		goto out;
2962908d778SJames Bottomley 	res = asd_init_sata_pm_table_ddb(dev);
2972908d778SJames Bottomley 	if (res)
2982908d778SJames Bottomley 		asd_free_ddb(dev->port->ha->lldd_ha,
2992908d778SJames Bottomley 			     (int) (unsigned long) dev->lldd_dev);
3002908d778SJames Bottomley out:
3012908d778SJames Bottomley 	return res;
3022908d778SJames Bottomley }
3032908d778SJames Bottomley 
asd_dev_found(struct domain_device * dev)3042908d778SJames Bottomley int asd_dev_found(struct domain_device *dev)
3052908d778SJames Bottomley {
30657ba07dcSDarrick J. Wong 	unsigned long flags;
3072908d778SJames Bottomley 	int res = 0;
30857ba07dcSDarrick J. Wong 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
3092908d778SJames Bottomley 
31057ba07dcSDarrick J. Wong 	spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
3112908d778SJames Bottomley 	switch (dev->dev_type) {
312aa9f8328SJames Bottomley 	case SAS_SATA_PM:
3132908d778SJames Bottomley 		res = asd_init_sata_pm_ddb(dev);
3142908d778SJames Bottomley 		break;
315aa9f8328SJames Bottomley 	case SAS_SATA_PM_PORT:
3162908d778SJames Bottomley 		res = asd_init_sata_pm_port_ddb(dev);
3172908d778SJames Bottomley 		break;
3182908d778SJames Bottomley 	default:
3192908d778SJames Bottomley 		if (dev->tproto)
3202908d778SJames Bottomley 			res = asd_init_target_ddb(dev);
3212908d778SJames Bottomley 		else
3222908d778SJames Bottomley 			res = asd_init_initiator_ddb(dev);
3232908d778SJames Bottomley 	}
32457ba07dcSDarrick J. Wong 	spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
32557ba07dcSDarrick J. Wong 
3262908d778SJames Bottomley 	return res;
3272908d778SJames Bottomley }
3282908d778SJames Bottomley 
asd_dev_gone(struct domain_device * dev)3292908d778SJames Bottomley void asd_dev_gone(struct domain_device *dev)
3302908d778SJames Bottomley {
3312908d778SJames Bottomley 	int ddb, sister_ddb;
33257ba07dcSDarrick J. Wong 	unsigned long flags;
3332908d778SJames Bottomley 	struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
3342908d778SJames Bottomley 
33557ba07dcSDarrick J. Wong 	spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
3362908d778SJames Bottomley 	ddb = (int) (unsigned long) dev->lldd_dev;
3372908d778SJames Bottomley 	sister_ddb = asd_ddbsite_read_word(asd_ha, ddb, SISTER_DDB);
3382908d778SJames Bottomley 
3392908d778SJames Bottomley 	if (sister_ddb != 0xFFFF)
3402908d778SJames Bottomley 		asd_free_ddb(asd_ha, sister_ddb);
3412908d778SJames Bottomley 	asd_free_ddb(asd_ha, ddb);
3422908d778SJames Bottomley 	dev->lldd_dev = NULL;
34357ba07dcSDarrick J. Wong 	spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
3442908d778SJames Bottomley }
345