• Home
  • Raw
  • Download

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
70 MODULE_AUTHOR("Anil Ravindranath<anil_ravindranath@pmc-sierra.com>");
77 "Enables firmware error code logging, default :1 high-severity"
78 " errors, 2: all errors including high-severity errors,"
126 * pmcraid_slave_alloc - Prepare for commands to a device
129 * This function is called by mid-layer prior to sending any command to the new
135 * 0 on success / -ENXIO if device does not exist
143 int rc = -ENXIO; in pmcraid_slave_alloc()
146 pinstance = shost_priv(scsi_dev->host); in pmcraid_slave_alloc()
148 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_slave_alloc()
155 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_slave_alloc()
156 list_for_each_entry(temp, &pinstance->used_res_q, queue) { in pmcraid_slave_alloc()
158 /* do not expose VSETs with order-ids > MAX_VSET_TARGETS */ in pmcraid_slave_alloc()
159 if (RES_IS_VSET(temp->cfg_entry)) { in pmcraid_slave_alloc()
161 target = temp->cfg_entry.unique_flags1; in pmcraid_slave_alloc()
163 target = le16_to_cpu(temp->cfg_entry.array_id) & 0xFF; in pmcraid_slave_alloc()
169 } else if (RES_IS_GSCSI(temp->cfg_entry)) { in pmcraid_slave_alloc()
170 target = RES_TARGET(temp->cfg_entry.resource_address); in pmcraid_slave_alloc()
172 lun = RES_LUN(temp->cfg_entry.resource_address); in pmcraid_slave_alloc()
177 if (bus == scsi_dev->channel && in pmcraid_slave_alloc()
178 target == scsi_dev->id && in pmcraid_slave_alloc()
179 lun == scsi_dev->lun) { in pmcraid_slave_alloc()
186 res->scsi_dev = scsi_dev; in pmcraid_slave_alloc()
187 scsi_dev->hostdata = res; in pmcraid_slave_alloc()
188 res->change_detected = 0; in pmcraid_slave_alloc()
189 atomic_set(&res->read_failures, 0); in pmcraid_slave_alloc()
190 atomic_set(&res->write_failures, 0); in pmcraid_slave_alloc()
193 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_slave_alloc()
198 * pmcraid_slave_configure - Configures a SCSI device
203 * timeout value (default 30s) will be over-written to a higher value (60s)
204 * and max_sectors value will be over-written to 512. It also sets queue depth
205 * to host->cmd_per_lun value
212 struct pmcraid_resource_entry *res = scsi_dev->hostdata; in pmcraid_slave_configure()
218 if (RES_IS_GSCSI(res->cfg_entry) && in pmcraid_slave_configure()
219 scsi_dev->type != TYPE_ENCLOSURE) in pmcraid_slave_configure()
220 return -ENXIO; in pmcraid_slave_configure()
223 scsi_dev->host->unique_id, in pmcraid_slave_configure()
224 scsi_dev->channel, in pmcraid_slave_configure()
225 scsi_dev->id, in pmcraid_slave_configure()
226 (u8)scsi_dev->lun); in pmcraid_slave_configure()
228 if (RES_IS_GSCSI(res->cfg_entry)) { in pmcraid_slave_configure()
229 scsi_dev->allow_restart = 1; in pmcraid_slave_configure()
230 } else if (RES_IS_VSET(res->cfg_entry)) { in pmcraid_slave_configure()
231 scsi_dev->allow_restart = 1; in pmcraid_slave_configure()
232 blk_queue_rq_timeout(scsi_dev->request_queue, in pmcraid_slave_configure()
234 blk_queue_max_hw_sectors(scsi_dev->request_queue, in pmcraid_slave_configure()
241 if (!RES_IS_GSCSI(res->cfg_entry) && !RES_IS_VSET(res->cfg_entry)) in pmcraid_slave_configure()
242 scsi_dev->tagged_supported = 0; in pmcraid_slave_configure()
248 * pmcraid_slave_destroy - Unconfigure a SCSI device before removing it
252 * This is called by mid-layer before removing a device. Pointer assignments
262 res = (struct pmcraid_resource_entry *)scsi_dev->hostdata; in pmcraid_slave_destroy()
265 res->scsi_dev = NULL; in pmcraid_slave_destroy()
267 scsi_dev->hostdata = NULL; in pmcraid_slave_destroy()
271 * pmcraid_change_queue_depth - Change the device's queue depth
286 * pmcraid_init_cmdblk - initializes a command block
296 struct pmcraid_ioarcb *ioarcb = &(cmd->ioa_cb->ioarcb); in pmcraid_init_cmdblk()
297 dma_addr_t dma_addr = cmd->ioa_cb_bus_addr; in pmcraid_init_cmdblk()
304 cmd->index = index; in pmcraid_init_cmdblk()
305 ioarcb->response_handle = cpu_to_le32(index << 2); in pmcraid_init_cmdblk()
306 ioarcb->ioarcb_bus_addr = cpu_to_le64(dma_addr); in pmcraid_init_cmdblk()
307 ioarcb->ioasa_bus_addr = cpu_to_le64(dma_addr + ioasa_offset); in pmcraid_init_cmdblk()
308 ioarcb->ioasa_len = cpu_to_le16(sizeof(struct pmcraid_ioasa)); in pmcraid_init_cmdblk()
310 /* re-initialization of various lengths, called once command is in pmcraid_init_cmdblk()
313 memset(&cmd->ioa_cb->ioarcb.cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_init_cmdblk()
314 ioarcb->hrrq_id = 0; in pmcraid_init_cmdblk()
315 ioarcb->request_flags0 = 0; in pmcraid_init_cmdblk()
316 ioarcb->request_flags1 = 0; in pmcraid_init_cmdblk()
317 ioarcb->cmd_timeout = 0; in pmcraid_init_cmdblk()
318 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~0x1FULL); in pmcraid_init_cmdblk()
319 ioarcb->ioadl_bus_addr = 0; in pmcraid_init_cmdblk()
320 ioarcb->ioadl_length = 0; in pmcraid_init_cmdblk()
321 ioarcb->data_transfer_length = 0; in pmcraid_init_cmdblk()
322 ioarcb->add_cmd_param_length = 0; in pmcraid_init_cmdblk()
323 ioarcb->add_cmd_param_offset = 0; in pmcraid_init_cmdblk()
324 cmd->ioa_cb->ioasa.ioasc = 0; in pmcraid_init_cmdblk()
325 cmd->ioa_cb->ioasa.residual_data_length = 0; in pmcraid_init_cmdblk()
326 cmd->time_left = 0; in pmcraid_init_cmdblk()
329 cmd->cmd_done = NULL; in pmcraid_init_cmdblk()
330 cmd->scsi_cmd = NULL; in pmcraid_init_cmdblk()
331 cmd->release = 0; in pmcraid_init_cmdblk()
332 cmd->completion_req = 0; in pmcraid_init_cmdblk()
333 cmd->sense_buffer = NULL; in pmcraid_init_cmdblk()
334 cmd->sense_buffer_dma = 0; in pmcraid_init_cmdblk()
335 cmd->dma_handle = 0; in pmcraid_init_cmdblk()
336 timer_setup(&cmd->timer, NULL, 0); in pmcraid_init_cmdblk()
340 * pmcraid_reinit_cmdblk - reinitialize a command block
349 pmcraid_init_cmdblk(cmd, -1); in pmcraid_reinit_cmdblk()
353 * pmcraid_get_free_cmd - get a free cmd block from command block pool
367 spin_lock_irqsave(&pinstance->free_pool_lock, lock_flags); in pmcraid_get_free_cmd()
369 if (!list_empty(&pinstance->free_cmd_pool)) { in pmcraid_get_free_cmd()
370 cmd = list_entry(pinstance->free_cmd_pool.next, in pmcraid_get_free_cmd()
372 list_del(&cmd->free_list); in pmcraid_get_free_cmd()
374 spin_unlock_irqrestore(&pinstance->free_pool_lock, lock_flags); in pmcraid_get_free_cmd()
383 * pmcraid_return_cmd - return a completed command block back into free pool
391 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_return_cmd()
394 spin_lock_irqsave(&pinstance->free_pool_lock, lock_flags); in pmcraid_return_cmd()
395 list_add_tail(&cmd->free_list, &pinstance->free_cmd_pool); in pmcraid_return_cmd()
396 spin_unlock_irqrestore(&pinstance->free_pool_lock, lock_flags); in pmcraid_return_cmd()
400 * pmcraid_read_interrupts - reads IOA interrupts
409 return (pinstance->interrupt_mode) ? in pmcraid_read_interrupts()
410 ioread32(pinstance->int_regs.ioa_host_msix_interrupt_reg) : in pmcraid_read_interrupts()
411 ioread32(pinstance->int_regs.ioa_host_interrupt_reg); in pmcraid_read_interrupts()
415 * pmcraid_disable_interrupts - Masks and clears all specified interrupts
428 u32 gmask = ioread32(pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_disable_interrupts()
431 iowrite32(intrs, pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_disable_interrupts()
432 iowrite32(nmask, pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_disable_interrupts()
433 ioread32(pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_disable_interrupts()
435 if (!pinstance->interrupt_mode) { in pmcraid_disable_interrupts()
437 pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_disable_interrupts()
438 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_disable_interrupts()
443 * pmcraid_enable_interrupts - Enables specified interrupts
456 u32 gmask = ioread32(pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_enable_interrupts()
459 iowrite32(nmask, pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_enable_interrupts()
461 if (!pinstance->interrupt_mode) { in pmcraid_enable_interrupts()
463 pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_enable_interrupts()
464 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_enable_interrupts()
468 ioread32(pinstance->int_regs.global_interrupt_mask_reg), in pmcraid_enable_interrupts()
469 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg)); in pmcraid_enable_interrupts()
473 * pmcraid_clr_trans_op - clear trans to op interrupt
486 if (!pinstance->interrupt_mode) { in pmcraid_clr_trans_op()
488 pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_clr_trans_op()
489 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_clr_trans_op()
491 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_clr_trans_op()
492 ioread32(pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_clr_trans_op()
495 if (pinstance->reset_cmd != NULL) { in pmcraid_clr_trans_op()
496 del_timer(&pinstance->reset_cmd->timer); in pmcraid_clr_trans_op()
498 pinstance->host->host_lock, lock_flags); in pmcraid_clr_trans_op()
499 pinstance->reset_cmd->cmd_done(pinstance->reset_cmd); in pmcraid_clr_trans_op()
501 pinstance->host->host_lock, lock_flags); in pmcraid_clr_trans_op()
506 * pmcraid_reset_type - Determine the required reset type
520 mask = ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_reset_type()
521 intrs = ioread32(pinstance->int_regs.ioa_host_interrupt_reg); in pmcraid_reset_type()
522 alerts = ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_reset_type()
528 pinstance->ioa_hard_reset = 1; in pmcraid_reset_type()
533 pinstance->ioa_unit_check = 1; in pmcraid_reset_type()
537 * 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()
630 * pmcraid_reset_alert - alerts IOA for a possible reset
634 * returns 0 if pci config-space is accessible and RESET_DOORBELL is
635 * 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()
843 scsi_cmd->scsi_done(scsi_cmd); 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()
965 * pmcraid_get_fwversion_done - completion function for get_fwversion
976 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_get_fwversion_done()
977 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_get_fwversion_done()
986 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_get_fwversion_done()
987 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_get_fwversion_done()
989 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_get_fwversion_done()
996 * pmcraid_get_fwversion - reads firmware version information
1005 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_get_fwversion()
1007 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_get_fwversion()
1011 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_get_fwversion()
1012 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_get_fwversion()
1013 ioarcb->cdb[0] = INQUIRY; in pmcraid_get_fwversion()
1014 ioarcb->cdb[1] = 1; in pmcraid_get_fwversion()
1015 ioarcb->cdb[2] = 0xD0; in pmcraid_get_fwversion()
1016 ioarcb->cdb[3] = (data_size >> 8) & 0xFF; in pmcraid_get_fwversion()
1017 ioarcb->cdb[4] = data_size & 0xFF; in pmcraid_get_fwversion()
1021 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_get_fwversion()
1024 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_get_fwversion()
1025 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL)); in pmcraid_get_fwversion()
1027 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_get_fwversion()
1028 ioarcb->data_transfer_length = cpu_to_le32(data_size); in pmcraid_get_fwversion()
1029 ioadl = &(ioarcb->add_data.u.ioadl[0]); in pmcraid_get_fwversion()
1030 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_get_fwversion()
1031 ioadl->address = cpu_to_le64(pinstance->inq_data_baddr); in pmcraid_get_fwversion()
1032 ioadl->data_len = cpu_to_le32(data_size); in pmcraid_get_fwversion()
1039 * pmcraid_identify_hrrq - registers host rrq buffers with IOA
1047 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_identify_hrrq()
1048 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_identify_hrrq()
1049 int index = cmd->hrrq_index; in pmcraid_identify_hrrq()
1050 __be64 hrrq_addr = cpu_to_be64(pinstance->hrrq_start_bus_addr[index]); in pmcraid_identify_hrrq()
1055 cmd->hrrq_index = index + 1; in pmcraid_identify_hrrq()
1057 if (cmd->hrrq_index < pinstance->num_hrrq) { in pmcraid_identify_hrrq()
1060 cmd->hrrq_index = 0; in pmcraid_identify_hrrq()
1065 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_identify_hrrq()
1066 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_identify_hrrq()
1069 ioarcb->hrrq_id = index; in pmcraid_identify_hrrq()
1070 ioarcb->cdb[0] = PMCRAID_IDENTIFY_HRRQ; in pmcraid_identify_hrrq()
1071 ioarcb->cdb[1] = index; in pmcraid_identify_hrrq()
1073 /* IOA expects 64-bit pci address to be written in B.E format in pmcraid_identify_hrrq()
1077 hrrq_addr, ioarcb->ioarcb_bus_addr, index); in pmcraid_identify_hrrq()
1079 memcpy(&(ioarcb->cdb[2]), &hrrq_addr, sizeof(hrrq_addr)); in pmcraid_identify_hrrq()
1080 memcpy(&(ioarcb->cdb[10]), &hrrq_size, sizeof(hrrq_size)); in pmcraid_identify_hrrq()
1083 * Note that this gets called even during reset from SCSI mid-layer in pmcraid_identify_hrrq()
1095 * pmcraid_send_hcam_cmd - send an initialized command block(HCAM) to IOA
1104 if (cmd->ioa_cb->ioarcb.cdb[1] == PMCRAID_HCAM_CODE_CONFIG_CHANGE) in pmcraid_send_hcam_cmd()
1105 atomic_set(&(cmd->drv_inst->ccn.ignore), 0); in pmcraid_send_hcam_cmd()
1107 atomic_set(&(cmd->drv_inst->ldn.ignore), 0); in pmcraid_send_hcam_cmd()
1109 pmcraid_send_cmd(cmd, cmd->cmd_done, 0, NULL); in pmcraid_send_hcam_cmd()
1113 * pmcraid_init_hcam - send an initialized command block(HCAM) to IOA
1145 dma = pinstance->ccn.baddr + PMCRAID_AEN_HDR_SIZE; in pmcraid_init_hcam()
1146 hcam = &pinstance->ccn; in pmcraid_init_hcam()
1150 dma = pinstance->ldn.baddr + PMCRAID_AEN_HDR_SIZE; in pmcraid_init_hcam()
1151 hcam = &pinstance->ldn; in pmcraid_init_hcam()
1155 hcam->cmd = cmd; in pmcraid_init_hcam()
1157 ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_init_hcam()
1158 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_init_hcam()
1161 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_init_hcam()
1162 ioadl = ioarcb->add_data.u.ioadl; in pmcraid_init_hcam()
1165 ioarcb->request_type = REQ_TYPE_HCAM; in pmcraid_init_hcam()
1166 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_init_hcam()
1167 ioarcb->cdb[0] = PMCRAID_HOST_CONTROLLED_ASYNC; in pmcraid_init_hcam()
1168 ioarcb->cdb[1] = type; in pmcraid_init_hcam()
1169 ioarcb->cdb[7] = (rcb_size >> 8) & 0xFF; in pmcraid_init_hcam()
1170 ioarcb->cdb[8] = (rcb_size) & 0xFF; in pmcraid_init_hcam()
1172 ioarcb->data_transfer_length = cpu_to_le32(rcb_size); in pmcraid_init_hcam()
1178 cmd->cmd_done = cmd_done; in pmcraid_init_hcam()
1183 * pmcraid_send_hcam - Send an HCAM to IOA
1200 * pmcraid_prepare_cancel_cmd - prepares a command block to abort another
1210 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_prepare_cancel_cmd()
1214 * cdb[2]..cdb[9] is Big-Endian format. Note that length bits in in pmcraid_prepare_cancel_cmd()
1217 ioarcb_addr = cpu_to_be64(le64_to_cpu(cmd_to_cancel->ioa_cb->ioarcb.ioarcb_bus_addr)); in pmcraid_prepare_cancel_cmd()
1222 ioarcb->resource_handle = cmd_to_cancel->ioa_cb->ioarcb.resource_handle; in pmcraid_prepare_cancel_cmd()
1223 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_prepare_cancel_cmd()
1224 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_prepare_cancel_cmd()
1225 ioarcb->cdb[0] = PMCRAID_ABORT_CMD; in pmcraid_prepare_cancel_cmd()
1227 memcpy(&(ioarcb->cdb[2]), &ioarcb_addr, sizeof(ioarcb_addr)); in pmcraid_prepare_cancel_cmd()
1231 * pmcraid_cancel_hcam - sends ABORT task to abort a given HCAM
1246 pinstance = cmd->drv_inst; in pmcraid_cancel_hcam()
1248 &pinstance->ldn : &pinstance->ccn; in pmcraid_cancel_hcam()
1251 * currently not pending with IOA, we would have hcam->cmd as non-null in pmcraid_cancel_hcam()
1253 if (hcam->cmd == NULL) in pmcraid_cancel_hcam()
1256 pmcraid_prepare_cancel_cmd(cmd, hcam->cmd); in pmcraid_cancel_hcam()
1258 /* writing to IOARRIN must be protected by host_lock, as mid-layer in pmcraid_cancel_hcam()
1267 * pmcraid_cancel_ccn - cancel CCN HCAM already registered with IOA
1274 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_cancel_ccn()
1275 le32_to_cpu(cmd->ioa_cb->ioasa.ioasc)); in pmcraid_cancel_ccn()
1285 * pmcraid_cancel_ldn - cancel LDN HCAM already registered with IOA
1297 * pmcraid_expose_resource - check if the resource can be exposed to OS
1310 if (cfgte->resource_type == RES_TYPE_VSET) { in pmcraid_expose_resource()
1312 retval = ((cfgte->unique_flags1 & 0x80) == 0); in pmcraid_expose_resource()
1314 retval = ((cfgte->unique_flags0 & 0x80) == 0 && in pmcraid_expose_resource()
1315 (cfgte->unique_flags1 & 0x80) == 0); in pmcraid_expose_resource()
1317 } else if (cfgte->resource_type == RES_TYPE_GSCSI) in pmcraid_expose_resource()
1318 retval = (RES_BUS(cfgte->resource_address) != in pmcraid_expose_resource()
1329 #define PMCRAID_AEN_ATTR_MAX (__PMCRAID_AEN_ATTR_MAX - 1)
1337 #define PMCRAID_AEN_CMD_MAX (__PMCRAID_AEN_CMD_MAX - 1)
1340 { .name = "events", /* not really used - see ID discussion below */ },
1353 * pmcraid_netlink_init - registers pmcraid_event_family
1357 * with netlink generic, non-zero otherwise
1375 * pmcraid_netlink_release - unregisters pmcraid_event_family
1386 * pmcraid_notify_aen - sends event msg to user space application
1404 aen_msg->hostno = (pinstance->host->unique_id << 16 | in pmcraid_notify_aen()
1405 MINOR(pinstance->cdev.dev)); in pmcraid_notify_aen()
1406 aen_msg->length = data_size; in pmcraid_notify_aen()
1414 ((struct genl_family *)&pmcraid_event_family)->hdrsize) in pmcraid_notify_aen()
1422 return -ENOMEM; in pmcraid_notify_aen()
1432 return -ENOMEM; in pmcraid_notify_aen()
1440 return -EINVAL; in pmcraid_notify_aen()
1449 /* If there are no listeners, genlmsg_multicast may return non-zero in pmcraid_notify_aen()
1458 * pmcraid_notify_ccn - notifies about CCN event msg to user space
1467 pinstance->ccn.msg, in pmcraid_notify_ccn()
1468 le32_to_cpu(pinstance->ccn.hcam->data_len) + in pmcraid_notify_ccn()
1473 * pmcraid_notify_ldn - notifies about CCN event msg to user space
1482 pinstance->ldn.msg, in pmcraid_notify_ldn()
1483 le32_to_cpu(pinstance->ldn.hcam->data_len) + in pmcraid_notify_ldn()
1488 * pmcraid_notify_ioastate - sends IOA state event msg to user space
1497 pinstance->scn.ioa_state = evt; in pmcraid_notify_ioastate()
1499 &pinstance->scn.msg, in pmcraid_notify_ioastate()
1504 * pmcraid_handle_config_change - Handle a config change from the adapter
1525 ccn_hcam = (struct pmcraid_hcam_ccn *)pinstance->ccn.hcam; in pmcraid_handle_config_change()
1526 cfg_entry = &ccn_hcam->cfg_entry; in pmcraid_handle_config_change()
1527 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_handle_config_change()
1531 le32_to_cpu(pinstance->ccn.hcam->ilid), in pmcraid_handle_config_change()
1532 pinstance->ccn.hcam->op_code, in pmcraid_handle_config_change()
1533 (le32_to_cpu(pinstance->ccn.hcam->timestamp1) | in pmcraid_handle_config_change()
1534 ((le32_to_cpu(pinstance->ccn.hcam->timestamp2) & 0xffffffffLL) << 32)), in pmcraid_handle_config_change()
1535 pinstance->ccn.hcam->notification_type, in pmcraid_handle_config_change()
1536 pinstance->ccn.hcam->notification_lost, in pmcraid_handle_config_change()
1537 pinstance->ccn.hcam->flags, in pmcraid_handle_config_change()
1538 pinstance->host->unique_id, in pmcraid_handle_config_change()
1541 RES_BUS(cfg_entry->resource_address)), in pmcraid_handle_config_change()
1544 cfg_entry->unique_flags1 : in pmcraid_handle_config_change()
1545 le16_to_cpu(cfg_entry->array_id) & 0xFF) : in pmcraid_handle_config_change()
1546 RES_TARGET(cfg_entry->resource_address), in pmcraid_handle_config_change()
1547 RES_LUN(cfg_entry->resource_address)); in pmcraid_handle_config_change()
1551 if (pinstance->ccn.hcam->notification_lost) { in pmcraid_handle_config_change()
1555 pinstance->reinit_cfg_table = 1; in pmcraid_handle_config_change()
1563 /* If this resource is not going to be added to mid-layer, just notify in pmcraid_handle_config_change()
1567 if (pinstance->ccn.hcam->notification_type == in pmcraid_handle_config_change()
1569 cfg_entry->resource_type == RES_TYPE_VSET) { in pmcraid_handle_config_change()
1570 hidden_entry = (cfg_entry->unique_flags1 & 0x80) != 0; in pmcraid_handle_config_change()
1575 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_handle_config_change()
1576 list_for_each_entry(res, &pinstance->used_res_q, queue) { in pmcraid_handle_config_change()
1577 rc = memcmp(&res->cfg_entry.resource_address, in pmcraid_handle_config_change()
1578 &cfg_entry->resource_address, in pmcraid_handle_config_change()
1579 sizeof(cfg_entry->resource_address)); in pmcraid_handle_config_change()
1589 spin_unlock_irqrestore(&pinstance->resource_lock, in pmcraid_handle_config_change()
1596 * ignore this notifications and re-register the same HCAM in pmcraid_handle_config_change()
1598 if (list_empty(&pinstance->free_res_q)) { in pmcraid_handle_config_change()
1599 spin_unlock_irqrestore(&pinstance->resource_lock, in pmcraid_handle_config_change()
1602 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_handle_config_change()
1606 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_handle_config_change()
1611 res = list_entry(pinstance->free_res_q.next, in pmcraid_handle_config_change()
1614 list_del(&res->queue); in pmcraid_handle_config_change()
1615 res->scsi_dev = NULL; in pmcraid_handle_config_change()
1616 res->reset_progress = 0; in pmcraid_handle_config_change()
1617 list_add_tail(&res->queue, &pinstance->used_res_q); in pmcraid_handle_config_change()
1620 memcpy(&res->cfg_entry, cfg_entry, pinstance->config_table_entry_size); in pmcraid_handle_config_change()
1622 if (pinstance->ccn.hcam->notification_type == in pmcraid_handle_config_change()
1624 if (res->scsi_dev) { in pmcraid_handle_config_change()
1626 res->cfg_entry.unique_flags1 &= 0x7F; in pmcraid_handle_config_change()
1628 res->cfg_entry.array_id &= cpu_to_le16(0xFF); in pmcraid_handle_config_change()
1629 res->change_detected = RES_CHANGE_DEL; in pmcraid_handle_config_change()
1630 res->cfg_entry.resource_handle = in pmcraid_handle_config_change()
1632 schedule_work(&pinstance->worker_q); in pmcraid_handle_config_change()
1634 /* This may be one of the non-exposed resources */ in pmcraid_handle_config_change()
1635 list_move_tail(&res->queue, &pinstance->free_res_q); in pmcraid_handle_config_change()
1637 } else if (!res->scsi_dev) { in pmcraid_handle_config_change()
1638 res->change_detected = RES_CHANGE_ADD; in pmcraid_handle_config_change()
1639 schedule_work(&pinstance->worker_q); in pmcraid_handle_config_change()
1641 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_handle_config_change()
1655 * pmcraid_get_error_info - return error string for an ioasc
1671 * pmcraid_ioasc_logger - log IOASC information based user-settings
1680 cmd->drv_inst->current_log_level < error_info->log_level) in pmcraid_ioasc_logger()
1685 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_ioasc_logger()
1686 le32_to_cpu(cmd->ioa_cb->ioarcb.resource_handle), in pmcraid_ioasc_logger()
1687 ioasc, error_info->error_string); in pmcraid_ioasc_logger()
1691 * pmcraid_handle_error_log - Handle a config change (error log) from the IOA
1703 hcam_ldn = (struct pmcraid_hcam_ldn *)pinstance->ldn.hcam; in pmcraid_handle_error_log()
1707 pinstance->ldn.hcam->ilid, in pmcraid_handle_error_log()
1708 pinstance->ldn.hcam->op_code, in pmcraid_handle_error_log()
1709 pinstance->ldn.hcam->notification_type, in pmcraid_handle_error_log()
1710 pinstance->ldn.hcam->notification_lost, in pmcraid_handle_error_log()
1711 pinstance->ldn.hcam->flags, in pmcraid_handle_error_log()
1712 pinstance->ldn.hcam->overlay_id); in pmcraid_handle_error_log()
1715 if (pinstance->ldn.hcam->notification_type != in pmcraid_handle_error_log()
1719 if (pinstance->ldn.hcam->notification_lost == in pmcraid_handle_error_log()
1721 dev_info(&pinstance->pdev->dev, "Error notifications lost\n"); in pmcraid_handle_error_log()
1723 ioasc = le32_to_cpu(hcam_ldn->error_log.fd_ioasc); in pmcraid_handle_error_log()
1727 dev_info(&pinstance->pdev->dev, in pmcraid_handle_error_log()
1730 pinstance->host, in pmcraid_handle_error_log()
1731 RES_BUS(hcam_ldn->error_log.fd_ra)); in pmcraid_handle_error_log()
1738 * pmcraid_process_ccn - Op done function for a CCN.
1749 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_process_ccn()
1750 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_process_ccn()
1753 pinstance->ccn.cmd = NULL; in pmcraid_process_ccn()
1758 * re-register the hcam in pmcraid_process_ccn()
1761 atomic_read(&pinstance->ccn.ignore) == 1) { in pmcraid_process_ccn()
1764 dev_info(&pinstance->pdev->dev, in pmcraid_process_ccn()
1766 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_process_ccn()
1768 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_process_ccn()
1775 * pmcraid_process_ldn - op done function for an LDN
1786 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_process_ldn()
1788 (struct pmcraid_hcam_ldn *)pinstance->ldn.hcam; in pmcraid_process_ldn()
1789 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_process_ldn()
1790 u32 fd_ioasc = le32_to_cpu(ldn_hcam->error_log.fd_ioasc); in pmcraid_process_ldn()
1794 pinstance->ldn.cmd = NULL; in pmcraid_process_ldn()
1798 * with IOA, no need to re-register the hcam as reset engine will do it in pmcraid_process_ldn()
1802 atomic_read(&pinstance->ccn.ignore) == 1) { in pmcraid_process_ldn()
1807 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_process_ldn()
1810 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_process_ldn()
1815 pinstance->timestamp_error = 1; in pmcraid_process_ldn()
1819 dev_info(&pinstance->pdev->dev, in pmcraid_process_ldn()
1832 * pmcraid_register_hcams - register HCAMs for CCN and LDN
1846 * pmcraid_unregister_hcams - cancel HCAMs registered already
1851 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_unregister_hcams()
1855 * prevent this, set 'ignore', so that bring-down sequence doesn't in pmcraid_unregister_hcams()
1856 * re-send any more hcams in pmcraid_unregister_hcams()
1858 atomic_set(&pinstance->ccn.ignore, 1); in pmcraid_unregister_hcams()
1859 atomic_set(&pinstance->ldn.ignore, 1); in pmcraid_unregister_hcams()
1865 if ((pinstance->force_ioa_reset && !pinstance->ioa_bringdown) || in pmcraid_unregister_hcams()
1866 pinstance->ioa_unit_check) { in pmcraid_unregister_hcams()
1867 pinstance->force_ioa_reset = 0; in pmcraid_unregister_hcams()
1868 pinstance->ioa_unit_check = 0; in pmcraid_unregister_hcams()
1869 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_unregister_hcams()
1882 * pmcraid_reset_enable_ioa - re-enable IOA after a hard reset
1899 if (!pinstance->interrupt_mode) { in pmcraid_reset_enable_ioa()
1901 pinstance->int_regs. in pmcraid_reset_enable_ioa()
1904 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_reset_enable_ioa()
1913 * pmcraid_soft_reset - performs a soft reset and makes IOA become ready
1921 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_soft_reset()
1927 * would re-initiate a reset in pmcraid_soft_reset()
1929 cmd->cmd_done = pmcraid_ioa_reset; in pmcraid_soft_reset()
1930 cmd->timer.expires = jiffies + in pmcraid_soft_reset()
1932 cmd->timer.function = pmcraid_timeout_handler; in pmcraid_soft_reset()
1934 if (!timer_pending(&cmd->timer)) in pmcraid_soft_reset()
1935 add_timer(&cmd->timer); in pmcraid_soft_reset()
1946 if (pinstance->interrupt_mode) { in pmcraid_soft_reset()
1948 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_soft_reset()
1949 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_soft_reset()
1952 iowrite32(doorbell, pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_soft_reset()
1953 ioread32(pinstance->int_regs.host_ioa_interrupt_reg), in pmcraid_soft_reset()
1954 int_reg = ioread32(pinstance->int_regs.ioa_host_interrupt_reg); in pmcraid_soft_reset()
1957 ioread32(pinstance->int_regs.host_ioa_interrupt_reg), in pmcraid_soft_reset()
1962 * pmcraid_get_dump - retrieves IOA dump in case of Unit Check interrupt
1975 * pmcraid_fail_outstanding_cmds - Fails all outstanding ops.
1994 spin_lock_irqsave(&pinstance->pending_pool_lock, lock_flags); in pmcraid_fail_outstanding_cmds()
1995 list_for_each_entry_safe(cmd, temp, &pinstance->pending_cmd_pool, in pmcraid_fail_outstanding_cmds()
1997 list_del(&cmd->free_list); in pmcraid_fail_outstanding_cmds()
1998 spin_unlock_irqrestore(&pinstance->pending_pool_lock, in pmcraid_fail_outstanding_cmds()
2000 cmd->ioa_cb->ioasa.ioasc = in pmcraid_fail_outstanding_cmds()
2002 cmd->ioa_cb->ioasa.ilid = in pmcraid_fail_outstanding_cmds()
2006 del_timer(&cmd->timer); in pmcraid_fail_outstanding_cmds()
2013 if (cmd->scsi_cmd) { in pmcraid_fail_outstanding_cmds()
2015 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_fail_outstanding_cmds()
2016 __le32 resp = cmd->ioa_cb->ioarcb.response_handle; in pmcraid_fail_outstanding_cmds()
2018 scsi_cmd->result |= DID_ERROR << 16; in pmcraid_fail_outstanding_cmds()
2025 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_fail_outstanding_cmds()
2026 scsi_cmd->result); in pmcraid_fail_outstanding_cmds()
2027 scsi_cmd->scsi_done(scsi_cmd); in pmcraid_fail_outstanding_cmds()
2028 } else if (cmd->cmd_done == pmcraid_internal_done || in pmcraid_fail_outstanding_cmds()
2029 cmd->cmd_done == pmcraid_erp_done) { in pmcraid_fail_outstanding_cmds()
2030 cmd->cmd_done(cmd); in pmcraid_fail_outstanding_cmds()
2031 } else if (cmd->cmd_done != pmcraid_ioa_reset && in pmcraid_fail_outstanding_cmds()
2032 cmd->cmd_done != pmcraid_ioa_shutdown_done) { in pmcraid_fail_outstanding_cmds()
2036 atomic_dec(&pinstance->outstanding_cmds); in pmcraid_fail_outstanding_cmds()
2037 spin_lock_irqsave(&pinstance->pending_pool_lock, lock_flags); in pmcraid_fail_outstanding_cmds()
2040 spin_unlock_irqrestore(&pinstance->pending_pool_lock, lock_flags); in pmcraid_fail_outstanding_cmds()
2044 * pmcraid_ioa_reset - Implementation of IOA reset logic
2060 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_ioa_reset()
2063 pinstance->ioa_reset_in_progress = 1; in pmcraid_ioa_reset()
2065 if (pinstance->reset_cmd != cmd) { in pmcraid_ioa_reset()
2067 pinstance->reset_cmd = cmd; in pmcraid_ioa_reset()
2071 pinstance->ioa_state, cmd); in pmcraid_ioa_reset()
2073 switch (pinstance->ioa_state) { in pmcraid_ioa_reset()
2087 * goes through hard-reset in pmcraid_ioa_reset()
2090 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_ioa_reset()
2095 /* We may be called during probe or resume. Some pre-processing in pmcraid_ioa_reset()
2098 scsi_block_requests(pinstance->host); in pmcraid_ioa_reset()
2102 * hard-reset. in pmcraid_ioa_reset()
2104 if (pinstance->ioa_hard_reset == 0) { in pmcraid_ioa_reset()
2105 if (ioread32(pinstance->ioa_status) & in pmcraid_ioa_reset()
2107 pmcraid_info("sticky bit set, bring-up\n"); in pmcraid_ioa_reset()
2108 pinstance->ioa_state = IOA_STATE_IN_BRINGUP; in pmcraid_ioa_reset()
2112 pinstance->ioa_state = IOA_STATE_IN_SOFT_RESET; in pmcraid_ioa_reset()
2119 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_ioa_reset()
2130 pinstance->ioa_state = IOA_STATE_IN_HARD_RESET; in pmcraid_ioa_reset()
2135 pinstance->ioa_reset_attempts++; in pmcraid_ioa_reset()
2138 if (pinstance->ioa_reset_attempts > PMCRAID_RESET_ATTEMPTS) { in pmcraid_ioa_reset()
2139 pinstance->ioa_reset_attempts = 0; in pmcraid_ioa_reset()
2141 pinstance->ioa_state = IOA_STATE_DEAD; in pmcraid_ioa_reset()
2143 if (pinstance->ioa_bringdown) in pmcraid_ioa_reset()
2156 pci_restore_state(pinstance->pdev); in pmcraid_ioa_reset()
2162 if (pinstance->ioa_unit_check) { in pmcraid_ioa_reset()
2164 pinstance->ioa_unit_check = 0; in pmcraid_ioa_reset()
2166 pinstance->ioa_reset_attempts--; in pmcraid_ioa_reset()
2167 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_ioa_reset()
2172 /* if the reset reason is to bring-down the ioa, we might be in pmcraid_ioa_reset()
2176 if (pinstance->ioa_bringdown) { in pmcraid_ioa_reset()
2178 pinstance->ioa_shutdown_type = SHUTDOWN_NONE; in pmcraid_ioa_reset()
2179 pinstance->ioa_bringdown = 0; in pmcraid_ioa_reset()
2180 pinstance->ioa_state = IOA_STATE_UNKNOWN; in pmcraid_ioa_reset()
2185 /* bring-up IOA, so proceed with soft reset in pmcraid_ioa_reset()
2190 pinstance->ioa_state = IOA_STATE_IN_BRINGUP; in pmcraid_ioa_reset()
2195 pinstance->ioa_state = IOA_STATE_IN_SOFT_RESET; in pmcraid_ioa_reset()
2205 pmcraid_info("In softreset proceeding with bring-up\n"); in pmcraid_ioa_reset()
2206 pinstance->ioa_state = IOA_STATE_IN_BRINGUP; in pmcraid_ioa_reset()
2219 pinstance->ioa_state = IOA_STATE_OPERATIONAL; in pmcraid_ioa_reset()
2230 if (pinstance->ioa_shutdown_type == SHUTDOWN_NONE && in pmcraid_ioa_reset()
2231 pinstance->force_ioa_reset == 0) { in pmcraid_ioa_reset()
2236 if (pinstance->ioa_shutdown_type != SHUTDOWN_NONE) in pmcraid_ioa_reset()
2237 pinstance->ioa_state = IOA_STATE_IN_BRINGDOWN; in pmcraid_ioa_reset()
2246 * any waiting threads and let the SCSI mid-layer send commands. Note in pmcraid_ioa_reset()
2250 pinstance->ioa_reset_in_progress = 0; in pmcraid_ioa_reset()
2251 pinstance->ioa_reset_attempts = 0; in pmcraid_ioa_reset()
2252 pinstance->reset_cmd = NULL; in pmcraid_ioa_reset()
2253 pinstance->ioa_shutdown_type = SHUTDOWN_NONE; in pmcraid_ioa_reset()
2254 pinstance->ioa_bringdown = 0; in pmcraid_ioa_reset()
2258 * hcam registration and resource exposure to mid-layer. in pmcraid_ioa_reset()
2260 if (pinstance->ioa_state == IOA_STATE_OPERATIONAL) in pmcraid_ioa_reset()
2263 wake_up_all(&pinstance->reset_wait_q); in pmcraid_ioa_reset()
2270 * pmcraid_initiate_reset - initiates reset sequence. This is called from
2287 if (!pinstance->ioa_reset_in_progress) { in pmcraid_initiate_reset()
2288 scsi_block_requests(pinstance->host); in pmcraid_initiate_reset()
2296 pinstance->ioa_shutdown_type = SHUTDOWN_NONE; in pmcraid_initiate_reset()
2297 pinstance->reset_cmd = cmd; in pmcraid_initiate_reset()
2298 pinstance->force_ioa_reset = 1; in pmcraid_initiate_reset()
2306 * pmcraid_reset_reload - utility routine for doing IOA reset either to bringup
2329 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2331 if (pinstance->ioa_reset_in_progress) { in pmcraid_reset_reload()
2334 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2336 wait_event(pinstance->reset_wait_q, in pmcraid_reset_reload()
2337 !pinstance->ioa_reset_in_progress); in pmcraid_reset_reload()
2339 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2341 if (pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_reset_reload()
2346 if (pinstance->ioa_state == target_state) { in pmcraid_reset_reload()
2353 scsi_block_requests(pinstance->host); in pmcraid_reset_reload()
2361 pinstance->ioa_bringdown = 1; in pmcraid_reset_reload()
2363 pinstance->ioa_shutdown_type = shutdown_type; in pmcraid_reset_reload()
2364 pinstance->reset_cmd = reset_cmd; in pmcraid_reset_reload()
2365 pinstance->force_ioa_reset = reset; in pmcraid_reset_reload()
2368 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2370 wait_event(pinstance->reset_wait_q, in pmcraid_reset_reload()
2371 !pinstance->ioa_reset_in_progress); in pmcraid_reset_reload()
2374 scsi_unblock_requests(pinstance->host); in pmcraid_reset_reload()
2375 return pinstance->ioa_state != target_state; in pmcraid_reset_reload()
2378 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2383 * pmcraid_reset_bringdown - wrapper over pmcraid_reset_reload to bringdown IOA
2398 * pmcraid_reset_bringup - wrapper over pmcraid_reset_reload to bring up IOA
2415 * pmcraid_request_sense - Send request sense to a device
2419 * condition. This method re-uses the same command block that failed earlier.
2423 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_request_sense()
2424 struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl; in pmcraid_request_sense()
2425 struct device *dev = &cmd->drv_inst->pdev->dev; in pmcraid_request_sense()
2427 cmd->sense_buffer = cmd->scsi_cmd->sense_buffer; in pmcraid_request_sense()
2428 cmd->sense_buffer_dma = dma_map_single(dev, cmd->sense_buffer, in pmcraid_request_sense()
2430 if (dma_mapping_error(dev, cmd->sense_buffer_dma)) { in pmcraid_request_sense()
2437 /* re-use the command block */ in pmcraid_request_sense()
2438 memset(&cmd->ioa_cb->ioasa, 0, sizeof(struct pmcraid_ioasa)); in pmcraid_request_sense()
2439 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_request_sense()
2440 ioarcb->request_flags0 = (SYNC_COMPLETE | in pmcraid_request_sense()
2443 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_request_sense()
2444 ioarcb->cdb[0] = REQUEST_SENSE; in pmcraid_request_sense()
2445 ioarcb->cdb[4] = SCSI_SENSE_BUFFERSIZE; in pmcraid_request_sense()
2447 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_request_sense()
2450 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_request_sense()
2452 ioarcb->data_transfer_length = cpu_to_le32(SCSI_SENSE_BUFFERSIZE); in pmcraid_request_sense()
2454 ioadl->address = cpu_to_le64(cmd->sense_buffer_dma); in pmcraid_request_sense()
2455 ioadl->data_len = cpu_to_le32(SCSI_SENSE_BUFFERSIZE); in pmcraid_request_sense()
2456 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_request_sense()
2459 * which runs in tasklets context. It is possible that mid-layer might in pmcraid_request_sense()
2469 * pmcraid_cancel_all - cancel all outstanding IOARCBs as part of error recovery
2477 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_cancel_all()
2478 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_cancel_all()
2479 struct pmcraid_resource_entry *res = scsi_cmd->device->hostdata; in pmcraid_cancel_all()
2481 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_cancel_all()
2482 ioarcb->request_flags0 = SYNC_OVERRIDE; in pmcraid_cancel_all()
2483 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_cancel_all()
2484 ioarcb->cdb[0] = PMCRAID_CANCEL_ALL_REQUESTS; in pmcraid_cancel_all()
2486 if (RES_IS_GSCSI(res->cfg_entry)) in pmcraid_cancel_all()
2487 ioarcb->cdb[1] = PMCRAID_SYNC_COMPLETE_AFTER_CANCEL; in pmcraid_cancel_all()
2489 ioarcb->ioadl_bus_addr = 0; in pmcraid_cancel_all()
2490 ioarcb->ioadl_length = 0; in pmcraid_cancel_all()
2491 ioarcb->data_transfer_length = 0; in pmcraid_cancel_all()
2492 ioarcb->ioarcb_bus_addr &= cpu_to_le64((~0x1FULL)); in pmcraid_cancel_all()
2494 /* writing to IOARRIN must be protected by host_lock, as mid-layer in pmcraid_cancel_all()
2513 u8 *sense_buf = cmd->scsi_cmd->sense_buffer; in pmcraid_frame_auto_sense()
2514 struct pmcraid_resource_entry *res = cmd->scsi_cmd->device->hostdata; in pmcraid_frame_auto_sense()
2515 struct pmcraid_ioasa *ioasa = &cmd->ioa_cb->ioasa; in pmcraid_frame_auto_sense()
2516 u32 ioasc = le32_to_cpu(ioasa->ioasc); in pmcraid_frame_auto_sense()
2520 cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION; in pmcraid_frame_auto_sense()
2522 if (RES_IS_VSET(res->cfg_entry) && in pmcraid_frame_auto_sense()
2524 ioasa->u.vset.failing_lba_hi != 0) { in pmcraid_frame_auto_sense()
2536 failing_lba = le32_to_cpu(ioasa->u.vset.failing_lba_hi); in pmcraid_frame_auto_sense()
2543 failing_lba = le32_to_cpu(ioasa->u.vset.failing_lba_lo); in pmcraid_frame_auto_sense()
2556 if (RES_IS_VSET(res->cfg_entry)) in pmcraid_frame_auto_sense()
2558 le32_to_cpu(ioasa->u. in pmcraid_frame_auto_sense()
2572 * pmcraid_error_handler - Error response handlers for a SCSI op
2581 * back to free-pool
2585 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_error_handler()
2586 struct pmcraid_resource_entry *res = scsi_cmd->device->hostdata; in pmcraid_error_handler()
2587 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_error_handler()
2588 struct pmcraid_ioasa *ioasa = &cmd->ioa_cb->ioasa; in pmcraid_error_handler()
2589 u32 ioasc = le32_to_cpu(ioasa->ioasc); in pmcraid_error_handler()
2599 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD) in pmcraid_error_handler()
2600 atomic_inc(&res->read_failures); in pmcraid_error_handler()
2601 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD) in pmcraid_error_handler()
2602 atomic_inc(&res->write_failures); in pmcraid_error_handler()
2604 if (!RES_IS_GSCSI(res->cfg_entry) && in pmcraid_error_handler()
2615 scsi_cmd->result |= (DID_ABORT << 16); in pmcraid_error_handler()
2620 scsi_cmd->result |= (DID_NO_CONNECT << 16); in pmcraid_error_handler()
2624 res->sync_reqd = 1; in pmcraid_error_handler()
2625 scsi_cmd->result |= (DID_IMM_RETRY << 16); in pmcraid_error_handler()
2629 scsi_cmd->result |= (DID_PASSTHROUGH << 16); in pmcraid_error_handler()
2634 if (!res->reset_progress) in pmcraid_error_handler()
2635 scsi_report_bus_reset(pinstance->host, in pmcraid_error_handler()
2636 scsi_cmd->device->channel); in pmcraid_error_handler()
2637 scsi_cmd->result |= (DID_ERROR << 16); in pmcraid_error_handler()
2641 scsi_cmd->result |= PMCRAID_IOASC_SENSE_STATUS(ioasc); in pmcraid_error_handler()
2642 res->sync_reqd = 1; in pmcraid_error_handler()
2653 * mid-layer in pmcraid_error_handler()
2655 if (ioasa->auto_sense_length != 0) { in pmcraid_error_handler()
2656 short sense_len = le16_to_cpu(ioasa->auto_sense_length); in pmcraid_error_handler()
2660 memcpy(scsi_cmd->sense_buffer, in pmcraid_error_handler()
2661 ioasa->sense_data, in pmcraid_error_handler()
2666 if (RES_IS_GSCSI(res->cfg_entry)) in pmcraid_error_handler()
2680 scsi_cmd->result |= (DID_ERROR << 16); in pmcraid_error_handler()
2687 * pmcraid_reset_device - device reset handler functions
2713 (struct pmcraid_instance *)scsi_cmd->device->host->hostdata; in pmcraid_reset_device()
2714 res = scsi_cmd->device->hostdata; in pmcraid_reset_device()
2717 sdev_printk(KERN_ERR, scsi_cmd->device, in pmcraid_reset_device()
2723 * This will force the mid-layer to call _eh_bus/host reset, which in pmcraid_reset_device()
2726 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2727 if (pinstance->ioa_reset_in_progress || in pmcraid_reset_device()
2728 pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_reset_device()
2729 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2733 res->reset_progress = 1; in pmcraid_reset_device()
2737 le32_to_cpu(res->cfg_entry.resource_address)); in pmcraid_reset_device()
2743 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2748 ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_reset_device()
2749 ioarcb->resource_handle = res->cfg_entry.resource_handle; in pmcraid_reset_device()
2750 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_reset_device()
2751 ioarcb->cdb[0] = PMCRAID_RESET_DEVICE; in pmcraid_reset_device()
2757 ioarcb->cdb[1] = modifier; in pmcraid_reset_device()
2759 init_completion(&cmd->wait_for_completion); in pmcraid_reset_device()
2760 cmd->completion_req = 1; in pmcraid_reset_device()
2763 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_reset_device()
2764 le32_to_cpu(cmd->ioa_cb->ioarcb.resource_handle), in pmcraid_reset_device()
2765 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2); in pmcraid_reset_device()
2772 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2778 wait_for_completion(&cmd->wait_for_completion); in pmcraid_reset_device()
2784 res->reset_progress = 0; in pmcraid_reset_device()
2785 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_reset_device()
2792 * _pmcraid_io_done - helper for pmcraid_io_done function
2798 * This function is invoked by pmcraid_io_done to complete mid-layer
2809 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in _pmcraid_io_done()
2815 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2, in _pmcraid_io_done()
2816 cmd->ioa_cb->ioarcb.cdb[0], in _pmcraid_io_done()
2817 ioasc, scsi_cmd->result); in _pmcraid_io_done()
2824 scsi_cmd->scsi_done(scsi_cmd); in _pmcraid_io_done()
2831 * pmcraid_io_done - SCSI completion function
2835 * This function is invoked by tasklet/mid-layer error handler to completing
2836 * the SCSI ops sent from mid-layer.
2844 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_io_done()
2845 u32 reslen = le32_to_cpu(cmd->ioa_cb->ioasa.residual_data_length); in pmcraid_io_done()
2852 * pmcraid_abort_cmd - Aborts a single IOARCB already submitted to IOA
2864 pinstance = (struct pmcraid_instance *)cmd->drv_inst; in pmcraid_abort_cmd()
2876 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_abort_cmd()
2877 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2); in pmcraid_abort_cmd()
2879 init_completion(&cancel_cmd->wait_for_completion); in pmcraid_abort_cmd()
2880 cancel_cmd->completion_req = 1; in pmcraid_abort_cmd()
2883 le32_to_cpu(cancel_cmd->ioa_cb->ioarcb.response_handle) >> 2, in pmcraid_abort_cmd()
2884 cancel_cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_abort_cmd()
2885 le32_to_cpu(cancel_cmd->ioa_cb->ioarcb.resource_handle)); in pmcraid_abort_cmd()
2895 * pmcraid_abort_complete - Waits for ABORT TASK completion
2908 wait_for_completion(&cancel_cmd->wait_for_completion); in pmcraid_abort_complete()
2909 res = cancel_cmd->res; in pmcraid_abort_complete()
2910 cancel_cmd->res = NULL; in pmcraid_abort_complete()
2911 ioasc = le32_to_cpu(cancel_cmd->ioa_cb->ioasa.ioasc); in pmcraid_abort_complete()
2921 res->sync_reqd = 1; in pmcraid_abort_complete()
2931 * pmcraid_eh_abort_handler - entry point for aborting a single task on errors
2933 * @scsi_cmd: scsi command struct given by mid-layer. When this is called
2934 * mid-layer ensures that no other commands are queued. This
2952 (struct pmcraid_instance *)scsi_cmd->device->host->hostdata; in pmcraid_eh_abort_handler()
2957 res = scsi_cmd->device->hostdata; in pmcraid_eh_abort_handler()
2963 * This will force the mid-layer to eventually call in pmcraid_eh_abort_handler()
2967 spin_lock_irqsave(pinstance->host->host_lock, host_lock_flags); in pmcraid_eh_abort_handler()
2969 if (pinstance->ioa_reset_in_progress || in pmcraid_eh_abort_handler()
2970 pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_eh_abort_handler()
2971 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_eh_abort_handler()
2981 spin_lock_irqsave(&pinstance->pending_pool_lock, pending_lock_flags); in pmcraid_eh_abort_handler()
2982 list_for_each_entry(cmd, &pinstance->pending_cmd_pool, free_list) { in pmcraid_eh_abort_handler()
2984 if (cmd->scsi_cmd == scsi_cmd) { in pmcraid_eh_abort_handler()
2990 spin_unlock_irqrestore(&pinstance->pending_pool_lock, in pmcraid_eh_abort_handler()
2999 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_eh_abort_handler()
3003 cancel_cmd->res = cmd->scsi_cmd->device->hostdata; in pmcraid_eh_abort_handler()
3011 * pmcraid_eh_xxxx_reset_handler - bus/target/device reset handler callbacks
3016 * Since these are called from mid-layer EH thread, no other IO will be queued
3052 * pmcraid_eh_host_reset_handler - adapter reset handler callback
3066 (struct pmcraid_instance *)(scmd->device->host->hostdata); in pmcraid_eh_host_reset_handler()
3073 while (waits--) { in pmcraid_eh_host_reset_handler()
3074 if (atomic_read(&pinstance->outstanding_cmds) <= in pmcraid_eh_host_reset_handler()
3080 dev_err(&pinstance->pdev->dev, in pmcraid_eh_host_reset_handler()
3086 * pmcraid_init_ioadls - initializes IOADL related fields in IOARCB
3088 * @sgcount: count of scatter-gather elements
3098 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_init_ioadls()
3101 if (ioarcb->add_cmd_param_length) in pmcraid_init_ioadls()
3102 ioadl_count = DIV_ROUND_UP(le16_to_cpu(ioarcb->add_cmd_param_length), 16); in pmcraid_init_ioadls()
3103 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc) * sgcount); in pmcraid_init_ioadls()
3105 if ((sgcount + ioadl_count) > (ARRAY_SIZE(ioarcb->add_data.u.ioadl))) { in pmcraid_init_ioadls()
3107 * structure, re-using 24 out of 27 ioadls part of IOARCB. in pmcraid_init_ioadls()
3111 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL)); in pmcraid_init_ioadls()
3112 ioarcb->ioadl_bus_addr = in pmcraid_init_ioadls()
3113 cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_init_ioadls()
3116 ioadl = &ioarcb->add_data.u.ioadl[3]; in pmcraid_init_ioadls()
3118 ioarcb->ioadl_bus_addr = in pmcraid_init_ioadls()
3119 cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_init_ioadls()
3123 ioadl = &ioarcb->add_data.u.ioadl[ioadl_count]; in pmcraid_init_ioadls()
3124 ioarcb->ioarcb_bus_addr |= in pmcraid_init_ioadls()
3132 * pmcraid_build_ioadl - Build a scatter/gather list and map the buffer
3140 * 0 on success or -1 on failure
3150 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_build_ioadl()
3151 struct pmcraid_ioarcb *ioarcb = &(cmd->ioa_cb->ioarcb); in pmcraid_build_ioadl()
3163 return -1; in pmcraid_build_ioadl()
3168 return -1; in pmcraid_build_ioadl()
3172 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) in pmcraid_build_ioadl()
3173 ioarcb->request_flags0 |= TRANSFER_DIR_WRITE; in pmcraid_build_ioadl()
3175 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_build_ioadl()
3176 ioarcb->data_transfer_length = cpu_to_le32(length); in pmcraid_build_ioadl()
3186 ioadl[i - 1].flags = IOADL_FLAGS_LAST_DESC; in pmcraid_build_ioadl()
3192 * pmcraid_free_sglist - Frees an allocated SG buffer list
3202 sgl_free_order(sglist->scatterlist, sglist->order); in pmcraid_free_sglist()
3207 * pmcraid_alloc_sglist - Allocates memory for a SG list
3222 sg_size = buflen / (PMCRAID_MAX_IOADLS - 1); in pmcraid_alloc_sglist()
3230 sglist->order = order; in pmcraid_alloc_sglist()
3232 GFP_KERNEL | GFP_DMA | __GFP_ZERO, &sglist->num_sg); in pmcraid_alloc_sglist()
3238 * pmcraid_copy_sglist - Copy user buffer to kernel buffer's SG list
3263 bsize_elem = PAGE_SIZE * (1 << sglist->order); in pmcraid_copy_sglist()
3265 sg = sglist->scatterlist; in pmcraid_copy_sglist()
3280 return -EFAULT; in pmcraid_copy_sglist()
3283 sg->length = bsize_elem; in pmcraid_copy_sglist()
3298 sg->length = len % bsize_elem; in pmcraid_copy_sglist()
3303 rc = -EFAULT; in pmcraid_copy_sglist()
3310 * pmcraid_queuecommand - Queue a mid-layer request
3314 * This function queues a request generated by the mid-layer. Midlayer calls
3315 * this routine within host->lock. Some of the functions called by queuecommand
3336 (struct pmcraid_instance *)scsi_cmd->device->host->hostdata; in pmcraid_queuecommand_lck()
3337 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_queuecommand_lck()
3338 scsi_cmd->scsi_done = done; in pmcraid_queuecommand_lck()
3339 res = scsi_cmd->device->hostdata; in pmcraid_queuecommand_lck()
3340 scsi_cmd->result = (DID_OK << 16); in pmcraid_queuecommand_lck()
3345 if (pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_queuecommand_lck()
3347 scsi_cmd->result = (DID_NO_CONNECT << 16); in pmcraid_queuecommand_lck()
3348 scsi_cmd->scsi_done(scsi_cmd); in pmcraid_queuecommand_lck()
3353 if (pinstance->ioa_reset_in_progress) in pmcraid_queuecommand_lck()
3359 if (scsi_cmd->cmnd[0] == SYNCHRONIZE_CACHE) { in pmcraid_queuecommand_lck()
3361 scsi_cmd->scsi_done(scsi_cmd); in pmcraid_queuecommand_lck()
3373 cmd->scsi_cmd = scsi_cmd; in pmcraid_queuecommand_lck()
3374 ioarcb = &(cmd->ioa_cb->ioarcb); in pmcraid_queuecommand_lck()
3375 memcpy(ioarcb->cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len); in pmcraid_queuecommand_lck()
3376 ioarcb->resource_handle = res->cfg_entry.resource_handle; in pmcraid_queuecommand_lck()
3377 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_queuecommand_lck()
3381 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses in pmcraid_queuecommand_lck()
3384 ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) % in pmcraid_queuecommand_lck()
3385 pinstance->num_hrrq; in pmcraid_queuecommand_lck()
3386 cmd->cmd_done = pmcraid_io_done; in pmcraid_queuecommand_lck()
3388 if (RES_IS_GSCSI(res->cfg_entry) || RES_IS_VSET(res->cfg_entry)) { in pmcraid_queuecommand_lck()
3389 if (scsi_cmd->underflow == 0) in pmcraid_queuecommand_lck()
3390 ioarcb->request_flags0 |= INHIBIT_UL_CHECK; in pmcraid_queuecommand_lck()
3392 if (res->sync_reqd) { in pmcraid_queuecommand_lck()
3393 ioarcb->request_flags0 |= SYNC_COMPLETE; in pmcraid_queuecommand_lck()
3394 res->sync_reqd = 0; in pmcraid_queuecommand_lck()
3397 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_queuecommand_lck()
3399 if (scsi_cmd->flags & SCMD_TAGGED) in pmcraid_queuecommand_lck()
3400 ioarcb->request_flags1 |= TASK_TAG_SIMPLE; in pmcraid_queuecommand_lck()
3402 if (RES_IS_GSCSI(res->cfg_entry)) in pmcraid_queuecommand_lck()
3403 ioarcb->request_flags1 |= DELAY_AFTER_RESET; in pmcraid_queuecommand_lck()
3409 le32_to_cpu(ioarcb->response_handle) >> 2, in pmcraid_queuecommand_lck()
3410 scsi_cmd->cmnd[0], pinstance->host->unique_id, in pmcraid_queuecommand_lck()
3411 RES_IS_VSET(res->cfg_entry) ? PMCRAID_VSET_BUS_ID : in pmcraid_queuecommand_lck()
3413 RES_IS_VSET(res->cfg_entry) ? in pmcraid_queuecommand_lck()
3415 res->cfg_entry.unique_flags1 : in pmcraid_queuecommand_lck()
3416 le16_to_cpu(res->cfg_entry.array_id) & 0xFF) : in pmcraid_queuecommand_lck()
3417 RES_TARGET(res->cfg_entry.resource_address), in pmcraid_queuecommand_lck()
3418 RES_LUN(res->cfg_entry.resource_address)); in pmcraid_queuecommand_lck()
3434 * pmcraid_open -char node "open" entry, allowed only users with admin access in DEF_SCSI_QCMD()
3441 return -EACCES; in DEF_SCSI_QCMD()
3444 pinstance = container_of(inode->i_cdev, struct pmcraid_instance, cdev); in DEF_SCSI_QCMD()
3445 filep->private_data = pinstance; in DEF_SCSI_QCMD()
3451 * pmcraid_fasync - Async notifier registration from applications
3461 pinstance = filep->private_data; in pmcraid_chr_fasync()
3462 mutex_lock(&pinstance->aen_queue_lock); in pmcraid_chr_fasync()
3463 rc = fasync_helper(fd, filep, mode, &pinstance->aen_queue); in pmcraid_chr_fasync()
3464 mutex_unlock(&pinstance->aen_queue_lock); in pmcraid_chr_fasync()
3471 * pmcraid_build_passthrough_ioadls - builds SG elements for passthrough
3479 * 0 on success, non-zero error code on failure
3489 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_build_passthrough_ioadls()
3497 return -ENOMEM; in pmcraid_build_passthrough_ioadls()
3500 sglist->num_dma_sg = dma_map_sg(&cmd->drv_inst->pdev->dev, in pmcraid_build_passthrough_ioadls()
3501 sglist->scatterlist, in pmcraid_build_passthrough_ioadls()
3502 sglist->num_sg, direction); in pmcraid_build_passthrough_ioadls()
3504 if (!sglist->num_dma_sg || sglist->num_dma_sg > PMCRAID_MAX_IOADLS) { in pmcraid_build_passthrough_ioadls()
3505 dev_err(&cmd->drv_inst->pdev->dev, in pmcraid_build_passthrough_ioadls()
3508 return -EIO; in pmcraid_build_passthrough_ioadls()
3511 cmd->sglist = sglist; in pmcraid_build_passthrough_ioadls()
3512 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_build_passthrough_ioadls()
3514 ioadl = pmcraid_init_ioadls(cmd, sglist->num_dma_sg); in pmcraid_build_passthrough_ioadls()
3517 for_each_sg(sglist->scatterlist, sg, sglist->num_dma_sg, i) { in pmcraid_build_passthrough_ioadls()
3524 ioadl[i - 1].flags = IOADL_FLAGS_LAST_DESC; in pmcraid_build_passthrough_ioadls()
3531 * pmcraid_release_passthrough_ioadls - release passthrough ioadls
3538 * 0 on success, non-zero error code on failure
3546 struct pmcraid_sglist *sglist = cmd->sglist; in pmcraid_release_passthrough_ioadls()
3549 dma_unmap_sg(&cmd->drv_inst->pdev->dev, in pmcraid_release_passthrough_ioadls()
3550 sglist->scatterlist, in pmcraid_release_passthrough_ioadls()
3551 sglist->num_sg, in pmcraid_release_passthrough_ioadls()
3554 cmd->sglist = NULL; in pmcraid_release_passthrough_ioadls()
3559 * pmcraid_ioctl_passthrough - handling passthrough IOCTL commands
3566 * 0 on success, non-zero error code on failure
3590 if (pinstance->ioa_reset_in_progress) { in pmcraid_ioctl_passthrough()
3592 pinstance->reset_wait_q, in pmcraid_ioctl_passthrough()
3593 !pinstance->ioa_reset_in_progress, in pmcraid_ioctl_passthrough()
3597 return -ETIMEDOUT; in pmcraid_ioctl_passthrough()
3599 return -ERESTARTSYS; in pmcraid_ioctl_passthrough()
3603 if (pinstance->ioa_state != IOA_STATE_OPERATIONAL) { in pmcraid_ioctl_passthrough()
3605 return -ENOTTY; in pmcraid_ioctl_passthrough()
3613 return -ENOMEM; in pmcraid_ioctl_passthrough()
3628 rc = -EFAULT; in pmcraid_ioctl_passthrough()
3632 request_size = le32_to_cpu(buffer->ioarcb.data_transfer_length); in pmcraid_ioctl_passthrough()
3634 if (buffer->ioarcb.request_flags0 & TRANSFER_DIR_WRITE) { in pmcraid_ioctl_passthrough()
3641 rc = -EINVAL; in pmcraid_ioctl_passthrough()
3646 if (le16_to_cpu(buffer->ioarcb.add_cmd_param_length) in pmcraid_ioctl_passthrough()
3648 rc = -EINVAL; in pmcraid_ioctl_passthrough()
3656 rc = -ENOMEM; in pmcraid_ioctl_passthrough()
3660 cmd->scsi_cmd = NULL; in pmcraid_ioctl_passthrough()
3661 ioarcb = &(cmd->ioa_cb->ioarcb); in pmcraid_ioctl_passthrough()
3663 /* Copy the user-provided IOARCB stuff field by field */ in pmcraid_ioctl_passthrough()
3664 ioarcb->resource_handle = buffer->ioarcb.resource_handle; in pmcraid_ioctl_passthrough()
3665 ioarcb->data_transfer_length = buffer->ioarcb.data_transfer_length; in pmcraid_ioctl_passthrough()
3666 ioarcb->cmd_timeout = buffer->ioarcb.cmd_timeout; in pmcraid_ioctl_passthrough()
3667 ioarcb->request_type = buffer->ioarcb.request_type; in pmcraid_ioctl_passthrough()
3668 ioarcb->request_flags0 = buffer->ioarcb.request_flags0; in pmcraid_ioctl_passthrough()
3669 ioarcb->request_flags1 = buffer->ioarcb.request_flags1; in pmcraid_ioctl_passthrough()
3670 memcpy(ioarcb->cdb, buffer->ioarcb.cdb, PMCRAID_MAX_CDB_LEN); in pmcraid_ioctl_passthrough()
3672 if (buffer->ioarcb.add_cmd_param_length) { in pmcraid_ioctl_passthrough()
3673 ioarcb->add_cmd_param_length = in pmcraid_ioctl_passthrough()
3674 buffer->ioarcb.add_cmd_param_length; in pmcraid_ioctl_passthrough()
3675 ioarcb->add_cmd_param_offset = in pmcraid_ioctl_passthrough()
3676 buffer->ioarcb.add_cmd_param_offset; in pmcraid_ioctl_passthrough()
3677 memcpy(ioarcb->add_data.u.add_cmd_params, in pmcraid_ioctl_passthrough()
3678 buffer->ioarcb.add_data.u.add_cmd_params, in pmcraid_ioctl_passthrough()
3679 le16_to_cpu(buffer->ioarcb.add_cmd_param_length)); in pmcraid_ioctl_passthrough()
3684 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses in pmcraid_ioctl_passthrough()
3687 ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) % in pmcraid_ioctl_passthrough()
3688 pinstance->num_hrrq; in pmcraid_ioctl_passthrough()
3704 rc = pmcraid_copy_sglist(cmd->sglist, in pmcraid_ioctl_passthrough()
3717 cmd->cmd_done = pmcraid_internal_done; in pmcraid_ioctl_passthrough()
3718 init_completion(&cmd->wait_for_completion); in pmcraid_ioctl_passthrough()
3719 cmd->completion_req = 1; in pmcraid_ioctl_passthrough()
3722 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2, in pmcraid_ioctl_passthrough()
3723 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_ioctl_passthrough()
3724 le32_to_cpu(cmd->ioa_cb->ioarcb.resource_handle)); in pmcraid_ioctl_passthrough()
3726 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_ioctl_passthrough()
3728 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_ioctl_passthrough()
3736 buffer->ioarcb.cmd_timeout = 0; in pmcraid_ioctl_passthrough()
3742 if (buffer->ioarcb.cmd_timeout == 0) { in pmcraid_ioctl_passthrough()
3743 wait_for_completion(&cmd->wait_for_completion); in pmcraid_ioctl_passthrough()
3745 &cmd->wait_for_completion, in pmcraid_ioctl_passthrough()
3746 msecs_to_jiffies(le16_to_cpu(buffer->ioarcb.cmd_timeout) * 1000))) { in pmcraid_ioctl_passthrough()
3749 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2, in pmcraid_ioctl_passthrough()
3750 cmd->ioa_cb->ioarcb.cdb[0]); in pmcraid_ioctl_passthrough()
3752 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_ioctl_passthrough()
3754 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_ioctl_passthrough()
3757 wait_for_completion(&cancel_cmd->wait_for_completion); in pmcraid_ioctl_passthrough()
3758 ioasc = le32_to_cpu(cancel_cmd->ioa_cb->ioasa.ioasc); in pmcraid_ioctl_passthrough()
3765 * return -ETIMEDOUT in pmcraid_ioctl_passthrough()
3770 rc = -ETIMEDOUT; in pmcraid_ioctl_passthrough()
3780 &cmd->wait_for_completion, in pmcraid_ioctl_passthrough()
3782 pmcraid_reset_bringup(cmd->drv_inst); in pmcraid_ioctl_passthrough()
3783 rc = -ETIMEDOUT; in pmcraid_ioctl_passthrough()
3789 * If copying IOASA to user-buffer fails, return in pmcraid_ioctl_passthrough()
3792 if (copy_to_user(ioasa, &cmd->ioa_cb->ioasa, in pmcraid_ioctl_passthrough()
3795 rc = -EFAULT; in pmcraid_ioctl_passthrough()
3802 rc = pmcraid_copy_sglist(cmd->sglist, in pmcraid_ioctl_passthrough()
3808 rc = -EFAULT; in pmcraid_ioctl_passthrough()
3828 * pmcraid_ioctl_driver - ioctl handler for commands handled by driver itself
3845 int rc = -ENOSYS; in pmcraid_ioctl_driver()
3861 * pmcraid_check_ioctl_buffer - check for proper access to user buffer
3882 return -EFAULT; in pmcraid_check_ioctl_buffer()
3886 rc = memcmp(hdr->signature, in pmcraid_check_ioctl_buffer()
3888 sizeof(hdr->signature)); in pmcraid_check_ioctl_buffer()
3891 return -EINVAL; in pmcraid_check_ioctl_buffer()
3898 * pmcraid_ioctl - char node ioctl entry point
3909 int retval = -ENOTTY; in pmcraid_chr_ioctl()
3915 return -ENOMEM; in pmcraid_chr_ioctl()
3926 pinstance = filep->private_data; in pmcraid_chr_ioctl()
3931 return -ENOTTY; in pmcraid_chr_ioctl()
3938 * mid-layer requests. in pmcraid_chr_ioctl()
3941 scsi_block_requests(pinstance->host); in pmcraid_chr_ioctl()
3944 hdr->buffer_length, argp); in pmcraid_chr_ioctl()
3947 scsi_unblock_requests(pinstance->host); in pmcraid_chr_ioctl()
3953 hdr->buffer_length, argp); in pmcraid_chr_ioctl()
3957 retval = -ENOTTY; in pmcraid_chr_ioctl()
3982 * pmcraid_show_log_level - Display adapter's error logging level
3996 (struct pmcraid_instance *)shost->hostdata; in pmcraid_show_log_level()
3997 return snprintf(buf, PAGE_SIZE, "%d\n", pinstance->current_log_level); in pmcraid_show_log_level()
4001 * pmcraid_store_log_level - Change the adapter's error logging level
4021 return -EINVAL; in pmcraid_store_log_level()
4022 /* log-level should be from 0 to 2 */ in pmcraid_store_log_level()
4024 return -EINVAL; in pmcraid_store_log_level()
4027 pinstance = (struct pmcraid_instance *)shost->hostdata; in pmcraid_store_log_level()
4028 pinstance->current_log_level = val; in pmcraid_store_log_level()
4043 * pmcraid_show_drv_version - Display driver version
4069 * pmcraid_show_io_adapter_id - Display driver assigned adapter id
4084 (struct pmcraid_instance *)shost->hostdata; in pmcraid_show_adapter_id()
4085 u32 adapter_id = (pinstance->pdev->bus->number << 8) | in pmcraid_show_adapter_id()
4086 pinstance->pdev->devfn; in pmcraid_show_adapter_id()
4091 adapter_id, MINOR(pinstance->cdev.dev), aen_group); in pmcraid_show_adapter_id()
4126 .this_id = -1,
4136 * pmcraid_isr_msix - implements MSI-X interrupt handling routine
4153 hrrq_id = hrrq_vector->hrrq_id; in pmcraid_isr_msix()
4154 pinstance = hrrq_vector->drv_inst; in pmcraid_isr_msix()
4160 ((ioread32(pinstance->int_regs.host_ioa_interrupt_reg) in pmcraid_isr_msix()
4169 pinstance->ioa_unit_check = 1; in pmcraid_isr_msix()
4173 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_isr_msix()
4177 pinstance->host->host_lock, in pmcraid_isr_msix()
4192 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_isr_msix()
4193 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_isr_msix()
4199 tasklet_schedule(&(pinstance->isr_tasklet[hrrq_id])); in pmcraid_isr_msix()
4205 * pmcraid_isr - implements legacy interrupt handling routine
4229 pinstance = hrrq_vector->drv_inst; in pmcraid_isr()
4243 pinstance->ioa_unit_check = 1; in pmcraid_isr()
4246 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
4250 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
4251 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_isr()
4253 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_isr()
4263 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
4265 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
4268 &(pinstance->isr_tasklet[hrrq_id])); in pmcraid_isr()
4277 * pmcraid_worker_function - worker thread function
4298 if (!atomic_read(&pinstance->expose_resources)) in pmcraid_worker_function()
4301 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_worker_function()
4303 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_worker_function()
4304 list_for_each_entry_safe(res, temp, &pinstance->used_res_q, queue) { in pmcraid_worker_function()
4306 if (res->change_detected == RES_CHANGE_DEL && res->scsi_dev) { in pmcraid_worker_function()
4307 sdev = res->scsi_dev; in pmcraid_worker_function()
4312 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_worker_function()
4316 pinstance->host->host_lock, in pmcraid_worker_function()
4319 res->cfg_entry.resource_address); in pmcraid_worker_function()
4320 list_move_tail(&res->queue, in pmcraid_worker_function()
4321 &pinstance->free_res_q); in pmcraid_worker_function()
4323 &pinstance->resource_lock, in pmcraid_worker_function()
4327 spin_lock_irqsave(&pinstance->resource_lock, in pmcraid_worker_function()
4329 res->change_detected = 0; in pmcraid_worker_function()
4332 pinstance->host->host_lock, in pmcraid_worker_function()
4338 list_for_each_entry(res, &pinstance->used_res_q, queue) { in pmcraid_worker_function()
4340 if (res->change_detected == RES_CHANGE_ADD) { in pmcraid_worker_function()
4343 &res->cfg_entry)) in pmcraid_worker_function()
4346 if (RES_IS_VSET(res->cfg_entry)) { in pmcraid_worker_function()
4349 target = res->cfg_entry.unique_flags1; in pmcraid_worker_function()
4351 target = le16_to_cpu(res->cfg_entry.array_id) & 0xFF; in pmcraid_worker_function()
4357 res->cfg_entry.resource_address); in pmcraid_worker_function()
4358 lun = RES_LUN(res->cfg_entry.resource_address); in pmcraid_worker_function()
4361 res->change_detected = 0; in pmcraid_worker_function()
4362 spin_unlock_irqrestore(&pinstance->resource_lock, in pmcraid_worker_function()
4364 scsi_add_device(pinstance->host, bus, target, lun); in pmcraid_worker_function()
4365 spin_lock_irqsave(&pinstance->resource_lock, in pmcraid_worker_function()
4370 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_worker_function()
4374 * pmcraid_tasklet_function - Tasklet function
4393 pinstance = hrrq_vector->drv_inst; in pmcraid_tasklet_function()
4394 id = hrrq_vector->hrrq_id; in pmcraid_tasklet_function()
4395 lockp = &(pinstance->hrrq_lock[id]); in pmcraid_tasklet_function()
4405 resp = le32_to_cpu(*(pinstance->hrrq_curr[id])); in pmcraid_tasklet_function()
4408 pinstance->host_toggle_bit[id]) { in pmcraid_tasklet_function()
4413 if (pinstance->hrrq_curr[id] < pinstance->hrrq_end[id]) { in pmcraid_tasklet_function()
4414 pinstance->hrrq_curr[id]++; in pmcraid_tasklet_function()
4416 pinstance->hrrq_curr[id] = pinstance->hrrq_start[id]; in pmcraid_tasklet_function()
4417 pinstance->host_toggle_bit[id] ^= 1u; in pmcraid_tasklet_function()
4423 resp = le32_to_cpu(*(pinstance->hrrq_curr[id])); in pmcraid_tasklet_function()
4427 cmd = pinstance->cmd_list[cmd_index]; in pmcraid_tasklet_function()
4430 spin_lock_irqsave(&pinstance->pending_pool_lock, in pmcraid_tasklet_function()
4432 list_del(&cmd->free_list); in pmcraid_tasklet_function()
4433 spin_unlock_irqrestore(&pinstance->pending_pool_lock, in pmcraid_tasklet_function()
4435 del_timer(&cmd->timer); in pmcraid_tasklet_function()
4436 atomic_dec(&pinstance->outstanding_cmds); in pmcraid_tasklet_function()
4438 if (cmd->cmd_done == pmcraid_ioa_reset) { in pmcraid_tasklet_function()
4439 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_tasklet_function()
4441 cmd->cmd_done(cmd); in pmcraid_tasklet_function()
4442 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_tasklet_function()
4444 } else if (cmd->cmd_done != NULL) { in pmcraid_tasklet_function()
4445 cmd->cmd_done(cmd); in pmcraid_tasklet_function()
4449 resp = le32_to_cpu(*(pinstance->hrrq_curr[id])); in pmcraid_tasklet_function()
4456 * pmcraid_unregister_interrupt_handler - de-register interrupts handlers
4459 * This routine un-registers registered interrupt handler and
4468 struct pci_dev *pdev = pinstance->pdev; in pmcraid_unregister_interrupt_handler()
4471 for (i = 0; i < pinstance->num_hrrq; i++) in pmcraid_unregister_interrupt_handler()
4472 free_irq(pci_irq_vector(pdev, i), &pinstance->hrrq_vector[i]); in pmcraid_unregister_interrupt_handler()
4474 pinstance->interrupt_mode = 0; in pmcraid_unregister_interrupt_handler()
4479 * pmcraid_register_interrupt_handler - registers interrupt handler
4480 * @pinstance: pointer to per-adapter instance structure
4483 * 0 on success, non-zero error code otherwise.
4488 struct pci_dev *pdev = pinstance->pdev; in pmcraid_register_interrupt_handler()
4501 if (pdev->msix_enabled) { in pmcraid_register_interrupt_handler()
4510 struct pmcraid_isr_param *vec = &pinstance->hrrq_vector[i]; in pmcraid_register_interrupt_handler()
4512 vec->hrrq_id = i; in pmcraid_register_interrupt_handler()
4513 vec->drv_inst = pinstance; in pmcraid_register_interrupt_handler()
4520 pinstance->num_hrrq = num_hrrq; in pmcraid_register_interrupt_handler()
4521 if (pdev->msix_enabled) { in pmcraid_register_interrupt_handler()
4522 pinstance->interrupt_mode = 1; in pmcraid_register_interrupt_handler()
4524 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_register_interrupt_handler()
4525 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_register_interrupt_handler()
4531 while (--i >= 0) in pmcraid_register_interrupt_handler()
4532 free_irq(pci_irq_vector(pdev, i), &pinstance->hrrq_vector[i]); in pmcraid_register_interrupt_handler()
4538 * pmcraid_release_cmd_blocks - release buufers allocated for command blocks
4550 kmem_cache_free(pinstance->cmd_cachep, pinstance->cmd_list[i]); in pmcraid_release_cmd_blocks()
4551 pinstance->cmd_list[i] = NULL; in pmcraid_release_cmd_blocks()
4553 kmem_cache_destroy(pinstance->cmd_cachep); in pmcraid_release_cmd_blocks()
4554 pinstance->cmd_cachep = NULL; in pmcraid_release_cmd_blocks()
4558 * pmcraid_release_control_blocks - releases buffers alloced for control blocks
4576 if (pinstance->control_pool == NULL) in pmcraid_release_control_blocks()
4580 dma_pool_free(pinstance->control_pool, in pmcraid_release_control_blocks()
4581 pinstance->cmd_list[i]->ioa_cb, in pmcraid_release_control_blocks()
4582 pinstance->cmd_list[i]->ioa_cb_bus_addr); in pmcraid_release_control_blocks()
4583 pinstance->cmd_list[i]->ioa_cb = NULL; in pmcraid_release_control_blocks()
4584 pinstance->cmd_list[i]->ioa_cb_bus_addr = 0; in pmcraid_release_control_blocks()
4586 dma_pool_destroy(pinstance->control_pool); in pmcraid_release_control_blocks()
4587 pinstance->control_pool = NULL; in pmcraid_release_control_blocks()
4591 * pmcraid_allocate_cmd_blocks - allocate memory for cmd block structures
4592 * @pinstance - pointer to per adapter instance structure
4597 * 0 in case of success; -ENOMEM in case of failure
4603 sprintf(pinstance->cmd_pool_name, "pmcraid_cmd_pool_%d", in pmcraid_allocate_cmd_blocks()
4604 pinstance->host->unique_id); in pmcraid_allocate_cmd_blocks()
4607 pinstance->cmd_cachep = kmem_cache_create( in pmcraid_allocate_cmd_blocks()
4608 pinstance->cmd_pool_name, in pmcraid_allocate_cmd_blocks()
4611 if (!pinstance->cmd_cachep) in pmcraid_allocate_cmd_blocks()
4612 return -ENOMEM; in pmcraid_allocate_cmd_blocks()
4615 pinstance->cmd_list[i] = in pmcraid_allocate_cmd_blocks()
4616 kmem_cache_alloc(pinstance->cmd_cachep, GFP_KERNEL); in pmcraid_allocate_cmd_blocks()
4617 if (!pinstance->cmd_list[i]) { in pmcraid_allocate_cmd_blocks()
4619 return -ENOMEM; in pmcraid_allocate_cmd_blocks()
4626 * pmcraid_allocate_control_blocks - allocates memory control blocks
4633 * 0 in case it can allocate all control blocks, otherwise -ENOMEM
4639 sprintf(pinstance->ctl_pool_name, "pmcraid_control_pool_%d", in pmcraid_allocate_control_blocks()
4640 pinstance->host->unique_id); in pmcraid_allocate_control_blocks()
4642 pinstance->control_pool = in pmcraid_allocate_control_blocks()
4643 dma_pool_create(pinstance->ctl_pool_name, in pmcraid_allocate_control_blocks()
4644 &pinstance->pdev->dev, in pmcraid_allocate_control_blocks()
4648 if (!pinstance->control_pool) in pmcraid_allocate_control_blocks()
4649 return -ENOMEM; in pmcraid_allocate_control_blocks()
4652 pinstance->cmd_list[i]->ioa_cb = in pmcraid_allocate_control_blocks()
4654 pinstance->control_pool, in pmcraid_allocate_control_blocks()
4656 &(pinstance->cmd_list[i]->ioa_cb_bus_addr)); in pmcraid_allocate_control_blocks()
4658 if (!pinstance->cmd_list[i]->ioa_cb) { in pmcraid_allocate_control_blocks()
4660 return -ENOMEM; in pmcraid_allocate_control_blocks()
4667 * pmcraid_release_host_rrqs - release memory allocated for hrrq buffer(s)
4680 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_host_rrqs()
4682 pinstance->hrrq_start[i], in pmcraid_release_host_rrqs()
4683 pinstance->hrrq_start_bus_addr[i]); in pmcraid_release_host_rrqs()
4686 pinstance->hrrq_start[i] = NULL; in pmcraid_release_host_rrqs()
4687 pinstance->hrrq_start_bus_addr[i] = 0; in pmcraid_release_host_rrqs()
4688 pinstance->host_toggle_bit[i] = 0; in pmcraid_release_host_rrqs()
4693 * pmcraid_allocate_host_rrqs - Allocate and initialize host RRQ buffers
4697 * 0 hrrq buffers are allocated, -ENOMEM otherwise.
4705 for (i = 0; i < pinstance->num_hrrq; i++) { in pmcraid_allocate_host_rrqs()
4706 pinstance->hrrq_start[i] = in pmcraid_allocate_host_rrqs()
4707 dma_alloc_coherent(&pinstance->pdev->dev, buffer_size, in pmcraid_allocate_host_rrqs()
4708 &pinstance->hrrq_start_bus_addr[i], in pmcraid_allocate_host_rrqs()
4710 if (!pinstance->hrrq_start[i]) { in pmcraid_allocate_host_rrqs()
4714 return -ENOMEM; in pmcraid_allocate_host_rrqs()
4717 pinstance->hrrq_curr[i] = pinstance->hrrq_start[i]; in pmcraid_allocate_host_rrqs()
4718 pinstance->hrrq_end[i] = in pmcraid_allocate_host_rrqs()
4719 pinstance->hrrq_start[i] + PMCRAID_MAX_CMD - 1; in pmcraid_allocate_host_rrqs()
4720 pinstance->host_toggle_bit[i] = 1; in pmcraid_allocate_host_rrqs()
4721 spin_lock_init(&pinstance->hrrq_lock[i]); in pmcraid_allocate_host_rrqs()
4727 * pmcraid_release_hcams - release HCAM buffers
4736 if (pinstance->ccn.msg != NULL) { in pmcraid_release_hcams()
4737 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_hcams()
4740 pinstance->ccn.msg, in pmcraid_release_hcams()
4741 pinstance->ccn.baddr); in pmcraid_release_hcams()
4743 pinstance->ccn.msg = NULL; in pmcraid_release_hcams()
4744 pinstance->ccn.hcam = NULL; in pmcraid_release_hcams()
4745 pinstance->ccn.baddr = 0; in pmcraid_release_hcams()
4748 if (pinstance->ldn.msg != NULL) { in pmcraid_release_hcams()
4749 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_hcams()
4752 pinstance->ldn.msg, in pmcraid_release_hcams()
4753 pinstance->ldn.baddr); in pmcraid_release_hcams()
4755 pinstance->ldn.msg = NULL; in pmcraid_release_hcams()
4756 pinstance->ldn.hcam = NULL; in pmcraid_release_hcams()
4757 pinstance->ldn.baddr = 0; in pmcraid_release_hcams()
4762 * pmcraid_allocate_hcams - allocates HCAM buffers
4766 * 0 in case of successful allocation, non-zero otherwise
4770 pinstance->ccn.msg = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_allocate_hcams()
4773 &pinstance->ccn.baddr, GFP_KERNEL); in pmcraid_allocate_hcams()
4775 pinstance->ldn.msg = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_allocate_hcams()
4778 &pinstance->ldn.baddr, GFP_KERNEL); in pmcraid_allocate_hcams()
4780 if (pinstance->ldn.msg == NULL || pinstance->ccn.msg == NULL) { in pmcraid_allocate_hcams()
4783 pinstance->ccn.hcam = in pmcraid_allocate_hcams()
4784 (void *)pinstance->ccn.msg + PMCRAID_AEN_HDR_SIZE; in pmcraid_allocate_hcams()
4785 pinstance->ldn.hcam = in pmcraid_allocate_hcams()
4786 (void *)pinstance->ldn.msg + PMCRAID_AEN_HDR_SIZE; in pmcraid_allocate_hcams()
4788 atomic_set(&pinstance->ccn.ignore, 0); in pmcraid_allocate_hcams()
4789 atomic_set(&pinstance->ldn.ignore, 0); in pmcraid_allocate_hcams()
4792 return (pinstance->ldn.msg == NULL) ? -ENOMEM : 0; in pmcraid_allocate_hcams()
4796 * pmcraid_release_config_buffers - release config.table buffers
4804 if (pinstance->cfg_table != NULL && in pmcraid_release_config_buffers()
4805 pinstance->cfg_table_bus_addr != 0) { in pmcraid_release_config_buffers()
4806 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_config_buffers()
4808 pinstance->cfg_table, in pmcraid_release_config_buffers()
4809 pinstance->cfg_table_bus_addr); in pmcraid_release_config_buffers()
4810 pinstance->cfg_table = NULL; in pmcraid_release_config_buffers()
4811 pinstance->cfg_table_bus_addr = 0; in pmcraid_release_config_buffers()
4814 if (pinstance->res_entries != NULL) { in pmcraid_release_config_buffers()
4818 list_del(&pinstance->res_entries[i].queue); in pmcraid_release_config_buffers()
4819 kfree(pinstance->res_entries); in pmcraid_release_config_buffers()
4820 pinstance->res_entries = NULL; in pmcraid_release_config_buffers()
4827 * pmcraid_allocate_config_buffers - allocates DMAable memory for config table
4831 * 0 for successful allocation, -ENOMEM for any failure
4837 pinstance->res_entries = in pmcraid_allocate_config_buffers()
4842 if (NULL == pinstance->res_entries) { in pmcraid_allocate_config_buffers()
4844 return -ENOMEM; in pmcraid_allocate_config_buffers()
4848 list_add_tail(&pinstance->res_entries[i].queue, in pmcraid_allocate_config_buffers()
4849 &pinstance->free_res_q); in pmcraid_allocate_config_buffers()
4851 pinstance->cfg_table = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_allocate_config_buffers()
4853 &pinstance->cfg_table_bus_addr, in pmcraid_allocate_config_buffers()
4856 if (NULL == pinstance->cfg_table) { in pmcraid_allocate_config_buffers()
4859 return -ENOMEM; in pmcraid_allocate_config_buffers()
4865 return -ENOMEM; in pmcraid_allocate_config_buffers()
4872 * pmcraid_init_tasklets - registers tasklets for response handling
4882 for (i = 0; i < pinstance->num_hrrq; i++) in pmcraid_init_tasklets()
4883 tasklet_init(&pinstance->isr_tasklet[i], in pmcraid_init_tasklets()
4885 (unsigned long)&pinstance->hrrq_vector[i]); in pmcraid_init_tasklets()
4889 * pmcraid_kill_tasklets - destroys tasklets registered for response handling
4899 for (i = 0; i < pinstance->num_hrrq; i++) in pmcraid_kill_tasklets()
4900 tasklet_kill(&pinstance->isr_tasklet[i]); in pmcraid_kill_tasklets()
4904 * pmcraid_release_buffers - release per-adapter buffers allocated
4916 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_release_buffers()
4918 if (pinstance->inq_data != NULL) { in pmcraid_release_buffers()
4919 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_buffers()
4921 pinstance->inq_data, in pmcraid_release_buffers()
4922 pinstance->inq_data_baddr); in pmcraid_release_buffers()
4924 pinstance->inq_data = NULL; in pmcraid_release_buffers()
4925 pinstance->inq_data_baddr = 0; in pmcraid_release_buffers()
4928 if (pinstance->timestamp_data != NULL) { in pmcraid_release_buffers()
4929 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_buffers()
4931 pinstance->timestamp_data, in pmcraid_release_buffers()
4932 pinstance->timestamp_data_baddr); in pmcraid_release_buffers()
4934 pinstance->timestamp_data = NULL; in pmcraid_release_buffers()
4935 pinstance->timestamp_data_baddr = 0; in pmcraid_release_buffers()
4940 * pmcraid_init_buffers - allocates memory and initializes various structures
4943 * This routine pre-allocates memory based on the type of block as below:
4946 * config-table entries : DMAable memory using dma_alloc_coherent
4950 * 0 in case all of the blocks are allocated, -ENOMEM otherwise.
4958 pinstance->num_hrrq); in pmcraid_init_buffers()
4959 return -ENOMEM; in pmcraid_init_buffers()
4964 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_init_buffers()
4965 return -ENOMEM; in pmcraid_init_buffers()
4971 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_init_buffers()
4972 return -ENOMEM; in pmcraid_init_buffers()
4979 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_init_buffers()
4980 return -ENOMEM; in pmcraid_init_buffers()
4984 pinstance->inq_data = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_init_buffers()
4986 &pinstance->inq_data_baddr, GFP_KERNEL); in pmcraid_init_buffers()
4987 if (pinstance->inq_data == NULL) { in pmcraid_init_buffers()
4990 return -ENOMEM; in pmcraid_init_buffers()
4994 pinstance->timestamp_data = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_init_buffers()
4996 &pinstance->timestamp_data_baddr, in pmcraid_init_buffers()
4998 if (pinstance->timestamp_data == NULL) { in pmcraid_init_buffers()
5002 return -ENOMEM; in pmcraid_init_buffers()
5011 struct pmcraid_cmd *cmdp = pinstance->cmd_list[i]; in pmcraid_init_buffers()
5013 cmdp->drv_inst = pinstance; in pmcraid_init_buffers()
5014 list_add_tail(&cmdp->free_list, &pinstance->free_cmd_pool); in pmcraid_init_buffers()
5021 * pmcraid_reinit_buffers - resets various buffer pointers
5031 for (i = 0; i < pinstance->num_hrrq; i++) { in pmcraid_reinit_buffers()
5032 memset(pinstance->hrrq_start[i], 0, buffer_size); in pmcraid_reinit_buffers()
5033 pinstance->hrrq_curr[i] = pinstance->hrrq_start[i]; in pmcraid_reinit_buffers()
5034 pinstance->hrrq_end[i] = in pmcraid_reinit_buffers()
5035 pinstance->hrrq_start[i] + PMCRAID_MAX_CMD - 1; in pmcraid_reinit_buffers()
5036 pinstance->host_toggle_bit[i] = 1; in pmcraid_reinit_buffers()
5041 * pmcraid_init_instance - initialize per instance data structure
5047 * 0 on success, non-zero in case of any failure
5053 (struct pmcraid_instance *)host->hostdata; in pmcraid_init_instance()
5055 pinstance->host = host; in pmcraid_init_instance()
5056 pinstance->pdev = pdev; in pmcraid_init_instance()
5059 pinstance->mapped_dma_addr = mapped_pci_addr; in pmcraid_init_instance()
5061 /* Initialize chip-specific details */ in pmcraid_init_instance()
5063 struct pmcraid_chip_details *chip_cfg = pinstance->chip_cfg; in pmcraid_init_instance()
5064 struct pmcraid_interrupts *pint_regs = &pinstance->int_regs; in pmcraid_init_instance()
5066 pinstance->ioarrin = mapped_pci_addr + chip_cfg->ioarrin; in pmcraid_init_instance()
5068 pint_regs->ioa_host_interrupt_reg = in pmcraid_init_instance()
5069 mapped_pci_addr + chip_cfg->ioa_host_intr; in pmcraid_init_instance()
5070 pint_regs->ioa_host_interrupt_clr_reg = in pmcraid_init_instance()
5071 mapped_pci_addr + chip_cfg->ioa_host_intr_clr; in pmcraid_init_instance()
5072 pint_regs->ioa_host_msix_interrupt_reg = in pmcraid_init_instance()
5073 mapped_pci_addr + chip_cfg->ioa_host_msix_intr; in pmcraid_init_instance()
5074 pint_regs->host_ioa_interrupt_reg = in pmcraid_init_instance()
5075 mapped_pci_addr + chip_cfg->host_ioa_intr; in pmcraid_init_instance()
5076 pint_regs->host_ioa_interrupt_clr_reg = in pmcraid_init_instance()
5077 mapped_pci_addr + chip_cfg->host_ioa_intr_clr; in pmcraid_init_instance()
5082 pinstance->mailbox = mapped_pci_addr + chip_cfg->mailbox; in pmcraid_init_instance()
5083 pinstance->ioa_status = mapped_pci_addr + chip_cfg->ioastatus; in pmcraid_init_instance()
5084 pint_regs->ioa_host_interrupt_mask_reg = in pmcraid_init_instance()
5085 mapped_pci_addr + chip_cfg->ioa_host_mask; in pmcraid_init_instance()
5086 pint_regs->ioa_host_interrupt_mask_clr_reg = in pmcraid_init_instance()
5087 mapped_pci_addr + chip_cfg->ioa_host_mask_clr; in pmcraid_init_instance()
5088 pint_regs->global_interrupt_mask_reg = in pmcraid_init_instance()
5089 mapped_pci_addr + chip_cfg->global_intr_mask; in pmcraid_init_instance()
5092 pinstance->ioa_reset_attempts = 0; in pmcraid_init_instance()
5093 init_waitqueue_head(&pinstance->reset_wait_q); in pmcraid_init_instance()
5095 atomic_set(&pinstance->outstanding_cmds, 0); in pmcraid_init_instance()
5096 atomic_set(&pinstance->last_message_id, 0); in pmcraid_init_instance()
5097 atomic_set(&pinstance->expose_resources, 0); in pmcraid_init_instance()
5099 INIT_LIST_HEAD(&pinstance->free_res_q); in pmcraid_init_instance()
5100 INIT_LIST_HEAD(&pinstance->used_res_q); in pmcraid_init_instance()
5101 INIT_LIST_HEAD(&pinstance->free_cmd_pool); in pmcraid_init_instance()
5102 INIT_LIST_HEAD(&pinstance->pending_cmd_pool); in pmcraid_init_instance()
5104 spin_lock_init(&pinstance->free_pool_lock); in pmcraid_init_instance()
5105 spin_lock_init(&pinstance->pending_pool_lock); in pmcraid_init_instance()
5106 spin_lock_init(&pinstance->resource_lock); in pmcraid_init_instance()
5107 mutex_init(&pinstance->aen_queue_lock); in pmcraid_init_instance()
5109 /* Work-queue (Shared) for deferred processing error handling */ in pmcraid_init_instance()
5110 INIT_WORK(&pinstance->worker_q, pmcraid_worker_function); in pmcraid_init_instance()
5113 pinstance->current_log_level = pmcraid_log_level; in pmcraid_init_instance()
5116 pinstance->ioa_state = IOA_STATE_UNKNOWN; in pmcraid_init_instance()
5117 pinstance->reset_cmd = NULL; in pmcraid_init_instance()
5122 * pmcraid_shutdown - shutdown adapter controller.
5138 * pmcraid_get_minor - returns unused minor number from minor number bitmap
5150 * pmcraid_release_minor - releases given minor back to minor number bitmap
5158 * pmcraid_setup_chrdev - allocates a minor number and registers a char device
5163 * 0 in case of success, otherwise non-zero
5171 cdev_init(&pinstance->cdev, &pmcraid_fops); in pmcraid_setup_chrdev()
5172 pinstance->cdev.owner = THIS_MODULE; in pmcraid_setup_chrdev()
5174 error = cdev_add(&pinstance->cdev, MKDEV(pmcraid_major, minor), 1); in pmcraid_setup_chrdev()
5185 * pmcraid_release_chrdev - unregisters per-adapter management interface
5194 pmcraid_release_minor(MINOR(pinstance->cdev.dev)); in pmcraid_release_chrdev()
5196 MKDEV(pmcraid_major, MINOR(pinstance->cdev.dev))); in pmcraid_release_chrdev()
5197 cdev_del(&pinstance->cdev); in pmcraid_release_chrdev()
5201 * pmcraid_remove - IOA hot plug remove entry point
5215 scsi_remove_host(pinstance->host); in pmcraid_remove()
5217 /* block requests from mid-layer */ in pmcraid_remove()
5218 scsi_block_requests(pinstance->host); in pmcraid_remove()
5224 flush_work(&pinstance->worker_q); in pmcraid_remove()
5229 iounmap(pinstance->mapped_dma_addr); in pmcraid_remove()
5231 scsi_host_put(pinstance->host); in pmcraid_remove()
5239 * pmcraid_suspend - driver suspend entry point for power management
5243 * Return Value - 0 always
5252 pci_set_drvdata(pinstance->pdev, pinstance); in pmcraid_suspend()
5262 * pmcraid_resume - driver resume entry point PCI power management
5265 * Return Value - 0 in case of success. Error code in case of any failure
5270 struct Scsi_Host *host = pinstance->host; in pmcraid_resume()
5280 dev_err(&pdev->dev, "resume: Enable device failed\n"); in pmcraid_resume()
5287 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) in pmcraid_resume()
5288 rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_resume()
5291 rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_resume()
5294 dev_err(&pdev->dev, "resume: Failed to set PCI DMA mask\n"); in pmcraid_resume()
5299 atomic_set(&pinstance->outstanding_cmds, 0); in pmcraid_resume()
5303 dev_err(&pdev->dev, in pmcraid_resume()
5305 rc = -ENODEV; in pmcraid_resume()
5315 pinstance->ioa_hard_reset = 1; in pmcraid_resume()
5321 dev_err(&pdev->dev, "couldn't initialize IOA\n"); in pmcraid_resume()
5322 rc = -ENODEV; in pmcraid_resume()
5350 * pmcraid_complete_ioa_reset - Called by either timer or tasklet during
5356 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_complete_ioa_reset()
5359 spin_lock_irqsave(pinstance->host->host_lock, flags); in pmcraid_complete_ioa_reset()
5361 spin_unlock_irqrestore(pinstance->host->host_lock, flags); in pmcraid_complete_ioa_reset()
5362 scsi_unblock_requests(pinstance->host); in pmcraid_complete_ioa_reset()
5363 schedule_work(&pinstance->worker_q); in pmcraid_complete_ioa_reset()
5367 * pmcraid_set_supported_devs - sends SET SUPPORTED DEVICES to IOAFP
5372 * 0 for success or non-zero for failure cases
5376 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_set_supported_devs()
5381 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_set_supported_devs()
5382 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_set_supported_devs()
5383 ioarcb->cdb[0] = PMCRAID_SET_SUPPORTED_DEVICES; in pmcraid_set_supported_devs()
5384 ioarcb->cdb[1] = ALL_DEVICES_SUPPORTED; in pmcraid_set_supported_devs()
5390 if (cmd->drv_inst->reinit_cfg_table) { in pmcraid_set_supported_devs()
5391 cmd->drv_inst->reinit_cfg_table = 0; in pmcraid_set_supported_devs()
5392 cmd->release = 1; in pmcraid_set_supported_devs()
5408 * pmcraid_set_timestamp - set the timestamp to IOAFP
5413 * 0 for success or non-zero for failure cases
5417 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_set_timestamp()
5418 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_set_timestamp()
5425 pinstance->timestamp_data->timestamp[0] = (__u8)(timestamp); in pmcraid_set_timestamp()
5426 pinstance->timestamp_data->timestamp[1] = (__u8)((timestamp) >> 8); in pmcraid_set_timestamp()
5427 pinstance->timestamp_data->timestamp[2] = (__u8)((timestamp) >> 16); in pmcraid_set_timestamp()
5428 pinstance->timestamp_data->timestamp[3] = (__u8)((timestamp) >> 24); in pmcraid_set_timestamp()
5429 pinstance->timestamp_data->timestamp[4] = (__u8)((timestamp) >> 32); in pmcraid_set_timestamp()
5430 pinstance->timestamp_data->timestamp[5] = (__u8)((timestamp) >> 40); in pmcraid_set_timestamp()
5433 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_set_timestamp()
5434 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_set_timestamp()
5435 ioarcb->cdb[0] = PMCRAID_SCSI_SET_TIMESTAMP; in pmcraid_set_timestamp()
5436 ioarcb->cdb[1] = PMCRAID_SCSI_SERVICE_ACTION; in pmcraid_set_timestamp()
5437 memcpy(&(ioarcb->cdb[6]), &time_stamp_len, sizeof(time_stamp_len)); in pmcraid_set_timestamp()
5439 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_set_timestamp()
5442 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_set_timestamp()
5443 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL)); in pmcraid_set_timestamp()
5445 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_set_timestamp()
5446 ioarcb->request_flags0 |= TRANSFER_DIR_WRITE; in pmcraid_set_timestamp()
5447 ioarcb->data_transfer_length = in pmcraid_set_timestamp()
5449 ioadl = &(ioarcb->add_data.u.ioadl[0]); in pmcraid_set_timestamp()
5450 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_set_timestamp()
5451 ioadl->address = cpu_to_le64(pinstance->timestamp_data_baddr); in pmcraid_set_timestamp()
5452 ioadl->data_len = cpu_to_le32(sizeof(struct pmcraid_timestamp_data)); in pmcraid_set_timestamp()
5454 if (!pinstance->timestamp_error) { in pmcraid_set_timestamp()
5455 pinstance->timestamp_error = 0; in pmcraid_set_timestamp()
5467 * pmcraid_init_res_table - Initialize the resource table
5472 * devices and schedule adding/removing them from the mid-layer
5480 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_init_res_table()
5488 if (pinstance->cfg_table->flags & MICROCODE_UPDATE_REQUIRED) in pmcraid_init_res_table()
5491 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_init_res_table()
5493 /* resource list is protected by pinstance->resource_lock. in pmcraid_init_res_table()
5494 * init_res_table can be called from probe (user-thread) or runtime in pmcraid_init_res_table()
5497 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_init_res_table()
5499 list_for_each_entry_safe(res, temp, &pinstance->used_res_q, queue) in pmcraid_init_res_table()
5500 list_move_tail(&res->queue, &old_res); in pmcraid_init_res_table()
5502 for (i = 0; i < le16_to_cpu(pinstance->cfg_table->num_entries); i++) { in pmcraid_init_res_table()
5503 if (be16_to_cpu(pinstance->inq_data->fw_version) <= in pmcraid_init_res_table()
5505 cfgte = &pinstance->cfg_table->entries[i]; in pmcraid_init_res_table()
5508 &pinstance->cfg_table->entries_ext[i]; in pmcraid_init_res_table()
5518 rc = memcmp(&res->cfg_entry.resource_address, in pmcraid_init_res_table()
5519 &cfgte->resource_address, in pmcraid_init_res_table()
5520 sizeof(cfgte->resource_address)); in pmcraid_init_res_table()
5522 list_move_tail(&res->queue, in pmcraid_init_res_table()
5523 &pinstance->used_res_q); in pmcraid_init_res_table()
5532 if (list_empty(&pinstance->free_res_q)) { in pmcraid_init_res_table()
5538 res = list_entry(pinstance->free_res_q.next, in pmcraid_init_res_table()
5541 res->scsi_dev = NULL; in pmcraid_init_res_table()
5542 res->change_detected = RES_CHANGE_ADD; in pmcraid_init_res_table()
5543 res->reset_progress = 0; in pmcraid_init_res_table()
5544 list_move_tail(&res->queue, &pinstance->used_res_q); in pmcraid_init_res_table()
5551 memcpy(&res->cfg_entry, cfgte, in pmcraid_init_res_table()
5552 pinstance->config_table_entry_size); in pmcraid_init_res_table()
5554 res->cfg_entry.resource_type, in pmcraid_init_res_table()
5556 res->cfg_entry.unique_flags1 : in pmcraid_init_res_table()
5557 le16_to_cpu(res->cfg_entry.array_id) & 0xFF), in pmcraid_init_res_table()
5558 le32_to_cpu(res->cfg_entry.resource_address)); in pmcraid_init_res_table()
5562 /* Detect any deleted entries, mark them for deletion from mid-layer */ in pmcraid_init_res_table()
5565 if (res->scsi_dev) { in pmcraid_init_res_table()
5566 res->change_detected = RES_CHANGE_DEL; in pmcraid_init_res_table()
5567 res->cfg_entry.resource_handle = in pmcraid_init_res_table()
5569 list_move_tail(&res->queue, &pinstance->used_res_q); in pmcraid_init_res_table()
5571 list_move_tail(&res->queue, &pinstance->free_res_q); in pmcraid_init_res_table()
5576 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_init_res_table()
5581 * pmcraid_querycfg - Send a Query IOA Config to the adapter.
5592 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_querycfg()
5594 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_querycfg()
5597 if (be16_to_cpu(pinstance->inq_data->fw_version) <= in pmcraid_querycfg()
5599 pinstance->config_table_entry_size = in pmcraid_querycfg()
5602 pinstance->config_table_entry_size = in pmcraid_querycfg()
5605 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_querycfg()
5606 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_querycfg()
5608 ioarcb->cdb[0] = PMCRAID_QUERY_IOA_CONFIG; in pmcraid_querycfg()
5610 /* firmware requires 4-byte length field, specified in B.E format */ in pmcraid_querycfg()
5611 memcpy(&(ioarcb->cdb[10]), &cfg_table_size, sizeof(cfg_table_size)); in pmcraid_querycfg()
5616 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_querycfg()
5619 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_querycfg()
5620 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~0x1FULL); in pmcraid_querycfg()
5622 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_querycfg()
5623 ioarcb->data_transfer_length = in pmcraid_querycfg()
5626 ioadl = &(ioarcb->add_data.u.ioadl[0]); in pmcraid_querycfg()
5627 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_querycfg()
5628 ioadl->address = cpu_to_le64(pinstance->cfg_table_bus_addr); in pmcraid_querycfg()
5629 ioadl->data_len = cpu_to_le32(sizeof(struct pmcraid_config_table)); in pmcraid_querycfg()
5637 * pmcraid_probe - PCI probe entry pointer for PMC MaxRAID controller driver
5643 * returns non-zero error code in case of any failure
5657 return -ENOMEM; in pmcraid_probe()
5664 dev_err(&pdev->dev, "Cannot enable adapter\n"); in pmcraid_probe()
5669 dev_info(&pdev->dev, in pmcraid_probe()
5671 pdev->vendor, pdev->device, in pmcraid_probe()
5677 dev_err(&pdev->dev, in pmcraid_probe()
5685 dev_err(&pdev->dev, "Couldn't map PCI registers memory\n"); in pmcraid_probe()
5686 rc = -ENOMEM; in pmcraid_probe()
5693 * 32-bit addressable range though it has 64-bit IOARRIN register. in pmcraid_probe()
5694 * However, firmware supports 64-bit streaming DMA buffers, whereas in pmcraid_probe()
5695 * coherent buffers are to be 32-bit. Since dma_alloc_coherent always in pmcraid_probe()
5700 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) in pmcraid_probe()
5701 rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_probe()
5703 /* firmware expects 32-bit DMA addresses for IOARRIN register; set 32 in pmcraid_probe()
5707 rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_probe()
5710 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n"); in pmcraid_probe()
5718 dev_err(&pdev->dev, "scsi_host_alloc failed!\n"); in pmcraid_probe()
5719 rc = -ENOMEM; in pmcraid_probe()
5723 host->max_id = PMCRAID_MAX_NUM_TARGETS_PER_BUS; in pmcraid_probe()
5724 host->max_lun = PMCRAID_MAX_NUM_LUNS_PER_TARGET; in pmcraid_probe()
5725 host->unique_id = host->host_no; in pmcraid_probe()
5726 host->max_channel = PMCRAID_MAX_BUS_TO_SCAN; in pmcraid_probe()
5727 host->max_cmd_len = PMCRAID_MAX_CDB_LEN; in pmcraid_probe()
5730 pinstance = (struct pmcraid_instance *)host->hostdata; in pmcraid_probe()
5733 pinstance->chip_cfg = in pmcraid_probe()
5734 (struct pmcraid_chip_details *)(dev_id->driver_data); in pmcraid_probe()
5739 dev_err(&pdev->dev, "failed to initialize adapter instance\n"); in pmcraid_probe()
5745 /* Save PCI config-space for use following the reset */ in pmcraid_probe()
5746 rc = pci_save_state(pinstance->pdev); in pmcraid_probe()
5749 dev_err(&pdev->dev, "Failed to save PCI config space\n"); in pmcraid_probe()
5758 dev_err(&pdev->dev, "couldn't register interrupt handler\n"); in pmcraid_probe()
5782 dev_err(&pdev->dev, "couldn't initialize IOA\n"); in pmcraid_probe()
5787 /* Add adapter instance into mid-layer list */ in pmcraid_probe()
5788 rc = scsi_add_host(pinstance->host, &pdev->dev); in pmcraid_probe()
5790 pmcraid_err("couldn't add host into mid-layer: %d\n", rc); in pmcraid_probe()
5794 scsi_scan_host(pinstance->host); in pmcraid_probe()
5799 pmcraid_err("couldn't create mgmt interface, error: %x\n", in pmcraid_probe()
5807 atomic_set(&pinstance->expose_resources, 1); in pmcraid_probe()
5808 schedule_work(&pinstance->worker_q); in pmcraid_probe()
5833 return -ENODEV; in pmcraid_probe()
5850 * pmcraid_init - module load entry point
5904 * pmcraid_exit - module unload entry point