Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Serial Attached SCSI (SAS) Transport Layer initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2005 Adaptec, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <scsi/sas_ata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <scsi/scsi_transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <scsi/scsi_transport_sas.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "sas_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "../scsi_sas_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static struct kmem_cache *sas_task_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static struct kmem_cache *sas_event_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) struct sas_task *sas_alloc_task(gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		spin_lock_init(&task->task_state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		task->task_state_flags = SAS_TASK_STATE_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	return task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) EXPORT_SYMBOL_GPL(sas_alloc_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) struct sas_task *sas_alloc_slow_task(gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct sas_task *task = sas_alloc_task(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct sas_task_slow *slow = kmalloc(sizeof(*slow), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (!task || !slow) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		if (task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			kmem_cache_free(sas_task_cache, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		kfree(slow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	task->slow_task = slow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	slow->task = task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	timer_setup(&slow->timer, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	init_completion(&slow->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) EXPORT_SYMBOL_GPL(sas_alloc_slow_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) void sas_free_task(struct sas_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		kfree(task->slow_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		kmem_cache_free(sas_task_cache, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) EXPORT_SYMBOL_GPL(sas_free_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /*------------ SAS addr hash -----------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) void sas_hash_addr(u8 *hashed, const u8 *sas_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	const u32 poly = 0x00DB2777;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	u32 r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	for (i = 0; i < SAS_ADDR_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		int b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		for (b = (SAS_ADDR_SIZE - 1); b >= 0; b--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			r <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			if ((1 << b) & sas_addr[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				if (!(r & 0x01000000))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 					r ^= poly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			} else if (r & 0x01000000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 				r ^= poly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	hashed[0] = (r >> 16) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	hashed[1] = (r >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	hashed[2] = r & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) int sas_register_ha(struct sas_ha_struct *sas_ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	char name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	mutex_init(&sas_ha->disco_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	spin_lock_init(&sas_ha->phy_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	sas_hash_addr(sas_ha->hashed_sas_addr, sas_ha->sas_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	set_bit(SAS_HA_REGISTERED, &sas_ha->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	spin_lock_init(&sas_ha->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	mutex_init(&sas_ha->drain_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	init_waitqueue_head(&sas_ha->eh_wait_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	INIT_LIST_HEAD(&sas_ha->defer_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	INIT_LIST_HEAD(&sas_ha->eh_dev_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	sas_ha->event_thres = SAS_PHY_SHUTDOWN_THRES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	error = sas_register_phys(sas_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		pr_notice("couldn't register sas phys:%d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	error = sas_register_ports(sas_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		pr_notice("couldn't register sas ports:%d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		goto Undo_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	snprintf(name, sizeof(name), "%s_event_q", dev_name(sas_ha->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	sas_ha->event_q = create_singlethread_workqueue(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (!sas_ha->event_q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		goto Undo_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	snprintf(name, sizeof(name), "%s_disco_q", dev_name(sas_ha->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	sas_ha->disco_q = create_singlethread_workqueue(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (!sas_ha->disco_q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		goto Undo_event_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	INIT_LIST_HEAD(&sas_ha->eh_done_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	INIT_LIST_HEAD(&sas_ha->eh_ata_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) Undo_event_q:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	destroy_workqueue(sas_ha->event_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) Undo_ports:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	sas_unregister_ports(sas_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) Undo_phys:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static void sas_disable_events(struct sas_ha_struct *sas_ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* Set the state to unregistered to avoid further unchained
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 * events to be queued, and flush any in-progress drainers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	mutex_lock(&sas_ha->drain_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	spin_lock_irq(&sas_ha->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	clear_bit(SAS_HA_REGISTERED, &sas_ha->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	spin_unlock_irq(&sas_ha->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	__sas_drain_work(sas_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	mutex_unlock(&sas_ha->drain_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int sas_unregister_ha(struct sas_ha_struct *sas_ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	sas_disable_events(sas_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	sas_unregister_ports(sas_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* flush unregistration work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	mutex_lock(&sas_ha->drain_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	__sas_drain_work(sas_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	mutex_unlock(&sas_ha->drain_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	destroy_workqueue(sas_ha->disco_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	destroy_workqueue(sas_ha->event_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int sas_get_linkerrors(struct sas_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (scsi_is_sas_phy_local(phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		struct sas_internal *i =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			to_sas_internal(sas_ha->core.shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return i->dft->lldd_control_phy(asd_phy, PHY_FUNC_GET_EVENTS, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	return sas_smp_get_phy_events(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int sas_try_ata_reset(struct asd_sas_phy *asd_phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	struct domain_device *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	/* try to route user requested link resets through libata */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (asd_phy->port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		dev = asd_phy->port->port_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	/* validate that dev has been probed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		dev = sas_find_dev_by_rphy(dev->rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (dev && dev_is_sata(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		sas_ata_schedule_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		sas_ata_wait_eh(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * transport_sas_phy_reset - reset a phy and permit libata to manage the link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * phy reset request via sysfs in host workqueue context so we know we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * can block on eh and safely traverse the domain_device topology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static int transport_sas_phy_reset(struct sas_phy *phy, int hard_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	enum phy_func reset_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (hard_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		reset_type = PHY_FUNC_HARD_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		reset_type = PHY_FUNC_LINK_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (scsi_is_sas_phy_local(phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		struct sas_internal *i =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			to_sas_internal(sas_ha->core.shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		if (!hard_reset && sas_try_ata_reset(asd_phy) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		return i->dft->lldd_control_phy(asd_phy, reset_type, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		struct domain_device *ddev = sas_find_dev_by_rphy(rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		struct domain_device *ata_dev = sas_ex_to_ata(ddev, phy->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		if (ata_dev && !hard_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			sas_ata_schedule_reset(ata_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			sas_ata_wait_eh(ata_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			return sas_smp_phy_control(ddev, phy->number, reset_type, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int sas_phy_enable(struct sas_phy *phy, int enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	enum phy_func cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		cmd = PHY_FUNC_LINK_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		cmd = PHY_FUNC_DISABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (scsi_is_sas_phy_local(phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		struct sas_internal *i =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			to_sas_internal(sas_ha->core.shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			ret = transport_sas_phy_reset(phy, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			ret = i->dft->lldd_control_phy(asd_phy, cmd, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		struct domain_device *ddev = sas_find_dev_by_rphy(rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			ret = transport_sas_phy_reset(phy, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			ret = sas_smp_phy_control(ddev, phy->number, cmd, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int sas_phy_reset(struct sas_phy *phy, int hard_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	enum phy_func reset_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (!phy->enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (hard_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		reset_type = PHY_FUNC_HARD_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		reset_type = PHY_FUNC_LINK_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (scsi_is_sas_phy_local(phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		struct sas_internal *i =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			to_sas_internal(sas_ha->core.shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		ret = i->dft->lldd_control_phy(asd_phy, reset_type, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		struct domain_device *ddev = sas_find_dev_by_rphy(rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		ret = sas_smp_phy_control(ddev, phy->number, reset_type, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int sas_set_phy_speed(struct sas_phy *phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		      struct sas_phy_linkrates *rates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if ((rates->minimum_linkrate &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	     rates->minimum_linkrate > phy->maximum_linkrate) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	    (rates->maximum_linkrate &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	     rates->maximum_linkrate < phy->minimum_linkrate))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (rates->minimum_linkrate &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	    rates->minimum_linkrate < phy->minimum_linkrate_hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		rates->minimum_linkrate = phy->minimum_linkrate_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (rates->maximum_linkrate &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	    rates->maximum_linkrate > phy->maximum_linkrate_hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		rates->maximum_linkrate = phy->maximum_linkrate_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (scsi_is_sas_phy_local(phy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		struct sas_internal *i =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			to_sas_internal(sas_ha->core.shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		ret = i->dft->lldd_control_phy(asd_phy, PHY_FUNC_SET_LINK_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 					       rates);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		struct domain_device *ddev = sas_find_dev_by_rphy(rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		ret = sas_smp_phy_control(ddev, phy->number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 					  PHY_FUNC_LINK_RESET, rates);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) void sas_prep_resume_ha(struct sas_ha_struct *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	set_bit(SAS_HA_REGISTERED, &ha->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	/* clear out any stale link events/data from the suspension path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	for (i = 0; i < ha->num_phys; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		struct asd_sas_phy *phy = ha->sas_phy[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		phy->frame_rcvd_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) EXPORT_SYMBOL(sas_prep_resume_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) static int phys_suspended(struct sas_ha_struct *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	int i, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	for (i = 0; i < ha->num_phys; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		struct asd_sas_phy *phy = ha->sas_phy[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		if (phy->suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 			rc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) void sas_resume_ha(struct sas_ha_struct *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	const unsigned long tmo = msecs_to_jiffies(25000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	/* deform ports on phys that did not resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	 * at this point we may be racing the phy coming back (as posted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	 * by the lldd).  So we post the event and once we are in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	 * libsas context check that the phy remains suspended before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	 * tearing it down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	i = phys_suspended(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		dev_info(ha->dev, "waiting up to 25 seconds for %d phy%s to resume\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			 i, i > 1 ? "s" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	wait_event_timeout(ha->eh_wait_q, phys_suspended(ha) == 0, tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	for (i = 0; i < ha->num_phys; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		struct asd_sas_phy *phy = ha->sas_phy[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		if (phy->suspended) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			dev_warn(&phy->phy->dev, "resume timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			sas_notify_phy_event(phy, PHYE_RESUME_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	/* all phys are back up or timed out, turn on i/o so we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	 * flush out disks that did not return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	scsi_unblock_requests(ha->core.shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	sas_drain_work(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) EXPORT_SYMBOL(sas_resume_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) void sas_suspend_ha(struct sas_ha_struct *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	sas_disable_events(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	scsi_block_requests(ha->core.shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	for (i = 0; i < ha->num_phys; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		struct asd_sas_port *port = ha->sas_port[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		sas_discover_event(port, DISCE_SUSPEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	/* flush suspend events while unregistered */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	mutex_lock(&ha->drain_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	__sas_drain_work(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	mutex_unlock(&ha->drain_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) EXPORT_SYMBOL(sas_suspend_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static void sas_phy_release(struct sas_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	kfree(phy->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	phy->hostdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static void phy_reset_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	struct sas_phy_data *d = container_of(work, typeof(*d), reset_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	d->reset_result = transport_sas_phy_reset(d->phy, d->hard_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static void phy_enable_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	struct sas_phy_data *d = container_of(work, typeof(*d), enable_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	d->enable_result = sas_phy_enable(d->phy, d->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static int sas_phy_setup(struct sas_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	struct sas_phy_data *d = kzalloc(sizeof(*d), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (!d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	mutex_init(&d->event_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	INIT_SAS_WORK(&d->reset_work, phy_reset_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	INIT_SAS_WORK(&d->enable_work, phy_enable_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	d->phy = phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	phy->hostdata = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static int queue_phy_reset(struct sas_phy *phy, int hard_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	struct sas_phy_data *d = phy->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	if (!d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	/* libsas workqueue coordinates ata-eh reset with discovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	mutex_lock(&d->event_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	d->reset_result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	d->hard_reset = hard_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	spin_lock_irq(&ha->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	sas_queue_work(ha, &d->reset_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	spin_unlock_irq(&ha->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	rc = sas_drain_work(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		rc = d->reset_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	mutex_unlock(&d->event_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static int queue_phy_enable(struct sas_phy *phy, int enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	struct sas_phy_data *d = phy->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	if (!d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	/* libsas workqueue coordinates ata-eh reset with discovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	mutex_lock(&d->event_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	d->enable_result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	d->enable = enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	spin_lock_irq(&ha->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	sas_queue_work(ha, &d->enable_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	spin_unlock_irq(&ha->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	rc = sas_drain_work(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		rc = d->enable_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	mutex_unlock(&d->event_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static struct sas_function_template sft = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	.phy_enable = queue_phy_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	.phy_reset = queue_phy_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	.phy_setup = sas_phy_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	.phy_release = sas_phy_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	.set_phy_speed = sas_set_phy_speed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	.get_linkerrors = sas_get_linkerrors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	.smp_handler = sas_smp_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static inline ssize_t phy_event_threshold_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 			struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	struct Scsi_Host *shost = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	return scnprintf(buf, PAGE_SIZE, "%u\n", sha->event_thres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) static inline ssize_t phy_event_threshold_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 			struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 			const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	struct Scsi_Host *shost = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	sha->event_thres = simple_strtol(buf, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	/* threshold cannot be set too small */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	if (sha->event_thres < 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		sha->event_thres = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) DEVICE_ATTR(phy_event_threshold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	S_IRUGO|S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	phy_event_threshold_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	phy_event_threshold_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) EXPORT_SYMBOL_GPL(dev_attr_phy_event_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) struct scsi_transport_template *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) sas_domain_attach_transport(struct sas_domain_function_template *dft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	struct scsi_transport_template *stt = sas_attach_transport(&sft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	struct sas_internal *i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	if (!stt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		return stt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	i = to_sas_internal(stt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	i->dft = dft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	stt->create_work_queue = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	stt->eh_strategy_handler = sas_scsi_recover_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	return stt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) EXPORT_SYMBOL_GPL(sas_domain_attach_transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static struct asd_sas_event *__sas_alloc_event(struct asd_sas_phy *phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 					       gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	struct asd_sas_event *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	struct sas_ha_struct *sas_ha = phy->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	struct sas_internal *i =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		to_sas_internal(sas_ha->core.shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	event = kmem_cache_zalloc(sas_event_cache, gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	atomic_inc(&phy->event_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	if (atomic_read(&phy->event_nr) > phy->ha->event_thres) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		if (i->dft->lldd_control_phy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 			if (cmpxchg(&phy->in_shutdown, 0, 1) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 				pr_notice("The phy%d bursting events, shut it down.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 					  phy->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 				sas_notify_phy_event_gfp(phy, PHYE_SHUTDOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 							 gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 			/* Do not support PHY control, stop allocating events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 			WARN_ONCE(1, "PHY control not supported.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 			kmem_cache_free(sas_event_cache, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 			atomic_dec(&phy->event_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 			event = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) struct asd_sas_event *sas_alloc_event(struct asd_sas_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	return __sas_alloc_event(phy, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) struct asd_sas_event *sas_alloc_event_gfp(struct asd_sas_phy *phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 					  gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	return __sas_alloc_event(phy, gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) void sas_free_event(struct asd_sas_event *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	struct asd_sas_phy *phy = event->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	kmem_cache_free(sas_event_cache, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	atomic_dec(&phy->event_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) /* ---------- SAS Class register/unregister ---------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) static int __init sas_class_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	sas_task_cache = KMEM_CACHE(sas_task, SLAB_HWCACHE_ALIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	if (!sas_task_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	sas_event_cache = KMEM_CACHE(asd_sas_event, SLAB_HWCACHE_ALIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	if (!sas_event_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 		goto free_task_kmem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) free_task_kmem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	kmem_cache_destroy(sas_task_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) static void __exit sas_class_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	kmem_cache_destroy(sas_task_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	kmem_cache_destroy(sas_event_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) MODULE_AUTHOR("Luben Tuikov <luben_tuikov@adaptec.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) MODULE_DESCRIPTION("SAS Transport Layer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) module_init(sas_class_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) module_exit(sas_class_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) EXPORT_SYMBOL_GPL(sas_register_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) EXPORT_SYMBOL_GPL(sas_unregister_ha);