aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/mpt2sas
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/mpt2sas')
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_transport.c242
1 files changed, 233 insertions, 9 deletions
diff --git a/drivers/scsi/mpt2sas/mpt2sas_transport.c b/drivers/scsi/mpt2sas/mpt2sas_transport.c
index 778e149f963..a96501fdba0 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_transport.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_transport.c
@@ -951,11 +951,229 @@ _transport_find_local_phy(struct MPT2SAS_ADAPTER *ioc, struct sas_phy *phy)
951 return NULL; 951 return NULL;
952} 952}
953 953
954/* report phy error log structure */
955struct phy_error_log_request{
956 u8 smp_frame_type; /* 0x40 */
957 u8 function; /* 0x11 */
958 u8 allocated_response_length;
959 u8 request_length; /* 02 */
960 u8 reserved_1[5];
961 u8 phy_identifier;
962 u8 reserved_2[2];
963};
964
965/* report phy error log reply structure */
966struct phy_error_log_reply{
967 u8 smp_frame_type; /* 0x41 */
968 u8 function; /* 0x11 */
969 u8 function_result;
970 u8 response_length;
971 u16 expander_change_count;
972 u8 reserved_1[3];
973 u8 phy_identifier;
974 u8 reserved_2[2];
975 u32 invalid_dword;
976 u32 running_disparity_error;
977 u32 loss_of_dword_sync;
978 u32 phy_reset_problem;
979};
980
954/** 981/**
955 * _transport_get_linkerrors - 982 * _transport_get_expander_phy_error_log - return expander counters
983 * @ioc: per adapter object
984 * @phy: The sas phy object
985 *
986 * Returns 0 for success, non-zero for failure.
987 *
988 */
989static int
990_transport_get_expander_phy_error_log(struct MPT2SAS_ADAPTER *ioc,
991 struct sas_phy *phy)
992{
993 Mpi2SmpPassthroughRequest_t *mpi_request;
994 Mpi2SmpPassthroughReply_t *mpi_reply;
995 struct phy_error_log_request *phy_error_log_request;
996 struct phy_error_log_reply *phy_error_log_reply;
997 int rc;
998 u16 smid;
999 u32 ioc_state;
1000 unsigned long timeleft;
1001 void *psge;
1002 u32 sgl_flags;
1003 u8 issue_reset = 0;
1004 void *data_out = NULL;
1005 dma_addr_t data_out_dma;
1006 u32 sz;
1007 u64 *sas_address_le;
1008 u16 wait_state_count;
1009
1010 if (ioc->shost_recovery) {
1011 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
1012 __func__, ioc->name);
1013 return -EFAULT;
1014 }
1015
1016 mutex_lock(&ioc->transport_cmds.mutex);
1017
1018 if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) {
1019 printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n",
1020 ioc->name, __func__);
1021 rc = -EAGAIN;
1022 goto out;
1023 }
1024 ioc->transport_cmds.status = MPT2_CMD_PENDING;
1025
1026 wait_state_count = 0;
1027 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
1028 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1029 if (wait_state_count++ == 10) {
1030 printk(MPT2SAS_ERR_FMT
1031 "%s: failed due to ioc not operational\n",
1032 ioc->name, __func__);
1033 rc = -EFAULT;
1034 goto out;
1035 }
1036 ssleep(1);
1037 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
1038 printk(MPT2SAS_INFO_FMT "%s: waiting for "
1039 "operational state(count=%d)\n", ioc->name,
1040 __func__, wait_state_count);
1041 }
1042 if (wait_state_count)
1043 printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n",
1044 ioc->name, __func__);
1045
1046 smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx);
1047 if (!smid) {
1048 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
1049 ioc->name, __func__);
1050 rc = -EAGAIN;
1051 goto out;
1052 }
1053
1054 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1055 ioc->transport_cmds.smid = smid;
1056
1057 sz = sizeof(struct phy_error_log_request) +
1058 sizeof(struct phy_error_log_reply);
1059 data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
1060 if (!data_out) {
1061 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__,
1062 __LINE__, __func__);
1063 rc = -ENOMEM;
1064 mpt2sas_base_free_smid(ioc, smid);
1065 goto out;
1066 }
1067
1068 rc = -EINVAL;
1069 memset(data_out, 0, sz);
1070 phy_error_log_request = data_out;
1071 phy_error_log_request->smp_frame_type = 0x40;
1072 phy_error_log_request->function = 0x11;
1073 phy_error_log_request->request_length = 2;
1074 phy_error_log_request->allocated_response_length = 0;
1075 phy_error_log_request->phy_identifier = phy->number;
1076
1077 memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t));
1078 mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH;
1079 mpi_request->PhysicalPort = 0xFF;
1080 mpi_request->VF_ID = 0; /* TODO */
1081 mpi_request->VP_ID = 0;
1082 sas_address_le = (u64 *)&mpi_request->SASAddress;
1083 *sas_address_le = cpu_to_le64(phy->identify.sas_address);
1084 mpi_request->RequestDataLength =
1085 cpu_to_le16(sizeof(struct phy_error_log_request));
1086 psge = &mpi_request->SGL;
1087
1088 /* WRITE sgel first */
1089 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
1090 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
1091 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1092 ioc->base_add_sg_single(psge, sgl_flags |
1093 sizeof(struct phy_error_log_request), data_out_dma);
1094
1095 /* incr sgel */
1096 psge += ioc->sge_size;
1097
1098 /* READ sgel last */
1099 sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT |
1100 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
1101 MPI2_SGE_FLAGS_END_OF_LIST);
1102 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1103 ioc->base_add_sg_single(psge, sgl_flags |
1104 sizeof(struct phy_error_log_reply), data_out_dma +
1105 sizeof(struct phy_error_log_request));
1106
1107 dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_error_log - "
1108 "send to sas_addr(0x%016llx), phy(%d)\n", ioc->name,
1109 (unsigned long long)phy->identify.sas_address, phy->number));
1110 mpt2sas_base_put_smid_default(ioc, smid);
1111 init_completion(&ioc->transport_cmds.done);
1112 timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done,
1113 10*HZ);
1114
1115 if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) {
1116 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
1117 ioc->name, __func__);
1118 _debug_dump_mf(mpi_request,
1119 sizeof(Mpi2SmpPassthroughRequest_t)/4);
1120 if (!(ioc->transport_cmds.status & MPT2_CMD_RESET))
1121 issue_reset = 1;
1122 goto issue_host_reset;
1123 }
1124
1125 dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_error_log - "
1126 "complete\n", ioc->name));
1127
1128 if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) {
1129
1130 mpi_reply = ioc->transport_cmds.reply;
1131
1132 dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
1133 "phy_error_log - reply data transfer size(%d)\n",
1134 ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
1135
1136 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
1137 sizeof(struct phy_error_log_reply))
1138 goto out;
1139
1140 phy_error_log_reply = data_out +
1141 sizeof(struct phy_error_log_request);
1142
1143 dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
1144 "phy_error_log - function_result(%d)\n",
1145 ioc->name, phy_error_log_reply->function_result));
1146
1147 phy->invalid_dword_count =
1148 be32_to_cpu(phy_error_log_reply->invalid_dword);
1149 phy->running_disparity_error_count =
1150 be32_to_cpu(phy_error_log_reply->running_disparity_error);
1151 phy->loss_of_dword_sync_count =
1152 be32_to_cpu(phy_error_log_reply->loss_of_dword_sync);
1153 phy->phy_reset_problem_count =
1154 be32_to_cpu(phy_error_log_reply->phy_reset_problem);
1155 rc = 0;
1156 } else
1157 dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT
1158 "phy_error_log - no reply\n", ioc->name));
1159
1160 issue_host_reset:
1161 if (issue_reset)
1162 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1163 FORCE_BIG_HAMMER);
1164 out:
1165 ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
1166 if (data_out)
1167 pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
1168
1169 mutex_unlock(&ioc->transport_cmds.mutex);
1170 return rc;
1171}
1172
1173/**
1174 * _transport_get_linkerrors - return phy counters for both hba and expanders
956 * @phy: The sas phy object 1175 * @phy: The sas phy object
957 * 1176 *
958 * Only support sas_host direct attached phys.
959 * Returns 0 for success, non-zero for failure. 1177 * Returns 0 for success, non-zero for failure.
960 * 1178 *
961 */ 1179 */
@@ -963,17 +1181,24 @@ static int
963_transport_get_linkerrors(struct sas_phy *phy) 1181_transport_get_linkerrors(struct sas_phy *phy)
964{ 1182{
965 struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); 1183 struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
966 struct _sas_phy *mpt2sas_phy; 1184 unsigned long flags;
967 Mpi2ConfigReply_t mpi_reply; 1185 Mpi2ConfigReply_t mpi_reply;
968 Mpi2SasPhyPage1_t phy_pg1; 1186 Mpi2SasPhyPage1_t phy_pg1;
969 1187
970 mpt2sas_phy = _transport_find_local_phy(ioc, phy); 1188 spin_lock_irqsave(&ioc->sas_node_lock, flags);
971 1189 if (_transport_sas_node_find_by_sas_address(ioc,
972 if (!mpt2sas_phy) /* this phy not on sas_host */ 1190 phy->identify.sas_address) == NULL) {
1191 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
973 return -EINVAL; 1192 return -EINVAL;
1193 }
1194 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1195
1196 if (phy->identify.sas_address != ioc->sas_hba.sas_address)
1197 return _transport_get_expander_phy_error_log(ioc, phy);
974 1198
1199 /* get hba phy error logs */
975 if ((mpt2sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1, 1200 if ((mpt2sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1,
976 mpt2sas_phy->phy_id))) { 1201 phy->number))) {
977 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1202 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
978 ioc->name, __FILE__, __LINE__, __func__); 1203 ioc->name, __FILE__, __LINE__, __func__);
979 return -ENXIO; 1204 return -ENXIO;
@@ -982,8 +1207,7 @@ _transport_get_linkerrors(struct sas_phy *phy)
982 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) 1207 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
983 printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status" 1208 printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status"
984 "(0x%04x), loginfo(0x%08x)\n", ioc->name, 1209 "(0x%04x), loginfo(0x%08x)\n", ioc->name,
985 mpt2sas_phy->phy_id, 1210 phy->number, le16_to_cpu(mpi_reply.IOCStatus),
986 le16_to_cpu(mpi_reply.IOCStatus),
987 le32_to_cpu(mpi_reply.IOCLogInfo)); 1211 le32_to_cpu(mpi_reply.IOCLogInfo));
988 1212
989 phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount); 1213 phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount);