11e66f787SSean Bruno /*-
2*7ea28254SJohn 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 {
35*7ea28254SJohn Hall DBG_FUNC("IN\n");
361e66f787SSean Bruno
37*7ea28254SJohn Hall rcb->status = PQI_STATUS_SUCCESS;
381e66f787SSean Bruno rcb->req_pending = false;
391e66f787SSean Bruno
40*7ea28254SJohn Hall DBG_FUNC("OUT\n");
41*7ea28254SJohn Hall }
42*7ea28254SJohn Hall
43*7ea28254SJohn Hall /* Safely determines if cdb is available and if so, will return SCSI opcode or
44*7ea28254SJohn Hall BMIC cmd if BMIC op code is detected */
45*7ea28254SJohn Hall uint8_t
pqisrc_get_cmd_from_rcb(rcb_t * rcb)46*7ea28254SJohn Hall pqisrc_get_cmd_from_rcb(rcb_t *rcb)
47*7ea28254SJohn Hall {
48*7ea28254SJohn Hall uint8_t opcode = 0xFF;
49*7ea28254SJohn Hall
50*7ea28254SJohn Hall if (rcb && rcb->cdbp)
51*7ea28254SJohn Hall {
52*7ea28254SJohn Hall opcode = rcb->cdbp[0];
53*7ea28254SJohn Hall if (IS_BMIC_OPCODE(opcode))
54*7ea28254SJohn Hall return rcb->cdbp[6];
55*7ea28254SJohn Hall }
56*7ea28254SJohn Hall
57*7ea28254SJohn 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
69*7ea28254SJohn 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
76*7ea28254SJohn 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)
81*7ea28254SJohn 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)
86*7ea28254SJohn Hall rcb->status = PQI_STATUS_SUCCESS;
879fac68fcSPAPANI SRIKANTH break;
88*7ea28254SJohn Hall default:
89*7ea28254SJohn Hall DBG_WARN("error_status 0x%x data_in_result 0x%x data_out_result 0x%x cmd rcb tag 0x%x\n",
90*7ea28254SJohn Hall error_info.status, error_info.data_in_result, error_info.data_out_result, rcb->tag);
91*7ea28254SJohn Hall }
92*7ea28254SJohn Hall
93*7ea28254SJohn Hall if (rcb->status != PQI_STATUS_SUCCESS)
94*7ea28254SJohn Hall {
95*7ea28254SJohn Hall DBG_INFO("error_status=0x%x data_in=0x%x data_out=0x%x detail=0x%x\n",
96*7ea28254SJohn Hall error_info.status, error_info.data_in_result, error_info.data_out_result,
97*7ea28254SJohn Hall pqisrc_get_cmd_from_rcb(rcb));
989fac68fcSPAPANI SRIKANTH }
991e66f787SSean Bruno
1001e66f787SSean Bruno rcb->req_pending = false;
1011e66f787SSean Bruno
102*7ea28254SJohn 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 {
111*7ea28254SJohn Hall DBG_FUNC("IN\n");
1121e66f787SSean Bruno
1131e66f787SSean Bruno os_io_response_success(rcb);
1141e66f787SSean Bruno
115*7ea28254SJohn 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
147*7ea28254SJohn Hall /* Suppress common errors unless verbose debug flag is on */
148*7ea28254SJohn Hall boolean_t
suppress_innocuous_error_prints(pqisrc_softstate_t * softs,rcb_t * rcb)149*7ea28254SJohn Hall suppress_innocuous_error_prints(pqisrc_softstate_t *softs, rcb_t *rcb)
150*7ea28254SJohn Hall {
151*7ea28254SJohn Hall uint8_t opcode = rcb->cdbp ? rcb->cdbp[0] : 0xFF;
152*7ea28254SJohn Hall
153*7ea28254SJohn Hall if ((opcode == SCSI_INQUIRY || /* 0x12 */
154*7ea28254SJohn Hall opcode == SCSI_MODE_SENSE || /* 0x1a */
155*7ea28254SJohn Hall opcode == SCSI_REPORT_LUNS || /* 0xa0 */
156*7ea28254SJohn Hall opcode == SCSI_LOG_SENSE || /* 0x4d */
157*7ea28254SJohn Hall opcode == SCSI_ATA_PASSTHRU16) /* 0x85 */
158*7ea28254SJohn Hall && (softs->err_resp_verbose == false))
159*7ea28254SJohn Hall return true;
160*7ea28254SJohn Hall
161*7ea28254SJohn Hall return false;
162*7ea28254SJohn Hall }
163*7ea28254SJohn 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 {
180*7ea28254SJohn Hall if (suppress_innocuous_error_prints(softs, rcb))
181*7ea28254SJohn Hall return;
182*7ea28254SJohn 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
191*7ea28254SJohn Hall /* dumps the aio error info and sense data then breaks down the output */
192*7ea28254SJohn Hall void
pqisrc_show_aio_error_info(pqisrc_softstate_t * softs,rcb_t * rcb,aio_path_error_info_elem_t * aio_err)193*7ea28254SJohn Hall pqisrc_show_aio_error_info(pqisrc_softstate_t *softs, rcb_t *rcb, aio_path_error_info_elem_t *aio_err)
194*7ea28254SJohn Hall {
195*7ea28254SJohn Hall DBG_NOTE("\n");
196*7ea28254SJohn Hall DBG_NOTE("aio err: status=0x%x serv_resp=0x%x data_pres=0x%x data_len=0x%x\n",
197*7ea28254SJohn Hall aio_err->status, aio_err->service_resp, aio_err->data_pres, aio_err->data_len);
198*7ea28254SJohn Hall
199*7ea28254SJohn Hall pqisrc_print_buffer(softs, "aio err info", aio_err,
200*7ea28254SJohn Hall offsetof(aio_path_error_info_elem_t, data), PRINT_FLAG_HDR_COLUMN);
201*7ea28254SJohn Hall
202*7ea28254SJohn Hall pqisrc_show_sense_data_full(softs, rcb, &aio_err->sense_data);
203*7ea28254SJohn Hall }
204*7ea28254SJohn Hall
205*7ea28254SJohn Hall
206*7ea28254SJohn Hall /* dumps the raid error info and sense data then breaks down the output */
207*7ea28254SJohn Hall void
pqisrc_show_raid_error_info(pqisrc_softstate_t * softs,rcb_t * rcb,raid_path_error_info_elem_t * raid_err)208*7ea28254SJohn Hall pqisrc_show_raid_error_info(pqisrc_softstate_t *softs, rcb_t *rcb, raid_path_error_info_elem_t *raid_err)
209*7ea28254SJohn Hall {
210*7ea28254SJohn Hall DBG_NOTE("\n");
211*7ea28254SJohn Hall DBG_NOTE("raid err: data_in=0x%x out=0x%x status=0x%x sense_len=0x%x resp_len=0x%x\n",
212*7ea28254SJohn Hall raid_err->data_in_result, raid_err->data_in_result,
213*7ea28254SJohn Hall raid_err->status, raid_err->sense_data_len, raid_err->resp_data_len);
214*7ea28254SJohn Hall
215*7ea28254SJohn Hall pqisrc_print_buffer(softs, "raid err info", raid_err,
216*7ea28254SJohn Hall offsetof(raid_path_error_info_elem_t, data), PRINT_FLAG_HDR_COLUMN);
217*7ea28254SJohn Hall
218*7ea28254SJohn Hall pqisrc_show_sense_data_full(softs, rcb, &raid_err->sense_data);
219*7ea28254SJohn Hall }
220*7ea28254SJohn Hall
221*7ea28254SJohn Hall /* return true if this an innocuous error */
222*7ea28254SJohn Hall boolean_t
pqisrc_is_innocuous_error(pqisrc_softstate_t * softs,rcb_t * rcb,void * err_info)223*7ea28254SJohn Hall pqisrc_is_innocuous_error(pqisrc_softstate_t *softs, rcb_t *rcb, void *err_info)
224*7ea28254SJohn Hall {
225*7ea28254SJohn Hall uint8_t opcode = rcb->cdbp ? rcb->cdbp[0] : 0xFF;
226*7ea28254SJohn Hall
227*7ea28254SJohn Hall /* These SCSI cmds are frequently cause "underrun" and other minor "error"
228*7ea28254SJohn Hall conditions while determining log page length, support, etc. */
229*7ea28254SJohn Hall if (opcode != SCSI_INQUIRY && /* 0x12 */
230*7ea28254SJohn Hall opcode != SCSI_MODE_SENSE && /* 0x1a */
231*7ea28254SJohn Hall opcode != SCSI_REPORT_LUNS && /* 0xa0 */
232*7ea28254SJohn Hall opcode != SCSI_LOG_SENSE && /* 0x4d */
233*7ea28254SJohn Hall opcode != SCSI_ATA_PASSTHRU16) /* 0x85 */
234*7ea28254SJohn Hall {
235*7ea28254SJohn Hall return false;
236*7ea28254SJohn Hall }
237*7ea28254SJohn Hall
238*7ea28254SJohn Hall /* treat all cmds above as innocuous unless verbose flag is set. */
239*7ea28254SJohn Hall if (softs->err_resp_verbose == false)
240*7ea28254SJohn Hall return true;
241*7ea28254SJohn Hall
242*7ea28254SJohn Hall if (rcb->path == AIO_PATH)
243*7ea28254SJohn Hall {
244*7ea28254SJohn Hall aio_path_error_info_elem_t *aio_err = err_info;
245*7ea28254SJohn Hall uint8_t key, asc, ascq;
246*7ea28254SJohn Hall
247*7ea28254SJohn Hall /* Byte[0]=Status=0x51, Byte[1]=service_resp=0x01 */
248*7ea28254SJohn Hall if (aio_err->status == PQI_AIO_STATUS_UNDERRUN &&
249*7ea28254SJohn Hall aio_err->service_resp == PQI_AIO_SERV_RESPONSE_FAILURE)
250*7ea28254SJohn Hall {
251*7ea28254SJohn Hall return true;
252*7ea28254SJohn Hall }
253*7ea28254SJohn Hall
254*7ea28254SJohn Hall /* get the key info so we can apply more filters... */
255*7ea28254SJohn Hall pqisrc_extract_sense_data(&aio_err->sense_data, &key, &asc, &ascq);
256*7ea28254SJohn Hall
257*7ea28254SJohn Hall /* Seeing a lot of invalid field in CDB for REPORT LUNs on AIO path.
258*7ea28254SJohn Hall Example CDB = a0 00 11 00 00 00 00 00 20 08 00 00
259*7ea28254SJohn Hall So filter out the full dump info for now. Also wonder if we should
260*7ea28254SJohn Hall just send REPORT LUNS to raid path? */
261*7ea28254SJohn Hall if (opcode == SCSI_REPORT_LUNS &&
262*7ea28254SJohn Hall key == 5 && asc == 0x24)
263*7ea28254SJohn Hall {
264*7ea28254SJohn Hall pqisrc_show_sense_data_simple(softs, rcb, &aio_err->sense_data);
265*7ea28254SJohn Hall return true;
266*7ea28254SJohn Hall }
267*7ea28254SJohn Hall
268*7ea28254SJohn Hall /* may want to return true here eventually? */
269*7ea28254SJohn Hall }
270*7ea28254SJohn Hall else
271*7ea28254SJohn Hall {
272*7ea28254SJohn Hall raid_path_error_info_elem_t *raid_err = err_info;
273*7ea28254SJohn Hall
274*7ea28254SJohn Hall /* Byte[1]=data_out=0x01 */
275*7ea28254SJohn Hall if (raid_err->data_out_result == PQI_RAID_DATA_IN_OUT_UNDERFLOW)
276*7ea28254SJohn Hall return true;
277*7ea28254SJohn Hall
278*7ea28254SJohn Hall /* We get these a alot: leave a tiny breadcrumb about the error,
279*7ea28254SJohn Hall but don't do full spew about it */
280*7ea28254SJohn Hall if (raid_err->status == PQI_AIO_STATUS_CHECK_CONDITION)
281*7ea28254SJohn Hall {
282*7ea28254SJohn Hall pqisrc_show_sense_data_simple(softs, rcb, &raid_err->sense_data);
283*7ea28254SJohn Hall return true;
284*7ea28254SJohn Hall }
285*7ea28254SJohn Hall }
286*7ea28254SJohn Hall
287*7ea28254SJohn Hall return false;
288*7ea28254SJohn Hall }
289*7ea28254SJohn 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
299*7ea28254SJohn Hall DBG_FUNC("IN\n");
300*7ea28254SJohn Hall
301*7ea28254SJohn 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) {
308*7ea28254SJohn Hall DBG_ERR("err_info structure is NULL err_idx :%x\n", err_idx);
3091e66f787SSean Bruno return;
3101e66f787SSean Bruno }
3111e66f787SSean Bruno
312*7ea28254SJohn Hall /* filter out certain underrun/success "errors" from printing */
313*7ea28254SJohn Hall if (!pqisrc_is_innocuous_error(softs, rcb, err_info)) {
314*7ea28254SJohn Hall
315*7ea28254SJohn Hall if (softs->err_resp_verbose == true)
316*7ea28254SJohn Hall pqisrc_show_rcb_details(softs, rcb,
317*7ea28254SJohn Hall "aio error", err_info);
318*7ea28254SJohn Hall }
319*7ea28254SJohn Hall
3201e66f787SSean Bruno os_aio_response_error(rcb, err_info);
3211e66f787SSean Bruno
322*7ea28254SJohn 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
334*7ea28254SJohn Hall DBG_FUNC("IN\n");
335*7ea28254SJohn Hall
336*7ea28254SJohn 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) {
343*7ea28254SJohn Hall DBG_ERR("err_info structure is NULL err_idx :%x\n", err_idx);
3441e66f787SSean Bruno return;
3451e66f787SSean Bruno }
3461e66f787SSean Bruno
347*7ea28254SJohn Hall /* filter out certain underrun/success "errors" from printing */
348*7ea28254SJohn Hall if (!pqisrc_is_innocuous_error(softs, rcb, err_info)) {
349*7ea28254SJohn Hall
350*7ea28254SJohn Hall if( softs->err_resp_verbose == true )
351*7ea28254SJohn Hall pqisrc_show_rcb_details(softs, rcb,
352*7ea28254SJohn Hall "raid error", err_info);
353*7ea28254SJohn Hall
354*7ea28254SJohn Hall }
355*7ea28254SJohn Hall
3561e66f787SSean Bruno os_raid_response_error(rcb, err_info);
3571e66f787SSean Bruno
358*7ea28254SJohn 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 {
368*7ea28254SJohn 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:
379*7ea28254SJohn Hall ret = PQI_STATUS_SUCCESS;
3801e66f787SSean Bruno break;
3811e66f787SSean Bruno default:
382*7ea28254SJohn Hall DBG_ERR("Tag #0x%08x TMF Failed, Response code : 0x%x\n",
383*7ea28254SJohn Hall rcb->tag, tmf_resp->resp_code);
384*7ea28254SJohn 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
391*7ea28254SJohn 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
399*7ea28254SJohn 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:
407*7ea28254SJohn 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
426*7ea28254SJohn Hall
427*7ea28254SJohn 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
433*7ea28254SJohn Hall DBG_IO("ci : %u pi : %u qid : %u\n", oq_ci, oq_pi, ob_q->q_id);
4341e66f787SSean Bruno
4351e66f787SSean Bruno while (1) {
436*7ea28254SJohn 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)) {
451*7ea28254SJohn 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) {
460*7ea28254SJohn 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
467*7ea28254SJohn Hall if (rcb->host_wants_to_abort_this)
468*7ea28254SJohn Hall {
469*7ea28254SJohn Hall DBG_INFO("cmd that was aborted came back. tag=%u\n", rcb->tag);
470*7ea28254SJohn Hall }
471*7ea28254SJohn Hall if (rcb->is_abort_cmd_from_host)
472*7ea28254SJohn Hall {
473*7ea28254SJohn Hall DBG_INFO("abort cmd came back. tag=%u\n", rcb->tag);
474*7ea28254SJohn 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
483*7ea28254SJohn 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 );
521*7ea28254SJohn Hall DBG_FUNC("OUT\n");
5221e66f787SSean Bruno }
523