2 * Copyright 2016-2021 Microchip Technology, Inc. and/or its subsidiaries.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include "smartpqi_includes.h"
31 * Process internal RAID response in the case of success.
34 pqisrc_process_internal_raid_response_success(pqisrc_softstate_t *softs,rcb_t *rcb)
38 rcb->status = REQUEST_SUCCESS;
39 rcb->req_pending = false;
45 * Process internal RAID response in the case of failure.
48 pqisrc_process_internal_raid_response_error(pqisrc_softstate_t *softs,
49 rcb_t *rcb, uint16_t err_idx)
51 raid_path_error_info_elem_t error_info;
55 rcb->error_info = (char *) (softs->err_buf_dma_mem.virt_addr) +
56 (err_idx * PQI_ERROR_BUFFER_ELEMENT_LENGTH);
58 memcpy(&error_info, rcb->error_info, sizeof(error_info));
60 DBG_INFO("error_status 0x%x data_in_result 0x%x data_out_result 0x%x\n",
61 error_info.status, error_info.data_in_result, error_info.data_out_result);
63 rcb->status = REQUEST_FAILED;
65 switch (error_info.data_out_result) {
66 case PQI_RAID_DATA_IN_OUT_GOOD:
67 if (error_info.status == PQI_RAID_DATA_IN_OUT_GOOD)
68 rcb->status = REQUEST_SUCCESS;
70 case PQI_RAID_DATA_IN_OUT_UNDERFLOW:
71 if (error_info.status == PQI_RAID_DATA_IN_OUT_GOOD ||
72 error_info.status == PQI_RAID_STATUS_CHECK_CONDITION)
73 rcb->status = REQUEST_SUCCESS;
77 rcb->req_pending = false;
83 * Process the AIO/RAID IO in the case of success.
86 pqisrc_process_io_response_success(pqisrc_softstate_t *softs, rcb_t *rcb)
90 os_io_response_success(rcb);
96 pqisrc_extract_sense_data(sense_data_u_t *sense_data, uint8_t *key, uint8_t *asc, uint8_t *ascq)
98 if (sense_data->fixed_format.response_code == SCSI_SENSE_RESPONSE_70 ||
99 sense_data->fixed_format.response_code == SCSI_SENSE_RESPONSE_71)
101 sense_data_fixed_t *fixed = &sense_data->fixed_format;
103 *key = fixed->sense_key;
104 *asc = fixed->sense_code;
105 *ascq = fixed->sense_qual;
107 else if (sense_data->descriptor_format.response_code == SCSI_SENSE_RESPONSE_72 ||
108 sense_data->descriptor_format.response_code == SCSI_SENSE_RESPONSE_73)
110 sense_data_descriptor_t *desc = &sense_data->descriptor_format;
112 *key = desc->sense_key;
113 *asc = desc->sense_code;
114 *ascq = desc->sense_qual;
125 pqisrc_show_sense_data_simple(pqisrc_softstate_t *softs, rcb_t *rcb, sense_data_u_t *sense_data)
127 uint8_t opcode = rcb->cdbp ? rcb->cdbp[0] : 0xFF;
128 char *path = io_path_to_ascii(rcb->path);
129 uint8_t key, asc, ascq;
130 pqisrc_extract_sense_data(sense_data, &key, &asc, &ascq);
132 DBG_NOTE("[ERR INFO] BTL: %d:%d:%d op=0x%x path=%s K:C:Q: %x:%x:%x\n",
133 rcb->dvp->bus, rcb->dvp->target, rcb->dvp->lun,
134 opcode, path, key, asc, ascq);
138 pqisrc_show_sense_data_full(pqisrc_softstate_t *softs, rcb_t *rcb, sense_data_u_t *sense_data)
140 pqisrc_print_buffer(softs, "sense data", sense_data, 32, 0);
142 pqisrc_show_sense_data_simple(softs, rcb, sense_data);
144 /* add more detail here as needed */
149 * Process the error info for AIO in the case of failure.
152 pqisrc_process_aio_response_error(pqisrc_softstate_t *softs,
153 rcb_t *rcb, uint16_t err_idx)
155 aio_path_error_info_elem_t *err_info = NULL;
159 err_info = (aio_path_error_info_elem_t*)
160 softs->err_buf_dma_mem.virt_addr +
163 if(err_info == NULL) {
164 DBG_ERR("err_info structure is NULL err_idx :%x", err_idx);
168 os_aio_response_error(rcb, err_info);
174 * Process the error info for RAID IO in the case of failure.
177 pqisrc_process_raid_response_error(pqisrc_softstate_t *softs,
178 rcb_t *rcb, uint16_t err_idx)
180 raid_path_error_info_elem_t *err_info = NULL;
184 err_info = (raid_path_error_info_elem_t*)
185 softs->err_buf_dma_mem.virt_addr +
188 if(err_info == NULL) {
189 DBG_ERR("err_info structure is NULL err_idx :%x", err_idx);
193 os_raid_response_error(rcb, err_info);
199 * Process the Task Management function response.
202 pqisrc_process_task_management_response(pqisrc_softstate_t *softs,
203 pqi_tmf_resp_t *tmf_resp)
205 int ret = REQUEST_SUCCESS;
206 uint32_t tag = (uint32_t)tmf_resp->req_id;
207 rcb_t *rcb = &softs->rcb[tag];
209 ASSERT(rcb->tag == tag);
213 switch (tmf_resp->resp_code) {
214 case SOP_TASK_MANAGEMENT_FUNCTION_COMPLETE:
215 case SOP_TASK_MANAGEMENT_FUNCTION_SUCCEEDED:
216 ret = REQUEST_SUCCESS;
219 DBG_WARN("TMF Failed, Response code : 0x%x\n", tmf_resp->resp_code);
220 ret = REQUEST_FAILED;
225 rcb->req_pending = false;
232 pqisrc_process_vendor_general_response(pqi_vendor_general_response_t *response)
235 int ret = REQUEST_SUCCESS;
237 switch(response->status) {
238 case PQI_VENDOR_RESPONSE_IU_SUCCESS:
240 case PQI_VENDOR_RESPONSE_IU_UNSUCCESS:
241 case PQI_VENDOR_RESPONSE_IU_INVALID_PARAM:
242 case PQI_VENDOR_RESPONSE_IU_INSUFF_RESRC:
243 ret = REQUEST_FAILED;
251 * Function used to process the response from the adapter
252 * which is invoked by IRQ handler.
255 pqisrc_process_response_queue(pqisrc_softstate_t *softs, int oq_id)
258 struct pqi_io_response *response;
259 uint32_t oq_pi, oq_ci;
260 pqi_scsi_dev_t *dvp = NULL;
264 ob_q = &softs->op_ob_q[oq_id - 1]; /* zero for event Q */
265 oq_ci = ob_q->ci_local;
266 oq_pi = *(ob_q->pi_virt_addr);
268 DBG_INFO("ci : %d pi : %d qid : %d\n", oq_ci, oq_pi, ob_q->q_id);
274 boolean_t os_scsi_cmd = false;
278 /* Get the response */
279 offset = oq_ci * ob_q->elem_size;
280 response = (struct pqi_io_response *)(ob_q->array_virt_addr +
282 tag = response->request_id;
283 rcb = &softs->rcb[tag];
284 /* Make sure we are processing a valid response. */
285 if ((rcb->tag != tag) || (rcb->req_pending == false)) {
286 DBG_ERR("No such request pending with tag : %x", tag);
287 oq_ci = (oq_ci + 1) % ob_q->num_elem;
290 /* Timedout request has been completed. This should not hit,
291 * if timeout is set as TIMEOUT_INFINITE while calling
292 * pqisrc_wait_on_condition(softs,rcb,timeout).
295 DBG_WARN("timed out request completing from firmware, driver already completed it with failure , free the tag %d\n", tag);
296 oq_ci = (oq_ci + 1) % ob_q->num_elem;
298 pqisrc_put_tag(&softs->taglist, tag);
302 if (IS_OS_SCSICMD(rcb)) {
307 DBG_WARN("Received IO completion for the Null device!!!\n");
311 DBG_INFO("response.header.iu_type : %x \n", response->header.iu_type);
313 switch (response->header.iu_type) {
314 case PQI_RESPONSE_IU_RAID_PATH_IO_SUCCESS:
315 case PQI_RESPONSE_IU_AIO_PATH_IO_SUCCESS:
316 rcb->success_cmp_callback(softs, rcb);
318 pqisrc_decrement_device_active_io(softs, dvp);
321 case PQI_RESPONSE_IU_RAID_PATH_IO_ERROR:
322 case PQI_RESPONSE_IU_AIO_PATH_IO_ERROR:
323 rcb->error_cmp_callback(softs, rcb, LE_16(response->error_index));
325 pqisrc_decrement_device_active_io(softs, dvp);
327 case PQI_RESPONSE_IU_GENERAL_MANAGEMENT:
328 rcb->req_pending = false;
330 case PQI_RESPONSE_IU_VENDOR_GENERAL:
331 rcb->req_pending = false;
332 rcb->status = pqisrc_process_vendor_general_response(
333 (pqi_vendor_general_response_t *)response);
335 case PQI_RESPONSE_IU_TASK_MANAGEMENT:
336 rcb->status = pqisrc_process_task_management_response(softs, (void *)response);
340 DBG_ERR("Invalid Response IU 0x%x\n",response->header.iu_type);
344 oq_ci = (oq_ci + 1) % ob_q->num_elem;
347 ob_q->ci_local = oq_ci;
348 PCI_MEM_PUT32(softs, ob_q->ci_register_abs,
349 ob_q->ci_register_offset, ob_q->ci_local );