Lines Matching +full:mgmt +full:- +full:sticky

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * pmcraid.c -- driver for PMC Sierra MaxRAID controller adapters
5 * Written By: Anil Ravindranath<anil_ravindranath@pmc-sierra.com>
6 * PMC-Sierra Inc
54 * pmcraid_adapter_count - count of configured adapters
59 * Supporting user-level control interface through IOCTL commands.
60 * pmcraid_major - major number to use
61 * pmcraid_minor - minor number(s) to use
72 MODULE_AUTHOR("Anil Ravindranath<anil_ravindranath@pmc-sierra.com>");
79 "Enables firmware error code logging, default :1 high-severity"
80 " errors, 2: all errors including high-severity errors,"
128 * pmcraid_slave_alloc - Prepare for commands to a device
131 * This function is called by mid-layer prior to sending any command to the new
137 * 0 on success / -ENXIO if device does not exist
145 int rc = -ENXIO; in pmcraid_slave_alloc()
148 pinstance = shost_priv(scsi_dev->host); in pmcraid_slave_alloc()
150 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_slave_alloc()
157 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_slave_alloc()
158 list_for_each_entry(temp, &pinstance->used_res_q, queue) { in pmcraid_slave_alloc()
160 /* do not expose VSETs with order-ids > MAX_VSET_TARGETS */ in pmcraid_slave_alloc()
161 if (RES_IS_VSET(temp->cfg_entry)) { in pmcraid_slave_alloc()
163 target = temp->cfg_entry.unique_flags1; in pmcraid_slave_alloc()
165 target = le16_to_cpu(temp->cfg_entry.array_id) & 0xFF; in pmcraid_slave_alloc()
171 } else if (RES_IS_GSCSI(temp->cfg_entry)) { in pmcraid_slave_alloc()
172 target = RES_TARGET(temp->cfg_entry.resource_address); in pmcraid_slave_alloc()
174 lun = RES_LUN(temp->cfg_entry.resource_address); in pmcraid_slave_alloc()
179 if (bus == scsi_dev->channel && in pmcraid_slave_alloc()
180 target == scsi_dev->id && in pmcraid_slave_alloc()
181 lun == scsi_dev->lun) { in pmcraid_slave_alloc()
188 res->scsi_dev = scsi_dev; in pmcraid_slave_alloc()
189 scsi_dev->hostdata = res; in pmcraid_slave_alloc()
190 res->change_detected = 0; in pmcraid_slave_alloc()
191 atomic_set(&res->read_failures, 0); in pmcraid_slave_alloc()
192 atomic_set(&res->write_failures, 0); in pmcraid_slave_alloc()
195 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_slave_alloc()
200 * pmcraid_device_configure - Configures a SCSI device
206 * timeout value (default 30s) will be over-written to a higher value (60s)
207 * and max_sectors value will be over-written to 512. It also sets queue depth
208 * to host->cmd_per_lun value
216 struct pmcraid_resource_entry *res = scsi_dev->hostdata; in pmcraid_device_configure()
222 if (RES_IS_GSCSI(res->cfg_entry) && in pmcraid_device_configure()
223 scsi_dev->type != TYPE_ENCLOSURE) in pmcraid_device_configure()
224 return -ENXIO; in pmcraid_device_configure()
227 scsi_dev->host->unique_id, in pmcraid_device_configure()
228 scsi_dev->channel, in pmcraid_device_configure()
229 scsi_dev->id, in pmcraid_device_configure()
230 (u8)scsi_dev->lun); in pmcraid_device_configure()
232 if (RES_IS_GSCSI(res->cfg_entry)) { in pmcraid_device_configure()
233 scsi_dev->allow_restart = 1; in pmcraid_device_configure()
234 } else if (RES_IS_VSET(res->cfg_entry)) { in pmcraid_device_configure()
235 scsi_dev->allow_restart = 1; in pmcraid_device_configure()
236 blk_queue_rq_timeout(scsi_dev->request_queue, in pmcraid_device_configure()
238 lim->max_hw_sectors = PMCRAID_VSET_MAX_SECTORS; in pmcraid_device_configure()
244 if (!RES_IS_GSCSI(res->cfg_entry) && !RES_IS_VSET(res->cfg_entry)) in pmcraid_device_configure()
245 scsi_dev->tagged_supported = 0; in pmcraid_device_configure()
251 * pmcraid_slave_destroy - Unconfigure a SCSI device before removing it
255 * This is called by mid-layer before removing a device. Pointer assignments
265 res = (struct pmcraid_resource_entry *)scsi_dev->hostdata; in pmcraid_slave_destroy()
268 res->scsi_dev = NULL; in pmcraid_slave_destroy()
270 scsi_dev->hostdata = NULL; in pmcraid_slave_destroy()
274 * pmcraid_change_queue_depth - Change the device's queue depth
289 * pmcraid_init_cmdblk - initializes a command block
299 struct pmcraid_ioarcb *ioarcb = &(cmd->ioa_cb->ioarcb); in pmcraid_init_cmdblk()
300 dma_addr_t dma_addr = cmd->ioa_cb_bus_addr; in pmcraid_init_cmdblk()
307 cmd->index = index; in pmcraid_init_cmdblk()
308 ioarcb->response_handle = cpu_to_le32(index << 2); in pmcraid_init_cmdblk()
309 ioarcb->ioarcb_bus_addr = cpu_to_le64(dma_addr); in pmcraid_init_cmdblk()
310 ioarcb->ioasa_bus_addr = cpu_to_le64(dma_addr + ioasa_offset); in pmcraid_init_cmdblk()
311 ioarcb->ioasa_len = cpu_to_le16(sizeof(struct pmcraid_ioasa)); in pmcraid_init_cmdblk()
313 /* re-initialization of various lengths, called once command is in pmcraid_init_cmdblk()
316 memset(&cmd->ioa_cb->ioarcb.cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_init_cmdblk()
317 ioarcb->hrrq_id = 0; in pmcraid_init_cmdblk()
318 ioarcb->request_flags0 = 0; in pmcraid_init_cmdblk()
319 ioarcb->request_flags1 = 0; in pmcraid_init_cmdblk()
320 ioarcb->cmd_timeout = 0; in pmcraid_init_cmdblk()
321 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~0x1FULL); in pmcraid_init_cmdblk()
322 ioarcb->ioadl_bus_addr = 0; in pmcraid_init_cmdblk()
323 ioarcb->ioadl_length = 0; in pmcraid_init_cmdblk()
324 ioarcb->data_transfer_length = 0; in pmcraid_init_cmdblk()
325 ioarcb->add_cmd_param_length = 0; in pmcraid_init_cmdblk()
326 ioarcb->add_cmd_param_offset = 0; in pmcraid_init_cmdblk()
327 cmd->ioa_cb->ioasa.ioasc = 0; in pmcraid_init_cmdblk()
328 cmd->ioa_cb->ioasa.residual_data_length = 0; in pmcraid_init_cmdblk()
329 cmd->time_left = 0; in pmcraid_init_cmdblk()
332 cmd->cmd_done = NULL; in pmcraid_init_cmdblk()
333 cmd->scsi_cmd = NULL; in pmcraid_init_cmdblk()
334 cmd->release = 0; in pmcraid_init_cmdblk()
335 cmd->completion_req = 0; in pmcraid_init_cmdblk()
336 cmd->sense_buffer = NULL; in pmcraid_init_cmdblk()
337 cmd->sense_buffer_dma = 0; in pmcraid_init_cmdblk()
338 cmd->dma_handle = 0; in pmcraid_init_cmdblk()
339 timer_setup(&cmd->timer, NULL, 0); in pmcraid_init_cmdblk()
343 * pmcraid_reinit_cmdblk - reinitialize a command block
352 pmcraid_init_cmdblk(cmd, -1); in pmcraid_reinit_cmdblk()
356 * pmcraid_get_free_cmd - get a free cmd block from command block pool
370 spin_lock_irqsave(&pinstance->free_pool_lock, lock_flags); in pmcraid_get_free_cmd()
372 if (!list_empty(&pinstance->free_cmd_pool)) { in pmcraid_get_free_cmd()
373 cmd = list_entry(pinstance->free_cmd_pool.next, in pmcraid_get_free_cmd()
375 list_del(&cmd->free_list); in pmcraid_get_free_cmd()
377 spin_unlock_irqrestore(&pinstance->free_pool_lock, lock_flags); in pmcraid_get_free_cmd()
386 * pmcraid_return_cmd - return a completed command block back into free pool
394 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_return_cmd()
397 spin_lock_irqsave(&pinstance->free_pool_lock, lock_flags); in pmcraid_return_cmd()
398 list_add_tail(&cmd->free_list, &pinstance->free_cmd_pool); in pmcraid_return_cmd()
399 spin_unlock_irqrestore(&pinstance->free_pool_lock, lock_flags); in pmcraid_return_cmd()
403 * pmcraid_read_interrupts - reads IOA interrupts
412 return (pinstance->interrupt_mode) ? in pmcraid_read_interrupts()
413 ioread32(pinstance->int_regs.ioa_host_msix_interrupt_reg) : in pmcraid_read_interrupts()
414 ioread32(pinstance->int_regs.ioa_host_interrupt_reg); in pmcraid_read_interrupts()
418 * pmcraid_disable_interrupts - Masks and clears all specified interrupts
431 u32 gmask = ioread32(pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_disable_interrupts()
434 iowrite32(intrs, pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_disable_interrupts()
435 iowrite32(nmask, pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_disable_interrupts()
436 ioread32(pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_disable_interrupts()
438 if (!pinstance->interrupt_mode) { in pmcraid_disable_interrupts()
440 pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_disable_interrupts()
441 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_disable_interrupts()
446 * pmcraid_enable_interrupts - Enables specified interrupts
458 u32 gmask = ioread32(pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_enable_interrupts()
461 iowrite32(nmask, pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_enable_interrupts()
463 if (!pinstance->interrupt_mode) { in pmcraid_enable_interrupts()
465 pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_enable_interrupts()
466 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_enable_interrupts()
470 ioread32(pinstance->int_regs.global_interrupt_mask_reg), in pmcraid_enable_interrupts()
471 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg)); in pmcraid_enable_interrupts()
475 * pmcraid_clr_trans_op - clear trans to op interrupt
488 if (!pinstance->interrupt_mode) { in pmcraid_clr_trans_op()
490 pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_clr_trans_op()
491 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_clr_trans_op()
493 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_clr_trans_op()
494 ioread32(pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_clr_trans_op()
497 if (pinstance->reset_cmd != NULL) { in pmcraid_clr_trans_op()
498 del_timer(&pinstance->reset_cmd->timer); in pmcraid_clr_trans_op()
500 pinstance->host->host_lock, lock_flags); in pmcraid_clr_trans_op()
501 pinstance->reset_cmd->cmd_done(pinstance->reset_cmd); in pmcraid_clr_trans_op()
503 pinstance->host->host_lock, lock_flags); in pmcraid_clr_trans_op()
508 * pmcraid_reset_type - Determine the required reset type
522 mask = ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_reset_type()
523 intrs = ioread32(pinstance->int_regs.ioa_host_interrupt_reg); in pmcraid_reset_type()
524 alerts = ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_reset_type()
530 pinstance->ioa_hard_reset = 1; in pmcraid_reset_type()
535 pinstance->ioa_unit_check = 1; in pmcraid_reset_type()
540 * pmcraid_bist_done - completion function for PCI BIST
548 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_bist_done()
553 rc = pci_read_config_word(pinstance->pdev, PCI_COMMAND, &pci_reg); in pmcraid_bist_done()
557 cmd->time_left > 0) { in pmcraid_bist_done()
559 cmd->timer.expires = jiffies + cmd->time_left; in pmcraid_bist_done()
560 cmd->time_left = 0; in pmcraid_bist_done()
561 add_timer(&cmd->timer); in pmcraid_bist_done()
563 cmd->time_left = 0; in pmcraid_bist_done()
565 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_bist_done()
567 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_bist_done()
572 * pmcraid_start_bist - starts BIST
579 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_start_bist()
584 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_start_bist()
585 doorbells = ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_start_bist()
586 intrs = ioread32(pinstance->int_regs.ioa_host_interrupt_reg); in pmcraid_start_bist()
590 cmd->time_left = msecs_to_jiffies(PMCRAID_BIST_TIMEOUT); in pmcraid_start_bist()
591 cmd->timer.expires = jiffies + msecs_to_jiffies(PMCRAID_BIST_TIMEOUT); in pmcraid_start_bist()
592 cmd->timer.function = pmcraid_bist_done; in pmcraid_start_bist()
593 add_timer(&cmd->timer); in pmcraid_start_bist()
597 * pmcraid_reset_alert_done - completion routine for reset_alert
605 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_reset_alert_done()
606 u32 status = ioread32(pinstance->ioa_status); in pmcraid_reset_alert_done()
614 cmd->time_left <= 0) { in pmcraid_reset_alert_done()
616 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_alert_done()
618 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_alert_done()
622 cmd->time_left -= PMCRAID_CHECK_FOR_RESET_TIMEOUT; in pmcraid_reset_alert_done()
623 cmd->timer.expires = jiffies + PMCRAID_CHECK_FOR_RESET_TIMEOUT; in pmcraid_reset_alert_done()
624 cmd->timer.function = pmcraid_reset_alert_done; in pmcraid_reset_alert_done()
625 add_timer(&cmd->timer); in pmcraid_reset_alert_done()
631 * pmcraid_reset_alert - alerts IOA for a possible reset
635 * returns 0 if pci config-space is accessible and RESET_DOORBELL is
636 * successfully written to IOA. Returns non-zero in case pci_config_space
641 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_reset_alert()
651 rc = pci_read_config_word(pinstance->pdev, PCI_COMMAND, &pci_reg); in pmcraid_reset_alert()
659 cmd->time_left = PMCRAID_RESET_TIMEOUT; in pmcraid_reset_alert()
660 cmd->timer.expires = jiffies + PMCRAID_CHECK_FOR_RESET_TIMEOUT; in pmcraid_reset_alert()
661 cmd->timer.function = pmcraid_reset_alert_done; in pmcraid_reset_alert()
662 add_timer(&cmd->timer); in pmcraid_reset_alert()
665 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_reset_alert()
667 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_reset_alert()
671 pinstance->ioa_state = IOA_STATE_IN_HARD_RESET; in pmcraid_reset_alert()
677 * pmcraid_timeout_handler - Timeout handler for internally generated ops
689 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_timeout_handler()
692 dev_info(&pinstance->pdev->dev, in pmcraid_timeout_handler()
694 cmd->ioa_cb->ioarcb.cdb[0]); in pmcraid_timeout_handler()
702 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_timeout_handler()
703 if (!pinstance->ioa_reset_in_progress) { in pmcraid_timeout_handler()
704 pinstance->ioa_reset_attempts = 0; in pmcraid_timeout_handler()
711 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_timeout_handler()
717 pinstance->reset_cmd = cmd; in pmcraid_timeout_handler()
718 pinstance->ioa_reset_in_progress = 1; in pmcraid_timeout_handler()
722 if (pinstance->reset_cmd != cmd) { in pmcraid_timeout_handler()
735 if (cmd == pinstance->reset_cmd) in pmcraid_timeout_handler()
736 cmd->cmd_done = pmcraid_ioa_reset; in pmcraid_timeout_handler()
740 if (pinstance->scn.ioa_state != PMC_DEVICE_EVENT_RESET_START && in pmcraid_timeout_handler()
741 pinstance->scn.ioa_state != PMC_DEVICE_EVENT_SHUTDOWN_START) in pmcraid_timeout_handler()
745 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_timeout_handler()
746 scsi_block_requests(pinstance->host); in pmcraid_timeout_handler()
748 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_timeout_handler()
752 * pmcraid_internal_done - completion routine for internally generated cmds
762 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_internal_done()
763 le32_to_cpu(cmd->ioa_cb->ioasa.ioasc)); in pmcraid_internal_done()
766 * response. Same will be indicated as part of cmd->completion_req in pmcraid_internal_done()
770 if (cmd->completion_req) { in pmcraid_internal_done()
771 cmd->completion_req = 0; in pmcraid_internal_done()
772 complete(&cmd->wait_for_completion); in pmcraid_internal_done()
779 if (cmd->release) { in pmcraid_internal_done()
780 cmd->release = 0; in pmcraid_internal_done()
786 * pmcraid_reinit_cfgtable_done - done function for cfg table reinitialization
790 * This routine is called after driver re-reads configuration table due to a
800 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_reinit_cfgtable_done()
801 le32_to_cpu(cmd->ioa_cb->ioasa.ioasc)); in pmcraid_reinit_cfgtable_done()
803 if (cmd->release) { in pmcraid_reinit_cfgtable_done()
804 cmd->release = 0; in pmcraid_reinit_cfgtable_done()
808 schedule_work(&cmd->drv_inst->worker_q); in pmcraid_reinit_cfgtable_done()
812 * pmcraid_erp_done - Process completion of SCSI error response from device
823 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_erp_done()
824 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_erp_done()
825 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_erp_done()
828 scsi_cmd->result |= (DID_ERROR << 16); in pmcraid_erp_done()
831 cmd->ioa_cb->ioarcb.cdb[0], ioasc); in pmcraid_erp_done()
834 if (cmd->sense_buffer) { in pmcraid_erp_done()
835 dma_unmap_single(&pinstance->pdev->dev, cmd->sense_buffer_dma, in pmcraid_erp_done()
837 cmd->sense_buffer = NULL; in pmcraid_erp_done()
838 cmd->sense_buffer_dma = 0; in pmcraid_erp_done()
847 * _pmcraid_fire_command - sends an IOA command to adapter
859 struct pmcraid_instance *pinstance = cmd->drv_inst; in _pmcraid_fire_command()
867 spin_lock_irqsave(&pinstance->pending_pool_lock, lock_flags); in _pmcraid_fire_command()
868 list_add_tail(&cmd->free_list, &pinstance->pending_cmd_pool); in _pmcraid_fire_command()
869 spin_unlock_irqrestore(&pinstance->pending_pool_lock, lock_flags); in _pmcraid_fire_command()
870 atomic_inc(&pinstance->outstanding_cmds); in _pmcraid_fire_command()
872 /* driver writes lower 32-bit value of IOARCB address only */ in _pmcraid_fire_command()
874 iowrite32(le64_to_cpu(cmd->ioa_cb->ioarcb.ioarcb_bus_addr), pinstance->ioarrin); in _pmcraid_fire_command()
878 * pmcraid_send_cmd - fires a command to IOA
899 cmd->cmd_done = cmd_done; in pmcraid_send_cmd()
903 cmd->timer.expires = jiffies + timeout; in pmcraid_send_cmd()
904 cmd->timer.function = timeout_func; in pmcraid_send_cmd()
905 add_timer(&cmd->timer); in pmcraid_send_cmd()
913 * pmcraid_ioa_shutdown_done - completion function for IOA shutdown command
921 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_ioa_shutdown_done()
924 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_ioa_shutdown_done()
926 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_ioa_shutdown_done()
930 * pmcraid_ioa_shutdown - sends SHUTDOWN command to ioa
940 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_ioa_shutdown()
941 le32_to_cpu(cmd->ioa_cb->ioasa.ioasc)); in pmcraid_ioa_shutdown()
947 cmd->ioa_cb->ioarcb.request_type = REQ_TYPE_IOACMD; in pmcraid_ioa_shutdown()
948 cmd->ioa_cb->ioarcb.resource_handle = in pmcraid_ioa_shutdown()
950 cmd->ioa_cb->ioarcb.cdb[0] = PMCRAID_IOA_SHUTDOWN; in pmcraid_ioa_shutdown()
951 cmd->ioa_cb->ioarcb.cdb[1] = PMCRAID_SHUTDOWN_NORMAL; in pmcraid_ioa_shutdown()
955 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle)); in pmcraid_ioa_shutdown()
957 pmcraid_notify_ioastate(cmd->drv_inst, PMC_DEVICE_EVENT_SHUTDOWN_START); in pmcraid_ioa_shutdown()
966 * pmcraid_get_fwversion_done - completion function for get_fwversion
975 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_get_fwversion_done()
976 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_get_fwversion_done()
985 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_get_fwversion_done()
986 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_get_fwversion_done()
988 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_get_fwversion_done()
995 * pmcraid_get_fwversion - reads firmware version information
1004 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_get_fwversion()
1006 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_get_fwversion()
1010 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_get_fwversion()
1011 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_get_fwversion()
1012 ioarcb->cdb[0] = INQUIRY; in pmcraid_get_fwversion()
1013 ioarcb->cdb[1] = 1; in pmcraid_get_fwversion()
1014 ioarcb->cdb[2] = 0xD0; in pmcraid_get_fwversion()
1015 ioarcb->cdb[3] = (data_size >> 8) & 0xFF; in pmcraid_get_fwversion()
1016 ioarcb->cdb[4] = data_size & 0xFF; in pmcraid_get_fwversion()
1020 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_get_fwversion()
1023 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_get_fwversion()
1024 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL)); in pmcraid_get_fwversion()
1026 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_get_fwversion()
1027 ioarcb->data_transfer_length = cpu_to_le32(data_size); in pmcraid_get_fwversion()
1028 ioadl = &(ioarcb->add_data.u.ioadl[0]); in pmcraid_get_fwversion()
1029 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_get_fwversion()
1030 ioadl->address = cpu_to_le64(pinstance->inq_data_baddr); in pmcraid_get_fwversion()
1031 ioadl->data_len = cpu_to_le32(data_size); in pmcraid_get_fwversion()
1038 * pmcraid_identify_hrrq - registers host rrq buffers with IOA
1046 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_identify_hrrq()
1047 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_identify_hrrq()
1048 int index = cmd->hrrq_index; in pmcraid_identify_hrrq()
1049 __be64 hrrq_addr = cpu_to_be64(pinstance->hrrq_start_bus_addr[index]); in pmcraid_identify_hrrq()
1054 cmd->hrrq_index = index + 1; in pmcraid_identify_hrrq()
1056 if (cmd->hrrq_index < pinstance->num_hrrq) { in pmcraid_identify_hrrq()
1059 cmd->hrrq_index = 0; in pmcraid_identify_hrrq()
1064 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_identify_hrrq()
1065 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_identify_hrrq()
1068 ioarcb->hrrq_id = index; in pmcraid_identify_hrrq()
1069 ioarcb->cdb[0] = PMCRAID_IDENTIFY_HRRQ; in pmcraid_identify_hrrq()
1070 ioarcb->cdb[1] = index; in pmcraid_identify_hrrq()
1072 /* IOA expects 64-bit pci address to be written in B.E format in pmcraid_identify_hrrq()
1076 hrrq_addr, ioarcb->ioarcb_bus_addr, index); in pmcraid_identify_hrrq()
1078 memcpy(&(ioarcb->cdb[2]), &hrrq_addr, sizeof(hrrq_addr)); in pmcraid_identify_hrrq()
1079 memcpy(&(ioarcb->cdb[10]), &hrrq_size, sizeof(hrrq_size)); in pmcraid_identify_hrrq()
1082 * Note that this gets called even during reset from SCSI mid-layer in pmcraid_identify_hrrq()
1094 * pmcraid_send_hcam_cmd - send an initialized command block(HCAM) to IOA
1103 if (cmd->ioa_cb->ioarcb.cdb[1] == PMCRAID_HCAM_CODE_CONFIG_CHANGE) in pmcraid_send_hcam_cmd()
1104 atomic_set(&(cmd->drv_inst->ccn.ignore), 0); in pmcraid_send_hcam_cmd()
1106 atomic_set(&(cmd->drv_inst->ldn.ignore), 0); in pmcraid_send_hcam_cmd()
1108 pmcraid_send_cmd(cmd, cmd->cmd_done, 0, NULL); in pmcraid_send_hcam_cmd()
1112 * pmcraid_init_hcam - send an initialized command block(HCAM) to IOA
1144 dma = pinstance->ccn.baddr + PMCRAID_AEN_HDR_SIZE; in pmcraid_init_hcam()
1145 hcam = &pinstance->ccn; in pmcraid_init_hcam()
1149 dma = pinstance->ldn.baddr + PMCRAID_AEN_HDR_SIZE; in pmcraid_init_hcam()
1150 hcam = &pinstance->ldn; in pmcraid_init_hcam()
1154 hcam->cmd = cmd; in pmcraid_init_hcam()
1156 ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_init_hcam()
1157 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_init_hcam()
1160 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_init_hcam()
1161 ioadl = ioarcb->add_data.u.ioadl; in pmcraid_init_hcam()
1164 ioarcb->request_type = REQ_TYPE_HCAM; in pmcraid_init_hcam()
1165 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_init_hcam()
1166 ioarcb->cdb[0] = PMCRAID_HOST_CONTROLLED_ASYNC; in pmcraid_init_hcam()
1167 ioarcb->cdb[1] = type; in pmcraid_init_hcam()
1168 ioarcb->cdb[7] = (rcb_size >> 8) & 0xFF; in pmcraid_init_hcam()
1169 ioarcb->cdb[8] = (rcb_size) & 0xFF; in pmcraid_init_hcam()
1171 ioarcb->data_transfer_length = cpu_to_le32(rcb_size); in pmcraid_init_hcam()
1177 cmd->cmd_done = cmd_done; in pmcraid_init_hcam()
1182 * pmcraid_send_hcam - Send an HCAM to IOA
1199 * pmcraid_prepare_cancel_cmd - prepares a command block to abort another
1209 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_prepare_cancel_cmd()
1213 * cdb[2]..cdb[9] is Big-Endian format. Note that length bits in in pmcraid_prepare_cancel_cmd()
1216 ioarcb_addr = cpu_to_be64(le64_to_cpu(cmd_to_cancel->ioa_cb->ioarcb.ioarcb_bus_addr)); in pmcraid_prepare_cancel_cmd()
1221 ioarcb->resource_handle = cmd_to_cancel->ioa_cb->ioarcb.resource_handle; in pmcraid_prepare_cancel_cmd()
1222 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_prepare_cancel_cmd()
1223 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_prepare_cancel_cmd()
1224 ioarcb->cdb[0] = PMCRAID_ABORT_CMD; in pmcraid_prepare_cancel_cmd()
1226 memcpy(&(ioarcb->cdb[2]), &ioarcb_addr, sizeof(ioarcb_addr)); in pmcraid_prepare_cancel_cmd()
1230 * pmcraid_cancel_hcam - sends ABORT task to abort a given HCAM
1245 pinstance = cmd->drv_inst; in pmcraid_cancel_hcam()
1247 &pinstance->ldn : &pinstance->ccn; in pmcraid_cancel_hcam()
1250 * currently not pending with IOA, we would have hcam->cmd as non-null in pmcraid_cancel_hcam()
1252 if (hcam->cmd == NULL) in pmcraid_cancel_hcam()
1255 pmcraid_prepare_cancel_cmd(cmd, hcam->cmd); in pmcraid_cancel_hcam()
1257 /* writing to IOARRIN must be protected by host_lock, as mid-layer in pmcraid_cancel_hcam()
1266 * pmcraid_cancel_ccn - cancel CCN HCAM already registered with IOA
1273 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_cancel_ccn()
1274 le32_to_cpu(cmd->ioa_cb->ioasa.ioasc)); in pmcraid_cancel_ccn()
1284 * pmcraid_cancel_ldn - cancel LDN HCAM already registered with IOA
1296 * pmcraid_expose_resource - check if the resource can be exposed to OS
1309 if (cfgte->resource_type == RES_TYPE_VSET) { in pmcraid_expose_resource()
1311 retval = ((cfgte->unique_flags1 & 0x80) == 0); in pmcraid_expose_resource()
1313 retval = ((cfgte->unique_flags0 & 0x80) == 0 && in pmcraid_expose_resource()
1314 (cfgte->unique_flags1 & 0x80) == 0); in pmcraid_expose_resource()
1316 } else if (cfgte->resource_type == RES_TYPE_GSCSI) in pmcraid_expose_resource()
1317 retval = (RES_BUS(cfgte->resource_address) != in pmcraid_expose_resource()
1328 #define PMCRAID_AEN_ATTR_MAX (__PMCRAID_AEN_ATTR_MAX - 1)
1336 #define PMCRAID_AEN_CMD_MAX (__PMCRAID_AEN_CMD_MAX - 1)
1339 { .name = "events", /* not really used - see ID discussion below */ },
1352 * pmcraid_netlink_init - registers pmcraid_event_family
1356 * with netlink generic, non-zero otherwise
1374 * pmcraid_netlink_release - unregisters pmcraid_event_family
1385 * pmcraid_notify_aen - sends event msg to user space application
1401 aen_msg->hostno = (pinstance->host->unique_id << 16 | in pmcraid_notify_aen()
1402 MINOR(pinstance->cdev.dev)); in pmcraid_notify_aen()
1403 aen_msg->length = data_size; in pmcraid_notify_aen()
1411 ((struct genl_family *)&pmcraid_event_family)->hdrsize) in pmcraid_notify_aen()
1419 return -ENOMEM; in pmcraid_notify_aen()
1429 return -ENOMEM; in pmcraid_notify_aen()
1437 return -EINVAL; in pmcraid_notify_aen()
1446 /* If there are no listeners, genlmsg_multicast may return non-zero in pmcraid_notify_aen()
1455 * pmcraid_notify_ccn - notifies about CCN event msg to user space
1464 pinstance->ccn.msg, in pmcraid_notify_ccn()
1465 le32_to_cpu(pinstance->ccn.hcam->data_len) + in pmcraid_notify_ccn()
1470 * pmcraid_notify_ldn - notifies about CCN event msg to user space
1479 pinstance->ldn.msg, in pmcraid_notify_ldn()
1480 le32_to_cpu(pinstance->ldn.hcam->data_len) + in pmcraid_notify_ldn()
1485 * pmcraid_notify_ioastate - sends IOA state event msg to user space
1494 pinstance->scn.ioa_state = evt; in pmcraid_notify_ioastate()
1496 &pinstance->scn.msg, in pmcraid_notify_ioastate()
1501 * pmcraid_handle_config_change - Handle a config change from the adapter
1522 ccn_hcam = (struct pmcraid_hcam_ccn *)pinstance->ccn.hcam; in pmcraid_handle_config_change()
1523 cfg_entry = &ccn_hcam->cfg_entry; in pmcraid_handle_config_change()
1524 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_handle_config_change()
1528 le32_to_cpu(pinstance->ccn.hcam->ilid), in pmcraid_handle_config_change()
1529 pinstance->ccn.hcam->op_code, in pmcraid_handle_config_change()
1530 (le32_to_cpu(pinstance->ccn.hcam->timestamp1) | in pmcraid_handle_config_change()
1531 ((le32_to_cpu(pinstance->ccn.hcam->timestamp2) & 0xffffffffLL) << 32)), in pmcraid_handle_config_change()
1532 pinstance->ccn.hcam->notification_type, in pmcraid_handle_config_change()
1533 pinstance->ccn.hcam->notification_lost, in pmcraid_handle_config_change()
1534 pinstance->ccn.hcam->flags, in pmcraid_handle_config_change()
1535 pinstance->host->unique_id, in pmcraid_handle_config_change()
1538 RES_BUS(cfg_entry->resource_address)), in pmcraid_handle_config_change()
1541 cfg_entry->unique_flags1 : in pmcraid_handle_config_change()
1542 le16_to_cpu(cfg_entry->array_id) & 0xFF) : in pmcraid_handle_config_change()
1543 RES_TARGET(cfg_entry->resource_address), in pmcraid_handle_config_change()
1544 RES_LUN(cfg_entry->resource_address)); in pmcraid_handle_config_change()
1548 if (pinstance->ccn.hcam->notification_lost) { in pmcraid_handle_config_change()
1552 pinstance->reinit_cfg_table = 1; in pmcraid_handle_config_change()
1560 /* If this resource is not going to be added to mid-layer, just notify in pmcraid_handle_config_change()
1564 if (pinstance->ccn.hcam->notification_type == in pmcraid_handle_config_change()
1566 cfg_entry->resource_type == RES_TYPE_VSET) { in pmcraid_handle_config_change()
1567 hidden_entry = (cfg_entry->unique_flags1 & 0x80) != 0; in pmcraid_handle_config_change()
1572 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_handle_config_change()
1573 list_for_each_entry(res, &pinstance->used_res_q, queue) { in pmcraid_handle_config_change()
1574 rc = memcmp(&res->cfg_entry.resource_address, in pmcraid_handle_config_change()
1575 &cfg_entry->resource_address, in pmcraid_handle_config_change()
1576 sizeof(cfg_entry->resource_address)); in pmcraid_handle_config_change()
1586 spin_unlock_irqrestore(&pinstance->resource_lock, in pmcraid_handle_config_change()
1593 * ignore this notifications and re-register the same HCAM in pmcraid_handle_config_change()
1595 if (list_empty(&pinstance->free_res_q)) { in pmcraid_handle_config_change()
1596 spin_unlock_irqrestore(&pinstance->resource_lock, in pmcraid_handle_config_change()
1599 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_handle_config_change()
1603 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_handle_config_change()
1608 res = list_entry(pinstance->free_res_q.next, in pmcraid_handle_config_change()
1611 list_del(&res->queue); in pmcraid_handle_config_change()
1612 res->scsi_dev = NULL; in pmcraid_handle_config_change()
1613 res->reset_progress = 0; in pmcraid_handle_config_change()
1614 list_add_tail(&res->queue, &pinstance->used_res_q); in pmcraid_handle_config_change()
1617 memcpy(&res->cfg_entry, cfg_entry, pinstance->config_table_entry_size); in pmcraid_handle_config_change()
1619 if (pinstance->ccn.hcam->notification_type == in pmcraid_handle_config_change()
1621 if (res->scsi_dev) { in pmcraid_handle_config_change()
1623 res->cfg_entry.unique_flags1 &= 0x7F; in pmcraid_handle_config_change()
1625 res->cfg_entry.array_id &= cpu_to_le16(0xFF); in pmcraid_handle_config_change()
1626 res->change_detected = RES_CHANGE_DEL; in pmcraid_handle_config_change()
1627 res->cfg_entry.resource_handle = in pmcraid_handle_config_change()
1629 schedule_work(&pinstance->worker_q); in pmcraid_handle_config_change()
1631 /* This may be one of the non-exposed resources */ in pmcraid_handle_config_change()
1632 list_move_tail(&res->queue, &pinstance->free_res_q); in pmcraid_handle_config_change()
1634 } else if (!res->scsi_dev) { in pmcraid_handle_config_change()
1635 res->change_detected = RES_CHANGE_ADD; in pmcraid_handle_config_change()
1636 schedule_work(&pinstance->worker_q); in pmcraid_handle_config_change()
1638 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_handle_config_change()
1652 * pmcraid_get_error_info - return error string for an ioasc
1668 * pmcraid_ioasc_logger - log IOASC information based user-settings
1677 cmd->drv_inst->current_log_level < error_info->log_level) in pmcraid_ioasc_logger()
1682 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_ioasc_logger()
1683 le32_to_cpu(cmd->ioa_cb->ioarcb.resource_handle), in pmcraid_ioasc_logger()
1684 ioasc, error_info->error_string); in pmcraid_ioasc_logger()
1688 * pmcraid_handle_error_log - Handle a config change (error log) from the IOA
1700 hcam_ldn = (struct pmcraid_hcam_ldn *)pinstance->ldn.hcam; in pmcraid_handle_error_log()
1704 pinstance->ldn.hcam->ilid, in pmcraid_handle_error_log()
1705 pinstance->ldn.hcam->op_code, in pmcraid_handle_error_log()
1706 pinstance->ldn.hcam->notification_type, in pmcraid_handle_error_log()
1707 pinstance->ldn.hcam->notification_lost, in pmcraid_handle_error_log()
1708 pinstance->ldn.hcam->flags, in pmcraid_handle_error_log()
1709 pinstance->ldn.hcam->overlay_id); in pmcraid_handle_error_log()
1712 if (pinstance->ldn.hcam->notification_type != in pmcraid_handle_error_log()
1716 if (pinstance->ldn.hcam->notification_lost == in pmcraid_handle_error_log()
1718 dev_info(&pinstance->pdev->dev, "Error notifications lost\n"); in pmcraid_handle_error_log()
1720 ioasc = le32_to_cpu(hcam_ldn->error_log.fd_ioasc); in pmcraid_handle_error_log()
1724 dev_info(&pinstance->pdev->dev, in pmcraid_handle_error_log()
1727 pinstance->host, in pmcraid_handle_error_log()
1728 RES_BUS(hcam_ldn->error_log.fd_ra)); in pmcraid_handle_error_log()
1735 * pmcraid_process_ccn - Op done function for a CCN.
1746 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_process_ccn()
1747 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_process_ccn()
1750 pinstance->ccn.cmd = NULL; in pmcraid_process_ccn()
1755 * re-register the hcam in pmcraid_process_ccn()
1758 atomic_read(&pinstance->ccn.ignore) == 1) { in pmcraid_process_ccn()
1761 dev_info(&pinstance->pdev->dev, in pmcraid_process_ccn()
1763 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_process_ccn()
1765 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_process_ccn()
1774 * pmcraid_process_ldn - op done function for an LDN
1782 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_process_ldn()
1784 (struct pmcraid_hcam_ldn *)pinstance->ldn.hcam; in pmcraid_process_ldn()
1785 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_process_ldn()
1786 u32 fd_ioasc = le32_to_cpu(ldn_hcam->error_log.fd_ioasc); in pmcraid_process_ldn()
1790 pinstance->ldn.cmd = NULL; in pmcraid_process_ldn()
1794 * with IOA, no need to re-register the hcam as reset engine will do it in pmcraid_process_ldn()
1798 atomic_read(&pinstance->ccn.ignore) == 1) { in pmcraid_process_ldn()
1803 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_process_ldn()
1806 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_process_ldn()
1811 pinstance->timestamp_error = 1; in pmcraid_process_ldn()
1815 dev_info(&pinstance->pdev->dev, in pmcraid_process_ldn()
1828 * pmcraid_register_hcams - register HCAMs for CCN and LDN
1842 * pmcraid_unregister_hcams - cancel HCAMs registered already
1847 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_unregister_hcams()
1851 * prevent this, set 'ignore', so that bring-down sequence doesn't in pmcraid_unregister_hcams()
1852 * re-send any more hcams in pmcraid_unregister_hcams()
1854 atomic_set(&pinstance->ccn.ignore, 1); in pmcraid_unregister_hcams()
1855 atomic_set(&pinstance->ldn.ignore, 1); in pmcraid_unregister_hcams()
1861 if ((pinstance->force_ioa_reset && !pinstance->ioa_bringdown) || in pmcraid_unregister_hcams()
1862 pinstance->ioa_unit_check) { in pmcraid_unregister_hcams()
1863 pinstance->force_ioa_reset = 0; in pmcraid_unregister_hcams()
1864 pinstance->ioa_unit_check = 0; in pmcraid_unregister_hcams()
1865 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_unregister_hcams()
1880 * pmcraid_reset_enable_ioa - re-enable IOA after a hard reset
1895 if (!pinstance->interrupt_mode) { in pmcraid_reset_enable_ioa()
1897 pinstance->int_regs. in pmcraid_reset_enable_ioa()
1900 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_reset_enable_ioa()
1909 * pmcraid_soft_reset - performs a soft reset and makes IOA become ready
1917 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_soft_reset()
1923 * would re-initiate a reset in pmcraid_soft_reset()
1925 cmd->cmd_done = pmcraid_ioa_reset; in pmcraid_soft_reset()
1926 cmd->timer.expires = jiffies + in pmcraid_soft_reset()
1928 cmd->timer.function = pmcraid_timeout_handler; in pmcraid_soft_reset()
1930 if (!timer_pending(&cmd->timer)) in pmcraid_soft_reset()
1931 add_timer(&cmd->timer); in pmcraid_soft_reset()
1942 if (pinstance->interrupt_mode) { in pmcraid_soft_reset()
1944 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_soft_reset()
1945 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_soft_reset()
1948 iowrite32(doorbell, pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_soft_reset()
1949 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_soft_reset()
1950 int_reg = ioread32(pinstance->int_regs.ioa_host_interrupt_reg); in pmcraid_soft_reset()
1953 ioread32(pinstance->int_regs.host_ioa_interrupt_reg), in pmcraid_soft_reset()
1958 * pmcraid_get_dump - retrieves IOA dump in case of Unit Check interrupt
1971 * pmcraid_fail_outstanding_cmds - Fails all outstanding ops.
1990 spin_lock_irqsave(&pinstance->pending_pool_lock, lock_flags); in pmcraid_fail_outstanding_cmds()
1991 list_for_each_entry_safe(cmd, temp, &pinstance->pending_cmd_pool, in pmcraid_fail_outstanding_cmds()
1993 list_del(&cmd->free_list); in pmcraid_fail_outstanding_cmds()
1994 spin_unlock_irqrestore(&pinstance->pending_pool_lock, in pmcraid_fail_outstanding_cmds()
1996 cmd->ioa_cb->ioasa.ioasc = in pmcraid_fail_outstanding_cmds()
1998 cmd->ioa_cb->ioasa.ilid = in pmcraid_fail_outstanding_cmds()
2002 del_timer(&cmd->timer); in pmcraid_fail_outstanding_cmds()
2009 if (cmd->scsi_cmd) { in pmcraid_fail_outstanding_cmds()
2011 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_fail_outstanding_cmds()
2012 __le32 resp = cmd->ioa_cb->ioarcb.response_handle; in pmcraid_fail_outstanding_cmds()
2014 scsi_cmd->result |= DID_ERROR << 16; in pmcraid_fail_outstanding_cmds()
2021 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_fail_outstanding_cmds()
2022 scsi_cmd->result); in pmcraid_fail_outstanding_cmds()
2024 } else if (cmd->cmd_done == pmcraid_internal_done || in pmcraid_fail_outstanding_cmds()
2025 cmd->cmd_done == pmcraid_erp_done) { in pmcraid_fail_outstanding_cmds()
2026 cmd->cmd_done(cmd); in pmcraid_fail_outstanding_cmds()
2027 } else if (cmd->cmd_done != pmcraid_ioa_reset && in pmcraid_fail_outstanding_cmds()
2028 cmd->cmd_done != pmcraid_ioa_shutdown_done) { in pmcraid_fail_outstanding_cmds()
2032 atomic_dec(&pinstance->outstanding_cmds); in pmcraid_fail_outstanding_cmds()
2033 spin_lock_irqsave(&pinstance->pending_pool_lock, lock_flags); in pmcraid_fail_outstanding_cmds()
2036 spin_unlock_irqrestore(&pinstance->pending_pool_lock, lock_flags); in pmcraid_fail_outstanding_cmds()
2040 * pmcraid_ioa_reset - Implementation of IOA reset logic
2056 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_ioa_reset()
2059 pinstance->ioa_reset_in_progress = 1; in pmcraid_ioa_reset()
2061 if (pinstance->reset_cmd != cmd) { in pmcraid_ioa_reset()
2063 pinstance->reset_cmd = cmd; in pmcraid_ioa_reset()
2067 pinstance->ioa_state, cmd); in pmcraid_ioa_reset()
2069 switch (pinstance->ioa_state) { in pmcraid_ioa_reset()
2083 * goes through hard-reset in pmcraid_ioa_reset()
2086 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_ioa_reset()
2091 /* We may be called during probe or resume. Some pre-processing in pmcraid_ioa_reset()
2094 scsi_block_requests(pinstance->host); in pmcraid_ioa_reset()
2098 * hard-reset. in pmcraid_ioa_reset()
2100 if (pinstance->ioa_hard_reset == 0) { in pmcraid_ioa_reset()
2101 if (ioread32(pinstance->ioa_status) & in pmcraid_ioa_reset()
2103 pmcraid_info("sticky bit set, bring-up\n"); in pmcraid_ioa_reset()
2104 pinstance->ioa_state = IOA_STATE_IN_BRINGUP; in pmcraid_ioa_reset()
2108 pinstance->ioa_state = IOA_STATE_IN_SOFT_RESET; in pmcraid_ioa_reset()
2115 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_ioa_reset()
2126 pinstance->ioa_state = IOA_STATE_IN_HARD_RESET; in pmcraid_ioa_reset()
2131 pinstance->ioa_reset_attempts++; in pmcraid_ioa_reset()
2134 if (pinstance->ioa_reset_attempts > PMCRAID_RESET_ATTEMPTS) { in pmcraid_ioa_reset()
2135 pinstance->ioa_reset_attempts = 0; in pmcraid_ioa_reset()
2137 pinstance->ioa_state = IOA_STATE_DEAD; in pmcraid_ioa_reset()
2139 if (pinstance->ioa_bringdown) in pmcraid_ioa_reset()
2152 pci_restore_state(pinstance->pdev); in pmcraid_ioa_reset()
2158 if (pinstance->ioa_unit_check) { in pmcraid_ioa_reset()
2160 pinstance->ioa_unit_check = 0; in pmcraid_ioa_reset()
2162 pinstance->ioa_reset_attempts--; in pmcraid_ioa_reset()
2163 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_ioa_reset()
2168 /* if the reset reason is to bring-down the ioa, we might be in pmcraid_ioa_reset()
2172 if (pinstance->ioa_bringdown) { in pmcraid_ioa_reset()
2174 pinstance->ioa_shutdown_type = SHUTDOWN_NONE; in pmcraid_ioa_reset()
2175 pinstance->ioa_bringdown = 0; in pmcraid_ioa_reset()
2176 pinstance->ioa_state = IOA_STATE_UNKNOWN; in pmcraid_ioa_reset()
2181 /* bring-up IOA, so proceed with soft reset in pmcraid_ioa_reset()
2186 pinstance->ioa_state = IOA_STATE_IN_BRINGUP; in pmcraid_ioa_reset()
2191 pinstance->ioa_state = IOA_STATE_IN_SOFT_RESET; in pmcraid_ioa_reset()
2201 pmcraid_info("In softreset proceeding with bring-up\n"); in pmcraid_ioa_reset()
2202 pinstance->ioa_state = IOA_STATE_IN_BRINGUP; in pmcraid_ioa_reset()
2215 pinstance->ioa_state = IOA_STATE_OPERATIONAL; in pmcraid_ioa_reset()
2226 if (pinstance->ioa_shutdown_type == SHUTDOWN_NONE && in pmcraid_ioa_reset()
2227 pinstance->force_ioa_reset == 0) { in pmcraid_ioa_reset()
2232 if (pinstance->ioa_shutdown_type != SHUTDOWN_NONE) in pmcraid_ioa_reset()
2233 pinstance->ioa_state = IOA_STATE_IN_BRINGDOWN; in pmcraid_ioa_reset()
2242 * any waiting threads and let the SCSI mid-layer send commands. Note in pmcraid_ioa_reset()
2246 pinstance->ioa_reset_in_progress = 0; in pmcraid_ioa_reset()
2247 pinstance->ioa_reset_attempts = 0; in pmcraid_ioa_reset()
2248 pinstance->reset_cmd = NULL; in pmcraid_ioa_reset()
2249 pinstance->ioa_shutdown_type = SHUTDOWN_NONE; in pmcraid_ioa_reset()
2250 pinstance->ioa_bringdown = 0; in pmcraid_ioa_reset()
2254 * hcam registration and resource exposure to mid-layer. in pmcraid_ioa_reset()
2256 if (pinstance->ioa_state == IOA_STATE_OPERATIONAL) in pmcraid_ioa_reset()
2259 wake_up_all(&pinstance->reset_wait_q); in pmcraid_ioa_reset()
2266 * pmcraid_initiate_reset - initiates reset sequence. This is called from
2283 if (!pinstance->ioa_reset_in_progress) { in pmcraid_initiate_reset()
2284 scsi_block_requests(pinstance->host); in pmcraid_initiate_reset()
2292 pinstance->ioa_shutdown_type = SHUTDOWN_NONE; in pmcraid_initiate_reset()
2293 pinstance->reset_cmd = cmd; in pmcraid_initiate_reset()
2294 pinstance->force_ioa_reset = 1; in pmcraid_initiate_reset()
2302 * pmcraid_reset_reload - utility routine for doing IOA reset either to bringup
2325 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2327 if (pinstance->ioa_reset_in_progress) { in pmcraid_reset_reload()
2330 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2332 wait_event(pinstance->reset_wait_q, in pmcraid_reset_reload()
2333 !pinstance->ioa_reset_in_progress); in pmcraid_reset_reload()
2335 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2337 if (pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_reset_reload()
2342 if (pinstance->ioa_state == target_state) { in pmcraid_reset_reload()
2349 scsi_block_requests(pinstance->host); in pmcraid_reset_reload()
2357 pinstance->ioa_bringdown = 1; in pmcraid_reset_reload()
2359 pinstance->ioa_shutdown_type = shutdown_type; in pmcraid_reset_reload()
2360 pinstance->reset_cmd = reset_cmd; in pmcraid_reset_reload()
2361 pinstance->force_ioa_reset = reset; in pmcraid_reset_reload()
2364 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2366 wait_event(pinstance->reset_wait_q, in pmcraid_reset_reload()
2367 !pinstance->ioa_reset_in_progress); in pmcraid_reset_reload()
2370 scsi_unblock_requests(pinstance->host); in pmcraid_reset_reload()
2371 return pinstance->ioa_state != target_state; in pmcraid_reset_reload()
2374 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2379 * pmcraid_reset_bringdown - wrapper over pmcraid_reset_reload to bringdown IOA
2394 * pmcraid_reset_bringup - wrapper over pmcraid_reset_reload to bring up IOA
2411 * pmcraid_request_sense - Send request sense to a device
2415 * condition. This method re-uses the same command block that failed earlier.
2419 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_request_sense()
2420 struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl; in pmcraid_request_sense()
2421 struct device *dev = &cmd->drv_inst->pdev->dev; in pmcraid_request_sense()
2423 cmd->sense_buffer = cmd->scsi_cmd->sense_buffer; in pmcraid_request_sense()
2424 cmd->sense_buffer_dma = dma_map_single(dev, cmd->sense_buffer, in pmcraid_request_sense()
2426 if (dma_mapping_error(dev, cmd->sense_buffer_dma)) { in pmcraid_request_sense()
2433 /* re-use the command block */ in pmcraid_request_sense()
2434 memset(&cmd->ioa_cb->ioasa, 0, sizeof(struct pmcraid_ioasa)); in pmcraid_request_sense()
2435 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_request_sense()
2436 ioarcb->request_flags0 = (SYNC_COMPLETE | in pmcraid_request_sense()
2439 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_request_sense()
2440 ioarcb->cdb[0] = REQUEST_SENSE; in pmcraid_request_sense()
2441 ioarcb->cdb[4] = SCSI_SENSE_BUFFERSIZE; in pmcraid_request_sense()
2443 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_request_sense()
2446 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_request_sense()
2448 ioarcb->data_transfer_length = cpu_to_le32(SCSI_SENSE_BUFFERSIZE); in pmcraid_request_sense()
2450 ioadl->address = cpu_to_le64(cmd->sense_buffer_dma); in pmcraid_request_sense()
2451 ioadl->data_len = cpu_to_le32(SCSI_SENSE_BUFFERSIZE); in pmcraid_request_sense()
2452 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_request_sense()
2455 * which runs in tasklets context. It is possible that mid-layer might in pmcraid_request_sense()
2465 * pmcraid_cancel_all - cancel all outstanding IOARCBs as part of error recovery
2473 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_cancel_all()
2474 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_cancel_all()
2475 struct pmcraid_resource_entry *res = scsi_cmd->device->hostdata; in pmcraid_cancel_all()
2477 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_cancel_all()
2478 ioarcb->request_flags0 = SYNC_OVERRIDE; in pmcraid_cancel_all()
2479 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_cancel_all()
2480 ioarcb->cdb[0] = PMCRAID_CANCEL_ALL_REQUESTS; in pmcraid_cancel_all()
2482 if (RES_IS_GSCSI(res->cfg_entry)) in pmcraid_cancel_all()
2483 ioarcb->cdb[1] = PMCRAID_SYNC_COMPLETE_AFTER_CANCEL; in pmcraid_cancel_all()
2485 ioarcb->ioadl_bus_addr = 0; in pmcraid_cancel_all()
2486 ioarcb->ioadl_length = 0; in pmcraid_cancel_all()
2487 ioarcb->data_transfer_length = 0; in pmcraid_cancel_all()
2488 ioarcb->ioarcb_bus_addr &= cpu_to_le64((~0x1FULL)); in pmcraid_cancel_all()
2490 /* writing to IOARRIN must be protected by host_lock, as mid-layer in pmcraid_cancel_all()
2509 u8 *sense_buf = cmd->scsi_cmd->sense_buffer; in pmcraid_frame_auto_sense()
2510 struct pmcraid_resource_entry *res = cmd->scsi_cmd->device->hostdata; in pmcraid_frame_auto_sense()
2511 struct pmcraid_ioasa *ioasa = &cmd->ioa_cb->ioasa; in pmcraid_frame_auto_sense()
2512 u32 ioasc = le32_to_cpu(ioasa->ioasc); in pmcraid_frame_auto_sense()
2516 cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION; in pmcraid_frame_auto_sense()
2518 if (RES_IS_VSET(res->cfg_entry) && in pmcraid_frame_auto_sense()
2520 ioasa->u.vset.failing_lba_hi != 0) { in pmcraid_frame_auto_sense()
2532 failing_lba = le32_to_cpu(ioasa->u.vset.failing_lba_hi); in pmcraid_frame_auto_sense()
2539 failing_lba = le32_to_cpu(ioasa->u.vset.failing_lba_lo); in pmcraid_frame_auto_sense()
2552 if (RES_IS_VSET(res->cfg_entry)) in pmcraid_frame_auto_sense()
2554 le32_to_cpu(ioasa->u. in pmcraid_frame_auto_sense()
2568 * pmcraid_error_handler - Error response handlers for a SCSI op
2577 * back to free-pool
2581 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_error_handler()
2582 struct pmcraid_resource_entry *res = scsi_cmd->device->hostdata; in pmcraid_error_handler()
2583 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_error_handler()
2584 struct pmcraid_ioasa *ioasa = &cmd->ioa_cb->ioasa; in pmcraid_error_handler()
2585 u32 ioasc = le32_to_cpu(ioasa->ioasc); in pmcraid_error_handler()
2595 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD) in pmcraid_error_handler()
2596 atomic_inc(&res->read_failures); in pmcraid_error_handler()
2597 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD) in pmcraid_error_handler()
2598 atomic_inc(&res->write_failures); in pmcraid_error_handler()
2600 if (!RES_IS_GSCSI(res->cfg_entry) && in pmcraid_error_handler()
2611 scsi_cmd->result |= (DID_ABORT << 16); in pmcraid_error_handler()
2616 scsi_cmd->result |= (DID_NO_CONNECT << 16); in pmcraid_error_handler()
2620 res->sync_reqd = 1; in pmcraid_error_handler()
2621 scsi_cmd->result |= (DID_IMM_RETRY << 16); in pmcraid_error_handler()
2625 scsi_cmd->result |= (DID_PASSTHROUGH << 16); in pmcraid_error_handler()
2630 if (!res->reset_progress) in pmcraid_error_handler()
2631 scsi_report_bus_reset(pinstance->host, in pmcraid_error_handler()
2632 scsi_cmd->device->channel); in pmcraid_error_handler()
2633 scsi_cmd->result |= (DID_ERROR << 16); in pmcraid_error_handler()
2637 scsi_cmd->result |= PMCRAID_IOASC_SENSE_STATUS(ioasc); in pmcraid_error_handler()
2638 res->sync_reqd = 1; in pmcraid_error_handler()
2649 * mid-layer in pmcraid_error_handler()
2651 if (ioasa->auto_sense_length != 0) { in pmcraid_error_handler()
2652 short sense_len = le16_to_cpu(ioasa->auto_sense_length); in pmcraid_error_handler()
2656 memcpy(scsi_cmd->sense_buffer, in pmcraid_error_handler()
2657 ioasa->sense_data, in pmcraid_error_handler()
2662 if (RES_IS_GSCSI(res->cfg_entry)) in pmcraid_error_handler()
2676 scsi_cmd->result |= (DID_ERROR << 16); in pmcraid_error_handler()
2683 * pmcraid_reset_device - device reset handler functions
2709 (struct pmcraid_instance *)scsi_dev->host->hostdata; in pmcraid_reset_device()
2710 res = scsi_dev->hostdata; in pmcraid_reset_device()
2719 * This will force the mid-layer to call _eh_bus/host reset, which in pmcraid_reset_device()
2722 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2723 if (pinstance->ioa_reset_in_progress || in pmcraid_reset_device()
2724 pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_reset_device()
2725 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2729 res->reset_progress = 1; in pmcraid_reset_device()
2733 le32_to_cpu(res->cfg_entry.resource_address)); in pmcraid_reset_device()
2739 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2744 ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_reset_device()
2745 ioarcb->resource_handle = res->cfg_entry.resource_handle; in pmcraid_reset_device()
2746 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_reset_device()
2747 ioarcb->cdb[0] = PMCRAID_RESET_DEVICE; in pmcraid_reset_device()
2753 ioarcb->cdb[1] = modifier; in pmcraid_reset_device()
2755 init_completion(&cmd->wait_for_completion); in pmcraid_reset_device()
2756 cmd->completion_req = 1; in pmcraid_reset_device()
2759 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_reset_device()
2760 le32_to_cpu(cmd->ioa_cb->ioarcb.resource_handle), in pmcraid_reset_device()
2761 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2); in pmcraid_reset_device()
2768 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2774 wait_for_completion(&cmd->wait_for_completion); in pmcraid_reset_device()
2780 res->reset_progress = 0; in pmcraid_reset_device()
2781 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_reset_device()
2788 * _pmcraid_io_done - helper for pmcraid_io_done function
2794 * This function is invoked by pmcraid_io_done to complete mid-layer
2805 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in _pmcraid_io_done()
2811 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2, in _pmcraid_io_done()
2812 cmd->ioa_cb->ioarcb.cdb[0], in _pmcraid_io_done()
2813 ioasc, scsi_cmd->result); in _pmcraid_io_done()
2827 * pmcraid_io_done - SCSI completion function
2831 * This function is invoked by tasklet/mid-layer error handler to completing
2832 * the SCSI ops sent from mid-layer.
2840 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_io_done()
2841 u32 reslen = le32_to_cpu(cmd->ioa_cb->ioasa.residual_data_length); in pmcraid_io_done()
2848 * pmcraid_abort_cmd - Aborts a single IOARCB already submitted to IOA
2860 pinstance = (struct pmcraid_instance *)cmd->drv_inst; in pmcraid_abort_cmd()
2872 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_abort_cmd()
2873 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2); in pmcraid_abort_cmd()
2875 init_completion(&cancel_cmd->wait_for_completion); in pmcraid_abort_cmd()
2876 cancel_cmd->completion_req = 1; in pmcraid_abort_cmd()
2879 le32_to_cpu(cancel_cmd->ioa_cb->ioarcb.response_handle) >> 2, in pmcraid_abort_cmd()
2880 cancel_cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_abort_cmd()
2881 le32_to_cpu(cancel_cmd->ioa_cb->ioarcb.resource_handle)); in pmcraid_abort_cmd()
2891 * pmcraid_abort_complete - Waits for ABORT TASK completion
2904 wait_for_completion(&cancel_cmd->wait_for_completion); in pmcraid_abort_complete()
2905 res = cancel_cmd->res; in pmcraid_abort_complete()
2906 cancel_cmd->res = NULL; in pmcraid_abort_complete()
2907 ioasc = le32_to_cpu(cancel_cmd->ioa_cb->ioasa.ioasc); in pmcraid_abort_complete()
2917 res->sync_reqd = 1; in pmcraid_abort_complete()
2927 * pmcraid_eh_abort_handler - entry point for aborting a single task on errors
2929 * @scsi_cmd: scsi command struct given by mid-layer. When this is called
2930 * mid-layer ensures that no other commands are queued. This
2948 (struct pmcraid_instance *)scsi_cmd->device->host->hostdata; in pmcraid_eh_abort_handler()
2953 res = scsi_cmd->device->hostdata; in pmcraid_eh_abort_handler()
2959 * This will force the mid-layer to eventually call in pmcraid_eh_abort_handler()
2963 spin_lock_irqsave(pinstance->host->host_lock, host_lock_flags); in pmcraid_eh_abort_handler()
2965 if (pinstance->ioa_reset_in_progress || in pmcraid_eh_abort_handler()
2966 pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_eh_abort_handler()
2967 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_eh_abort_handler()
2977 spin_lock_irqsave(&pinstance->pending_pool_lock, pending_lock_flags); in pmcraid_eh_abort_handler()
2978 list_for_each_entry(cmd, &pinstance->pending_cmd_pool, free_list) { in pmcraid_eh_abort_handler()
2980 if (cmd->scsi_cmd == scsi_cmd) { in pmcraid_eh_abort_handler()
2986 spin_unlock_irqrestore(&pinstance->pending_pool_lock, in pmcraid_eh_abort_handler()
2995 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_eh_abort_handler()
2999 cancel_cmd->res = cmd->scsi_cmd->device->hostdata; in pmcraid_eh_abort_handler()
3007 * pmcraid_eh_device_reset_handler - bus/target/device reset handler callbacks
3012 * Since these are called from mid-layer EH thread, no other IO will be queued
3024 return pmcraid_reset_device(scmd->device, in pmcraid_eh_device_reset_handler()
3031 struct Scsi_Host *host = scmd->device->host; in pmcraid_eh_bus_reset_handler()
3033 (struct pmcraid_instance *)host->hostdata; in pmcraid_eh_bus_reset_handler()
3043 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_eh_bus_reset_handler()
3044 list_for_each_entry(temp, &pinstance->used_res_q, queue) { in pmcraid_eh_bus_reset_handler()
3045 if (scmd->device->channel == PMCRAID_VSET_BUS_ID && in pmcraid_eh_bus_reset_handler()
3046 RES_IS_VSET(temp->cfg_entry)) { in pmcraid_eh_bus_reset_handler()
3049 } else if (scmd->device->channel == PMCRAID_PHYS_BUS_ID && in pmcraid_eh_bus_reset_handler()
3050 RES_IS_GSCSI(temp->cfg_entry)) { in pmcraid_eh_bus_reset_handler()
3056 sdev = res->scsi_dev; in pmcraid_eh_bus_reset_handler()
3057 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_eh_bus_reset_handler()
3070 struct Scsi_Host *shost = scmd->device->host; in pmcraid_eh_target_reset_handler()
3075 if ((tmp->channel == scmd->device->channel) && in pmcraid_eh_target_reset_handler()
3076 (tmp->id == scmd->device->id)) { in pmcraid_eh_target_reset_handler()
3093 * pmcraid_eh_host_reset_handler - adapter reset handler callback
3107 (struct pmcraid_instance *)(scmd->device->host->hostdata); in pmcraid_eh_host_reset_handler()
3114 while (waits--) { in pmcraid_eh_host_reset_handler()
3115 if (atomic_read(&pinstance->outstanding_cmds) <= in pmcraid_eh_host_reset_handler()
3121 dev_err(&pinstance->pdev->dev, in pmcraid_eh_host_reset_handler()
3127 * pmcraid_init_ioadls - initializes IOADL related fields in IOARCB
3129 * @sgcount: count of scatter-gather elements
3139 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_init_ioadls()
3142 if (ioarcb->add_cmd_param_length) in pmcraid_init_ioadls()
3143 ioadl_count = DIV_ROUND_UP(le16_to_cpu(ioarcb->add_cmd_param_length), 16); in pmcraid_init_ioadls()
3144 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc) * sgcount); in pmcraid_init_ioadls()
3146 if ((sgcount + ioadl_count) > (ARRAY_SIZE(ioarcb->add_data.u.ioadl))) { in pmcraid_init_ioadls()
3148 * structure, re-using 24 out of 27 ioadls part of IOARCB. in pmcraid_init_ioadls()
3152 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL)); in pmcraid_init_ioadls()
3153 ioarcb->ioadl_bus_addr = in pmcraid_init_ioadls()
3154 cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_init_ioadls()
3157 ioadl = &ioarcb->add_data.u.ioadl[3]; in pmcraid_init_ioadls()
3159 ioarcb->ioadl_bus_addr = in pmcraid_init_ioadls()
3160 cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_init_ioadls()
3164 ioadl = &ioarcb->add_data.u.ioadl[ioadl_count]; in pmcraid_init_ioadls()
3165 ioarcb->ioarcb_bus_addr |= in pmcraid_init_ioadls()
3173 * pmcraid_build_ioadl - Build a scatter/gather list and map the buffer
3181 * 0 on success or -1 on failure
3191 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_build_ioadl()
3192 struct pmcraid_ioarcb *ioarcb = &(cmd->ioa_cb->ioarcb); in pmcraid_build_ioadl()
3204 return -1; in pmcraid_build_ioadl()
3209 return -1; in pmcraid_build_ioadl()
3213 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) in pmcraid_build_ioadl()
3214 ioarcb->request_flags0 |= TRANSFER_DIR_WRITE; in pmcraid_build_ioadl()
3216 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_build_ioadl()
3217 ioarcb->data_transfer_length = cpu_to_le32(length); in pmcraid_build_ioadl()
3227 ioadl[i - 1].flags = IOADL_FLAGS_LAST_DESC; in pmcraid_build_ioadl()
3233 * pmcraid_queuecommand_lck - Queue a mid-layer request
3236 * This function queues a request generated by the mid-layer. Midlayer calls
3237 * this routine within host->lock. Some of the functions called by queuecommand
3255 (struct pmcraid_instance *)scsi_cmd->device->host->hostdata; in pmcraid_queuecommand_lck()
3256 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_queuecommand_lck()
3257 res = scsi_cmd->device->hostdata; in pmcraid_queuecommand_lck()
3258 scsi_cmd->result = (DID_OK << 16); in pmcraid_queuecommand_lck()
3263 if (pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_queuecommand_lck()
3265 scsi_cmd->result = (DID_NO_CONNECT << 16); in pmcraid_queuecommand_lck()
3271 if (pinstance->ioa_reset_in_progress) in pmcraid_queuecommand_lck()
3277 if (scsi_cmd->cmnd[0] == SYNCHRONIZE_CACHE) { in pmcraid_queuecommand_lck()
3291 cmd->scsi_cmd = scsi_cmd; in pmcraid_queuecommand_lck()
3292 ioarcb = &(cmd->ioa_cb->ioarcb); in pmcraid_queuecommand_lck()
3293 memcpy(ioarcb->cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len); in pmcraid_queuecommand_lck()
3294 ioarcb->resource_handle = res->cfg_entry.resource_handle; in pmcraid_queuecommand_lck()
3295 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_queuecommand_lck()
3299 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses in pmcraid_queuecommand_lck()
3302 ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) % in pmcraid_queuecommand_lck()
3303 pinstance->num_hrrq; in pmcraid_queuecommand_lck()
3304 cmd->cmd_done = pmcraid_io_done; in pmcraid_queuecommand_lck()
3306 if (RES_IS_GSCSI(res->cfg_entry) || RES_IS_VSET(res->cfg_entry)) { in pmcraid_queuecommand_lck()
3307 if (scsi_cmd->underflow == 0) in pmcraid_queuecommand_lck()
3308 ioarcb->request_flags0 |= INHIBIT_UL_CHECK; in pmcraid_queuecommand_lck()
3310 if (res->sync_reqd) { in pmcraid_queuecommand_lck()
3311 ioarcb->request_flags0 |= SYNC_COMPLETE; in pmcraid_queuecommand_lck()
3312 res->sync_reqd = 0; in pmcraid_queuecommand_lck()
3315 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_queuecommand_lck()
3317 if (scsi_cmd->flags & SCMD_TAGGED) in pmcraid_queuecommand_lck()
3318 ioarcb->request_flags1 |= TASK_TAG_SIMPLE; in pmcraid_queuecommand_lck()
3320 if (RES_IS_GSCSI(res->cfg_entry)) in pmcraid_queuecommand_lck()
3321 ioarcb->request_flags1 |= DELAY_AFTER_RESET; in pmcraid_queuecommand_lck()
3327 le32_to_cpu(ioarcb->response_handle) >> 2, in pmcraid_queuecommand_lck()
3328 scsi_cmd->cmnd[0], pinstance->host->unique_id, in pmcraid_queuecommand_lck()
3329 RES_IS_VSET(res->cfg_entry) ? PMCRAID_VSET_BUS_ID : in pmcraid_queuecommand_lck()
3331 RES_IS_VSET(res->cfg_entry) ? in pmcraid_queuecommand_lck()
3333 res->cfg_entry.unique_flags1 : in pmcraid_queuecommand_lck()
3334 le16_to_cpu(res->cfg_entry.array_id) & 0xFF) : in pmcraid_queuecommand_lck()
3335 RES_TARGET(res->cfg_entry.resource_address), in pmcraid_queuecommand_lck()
3336 RES_LUN(res->cfg_entry.resource_address)); in pmcraid_queuecommand_lck()
3352 * pmcraid_open -char node "open" entry, allowed only users with admin access in DEF_SCSI_QCMD()
3359 return -EACCES; in DEF_SCSI_QCMD()
3362 pinstance = container_of(inode->i_cdev, struct pmcraid_instance, cdev); in DEF_SCSI_QCMD()
3363 filep->private_data = pinstance; in DEF_SCSI_QCMD()
3369 * pmcraid_fasync - Async notifier registration from applications
3379 pinstance = filep->private_data; in pmcraid_chr_fasync()
3380 mutex_lock(&pinstance->aen_queue_lock); in pmcraid_chr_fasync()
3381 rc = fasync_helper(fd, filep, mode, &pinstance->aen_queue); in pmcraid_chr_fasync()
3382 mutex_unlock(&pinstance->aen_queue_lock); in pmcraid_chr_fasync()
3388 * pmcraid_ioctl_driver - ioctl handler for commands handled by driver itself
3405 int rc = -ENOSYS; in pmcraid_ioctl_driver()
3421 * pmcraid_check_ioctl_buffer - check for proper access to user buffer
3442 return -EFAULT; in pmcraid_check_ioctl_buffer()
3446 rc = memcmp(hdr->signature, in pmcraid_check_ioctl_buffer()
3448 sizeof(hdr->signature)); in pmcraid_check_ioctl_buffer()
3451 return -EINVAL; in pmcraid_check_ioctl_buffer()
3458 * pmcraid_ioctl - char node ioctl entry point
3469 int retval = -ENOTTY; in pmcraid_chr_ioctl()
3475 return -ENOMEM; in pmcraid_chr_ioctl()
3486 pinstance = filep->private_data; in pmcraid_chr_ioctl()
3491 return -ENOTTY; in pmcraid_chr_ioctl()
3499 hdr->buffer_length, argp); in pmcraid_chr_ioctl()
3503 retval = -ENOTTY; in pmcraid_chr_ioctl()
3528 * pmcraid_show_log_level - Display adapter's error logging level
3543 (struct pmcraid_instance *)shost->hostdata; in pmcraid_show_log_level()
3544 return snprintf(buf, PAGE_SIZE, "%d\n", pinstance->current_log_level); in pmcraid_show_log_level()
3548 * pmcraid_store_log_level - Change the adapter's error logging level
3569 return -EINVAL; in pmcraid_store_log_level()
3570 /* log-level should be from 0 to 2 */ in pmcraid_store_log_level()
3572 return -EINVAL; in pmcraid_store_log_level()
3575 pinstance = (struct pmcraid_instance *)shost->hostdata; in pmcraid_store_log_level()
3576 pinstance->current_log_level = val; in pmcraid_store_log_level()
3591 * pmcraid_show_drv_version - Display driver version
3618 * pmcraid_show_adapter_id - Display driver assigned adapter id
3634 (struct pmcraid_instance *)shost->hostdata; in pmcraid_show_adapter_id()
3635 u32 adapter_id = pci_dev_id(pinstance->pdev); in pmcraid_show_adapter_id()
3640 adapter_id, MINOR(pinstance->cdev.dev), aen_group); in pmcraid_show_adapter_id()
3676 .this_id = -1,
3686 * pmcraid_isr_msix - implements MSI-X interrupt handling routine
3703 hrrq_id = hrrq_vector->hrrq_id; in pmcraid_isr_msix()
3704 pinstance = hrrq_vector->drv_inst; in pmcraid_isr_msix()
3710 ((ioread32(pinstance->int_regs.host_ioa_interrupt_reg) in pmcraid_isr_msix()
3719 pinstance->ioa_unit_check = 1; in pmcraid_isr_msix()
3723 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_isr_msix()
3727 pinstance->host->host_lock, in pmcraid_isr_msix()
3742 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_isr_msix()
3743 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_isr_msix()
3749 tasklet_schedule(&(pinstance->isr_tasklet[hrrq_id])); in pmcraid_isr_msix()
3755 * pmcraid_isr - implements legacy interrupt handling routine
3779 pinstance = hrrq_vector->drv_inst; in pmcraid_isr()
3793 pinstance->ioa_unit_check = 1; in pmcraid_isr()
3796 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
3800 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
3801 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_isr()
3803 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_isr()
3813 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
3815 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
3818 &(pinstance->isr_tasklet[hrrq_id])); in pmcraid_isr()
3827 * pmcraid_worker_function - worker thread function
3848 if (!atomic_read(&pinstance->expose_resources)) in pmcraid_worker_function()
3851 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_worker_function()
3853 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_worker_function()
3854 list_for_each_entry_safe(res, temp, &pinstance->used_res_q, queue) { in pmcraid_worker_function()
3856 if (res->change_detected == RES_CHANGE_DEL && res->scsi_dev) { in pmcraid_worker_function()
3857 sdev = res->scsi_dev; in pmcraid_worker_function()
3862 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_worker_function()
3866 pinstance->host->host_lock, in pmcraid_worker_function()
3869 res->cfg_entry.resource_address); in pmcraid_worker_function()
3870 list_move_tail(&res->queue, in pmcraid_worker_function()
3871 &pinstance->free_res_q); in pmcraid_worker_function()
3873 &pinstance->resource_lock, in pmcraid_worker_function()
3877 spin_lock_irqsave(&pinstance->resource_lock, in pmcraid_worker_function()
3879 res->change_detected = 0; in pmcraid_worker_function()
3882 pinstance->host->host_lock, in pmcraid_worker_function()
3888 list_for_each_entry(res, &pinstance->used_res_q, queue) { in pmcraid_worker_function()
3890 if (res->change_detected == RES_CHANGE_ADD) { in pmcraid_worker_function()
3893 &res->cfg_entry)) in pmcraid_worker_function()
3896 if (RES_IS_VSET(res->cfg_entry)) { in pmcraid_worker_function()
3899 target = res->cfg_entry.unique_flags1; in pmcraid_worker_function()
3901 target = le16_to_cpu(res->cfg_entry.array_id) & 0xFF; in pmcraid_worker_function()
3907 res->cfg_entry.resource_address); in pmcraid_worker_function()
3908 lun = RES_LUN(res->cfg_entry.resource_address); in pmcraid_worker_function()
3911 res->change_detected = 0; in pmcraid_worker_function()
3912 spin_unlock_irqrestore(&pinstance->resource_lock, in pmcraid_worker_function()
3914 scsi_add_device(pinstance->host, bus, target, lun); in pmcraid_worker_function()
3915 spin_lock_irqsave(&pinstance->resource_lock, in pmcraid_worker_function()
3920 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_worker_function()
3924 * pmcraid_tasklet_function - Tasklet function
3943 pinstance = hrrq_vector->drv_inst; in pmcraid_tasklet_function()
3944 id = hrrq_vector->hrrq_id; in pmcraid_tasklet_function()
3945 lockp = &(pinstance->hrrq_lock[id]); in pmcraid_tasklet_function()
3955 resp = le32_to_cpu(*(pinstance->hrrq_curr[id])); in pmcraid_tasklet_function()
3958 pinstance->host_toggle_bit[id]) { in pmcraid_tasklet_function()
3963 if (pinstance->hrrq_curr[id] < pinstance->hrrq_end[id]) { in pmcraid_tasklet_function()
3964 pinstance->hrrq_curr[id]++; in pmcraid_tasklet_function()
3966 pinstance->hrrq_curr[id] = pinstance->hrrq_start[id]; in pmcraid_tasklet_function()
3967 pinstance->host_toggle_bit[id] ^= 1u; in pmcraid_tasklet_function()
3973 resp = le32_to_cpu(*(pinstance->hrrq_curr[id])); in pmcraid_tasklet_function()
3977 cmd = pinstance->cmd_list[cmd_index]; in pmcraid_tasklet_function()
3980 spin_lock_irqsave(&pinstance->pending_pool_lock, in pmcraid_tasklet_function()
3982 list_del(&cmd->free_list); in pmcraid_tasklet_function()
3983 spin_unlock_irqrestore(&pinstance->pending_pool_lock, in pmcraid_tasklet_function()
3985 del_timer(&cmd->timer); in pmcraid_tasklet_function()
3986 atomic_dec(&pinstance->outstanding_cmds); in pmcraid_tasklet_function()
3988 if (cmd->cmd_done == pmcraid_ioa_reset) { in pmcraid_tasklet_function()
3989 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_tasklet_function()
3991 cmd->cmd_done(cmd); in pmcraid_tasklet_function()
3992 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_tasklet_function()
3994 } else if (cmd->cmd_done != NULL) { in pmcraid_tasklet_function()
3995 cmd->cmd_done(cmd); in pmcraid_tasklet_function()
3999 resp = le32_to_cpu(*(pinstance->hrrq_curr[id])); in pmcraid_tasklet_function()
4006 * pmcraid_unregister_interrupt_handler - de-register interrupts handlers
4009 * This routine un-registers registered interrupt handler and
4018 struct pci_dev *pdev = pinstance->pdev; in pmcraid_unregister_interrupt_handler()
4021 for (i = 0; i < pinstance->num_hrrq; i++) in pmcraid_unregister_interrupt_handler()
4022 free_irq(pci_irq_vector(pdev, i), &pinstance->hrrq_vector[i]); in pmcraid_unregister_interrupt_handler()
4024 pinstance->interrupt_mode = 0; in pmcraid_unregister_interrupt_handler()
4029 * pmcraid_register_interrupt_handler - registers interrupt handler
4030 * @pinstance: pointer to per-adapter instance structure
4033 * 0 on success, non-zero error code otherwise.
4038 struct pci_dev *pdev = pinstance->pdev; in pmcraid_register_interrupt_handler()
4051 if (pdev->msix_enabled) { in pmcraid_register_interrupt_handler()
4060 struct pmcraid_isr_param *vec = &pinstance->hrrq_vector[i]; in pmcraid_register_interrupt_handler()
4062 vec->hrrq_id = i; in pmcraid_register_interrupt_handler()
4063 vec->drv_inst = pinstance; in pmcraid_register_interrupt_handler()
4070 pinstance->num_hrrq = num_hrrq; in pmcraid_register_interrupt_handler()
4071 if (pdev->msix_enabled) { in pmcraid_register_interrupt_handler()
4072 pinstance->interrupt_mode = 1; in pmcraid_register_interrupt_handler()
4074 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_register_interrupt_handler()
4075 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_register_interrupt_handler()
4081 while (--i >= 0) in pmcraid_register_interrupt_handler()
4082 free_irq(pci_irq_vector(pdev, i), &pinstance->hrrq_vector[i]); in pmcraid_register_interrupt_handler()
4088 * pmcraid_release_cmd_blocks - release buufers allocated for command blocks
4100 kmem_cache_free(pinstance->cmd_cachep, pinstance->cmd_list[i]); in pmcraid_release_cmd_blocks()
4101 pinstance->cmd_list[i] = NULL; in pmcraid_release_cmd_blocks()
4103 kmem_cache_destroy(pinstance->cmd_cachep); in pmcraid_release_cmd_blocks()
4104 pinstance->cmd_cachep = NULL; in pmcraid_release_cmd_blocks()
4108 * pmcraid_release_control_blocks - releases buffers alloced for control blocks
4126 if (pinstance->control_pool == NULL) in pmcraid_release_control_blocks()
4130 dma_pool_free(pinstance->control_pool, in pmcraid_release_control_blocks()
4131 pinstance->cmd_list[i]->ioa_cb, in pmcraid_release_control_blocks()
4132 pinstance->cmd_list[i]->ioa_cb_bus_addr); in pmcraid_release_control_blocks()
4133 pinstance->cmd_list[i]->ioa_cb = NULL; in pmcraid_release_control_blocks()
4134 pinstance->cmd_list[i]->ioa_cb_bus_addr = 0; in pmcraid_release_control_blocks()
4136 dma_pool_destroy(pinstance->control_pool); in pmcraid_release_control_blocks()
4137 pinstance->control_pool = NULL; in pmcraid_release_control_blocks()
4141 * pmcraid_allocate_cmd_blocks - allocate memory for cmd block structures
4147 * 0 in case of success; -ENOMEM in case of failure
4153 sprintf(pinstance->cmd_pool_name, "pmcraid_cmd_pool_%d", in pmcraid_allocate_cmd_blocks()
4154 pinstance->host->unique_id); in pmcraid_allocate_cmd_blocks()
4157 pinstance->cmd_cachep = kmem_cache_create( in pmcraid_allocate_cmd_blocks()
4158 pinstance->cmd_pool_name, in pmcraid_allocate_cmd_blocks()
4161 if (!pinstance->cmd_cachep) in pmcraid_allocate_cmd_blocks()
4162 return -ENOMEM; in pmcraid_allocate_cmd_blocks()
4165 pinstance->cmd_list[i] = in pmcraid_allocate_cmd_blocks()
4166 kmem_cache_alloc(pinstance->cmd_cachep, GFP_KERNEL); in pmcraid_allocate_cmd_blocks()
4167 if (!pinstance->cmd_list[i]) { in pmcraid_allocate_cmd_blocks()
4169 return -ENOMEM; in pmcraid_allocate_cmd_blocks()
4176 * pmcraid_allocate_control_blocks - allocates memory control blocks
4183 * 0 in case it can allocate all control blocks, otherwise -ENOMEM
4189 sprintf(pinstance->ctl_pool_name, "pmcraid_control_pool_%d", in pmcraid_allocate_control_blocks()
4190 pinstance->host->unique_id); in pmcraid_allocate_control_blocks()
4192 pinstance->control_pool = in pmcraid_allocate_control_blocks()
4193 dma_pool_create(pinstance->ctl_pool_name, in pmcraid_allocate_control_blocks()
4194 &pinstance->pdev->dev, in pmcraid_allocate_control_blocks()
4198 if (!pinstance->control_pool) in pmcraid_allocate_control_blocks()
4199 return -ENOMEM; in pmcraid_allocate_control_blocks()
4202 pinstance->cmd_list[i]->ioa_cb = in pmcraid_allocate_control_blocks()
4204 pinstance->control_pool, in pmcraid_allocate_control_blocks()
4206 &(pinstance->cmd_list[i]->ioa_cb_bus_addr)); in pmcraid_allocate_control_blocks()
4208 if (!pinstance->cmd_list[i]->ioa_cb) { in pmcraid_allocate_control_blocks()
4210 return -ENOMEM; in pmcraid_allocate_control_blocks()
4217 * pmcraid_release_host_rrqs - release memory allocated for hrrq buffer(s)
4230 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_host_rrqs()
4232 pinstance->hrrq_start[i], in pmcraid_release_host_rrqs()
4233 pinstance->hrrq_start_bus_addr[i]); in pmcraid_release_host_rrqs()
4236 pinstance->hrrq_start[i] = NULL; in pmcraid_release_host_rrqs()
4237 pinstance->hrrq_start_bus_addr[i] = 0; in pmcraid_release_host_rrqs()
4238 pinstance->host_toggle_bit[i] = 0; in pmcraid_release_host_rrqs()
4243 * pmcraid_allocate_host_rrqs - Allocate and initialize host RRQ buffers
4247 * 0 hrrq buffers are allocated, -ENOMEM otherwise.
4255 for (i = 0; i < pinstance->num_hrrq; i++) { in pmcraid_allocate_host_rrqs()
4256 pinstance->hrrq_start[i] = in pmcraid_allocate_host_rrqs()
4257 dma_alloc_coherent(&pinstance->pdev->dev, buffer_size, in pmcraid_allocate_host_rrqs()
4258 &pinstance->hrrq_start_bus_addr[i], in pmcraid_allocate_host_rrqs()
4260 if (!pinstance->hrrq_start[i]) { in pmcraid_allocate_host_rrqs()
4264 return -ENOMEM; in pmcraid_allocate_host_rrqs()
4267 pinstance->hrrq_curr[i] = pinstance->hrrq_start[i]; in pmcraid_allocate_host_rrqs()
4268 pinstance->hrrq_end[i] = in pmcraid_allocate_host_rrqs()
4269 pinstance->hrrq_start[i] + PMCRAID_MAX_CMD - 1; in pmcraid_allocate_host_rrqs()
4270 pinstance->host_toggle_bit[i] = 1; in pmcraid_allocate_host_rrqs()
4271 spin_lock_init(&pinstance->hrrq_lock[i]); in pmcraid_allocate_host_rrqs()
4277 * pmcraid_release_hcams - release HCAM buffers
4286 if (pinstance->ccn.msg != NULL) { in pmcraid_release_hcams()
4287 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_hcams()
4290 pinstance->ccn.msg, in pmcraid_release_hcams()
4291 pinstance->ccn.baddr); in pmcraid_release_hcams()
4293 pinstance->ccn.msg = NULL; in pmcraid_release_hcams()
4294 pinstance->ccn.hcam = NULL; in pmcraid_release_hcams()
4295 pinstance->ccn.baddr = 0; in pmcraid_release_hcams()
4298 if (pinstance->ldn.msg != NULL) { in pmcraid_release_hcams()
4299 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_hcams()
4302 pinstance->ldn.msg, in pmcraid_release_hcams()
4303 pinstance->ldn.baddr); in pmcraid_release_hcams()
4305 pinstance->ldn.msg = NULL; in pmcraid_release_hcams()
4306 pinstance->ldn.hcam = NULL; in pmcraid_release_hcams()
4307 pinstance->ldn.baddr = 0; in pmcraid_release_hcams()
4312 * pmcraid_allocate_hcams - allocates HCAM buffers
4316 * 0 in case of successful allocation, non-zero otherwise
4320 pinstance->ccn.msg = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_allocate_hcams()
4323 &pinstance->ccn.baddr, GFP_KERNEL); in pmcraid_allocate_hcams()
4325 pinstance->ldn.msg = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_allocate_hcams()
4328 &pinstance->ldn.baddr, GFP_KERNEL); in pmcraid_allocate_hcams()
4330 if (pinstance->ldn.msg == NULL || pinstance->ccn.msg == NULL) { in pmcraid_allocate_hcams()
4333 pinstance->ccn.hcam = in pmcraid_allocate_hcams()
4334 (void *)pinstance->ccn.msg + PMCRAID_AEN_HDR_SIZE; in pmcraid_allocate_hcams()
4335 pinstance->ldn.hcam = in pmcraid_allocate_hcams()
4336 (void *)pinstance->ldn.msg + PMCRAID_AEN_HDR_SIZE; in pmcraid_allocate_hcams()
4338 atomic_set(&pinstance->ccn.ignore, 0); in pmcraid_allocate_hcams()
4339 atomic_set(&pinstance->ldn.ignore, 0); in pmcraid_allocate_hcams()
4342 return (pinstance->ldn.msg == NULL) ? -ENOMEM : 0; in pmcraid_allocate_hcams()
4346 * pmcraid_release_config_buffers - release config.table buffers
4354 if (pinstance->cfg_table != NULL && in pmcraid_release_config_buffers()
4355 pinstance->cfg_table_bus_addr != 0) { in pmcraid_release_config_buffers()
4356 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_config_buffers()
4358 pinstance->cfg_table, in pmcraid_release_config_buffers()
4359 pinstance->cfg_table_bus_addr); in pmcraid_release_config_buffers()
4360 pinstance->cfg_table = NULL; in pmcraid_release_config_buffers()
4361 pinstance->cfg_table_bus_addr = 0; in pmcraid_release_config_buffers()
4364 if (pinstance->res_entries != NULL) { in pmcraid_release_config_buffers()
4368 list_del(&pinstance->res_entries[i].queue); in pmcraid_release_config_buffers()
4369 kfree(pinstance->res_entries); in pmcraid_release_config_buffers()
4370 pinstance->res_entries = NULL; in pmcraid_release_config_buffers()
4377 * pmcraid_allocate_config_buffers - allocates DMAable memory for config table
4381 * 0 for successful allocation, -ENOMEM for any failure
4387 pinstance->res_entries = in pmcraid_allocate_config_buffers()
4392 if (NULL == pinstance->res_entries) { in pmcraid_allocate_config_buffers()
4394 return -ENOMEM; in pmcraid_allocate_config_buffers()
4398 list_add_tail(&pinstance->res_entries[i].queue, in pmcraid_allocate_config_buffers()
4399 &pinstance->free_res_q); in pmcraid_allocate_config_buffers()
4401 pinstance->cfg_table = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_allocate_config_buffers()
4403 &pinstance->cfg_table_bus_addr, in pmcraid_allocate_config_buffers()
4406 if (NULL == pinstance->cfg_table) { in pmcraid_allocate_config_buffers()
4409 return -ENOMEM; in pmcraid_allocate_config_buffers()
4415 return -ENOMEM; in pmcraid_allocate_config_buffers()
4422 * pmcraid_init_tasklets - registers tasklets for response handling
4432 for (i = 0; i < pinstance->num_hrrq; i++) in pmcraid_init_tasklets()
4433 tasklet_init(&pinstance->isr_tasklet[i], in pmcraid_init_tasklets()
4435 (unsigned long)&pinstance->hrrq_vector[i]); in pmcraid_init_tasklets()
4439 * pmcraid_kill_tasklets - destroys tasklets registered for response handling
4449 for (i = 0; i < pinstance->num_hrrq; i++) in pmcraid_kill_tasklets()
4450 tasklet_kill(&pinstance->isr_tasklet[i]); in pmcraid_kill_tasklets()
4454 * pmcraid_release_buffers - release per-adapter buffers allocated
4466 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_release_buffers()
4468 if (pinstance->inq_data != NULL) { in pmcraid_release_buffers()
4469 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_buffers()
4471 pinstance->inq_data, in pmcraid_release_buffers()
4472 pinstance->inq_data_baddr); in pmcraid_release_buffers()
4474 pinstance->inq_data = NULL; in pmcraid_release_buffers()
4475 pinstance->inq_data_baddr = 0; in pmcraid_release_buffers()
4478 if (pinstance->timestamp_data != NULL) { in pmcraid_release_buffers()
4479 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_buffers()
4481 pinstance->timestamp_data, in pmcraid_release_buffers()
4482 pinstance->timestamp_data_baddr); in pmcraid_release_buffers()
4484 pinstance->timestamp_data = NULL; in pmcraid_release_buffers()
4485 pinstance->timestamp_data_baddr = 0; in pmcraid_release_buffers()
4490 * pmcraid_init_buffers - allocates memory and initializes various structures
4493 * This routine pre-allocates memory based on the type of block as below:
4496 * config-table entries : DMAable memory using dma_alloc_coherent
4500 * 0 in case all of the blocks are allocated, -ENOMEM otherwise.
4508 pinstance->num_hrrq); in pmcraid_init_buffers()
4509 return -ENOMEM; in pmcraid_init_buffers()
4514 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_init_buffers()
4515 return -ENOMEM; in pmcraid_init_buffers()
4521 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_init_buffers()
4522 return -ENOMEM; in pmcraid_init_buffers()
4529 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_init_buffers()
4530 return -ENOMEM; in pmcraid_init_buffers()
4534 pinstance->inq_data = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_init_buffers()
4536 &pinstance->inq_data_baddr, GFP_KERNEL); in pmcraid_init_buffers()
4537 if (pinstance->inq_data == NULL) { in pmcraid_init_buffers()
4540 return -ENOMEM; in pmcraid_init_buffers()
4544 pinstance->timestamp_data = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_init_buffers()
4546 &pinstance->timestamp_data_baddr, in pmcraid_init_buffers()
4548 if (pinstance->timestamp_data == NULL) { in pmcraid_init_buffers()
4552 return -ENOMEM; in pmcraid_init_buffers()
4561 struct pmcraid_cmd *cmdp = pinstance->cmd_list[i]; in pmcraid_init_buffers()
4563 cmdp->drv_inst = pinstance; in pmcraid_init_buffers()
4564 list_add_tail(&cmdp->free_list, &pinstance->free_cmd_pool); in pmcraid_init_buffers()
4571 * pmcraid_reinit_buffers - resets various buffer pointers
4581 for (i = 0; i < pinstance->num_hrrq; i++) { in pmcraid_reinit_buffers()
4582 memset(pinstance->hrrq_start[i], 0, buffer_size); in pmcraid_reinit_buffers()
4583 pinstance->hrrq_curr[i] = pinstance->hrrq_start[i]; in pmcraid_reinit_buffers()
4584 pinstance->hrrq_end[i] = in pmcraid_reinit_buffers()
4585 pinstance->hrrq_start[i] + PMCRAID_MAX_CMD - 1; in pmcraid_reinit_buffers()
4586 pinstance->host_toggle_bit[i] = 1; in pmcraid_reinit_buffers()
4591 * pmcraid_init_instance - initialize per instance data structure
4597 * 0 on success, non-zero in case of any failure
4603 (struct pmcraid_instance *)host->hostdata; in pmcraid_init_instance()
4605 pinstance->host = host; in pmcraid_init_instance()
4606 pinstance->pdev = pdev; in pmcraid_init_instance()
4609 pinstance->mapped_dma_addr = mapped_pci_addr; in pmcraid_init_instance()
4611 /* Initialize chip-specific details */ in pmcraid_init_instance()
4613 struct pmcraid_chip_details *chip_cfg = pinstance->chip_cfg; in pmcraid_init_instance()
4614 struct pmcraid_interrupts *pint_regs = &pinstance->int_regs; in pmcraid_init_instance()
4616 pinstance->ioarrin = mapped_pci_addr + chip_cfg->ioarrin; in pmcraid_init_instance()
4618 pint_regs->ioa_host_interrupt_reg = in pmcraid_init_instance()
4619 mapped_pci_addr + chip_cfg->ioa_host_intr; in pmcraid_init_instance()
4620 pint_regs->ioa_host_interrupt_clr_reg = in pmcraid_init_instance()
4621 mapped_pci_addr + chip_cfg->ioa_host_intr_clr; in pmcraid_init_instance()
4622 pint_regs->ioa_host_msix_interrupt_reg = in pmcraid_init_instance()
4623 mapped_pci_addr + chip_cfg->ioa_host_msix_intr; in pmcraid_init_instance()
4624 pint_regs->host_ioa_interrupt_reg = in pmcraid_init_instance()
4625 mapped_pci_addr + chip_cfg->host_ioa_intr; in pmcraid_init_instance()
4626 pint_regs->host_ioa_interrupt_clr_reg = in pmcraid_init_instance()
4627 mapped_pci_addr + chip_cfg->host_ioa_intr_clr; in pmcraid_init_instance()
4632 pinstance->mailbox = mapped_pci_addr + chip_cfg->mailbox; in pmcraid_init_instance()
4633 pinstance->ioa_status = mapped_pci_addr + chip_cfg->ioastatus; in pmcraid_init_instance()
4634 pint_regs->ioa_host_interrupt_mask_reg = in pmcraid_init_instance()
4635 mapped_pci_addr + chip_cfg->ioa_host_mask; in pmcraid_init_instance()
4636 pint_regs->ioa_host_interrupt_mask_clr_reg = in pmcraid_init_instance()
4637 mapped_pci_addr + chip_cfg->ioa_host_mask_clr; in pmcraid_init_instance()
4638 pint_regs->global_interrupt_mask_reg = in pmcraid_init_instance()
4639 mapped_pci_addr + chip_cfg->global_intr_mask; in pmcraid_init_instance()
4642 pinstance->ioa_reset_attempts = 0; in pmcraid_init_instance()
4643 init_waitqueue_head(&pinstance->reset_wait_q); in pmcraid_init_instance()
4645 atomic_set(&pinstance->outstanding_cmds, 0); in pmcraid_init_instance()
4646 atomic_set(&pinstance->last_message_id, 0); in pmcraid_init_instance()
4647 atomic_set(&pinstance->expose_resources, 0); in pmcraid_init_instance()
4649 INIT_LIST_HEAD(&pinstance->free_res_q); in pmcraid_init_instance()
4650 INIT_LIST_HEAD(&pinstance->used_res_q); in pmcraid_init_instance()
4651 INIT_LIST_HEAD(&pinstance->free_cmd_pool); in pmcraid_init_instance()
4652 INIT_LIST_HEAD(&pinstance->pending_cmd_pool); in pmcraid_init_instance()
4654 spin_lock_init(&pinstance->free_pool_lock); in pmcraid_init_instance()
4655 spin_lock_init(&pinstance->pending_pool_lock); in pmcraid_init_instance()
4656 spin_lock_init(&pinstance->resource_lock); in pmcraid_init_instance()
4657 mutex_init(&pinstance->aen_queue_lock); in pmcraid_init_instance()
4659 /* Work-queue (Shared) for deferred processing error handling */ in pmcraid_init_instance()
4660 INIT_WORK(&pinstance->worker_q, pmcraid_worker_function); in pmcraid_init_instance()
4663 pinstance->current_log_level = pmcraid_log_level; in pmcraid_init_instance()
4666 pinstance->ioa_state = IOA_STATE_UNKNOWN; in pmcraid_init_instance()
4667 pinstance->reset_cmd = NULL; in pmcraid_init_instance()
4672 * pmcraid_shutdown - shutdown adapter controller.
4688 * pmcraid_get_minor - returns unused minor number from minor number bitmap
4700 * pmcraid_release_minor - releases given minor back to minor number bitmap
4708 * pmcraid_setup_chrdev - allocates a minor number and registers a char device
4713 * 0 in case of success, otherwise non-zero
4721 cdev_init(&pinstance->cdev, &pmcraid_fops); in pmcraid_setup_chrdev()
4722 pinstance->cdev.owner = THIS_MODULE; in pmcraid_setup_chrdev()
4724 error = cdev_add(&pinstance->cdev, MKDEV(pmcraid_major, minor), 1); in pmcraid_setup_chrdev()
4735 * pmcraid_release_chrdev - unregisters per-adapter management interface
4744 pmcraid_release_minor(MINOR(pinstance->cdev.dev)); in pmcraid_release_chrdev()
4746 MKDEV(pmcraid_major, MINOR(pinstance->cdev.dev))); in pmcraid_release_chrdev()
4747 cdev_del(&pinstance->cdev); in pmcraid_release_chrdev()
4751 * pmcraid_remove - IOA hot plug remove entry point
4765 scsi_remove_host(pinstance->host); in pmcraid_remove()
4767 /* block requests from mid-layer */ in pmcraid_remove()
4768 scsi_block_requests(pinstance->host); in pmcraid_remove()
4774 flush_work(&pinstance->worker_q); in pmcraid_remove()
4779 iounmap(pinstance->mapped_dma_addr); in pmcraid_remove()
4781 scsi_host_put(pinstance->host); in pmcraid_remove()
4788 * pmcraid_suspend - driver suspend entry point for power management
4791 * Return Value - 0 always
4807 * pmcraid_resume - driver resume entry point PCI power management
4810 * Return Value - 0 in case of success. Error code in case of any failure
4816 struct Scsi_Host *host = pinstance->host; in pmcraid_resume()
4820 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) in pmcraid_resume()
4821 rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_resume()
4824 rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_resume()
4827 dev_err(&pdev->dev, "resume: Failed to set PCI DMA mask\n"); in pmcraid_resume()
4832 atomic_set(&pinstance->outstanding_cmds, 0); in pmcraid_resume()
4836 dev_err(&pdev->dev, in pmcraid_resume()
4838 rc = -ENODEV; in pmcraid_resume()
4848 pinstance->ioa_hard_reset = 1; in pmcraid_resume()
4854 dev_err(&pdev->dev, "couldn't initialize IOA\n"); in pmcraid_resume()
4855 rc = -ENODEV; in pmcraid_resume()
4875 * pmcraid_complete_ioa_reset - Called by either timer or tasklet during
4881 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_complete_ioa_reset()
4884 spin_lock_irqsave(pinstance->host->host_lock, flags); in pmcraid_complete_ioa_reset()
4886 spin_unlock_irqrestore(pinstance->host->host_lock, flags); in pmcraid_complete_ioa_reset()
4887 scsi_unblock_requests(pinstance->host); in pmcraid_complete_ioa_reset()
4888 schedule_work(&pinstance->worker_q); in pmcraid_complete_ioa_reset()
4892 * pmcraid_set_supported_devs - sends SET SUPPORTED DEVICES to IOAFP
4897 * 0 for success or non-zero for failure cases
4901 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_set_supported_devs()
4906 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_set_supported_devs()
4907 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_set_supported_devs()
4908 ioarcb->cdb[0] = PMCRAID_SET_SUPPORTED_DEVICES; in pmcraid_set_supported_devs()
4909 ioarcb->cdb[1] = ALL_DEVICES_SUPPORTED; in pmcraid_set_supported_devs()
4915 if (cmd->drv_inst->reinit_cfg_table) { in pmcraid_set_supported_devs()
4916 cmd->drv_inst->reinit_cfg_table = 0; in pmcraid_set_supported_devs()
4917 cmd->release = 1; in pmcraid_set_supported_devs()
4933 * pmcraid_set_timestamp - set the timestamp to IOAFP
4938 * 0 for success or non-zero for failure cases
4942 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_set_timestamp()
4943 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_set_timestamp()
4950 pinstance->timestamp_data->timestamp[0] = (__u8)(timestamp); in pmcraid_set_timestamp()
4951 pinstance->timestamp_data->timestamp[1] = (__u8)((timestamp) >> 8); in pmcraid_set_timestamp()
4952 pinstance->timestamp_data->timestamp[2] = (__u8)((timestamp) >> 16); in pmcraid_set_timestamp()
4953 pinstance->timestamp_data->timestamp[3] = (__u8)((timestamp) >> 24); in pmcraid_set_timestamp()
4954 pinstance->timestamp_data->timestamp[4] = (__u8)((timestamp) >> 32); in pmcraid_set_timestamp()
4955 pinstance->timestamp_data->timestamp[5] = (__u8)((timestamp) >> 40); in pmcraid_set_timestamp()
4958 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_set_timestamp()
4959 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_set_timestamp()
4960 ioarcb->cdb[0] = PMCRAID_SCSI_SET_TIMESTAMP; in pmcraid_set_timestamp()
4961 ioarcb->cdb[1] = PMCRAID_SCSI_SERVICE_ACTION; in pmcraid_set_timestamp()
4962 memcpy(&(ioarcb->cdb[6]), &time_stamp_len, sizeof(time_stamp_len)); in pmcraid_set_timestamp()
4964 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_set_timestamp()
4967 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_set_timestamp()
4968 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL)); in pmcraid_set_timestamp()
4970 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_set_timestamp()
4971 ioarcb->request_flags0 |= TRANSFER_DIR_WRITE; in pmcraid_set_timestamp()
4972 ioarcb->data_transfer_length = in pmcraid_set_timestamp()
4974 ioadl = &(ioarcb->add_data.u.ioadl[0]); in pmcraid_set_timestamp()
4975 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_set_timestamp()
4976 ioadl->address = cpu_to_le64(pinstance->timestamp_data_baddr); in pmcraid_set_timestamp()
4977 ioadl->data_len = cpu_to_le32(sizeof(struct pmcraid_timestamp_data)); in pmcraid_set_timestamp()
4979 if (!pinstance->timestamp_error) { in pmcraid_set_timestamp()
4980 pinstance->timestamp_error = 0; in pmcraid_set_timestamp()
4992 * pmcraid_init_res_table - Initialize the resource table
4997 * devices and schedule adding/removing them from the mid-layer
5005 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_init_res_table()
5013 if (pinstance->cfg_table->flags & MICROCODE_UPDATE_REQUIRED) in pmcraid_init_res_table()
5016 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_init_res_table()
5018 /* resource list is protected by pinstance->resource_lock. in pmcraid_init_res_table()
5019 * init_res_table can be called from probe (user-thread) or runtime in pmcraid_init_res_table()
5022 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_init_res_table()
5024 list_for_each_entry_safe(res, temp, &pinstance->used_res_q, queue) in pmcraid_init_res_table()
5025 list_move_tail(&res->queue, &old_res); in pmcraid_init_res_table()
5027 for (i = 0; i < le16_to_cpu(pinstance->cfg_table->num_entries); i++) { in pmcraid_init_res_table()
5028 if (be16_to_cpu(pinstance->inq_data->fw_version) <= in pmcraid_init_res_table()
5030 cfgte = &pinstance->cfg_table->entries[i]; in pmcraid_init_res_table()
5033 &pinstance->cfg_table->entries_ext[i]; in pmcraid_init_res_table()
5043 rc = memcmp(&res->cfg_entry.resource_address, in pmcraid_init_res_table()
5044 &cfgte->resource_address, in pmcraid_init_res_table()
5045 sizeof(cfgte->resource_address)); in pmcraid_init_res_table()
5047 list_move_tail(&res->queue, in pmcraid_init_res_table()
5048 &pinstance->used_res_q); in pmcraid_init_res_table()
5057 if (list_empty(&pinstance->free_res_q)) { in pmcraid_init_res_table()
5063 res = list_entry(pinstance->free_res_q.next, in pmcraid_init_res_table()
5066 res->scsi_dev = NULL; in pmcraid_init_res_table()
5067 res->change_detected = RES_CHANGE_ADD; in pmcraid_init_res_table()
5068 res->reset_progress = 0; in pmcraid_init_res_table()
5069 list_move_tail(&res->queue, &pinstance->used_res_q); in pmcraid_init_res_table()
5076 memcpy(&res->cfg_entry, cfgte, in pmcraid_init_res_table()
5077 pinstance->config_table_entry_size); in pmcraid_init_res_table()
5079 res->cfg_entry.resource_type, in pmcraid_init_res_table()
5081 res->cfg_entry.unique_flags1 : in pmcraid_init_res_table()
5082 le16_to_cpu(res->cfg_entry.array_id) & 0xFF), in pmcraid_init_res_table()
5083 le32_to_cpu(res->cfg_entry.resource_address)); in pmcraid_init_res_table()
5087 /* Detect any deleted entries, mark them for deletion from mid-layer */ in pmcraid_init_res_table()
5090 if (res->scsi_dev) { in pmcraid_init_res_table()
5091 res->change_detected = RES_CHANGE_DEL; in pmcraid_init_res_table()
5092 res->cfg_entry.resource_handle = in pmcraid_init_res_table()
5094 list_move_tail(&res->queue, &pinstance->used_res_q); in pmcraid_init_res_table()
5096 list_move_tail(&res->queue, &pinstance->free_res_q); in pmcraid_init_res_table()
5101 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_init_res_table()
5106 * pmcraid_querycfg - Send a Query IOA Config to the adapter.
5117 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_querycfg()
5119 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_querycfg()
5122 if (be16_to_cpu(pinstance->inq_data->fw_version) <= in pmcraid_querycfg()
5124 pinstance->config_table_entry_size = in pmcraid_querycfg()
5127 pinstance->config_table_entry_size = in pmcraid_querycfg()
5130 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_querycfg()
5131 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_querycfg()
5133 ioarcb->cdb[0] = PMCRAID_QUERY_IOA_CONFIG; in pmcraid_querycfg()
5135 /* firmware requires 4-byte length field, specified in B.E format */ in pmcraid_querycfg()
5136 memcpy(&(ioarcb->cdb[10]), &cfg_table_size, sizeof(cfg_table_size)); in pmcraid_querycfg()
5141 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_querycfg()
5144 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_querycfg()
5145 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~0x1FULL); in pmcraid_querycfg()
5147 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_querycfg()
5148 ioarcb->data_transfer_length = in pmcraid_querycfg()
5151 ioadl = &(ioarcb->add_data.u.ioadl[0]); in pmcraid_querycfg()
5152 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_querycfg()
5153 ioadl->address = cpu_to_le64(pinstance->cfg_table_bus_addr); in pmcraid_querycfg()
5154 ioadl->data_len = cpu_to_le32(sizeof(struct pmcraid_config_table)); in pmcraid_querycfg()
5162 * pmcraid_probe - PCI probe entry pointer for PMC MaxRAID controller driver
5168 * returns non-zero error code in case of any failure
5182 return -ENOMEM; in pmcraid_probe()
5189 dev_err(&pdev->dev, "Cannot enable adapter\n"); in pmcraid_probe()
5194 dev_info(&pdev->dev, in pmcraid_probe()
5196 pdev->vendor, pdev->device, in pmcraid_probe()
5202 dev_err(&pdev->dev, in pmcraid_probe()
5210 dev_err(&pdev->dev, "Couldn't map PCI registers memory\n"); in pmcraid_probe()
5211 rc = -ENOMEM; in pmcraid_probe()
5218 * 32-bit addressable range though it has 64-bit IOARRIN register. in pmcraid_probe()
5219 * However, firmware supports 64-bit streaming DMA buffers, whereas in pmcraid_probe()
5220 * coherent buffers are to be 32-bit. Since dma_alloc_coherent always in pmcraid_probe()
5225 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) in pmcraid_probe()
5226 rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_probe()
5228 /* firmware expects 32-bit DMA addresses for IOARRIN register; set 32 in pmcraid_probe()
5232 rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_probe()
5235 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n"); in pmcraid_probe()
5243 dev_err(&pdev->dev, "scsi_host_alloc failed!\n"); in pmcraid_probe()
5244 rc = -ENOMEM; in pmcraid_probe()
5248 host->max_id = PMCRAID_MAX_NUM_TARGETS_PER_BUS; in pmcraid_probe()
5249 host->max_lun = PMCRAID_MAX_NUM_LUNS_PER_TARGET; in pmcraid_probe()
5250 host->unique_id = host->host_no; in pmcraid_probe()
5251 host->max_channel = PMCRAID_MAX_BUS_TO_SCAN; in pmcraid_probe()
5252 host->max_cmd_len = PMCRAID_MAX_CDB_LEN; in pmcraid_probe()
5255 pinstance = (struct pmcraid_instance *)host->hostdata; in pmcraid_probe()
5258 pinstance->chip_cfg = in pmcraid_probe()
5259 (struct pmcraid_chip_details *)(dev_id->driver_data); in pmcraid_probe()
5264 dev_err(&pdev->dev, "failed to initialize adapter instance\n"); in pmcraid_probe()
5270 /* Save PCI config-space for use following the reset */ in pmcraid_probe()
5271 rc = pci_save_state(pinstance->pdev); in pmcraid_probe()
5274 dev_err(&pdev->dev, "Failed to save PCI config space\n"); in pmcraid_probe()
5283 dev_err(&pdev->dev, "couldn't register interrupt handler\n"); in pmcraid_probe()
5307 dev_err(&pdev->dev, "couldn't initialize IOA\n"); in pmcraid_probe()
5312 /* Add adapter instance into mid-layer list */ in pmcraid_probe()
5313 rc = scsi_add_host(pinstance->host, &pdev->dev); in pmcraid_probe()
5315 pmcraid_err("couldn't add host into mid-layer: %d\n", rc); in pmcraid_probe()
5319 scsi_scan_host(pinstance->host); in pmcraid_probe()
5324 pmcraid_err("couldn't create mgmt interface, error: %x\n", in pmcraid_probe()
5332 atomic_set(&pinstance->expose_resources, 1); in pmcraid_probe()
5333 schedule_work(&pinstance->worker_q); in pmcraid_probe()
5358 return -ENODEV; in pmcraid_probe()
5376 * pmcraid_init - module load entry point
5430 * pmcraid_exit - module unload entry point