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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Serial Attached SCSI (SAS) Phy class
^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 "sas_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <scsi/scsi_transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <scsi/scsi_transport_sas.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "../scsi_sas_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /* ---------- Phy events ---------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static void sas_phye_loss_of_signal(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	struct asd_sas_event *ev = to_asd_sas_event(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	struct asd_sas_phy *phy = ev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	phy->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	sas_deform_port(phy, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static void sas_phye_oob_done(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct asd_sas_event *ev = to_asd_sas_event(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct asd_sas_phy *phy = ev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	phy->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static void sas_phye_oob_error(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct asd_sas_event *ev = to_asd_sas_event(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct asd_sas_phy *phy = ev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct sas_ha_struct *sas_ha = phy->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct asd_sas_port *port = phy->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct sas_internal *i =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		to_sas_internal(sas_ha->core.shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	sas_deform_port(phy, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (!port && phy->enabled && i->dft->lldd_control_phy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		phy->error++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		switch (phy->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			i->dft->lldd_control_phy(phy, PHY_FUNC_HARD_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 						 NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			phy->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			phy->enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static void sas_phye_spinup_hold(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct asd_sas_event *ev = to_asd_sas_event(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct asd_sas_phy *phy = ev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct sas_ha_struct *sas_ha = phy->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct sas_internal *i =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		to_sas_internal(sas_ha->core.shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	phy->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	i->dft->lldd_control_phy(phy, PHY_FUNC_RELEASE_SPINUP_HOLD, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static void sas_phye_resume_timeout(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct asd_sas_event *ev = to_asd_sas_event(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct asd_sas_phy *phy = ev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	/* phew, lldd got the phy back in the nick of time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (!phy->suspended) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		dev_info(&phy->phy->dev, "resume timeout cancelled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	phy->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	phy->suspended = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	sas_deform_port(phy, 1);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static void sas_phye_shutdown(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct asd_sas_event *ev = to_asd_sas_event(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct asd_sas_phy *phy = ev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct sas_ha_struct *sas_ha = phy->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct sas_internal *i =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		to_sas_internal(sas_ha->core.shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (phy->enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		phy->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		phy->enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		ret = i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			pr_notice("lldd disable phy%d returned %d\n", phy->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				  ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		pr_notice("phy%d is not enabled, cannot shutdown\n", phy->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	phy->in_shutdown = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* ---------- Phy class registration ---------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int sas_register_phys(struct sas_ha_struct *sas_ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/* Now register the phys. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	for (i = 0; i < sas_ha->num_phys; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		struct asd_sas_phy *phy = sas_ha->sas_phy[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		phy->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		atomic_set(&phy->event_nr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		INIT_LIST_HEAD(&phy->port_phy_el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		phy->port = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		phy->ha = sas_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		spin_lock_init(&phy->frame_rcvd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		spin_lock_init(&phy->sas_prim_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		phy->frame_rcvd_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		phy->phy = sas_phy_alloc(&sas_ha->core.shost->shost_gendev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		if (!phy->phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		phy->phy->identify.initiator_port_protocols =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			phy->iproto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		phy->phy->identify.target_port_protocols = phy->tproto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		phy->phy->identify.sas_address = SAS_ADDR(sas_ha->sas_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		phy->phy->identify.phy_identifier = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		phy->phy->minimum_linkrate_hw = SAS_LINK_RATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		phy->phy->maximum_linkrate_hw = SAS_LINK_RATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		phy->phy->minimum_linkrate = SAS_LINK_RATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		phy->phy->maximum_linkrate = SAS_LINK_RATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		phy->phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		sas_phy_add(phy->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) const work_func_t sas_phy_event_fns[PHY_NUM_EVENTS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	[PHYE_LOSS_OF_SIGNAL] = sas_phye_loss_of_signal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	[PHYE_OOB_DONE] = sas_phye_oob_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	[PHYE_OOB_ERROR] = sas_phye_oob_error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	[PHYE_SPINUP_HOLD] = sas_phye_spinup_hold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	[PHYE_RESUME_TIMEOUT] = sas_phye_resume_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	[PHYE_SHUTDOWN] = sas_phye_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) };