11e66f787SSean Bruno /*-
27ea28254SJohn Hall  * Copyright 2016-2023 Microchip Technology, Inc. and/or its subsidiaries.
31e66f787SSean Bruno  *
41e66f787SSean Bruno  * Redistribution and use in source and binary forms, with or without
51e66f787SSean Bruno  * modification, are permitted provided that the following conditions
61e66f787SSean Bruno  * are met:
71e66f787SSean Bruno  * 1. Redistributions of source code must retain the above copyright
81e66f787SSean Bruno  *    notice, this list of conditions and the following disclaimer.
91e66f787SSean Bruno  * 2. Redistributions in binary form must reproduce the above copyright
101e66f787SSean Bruno  *    notice, this list of conditions and the following disclaimer in the
111e66f787SSean Bruno  *    documentation and/or other materials provided with the distribution.
121e66f787SSean Bruno  *
131e66f787SSean Bruno  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
141e66f787SSean Bruno  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
151e66f787SSean Bruno  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
161e66f787SSean Bruno  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
171e66f787SSean Bruno  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
181e66f787SSean Bruno  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
191e66f787SSean Bruno  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
201e66f787SSean Bruno  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
211e66f787SSean Bruno  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
221e66f787SSean Bruno  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
231e66f787SSean Bruno  * SUCH DAMAGE.
241e66f787SSean Bruno  */
251e66f787SSean Bruno 
261e66f787SSean Bruno 
271e66f787SSean Bruno #include "smartpqi_includes.h"
281e66f787SSean Bruno 
291e66f787SSean Bruno /*
301e66f787SSean Bruno  * Process internal RAID response in the case of success.
311e66f787SSean Bruno  */
329fac68fcSPAPANI SRIKANTH void
pqisrc_process_internal_raid_response_success(pqisrc_softstate_t * softs,rcb_t * rcb)339fac68fcSPAPANI SRIKANTH pqisrc_process_internal_raid_response_success(pqisrc_softstate_t *softs,rcb_t *rcb)
341e66f787SSean Bruno {
357ea28254SJohn Hall 	DBG_FUNC("IN\n");
361e66f787SSean Bruno 
377ea28254SJohn Hall 	rcb->status = PQI_STATUS_SUCCESS;
381e66f787SSean Bruno 	rcb->req_pending = false;
391e66f787SSean Bruno 
407ea28254SJohn Hall 	DBG_FUNC("OUT\n");
417ea28254SJohn Hall }
427ea28254SJohn Hall 
437ea28254SJohn Hall /* Safely determines if cdb is available and if so, will return SCSI opcode or
447ea28254SJohn Hall    BMIC cmd if BMIC op code is detected */
457ea28254SJohn Hall uint8_t
pqisrc_get_cmd_from_rcb(rcb_t * rcb)467ea28254SJohn Hall pqisrc_get_cmd_from_rcb(rcb_t *rcb)
477ea28254SJohn Hall {
487ea28254SJohn Hall 	uint8_t opcode = 0xFF;
497ea28254SJohn Hall 
507ea28254SJohn Hall 	if (rcb && rcb->cdbp)
517ea28254SJohn Hall 	{
527ea28254SJohn Hall 		opcode = rcb->cdbp[0];
537ea28254SJohn Hall 		if (IS_BMIC_OPCODE(opcode))
547ea28254SJohn Hall 			return rcb->cdbp[6];
557ea28254SJohn Hall 	}
567ea28254SJohn Hall 
577ea28254SJohn Hall 	return opcode;
581e66f787SSean Bruno }
591e66f787SSean Bruno 
601e66f787SSean Bruno /*
611e66f787SSean Bruno  * Process internal RAID response in the case of failure.
621e66f787SSean Bruno  */
639fac68fcSPAPANI SRIKANTH void
pqisrc_process_internal_raid_response_error(pqisrc_softstate_t * softs,rcb_t * rcb,uint16_t err_idx)649fac68fcSPAPANI SRIKANTH pqisrc_process_internal_raid_response_error(pqisrc_softstate_t *softs,
651e66f787SSean Bruno 				       rcb_t *rcb, uint16_t err_idx)
661e66f787SSean Bruno {
671e66f787SSean Bruno 	raid_path_error_info_elem_t error_info;
681e66f787SSean Bruno 
697ea28254SJohn Hall 	DBG_FUNC("IN\n");
701e66f787SSean Bruno 
711e66f787SSean Bruno 	rcb->error_info = (char *) (softs->err_buf_dma_mem.virt_addr) +
721e66f787SSean Bruno 			  (err_idx * PQI_ERROR_BUFFER_ELEMENT_LENGTH);
739fac68fcSPAPANI SRIKANTH 
741e66f787SSean Bruno 	memcpy(&error_info, rcb->error_info, sizeof(error_info));
751e66f787SSean Bruno 
767ea28254SJohn Hall 	rcb->status = PQI_STATUS_TIMEOUT;
779fac68fcSPAPANI SRIKANTH 
789fac68fcSPAPANI SRIKANTH 	switch (error_info.data_out_result) {
799fac68fcSPAPANI SRIKANTH 	case PQI_RAID_DATA_IN_OUT_GOOD:
809fac68fcSPAPANI SRIKANTH 		if (error_info.status == PQI_RAID_DATA_IN_OUT_GOOD)
817ea28254SJohn Hall 			rcb->status = PQI_STATUS_SUCCESS;
829fac68fcSPAPANI SRIKANTH 		break;
839fac68fcSPAPANI SRIKANTH 	case PQI_RAID_DATA_IN_OUT_UNDERFLOW:
849fac68fcSPAPANI SRIKANTH 		if (error_info.status == PQI_RAID_DATA_IN_OUT_GOOD ||
859fac68fcSPAPANI SRIKANTH 				error_info.status == PQI_RAID_STATUS_CHECK_CONDITION)
867ea28254SJohn Hall 			rcb->status = PQI_STATUS_SUCCESS;
879fac68fcSPAPANI SRIKANTH 		break;
887ea28254SJohn Hall 	default:
897ea28254SJohn Hall 		DBG_WARN("error_status 0x%x data_in_result 0x%x data_out_result 0x%x cmd rcb tag 0x%x\n",
907ea28254SJohn Hall 		error_info.status, error_info.data_in_result, error_info.data_out_result, rcb->tag);
917ea28254SJohn Hall 	}
927ea28254SJohn Hall 
937ea28254SJohn Hall 	if (rcb->status != PQI_STATUS_SUCCESS)
947ea28254SJohn Hall 	{
957ea28254SJohn Hall 		DBG_INFO("error_status=0x%x data_in=0x%x data_out=0x%x detail=0x%x\n",
967ea28254SJohn Hall 			error_info.status, error_info.data_in_result, error_info.data_out_result,
977ea28254SJohn Hall 			pqisrc_get_cmd_from_rcb(rcb));
989fac68fcSPAPANI SRIKANTH 	}
991e66f787SSean Bruno 
1001e66f787SSean Bruno 	rcb->req_pending = false;
1011e66f787SSean Bruno 
1027ea28254SJohn Hall 	DBG_FUNC("OUT\n");
1031e66f787SSean Bruno }
1041e66f787SSean Bruno 
1051e66f787SSean Bruno /*
1061e66f787SSean Bruno  * Process the AIO/RAID IO in the case of success.
1071e66f787SSean Bruno  */
1089fac68fcSPAPANI SRIKANTH void
pqisrc_process_io_response_success(pqisrc_softstate_t * softs,rcb_t * rcb)1099fac68fcSPAPANI SRIKANTH pqisrc_process_io_response_success(pqisrc_softstate_t *softs, rcb_t *rcb)
1101e66f787SSean Bruno {
1117ea28254SJohn Hall 	DBG_FUNC("IN\n");
1121e66f787SSean Bruno 
1131e66f787SSean Bruno 	os_io_response_success(rcb);
1141e66f787SSean Bruno 
1157ea28254SJohn Hall 	DBG_FUNC("OUT\n");
1161e66f787SSean Bruno }
1171e66f787SSean Bruno 
1189fac68fcSPAPANI SRIKANTH static void
pqisrc_extract_sense_data(sense_data_u_t * sense_data,uint8_t * key,uint8_t * asc,uint8_t * ascq)1199fac68fcSPAPANI SRIKANTH pqisrc_extract_sense_data(sense_data_u_t *sense_data, uint8_t *key, uint8_t *asc, uint8_t *ascq)
1209fac68fcSPAPANI SRIKANTH {
1219fac68fcSPAPANI SRIKANTH 	if (sense_data->fixed_format.response_code == SCSI_SENSE_RESPONSE_70 ||
1229fac68fcSPAPANI SRIKANTH 		sense_data->fixed_format.response_code == SCSI_SENSE_RESPONSE_71)
1239fac68fcSPAPANI SRIKANTH 	{
1249fac68fcSPAPANI SRIKANTH 		sense_data_fixed_t *fixed = &sense_data->fixed_format;
1259fac68fcSPAPANI SRIKANTH 
1269fac68fcSPAPANI SRIKANTH 		*key = fixed->sense_key;
1279fac68fcSPAPANI SRIKANTH 		*asc = fixed->sense_code;
1289fac68fcSPAPANI SRIKANTH 		*ascq = fixed->sense_qual;
1299fac68fcSPAPANI SRIKANTH 	}
1309fac68fcSPAPANI SRIKANTH 	else if (sense_data->descriptor_format.response_code == SCSI_SENSE_RESPONSE_72 ||
1319fac68fcSPAPANI SRIKANTH 		sense_data->descriptor_format.response_code == SCSI_SENSE_RESPONSE_73)
1329fac68fcSPAPANI SRIKANTH 	{
1339fac68fcSPAPANI SRIKANTH 		sense_data_descriptor_t *desc = &sense_data->descriptor_format;
1349fac68fcSPAPANI SRIKANTH 
1359fac68fcSPAPANI SRIKANTH 		*key = desc->sense_key;
1369fac68fcSPAPANI SRIKANTH 		*asc = desc->sense_code;
1379fac68fcSPAPANI SRIKANTH 		*ascq = desc->sense_qual;
1389fac68fcSPAPANI SRIKANTH 	}
1399fac68fcSPAPANI SRIKANTH 	else
1409fac68fcSPAPANI SRIKANTH 	{
1419fac68fcSPAPANI SRIKANTH 		*key = 0xFF;
1429fac68fcSPAPANI SRIKANTH 		*asc = 0xFF;
1439fac68fcSPAPANI SRIKANTH 		*ascq = 0xFF;
1449fac68fcSPAPANI SRIKANTH 	}
1459fac68fcSPAPANI SRIKANTH }
1469fac68fcSPAPANI SRIKANTH 
1477ea28254SJohn Hall /* Suppress common errors unless verbose debug flag is on */
1487ea28254SJohn Hall boolean_t
suppress_innocuous_error_prints(pqisrc_softstate_t * softs,rcb_t * rcb)1497ea28254SJohn Hall suppress_innocuous_error_prints(pqisrc_softstate_t *softs, rcb_t *rcb)
1507ea28254SJohn Hall {
1517ea28254SJohn Hall 	uint8_t opcode = rcb->cdbp ? rcb->cdbp[0] : 0xFF;
1527ea28254SJohn Hall 
1537ea28254SJohn Hall 	if ((opcode == SCSI_INQUIRY ||           /* 0x12 */
1547ea28254SJohn Hall 		opcode == SCSI_MODE_SENSE ||     /* 0x1a */
1557ea28254SJohn Hall 		opcode == SCSI_REPORT_LUNS ||    /* 0xa0 */
1567ea28254SJohn Hall 		opcode == SCSI_LOG_SENSE ||      /* 0x4d */
1577ea28254SJohn Hall 		opcode == SCSI_ATA_PASSTHRU16)   /* 0x85 */
1587ea28254SJohn Hall 		&& (softs->err_resp_verbose == false))
1597ea28254SJohn Hall 		return true;
1607ea28254SJohn Hall 
1617ea28254SJohn Hall 	return false;
1627ea28254SJohn Hall }
1637ea28254SJohn Hall 
1649fac68fcSPAPANI SRIKANTH static void
pqisrc_show_sense_data_simple(pqisrc_softstate_t * softs,rcb_t * rcb,sense_data_u_t * sense_data)1659fac68fcSPAPANI SRIKANTH pqisrc_show_sense_data_simple(pqisrc_softstate_t *softs, rcb_t *rcb, sense_data_u_t *sense_data)
1669fac68fcSPAPANI SRIKANTH {
1679fac68fcSPAPANI SRIKANTH 	uint8_t opcode = rcb->cdbp ? rcb->cdbp[0] : 0xFF;
1689fac68fcSPAPANI SRIKANTH 	char *path = io_path_to_ascii(rcb->path);
1699fac68fcSPAPANI SRIKANTH 	uint8_t key, asc, ascq;
1709fac68fcSPAPANI SRIKANTH 	pqisrc_extract_sense_data(sense_data, &key, &asc, &ascq);
1719fac68fcSPAPANI SRIKANTH 
1729fac68fcSPAPANI SRIKANTH 	DBG_NOTE("[ERR INFO] BTL: %d:%d:%d op=0x%x path=%s K:C:Q: %x:%x:%x\n",
1739fac68fcSPAPANI SRIKANTH 		rcb->dvp->bus, rcb->dvp->target, rcb->dvp->lun,
1749fac68fcSPAPANI SRIKANTH 		opcode, path, key, asc, ascq);
1759fac68fcSPAPANI SRIKANTH }
1769fac68fcSPAPANI SRIKANTH 
1779fac68fcSPAPANI SRIKANTH void
pqisrc_show_sense_data_full(pqisrc_softstate_t * softs,rcb_t * rcb,sense_data_u_t * sense_data)1789fac68fcSPAPANI SRIKANTH pqisrc_show_sense_data_full(pqisrc_softstate_t *softs, rcb_t *rcb, sense_data_u_t *sense_data)
1799fac68fcSPAPANI SRIKANTH {
1807ea28254SJohn Hall 	if (suppress_innocuous_error_prints(softs, rcb))
1817ea28254SJohn Hall 		return;
1827ea28254SJohn Hall 
1839fac68fcSPAPANI SRIKANTH 	pqisrc_print_buffer(softs, "sense data", sense_data, 32, 0);
1849fac68fcSPAPANI SRIKANTH 
1859fac68fcSPAPANI SRIKANTH 	pqisrc_show_sense_data_simple(softs, rcb, sense_data);
1869fac68fcSPAPANI SRIKANTH 
1879fac68fcSPAPANI SRIKANTH 	/* add more detail here as needed */
1889fac68fcSPAPANI SRIKANTH }
1899fac68fcSPAPANI SRIKANTH 
1909fac68fcSPAPANI SRIKANTH 
1917ea28254SJohn Hall /*  dumps the aio error info and sense data then breaks down the output */
1927ea28254SJohn Hall void
pqisrc_show_aio_error_info(pqisrc_softstate_t * softs,rcb_t * rcb,aio_path_error_info_elem_t * aio_err)1937ea28254SJohn Hall pqisrc_show_aio_error_info(pqisrc_softstate_t *softs, rcb_t *rcb, aio_path_error_info_elem_t *aio_err)
1947ea28254SJohn Hall {
1957ea28254SJohn Hall 	DBG_NOTE("\n");
1967ea28254SJohn Hall 	DBG_NOTE("aio err: status=0x%x serv_resp=0x%x data_pres=0x%x data_len=0x%x\n",
1977ea28254SJohn Hall 		aio_err->status, aio_err->service_resp, aio_err->data_pres, aio_err->data_len);
1987ea28254SJohn Hall 
1997ea28254SJohn Hall 	pqisrc_print_buffer(softs, "aio err info", aio_err,
2007ea28254SJohn Hall 		offsetof(aio_path_error_info_elem_t, data), PRINT_FLAG_HDR_COLUMN);
2017ea28254SJohn Hall 
2027ea28254SJohn Hall 	pqisrc_show_sense_data_full(softs, rcb, &aio_err->sense_data);
2037ea28254SJohn Hall }
2047ea28254SJohn Hall 
2057ea28254SJohn Hall 
2067ea28254SJohn Hall /*  dumps the raid error info and sense data then breaks down the output */
2077ea28254SJohn Hall void
pqisrc_show_raid_error_info(pqisrc_softstate_t * softs,rcb_t * rcb,raid_path_error_info_elem_t * raid_err)2087ea28254SJohn Hall pqisrc_show_raid_error_info(pqisrc_softstate_t *softs, rcb_t *rcb, raid_path_error_info_elem_t *raid_err)
2097ea28254SJohn Hall {
2107ea28254SJohn Hall 	DBG_NOTE("\n");
2117ea28254SJohn Hall 	DBG_NOTE("raid err: data_in=0x%x out=0x%x status=0x%x sense_len=0x%x resp_len=0x%x\n",
2127ea28254SJohn Hall 		raid_err->data_in_result, raid_err->data_in_result,
2137ea28254SJohn Hall 		raid_err->status, raid_err->sense_data_len, raid_err->resp_data_len);
2147ea28254SJohn Hall 
2157ea28254SJohn Hall 	pqisrc_print_buffer(softs, "raid err info", raid_err,
2167ea28254SJohn Hall 		offsetof(raid_path_error_info_elem_t, data), PRINT_FLAG_HDR_COLUMN);
2177ea28254SJohn Hall 
2187ea28254SJohn Hall 	pqisrc_show_sense_data_full(softs, rcb, &raid_err->sense_data);
2197ea28254SJohn Hall }
2207ea28254SJohn Hall 
2217ea28254SJohn Hall /*  return true if this an innocuous error */
2227ea28254SJohn Hall boolean_t
pqisrc_is_innocuous_error(pqisrc_softstate_t * softs,rcb_t * rcb,void * err_info)2237ea28254SJohn Hall pqisrc_is_innocuous_error(pqisrc_softstate_t *softs, rcb_t *rcb, void *err_info)
2247ea28254SJohn Hall {
2257ea28254SJohn Hall 	uint8_t opcode = rcb->cdbp ? rcb->cdbp[0] : 0xFF;
2267ea28254SJohn Hall 
2277ea28254SJohn Hall 	/* These SCSI cmds are frequently cause "underrun" and other minor "error"
2287ea28254SJohn Hall 		conditions while determining log page length, support, etc. */
2297ea28254SJohn Hall 	if (opcode != SCSI_INQUIRY &&        /* 0x12 */
2307ea28254SJohn Hall 		 opcode != SCSI_MODE_SENSE &&     /* 0x1a */
2317ea28254SJohn Hall 		 opcode != SCSI_REPORT_LUNS &&    /* 0xa0 */
2327ea28254SJohn Hall 		 opcode != SCSI_LOG_SENSE &&      /* 0x4d */
2337ea28254SJohn Hall 		 opcode != SCSI_ATA_PASSTHRU16)   /* 0x85 */
2347ea28254SJohn Hall 	{
2357ea28254SJohn Hall 		return false;
2367ea28254SJohn Hall 	}
2377ea28254SJohn Hall 
2387ea28254SJohn Hall 	/* treat all cmds above as innocuous unless verbose flag is set. */
2397ea28254SJohn Hall 	if (softs->err_resp_verbose == false)
2407ea28254SJohn Hall 		return true;
2417ea28254SJohn Hall 
2427ea28254SJohn Hall 	if (rcb->path == AIO_PATH)
2437ea28254SJohn Hall 	{
2447ea28254SJohn Hall 		aio_path_error_info_elem_t *aio_err = err_info;
2457ea28254SJohn Hall 		uint8_t key, asc, ascq;
2467ea28254SJohn Hall 
2477ea28254SJohn Hall 		/* Byte[0]=Status=0x51, Byte[1]=service_resp=0x01 */
2487ea28254SJohn Hall 		if (aio_err->status == PQI_AIO_STATUS_UNDERRUN &&
2497ea28254SJohn Hall 			aio_err->service_resp == PQI_AIO_SERV_RESPONSE_FAILURE)
2507ea28254SJohn Hall 		{
2517ea28254SJohn Hall 			return true;
2527ea28254SJohn Hall 		}
2537ea28254SJohn Hall 
2547ea28254SJohn Hall 		/* get the key info so we can apply more filters... */
2557ea28254SJohn Hall 		pqisrc_extract_sense_data(&aio_err->sense_data, &key, &asc, &ascq);
2567ea28254SJohn Hall 
2577ea28254SJohn Hall 		/* Seeing a lot of invalid field in CDB for REPORT LUNs on AIO path.
2587ea28254SJohn Hall 			Example CDB = a0 00 11 00 00 00 00 00 20 08 00 00
2597ea28254SJohn Hall 			So filter out the full dump info for now.  Also wonder if we should
2607ea28254SJohn Hall 			just send REPORT LUNS to raid path? */
2617ea28254SJohn Hall 		if (opcode == SCSI_REPORT_LUNS &&
2627ea28254SJohn Hall 			key == 5 && asc == 0x24)
2637ea28254SJohn Hall 		{
2647ea28254SJohn Hall 			pqisrc_show_sense_data_simple(softs, rcb, &aio_err->sense_data);
2657ea28254SJohn Hall 			return true;
2667ea28254SJohn Hall 		}
2677ea28254SJohn Hall 
2687ea28254SJohn Hall 		/* may want to return true here eventually? */
2697ea28254SJohn Hall 	}
2707ea28254SJohn Hall 	else
2717ea28254SJohn Hall 	{
2727ea28254SJohn Hall 		raid_path_error_info_elem_t *raid_err = err_info;
2737ea28254SJohn Hall 
2747ea28254SJohn Hall 		/* Byte[1]=data_out=0x01 */
2757ea28254SJohn Hall 		if (raid_err->data_out_result == PQI_RAID_DATA_IN_OUT_UNDERFLOW)
2767ea28254SJohn Hall 			return true;
2777ea28254SJohn Hall 
2787ea28254SJohn Hall 		/* We get these a alot: leave a tiny breadcrumb about the error,
2797ea28254SJohn Hall 			but don't do full spew about it */
2807ea28254SJohn Hall 		if (raid_err->status == PQI_AIO_STATUS_CHECK_CONDITION)
2817ea28254SJohn Hall 		{
2827ea28254SJohn Hall 			pqisrc_show_sense_data_simple(softs, rcb, &raid_err->sense_data);
2837ea28254SJohn Hall 			return true;
2847ea28254SJohn Hall 		}
2857ea28254SJohn Hall 	}
2867ea28254SJohn Hall 
2877ea28254SJohn Hall 	return false;
2887ea28254SJohn Hall }
2897ea28254SJohn Hall 
2901e66f787SSean Bruno /*
2911e66f787SSean Bruno  * Process the error info for AIO in the case of failure.
2921e66f787SSean Bruno  */
2939fac68fcSPAPANI SRIKANTH void
pqisrc_process_aio_response_error(pqisrc_softstate_t * softs,rcb_t * rcb,uint16_t err_idx)2949fac68fcSPAPANI SRIKANTH pqisrc_process_aio_response_error(pqisrc_softstate_t *softs,
2951e66f787SSean Bruno 		rcb_t *rcb, uint16_t err_idx)
2961e66f787SSean Bruno {
2971e66f787SSean Bruno 	aio_path_error_info_elem_t *err_info = NULL;
2981e66f787SSean Bruno 
2997ea28254SJohn Hall 	DBG_FUNC("IN\n");
3007ea28254SJohn Hall 
3017ea28254SJohn Hall 	ASSERT(rcb->path == AIO_PATH);
3021e66f787SSean Bruno 
3031e66f787SSean Bruno 	err_info = (aio_path_error_info_elem_t*)
3041e66f787SSean Bruno 			softs->err_buf_dma_mem.virt_addr +
3051e66f787SSean Bruno 			err_idx;
3061e66f787SSean Bruno 
3071e66f787SSean Bruno 	if(err_info == NULL) {
3087ea28254SJohn Hall 		DBG_ERR("err_info structure is NULL  err_idx :%x\n", err_idx);
3091e66f787SSean Bruno 		return;
3101e66f787SSean Bruno 	}
3111e66f787SSean Bruno 
3127ea28254SJohn Hall 	/* filter out certain underrun/success "errors" from printing */
3137ea28254SJohn Hall 	if (!pqisrc_is_innocuous_error(softs, rcb, err_info)) {
3147ea28254SJohn Hall 
3157ea28254SJohn Hall 		if (softs->err_resp_verbose == true)
3167ea28254SJohn Hall 			pqisrc_show_rcb_details(softs, rcb,
3177ea28254SJohn Hall 					"aio error", err_info);
3187ea28254SJohn Hall 	}
3197ea28254SJohn Hall 
3201e66f787SSean Bruno 	os_aio_response_error(rcb, err_info);
3211e66f787SSean Bruno 
3227ea28254SJohn Hall 	DBG_FUNC("OUT\n");
3231e66f787SSean Bruno }
3241e66f787SSean Bruno 
3251e66f787SSean Bruno /*
3261e66f787SSean Bruno  * Process the error info for RAID IO in the case of failure.
3271e66f787SSean Bruno  */
3289fac68fcSPAPANI SRIKANTH void
pqisrc_process_raid_response_error(pqisrc_softstate_t * softs,rcb_t * rcb,uint16_t err_idx)3299fac68fcSPAPANI SRIKANTH pqisrc_process_raid_response_error(pqisrc_softstate_t *softs,
3301e66f787SSean Bruno 		rcb_t *rcb, uint16_t err_idx)
3311e66f787SSean Bruno {
3321e66f787SSean Bruno 	raid_path_error_info_elem_t *err_info = NULL;
3331e66f787SSean Bruno 
3347ea28254SJohn Hall 	DBG_FUNC("IN\n");
3357ea28254SJohn Hall 
3367ea28254SJohn Hall 	ASSERT(rcb->path == RAID_PATH);
3371e66f787SSean Bruno 
3381e66f787SSean Bruno 	err_info = (raid_path_error_info_elem_t*)
3391e66f787SSean Bruno 			softs->err_buf_dma_mem.virt_addr +
3401e66f787SSean Bruno 			err_idx;
3411e66f787SSean Bruno 
3421e66f787SSean Bruno 	if(err_info == NULL) {
3437ea28254SJohn Hall 		DBG_ERR("err_info structure is NULL  err_idx :%x\n", err_idx);
3441e66f787SSean Bruno 		return;
3451e66f787SSean Bruno 	}
3461e66f787SSean Bruno 
3477ea28254SJohn Hall 	/* filter out certain underrun/success "errors" from printing */
3487ea28254SJohn Hall 	if (!pqisrc_is_innocuous_error(softs, rcb, err_info)) {
3497ea28254SJohn Hall 
3507ea28254SJohn Hall 		if( softs->err_resp_verbose == true )
3517ea28254SJohn Hall 			pqisrc_show_rcb_details(softs, rcb,
3527ea28254SJohn Hall 					"raid error", err_info);
3537ea28254SJohn Hall 
3547ea28254SJohn Hall 	}
3557ea28254SJohn Hall 
3561e66f787SSean Bruno 	os_raid_response_error(rcb, err_info);
3571e66f787SSean Bruno 
3587ea28254SJohn Hall 	DBG_FUNC("OUT\n");
3591e66f787SSean Bruno }
3601e66f787SSean Bruno 
3611e66f787SSean Bruno /*
3621e66f787SSean Bruno  * Process the Task Management function response.
3631e66f787SSean Bruno  */
3649fac68fcSPAPANI SRIKANTH int
pqisrc_process_task_management_response(pqisrc_softstate_t * softs,pqi_tmf_resp_t * tmf_resp)3659fac68fcSPAPANI SRIKANTH pqisrc_process_task_management_response(pqisrc_softstate_t *softs,
3661e66f787SSean Bruno 			pqi_tmf_resp_t *tmf_resp)
3671e66f787SSean Bruno {
3687ea28254SJohn Hall 	int ret = PQI_STATUS_SUCCESS;
3691e66f787SSean Bruno 	uint32_t tag = (uint32_t)tmf_resp->req_id;
3701e66f787SSean Bruno 	rcb_t *rcb = &softs->rcb[tag];
3711e66f787SSean Bruno 
3721e66f787SSean Bruno 	ASSERT(rcb->tag == tag);
3731e66f787SSean Bruno 
3741e66f787SSean Bruno 	DBG_FUNC("IN\n");
3751e66f787SSean Bruno 
3761e66f787SSean Bruno 	switch (tmf_resp->resp_code) {
3771e66f787SSean Bruno 	case SOP_TASK_MANAGEMENT_FUNCTION_COMPLETE:
3781e66f787SSean Bruno 	case SOP_TASK_MANAGEMENT_FUNCTION_SUCCEEDED:
3797ea28254SJohn Hall 		ret = PQI_STATUS_SUCCESS;
3801e66f787SSean Bruno 		break;
3811e66f787SSean Bruno 	default:
3827ea28254SJohn Hall 		DBG_ERR("Tag #0x%08x TMF Failed, Response code : 0x%x\n",
3837ea28254SJohn Hall 			rcb->tag, tmf_resp->resp_code);
3847ea28254SJohn Hall 		ret = PQI_STATUS_TIMEOUT;
3851e66f787SSean Bruno 		break;
3861e66f787SSean Bruno 	}
3871e66f787SSean Bruno 
3881e66f787SSean Bruno 	rcb->status = ret;
3891e66f787SSean Bruno 	rcb->req_pending = false;
3901e66f787SSean Bruno 
3917ea28254SJohn Hall 	DBG_FUNC("OUT\n");
3921e66f787SSean Bruno 	return ret;
3931e66f787SSean Bruno }
3941e66f787SSean Bruno 
3959fac68fcSPAPANI SRIKANTH static int
pqisrc_process_vendor_general_response(pqi_vendor_general_response_t * response)3969fac68fcSPAPANI SRIKANTH pqisrc_process_vendor_general_response(pqi_vendor_general_response_t *response)
3979fac68fcSPAPANI SRIKANTH {
3989fac68fcSPAPANI SRIKANTH 
3997ea28254SJohn Hall 	int ret = PQI_STATUS_SUCCESS;
4009fac68fcSPAPANI SRIKANTH 
4019fac68fcSPAPANI SRIKANTH 	switch(response->status) {
4029fac68fcSPAPANI SRIKANTH 	case PQI_VENDOR_RESPONSE_IU_SUCCESS:
4039fac68fcSPAPANI SRIKANTH 		break;
4049fac68fcSPAPANI SRIKANTH 	case PQI_VENDOR_RESPONSE_IU_UNSUCCESS:
4059fac68fcSPAPANI SRIKANTH 	case PQI_VENDOR_RESPONSE_IU_INVALID_PARAM:
4069fac68fcSPAPANI SRIKANTH 	case PQI_VENDOR_RESPONSE_IU_INSUFF_RESRC:
4077ea28254SJohn Hall 		ret = PQI_STATUS_TIMEOUT;
4089fac68fcSPAPANI SRIKANTH 		break;
4099fac68fcSPAPANI SRIKANTH 	}
4109fac68fcSPAPANI SRIKANTH 
4119fac68fcSPAPANI SRIKANTH 	return ret;
4129fac68fcSPAPANI SRIKANTH }
4139fac68fcSPAPANI SRIKANTH 
4141e66f787SSean Bruno /*
4151e66f787SSean Bruno  * Function used to process the response from the adapter
4161e66f787SSean Bruno  * which is invoked by IRQ handler.
4171e66f787SSean Bruno  */
4181e66f787SSean Bruno void
pqisrc_process_response_queue(pqisrc_softstate_t * softs,int oq_id)4191e66f787SSean Bruno pqisrc_process_response_queue(pqisrc_softstate_t *softs, int oq_id)
4201e66f787SSean Bruno {
4211e66f787SSean Bruno 	ob_queue_t *ob_q;
4221e66f787SSean Bruno 	struct pqi_io_response *response;
4231e66f787SSean Bruno 	uint32_t oq_pi, oq_ci;
4249fac68fcSPAPANI SRIKANTH 	pqi_scsi_dev_t	*dvp = NULL;
4251e66f787SSean Bruno 
4267ea28254SJohn Hall 
4277ea28254SJohn Hall 	DBG_FUNC("IN\n");
4281e66f787SSean Bruno 
4291e66f787SSean Bruno 	ob_q = &softs->op_ob_q[oq_id - 1]; /* zero for event Q */
4301e66f787SSean Bruno 	oq_ci = ob_q->ci_local;
4311e66f787SSean Bruno 	oq_pi = *(ob_q->pi_virt_addr);
4321e66f787SSean Bruno 
4337ea28254SJohn Hall 	DBG_IO("ci : %u pi : %u qid : %u\n", oq_ci, oq_pi, ob_q->q_id);
4341e66f787SSean Bruno 
4351e66f787SSean Bruno 	while (1) {
4367ea28254SJohn Hall 		boolean_t os_scsi_cmd = false;
4371e66f787SSean Bruno 		rcb_t *rcb = NULL;
4381e66f787SSean Bruno 		uint32_t tag = 0;
4391e66f787SSean Bruno 		uint32_t offset;
4401e66f787SSean Bruno 
4411e66f787SSean Bruno 		if (oq_pi == oq_ci)
4421e66f787SSean Bruno 			break;
4431e66f787SSean Bruno 		/* Get the response */
4441e66f787SSean Bruno 		offset = oq_ci * ob_q->elem_size;
4451e66f787SSean Bruno 		response = (struct pqi_io_response *)(ob_q->array_virt_addr +
4461e66f787SSean Bruno 							offset);
4471e66f787SSean Bruno 		tag = response->request_id;
4481e66f787SSean Bruno 		rcb = &softs->rcb[tag];
4491e66f787SSean Bruno 		/* Make sure we are processing a valid response. */
4509fac68fcSPAPANI SRIKANTH 		if ((rcb->tag != tag) || (rcb->req_pending == false)) {
4517ea28254SJohn Hall 			DBG_ERR("No such request pending with tag : %x rcb->tag : %x", tag, rcb->tag);
4529fac68fcSPAPANI SRIKANTH 			oq_ci = (oq_ci + 1) % ob_q->num_elem;
4539fac68fcSPAPANI SRIKANTH 			break;
4549fac68fcSPAPANI SRIKANTH 		}
4559fac68fcSPAPANI SRIKANTH 		/* Timedout request has been completed. This should not hit,
4569fac68fcSPAPANI SRIKANTH 		 * if timeout is set as TIMEOUT_INFINITE while calling
4579fac68fcSPAPANI SRIKANTH 		 * pqisrc_wait_on_condition(softs,rcb,timeout).
4589fac68fcSPAPANI SRIKANTH 		 */
4599fac68fcSPAPANI SRIKANTH 		if (rcb->timedout) {
4607ea28254SJohn Hall 			DBG_WARN("timed out request completing from firmware, driver already completed it with failure , free the tag 0x%x\n", tag);
4619fac68fcSPAPANI SRIKANTH 			oq_ci = (oq_ci + 1) % ob_q->num_elem;
4629fac68fcSPAPANI SRIKANTH 			os_reset_rcb(rcb);
4639fac68fcSPAPANI SRIKANTH 			pqisrc_put_tag(&softs->taglist, tag);
4649fac68fcSPAPANI SRIKANTH 			break;
4659fac68fcSPAPANI SRIKANTH 		}
4669fac68fcSPAPANI SRIKANTH 
4677ea28254SJohn Hall 		if (rcb->host_wants_to_abort_this)
4687ea28254SJohn Hall 		{
4697ea28254SJohn Hall 			DBG_INFO("cmd that was aborted came back. tag=%u\n", rcb->tag);
4707ea28254SJohn Hall 		}
4717ea28254SJohn Hall 		if (rcb->is_abort_cmd_from_host)
4727ea28254SJohn Hall 		{
4737ea28254SJohn Hall 			DBG_INFO("abort cmd came back. tag=%u\n", rcb->tag);
4747ea28254SJohn Hall 		}
4759fac68fcSPAPANI SRIKANTH 		if (IS_OS_SCSICMD(rcb)) {
4769fac68fcSPAPANI SRIKANTH 			dvp = rcb->dvp;
4779fac68fcSPAPANI SRIKANTH 			if (dvp)
4789fac68fcSPAPANI SRIKANTH 				os_scsi_cmd = true;
4799fac68fcSPAPANI SRIKANTH 			else
4809fac68fcSPAPANI SRIKANTH 				DBG_WARN("Received IO completion for the Null device!!!\n");
4819fac68fcSPAPANI SRIKANTH 		}
4829fac68fcSPAPANI SRIKANTH 
4837ea28254SJohn Hall 		DBG_IO("response.header.iu_type : %x \n", response->header.iu_type);
4841e66f787SSean Bruno 
4851e66f787SSean Bruno 		switch (response->header.iu_type) {
4861e66f787SSean Bruno 		case PQI_RESPONSE_IU_RAID_PATH_IO_SUCCESS:
4871e66f787SSean Bruno 		case PQI_RESPONSE_IU_AIO_PATH_IO_SUCCESS:
4881e66f787SSean Bruno 			rcb->success_cmp_callback(softs, rcb);
4899fac68fcSPAPANI SRIKANTH 			if (os_scsi_cmd)
4909fac68fcSPAPANI SRIKANTH 				pqisrc_decrement_device_active_io(softs, dvp);
4911e66f787SSean Bruno 			break;
4921e66f787SSean Bruno 		case PQI_RESPONSE_IU_RAID_PATH_IO_ERROR:
4931e66f787SSean Bruno 		case PQI_RESPONSE_IU_AIO_PATH_IO_ERROR:
4941e66f787SSean Bruno 			rcb->error_cmp_callback(softs, rcb, LE_16(response->error_index));
4959fac68fcSPAPANI SRIKANTH 			if (os_scsi_cmd)
4969fac68fcSPAPANI SRIKANTH 				pqisrc_decrement_device_active_io(softs, dvp);
4971e66f787SSean Bruno 			break;
4981e66f787SSean Bruno 		case PQI_RESPONSE_IU_GENERAL_MANAGEMENT:
4991e66f787SSean Bruno 			rcb->req_pending = false;
5001e66f787SSean Bruno 			break;
5019fac68fcSPAPANI SRIKANTH 		case PQI_RESPONSE_IU_VENDOR_GENERAL:
5029fac68fcSPAPANI SRIKANTH 			rcb->req_pending = false;
5039fac68fcSPAPANI SRIKANTH 			rcb->status = pqisrc_process_vendor_general_response(
5049fac68fcSPAPANI SRIKANTH 								(pqi_vendor_general_response_t *)response);
5059fac68fcSPAPANI SRIKANTH 			break;
5061e66f787SSean Bruno 		case PQI_RESPONSE_IU_TASK_MANAGEMENT:
5071e66f787SSean Bruno 			rcb->status = pqisrc_process_task_management_response(softs, (void *)response);
5081e66f787SSean Bruno 			break;
5091e66f787SSean Bruno 
5101e66f787SSean Bruno 		default:
5111e66f787SSean Bruno 			DBG_ERR("Invalid Response IU 0x%x\n",response->header.iu_type);
5121e66f787SSean Bruno 			break;
5131e66f787SSean Bruno 		}
5141e66f787SSean Bruno 
5151e66f787SSean Bruno 		oq_ci = (oq_ci + 1) % ob_q->num_elem;
5161e66f787SSean Bruno 	}
5171e66f787SSean Bruno 
5181e66f787SSean Bruno 	ob_q->ci_local = oq_ci;
5191e66f787SSean Bruno 	PCI_MEM_PUT32(softs, ob_q->ci_register_abs,
5201e66f787SSean Bruno 		ob_q->ci_register_offset, ob_q->ci_local );
5217ea28254SJohn Hall 	DBG_FUNC("OUT\n");
5221e66f787SSean Bruno }
523