• 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
455 u32 gmask = ioread32(pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_enable_interrupts()
458 iowrite32(nmask, pinstance->int_regs.global_interrupt_mask_reg); in pmcraid_enable_interrupts()
460 if (!pinstance->interrupt_mode) { in pmcraid_enable_interrupts()
462 pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_enable_interrupts()
463 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_enable_interrupts()
467 ioread32(pinstance->int_regs.global_interrupt_mask_reg), in pmcraid_enable_interrupts()
468 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg)); in pmcraid_enable_interrupts()
472 * pmcraid_clr_trans_op - clear trans to op interrupt
485 if (!pinstance->interrupt_mode) { in pmcraid_clr_trans_op()
487 pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_clr_trans_op()
488 ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_clr_trans_op()
490 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_clr_trans_op()
491 ioread32(pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_clr_trans_op()
494 if (pinstance->reset_cmd != NULL) { in pmcraid_clr_trans_op()
495 del_timer(&pinstance->reset_cmd->timer); in pmcraid_clr_trans_op()
497 pinstance->host->host_lock, lock_flags); in pmcraid_clr_trans_op()
498 pinstance->reset_cmd->cmd_done(pinstance->reset_cmd); in pmcraid_clr_trans_op()
500 pinstance->host->host_lock, lock_flags); in pmcraid_clr_trans_op()
505 * pmcraid_reset_type - Determine the required reset type
519 mask = ioread32(pinstance->int_regs.ioa_host_interrupt_mask_reg); in pmcraid_reset_type()
520 intrs = ioread32(pinstance->int_regs.ioa_host_interrupt_reg); in pmcraid_reset_type()
521 alerts = ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_reset_type()
527 pinstance->ioa_hard_reset = 1; in pmcraid_reset_type()
532 pinstance->ioa_unit_check = 1; in pmcraid_reset_type()
537 * pmcraid_bist_done - completion function for PCI BIST
545 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_bist_done()
550 rc = pci_read_config_word(pinstance->pdev, PCI_COMMAND, &pci_reg); in pmcraid_bist_done()
554 cmd->time_left > 0) { in pmcraid_bist_done()
556 cmd->timer.expires = jiffies + cmd->time_left; in pmcraid_bist_done()
557 cmd->time_left = 0; in pmcraid_bist_done()
558 add_timer(&cmd->timer); in pmcraid_bist_done()
560 cmd->time_left = 0; in pmcraid_bist_done()
562 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_bist_done()
564 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_bist_done()
569 * pmcraid_start_bist - starts BIST
576 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_start_bist()
581 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_start_bist()
582 doorbells = ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_start_bist()
583 intrs = ioread32(pinstance->int_regs.ioa_host_interrupt_reg); in pmcraid_start_bist()
587 cmd->time_left = msecs_to_jiffies(PMCRAID_BIST_TIMEOUT); in pmcraid_start_bist()
588 cmd->timer.expires = jiffies + msecs_to_jiffies(PMCRAID_BIST_TIMEOUT); in pmcraid_start_bist()
589 cmd->timer.function = pmcraid_bist_done; in pmcraid_start_bist()
590 add_timer(&cmd->timer); in pmcraid_start_bist()
594 * pmcraid_reset_alert_done - completion routine for reset_alert
602 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_reset_alert_done()
603 u32 status = ioread32(pinstance->ioa_status); in pmcraid_reset_alert_done()
611 cmd->time_left <= 0) { in pmcraid_reset_alert_done()
613 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_alert_done()
615 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_alert_done()
619 cmd->time_left -= PMCRAID_CHECK_FOR_RESET_TIMEOUT; in pmcraid_reset_alert_done()
620 cmd->timer.expires = jiffies + PMCRAID_CHECK_FOR_RESET_TIMEOUT; in pmcraid_reset_alert_done()
621 cmd->timer.function = pmcraid_reset_alert_done; in pmcraid_reset_alert_done()
622 add_timer(&cmd->timer); in pmcraid_reset_alert_done()
628 * pmcraid_reset_alert - alerts IOA for a possible reset
632 * returns 0 if pci config-space is accessible and RESET_DOORBELL is
633 * successfully written to IOA. Returns non-zero in case pci_config_space
638 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_reset_alert()
648 rc = pci_read_config_word(pinstance->pdev, PCI_COMMAND, &pci_reg); in pmcraid_reset_alert()
656 cmd->time_left = PMCRAID_RESET_TIMEOUT; in pmcraid_reset_alert()
657 cmd->timer.expires = jiffies + PMCRAID_CHECK_FOR_RESET_TIMEOUT; in pmcraid_reset_alert()
658 cmd->timer.function = pmcraid_reset_alert_done; in pmcraid_reset_alert()
659 add_timer(&cmd->timer); in pmcraid_reset_alert()
662 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_reset_alert()
664 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_reset_alert()
668 pinstance->ioa_state = IOA_STATE_IN_HARD_RESET; in pmcraid_reset_alert()
674 * pmcraid_timeout_handler - Timeout handler for internally generated ops
686 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_timeout_handler()
689 dev_info(&pinstance->pdev->dev, in pmcraid_timeout_handler()
691 cmd->ioa_cb->ioarcb.cdb[0]); in pmcraid_timeout_handler()
699 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_timeout_handler()
700 if (!pinstance->ioa_reset_in_progress) { in pmcraid_timeout_handler()
701 pinstance->ioa_reset_attempts = 0; in pmcraid_timeout_handler()
708 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_timeout_handler()
714 pinstance->reset_cmd = cmd; in pmcraid_timeout_handler()
715 pinstance->ioa_reset_in_progress = 1; in pmcraid_timeout_handler()
719 if (pinstance->reset_cmd != cmd) { in pmcraid_timeout_handler()
732 if (cmd == pinstance->reset_cmd) in pmcraid_timeout_handler()
733 cmd->cmd_done = pmcraid_ioa_reset; in pmcraid_timeout_handler()
737 if (pinstance->scn.ioa_state != PMC_DEVICE_EVENT_RESET_START && in pmcraid_timeout_handler()
738 pinstance->scn.ioa_state != PMC_DEVICE_EVENT_SHUTDOWN_START) in pmcraid_timeout_handler()
742 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_timeout_handler()
743 scsi_block_requests(pinstance->host); in pmcraid_timeout_handler()
745 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_timeout_handler()
749 * pmcraid_internal_done - completion routine for internally generated cmds
759 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_internal_done()
760 le32_to_cpu(cmd->ioa_cb->ioasa.ioasc)); in pmcraid_internal_done()
763 * response. Same will be indicated as part of cmd->completion_req in pmcraid_internal_done()
767 if (cmd->completion_req) { in pmcraid_internal_done()
768 cmd->completion_req = 0; in pmcraid_internal_done()
769 complete(&cmd->wait_for_completion); in pmcraid_internal_done()
776 if (cmd->release) { in pmcraid_internal_done()
777 cmd->release = 0; in pmcraid_internal_done()
783 * pmcraid_reinit_cfgtable_done - done function for cfg table reinitialization
787 * This routine is called after driver re-reads configuration table due to a
797 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_reinit_cfgtable_done()
798 le32_to_cpu(cmd->ioa_cb->ioasa.ioasc)); in pmcraid_reinit_cfgtable_done()
800 if (cmd->release) { in pmcraid_reinit_cfgtable_done()
801 cmd->release = 0; in pmcraid_reinit_cfgtable_done()
805 schedule_work(&cmd->drv_inst->worker_q); in pmcraid_reinit_cfgtable_done()
809 * pmcraid_erp_done - Process completion of SCSI error response from device
820 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_erp_done()
821 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_erp_done()
822 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_erp_done()
825 scsi_cmd->result |= (DID_ERROR << 16); in pmcraid_erp_done()
828 cmd->ioa_cb->ioarcb.cdb[0], ioasc); in pmcraid_erp_done()
831 if (cmd->sense_buffer) { in pmcraid_erp_done()
832 dma_unmap_single(&pinstance->pdev->dev, cmd->sense_buffer_dma, in pmcraid_erp_done()
834 cmd->sense_buffer = NULL; in pmcraid_erp_done()
835 cmd->sense_buffer_dma = 0; in pmcraid_erp_done()
844 * _pmcraid_fire_command - sends an IOA command to adapter
856 struct pmcraid_instance *pinstance = cmd->drv_inst; in _pmcraid_fire_command()
864 spin_lock_irqsave(&pinstance->pending_pool_lock, lock_flags); in _pmcraid_fire_command()
865 list_add_tail(&cmd->free_list, &pinstance->pending_cmd_pool); in _pmcraid_fire_command()
866 spin_unlock_irqrestore(&pinstance->pending_pool_lock, lock_flags); in _pmcraid_fire_command()
867 atomic_inc(&pinstance->outstanding_cmds); in _pmcraid_fire_command()
869 /* driver writes lower 32-bit value of IOARCB address only */ in _pmcraid_fire_command()
871 iowrite32(le64_to_cpu(cmd->ioa_cb->ioarcb.ioarcb_bus_addr), pinstance->ioarrin); in _pmcraid_fire_command()
875 * pmcraid_send_cmd - fires a command to IOA
896 cmd->cmd_done = cmd_done; in pmcraid_send_cmd()
900 cmd->timer.expires = jiffies + timeout; in pmcraid_send_cmd()
901 cmd->timer.function = timeout_func; in pmcraid_send_cmd()
902 add_timer(&cmd->timer); in pmcraid_send_cmd()
910 * pmcraid_ioa_shutdown_done - completion function for IOA shutdown command
918 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_ioa_shutdown_done()
921 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_ioa_shutdown_done()
923 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_ioa_shutdown_done()
927 * pmcraid_ioa_shutdown - sends SHUTDOWN command to ioa
937 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_ioa_shutdown()
938 le32_to_cpu(cmd->ioa_cb->ioasa.ioasc)); in pmcraid_ioa_shutdown()
944 cmd->ioa_cb->ioarcb.request_type = REQ_TYPE_IOACMD; in pmcraid_ioa_shutdown()
945 cmd->ioa_cb->ioarcb.resource_handle = in pmcraid_ioa_shutdown()
947 cmd->ioa_cb->ioarcb.cdb[0] = PMCRAID_IOA_SHUTDOWN; in pmcraid_ioa_shutdown()
948 cmd->ioa_cb->ioarcb.cdb[1] = PMCRAID_SHUTDOWN_NORMAL; in pmcraid_ioa_shutdown()
952 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle)); in pmcraid_ioa_shutdown()
954 pmcraid_notify_ioastate(cmd->drv_inst, PMC_DEVICE_EVENT_SHUTDOWN_START); in pmcraid_ioa_shutdown()
963 * pmcraid_get_fwversion_done - completion function for get_fwversion
972 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_get_fwversion_done()
973 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_get_fwversion_done()
982 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_get_fwversion_done()
983 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_get_fwversion_done()
985 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_get_fwversion_done()
992 * pmcraid_get_fwversion - reads firmware version information
1001 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_get_fwversion()
1003 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_get_fwversion()
1007 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_get_fwversion()
1008 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_get_fwversion()
1009 ioarcb->cdb[0] = INQUIRY; in pmcraid_get_fwversion()
1010 ioarcb->cdb[1] = 1; in pmcraid_get_fwversion()
1011 ioarcb->cdb[2] = 0xD0; in pmcraid_get_fwversion()
1012 ioarcb->cdb[3] = (data_size >> 8) & 0xFF; in pmcraid_get_fwversion()
1013 ioarcb->cdb[4] = data_size & 0xFF; in pmcraid_get_fwversion()
1017 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_get_fwversion()
1020 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_get_fwversion()
1021 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL)); in pmcraid_get_fwversion()
1023 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_get_fwversion()
1024 ioarcb->data_transfer_length = cpu_to_le32(data_size); in pmcraid_get_fwversion()
1025 ioadl = &(ioarcb->add_data.u.ioadl[0]); in pmcraid_get_fwversion()
1026 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_get_fwversion()
1027 ioadl->address = cpu_to_le64(pinstance->inq_data_baddr); in pmcraid_get_fwversion()
1028 ioadl->data_len = cpu_to_le32(data_size); in pmcraid_get_fwversion()
1035 * pmcraid_identify_hrrq - registers host rrq buffers with IOA
1043 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_identify_hrrq()
1044 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_identify_hrrq()
1045 int index = cmd->hrrq_index; in pmcraid_identify_hrrq()
1046 __be64 hrrq_addr = cpu_to_be64(pinstance->hrrq_start_bus_addr[index]); in pmcraid_identify_hrrq()
1051 cmd->hrrq_index = index + 1; in pmcraid_identify_hrrq()
1053 if (cmd->hrrq_index < pinstance->num_hrrq) { in pmcraid_identify_hrrq()
1056 cmd->hrrq_index = 0; in pmcraid_identify_hrrq()
1061 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_identify_hrrq()
1062 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_identify_hrrq()
1065 ioarcb->hrrq_id = index; in pmcraid_identify_hrrq()
1066 ioarcb->cdb[0] = PMCRAID_IDENTIFY_HRRQ; in pmcraid_identify_hrrq()
1067 ioarcb->cdb[1] = index; in pmcraid_identify_hrrq()
1069 /* IOA expects 64-bit pci address to be written in B.E format in pmcraid_identify_hrrq()
1073 hrrq_addr, ioarcb->ioarcb_bus_addr, index); in pmcraid_identify_hrrq()
1075 memcpy(&(ioarcb->cdb[2]), &hrrq_addr, sizeof(hrrq_addr)); in pmcraid_identify_hrrq()
1076 memcpy(&(ioarcb->cdb[10]), &hrrq_size, sizeof(hrrq_size)); in pmcraid_identify_hrrq()
1079 * Note that this gets called even during reset from SCSI mid-layer in pmcraid_identify_hrrq()
1091 * pmcraid_send_hcam_cmd - send an initialized command block(HCAM) to IOA
1100 if (cmd->ioa_cb->ioarcb.cdb[1] == PMCRAID_HCAM_CODE_CONFIG_CHANGE) in pmcraid_send_hcam_cmd()
1101 atomic_set(&(cmd->drv_inst->ccn.ignore), 0); in pmcraid_send_hcam_cmd()
1103 atomic_set(&(cmd->drv_inst->ldn.ignore), 0); in pmcraid_send_hcam_cmd()
1105 pmcraid_send_cmd(cmd, cmd->cmd_done, 0, NULL); in pmcraid_send_hcam_cmd()
1109 * pmcraid_init_hcam - send an initialized command block(HCAM) to IOA
1141 dma = pinstance->ccn.baddr + PMCRAID_AEN_HDR_SIZE; in pmcraid_init_hcam()
1142 hcam = &pinstance->ccn; in pmcraid_init_hcam()
1146 dma = pinstance->ldn.baddr + PMCRAID_AEN_HDR_SIZE; in pmcraid_init_hcam()
1147 hcam = &pinstance->ldn; in pmcraid_init_hcam()
1151 hcam->cmd = cmd; in pmcraid_init_hcam()
1153 ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_init_hcam()
1154 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_init_hcam()
1157 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_init_hcam()
1158 ioadl = ioarcb->add_data.u.ioadl; in pmcraid_init_hcam()
1161 ioarcb->request_type = REQ_TYPE_HCAM; in pmcraid_init_hcam()
1162 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_init_hcam()
1163 ioarcb->cdb[0] = PMCRAID_HOST_CONTROLLED_ASYNC; in pmcraid_init_hcam()
1164 ioarcb->cdb[1] = type; in pmcraid_init_hcam()
1165 ioarcb->cdb[7] = (rcb_size >> 8) & 0xFF; in pmcraid_init_hcam()
1166 ioarcb->cdb[8] = (rcb_size) & 0xFF; in pmcraid_init_hcam()
1168 ioarcb->data_transfer_length = cpu_to_le32(rcb_size); in pmcraid_init_hcam()
1174 cmd->cmd_done = cmd_done; in pmcraid_init_hcam()
1179 * pmcraid_send_hcam - Send an HCAM to IOA
1196 * pmcraid_prepare_cancel_cmd - prepares a command block to abort another
1206 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_prepare_cancel_cmd()
1210 * cdb[2]..cdb[9] is Big-Endian format. Note that length bits in in pmcraid_prepare_cancel_cmd()
1213 ioarcb_addr = cpu_to_be64(le64_to_cpu(cmd_to_cancel->ioa_cb->ioarcb.ioarcb_bus_addr)); in pmcraid_prepare_cancel_cmd()
1218 ioarcb->resource_handle = cmd_to_cancel->ioa_cb->ioarcb.resource_handle; in pmcraid_prepare_cancel_cmd()
1219 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_prepare_cancel_cmd()
1220 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_prepare_cancel_cmd()
1221 ioarcb->cdb[0] = PMCRAID_ABORT_CMD; in pmcraid_prepare_cancel_cmd()
1223 memcpy(&(ioarcb->cdb[2]), &ioarcb_addr, sizeof(ioarcb_addr)); in pmcraid_prepare_cancel_cmd()
1227 * pmcraid_cancel_hcam - sends ABORT task to abort a given HCAM
1242 pinstance = cmd->drv_inst; in pmcraid_cancel_hcam()
1244 &pinstance->ldn : &pinstance->ccn; in pmcraid_cancel_hcam()
1247 * currently not pending with IOA, we would have hcam->cmd as non-null in pmcraid_cancel_hcam()
1249 if (hcam->cmd == NULL) in pmcraid_cancel_hcam()
1252 pmcraid_prepare_cancel_cmd(cmd, hcam->cmd); in pmcraid_cancel_hcam()
1254 /* writing to IOARRIN must be protected by host_lock, as mid-layer in pmcraid_cancel_hcam()
1263 * pmcraid_cancel_ccn - cancel CCN HCAM already registered with IOA
1270 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_cancel_ccn()
1271 le32_to_cpu(cmd->ioa_cb->ioasa.ioasc)); in pmcraid_cancel_ccn()
1281 * pmcraid_cancel_ldn - cancel LDN HCAM already registered with IOA
1293 * pmcraid_expose_resource - check if the resource can be exposed to OS
1306 if (cfgte->resource_type == RES_TYPE_VSET) { in pmcraid_expose_resource()
1308 retval = ((cfgte->unique_flags1 & 0x80) == 0); in pmcraid_expose_resource()
1310 retval = ((cfgte->unique_flags0 & 0x80) == 0 && in pmcraid_expose_resource()
1311 (cfgte->unique_flags1 & 0x80) == 0); in pmcraid_expose_resource()
1313 } else if (cfgte->resource_type == RES_TYPE_GSCSI) in pmcraid_expose_resource()
1314 retval = (RES_BUS(cfgte->resource_address) != in pmcraid_expose_resource()
1325 #define PMCRAID_AEN_ATTR_MAX (__PMCRAID_AEN_ATTR_MAX - 1)
1333 #define PMCRAID_AEN_CMD_MAX (__PMCRAID_AEN_CMD_MAX - 1)
1336 { .name = "events", /* not really used - see ID discussion below */ },
1349 * pmcraid_netlink_init - registers pmcraid_event_family
1353 * with netlink generic, non-zero otherwise
1371 * pmcraid_netlink_release - unregisters pmcraid_event_family
1382 * pmcraid_notify_aen - sends event msg to user space application
1398 aen_msg->hostno = (pinstance->host->unique_id << 16 | in pmcraid_notify_aen()
1399 MINOR(pinstance->cdev.dev)); in pmcraid_notify_aen()
1400 aen_msg->length = data_size; in pmcraid_notify_aen()
1408 ((struct genl_family *)&pmcraid_event_family)->hdrsize) in pmcraid_notify_aen()
1416 return -ENOMEM; in pmcraid_notify_aen()
1426 return -ENOMEM; in pmcraid_notify_aen()
1434 return -EINVAL; in pmcraid_notify_aen()
1443 /* If there are no listeners, genlmsg_multicast may return non-zero in pmcraid_notify_aen()
1452 * pmcraid_notify_ccn - notifies about CCN event msg to user space
1461 pinstance->ccn.msg, in pmcraid_notify_ccn()
1462 le32_to_cpu(pinstance->ccn.hcam->data_len) + in pmcraid_notify_ccn()
1467 * pmcraid_notify_ldn - notifies about CCN event msg to user space
1476 pinstance->ldn.msg, in pmcraid_notify_ldn()
1477 le32_to_cpu(pinstance->ldn.hcam->data_len) + in pmcraid_notify_ldn()
1482 * pmcraid_notify_ioastate - sends IOA state event msg to user space
1491 pinstance->scn.ioa_state = evt; in pmcraid_notify_ioastate()
1493 &pinstance->scn.msg, in pmcraid_notify_ioastate()
1498 * pmcraid_handle_config_change - Handle a config change from the adapter
1519 ccn_hcam = (struct pmcraid_hcam_ccn *)pinstance->ccn.hcam; in pmcraid_handle_config_change()
1520 cfg_entry = &ccn_hcam->cfg_entry; in pmcraid_handle_config_change()
1521 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_handle_config_change()
1525 le32_to_cpu(pinstance->ccn.hcam->ilid), in pmcraid_handle_config_change()
1526 pinstance->ccn.hcam->op_code, in pmcraid_handle_config_change()
1527 (le32_to_cpu(pinstance->ccn.hcam->timestamp1) | in pmcraid_handle_config_change()
1528 ((le32_to_cpu(pinstance->ccn.hcam->timestamp2) & 0xffffffffLL) << 32)), in pmcraid_handle_config_change()
1529 pinstance->ccn.hcam->notification_type, in pmcraid_handle_config_change()
1530 pinstance->ccn.hcam->notification_lost, in pmcraid_handle_config_change()
1531 pinstance->ccn.hcam->flags, in pmcraid_handle_config_change()
1532 pinstance->host->unique_id, in pmcraid_handle_config_change()
1535 RES_BUS(cfg_entry->resource_address)), in pmcraid_handle_config_change()
1538 cfg_entry->unique_flags1 : in pmcraid_handle_config_change()
1539 le16_to_cpu(cfg_entry->array_id) & 0xFF) : in pmcraid_handle_config_change()
1540 RES_TARGET(cfg_entry->resource_address), in pmcraid_handle_config_change()
1541 RES_LUN(cfg_entry->resource_address)); in pmcraid_handle_config_change()
1545 if (pinstance->ccn.hcam->notification_lost) { in pmcraid_handle_config_change()
1549 pinstance->reinit_cfg_table = 1; in pmcraid_handle_config_change()
1557 /* If this resource is not going to be added to mid-layer, just notify in pmcraid_handle_config_change()
1561 if (pinstance->ccn.hcam->notification_type == in pmcraid_handle_config_change()
1563 cfg_entry->resource_type == RES_TYPE_VSET) { in pmcraid_handle_config_change()
1564 hidden_entry = (cfg_entry->unique_flags1 & 0x80) != 0; in pmcraid_handle_config_change()
1569 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_handle_config_change()
1570 list_for_each_entry(res, &pinstance->used_res_q, queue) { in pmcraid_handle_config_change()
1571 rc = memcmp(&res->cfg_entry.resource_address, in pmcraid_handle_config_change()
1572 &cfg_entry->resource_address, in pmcraid_handle_config_change()
1573 sizeof(cfg_entry->resource_address)); in pmcraid_handle_config_change()
1583 spin_unlock_irqrestore(&pinstance->resource_lock, in pmcraid_handle_config_change()
1590 * ignore this notifications and re-register the same HCAM in pmcraid_handle_config_change()
1592 if (list_empty(&pinstance->free_res_q)) { in pmcraid_handle_config_change()
1593 spin_unlock_irqrestore(&pinstance->resource_lock, in pmcraid_handle_config_change()
1596 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_handle_config_change()
1600 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_handle_config_change()
1605 res = list_entry(pinstance->free_res_q.next, in pmcraid_handle_config_change()
1608 list_del(&res->queue); in pmcraid_handle_config_change()
1609 res->scsi_dev = NULL; in pmcraid_handle_config_change()
1610 res->reset_progress = 0; in pmcraid_handle_config_change()
1611 list_add_tail(&res->queue, &pinstance->used_res_q); in pmcraid_handle_config_change()
1614 memcpy(&res->cfg_entry, cfg_entry, pinstance->config_table_entry_size); in pmcraid_handle_config_change()
1616 if (pinstance->ccn.hcam->notification_type == in pmcraid_handle_config_change()
1618 if (res->scsi_dev) { in pmcraid_handle_config_change()
1620 res->cfg_entry.unique_flags1 &= 0x7F; in pmcraid_handle_config_change()
1622 res->cfg_entry.array_id &= cpu_to_le16(0xFF); in pmcraid_handle_config_change()
1623 res->change_detected = RES_CHANGE_DEL; in pmcraid_handle_config_change()
1624 res->cfg_entry.resource_handle = in pmcraid_handle_config_change()
1626 schedule_work(&pinstance->worker_q); in pmcraid_handle_config_change()
1628 /* This may be one of the non-exposed resources */ in pmcraid_handle_config_change()
1629 list_move_tail(&res->queue, &pinstance->free_res_q); in pmcraid_handle_config_change()
1631 } else if (!res->scsi_dev) { in pmcraid_handle_config_change()
1632 res->change_detected = RES_CHANGE_ADD; in pmcraid_handle_config_change()
1633 schedule_work(&pinstance->worker_q); in pmcraid_handle_config_change()
1635 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_handle_config_change()
1649 * pmcraid_get_error_info - return error string for an ioasc
1665 * pmcraid_ioasc_logger - log IOASC information based user-settings
1674 cmd->drv_inst->current_log_level < error_info->log_level) in pmcraid_ioasc_logger()
1679 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_ioasc_logger()
1680 le32_to_cpu(cmd->ioa_cb->ioarcb.resource_handle), in pmcraid_ioasc_logger()
1681 ioasc, error_info->error_string); in pmcraid_ioasc_logger()
1685 * pmcraid_handle_error_log - Handle a config change (error log) from the IOA
1697 hcam_ldn = (struct pmcraid_hcam_ldn *)pinstance->ldn.hcam; in pmcraid_handle_error_log()
1701 pinstance->ldn.hcam->ilid, in pmcraid_handle_error_log()
1702 pinstance->ldn.hcam->op_code, in pmcraid_handle_error_log()
1703 pinstance->ldn.hcam->notification_type, in pmcraid_handle_error_log()
1704 pinstance->ldn.hcam->notification_lost, in pmcraid_handle_error_log()
1705 pinstance->ldn.hcam->flags, in pmcraid_handle_error_log()
1706 pinstance->ldn.hcam->overlay_id); in pmcraid_handle_error_log()
1709 if (pinstance->ldn.hcam->notification_type != in pmcraid_handle_error_log()
1713 if (pinstance->ldn.hcam->notification_lost == in pmcraid_handle_error_log()
1715 dev_info(&pinstance->pdev->dev, "Error notifications lost\n"); in pmcraid_handle_error_log()
1717 ioasc = le32_to_cpu(hcam_ldn->error_log.fd_ioasc); in pmcraid_handle_error_log()
1721 dev_info(&pinstance->pdev->dev, in pmcraid_handle_error_log()
1724 pinstance->host, in pmcraid_handle_error_log()
1725 RES_BUS(hcam_ldn->error_log.fd_ra)); in pmcraid_handle_error_log()
1732 * pmcraid_process_ccn - Op done function for a CCN.
1743 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_process_ccn()
1744 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_process_ccn()
1747 pinstance->ccn.cmd = NULL; in pmcraid_process_ccn()
1752 * re-register the hcam in pmcraid_process_ccn()
1755 atomic_read(&pinstance->ccn.ignore) == 1) { in pmcraid_process_ccn()
1758 dev_info(&pinstance->pdev->dev, in pmcraid_process_ccn()
1760 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_process_ccn()
1762 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_process_ccn()
1771 * pmcraid_process_ldn - op done function for an LDN
1779 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_process_ldn()
1781 (struct pmcraid_hcam_ldn *)pinstance->ldn.hcam; in pmcraid_process_ldn()
1782 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_process_ldn()
1783 u32 fd_ioasc = le32_to_cpu(ldn_hcam->error_log.fd_ioasc); in pmcraid_process_ldn()
1787 pinstance->ldn.cmd = NULL; in pmcraid_process_ldn()
1791 * with IOA, no need to re-register the hcam as reset engine will do it in pmcraid_process_ldn()
1795 atomic_read(&pinstance->ccn.ignore) == 1) { in pmcraid_process_ldn()
1800 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_process_ldn()
1803 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_process_ldn()
1808 pinstance->timestamp_error = 1; in pmcraid_process_ldn()
1812 dev_info(&pinstance->pdev->dev, in pmcraid_process_ldn()
1825 * pmcraid_register_hcams - register HCAMs for CCN and LDN
1839 * pmcraid_unregister_hcams - cancel HCAMs registered already
1844 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_unregister_hcams()
1848 * prevent this, set 'ignore', so that bring-down sequence doesn't in pmcraid_unregister_hcams()
1849 * re-send any more hcams in pmcraid_unregister_hcams()
1851 atomic_set(&pinstance->ccn.ignore, 1); in pmcraid_unregister_hcams()
1852 atomic_set(&pinstance->ldn.ignore, 1); in pmcraid_unregister_hcams()
1858 if ((pinstance->force_ioa_reset && !pinstance->ioa_bringdown) || in pmcraid_unregister_hcams()
1859 pinstance->ioa_unit_check) { in pmcraid_unregister_hcams()
1860 pinstance->force_ioa_reset = 0; in pmcraid_unregister_hcams()
1861 pinstance->ioa_unit_check = 0; in pmcraid_unregister_hcams()
1862 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_unregister_hcams()
1877 * pmcraid_reset_enable_ioa - re-enable IOA after a hard reset
1892 if (!pinstance->interrupt_mode) { in pmcraid_reset_enable_ioa()
1894 pinstance->int_regs. in pmcraid_reset_enable_ioa()
1897 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_reset_enable_ioa()
1906 * pmcraid_soft_reset - performs a soft reset and makes IOA become ready
1914 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_soft_reset()
1920 * would re-initiate a reset in pmcraid_soft_reset()
1922 cmd->cmd_done = pmcraid_ioa_reset; in pmcraid_soft_reset()
1923 cmd->timer.expires = jiffies + in pmcraid_soft_reset()
1925 cmd->timer.function = pmcraid_timeout_handler; in pmcraid_soft_reset()
1927 if (!timer_pending(&cmd->timer)) in pmcraid_soft_reset()
1928 add_timer(&cmd->timer); in pmcraid_soft_reset()
1939 if (pinstance->interrupt_mode) { in pmcraid_soft_reset()
1941 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_soft_reset()
1942 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_soft_reset()
1945 iowrite32(doorbell, pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_soft_reset()
1946 ioread32(pinstance->int_regs.host_ioa_interrupt_reg), in pmcraid_soft_reset()
1947 int_reg = ioread32(pinstance->int_regs.ioa_host_interrupt_reg); in pmcraid_soft_reset()
1950 ioread32(pinstance->int_regs.host_ioa_interrupt_reg), in pmcraid_soft_reset()
1955 * pmcraid_get_dump - retrieves IOA dump in case of Unit Check interrupt
1968 * pmcraid_fail_outstanding_cmds - Fails all outstanding ops.
1987 spin_lock_irqsave(&pinstance->pending_pool_lock, lock_flags); in pmcraid_fail_outstanding_cmds()
1988 list_for_each_entry_safe(cmd, temp, &pinstance->pending_cmd_pool, in pmcraid_fail_outstanding_cmds()
1990 list_del(&cmd->free_list); in pmcraid_fail_outstanding_cmds()
1991 spin_unlock_irqrestore(&pinstance->pending_pool_lock, in pmcraid_fail_outstanding_cmds()
1993 cmd->ioa_cb->ioasa.ioasc = in pmcraid_fail_outstanding_cmds()
1995 cmd->ioa_cb->ioasa.ilid = in pmcraid_fail_outstanding_cmds()
1999 del_timer(&cmd->timer); in pmcraid_fail_outstanding_cmds()
2006 if (cmd->scsi_cmd) { in pmcraid_fail_outstanding_cmds()
2008 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_fail_outstanding_cmds()
2009 __le32 resp = cmd->ioa_cb->ioarcb.response_handle; in pmcraid_fail_outstanding_cmds()
2011 scsi_cmd->result |= DID_ERROR << 16; in pmcraid_fail_outstanding_cmds()
2018 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_fail_outstanding_cmds()
2019 scsi_cmd->result); in pmcraid_fail_outstanding_cmds()
2021 } else if (cmd->cmd_done == pmcraid_internal_done || in pmcraid_fail_outstanding_cmds()
2022 cmd->cmd_done == pmcraid_erp_done) { in pmcraid_fail_outstanding_cmds()
2023 cmd->cmd_done(cmd); in pmcraid_fail_outstanding_cmds()
2024 } else if (cmd->cmd_done != pmcraid_ioa_reset && in pmcraid_fail_outstanding_cmds()
2025 cmd->cmd_done != pmcraid_ioa_shutdown_done) { in pmcraid_fail_outstanding_cmds()
2029 atomic_dec(&pinstance->outstanding_cmds); in pmcraid_fail_outstanding_cmds()
2030 spin_lock_irqsave(&pinstance->pending_pool_lock, lock_flags); in pmcraid_fail_outstanding_cmds()
2033 spin_unlock_irqrestore(&pinstance->pending_pool_lock, lock_flags); in pmcraid_fail_outstanding_cmds()
2037 * pmcraid_ioa_reset - Implementation of IOA reset logic
2053 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_ioa_reset()
2056 pinstance->ioa_reset_in_progress = 1; in pmcraid_ioa_reset()
2058 if (pinstance->reset_cmd != cmd) { in pmcraid_ioa_reset()
2060 pinstance->reset_cmd = cmd; in pmcraid_ioa_reset()
2064 pinstance->ioa_state, cmd); in pmcraid_ioa_reset()
2066 switch (pinstance->ioa_state) { in pmcraid_ioa_reset()
2080 * goes through hard-reset in pmcraid_ioa_reset()
2083 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_ioa_reset()
2088 /* We may be called during probe or resume. Some pre-processing in pmcraid_ioa_reset()
2091 scsi_block_requests(pinstance->host); in pmcraid_ioa_reset()
2095 * hard-reset. in pmcraid_ioa_reset()
2097 if (pinstance->ioa_hard_reset == 0) { in pmcraid_ioa_reset()
2098 if (ioread32(pinstance->ioa_status) & in pmcraid_ioa_reset()
2100 pmcraid_info("sticky bit set, bring-up\n"); in pmcraid_ioa_reset()
2101 pinstance->ioa_state = IOA_STATE_IN_BRINGUP; in pmcraid_ioa_reset()
2105 pinstance->ioa_state = IOA_STATE_IN_SOFT_RESET; in pmcraid_ioa_reset()
2112 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_ioa_reset()
2123 pinstance->ioa_state = IOA_STATE_IN_HARD_RESET; in pmcraid_ioa_reset()
2128 pinstance->ioa_reset_attempts++; in pmcraid_ioa_reset()
2131 if (pinstance->ioa_reset_attempts > PMCRAID_RESET_ATTEMPTS) { in pmcraid_ioa_reset()
2132 pinstance->ioa_reset_attempts = 0; in pmcraid_ioa_reset()
2134 pinstance->ioa_state = IOA_STATE_DEAD; in pmcraid_ioa_reset()
2136 if (pinstance->ioa_bringdown) in pmcraid_ioa_reset()
2149 pci_restore_state(pinstance->pdev); in pmcraid_ioa_reset()
2155 if (pinstance->ioa_unit_check) { in pmcraid_ioa_reset()
2157 pinstance->ioa_unit_check = 0; in pmcraid_ioa_reset()
2159 pinstance->ioa_reset_attempts--; in pmcraid_ioa_reset()
2160 pinstance->ioa_state = IOA_STATE_IN_RESET_ALERT; in pmcraid_ioa_reset()
2165 /* if the reset reason is to bring-down the ioa, we might be in pmcraid_ioa_reset()
2169 if (pinstance->ioa_bringdown) { in pmcraid_ioa_reset()
2171 pinstance->ioa_shutdown_type = SHUTDOWN_NONE; in pmcraid_ioa_reset()
2172 pinstance->ioa_bringdown = 0; in pmcraid_ioa_reset()
2173 pinstance->ioa_state = IOA_STATE_UNKNOWN; in pmcraid_ioa_reset()
2178 /* bring-up IOA, so proceed with soft reset in pmcraid_ioa_reset()
2183 pinstance->ioa_state = IOA_STATE_IN_BRINGUP; in pmcraid_ioa_reset()
2188 pinstance->ioa_state = IOA_STATE_IN_SOFT_RESET; in pmcraid_ioa_reset()
2198 pmcraid_info("In softreset proceeding with bring-up\n"); in pmcraid_ioa_reset()
2199 pinstance->ioa_state = IOA_STATE_IN_BRINGUP; in pmcraid_ioa_reset()
2212 pinstance->ioa_state = IOA_STATE_OPERATIONAL; in pmcraid_ioa_reset()
2223 if (pinstance->ioa_shutdown_type == SHUTDOWN_NONE && in pmcraid_ioa_reset()
2224 pinstance->force_ioa_reset == 0) { in pmcraid_ioa_reset()
2229 if (pinstance->ioa_shutdown_type != SHUTDOWN_NONE) in pmcraid_ioa_reset()
2230 pinstance->ioa_state = IOA_STATE_IN_BRINGDOWN; in pmcraid_ioa_reset()
2239 * any waiting threads and let the SCSI mid-layer send commands. Note in pmcraid_ioa_reset()
2243 pinstance->ioa_reset_in_progress = 0; in pmcraid_ioa_reset()
2244 pinstance->ioa_reset_attempts = 0; in pmcraid_ioa_reset()
2245 pinstance->reset_cmd = NULL; in pmcraid_ioa_reset()
2246 pinstance->ioa_shutdown_type = SHUTDOWN_NONE; in pmcraid_ioa_reset()
2247 pinstance->ioa_bringdown = 0; in pmcraid_ioa_reset()
2251 * hcam registration and resource exposure to mid-layer. in pmcraid_ioa_reset()
2253 if (pinstance->ioa_state == IOA_STATE_OPERATIONAL) in pmcraid_ioa_reset()
2256 wake_up_all(&pinstance->reset_wait_q); in pmcraid_ioa_reset()
2263 * pmcraid_initiate_reset - initiates reset sequence. This is called from
2280 if (!pinstance->ioa_reset_in_progress) { in pmcraid_initiate_reset()
2281 scsi_block_requests(pinstance->host); in pmcraid_initiate_reset()
2289 pinstance->ioa_shutdown_type = SHUTDOWN_NONE; in pmcraid_initiate_reset()
2290 pinstance->reset_cmd = cmd; in pmcraid_initiate_reset()
2291 pinstance->force_ioa_reset = 1; in pmcraid_initiate_reset()
2299 * pmcraid_reset_reload - utility routine for doing IOA reset either to bringup
2322 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2324 if (pinstance->ioa_reset_in_progress) { in pmcraid_reset_reload()
2327 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2329 wait_event(pinstance->reset_wait_q, in pmcraid_reset_reload()
2330 !pinstance->ioa_reset_in_progress); in pmcraid_reset_reload()
2332 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2334 if (pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_reset_reload()
2339 if (pinstance->ioa_state == target_state) { in pmcraid_reset_reload()
2346 scsi_block_requests(pinstance->host); in pmcraid_reset_reload()
2354 pinstance->ioa_bringdown = 1; in pmcraid_reset_reload()
2356 pinstance->ioa_shutdown_type = shutdown_type; in pmcraid_reset_reload()
2357 pinstance->reset_cmd = reset_cmd; in pmcraid_reset_reload()
2358 pinstance->force_ioa_reset = reset; in pmcraid_reset_reload()
2361 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2363 wait_event(pinstance->reset_wait_q, in pmcraid_reset_reload()
2364 !pinstance->ioa_reset_in_progress); in pmcraid_reset_reload()
2367 scsi_unblock_requests(pinstance->host); in pmcraid_reset_reload()
2368 return pinstance->ioa_state != target_state; in pmcraid_reset_reload()
2371 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_reload()
2376 * pmcraid_reset_bringdown - wrapper over pmcraid_reset_reload to bringdown IOA
2391 * pmcraid_reset_bringup - wrapper over pmcraid_reset_reload to bring up IOA
2408 * pmcraid_request_sense - Send request sense to a device
2412 * condition. This method re-uses the same command block that failed earlier.
2416 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_request_sense()
2417 struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl; in pmcraid_request_sense()
2418 struct device *dev = &cmd->drv_inst->pdev->dev; in pmcraid_request_sense()
2420 cmd->sense_buffer = cmd->scsi_cmd->sense_buffer; in pmcraid_request_sense()
2421 cmd->sense_buffer_dma = dma_map_single(dev, cmd->sense_buffer, in pmcraid_request_sense()
2423 if (dma_mapping_error(dev, cmd->sense_buffer_dma)) { in pmcraid_request_sense()
2430 /* re-use the command block */ in pmcraid_request_sense()
2431 memset(&cmd->ioa_cb->ioasa, 0, sizeof(struct pmcraid_ioasa)); in pmcraid_request_sense()
2432 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_request_sense()
2433 ioarcb->request_flags0 = (SYNC_COMPLETE | in pmcraid_request_sense()
2436 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_request_sense()
2437 ioarcb->cdb[0] = REQUEST_SENSE; in pmcraid_request_sense()
2438 ioarcb->cdb[4] = SCSI_SENSE_BUFFERSIZE; in pmcraid_request_sense()
2440 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_request_sense()
2443 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_request_sense()
2445 ioarcb->data_transfer_length = cpu_to_le32(SCSI_SENSE_BUFFERSIZE); in pmcraid_request_sense()
2447 ioadl->address = cpu_to_le64(cmd->sense_buffer_dma); in pmcraid_request_sense()
2448 ioadl->data_len = cpu_to_le32(SCSI_SENSE_BUFFERSIZE); in pmcraid_request_sense()
2449 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_request_sense()
2452 * which runs in tasklets context. It is possible that mid-layer might in pmcraid_request_sense()
2462 * pmcraid_cancel_all - cancel all outstanding IOARCBs as part of error recovery
2470 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_cancel_all()
2471 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_cancel_all()
2472 struct pmcraid_resource_entry *res = scsi_cmd->device->hostdata; in pmcraid_cancel_all()
2474 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN); in pmcraid_cancel_all()
2475 ioarcb->request_flags0 = SYNC_OVERRIDE; in pmcraid_cancel_all()
2476 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_cancel_all()
2477 ioarcb->cdb[0] = PMCRAID_CANCEL_ALL_REQUESTS; in pmcraid_cancel_all()
2479 if (RES_IS_GSCSI(res->cfg_entry)) in pmcraid_cancel_all()
2480 ioarcb->cdb[1] = PMCRAID_SYNC_COMPLETE_AFTER_CANCEL; in pmcraid_cancel_all()
2482 ioarcb->ioadl_bus_addr = 0; in pmcraid_cancel_all()
2483 ioarcb->ioadl_length = 0; in pmcraid_cancel_all()
2484 ioarcb->data_transfer_length = 0; in pmcraid_cancel_all()
2485 ioarcb->ioarcb_bus_addr &= cpu_to_le64((~0x1FULL)); in pmcraid_cancel_all()
2487 /* writing to IOARRIN must be protected by host_lock, as mid-layer in pmcraid_cancel_all()
2506 u8 *sense_buf = cmd->scsi_cmd->sense_buffer; in pmcraid_frame_auto_sense()
2507 struct pmcraid_resource_entry *res = cmd->scsi_cmd->device->hostdata; in pmcraid_frame_auto_sense()
2508 struct pmcraid_ioasa *ioasa = &cmd->ioa_cb->ioasa; in pmcraid_frame_auto_sense()
2509 u32 ioasc = le32_to_cpu(ioasa->ioasc); in pmcraid_frame_auto_sense()
2513 cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION; in pmcraid_frame_auto_sense()
2515 if (RES_IS_VSET(res->cfg_entry) && in pmcraid_frame_auto_sense()
2517 ioasa->u.vset.failing_lba_hi != 0) { in pmcraid_frame_auto_sense()
2529 failing_lba = le32_to_cpu(ioasa->u.vset.failing_lba_hi); in pmcraid_frame_auto_sense()
2536 failing_lba = le32_to_cpu(ioasa->u.vset.failing_lba_lo); in pmcraid_frame_auto_sense()
2549 if (RES_IS_VSET(res->cfg_entry)) in pmcraid_frame_auto_sense()
2551 le32_to_cpu(ioasa->u. in pmcraid_frame_auto_sense()
2565 * pmcraid_error_handler - Error response handlers for a SCSI op
2574 * back to free-pool
2578 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_error_handler()
2579 struct pmcraid_resource_entry *res = scsi_cmd->device->hostdata; in pmcraid_error_handler()
2580 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_error_handler()
2581 struct pmcraid_ioasa *ioasa = &cmd->ioa_cb->ioasa; in pmcraid_error_handler()
2582 u32 ioasc = le32_to_cpu(ioasa->ioasc); in pmcraid_error_handler()
2592 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD) in pmcraid_error_handler()
2593 atomic_inc(&res->read_failures); in pmcraid_error_handler()
2594 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD) in pmcraid_error_handler()
2595 atomic_inc(&res->write_failures); in pmcraid_error_handler()
2597 if (!RES_IS_GSCSI(res->cfg_entry) && in pmcraid_error_handler()
2608 scsi_cmd->result |= (DID_ABORT << 16); in pmcraid_error_handler()
2613 scsi_cmd->result |= (DID_NO_CONNECT << 16); in pmcraid_error_handler()
2617 res->sync_reqd = 1; in pmcraid_error_handler()
2618 scsi_cmd->result |= (DID_IMM_RETRY << 16); in pmcraid_error_handler()
2622 scsi_cmd->result |= (DID_PASSTHROUGH << 16); in pmcraid_error_handler()
2627 if (!res->reset_progress) in pmcraid_error_handler()
2628 scsi_report_bus_reset(pinstance->host, in pmcraid_error_handler()
2629 scsi_cmd->device->channel); in pmcraid_error_handler()
2630 scsi_cmd->result |= (DID_ERROR << 16); in pmcraid_error_handler()
2634 scsi_cmd->result |= PMCRAID_IOASC_SENSE_STATUS(ioasc); in pmcraid_error_handler()
2635 res->sync_reqd = 1; in pmcraid_error_handler()
2646 * mid-layer in pmcraid_error_handler()
2648 if (ioasa->auto_sense_length != 0) { in pmcraid_error_handler()
2649 short sense_len = le16_to_cpu(ioasa->auto_sense_length); in pmcraid_error_handler()
2653 memcpy(scsi_cmd->sense_buffer, in pmcraid_error_handler()
2654 ioasa->sense_data, in pmcraid_error_handler()
2659 if (RES_IS_GSCSI(res->cfg_entry)) in pmcraid_error_handler()
2673 scsi_cmd->result |= (DID_ERROR << 16); in pmcraid_error_handler()
2680 * pmcraid_reset_device - device reset handler functions
2706 (struct pmcraid_instance *)scsi_cmd->device->host->hostdata; in pmcraid_reset_device()
2707 res = scsi_cmd->device->hostdata; in pmcraid_reset_device()
2710 sdev_printk(KERN_ERR, scsi_cmd->device, in pmcraid_reset_device()
2716 * This will force the mid-layer to call _eh_bus/host reset, which in pmcraid_reset_device()
2719 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2720 if (pinstance->ioa_reset_in_progress || in pmcraid_reset_device()
2721 pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_reset_device()
2722 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2726 res->reset_progress = 1; in pmcraid_reset_device()
2730 le32_to_cpu(res->cfg_entry.resource_address)); in pmcraid_reset_device()
2736 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2741 ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_reset_device()
2742 ioarcb->resource_handle = res->cfg_entry.resource_handle; in pmcraid_reset_device()
2743 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_reset_device()
2744 ioarcb->cdb[0] = PMCRAID_RESET_DEVICE; in pmcraid_reset_device()
2750 ioarcb->cdb[1] = modifier; in pmcraid_reset_device()
2752 init_completion(&cmd->wait_for_completion); in pmcraid_reset_device()
2753 cmd->completion_req = 1; in pmcraid_reset_device()
2756 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_reset_device()
2757 le32_to_cpu(cmd->ioa_cb->ioarcb.resource_handle), in pmcraid_reset_device()
2758 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2); in pmcraid_reset_device()
2765 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_reset_device()
2771 wait_for_completion(&cmd->wait_for_completion); in pmcraid_reset_device()
2777 res->reset_progress = 0; in pmcraid_reset_device()
2778 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_reset_device()
2785 * _pmcraid_io_done - helper for pmcraid_io_done function
2791 * This function is invoked by pmcraid_io_done to complete mid-layer
2802 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in _pmcraid_io_done()
2808 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2, in _pmcraid_io_done()
2809 cmd->ioa_cb->ioarcb.cdb[0], in _pmcraid_io_done()
2810 ioasc, scsi_cmd->result); in _pmcraid_io_done()
2824 * pmcraid_io_done - SCSI completion function
2828 * This function is invoked by tasklet/mid-layer error handler to completing
2829 * the SCSI ops sent from mid-layer.
2837 u32 ioasc = le32_to_cpu(cmd->ioa_cb->ioasa.ioasc); in pmcraid_io_done()
2838 u32 reslen = le32_to_cpu(cmd->ioa_cb->ioasa.residual_data_length); in pmcraid_io_done()
2845 * pmcraid_abort_cmd - Aborts a single IOARCB already submitted to IOA
2857 pinstance = (struct pmcraid_instance *)cmd->drv_inst; in pmcraid_abort_cmd()
2869 cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_abort_cmd()
2870 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2); in pmcraid_abort_cmd()
2872 init_completion(&cancel_cmd->wait_for_completion); in pmcraid_abort_cmd()
2873 cancel_cmd->completion_req = 1; in pmcraid_abort_cmd()
2876 le32_to_cpu(cancel_cmd->ioa_cb->ioarcb.response_handle) >> 2, in pmcraid_abort_cmd()
2877 cancel_cmd->ioa_cb->ioarcb.cdb[0], in pmcraid_abort_cmd()
2878 le32_to_cpu(cancel_cmd->ioa_cb->ioarcb.resource_handle)); in pmcraid_abort_cmd()
2888 * pmcraid_abort_complete - Waits for ABORT TASK completion
2901 wait_for_completion(&cancel_cmd->wait_for_completion); in pmcraid_abort_complete()
2902 res = cancel_cmd->res; in pmcraid_abort_complete()
2903 cancel_cmd->res = NULL; in pmcraid_abort_complete()
2904 ioasc = le32_to_cpu(cancel_cmd->ioa_cb->ioasa.ioasc); in pmcraid_abort_complete()
2914 res->sync_reqd = 1; in pmcraid_abort_complete()
2924 * pmcraid_eh_abort_handler - entry point for aborting a single task on errors
2926 * @scsi_cmd: scsi command struct given by mid-layer. When this is called
2927 * mid-layer ensures that no other commands are queued. This
2945 (struct pmcraid_instance *)scsi_cmd->device->host->hostdata; in pmcraid_eh_abort_handler()
2950 res = scsi_cmd->device->hostdata; in pmcraid_eh_abort_handler()
2956 * This will force the mid-layer to eventually call in pmcraid_eh_abort_handler()
2960 spin_lock_irqsave(pinstance->host->host_lock, host_lock_flags); in pmcraid_eh_abort_handler()
2962 if (pinstance->ioa_reset_in_progress || in pmcraid_eh_abort_handler()
2963 pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_eh_abort_handler()
2964 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_eh_abort_handler()
2974 spin_lock_irqsave(&pinstance->pending_pool_lock, pending_lock_flags); in pmcraid_eh_abort_handler()
2975 list_for_each_entry(cmd, &pinstance->pending_cmd_pool, free_list) { in pmcraid_eh_abort_handler()
2977 if (cmd->scsi_cmd == scsi_cmd) { in pmcraid_eh_abort_handler()
2983 spin_unlock_irqrestore(&pinstance->pending_pool_lock, in pmcraid_eh_abort_handler()
2992 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_eh_abort_handler()
2996 cancel_cmd->res = cmd->scsi_cmd->device->hostdata; in pmcraid_eh_abort_handler()
3004 * pmcraid_eh_device_reset_handler - bus/target/device reset handler callbacks
3009 * Since these are called from mid-layer EH thread, no other IO will be queued
3045 * pmcraid_eh_host_reset_handler - adapter reset handler callback
3059 (struct pmcraid_instance *)(scmd->device->host->hostdata); in pmcraid_eh_host_reset_handler()
3066 while (waits--) { in pmcraid_eh_host_reset_handler()
3067 if (atomic_read(&pinstance->outstanding_cmds) <= in pmcraid_eh_host_reset_handler()
3073 dev_err(&pinstance->pdev->dev, in pmcraid_eh_host_reset_handler()
3079 * pmcraid_init_ioadls - initializes IOADL related fields in IOARCB
3081 * @sgcount: count of scatter-gather elements
3091 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_init_ioadls()
3094 if (ioarcb->add_cmd_param_length) in pmcraid_init_ioadls()
3095 ioadl_count = DIV_ROUND_UP(le16_to_cpu(ioarcb->add_cmd_param_length), 16); in pmcraid_init_ioadls()
3096 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc) * sgcount); in pmcraid_init_ioadls()
3098 if ((sgcount + ioadl_count) > (ARRAY_SIZE(ioarcb->add_data.u.ioadl))) { in pmcraid_init_ioadls()
3100 * structure, re-using 24 out of 27 ioadls part of IOARCB. in pmcraid_init_ioadls()
3104 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL)); in pmcraid_init_ioadls()
3105 ioarcb->ioadl_bus_addr = in pmcraid_init_ioadls()
3106 cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_init_ioadls()
3109 ioadl = &ioarcb->add_data.u.ioadl[3]; in pmcraid_init_ioadls()
3111 ioarcb->ioadl_bus_addr = in pmcraid_init_ioadls()
3112 cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_init_ioadls()
3116 ioadl = &ioarcb->add_data.u.ioadl[ioadl_count]; in pmcraid_init_ioadls()
3117 ioarcb->ioarcb_bus_addr |= in pmcraid_init_ioadls()
3125 * pmcraid_build_ioadl - Build a scatter/gather list and map the buffer
3133 * 0 on success or -1 on failure
3143 struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd; in pmcraid_build_ioadl()
3144 struct pmcraid_ioarcb *ioarcb = &(cmd->ioa_cb->ioarcb); in pmcraid_build_ioadl()
3156 return -1; in pmcraid_build_ioadl()
3161 return -1; in pmcraid_build_ioadl()
3165 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) in pmcraid_build_ioadl()
3166 ioarcb->request_flags0 |= TRANSFER_DIR_WRITE; in pmcraid_build_ioadl()
3168 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_build_ioadl()
3169 ioarcb->data_transfer_length = cpu_to_le32(length); in pmcraid_build_ioadl()
3179 ioadl[i - 1].flags = IOADL_FLAGS_LAST_DESC; in pmcraid_build_ioadl()
3185 * pmcraid_queuecommand_lck - Queue a mid-layer request
3188 * This function queues a request generated by the mid-layer. Midlayer calls
3189 * this routine within host->lock. Some of the functions called by queuecommand
3207 (struct pmcraid_instance *)scsi_cmd->device->host->hostdata; in pmcraid_queuecommand_lck()
3208 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_queuecommand_lck()
3209 res = scsi_cmd->device->hostdata; in pmcraid_queuecommand_lck()
3210 scsi_cmd->result = (DID_OK << 16); in pmcraid_queuecommand_lck()
3215 if (pinstance->ioa_state == IOA_STATE_DEAD) { in pmcraid_queuecommand_lck()
3217 scsi_cmd->result = (DID_NO_CONNECT << 16); in pmcraid_queuecommand_lck()
3223 if (pinstance->ioa_reset_in_progress) in pmcraid_queuecommand_lck()
3229 if (scsi_cmd->cmnd[0] == SYNCHRONIZE_CACHE) { in pmcraid_queuecommand_lck()
3243 cmd->scsi_cmd = scsi_cmd; in pmcraid_queuecommand_lck()
3244 ioarcb = &(cmd->ioa_cb->ioarcb); in pmcraid_queuecommand_lck()
3245 memcpy(ioarcb->cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len); in pmcraid_queuecommand_lck()
3246 ioarcb->resource_handle = res->cfg_entry.resource_handle; in pmcraid_queuecommand_lck()
3247 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_queuecommand_lck()
3251 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses in pmcraid_queuecommand_lck()
3254 ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) % in pmcraid_queuecommand_lck()
3255 pinstance->num_hrrq; in pmcraid_queuecommand_lck()
3256 cmd->cmd_done = pmcraid_io_done; in pmcraid_queuecommand_lck()
3258 if (RES_IS_GSCSI(res->cfg_entry) || RES_IS_VSET(res->cfg_entry)) { in pmcraid_queuecommand_lck()
3259 if (scsi_cmd->underflow == 0) in pmcraid_queuecommand_lck()
3260 ioarcb->request_flags0 |= INHIBIT_UL_CHECK; in pmcraid_queuecommand_lck()
3262 if (res->sync_reqd) { in pmcraid_queuecommand_lck()
3263 ioarcb->request_flags0 |= SYNC_COMPLETE; in pmcraid_queuecommand_lck()
3264 res->sync_reqd = 0; in pmcraid_queuecommand_lck()
3267 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_queuecommand_lck()
3269 if (scsi_cmd->flags & SCMD_TAGGED) in pmcraid_queuecommand_lck()
3270 ioarcb->request_flags1 |= TASK_TAG_SIMPLE; in pmcraid_queuecommand_lck()
3272 if (RES_IS_GSCSI(res->cfg_entry)) in pmcraid_queuecommand_lck()
3273 ioarcb->request_flags1 |= DELAY_AFTER_RESET; in pmcraid_queuecommand_lck()
3279 le32_to_cpu(ioarcb->response_handle) >> 2, in pmcraid_queuecommand_lck()
3280 scsi_cmd->cmnd[0], pinstance->host->unique_id, in pmcraid_queuecommand_lck()
3281 RES_IS_VSET(res->cfg_entry) ? PMCRAID_VSET_BUS_ID : in pmcraid_queuecommand_lck()
3283 RES_IS_VSET(res->cfg_entry) ? in pmcraid_queuecommand_lck()
3285 res->cfg_entry.unique_flags1 : in pmcraid_queuecommand_lck()
3286 le16_to_cpu(res->cfg_entry.array_id) & 0xFF) : in pmcraid_queuecommand_lck()
3287 RES_TARGET(res->cfg_entry.resource_address), in pmcraid_queuecommand_lck()
3288 RES_LUN(res->cfg_entry.resource_address)); in pmcraid_queuecommand_lck()
3304 * pmcraid_open -char node "open" entry, allowed only users with admin access in DEF_SCSI_QCMD()
3311 return -EACCES; in DEF_SCSI_QCMD()
3314 pinstance = container_of(inode->i_cdev, struct pmcraid_instance, cdev); in DEF_SCSI_QCMD()
3315 filep->private_data = pinstance; in DEF_SCSI_QCMD()
3321 * pmcraid_fasync - Async notifier registration from applications
3331 pinstance = filep->private_data; in pmcraid_chr_fasync()
3332 mutex_lock(&pinstance->aen_queue_lock); in pmcraid_chr_fasync()
3333 rc = fasync_helper(fd, filep, mode, &pinstance->aen_queue); in pmcraid_chr_fasync()
3334 mutex_unlock(&pinstance->aen_queue_lock); in pmcraid_chr_fasync()
3340 * pmcraid_ioctl_driver - ioctl handler for commands handled by driver itself
3357 int rc = -ENOSYS; in pmcraid_ioctl_driver()
3373 * pmcraid_check_ioctl_buffer - check for proper access to user buffer
3394 return -EFAULT; in pmcraid_check_ioctl_buffer()
3398 rc = memcmp(hdr->signature, in pmcraid_check_ioctl_buffer()
3400 sizeof(hdr->signature)); in pmcraid_check_ioctl_buffer()
3403 return -EINVAL; in pmcraid_check_ioctl_buffer()
3410 * pmcraid_ioctl - char node ioctl entry point
3421 int retval = -ENOTTY; in pmcraid_chr_ioctl()
3427 return -ENOMEM; in pmcraid_chr_ioctl()
3438 pinstance = filep->private_data; in pmcraid_chr_ioctl()
3443 return -ENOTTY; in pmcraid_chr_ioctl()
3451 hdr->buffer_length, argp); in pmcraid_chr_ioctl()
3455 retval = -ENOTTY; in pmcraid_chr_ioctl()
3480 * pmcraid_show_log_level - Display adapter's error logging level
3495 (struct pmcraid_instance *)shost->hostdata; in pmcraid_show_log_level()
3496 return snprintf(buf, PAGE_SIZE, "%d\n", pinstance->current_log_level); in pmcraid_show_log_level()
3500 * pmcraid_store_log_level - Change the adapter's error logging level
3521 return -EINVAL; in pmcraid_store_log_level()
3522 /* log-level should be from 0 to 2 */ in pmcraid_store_log_level()
3524 return -EINVAL; in pmcraid_store_log_level()
3527 pinstance = (struct pmcraid_instance *)shost->hostdata; in pmcraid_store_log_level()
3528 pinstance->current_log_level = val; in pmcraid_store_log_level()
3543 * pmcraid_show_drv_version - Display driver version
3570 * pmcraid_show_adapter_id - Display driver assigned adapter id
3586 (struct pmcraid_instance *)shost->hostdata; in pmcraid_show_adapter_id()
3587 u32 adapter_id = pci_dev_id(pinstance->pdev); in pmcraid_show_adapter_id()
3592 adapter_id, MINOR(pinstance->cdev.dev), aen_group); in pmcraid_show_adapter_id()
3628 .this_id = -1,
3638 * pmcraid_isr_msix - implements MSI-X interrupt handling routine
3655 hrrq_id = hrrq_vector->hrrq_id; in pmcraid_isr_msix()
3656 pinstance = hrrq_vector->drv_inst; in pmcraid_isr_msix()
3662 ((ioread32(pinstance->int_regs.host_ioa_interrupt_reg) in pmcraid_isr_msix()
3671 pinstance->ioa_unit_check = 1; in pmcraid_isr_msix()
3675 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_isr_msix()
3679 pinstance->host->host_lock, in pmcraid_isr_msix()
3694 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_isr_msix()
3695 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_isr_msix()
3701 tasklet_schedule(&(pinstance->isr_tasklet[hrrq_id])); in pmcraid_isr_msix()
3707 * pmcraid_isr - implements legacy interrupt handling routine
3731 pinstance = hrrq_vector->drv_inst; in pmcraid_isr()
3745 pinstance->ioa_unit_check = 1; in pmcraid_isr()
3748 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
3752 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
3753 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); in pmcraid_isr()
3755 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); in pmcraid_isr()
3765 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
3767 pinstance->int_regs.ioa_host_interrupt_clr_reg); in pmcraid_isr()
3770 &(pinstance->isr_tasklet[hrrq_id])); in pmcraid_isr()
3779 * pmcraid_worker_function - worker thread function
3800 if (!atomic_read(&pinstance->expose_resources)) in pmcraid_worker_function()
3803 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_worker_function()
3805 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_worker_function()
3806 list_for_each_entry_safe(res, temp, &pinstance->used_res_q, queue) { in pmcraid_worker_function()
3808 if (res->change_detected == RES_CHANGE_DEL && res->scsi_dev) { in pmcraid_worker_function()
3809 sdev = res->scsi_dev; in pmcraid_worker_function()
3814 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_worker_function()
3818 pinstance->host->host_lock, in pmcraid_worker_function()
3821 res->cfg_entry.resource_address); in pmcraid_worker_function()
3822 list_move_tail(&res->queue, in pmcraid_worker_function()
3823 &pinstance->free_res_q); in pmcraid_worker_function()
3825 &pinstance->resource_lock, in pmcraid_worker_function()
3829 spin_lock_irqsave(&pinstance->resource_lock, in pmcraid_worker_function()
3831 res->change_detected = 0; in pmcraid_worker_function()
3834 pinstance->host->host_lock, in pmcraid_worker_function()
3840 list_for_each_entry(res, &pinstance->used_res_q, queue) { in pmcraid_worker_function()
3842 if (res->change_detected == RES_CHANGE_ADD) { in pmcraid_worker_function()
3845 &res->cfg_entry)) in pmcraid_worker_function()
3848 if (RES_IS_VSET(res->cfg_entry)) { in pmcraid_worker_function()
3851 target = res->cfg_entry.unique_flags1; in pmcraid_worker_function()
3853 target = le16_to_cpu(res->cfg_entry.array_id) & 0xFF; in pmcraid_worker_function()
3859 res->cfg_entry.resource_address); in pmcraid_worker_function()
3860 lun = RES_LUN(res->cfg_entry.resource_address); in pmcraid_worker_function()
3863 res->change_detected = 0; in pmcraid_worker_function()
3864 spin_unlock_irqrestore(&pinstance->resource_lock, in pmcraid_worker_function()
3866 scsi_add_device(pinstance->host, bus, target, lun); in pmcraid_worker_function()
3867 spin_lock_irqsave(&pinstance->resource_lock, in pmcraid_worker_function()
3872 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_worker_function()
3876 * pmcraid_tasklet_function - Tasklet function
3895 pinstance = hrrq_vector->drv_inst; in pmcraid_tasklet_function()
3896 id = hrrq_vector->hrrq_id; in pmcraid_tasklet_function()
3897 lockp = &(pinstance->hrrq_lock[id]); in pmcraid_tasklet_function()
3907 resp = le32_to_cpu(*(pinstance->hrrq_curr[id])); in pmcraid_tasklet_function()
3910 pinstance->host_toggle_bit[id]) { in pmcraid_tasklet_function()
3915 if (pinstance->hrrq_curr[id] < pinstance->hrrq_end[id]) { in pmcraid_tasklet_function()
3916 pinstance->hrrq_curr[id]++; in pmcraid_tasklet_function()
3918 pinstance->hrrq_curr[id] = pinstance->hrrq_start[id]; in pmcraid_tasklet_function()
3919 pinstance->host_toggle_bit[id] ^= 1u; in pmcraid_tasklet_function()
3925 resp = le32_to_cpu(*(pinstance->hrrq_curr[id])); in pmcraid_tasklet_function()
3929 cmd = pinstance->cmd_list[cmd_index]; in pmcraid_tasklet_function()
3932 spin_lock_irqsave(&pinstance->pending_pool_lock, in pmcraid_tasklet_function()
3934 list_del(&cmd->free_list); in pmcraid_tasklet_function()
3935 spin_unlock_irqrestore(&pinstance->pending_pool_lock, in pmcraid_tasklet_function()
3937 del_timer(&cmd->timer); in pmcraid_tasklet_function()
3938 atomic_dec(&pinstance->outstanding_cmds); in pmcraid_tasklet_function()
3940 if (cmd->cmd_done == pmcraid_ioa_reset) { in pmcraid_tasklet_function()
3941 spin_lock_irqsave(pinstance->host->host_lock, in pmcraid_tasklet_function()
3943 cmd->cmd_done(cmd); in pmcraid_tasklet_function()
3944 spin_unlock_irqrestore(pinstance->host->host_lock, in pmcraid_tasklet_function()
3946 } else if (cmd->cmd_done != NULL) { in pmcraid_tasklet_function()
3947 cmd->cmd_done(cmd); in pmcraid_tasklet_function()
3951 resp = le32_to_cpu(*(pinstance->hrrq_curr[id])); in pmcraid_tasklet_function()
3958 * pmcraid_unregister_interrupt_handler - de-register interrupts handlers
3961 * This routine un-registers registered interrupt handler and
3970 struct pci_dev *pdev = pinstance->pdev; in pmcraid_unregister_interrupt_handler()
3973 for (i = 0; i < pinstance->num_hrrq; i++) in pmcraid_unregister_interrupt_handler()
3974 free_irq(pci_irq_vector(pdev, i), &pinstance->hrrq_vector[i]); in pmcraid_unregister_interrupt_handler()
3976 pinstance->interrupt_mode = 0; in pmcraid_unregister_interrupt_handler()
3981 * pmcraid_register_interrupt_handler - registers interrupt handler
3982 * @pinstance: pointer to per-adapter instance structure
3985 * 0 on success, non-zero error code otherwise.
3990 struct pci_dev *pdev = pinstance->pdev; in pmcraid_register_interrupt_handler()
4003 if (pdev->msix_enabled) { in pmcraid_register_interrupt_handler()
4012 struct pmcraid_isr_param *vec = &pinstance->hrrq_vector[i]; in pmcraid_register_interrupt_handler()
4014 vec->hrrq_id = i; in pmcraid_register_interrupt_handler()
4015 vec->drv_inst = pinstance; in pmcraid_register_interrupt_handler()
4022 pinstance->num_hrrq = num_hrrq; in pmcraid_register_interrupt_handler()
4023 if (pdev->msix_enabled) { in pmcraid_register_interrupt_handler()
4024 pinstance->interrupt_mode = 1; in pmcraid_register_interrupt_handler()
4026 pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_register_interrupt_handler()
4027 ioread32(pinstance->int_regs.host_ioa_interrupt_reg); in pmcraid_register_interrupt_handler()
4033 while (--i >= 0) in pmcraid_register_interrupt_handler()
4034 free_irq(pci_irq_vector(pdev, i), &pinstance->hrrq_vector[i]); in pmcraid_register_interrupt_handler()
4040 * pmcraid_release_cmd_blocks - release buufers allocated for command blocks
4052 kmem_cache_free(pinstance->cmd_cachep, pinstance->cmd_list[i]); in pmcraid_release_cmd_blocks()
4053 pinstance->cmd_list[i] = NULL; in pmcraid_release_cmd_blocks()
4055 kmem_cache_destroy(pinstance->cmd_cachep); in pmcraid_release_cmd_blocks()
4056 pinstance->cmd_cachep = NULL; in pmcraid_release_cmd_blocks()
4060 * pmcraid_release_control_blocks - releases buffers alloced for control blocks
4078 if (pinstance->control_pool == NULL) in pmcraid_release_control_blocks()
4082 dma_pool_free(pinstance->control_pool, in pmcraid_release_control_blocks()
4083 pinstance->cmd_list[i]->ioa_cb, in pmcraid_release_control_blocks()
4084 pinstance->cmd_list[i]->ioa_cb_bus_addr); in pmcraid_release_control_blocks()
4085 pinstance->cmd_list[i]->ioa_cb = NULL; in pmcraid_release_control_blocks()
4086 pinstance->cmd_list[i]->ioa_cb_bus_addr = 0; in pmcraid_release_control_blocks()
4088 dma_pool_destroy(pinstance->control_pool); in pmcraid_release_control_blocks()
4089 pinstance->control_pool = NULL; in pmcraid_release_control_blocks()
4093 * pmcraid_allocate_cmd_blocks - allocate memory for cmd block structures
4099 * 0 in case of success; -ENOMEM in case of failure
4105 sprintf(pinstance->cmd_pool_name, "pmcraid_cmd_pool_%d", in pmcraid_allocate_cmd_blocks()
4106 pinstance->host->unique_id); in pmcraid_allocate_cmd_blocks()
4109 pinstance->cmd_cachep = kmem_cache_create( in pmcraid_allocate_cmd_blocks()
4110 pinstance->cmd_pool_name, in pmcraid_allocate_cmd_blocks()
4113 if (!pinstance->cmd_cachep) in pmcraid_allocate_cmd_blocks()
4114 return -ENOMEM; in pmcraid_allocate_cmd_blocks()
4117 pinstance->cmd_list[i] = in pmcraid_allocate_cmd_blocks()
4118 kmem_cache_alloc(pinstance->cmd_cachep, GFP_KERNEL); in pmcraid_allocate_cmd_blocks()
4119 if (!pinstance->cmd_list[i]) { in pmcraid_allocate_cmd_blocks()
4121 return -ENOMEM; in pmcraid_allocate_cmd_blocks()
4128 * pmcraid_allocate_control_blocks - allocates memory control blocks
4135 * 0 in case it can allocate all control blocks, otherwise -ENOMEM
4141 sprintf(pinstance->ctl_pool_name, "pmcraid_control_pool_%d", in pmcraid_allocate_control_blocks()
4142 pinstance->host->unique_id); in pmcraid_allocate_control_blocks()
4144 pinstance->control_pool = in pmcraid_allocate_control_blocks()
4145 dma_pool_create(pinstance->ctl_pool_name, in pmcraid_allocate_control_blocks()
4146 &pinstance->pdev->dev, in pmcraid_allocate_control_blocks()
4150 if (!pinstance->control_pool) in pmcraid_allocate_control_blocks()
4151 return -ENOMEM; in pmcraid_allocate_control_blocks()
4154 pinstance->cmd_list[i]->ioa_cb = in pmcraid_allocate_control_blocks()
4156 pinstance->control_pool, in pmcraid_allocate_control_blocks()
4158 &(pinstance->cmd_list[i]->ioa_cb_bus_addr)); in pmcraid_allocate_control_blocks()
4160 if (!pinstance->cmd_list[i]->ioa_cb) { in pmcraid_allocate_control_blocks()
4162 return -ENOMEM; in pmcraid_allocate_control_blocks()
4169 * pmcraid_release_host_rrqs - release memory allocated for hrrq buffer(s)
4182 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_host_rrqs()
4184 pinstance->hrrq_start[i], in pmcraid_release_host_rrqs()
4185 pinstance->hrrq_start_bus_addr[i]); in pmcraid_release_host_rrqs()
4188 pinstance->hrrq_start[i] = NULL; in pmcraid_release_host_rrqs()
4189 pinstance->hrrq_start_bus_addr[i] = 0; in pmcraid_release_host_rrqs()
4190 pinstance->host_toggle_bit[i] = 0; in pmcraid_release_host_rrqs()
4195 * pmcraid_allocate_host_rrqs - Allocate and initialize host RRQ buffers
4199 * 0 hrrq buffers are allocated, -ENOMEM otherwise.
4207 for (i = 0; i < pinstance->num_hrrq; i++) { in pmcraid_allocate_host_rrqs()
4208 pinstance->hrrq_start[i] = in pmcraid_allocate_host_rrqs()
4209 dma_alloc_coherent(&pinstance->pdev->dev, buffer_size, in pmcraid_allocate_host_rrqs()
4210 &pinstance->hrrq_start_bus_addr[i], in pmcraid_allocate_host_rrqs()
4212 if (!pinstance->hrrq_start[i]) { in pmcraid_allocate_host_rrqs()
4216 return -ENOMEM; in pmcraid_allocate_host_rrqs()
4219 pinstance->hrrq_curr[i] = pinstance->hrrq_start[i]; in pmcraid_allocate_host_rrqs()
4220 pinstance->hrrq_end[i] = in pmcraid_allocate_host_rrqs()
4221 pinstance->hrrq_start[i] + PMCRAID_MAX_CMD - 1; in pmcraid_allocate_host_rrqs()
4222 pinstance->host_toggle_bit[i] = 1; in pmcraid_allocate_host_rrqs()
4223 spin_lock_init(&pinstance->hrrq_lock[i]); in pmcraid_allocate_host_rrqs()
4229 * pmcraid_release_hcams - release HCAM buffers
4238 if (pinstance->ccn.msg != NULL) { in pmcraid_release_hcams()
4239 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_hcams()
4242 pinstance->ccn.msg, in pmcraid_release_hcams()
4243 pinstance->ccn.baddr); in pmcraid_release_hcams()
4245 pinstance->ccn.msg = NULL; in pmcraid_release_hcams()
4246 pinstance->ccn.hcam = NULL; in pmcraid_release_hcams()
4247 pinstance->ccn.baddr = 0; in pmcraid_release_hcams()
4250 if (pinstance->ldn.msg != NULL) { in pmcraid_release_hcams()
4251 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_hcams()
4254 pinstance->ldn.msg, in pmcraid_release_hcams()
4255 pinstance->ldn.baddr); in pmcraid_release_hcams()
4257 pinstance->ldn.msg = NULL; in pmcraid_release_hcams()
4258 pinstance->ldn.hcam = NULL; in pmcraid_release_hcams()
4259 pinstance->ldn.baddr = 0; in pmcraid_release_hcams()
4264 * pmcraid_allocate_hcams - allocates HCAM buffers
4268 * 0 in case of successful allocation, non-zero otherwise
4272 pinstance->ccn.msg = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_allocate_hcams()
4275 &pinstance->ccn.baddr, GFP_KERNEL); in pmcraid_allocate_hcams()
4277 pinstance->ldn.msg = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_allocate_hcams()
4280 &pinstance->ldn.baddr, GFP_KERNEL); in pmcraid_allocate_hcams()
4282 if (pinstance->ldn.msg == NULL || pinstance->ccn.msg == NULL) { in pmcraid_allocate_hcams()
4285 pinstance->ccn.hcam = in pmcraid_allocate_hcams()
4286 (void *)pinstance->ccn.msg + PMCRAID_AEN_HDR_SIZE; in pmcraid_allocate_hcams()
4287 pinstance->ldn.hcam = in pmcraid_allocate_hcams()
4288 (void *)pinstance->ldn.msg + PMCRAID_AEN_HDR_SIZE; in pmcraid_allocate_hcams()
4290 atomic_set(&pinstance->ccn.ignore, 0); in pmcraid_allocate_hcams()
4291 atomic_set(&pinstance->ldn.ignore, 0); in pmcraid_allocate_hcams()
4294 return (pinstance->ldn.msg == NULL) ? -ENOMEM : 0; in pmcraid_allocate_hcams()
4298 * pmcraid_release_config_buffers - release config.table buffers
4306 if (pinstance->cfg_table != NULL && in pmcraid_release_config_buffers()
4307 pinstance->cfg_table_bus_addr != 0) { in pmcraid_release_config_buffers()
4308 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_config_buffers()
4310 pinstance->cfg_table, in pmcraid_release_config_buffers()
4311 pinstance->cfg_table_bus_addr); in pmcraid_release_config_buffers()
4312 pinstance->cfg_table = NULL; in pmcraid_release_config_buffers()
4313 pinstance->cfg_table_bus_addr = 0; in pmcraid_release_config_buffers()
4316 if (pinstance->res_entries != NULL) { in pmcraid_release_config_buffers()
4320 list_del(&pinstance->res_entries[i].queue); in pmcraid_release_config_buffers()
4321 kfree(pinstance->res_entries); in pmcraid_release_config_buffers()
4322 pinstance->res_entries = NULL; in pmcraid_release_config_buffers()
4329 * pmcraid_allocate_config_buffers - allocates DMAable memory for config table
4333 * 0 for successful allocation, -ENOMEM for any failure
4339 pinstance->res_entries = in pmcraid_allocate_config_buffers()
4344 if (NULL == pinstance->res_entries) { in pmcraid_allocate_config_buffers()
4346 return -ENOMEM; in pmcraid_allocate_config_buffers()
4350 list_add_tail(&pinstance->res_entries[i].queue, in pmcraid_allocate_config_buffers()
4351 &pinstance->free_res_q); in pmcraid_allocate_config_buffers()
4353 pinstance->cfg_table = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_allocate_config_buffers()
4355 &pinstance->cfg_table_bus_addr, in pmcraid_allocate_config_buffers()
4358 if (NULL == pinstance->cfg_table) { in pmcraid_allocate_config_buffers()
4361 return -ENOMEM; in pmcraid_allocate_config_buffers()
4367 return -ENOMEM; in pmcraid_allocate_config_buffers()
4374 * pmcraid_init_tasklets - registers tasklets for response handling
4384 for (i = 0; i < pinstance->num_hrrq; i++) in pmcraid_init_tasklets()
4385 tasklet_init(&pinstance->isr_tasklet[i], in pmcraid_init_tasklets()
4387 (unsigned long)&pinstance->hrrq_vector[i]); in pmcraid_init_tasklets()
4391 * pmcraid_kill_tasklets - destroys tasklets registered for response handling
4401 for (i = 0; i < pinstance->num_hrrq; i++) in pmcraid_kill_tasklets()
4402 tasklet_kill(&pinstance->isr_tasklet[i]); in pmcraid_kill_tasklets()
4406 * pmcraid_release_buffers - release per-adapter buffers allocated
4418 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_release_buffers()
4420 if (pinstance->inq_data != NULL) { in pmcraid_release_buffers()
4421 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_buffers()
4423 pinstance->inq_data, in pmcraid_release_buffers()
4424 pinstance->inq_data_baddr); in pmcraid_release_buffers()
4426 pinstance->inq_data = NULL; in pmcraid_release_buffers()
4427 pinstance->inq_data_baddr = 0; in pmcraid_release_buffers()
4430 if (pinstance->timestamp_data != NULL) { in pmcraid_release_buffers()
4431 dma_free_coherent(&pinstance->pdev->dev, in pmcraid_release_buffers()
4433 pinstance->timestamp_data, in pmcraid_release_buffers()
4434 pinstance->timestamp_data_baddr); in pmcraid_release_buffers()
4436 pinstance->timestamp_data = NULL; in pmcraid_release_buffers()
4437 pinstance->timestamp_data_baddr = 0; in pmcraid_release_buffers()
4442 * pmcraid_init_buffers - allocates memory and initializes various structures
4445 * This routine pre-allocates memory based on the type of block as below:
4448 * config-table entries : DMAable memory using dma_alloc_coherent
4452 * 0 in case all of the blocks are allocated, -ENOMEM otherwise.
4460 pinstance->num_hrrq); in pmcraid_init_buffers()
4461 return -ENOMEM; in pmcraid_init_buffers()
4466 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_init_buffers()
4467 return -ENOMEM; in pmcraid_init_buffers()
4473 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_init_buffers()
4474 return -ENOMEM; in pmcraid_init_buffers()
4481 pmcraid_release_host_rrqs(pinstance, pinstance->num_hrrq); in pmcraid_init_buffers()
4482 return -ENOMEM; in pmcraid_init_buffers()
4486 pinstance->inq_data = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_init_buffers()
4488 &pinstance->inq_data_baddr, GFP_KERNEL); in pmcraid_init_buffers()
4489 if (pinstance->inq_data == NULL) { in pmcraid_init_buffers()
4492 return -ENOMEM; in pmcraid_init_buffers()
4496 pinstance->timestamp_data = dma_alloc_coherent(&pinstance->pdev->dev, in pmcraid_init_buffers()
4498 &pinstance->timestamp_data_baddr, in pmcraid_init_buffers()
4500 if (pinstance->timestamp_data == NULL) { in pmcraid_init_buffers()
4504 return -ENOMEM; in pmcraid_init_buffers()
4513 struct pmcraid_cmd *cmdp = pinstance->cmd_list[i]; in pmcraid_init_buffers()
4515 cmdp->drv_inst = pinstance; in pmcraid_init_buffers()
4516 list_add_tail(&cmdp->free_list, &pinstance->free_cmd_pool); in pmcraid_init_buffers()
4523 * pmcraid_reinit_buffers - resets various buffer pointers
4533 for (i = 0; i < pinstance->num_hrrq; i++) { in pmcraid_reinit_buffers()
4534 memset(pinstance->hrrq_start[i], 0, buffer_size); in pmcraid_reinit_buffers()
4535 pinstance->hrrq_curr[i] = pinstance->hrrq_start[i]; in pmcraid_reinit_buffers()
4536 pinstance->hrrq_end[i] = in pmcraid_reinit_buffers()
4537 pinstance->hrrq_start[i] + PMCRAID_MAX_CMD - 1; in pmcraid_reinit_buffers()
4538 pinstance->host_toggle_bit[i] = 1; in pmcraid_reinit_buffers()
4543 * pmcraid_init_instance - initialize per instance data structure
4549 * 0 on success, non-zero in case of any failure
4555 (struct pmcraid_instance *)host->hostdata; in pmcraid_init_instance()
4557 pinstance->host = host; in pmcraid_init_instance()
4558 pinstance->pdev = pdev; in pmcraid_init_instance()
4561 pinstance->mapped_dma_addr = mapped_pci_addr; in pmcraid_init_instance()
4563 /* Initialize chip-specific details */ in pmcraid_init_instance()
4565 struct pmcraid_chip_details *chip_cfg = pinstance->chip_cfg; in pmcraid_init_instance()
4566 struct pmcraid_interrupts *pint_regs = &pinstance->int_regs; in pmcraid_init_instance()
4568 pinstance->ioarrin = mapped_pci_addr + chip_cfg->ioarrin; in pmcraid_init_instance()
4570 pint_regs->ioa_host_interrupt_reg = in pmcraid_init_instance()
4571 mapped_pci_addr + chip_cfg->ioa_host_intr; in pmcraid_init_instance()
4572 pint_regs->ioa_host_interrupt_clr_reg = in pmcraid_init_instance()
4573 mapped_pci_addr + chip_cfg->ioa_host_intr_clr; in pmcraid_init_instance()
4574 pint_regs->ioa_host_msix_interrupt_reg = in pmcraid_init_instance()
4575 mapped_pci_addr + chip_cfg->ioa_host_msix_intr; in pmcraid_init_instance()
4576 pint_regs->host_ioa_interrupt_reg = in pmcraid_init_instance()
4577 mapped_pci_addr + chip_cfg->host_ioa_intr; in pmcraid_init_instance()
4578 pint_regs->host_ioa_interrupt_clr_reg = in pmcraid_init_instance()
4579 mapped_pci_addr + chip_cfg->host_ioa_intr_clr; in pmcraid_init_instance()
4584 pinstance->mailbox = mapped_pci_addr + chip_cfg->mailbox; in pmcraid_init_instance()
4585 pinstance->ioa_status = mapped_pci_addr + chip_cfg->ioastatus; in pmcraid_init_instance()
4586 pint_regs->ioa_host_interrupt_mask_reg = in pmcraid_init_instance()
4587 mapped_pci_addr + chip_cfg->ioa_host_mask; in pmcraid_init_instance()
4588 pint_regs->ioa_host_interrupt_mask_clr_reg = in pmcraid_init_instance()
4589 mapped_pci_addr + chip_cfg->ioa_host_mask_clr; in pmcraid_init_instance()
4590 pint_regs->global_interrupt_mask_reg = in pmcraid_init_instance()
4591 mapped_pci_addr + chip_cfg->global_intr_mask; in pmcraid_init_instance()
4594 pinstance->ioa_reset_attempts = 0; in pmcraid_init_instance()
4595 init_waitqueue_head(&pinstance->reset_wait_q); in pmcraid_init_instance()
4597 atomic_set(&pinstance->outstanding_cmds, 0); in pmcraid_init_instance()
4598 atomic_set(&pinstance->last_message_id, 0); in pmcraid_init_instance()
4599 atomic_set(&pinstance->expose_resources, 0); in pmcraid_init_instance()
4601 INIT_LIST_HEAD(&pinstance->free_res_q); in pmcraid_init_instance()
4602 INIT_LIST_HEAD(&pinstance->used_res_q); in pmcraid_init_instance()
4603 INIT_LIST_HEAD(&pinstance->free_cmd_pool); in pmcraid_init_instance()
4604 INIT_LIST_HEAD(&pinstance->pending_cmd_pool); in pmcraid_init_instance()
4606 spin_lock_init(&pinstance->free_pool_lock); in pmcraid_init_instance()
4607 spin_lock_init(&pinstance->pending_pool_lock); in pmcraid_init_instance()
4608 spin_lock_init(&pinstance->resource_lock); in pmcraid_init_instance()
4609 mutex_init(&pinstance->aen_queue_lock); in pmcraid_init_instance()
4611 /* Work-queue (Shared) for deferred processing error handling */ in pmcraid_init_instance()
4612 INIT_WORK(&pinstance->worker_q, pmcraid_worker_function); in pmcraid_init_instance()
4615 pinstance->current_log_level = pmcraid_log_level; in pmcraid_init_instance()
4618 pinstance->ioa_state = IOA_STATE_UNKNOWN; in pmcraid_init_instance()
4619 pinstance->reset_cmd = NULL; in pmcraid_init_instance()
4624 * pmcraid_shutdown - shutdown adapter controller.
4640 * pmcraid_get_minor - returns unused minor number from minor number bitmap
4652 * pmcraid_release_minor - releases given minor back to minor number bitmap
4660 * pmcraid_setup_chrdev - allocates a minor number and registers a char device
4665 * 0 in case of success, otherwise non-zero
4673 cdev_init(&pinstance->cdev, &pmcraid_fops); in pmcraid_setup_chrdev()
4674 pinstance->cdev.owner = THIS_MODULE; in pmcraid_setup_chrdev()
4676 error = cdev_add(&pinstance->cdev, MKDEV(pmcraid_major, minor), 1); in pmcraid_setup_chrdev()
4687 * pmcraid_release_chrdev - unregisters per-adapter management interface
4696 pmcraid_release_minor(MINOR(pinstance->cdev.dev)); in pmcraid_release_chrdev()
4698 MKDEV(pmcraid_major, MINOR(pinstance->cdev.dev))); in pmcraid_release_chrdev()
4699 cdev_del(&pinstance->cdev); in pmcraid_release_chrdev()
4703 * pmcraid_remove - IOA hot plug remove entry point
4717 scsi_remove_host(pinstance->host); in pmcraid_remove()
4719 /* block requests from mid-layer */ in pmcraid_remove()
4720 scsi_block_requests(pinstance->host); in pmcraid_remove()
4726 flush_work(&pinstance->worker_q); in pmcraid_remove()
4731 iounmap(pinstance->mapped_dma_addr); in pmcraid_remove()
4733 scsi_host_put(pinstance->host); in pmcraid_remove()
4740 * pmcraid_suspend - driver suspend entry point for power management
4743 * Return Value - 0 always
4759 * pmcraid_resume - driver resume entry point PCI power management
4762 * Return Value - 0 in case of success. Error code in case of any failure
4768 struct Scsi_Host *host = pinstance->host; in pmcraid_resume()
4772 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) in pmcraid_resume()
4773 rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_resume()
4776 rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_resume()
4779 dev_err(&pdev->dev, "resume: Failed to set PCI DMA mask\n"); in pmcraid_resume()
4784 atomic_set(&pinstance->outstanding_cmds, 0); in pmcraid_resume()
4788 dev_err(&pdev->dev, in pmcraid_resume()
4790 rc = -ENODEV; in pmcraid_resume()
4800 pinstance->ioa_hard_reset = 1; in pmcraid_resume()
4806 dev_err(&pdev->dev, "couldn't initialize IOA\n"); in pmcraid_resume()
4807 rc = -ENODEV; in pmcraid_resume()
4827 * pmcraid_complete_ioa_reset - Called by either timer or tasklet during
4833 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_complete_ioa_reset()
4836 spin_lock_irqsave(pinstance->host->host_lock, flags); in pmcraid_complete_ioa_reset()
4838 spin_unlock_irqrestore(pinstance->host->host_lock, flags); in pmcraid_complete_ioa_reset()
4839 scsi_unblock_requests(pinstance->host); in pmcraid_complete_ioa_reset()
4840 schedule_work(&pinstance->worker_q); in pmcraid_complete_ioa_reset()
4844 * pmcraid_set_supported_devs - sends SET SUPPORTED DEVICES to IOAFP
4849 * 0 for success or non-zero for failure cases
4853 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_set_supported_devs()
4858 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_set_supported_devs()
4859 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_set_supported_devs()
4860 ioarcb->cdb[0] = PMCRAID_SET_SUPPORTED_DEVICES; in pmcraid_set_supported_devs()
4861 ioarcb->cdb[1] = ALL_DEVICES_SUPPORTED; in pmcraid_set_supported_devs()
4867 if (cmd->drv_inst->reinit_cfg_table) { in pmcraid_set_supported_devs()
4868 cmd->drv_inst->reinit_cfg_table = 0; in pmcraid_set_supported_devs()
4869 cmd->release = 1; in pmcraid_set_supported_devs()
4885 * pmcraid_set_timestamp - set the timestamp to IOAFP
4890 * 0 for success or non-zero for failure cases
4894 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_set_timestamp()
4895 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_set_timestamp()
4902 pinstance->timestamp_data->timestamp[0] = (__u8)(timestamp); in pmcraid_set_timestamp()
4903 pinstance->timestamp_data->timestamp[1] = (__u8)((timestamp) >> 8); in pmcraid_set_timestamp()
4904 pinstance->timestamp_data->timestamp[2] = (__u8)((timestamp) >> 16); in pmcraid_set_timestamp()
4905 pinstance->timestamp_data->timestamp[3] = (__u8)((timestamp) >> 24); in pmcraid_set_timestamp()
4906 pinstance->timestamp_data->timestamp[4] = (__u8)((timestamp) >> 32); in pmcraid_set_timestamp()
4907 pinstance->timestamp_data->timestamp[5] = (__u8)((timestamp) >> 40); in pmcraid_set_timestamp()
4910 ioarcb->request_type = REQ_TYPE_SCSI; in pmcraid_set_timestamp()
4911 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_set_timestamp()
4912 ioarcb->cdb[0] = PMCRAID_SCSI_SET_TIMESTAMP; in pmcraid_set_timestamp()
4913 ioarcb->cdb[1] = PMCRAID_SCSI_SERVICE_ACTION; in pmcraid_set_timestamp()
4914 memcpy(&(ioarcb->cdb[6]), &time_stamp_len, sizeof(time_stamp_len)); in pmcraid_set_timestamp()
4916 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_set_timestamp()
4919 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_set_timestamp()
4920 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL)); in pmcraid_set_timestamp()
4922 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_set_timestamp()
4923 ioarcb->request_flags0 |= TRANSFER_DIR_WRITE; in pmcraid_set_timestamp()
4924 ioarcb->data_transfer_length = in pmcraid_set_timestamp()
4926 ioadl = &(ioarcb->add_data.u.ioadl[0]); in pmcraid_set_timestamp()
4927 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_set_timestamp()
4928 ioadl->address = cpu_to_le64(pinstance->timestamp_data_baddr); in pmcraid_set_timestamp()
4929 ioadl->data_len = cpu_to_le32(sizeof(struct pmcraid_timestamp_data)); in pmcraid_set_timestamp()
4931 if (!pinstance->timestamp_error) { in pmcraid_set_timestamp()
4932 pinstance->timestamp_error = 0; in pmcraid_set_timestamp()
4944 * pmcraid_init_res_table - Initialize the resource table
4949 * devices and schedule adding/removing them from the mid-layer
4957 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_init_res_table()
4965 if (pinstance->cfg_table->flags & MICROCODE_UPDATE_REQUIRED) in pmcraid_init_res_table()
4968 fw_version = be16_to_cpu(pinstance->inq_data->fw_version); in pmcraid_init_res_table()
4970 /* resource list is protected by pinstance->resource_lock. in pmcraid_init_res_table()
4971 * init_res_table can be called from probe (user-thread) or runtime in pmcraid_init_res_table()
4974 spin_lock_irqsave(&pinstance->resource_lock, lock_flags); in pmcraid_init_res_table()
4976 list_for_each_entry_safe(res, temp, &pinstance->used_res_q, queue) in pmcraid_init_res_table()
4977 list_move_tail(&res->queue, &old_res); in pmcraid_init_res_table()
4979 for (i = 0; i < le16_to_cpu(pinstance->cfg_table->num_entries); i++) { in pmcraid_init_res_table()
4980 if (be16_to_cpu(pinstance->inq_data->fw_version) <= in pmcraid_init_res_table()
4982 cfgte = &pinstance->cfg_table->entries[i]; in pmcraid_init_res_table()
4985 &pinstance->cfg_table->entries_ext[i]; in pmcraid_init_res_table()
4995 rc = memcmp(&res->cfg_entry.resource_address, in pmcraid_init_res_table()
4996 &cfgte->resource_address, in pmcraid_init_res_table()
4997 sizeof(cfgte->resource_address)); in pmcraid_init_res_table()
4999 list_move_tail(&res->queue, in pmcraid_init_res_table()
5000 &pinstance->used_res_q); in pmcraid_init_res_table()
5009 if (list_empty(&pinstance->free_res_q)) { in pmcraid_init_res_table()
5015 res = list_entry(pinstance->free_res_q.next, in pmcraid_init_res_table()
5018 res->scsi_dev = NULL; in pmcraid_init_res_table()
5019 res->change_detected = RES_CHANGE_ADD; in pmcraid_init_res_table()
5020 res->reset_progress = 0; in pmcraid_init_res_table()
5021 list_move_tail(&res->queue, &pinstance->used_res_q); in pmcraid_init_res_table()
5028 memcpy(&res->cfg_entry, cfgte, in pmcraid_init_res_table()
5029 pinstance->config_table_entry_size); in pmcraid_init_res_table()
5031 res->cfg_entry.resource_type, in pmcraid_init_res_table()
5033 res->cfg_entry.unique_flags1 : in pmcraid_init_res_table()
5034 le16_to_cpu(res->cfg_entry.array_id) & 0xFF), in pmcraid_init_res_table()
5035 le32_to_cpu(res->cfg_entry.resource_address)); in pmcraid_init_res_table()
5039 /* Detect any deleted entries, mark them for deletion from mid-layer */ in pmcraid_init_res_table()
5042 if (res->scsi_dev) { in pmcraid_init_res_table()
5043 res->change_detected = RES_CHANGE_DEL; in pmcraid_init_res_table()
5044 res->cfg_entry.resource_handle = in pmcraid_init_res_table()
5046 list_move_tail(&res->queue, &pinstance->used_res_q); in pmcraid_init_res_table()
5048 list_move_tail(&res->queue, &pinstance->free_res_q); in pmcraid_init_res_table()
5053 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags); in pmcraid_init_res_table()
5058 * pmcraid_querycfg - Send a Query IOA Config to the adapter.
5069 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; in pmcraid_querycfg()
5071 struct pmcraid_instance *pinstance = cmd->drv_inst; in pmcraid_querycfg()
5074 if (be16_to_cpu(pinstance->inq_data->fw_version) <= in pmcraid_querycfg()
5076 pinstance->config_table_entry_size = in pmcraid_querycfg()
5079 pinstance->config_table_entry_size = in pmcraid_querycfg()
5082 ioarcb->request_type = REQ_TYPE_IOACMD; in pmcraid_querycfg()
5083 ioarcb->resource_handle = cpu_to_le32(PMCRAID_IOA_RES_HANDLE); in pmcraid_querycfg()
5085 ioarcb->cdb[0] = PMCRAID_QUERY_IOA_CONFIG; in pmcraid_querycfg()
5087 /* firmware requires 4-byte length field, specified in B.E format */ in pmcraid_querycfg()
5088 memcpy(&(ioarcb->cdb[10]), &cfg_table_size, sizeof(cfg_table_size)); in pmcraid_querycfg()
5093 ioarcb->ioadl_bus_addr = cpu_to_le64((cmd->ioa_cb_bus_addr) + in pmcraid_querycfg()
5096 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); in pmcraid_querycfg()
5097 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~0x1FULL); in pmcraid_querycfg()
5099 ioarcb->request_flags0 |= NO_LINK_DESCS; in pmcraid_querycfg()
5100 ioarcb->data_transfer_length = in pmcraid_querycfg()
5103 ioadl = &(ioarcb->add_data.u.ioadl[0]); in pmcraid_querycfg()
5104 ioadl->flags = IOADL_FLAGS_LAST_DESC; in pmcraid_querycfg()
5105 ioadl->address = cpu_to_le64(pinstance->cfg_table_bus_addr); in pmcraid_querycfg()
5106 ioadl->data_len = cpu_to_le32(sizeof(struct pmcraid_config_table)); in pmcraid_querycfg()
5114 * pmcraid_probe - PCI probe entry pointer for PMC MaxRAID controller driver
5120 * returns non-zero error code in case of any failure
5134 return -ENOMEM; in pmcraid_probe()
5141 dev_err(&pdev->dev, "Cannot enable adapter\n"); in pmcraid_probe()
5146 dev_info(&pdev->dev, in pmcraid_probe()
5148 pdev->vendor, pdev->device, in pmcraid_probe()
5154 dev_err(&pdev->dev, in pmcraid_probe()
5162 dev_err(&pdev->dev, "Couldn't map PCI registers memory\n"); in pmcraid_probe()
5163 rc = -ENOMEM; in pmcraid_probe()
5170 * 32-bit addressable range though it has 64-bit IOARRIN register. in pmcraid_probe()
5171 * However, firmware supports 64-bit streaming DMA buffers, whereas in pmcraid_probe()
5172 * coherent buffers are to be 32-bit. Since dma_alloc_coherent always in pmcraid_probe()
5177 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) in pmcraid_probe()
5178 rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_probe()
5180 /* firmware expects 32-bit DMA addresses for IOARRIN register; set 32 in pmcraid_probe()
5184 rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); in pmcraid_probe()
5187 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n"); in pmcraid_probe()
5195 dev_err(&pdev->dev, "scsi_host_alloc failed!\n"); in pmcraid_probe()
5196 rc = -ENOMEM; in pmcraid_probe()
5200 host->max_id = PMCRAID_MAX_NUM_TARGETS_PER_BUS; in pmcraid_probe()
5201 host->max_lun = PMCRAID_MAX_NUM_LUNS_PER_TARGET; in pmcraid_probe()
5202 host->unique_id = host->host_no; in pmcraid_probe()
5203 host->max_channel = PMCRAID_MAX_BUS_TO_SCAN; in pmcraid_probe()
5204 host->max_cmd_len = PMCRAID_MAX_CDB_LEN; in pmcraid_probe()
5207 pinstance = (struct pmcraid_instance *)host->hostdata; in pmcraid_probe()
5210 pinstance->chip_cfg = in pmcraid_probe()
5211 (struct pmcraid_chip_details *)(dev_id->driver_data); in pmcraid_probe()
5216 dev_err(&pdev->dev, "failed to initialize adapter instance\n"); in pmcraid_probe()
5222 /* Save PCI config-space for use following the reset */ in pmcraid_probe()
5223 rc = pci_save_state(pinstance->pdev); in pmcraid_probe()
5226 dev_err(&pdev->dev, "Failed to save PCI config space\n"); in pmcraid_probe()
5235 dev_err(&pdev->dev, "couldn't register interrupt handler\n"); in pmcraid_probe()
5259 dev_err(&pdev->dev, "couldn't initialize IOA\n"); in pmcraid_probe()
5264 /* Add adapter instance into mid-layer list */ in pmcraid_probe()
5265 rc = scsi_add_host(pinstance->host, &pdev->dev); in pmcraid_probe()
5267 pmcraid_err("couldn't add host into mid-layer: %d\n", rc); in pmcraid_probe()
5271 scsi_scan_host(pinstance->host); in pmcraid_probe()
5276 pmcraid_err("couldn't create mgmt interface, error: %x\n", in pmcraid_probe()
5284 atomic_set(&pinstance->expose_resources, 1); in pmcraid_probe()
5285 schedule_work(&pinstance->worker_q); in pmcraid_probe()
5310 return -ENODEV; in pmcraid_probe()
5328 * pmcraid_init - module load entry point
5382 * pmcraid_exit - module unload entry point