2 * Copyright (c) 2018 Microsemi Corporation.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include "smartpqi_includes.h"
31 /* Validate the scsi sense response code */
32 static inline boolean_t pqisrc_scsi_sense_valid(const struct sense_header_scsi *sshdr)
41 return (sshdr->response_code & 0x70) == 0x70;
44 /* Initialize target ID pool for HBA/PDs */
45 void pqisrc_init_targetid_pool(pqisrc_softstate_t *softs)
47 int i, tid = PQI_MAX_PHYSICALS + PQI_MAX_LOGICALS - 1;
49 for(i = 0; i < PQI_MAX_PHYSICALS; i++) {
50 softs->tid_pool.tid[i] = tid--;
52 softs->tid_pool.index = i - 1;
55 int pqisrc_alloc_tid(pqisrc_softstate_t *softs)
57 if(softs->tid_pool.index <= -1) {
58 DBG_ERR("Target ID exhausted\n");
62 return softs->tid_pool.tid[softs->tid_pool.index--];
65 void pqisrc_free_tid(pqisrc_softstate_t *softs, int tid)
67 if(softs->tid_pool.index >= PQI_MAX_PHYSICALS) {
68 DBG_ERR("Target ID queue is full\n");
72 softs->tid_pool.index++;
73 softs->tid_pool.tid[softs->tid_pool.index] = tid;
76 /* Update scsi sense info to a local buffer*/
77 boolean_t pqisrc_update_scsi_sense(const uint8_t *buff, int len,
78 struct sense_header_scsi *header)
86 memset(header, 0, sizeof(struct sense_header_scsi));
88 header->response_code = (buff[0] & 0x7f);
90 if (!pqisrc_scsi_sense_valid(header))
93 if (header->response_code >= 0x72) {
94 /* descriptor format */
96 header->sense_key = (buff[1] & 0xf);
98 header->asc = buff[2];
100 header->ascq = buff[3];
102 header->additional_length = buff[7];
106 header->sense_key = (buff[2] & 0xf);
108 len = (len < (buff[7] + 8)) ?
111 header->asc = buff[12];
113 header->ascq = buff[13];
123 * Function used to build the internal raid request and analyze the response
125 int pqisrc_build_send_raid_request(pqisrc_softstate_t *softs, pqisrc_raid_req_t *request,
126 void *buff, size_t datasize, uint8_t cmd, uint16_t vpd_page, uint8_t *scsi3addr,
127 raid_path_error_info_elem_t *error_info)
131 int ret = PQI_STATUS_SUCCESS;
133 struct dma_mem device_mem;
136 ib_queue_t *ib_q = &softs->op_raid_ib_q[PQI_DEFAULT_IB_QUEUE];
137 ob_queue_t *ob_q = &softs->op_ob_q[PQI_DEFAULT_IB_QUEUE];
143 memset(&device_mem, 0, sizeof(struct dma_mem));
145 /* for TUR datasize: 0 buff: NULL */
147 device_mem.tag = "device_mem";
148 device_mem.size = datasize;
149 device_mem.align = PQISRC_DEFAULT_DMA_ALIGN;
151 ret = os_dma_mem_alloc(softs, &device_mem);
154 DBG_ERR("failed to allocate dma memory for device_mem return code %d\n", ret);
158 sgd = (sgt_t *)&request->sg_descriptors[0];
160 sgd->addr = device_mem.dma_addr;
162 sgd->flags = SG_FLAG_LAST;
165 /* Build raid path request */
166 request->header.iu_type = PQI_IU_TYPE_RAID_PATH_IO_REQUEST;
168 request->header.iu_length = LE_16(offsetof(pqisrc_raid_req_t,
169 sg_descriptors[1]) - PQI_REQUEST_HEADER_LENGTH);
170 request->buffer_length = LE_32(datasize);
171 memcpy(request->lun_number, scsi3addr, sizeof(request->lun_number));
172 request->task_attribute = SOP_TASK_ATTRIBUTE_SIMPLE;
173 request->additional_cdb_bytes_usage = PQI_ADDITIONAL_CDB_BYTES_0;
179 request->data_direction = SOP_DATA_DIR_TO_DEVICE;
181 if (vpd_page & VPD_PAGE) {
183 cdb[2] = (uint8_t)vpd_page;
185 cdb[4] = (uint8_t)datasize;
189 request->data_direction = SOP_DATA_DIR_TO_DEVICE;
191 if (cmd == SA_REPORT_PHYS)
192 cdb[1] = SA_REPORT_PHYS_EXTENDED;
194 cdb[1] = SA_REPORT_LOG_EXTENDED;
195 cdb[8] = (uint8_t)((datasize) >> 8);
196 cdb[9] = (uint8_t)datasize;
198 case TEST_UNIT_READY:
199 request->data_direction = SOP_DATA_DIR_NONE;
201 case SA_GET_RAID_MAP:
202 request->data_direction = SOP_DATA_DIR_TO_DEVICE;
203 cdb[0] = SA_CISS_READ;
205 cdb[8] = (uint8_t)((datasize) >> 8);
206 cdb[9] = (uint8_t)datasize;
209 request->data_direction = SOP_DATA_DIR_FROM_DEVICE;
210 memcpy(device_mem.virt_addr, buff, datasize);
212 cdb[6] = BMIC_CACHE_FLUSH;
213 cdb[7] = (uint8_t)((datasize) << 8);
214 cdb[8] = (uint8_t)((datasize) >> 8);
216 case BMIC_IDENTIFY_CONTROLLER:
217 case BMIC_IDENTIFY_PHYSICAL_DEVICE:
218 request->data_direction = SOP_DATA_DIR_TO_DEVICE;
221 cdb[7] = (uint8_t)((datasize) << 8);
222 cdb[8] = (uint8_t)((datasize) >> 8);
224 case BMIC_WRITE_HOST_WELLNESS:
225 request->data_direction = SOP_DATA_DIR_FROM_DEVICE;
226 memcpy(device_mem.virt_addr, buff, datasize);
229 cdb[7] = (uint8_t)((datasize) << 8);
230 cdb[8] = (uint8_t)((datasize) >> 8);
232 case BMIC_SENSE_SUBSYSTEM_INFORMATION:
233 request->data_direction = SOP_DATA_DIR_TO_DEVICE;
236 cdb[7] = (uint8_t)((datasize) << 8);
237 cdb[8] = (uint8_t)((datasize) >> 8);
240 DBG_ERR("unknown command 0x%x", cmd);
244 tag = pqisrc_get_tag(&softs->taglist);
245 if (INVALID_ELEM == tag) {
246 DBG_ERR("Tag not available\n");
247 ret = PQI_STATUS_FAILURE;
251 ((pqisrc_raid_req_t *)request)->request_id = tag;
252 ((pqisrc_raid_req_t *)request)->error_index = ((pqisrc_raid_req_t *)request)->request_id;
253 ((pqisrc_raid_req_t *)request)->response_queue_id = ob_q->q_id;
254 rcb = &softs->rcb[tag];
255 rcb->success_cmp_callback = pqisrc_process_internal_raid_response_success;
256 rcb->error_cmp_callback = pqisrc_process_internal_raid_response_error;
258 rcb->req_pending = true;
261 ret = pqisrc_submit_cmnd(softs, ib_q, request);
263 if (ret != PQI_STATUS_SUCCESS) {
264 DBG_ERR("Unable to submit command\n");
268 ret = pqisrc_wait_on_condition(softs, rcb);
269 if (ret != PQI_STATUS_SUCCESS) {
270 DBG_ERR("Internal RAID request timed out: cmd : 0x%c\n", cmd);
276 memcpy(buff, device_mem.virt_addr, datasize);
278 os_dma_mem_free(softs, &device_mem);
286 sizeof(*error_info));
288 if (error_info->data_out_result ==
289 PQI_RAID_DATA_IN_OUT_UNDERFLOW) {
290 ret = PQI_STATUS_SUCCESS;
293 DBG_DISC("Error!! Bus=%u Target=%u, Cmd=0x%x,"
294 "Ret=%d\n", BMIC_GET_LEVEL_2_BUS(scsi3addr),
295 BMIC_GET_LEVEL_TWO_TARGET(scsi3addr),
297 ret = PQI_STATUS_FAILURE;
302 ret = PQI_STATUS_SUCCESS;
303 memset(error_info, 0, sizeof(*error_info));
308 pqisrc_put_tag(&softs->taglist, ((pqisrc_raid_req_t *)request)->request_id);
313 DBG_ERR("Error!! Bus=%u Target=%u, Cmd=0x%x, Ret=%d\n",
314 BMIC_GET_LEVEL_2_BUS(scsi3addr), BMIC_GET_LEVEL_TWO_TARGET(scsi3addr),
317 pqisrc_put_tag(&softs->taglist, ((pqisrc_raid_req_t *)request)->request_id);
320 os_dma_mem_free(softs, &device_mem);
321 DBG_FUNC("FAILED \n");
325 /* common function used to send report physical and logical luns cmnds*/
326 static int pqisrc_report_luns(pqisrc_softstate_t *softs, uint8_t cmd,
327 void *buff, size_t buf_len)
330 pqisrc_raid_req_t request;
334 memset(&request, 0, sizeof(request));
335 ret = pqisrc_build_send_raid_request(softs, &request, buff,
336 buf_len, cmd, 0, (uint8_t *)RAID_CTLR_LUNID, NULL);
343 /* subroutine used to get physical and logical luns of the device */
344 static int pqisrc_get_physical_logical_luns(pqisrc_softstate_t *softs, uint8_t cmd,
345 reportlun_data_ext_t **buff, size_t *data_length)
350 size_t new_lun_list_length;
351 reportlun_data_ext_t *lun_data;
352 reportlun_header_t report_lun_header;
356 ret = pqisrc_report_luns(softs, cmd, &report_lun_header,
357 sizeof(report_lun_header));
360 DBG_ERR("failed return code: %d\n", ret);
363 list_len = BE_32(report_lun_header.list_length);
366 data_len = sizeof(reportlun_header_t) + list_len;
367 *data_length = data_len;
369 lun_data = os_mem_alloc(softs, data_len);
372 DBG_ERR("failed to allocate memory for lun_data\n");
373 return PQI_STATUS_FAILURE;
377 DBG_DISC("list_len is 0\n");
378 memcpy(lun_data, &report_lun_header, sizeof(report_lun_header));
382 ret = pqisrc_report_luns(softs, cmd, lun_data, data_len);
389 new_lun_list_length = BE_32(lun_data->header.list_length);
391 if (new_lun_list_length > list_len) {
392 list_len = new_lun_list_length;
393 os_mem_free(softs, (void *)lun_data, data_len);
403 os_mem_free(softs, (void *)lun_data, data_len);
409 * Function used to get physical and logical device list
411 static int pqisrc_get_phys_log_device_list(pqisrc_softstate_t *softs,
412 reportlun_data_ext_t **physical_dev_list,
413 reportlun_data_ext_t **logical_dev_list,
414 size_t *phys_data_length,
415 size_t *log_data_length)
417 int ret = PQI_STATUS_SUCCESS;
418 size_t logical_list_length;
419 size_t logdev_data_length;
421 reportlun_data_ext_t *local_logdev_list;
422 reportlun_data_ext_t *logdev_data;
423 reportlun_header_t report_lun_header;
427 ret = pqisrc_get_physical_logical_luns(softs, SA_REPORT_PHYS, physical_dev_list, phys_data_length);
429 DBG_ERR("report physical LUNs failed");
433 ret = pqisrc_get_physical_logical_luns(softs, SA_REPORT_LOG, logical_dev_list, log_data_length);
435 DBG_ERR("report logical LUNs failed");
439 logdev_data = *logical_dev_list;
442 logical_list_length =
443 BE_32(logdev_data->header.list_length);
445 memset(&report_lun_header, 0, sizeof(report_lun_header));
447 (reportlun_data_ext_t *)&report_lun_header;
448 logical_list_length = 0;
451 logdev_data_length = sizeof(reportlun_header_t) +
454 /* Adding LOGICAL device entry for controller */
455 local_logdev_list = os_mem_alloc(softs,
456 logdev_data_length + sizeof(reportlun_ext_entry_t));
457 if (!local_logdev_list) {
458 data_length = *log_data_length;
459 os_mem_free(softs, (char *)*logical_dev_list, data_length);
460 *logical_dev_list = NULL;
461 return PQI_STATUS_FAILURE;
464 memcpy(local_logdev_list, logdev_data, logdev_data_length);
465 memset((uint8_t *)local_logdev_list + logdev_data_length, 0,
466 sizeof(reportlun_ext_entry_t));
467 local_logdev_list->header.list_length = BE_32(logical_list_length +
468 sizeof(reportlun_ext_entry_t));
469 data_length = *log_data_length;
470 os_mem_free(softs, (char *)*logical_dev_list, data_length);
471 *log_data_length = logdev_data_length + sizeof(reportlun_ext_entry_t);
472 *logical_dev_list = local_logdev_list;
479 /* Subroutine used to set Bus-Target-Lun for the requested device */
480 static inline void pqisrc_set_btl(pqi_scsi_dev_t *device,
481 int bus, int target, int lun)
486 device->target = target;
492 inline boolean_t pqisrc_is_external_raid_device(pqi_scsi_dev_t *device)
494 return device->is_external_raid_device;
497 static inline boolean_t pqisrc_is_external_raid_addr(uint8_t *scsi3addr)
499 return scsi3addr[2] != 0;
502 /* Function used to assign Bus-Target-Lun for the requested device */
503 static void pqisrc_assign_btl(pqi_scsi_dev_t *device)
512 scsi3addr = device->scsi3addr;
513 lunid = GET_LE32(scsi3addr);
515 if (pqisrc_is_hba_lunid(scsi3addr)) {
516 /* The specified device is the controller. */
517 pqisrc_set_btl(device, PQI_HBA_BUS, PQI_CTLR_INDEX, lunid & 0x3fff);
518 device->target_lun_valid = true;
522 if (pqisrc_is_logical_device(device)) {
523 if (pqisrc_is_external_raid_device(device)) {
524 DBG_DISC("External Raid Device!!!");
525 bus = PQI_EXTERNAL_RAID_VOLUME_BUS;
526 target = (lunid >> 16) & 0x3fff;
529 bus = PQI_RAID_VOLUME_BUS;
531 target = lunid & 0x3fff;
533 pqisrc_set_btl(device, bus, target, lun);
534 device->target_lun_valid = true;
541 /* Build and send the internal INQUIRY command to particular device */
542 static int pqisrc_send_scsi_inquiry(pqisrc_softstate_t *softs,
543 uint8_t *scsi3addr, uint16_t vpd_page, uint8_t *buff, int buf_len)
545 int ret = PQI_STATUS_SUCCESS;
546 pqisrc_raid_req_t request;
547 raid_path_error_info_elem_t error_info;
551 memset(&request, 0, sizeof(request));
552 ret = pqisrc_build_send_raid_request(softs, &request, buff, buf_len,
553 SA_INQUIRY, vpd_page, scsi3addr, &error_info);
559 /* Function used to parse the sense information from response */
560 static void pqisrc_fetch_sense_info(const uint8_t *sense_data,
561 unsigned sense_data_length, uint8_t *sense_key, uint8_t *asc, uint8_t *ascq)
563 struct sense_header_scsi header;
571 if (pqisrc_update_scsi_sense(sense_data, sense_data_length, &header)) {
572 *sense_key = header.sense_key;
577 DBG_DISC("sense_key: %x asc: %x ascq: %x\n", *sense_key, *asc, *ascq);
582 /* Function used to validate volume offline status */
583 static uint8_t pqisrc_get_volume_offline_status(pqisrc_softstate_t *softs,
586 int ret = PQI_STATUS_SUCCESS;
587 uint8_t status = SA_LV_STATUS_VPD_UNSUPPORTED;
589 uint8_t *buff = NULL;
593 buff = os_mem_alloc(softs, 64);
595 return PQI_STATUS_FAILURE;
597 /* Get the size of the VPD return buff. */
598 ret = pqisrc_send_scsi_inquiry(softs, scsi3addr, VPD_PAGE | SA_VPD_LV_STATUS,
599 buff, SCSI_VPD_HEADER_LENGTH);
606 /* Now get the whole VPD buff. */
607 ret = pqisrc_send_scsi_inquiry(softs, scsi3addr, VPD_PAGE | SA_VPD_LV_STATUS,
608 buff, size + SCSI_VPD_HEADER_LENGTH);
615 os_mem_free(softs, (char *)buff, 64);
621 /* Determine offline status of a volume. Returns appropriate SA_LV_* status.*/
622 static uint8_t pqisrc_get_dev_vol_status(pqisrc_softstate_t *softs,
625 int ret = PQI_STATUS_SUCCESS;
627 unsigned sense_data_len;
633 pqisrc_raid_req_t request;
634 raid_path_error_info_elem_t error_info;
638 memset(&request, 0, sizeof(request));
639 ret = pqisrc_build_send_raid_request(softs, &request, NULL, 0,
640 TEST_UNIT_READY, 0, scsi3addr, &error_info);
644 sense_data = error_info.data;
645 sense_data_len = LE_16(error_info.sense_data_len);
647 if (sense_data_len > sizeof(error_info.data))
648 sense_data_len = sizeof(error_info.data);
650 pqisrc_fetch_sense_info(sense_data, sense_data_len, &sense_key, &asc,
653 scsi_status = error_info.status;
655 /* scsi status: "CHECK CONDN" / SK: "not ready" ? */
656 if (scsi_status != 2 ||
658 asc != ASC_LUN_NOT_READY) {
662 /* Determine the reason for not ready state. */
663 off_status = pqisrc_get_volume_offline_status(softs, scsi3addr);
665 DBG_DISC("offline_status 0x%x\n", off_status);
667 /* Keep volume offline in certain cases. */
668 switch (off_status) {
669 case SA_LV_UNDERGOING_ERASE:
670 case SA_LV_NOT_AVAILABLE:
671 case SA_LV_UNDERGOING_RPI:
672 case SA_LV_PENDING_RPI:
673 case SA_LV_ENCRYPTED_NO_KEY:
674 case SA_LV_PLAINTEXT_IN_ENCRYPT_ONLY_CONTROLLER:
675 case SA_LV_UNDERGOING_ENCRYPTION:
676 case SA_LV_UNDERGOING_ENCRYPTION_REKEYING:
677 case SA_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER:
679 case SA_LV_STATUS_VPD_UNSUPPORTED:
681 * If the VPD status page isn't available,
682 * use ASC/ASCQ to determine state.
684 if (ascq == ASCQ_LUN_NOT_READY_FORMAT_IN_PROGRESS ||
685 ascq == ASCQ_LUN_NOT_READY_INITIALIZING_CMD_REQ)
695 return SA_LV_STATUS_VPD_UNSUPPORTED;
698 /* Validate the RAID map parameters */
699 static int pqisrc_raid_map_validation(pqisrc_softstate_t *softs,
700 pqi_scsi_dev_t *device, pqisrc_raid_map_t *raid_map)
703 uint32_t raidmap_size;
704 uint32_t r5or6_blocks_per_row;
705 unsigned phys_dev_num;
706 unsigned num_raidmap_entries;
710 raidmap_size = LE_32(raid_map->structure_size);
711 if (raidmap_size < offsetof(pqisrc_raid_map_t, dev_data)) {
712 error_msg = "RAID map too small\n";
716 if (raidmap_size > sizeof(*raid_map)) {
717 error_msg = "RAID map too large\n";
721 phys_dev_num = LE_16(raid_map->layout_map_count) *
722 (LE_16(raid_map->data_disks_per_row) +
723 LE_16(raid_map->metadata_disks_per_row));
724 num_raidmap_entries = phys_dev_num *
725 LE_16(raid_map->row_cnt);
727 if (num_raidmap_entries > RAID_MAP_MAX_ENTRIES) {
728 error_msg = "invalid number of map entries in RAID map\n";
732 if (device->raid_level == SA_RAID_1) {
733 if (LE_16(raid_map->layout_map_count) != 2) {
734 error_msg = "invalid RAID-1 map\n";
737 } else if (device->raid_level == SA_RAID_ADM) {
738 if (LE_16(raid_map->layout_map_count) != 3) {
739 error_msg = "invalid RAID-1(ADM) map\n";
742 } else if ((device->raid_level == SA_RAID_5 ||
743 device->raid_level == SA_RAID_6) &&
744 LE_16(raid_map->layout_map_count) > 1) {
746 r5or6_blocks_per_row =
747 LE_16(raid_map->strip_size) *
748 LE_16(raid_map->data_disks_per_row);
749 if (r5or6_blocks_per_row == 0) {
750 error_msg = "invalid RAID-5 or RAID-6 map\n";
760 DBG_ERR("%s\n", error_msg);
761 return PQI_STATUS_FAILURE;
764 /* Get device raidmap for the requested device */
765 static int pqisrc_get_device_raidmap(pqisrc_softstate_t *softs,
766 pqi_scsi_dev_t *device)
768 int ret = PQI_STATUS_SUCCESS;
769 pqisrc_raid_req_t request;
770 pqisrc_raid_map_t *raid_map;
774 raid_map = os_mem_alloc(softs, sizeof(*raid_map));
776 return PQI_STATUS_FAILURE;
778 memset(&request, 0, sizeof(request));
779 ret = pqisrc_build_send_raid_request(softs, &request, raid_map, sizeof(*raid_map),
780 SA_GET_RAID_MAP, 0, device->scsi3addr, NULL);
783 DBG_ERR("error in build send raid req ret=%d\n", ret);
787 ret = pqisrc_raid_map_validation(softs, device, raid_map);
789 DBG_ERR("error in raid map validation ret=%d\n", ret);
793 device->raid_map = raid_map;
798 os_mem_free(softs, (char*)raid_map, sizeof(*raid_map));
799 DBG_FUNC("FAILED \n");
803 /* Get device ioaccel_status to validate the type of device */
804 static void pqisrc_get_dev_ioaccel_status(pqisrc_softstate_t *softs,
805 pqi_scsi_dev_t *device)
807 int ret = PQI_STATUS_SUCCESS;
809 uint8_t ioaccel_status;
813 buff = os_mem_alloc(softs, 64);
817 ret = pqisrc_send_scsi_inquiry(softs, device->scsi3addr,
818 VPD_PAGE | SA_VPD_LV_IOACCEL_STATUS, buff, 64);
820 DBG_ERR("error in send scsi inquiry ret=%d\n", ret);
824 ioaccel_status = buff[IOACCEL_STATUS_BYTE];
825 device->offload_config =
826 !!(ioaccel_status & OFFLOAD_CONFIGURED_BIT);
828 if (device->offload_config) {
829 device->offload_enabled_pending =
830 !!(ioaccel_status & OFFLOAD_ENABLED_BIT);
831 if (pqisrc_get_device_raidmap(softs, device))
832 device->offload_enabled_pending = false;
835 DBG_DISC("offload_config: 0x%x offload_enabled_pending: 0x%x \n",
836 device->offload_config, device->offload_enabled_pending);
839 os_mem_free(softs, (char*)buff, 64);
843 /* Get RAID level of requested device */
844 static void pqisrc_get_dev_raid_level(pqisrc_softstate_t *softs,
845 pqi_scsi_dev_t *device)
852 raid_level = SA_RAID_UNKNOWN;
854 buff = os_mem_alloc(softs, 64);
857 ret = pqisrc_send_scsi_inquiry(softs, device->scsi3addr,
858 VPD_PAGE | SA_VPD_LV_DEVICE_GEOMETRY, buff, 64);
860 raid_level = buff[8];
861 if (raid_level > SA_RAID_MAX)
862 raid_level = SA_RAID_UNKNOWN;
864 os_mem_free(softs, (char*)buff, 64);
867 device->raid_level = raid_level;
868 DBG_DISC("RAID LEVEL: %x \n", raid_level);
872 /* Parse the inquiry response and determine the type of device */
873 static int pqisrc_get_dev_data(pqisrc_softstate_t *softs,
874 pqi_scsi_dev_t *device)
876 int ret = PQI_STATUS_SUCCESS;
881 inq_buff = os_mem_alloc(softs, OBDR_TAPE_INQ_SIZE);
883 return PQI_STATUS_FAILURE;
885 /* Send an inquiry to the device to see what it is. */
886 ret = pqisrc_send_scsi_inquiry(softs, device->scsi3addr, 0, inq_buff,
890 pqisrc_sanitize_inquiry_string(&inq_buff[8], 8);
891 pqisrc_sanitize_inquiry_string(&inq_buff[16], 16);
893 device->devtype = inq_buff[0] & 0x1f;
894 memcpy(device->vendor, &inq_buff[8],
895 sizeof(device->vendor));
896 memcpy(device->model, &inq_buff[16],
897 sizeof(device->model));
898 DBG_DISC("DEV_TYPE: %x VENDOR: %s MODEL: %s\n", device->devtype, device->vendor, device->model);
900 if (pqisrc_is_logical_device(device) && device->devtype == DISK_DEVICE) {
901 if (pqisrc_is_external_raid_device(device)) {
902 device->raid_level = SA_RAID_UNKNOWN;
903 device->volume_status = SA_LV_OK;
904 device->volume_offline = false;
907 pqisrc_get_dev_raid_level(softs, device);
908 pqisrc_get_dev_ioaccel_status(softs, device);
909 device->volume_status = pqisrc_get_dev_vol_status(softs,
911 device->volume_offline = device->volume_status != SA_LV_OK;
916 * Check if this is a One-Button-Disaster-Recovery device
917 * by looking for "$DR-10" at offset 43 in the inquiry data.
919 device->is_obdr_device = (device->devtype == ROM_DEVICE &&
920 memcmp(&inq_buff[OBDR_SIG_OFFSET], OBDR_TAPE_SIG,
923 os_mem_free(softs, (char*)inq_buff, OBDR_TAPE_INQ_SIZE);
930 * BMIC (Basic Management And Interface Commands) command
931 * to get the controller identify params
933 static int pqisrc_identify_ctrl(pqisrc_softstate_t *softs,
934 bmic_ident_ctrl_t *buff)
936 int ret = PQI_STATUS_SUCCESS;
937 pqisrc_raid_req_t request;
941 memset(&request, 0, sizeof(request));
942 ret = pqisrc_build_send_raid_request(softs, &request, buff, sizeof(*buff),
943 BMIC_IDENTIFY_CONTROLLER, 0, (uint8_t *)RAID_CTLR_LUNID, NULL);
949 /* Get the adapter FW version using BMIC_IDENTIFY_CONTROLLER */
950 int pqisrc_get_ctrl_fw_version(pqisrc_softstate_t *softs)
952 int ret = PQI_STATUS_SUCCESS;
953 bmic_ident_ctrl_t *identify_ctrl;
957 identify_ctrl = os_mem_alloc(softs, sizeof(*identify_ctrl));
958 if (!identify_ctrl) {
959 DBG_ERR("failed to allocate memory for identify_ctrl\n");
960 return PQI_STATUS_FAILURE;
963 memset(identify_ctrl, 0, sizeof(*identify_ctrl));
965 ret = pqisrc_identify_ctrl(softs, identify_ctrl);
969 softs->fw_build_number = identify_ctrl->fw_build_number;
970 memcpy(softs->fw_version, identify_ctrl->fw_version,
971 sizeof(identify_ctrl->fw_version));
972 softs->fw_version[sizeof(identify_ctrl->fw_version)] = '\0';
973 snprintf(softs->fw_version +
974 strlen(softs->fw_version),
975 sizeof(softs->fw_version),
976 "-%u", identify_ctrl->fw_build_number);
978 os_mem_free(softs, (char *)identify_ctrl, sizeof(*identify_ctrl));
979 DBG_INIT("Firmware version: %s Firmware build number: %d\n", softs->fw_version, softs->fw_build_number);
984 /* BMIC command to determine scsi device identify params */
985 static int pqisrc_identify_physical_disk(pqisrc_softstate_t *softs,
986 pqi_scsi_dev_t *device,
987 bmic_ident_physdev_t *buff,
990 int ret = PQI_STATUS_SUCCESS;
991 uint16_t bmic_device_index;
992 pqisrc_raid_req_t request;
996 memset(&request, 0, sizeof(request));
997 bmic_device_index = BMIC_GET_DRIVE_NUMBER(device->scsi3addr);
998 request.cdb[2] = (uint8_t)bmic_device_index;
999 request.cdb[9] = (uint8_t)(bmic_device_index >> 8);
1001 ret = pqisrc_build_send_raid_request(softs, &request, buff, buf_len,
1002 BMIC_IDENTIFY_PHYSICAL_DEVICE, 0, (uint8_t *)RAID_CTLR_LUNID, NULL);
1008 * Function used to get the scsi device information using one of BMIC
1009 * BMIC_IDENTIFY_PHYSICAL_DEVICE
1011 static void pqisrc_get_physical_device_info(pqisrc_softstate_t *softs,
1012 pqi_scsi_dev_t *device,
1013 bmic_ident_physdev_t *id_phys)
1015 int ret = PQI_STATUS_SUCCESS;
1018 memset(id_phys, 0, sizeof(*id_phys));
1020 ret= pqisrc_identify_physical_disk(softs, device,
1021 id_phys, sizeof(*id_phys));
1023 device->queue_depth = PQI_PHYSICAL_DISK_DEFAULT_MAX_QUEUE_DEPTH;
1027 device->queue_depth =
1028 LE_16(id_phys->current_queue_depth_limit);
1029 device->device_type = id_phys->device_type;
1030 device->active_path_index = id_phys->active_path_number;
1031 device->path_map = id_phys->redundant_path_present_map;
1032 memcpy(&device->box,
1033 &id_phys->alternate_paths_phys_box_on_port,
1034 sizeof(device->box));
1035 memcpy(&device->phys_connector,
1036 &id_phys->alternate_paths_phys_connector,
1037 sizeof(device->phys_connector));
1038 device->bay = id_phys->phys_bay_in_box;
1040 DBG_DISC("BMIC DEV_TYPE: %x QUEUE DEPTH: 0x%x \n", device->device_type, device->queue_depth);
1044 /* Function used to find the entry of the device in a list */
1045 static device_status_t pqisrc_scsi_find_entry(pqisrc_softstate_t *softs,
1046 pqi_scsi_dev_t *device_to_find,
1047 pqi_scsi_dev_t **same_device)
1049 pqi_scsi_dev_t *device;
1052 for(i = 0; i < PQI_MAX_DEVICES; i++) {
1053 for(j = 0; j < PQI_MAX_MULTILUN; j++) {
1054 if(softs->device_list[i][j] == NULL)
1056 device = softs->device_list[i][j];
1057 if (pqisrc_scsi3addr_equal(device_to_find->scsi3addr,
1058 device->scsi3addr)) {
1059 *same_device = device;
1060 if (pqisrc_device_equal(device_to_find, device)) {
1061 if (device_to_find->volume_offline)
1062 return DEVICE_CHANGED;
1063 return DEVICE_UNCHANGED;
1065 return DEVICE_CHANGED;
1071 return DEVICE_NOT_FOUND;
1074 /* Update the newly added devices as existed device */
1075 static void pqisrc_exist_device_update(pqisrc_softstate_t *softs,
1076 pqi_scsi_dev_t *device_exist,
1077 pqi_scsi_dev_t *new_device)
1080 device_exist->expose_device = new_device->expose_device;
1081 memcpy(device_exist->vendor, new_device->vendor,
1082 sizeof(device_exist->vendor));
1083 memcpy(device_exist->model, new_device->model,
1084 sizeof(device_exist->model));
1085 device_exist->is_physical_device = new_device->is_physical_device;
1086 device_exist->is_external_raid_device =
1087 new_device->is_external_raid_device;
1088 device_exist->sas_address = new_device->sas_address;
1089 device_exist->raid_level = new_device->raid_level;
1090 device_exist->queue_depth = new_device->queue_depth;
1091 device_exist->ioaccel_handle = new_device->ioaccel_handle;
1092 device_exist->volume_status = new_device->volume_status;
1093 device_exist->active_path_index = new_device->active_path_index;
1094 device_exist->path_map = new_device->path_map;
1095 device_exist->bay = new_device->bay;
1096 memcpy(device_exist->box, new_device->box,
1097 sizeof(device_exist->box));
1098 memcpy(device_exist->phys_connector, new_device->phys_connector,
1099 sizeof(device_exist->phys_connector));
1100 device_exist->offload_config = new_device->offload_config;
1101 device_exist->offload_enabled = false;
1102 device_exist->offload_enabled_pending =
1103 new_device->offload_enabled_pending;
1104 device_exist->offload_to_mirror = 0;
1105 if (device_exist->raid_map)
1107 (char *)device_exist->raid_map,
1108 sizeof(*device_exist->raid_map));
1109 device_exist->raid_map = new_device->raid_map;
1110 /* To prevent this from being freed later. */
1111 new_device->raid_map = NULL;
1115 /* Validate the ioaccel_handle for a newly added device */
1116 static pqi_scsi_dev_t *pqisrc_identify_device_via_ioaccel(
1117 pqisrc_softstate_t *softs, uint32_t ioaccel_handle)
1119 pqi_scsi_dev_t *device;
1122 for(i = 0; i < PQI_MAX_DEVICES; i++) {
1123 for(j = 0; j < PQI_MAX_MULTILUN; j++) {
1124 if(softs->device_list[i][j] == NULL)
1126 device = softs->device_list[i][j];
1127 if (device->devtype != DISK_DEVICE)
1129 if (pqisrc_is_logical_device(device))
1131 if (device->ioaccel_handle == ioaccel_handle)
1140 /* Get the scsi device queue depth */
1141 static void pqisrc_update_log_dev_qdepth(pqisrc_softstate_t *softs)
1144 unsigned phys_dev_num;
1145 unsigned num_raidmap_entries;
1146 unsigned queue_depth;
1147 pqisrc_raid_map_t *raid_map;
1148 pqi_scsi_dev_t *device;
1149 raidmap_data_t *dev_data;
1150 pqi_scsi_dev_t *phys_disk;
1156 for(i = 0; i < PQI_MAX_DEVICES; i++) {
1157 for(j = 0; j < PQI_MAX_MULTILUN; j++) {
1158 if(softs->device_list[i][j] == NULL)
1160 device = softs->device_list[i][j];
1161 if (device->devtype != DISK_DEVICE)
1163 if (!pqisrc_is_logical_device(device))
1165 if (pqisrc_is_external_raid_device(device))
1167 device->queue_depth = PQI_LOGICAL_DISK_DEFAULT_MAX_QUEUE_DEPTH;
1168 raid_map = device->raid_map;
1171 dev_data = raid_map->dev_data;
1172 phys_dev_num = LE_16(raid_map->layout_map_count) *
1173 (LE_16(raid_map->data_disks_per_row) +
1174 LE_16(raid_map->metadata_disks_per_row));
1175 num_raidmap_entries = phys_dev_num *
1176 LE_16(raid_map->row_cnt);
1179 for (k = 0; k < num_raidmap_entries; k++) {
1180 phys_disk = pqisrc_identify_device_via_ioaccel(softs,
1181 dev_data[k].ioaccel_handle);
1185 "Failed to find physical disk handle for logical drive %016llx\n",
1186 (unsigned long long)BE_64(device->scsi3addr[0]));
1187 device->offload_enabled = false;
1188 device->offload_enabled_pending = false;
1190 os_mem_free(softs, (char *)raid_map, sizeof(*raid_map));
1191 device->raid_map = NULL;
1195 queue_depth += phys_disk->queue_depth;
1198 device->queue_depth = queue_depth;
1199 } /* end inner loop */
1200 }/* end outer loop */
1204 /* Function used to add a scsi device to OS scsi subsystem */
1205 static int pqisrc_add_device(pqisrc_softstate_t *softs,
1206 pqi_scsi_dev_t *device)
1209 DBG_DISC("vendor: %s model: %s bus:%d target:%d lun:%d is_physical_device:0x%x expose_device:0x%x volume_offline 0x%x volume_status 0x%x \n",
1210 device->vendor, device->model, device->bus, device->target, device->lun, device->is_physical_device, device->expose_device, device->volume_offline, device->volume_status);
1212 device->invalid = false;
1214 if(device->expose_device) {
1215 /* TBD: Call OS upper layer function to add the device entry */
1216 os_add_device(softs,device);
1219 return PQI_STATUS_SUCCESS;
1223 /* Function used to remove a scsi device from OS scsi subsystem */
1224 void pqisrc_remove_device(pqisrc_softstate_t *softs,
1225 pqi_scsi_dev_t *device)
1228 DBG_DISC("vendor: %s model: %s bus:%d target:%d lun:%d is_physical_device:0x%x expose_device:0x%x volume_offline 0x%x volume_status 0x%x \n",
1229 device->vendor, device->model, device->bus, device->target, device->lun, device->is_physical_device, device->expose_device, device->volume_offline, device->volume_status);
1231 /* TBD: Call OS upper layer function to remove the device entry */
1232 device->invalid = true;
1233 os_remove_device(softs,device);
1238 * When exposing new device to OS fails then adjst list according to the
1241 static void pqisrc_adjust_list(pqisrc_softstate_t *softs,
1242 pqi_scsi_dev_t *device)
1247 DBG_ERR("softs = %p: device is NULL !!!\n", softs);
1251 OS_ACQUIRE_SPINLOCK(&softs->devlist_lock);
1252 softs->device_list[device->target][device->lun] = NULL;
1253 OS_RELEASE_SPINLOCK(&softs->devlist_lock);
1254 pqisrc_device_mem_free(softs, device);
1259 /* Debug routine used to display the RAID volume status of the device */
1260 static void pqisrc_display_volume_status(pqisrc_softstate_t *softs,
1261 pqi_scsi_dev_t *device)
1266 switch (device->volume_status) {
1268 status = "Volume is online.";
1270 case SA_LV_UNDERGOING_ERASE:
1271 status = "Volume is undergoing background erase process.";
1273 case SA_LV_NOT_AVAILABLE:
1274 status = "Volume is waiting for transforming volume.";
1276 case SA_LV_UNDERGOING_RPI:
1277 status = "Volume is undergoing rapid parity initialization process.";
1279 case SA_LV_PENDING_RPI:
1280 status = "Volume is queued for rapid parity initialization process.";
1282 case SA_LV_ENCRYPTED_NO_KEY:
1283 status = "Volume is encrypted and cannot be accessed because key is not present.";
1285 case SA_LV_PLAINTEXT_IN_ENCRYPT_ONLY_CONTROLLER:
1286 status = "Volume is not encrypted and cannot be accessed because controller is in encryption-only mode.";
1288 case SA_LV_UNDERGOING_ENCRYPTION:
1289 status = "Volume is undergoing encryption process.";
1291 case SA_LV_UNDERGOING_ENCRYPTION_REKEYING:
1292 status = "Volume is undergoing encryption re-keying process.";
1294 case SA_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER:
1295 status = "Volume is encrypted and cannot be accessed because controller does not have encryption enabled.";
1297 case SA_LV_PENDING_ENCRYPTION:
1298 status = "Volume is pending migration to encrypted state, but process has not started.";
1300 case SA_LV_PENDING_ENCRYPTION_REKEYING:
1301 status = "Volume is encrypted and is pending encryption rekeying.";
1303 case SA_LV_STATUS_VPD_UNSUPPORTED:
1304 status = "Volume status is not available through vital product data pages.";
1307 status = "Volume is in an unknown state.";
1311 DBG_DISC("scsi BTL %d:%d:%d %s\n",
1312 device->bus, device->target, device->lun, status);
1316 void pqisrc_device_mem_free(pqisrc_softstate_t *softs, pqi_scsi_dev_t *device)
1321 if (device->raid_map) {
1322 os_mem_free(softs, (char *)device->raid_map, sizeof(pqisrc_raid_map_t));
1324 os_mem_free(softs, (char *)device,sizeof(*device));
1329 /* OS should call this function to free the scsi device */
1330 void pqisrc_free_device(pqisrc_softstate_t * softs,pqi_scsi_dev_t *device)
1333 OS_ACQUIRE_SPINLOCK(&softs->devlist_lock);
1334 if (!pqisrc_is_logical_device(device)) {
1335 pqisrc_free_tid(softs,device->target);
1337 pqisrc_device_mem_free(softs, device);
1338 OS_RELEASE_SPINLOCK(&softs->devlist_lock);
1342 /* Update the newly added devices to the device list */
1343 static void pqisrc_update_device_list(pqisrc_softstate_t *softs,
1344 pqi_scsi_dev_t *new_device_list[], int num_new_devices)
1348 device_status_t dev_status;
1349 pqi_scsi_dev_t *device;
1350 pqi_scsi_dev_t *same_device;
1351 pqi_scsi_dev_t **added = NULL;
1352 pqi_scsi_dev_t **removed = NULL;
1353 int nadded = 0, nremoved = 0;
1359 added = os_mem_alloc(softs, sizeof(*added) * PQI_MAX_DEVICES);
1360 removed = os_mem_alloc(softs, sizeof(*removed) * PQI_MAX_DEVICES);
1362 if (!added || !removed) {
1363 DBG_WARN("Out of memory \n");
1367 OS_ACQUIRE_SPINLOCK(&softs->devlist_lock);
1369 for(i = 0; i < PQI_MAX_DEVICES; i++) {
1370 for(j = 0; j < PQI_MAX_MULTILUN; j++) {
1371 if(softs->device_list[i][j] == NULL)
1373 device = softs->device_list[i][j];
1374 device->device_gone = true;
1377 DBG_IO("Device list used an array\n");
1378 for (i = 0; i < num_new_devices; i++) {
1379 device = new_device_list[i];
1381 dev_status = pqisrc_scsi_find_entry(softs, device,
1384 switch (dev_status) {
1385 case DEVICE_UNCHANGED:
1386 /* New Device present in existing device list */
1387 device->new_device = false;
1388 same_device->device_gone = false;
1389 pqisrc_exist_device_update(softs, same_device, device);
1391 case DEVICE_NOT_FOUND:
1392 /* Device not found in existing list */
1393 device->new_device = true;
1395 case DEVICE_CHANGED:
1396 /* Actual device gone need to add device to list*/
1397 device->new_device = true;
1403 /* Process all devices that have gone away. */
1404 for(i = 0, nremoved = 0; i < PQI_MAX_DEVICES; i++) {
1405 for(j = 0; j < PQI_MAX_MULTILUN; j++) {
1406 if(softs->device_list[i][j] == NULL)
1408 device = softs->device_list[i][j];
1409 if (device->device_gone) {
1410 softs->device_list[device->target][device->lun] = NULL;
1411 removed[nremoved] = device;
1417 /* Process all new devices. */
1418 for (i = 0, nadded = 0; i < num_new_devices; i++) {
1419 device = new_device_list[i];
1420 if (!device->new_device)
1422 if (device->volume_offline)
1425 /* physical device */
1426 if (!pqisrc_is_logical_device(device)) {
1427 tid = pqisrc_alloc_tid(softs);
1428 if(INVALID_ELEM != tid)
1429 pqisrc_set_btl(device, PQI_PHYSICAL_DEVICE_BUS, tid, 0);
1432 softs->device_list[device->target][device->lun] = device;
1433 DBG_DISC("Added device %p at B : %d T : %d L : %d\n",device,
1434 device->bus,device->target,device->lun);
1435 /* To prevent this entry from being freed later. */
1436 new_device_list[i] = NULL;
1437 added[nadded] = device;
1441 pqisrc_update_log_dev_qdepth(softs);
1443 for(i = 0; i < PQI_MAX_DEVICES; i++) {
1444 for(j = 0; j < PQI_MAX_MULTILUN; j++) {
1445 if(softs->device_list[i][j] == NULL)
1447 device = softs->device_list[i][j];
1448 device->offload_enabled = device->offload_enabled_pending;
1452 OS_RELEASE_SPINLOCK(&softs->devlist_lock);
1454 for(i = 0; i < nremoved; i++) {
1455 device = removed[i];
1458 pqisrc_remove_device(softs, device);
1459 pqisrc_display_device_info(softs, "removed", device);
1463 for(i = 0; i < PQI_MAX_DEVICES; i++) {
1464 for(j = 0; j < PQI_MAX_MULTILUN; j++) {
1465 if(softs->device_list[i][j] == NULL)
1467 device = softs->device_list[i][j];
1469 * Notify the OS upper layer if the queue depth of any existing device has
1472 if (device->queue_depth !=
1473 device->advertised_queue_depth) {
1474 device->advertised_queue_depth = device->queue_depth;
1475 /* TBD: Call OS upper layer function to change device Q depth */
1479 for(i = 0; i < nadded; i++) {
1481 if (device->expose_device) {
1482 ret = pqisrc_add_device(softs, device);
1484 DBG_WARN("scsi %d:%d:%d addition failed, device not added\n",
1485 device->bus, device->target,
1487 pqisrc_adjust_list(softs, device);
1492 pqisrc_display_device_info(softs, "added", device);
1495 /* Process all volumes that are offline. */
1496 for (i = 0; i < num_new_devices; i++) {
1497 device = new_device_list[i];
1500 if (!device->new_device)
1502 if (device->volume_offline) {
1503 pqisrc_display_volume_status(softs, device);
1504 pqisrc_display_device_info(softs, "offline", device);
1510 os_mem_free(softs, (char *)added,
1511 sizeof(*added) * PQI_MAX_DEVICES);
1513 os_mem_free(softs, (char *)removed,
1514 sizeof(*removed) * PQI_MAX_DEVICES);
1520 * Let the Adapter know about driver version using one of BMIC
1521 * BMIC_WRITE_HOST_WELLNESS
1523 int pqisrc_write_driver_version_to_host_wellness(pqisrc_softstate_t *softs)
1525 int rval = PQI_STATUS_SUCCESS;
1526 struct bmic_host_wellness_driver_version *host_wellness_driver_ver;
1528 pqisrc_raid_req_t request;
1532 memset(&request, 0, sizeof(request));
1533 data_length = sizeof(*host_wellness_driver_ver);
1535 host_wellness_driver_ver = os_mem_alloc(softs, data_length);
1536 if (!host_wellness_driver_ver) {
1537 DBG_ERR("failed to allocate memory for host wellness driver_version\n");
1538 return PQI_STATUS_FAILURE;
1541 host_wellness_driver_ver->start_tag[0] = '<';
1542 host_wellness_driver_ver->start_tag[1] = 'H';
1543 host_wellness_driver_ver->start_tag[2] = 'W';
1544 host_wellness_driver_ver->start_tag[3] = '>';
1545 host_wellness_driver_ver->driver_version_tag[0] = 'D';
1546 host_wellness_driver_ver->driver_version_tag[1] = 'V';
1547 host_wellness_driver_ver->driver_version_length = LE_16(sizeof(host_wellness_driver_ver->driver_version));
1548 strncpy(host_wellness_driver_ver->driver_version, softs->os_name,
1549 sizeof(host_wellness_driver_ver->driver_version));
1550 if (strlen(softs->os_name) < sizeof(host_wellness_driver_ver->driver_version) ) {
1551 strncpy(host_wellness_driver_ver->driver_version + strlen(softs->os_name), PQISRC_DRIVER_VERSION,
1552 sizeof(host_wellness_driver_ver->driver_version) - strlen(softs->os_name));
1554 DBG_DISC("OS name length(%lu) is longer than buffer of driver_version\n",
1555 strlen(softs->os_name));
1557 host_wellness_driver_ver->driver_version[sizeof(host_wellness_driver_ver->driver_version) - 1] = '\0';
1558 host_wellness_driver_ver->end_tag[0] = 'Z';
1559 host_wellness_driver_ver->end_tag[1] = 'Z';
1561 rval = pqisrc_build_send_raid_request(softs, &request, host_wellness_driver_ver,data_length,
1562 BMIC_WRITE_HOST_WELLNESS, 0, (uint8_t *)RAID_CTLR_LUNID, NULL);
1564 os_mem_free(softs, (char *)host_wellness_driver_ver, data_length);
1571 * Write current RTC time from host to the adapter using
1572 * BMIC_WRITE_HOST_WELLNESS
1574 int pqisrc_write_current_time_to_host_wellness(pqisrc_softstate_t *softs)
1576 int rval = PQI_STATUS_SUCCESS;
1577 struct bmic_host_wellness_time *host_wellness_time;
1579 pqisrc_raid_req_t request;
1583 memset(&request, 0, sizeof(request));
1584 data_length = sizeof(*host_wellness_time);
1586 host_wellness_time = os_mem_alloc(softs, data_length);
1587 if (!host_wellness_time) {
1588 DBG_ERR("failed to allocate memory for host wellness time structure\n");
1589 return PQI_STATUS_FAILURE;
1592 host_wellness_time->start_tag[0] = '<';
1593 host_wellness_time->start_tag[1] = 'H';
1594 host_wellness_time->start_tag[2] = 'W';
1595 host_wellness_time->start_tag[3] = '>';
1596 host_wellness_time->time_tag[0] = 'T';
1597 host_wellness_time->time_tag[1] = 'D';
1598 host_wellness_time->time_length = LE_16(offsetof(struct bmic_host_wellness_time, time_length) -
1599 offsetof(struct bmic_host_wellness_time, century));
1601 os_get_time(host_wellness_time);
1603 host_wellness_time->dont_write_tag[0] = 'D';
1604 host_wellness_time->dont_write_tag[1] = 'W';
1605 host_wellness_time->end_tag[0] = 'Z';
1606 host_wellness_time->end_tag[1] = 'Z';
1608 rval = pqisrc_build_send_raid_request(softs, &request, host_wellness_time,data_length,
1609 BMIC_WRITE_HOST_WELLNESS, 0, (uint8_t *)RAID_CTLR_LUNID, NULL);
1611 os_mem_free(softs, (char *)host_wellness_time, data_length);
1618 * Function used to perform a rescan of scsi devices
1619 * for any config change events
1621 int pqisrc_scan_devices(pqisrc_softstate_t *softs)
1623 boolean_t is_physical_device;
1624 int ret = PQI_STATUS_FAILURE;
1627 int phy_log_dev_cnt;
1629 uint32_t physical_cnt;
1630 uint32_t logical_cnt;
1631 uint32_t ndev_allocated = 0;
1632 size_t phys_data_length, log_data_length;
1633 reportlun_data_ext_t *physical_dev_list = NULL;
1634 reportlun_data_ext_t *logical_dev_list = NULL;
1635 reportlun_ext_entry_t *lun_ext_entry = NULL;
1636 bmic_ident_physdev_t *bmic_phy_info = NULL;
1637 pqi_scsi_dev_t **new_device_list = NULL;
1638 pqi_scsi_dev_t *device = NULL;
1642 ret = pqisrc_get_phys_log_device_list(softs, &physical_dev_list, &logical_dev_list,
1643 &phys_data_length, &log_data_length);
1648 physical_cnt = BE_32(physical_dev_list->header.list_length)
1649 / sizeof(physical_dev_list->lun_entries[0]);
1651 logical_cnt = BE_32(logical_dev_list->header.list_length)
1652 / sizeof(logical_dev_list->lun_entries[0]);
1654 DBG_DISC("physical_cnt %d logical_cnt %d\n", physical_cnt, logical_cnt);
1657 bmic_phy_info = os_mem_alloc(softs, sizeof(*bmic_phy_info));
1658 if (bmic_phy_info == NULL) {
1659 ret = PQI_STATUS_FAILURE;
1660 DBG_ERR("failed to allocate memory for BMIC ID PHYS Device : %d\n", ret);
1664 phy_log_dev_cnt = physical_cnt + logical_cnt;
1665 new_device_list = os_mem_alloc(softs,
1666 sizeof(*new_device_list) * phy_log_dev_cnt);
1668 if (new_device_list == NULL) {
1669 ret = PQI_STATUS_FAILURE;
1670 DBG_ERR("failed to allocate memory for device list : %d\n", ret);
1674 for (i = 0; i < phy_log_dev_cnt; i++) {
1675 new_device_list[i] = os_mem_alloc(softs,
1676 sizeof(*new_device_list[i]));
1677 if (new_device_list[i] == NULL) {
1678 ret = PQI_STATUS_FAILURE;
1679 DBG_ERR("failed to allocate memory for device list : %d\n", ret);
1685 ndev_allocated = phy_log_dev_cnt;
1687 for (i = 0; i < phy_log_dev_cnt; i++) {
1688 if (i < physical_cnt) {
1689 is_physical_device = true;
1690 lun_ext_entry = &physical_dev_list->lun_entries[i];
1692 is_physical_device = false;
1694 &logical_dev_list->lun_entries[i - physical_cnt];
1697 scsi3addr = lun_ext_entry->lunid;
1698 /* Save the target sas adderess for external raid device */
1699 if(lun_ext_entry->device_type == CONTROLLER_DEVICE) {
1700 int target = lun_ext_entry->lunid[3] & 0x3f;
1701 softs->target_sas_addr[target] = BE_64(lun_ext_entry->wwid);
1704 /* Skip masked physical non-disk devices. */
1705 if (MASKED_DEVICE(scsi3addr) && is_physical_device
1706 && (lun_ext_entry->ioaccel_handle == 0))
1709 device = new_device_list[new_dev_cnt];
1710 memset(device, 0, sizeof(*device));
1711 memcpy(device->scsi3addr, scsi3addr, sizeof(device->scsi3addr));
1712 device->wwid = lun_ext_entry->wwid;
1713 device->is_physical_device = is_physical_device;
1714 if (!is_physical_device)
1715 device->is_external_raid_device =
1716 pqisrc_is_external_raid_addr(scsi3addr);
1719 /* Get device type, vendor, model, device ID. */
1720 ret = pqisrc_get_dev_data(softs, device);
1722 DBG_WARN("Inquiry failed, skipping device %016llx\n",
1723 (unsigned long long)BE_64(device->scsi3addr[0]));
1724 DBG_DISC("INQUIRY FAILED \n");
1727 pqisrc_assign_btl(device);
1730 * Expose all devices except for physical devices that
1733 if (device->is_physical_device &&
1734 MASKED_DEVICE(scsi3addr))
1735 device->expose_device = false;
1737 device->expose_device = true;
1739 if (device->is_physical_device &&
1740 (lun_ext_entry->device_flags &
1741 REPORT_LUN_DEV_FLAG_AIO_ENABLED) &&
1742 lun_ext_entry->ioaccel_handle) {
1743 device->aio_enabled = true;
1745 switch (device->devtype) {
1748 * We don't *really* support actual CD-ROM devices,
1749 * but we do support the HP "One Button Disaster
1750 * Recovery" tape drive which temporarily pretends to
1751 * be a CD-ROM drive.
1753 if (device->is_obdr_device)
1758 if (device->is_physical_device) {
1759 device->ioaccel_handle =
1760 lun_ext_entry->ioaccel_handle;
1761 device->sas_address = BE_64(lun_ext_entry->wwid);
1762 pqisrc_get_physical_device_info(softs, device,
1767 case ENCLOSURE_DEVICE:
1768 if (device->is_physical_device) {
1769 device->sas_address = BE_64(lun_ext_entry->wwid);
1774 case MEDIUM_CHANGER_DEVICE:
1779 * Only present the HBA controller itself as a RAID
1780 * controller. If it's a RAID controller other than
1781 * the HBA itself (an external RAID controller, MSA500
1782 * or similar), don't present it.
1784 if (pqisrc_is_hba_lunid(scsi3addr))
1788 case CONTROLLER_DEVICE:
1792 DBG_DISC("new_dev_cnt %d\n", new_dev_cnt);
1794 pqisrc_update_device_list(softs, new_device_list, new_dev_cnt);
1797 if (new_device_list) {
1798 for (i = 0; i < ndev_allocated; i++) {
1799 if (new_device_list[i]) {
1800 if(new_device_list[i]->raid_map)
1801 os_mem_free(softs, (char *)new_device_list[i]->raid_map,
1802 sizeof(pqisrc_raid_map_t));
1803 os_mem_free(softs, (char*)new_device_list[i],
1804 sizeof(*new_device_list[i]));
1807 os_mem_free(softs, (char *)new_device_list,
1808 sizeof(*new_device_list) * ndev_allocated);
1810 if(physical_dev_list)
1811 os_mem_free(softs, (char *)physical_dev_list, phys_data_length);
1812 if(logical_dev_list)
1813 os_mem_free(softs, (char *)logical_dev_list, log_data_length);
1815 os_mem_free(softs, (char *)bmic_phy_info, sizeof(*bmic_phy_info));
1823 * Clean up memory allocated for devices.
1825 void pqisrc_cleanup_devices(pqisrc_softstate_t *softs)
1829 pqi_scsi_dev_t *dvp = NULL;
1832 for(i = 0; i < PQI_MAX_DEVICES; i++) {
1833 for(j = 0; j < PQI_MAX_MULTILUN; j++) {
1834 if (softs->device_list[i][j] == NULL)
1836 dvp = softs->device_list[i][j];
1837 pqisrc_device_mem_free(softs, dvp);