Lines Matching +full:host +full:- +full:port
1 // SPDX-License-Identifier: GPL-2.0-or-later
36 * process_cmd_err() - command error handler
44 struct afu *afu = cmd->parent; in process_cmd_err()
45 struct cxlflash_cfg *cfg = afu->parent; in process_cmd_err()
46 struct device *dev = &cfg->dev->dev; in process_cmd_err()
50 ioasa = &(cmd->sa); in process_cmd_err()
52 if (ioasa->rc.flags & SISL_RC_FLAGS_UNDERRUN) { in process_cmd_err()
53 resid = ioasa->resid; in process_cmd_err()
59 if (ioasa->rc.flags & SISL_RC_FLAGS_OVERRUN) { in process_cmd_err()
62 scp->result = (DID_ERROR << 16); in process_cmd_err()
67 ioasa->rc.afu_rc, ioasa->rc.scsi_rc, ioasa->rc.fc_rc, in process_cmd_err()
68 ioasa->afu_extra, ioasa->scsi_extra, ioasa->fc_extra); in process_cmd_err()
70 if (ioasa->rc.scsi_rc) { in process_cmd_err()
72 if (ioasa->rc.flags & SISL_RC_FLAGS_SENSE_VALID) { in process_cmd_err()
73 memcpy(scp->sense_buffer, ioasa->sense_data, in process_cmd_err()
75 scp->result = ioasa->rc.scsi_rc; in process_cmd_err()
77 scp->result = ioasa->rc.scsi_rc | (DID_ERROR << 16); in process_cmd_err()
81 * We encountered an error. Set scp->result based on nature in process_cmd_err()
84 if (ioasa->rc.fc_rc) { in process_cmd_err()
86 switch (ioasa->rc.fc_rc) { in process_cmd_err()
88 scp->result = (DID_REQUEUE << 16); in process_cmd_err()
92 if (!(ioasa->rc.flags & SISL_RC_FLAGS_OVERRUN)) { in process_cmd_err()
98 scp->result = (DID_ERROR << 16); in process_cmd_err()
111 scp->result = (DID_ERROR << 16); in process_cmd_err()
116 if (ioasa->rc.afu_rc) { in process_cmd_err()
118 switch (ioasa->rc.afu_rc) { in process_cmd_err()
120 scp->result = (DID_NO_CONNECT << 16); in process_cmd_err()
123 switch (ioasa->afu_extra) { in process_cmd_err()
126 scp->result = (DID_IMM_RETRY << 16); in process_cmd_err()
130 scp->result = (DID_ERROR << 16); in process_cmd_err()
135 scp->result = (DID_ALLOC_FAILURE << 16); in process_cmd_err()
138 scp->result = (DID_ERROR << 16); in process_cmd_err()
144 * cmd_complete() - command completion handler
156 struct afu *afu = cmd->parent; in cmd_complete()
157 struct cxlflash_cfg *cfg = afu->parent; in cmd_complete()
158 struct device *dev = &cfg->dev->dev; in cmd_complete()
159 struct hwq *hwq = get_hwq(afu, cmd->hwq_index); in cmd_complete()
161 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in cmd_complete()
162 list_del(&cmd->list); in cmd_complete()
163 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in cmd_complete()
165 if (cmd->scp) { in cmd_complete()
166 scp = cmd->scp; in cmd_complete()
167 if (unlikely(cmd->sa.ioasc)) in cmd_complete()
170 scp->result = (DID_OK << 16); in cmd_complete()
173 __func__, scp, scp->result, cmd->sa.ioasc); in cmd_complete()
174 scp->scsi_done(scp); in cmd_complete()
175 } else if (cmd->cmd_tmf) { in cmd_complete()
176 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in cmd_complete()
177 cfg->tmf_active = false; in cmd_complete()
178 wake_up_all_locked(&cfg->tmf_waitq); in cmd_complete()
179 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cmd_complete()
181 complete(&cmd->cevent); in cmd_complete()
185 * flush_pending_cmds() - flush all pending commands on this hardware queue
193 struct cxlflash_cfg *cfg = hwq->afu->parent; in flush_pending_cmds()
198 list_for_each_entry_safe(cmd, tmp, &hwq->pending_cmds, list) { in flush_pending_cmds()
200 if (!list_empty(&cmd->queue)) in flush_pending_cmds()
203 list_del(&cmd->list); in flush_pending_cmds()
205 if (cmd->scp) { in flush_pending_cmds()
206 scp = cmd->scp; in flush_pending_cmds()
207 scp->result = (DID_IMM_RETRY << 16); in flush_pending_cmds()
208 scp->scsi_done(scp); in flush_pending_cmds()
210 cmd->cmd_aborted = true; in flush_pending_cmds()
212 if (cmd->cmd_tmf) { in flush_pending_cmds()
213 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in flush_pending_cmds()
214 cfg->tmf_active = false; in flush_pending_cmds()
215 wake_up_all_locked(&cfg->tmf_waitq); in flush_pending_cmds()
216 spin_unlock_irqrestore(&cfg->tmf_slock, in flush_pending_cmds()
219 complete(&cmd->cevent); in flush_pending_cmds()
225 * context_reset() - reset context via specified register
233 * Return: 0 on success, -errno on failure
237 struct cxlflash_cfg *cfg = hwq->afu->parent; in context_reset()
238 struct device *dev = &cfg->dev->dev; in context_reset()
239 int rc = -ETIMEDOUT; in context_reset()
246 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in context_reset()
263 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in context_reset()
271 * context_reset_ioarrin() - reset context via IOARRIN register
274 * Return: 0 on success, -errno on failure
278 return context_reset(hwq, &hwq->host_map->ioarrin); in context_reset_ioarrin()
282 * context_reset_sq() - reset context via SQ_CONTEXT_RESET register
285 * Return: 0 on success, -errno on failure
289 return context_reset(hwq, &hwq->host_map->sq_ctx_reset); in context_reset_sq()
293 * send_cmd_ioarrin() - sends an AFU command via IOARRIN register
294 * @afu: AFU associated with the host.
302 struct cxlflash_cfg *cfg = afu->parent; in send_cmd_ioarrin()
303 struct device *dev = &cfg->dev->dev; in send_cmd_ioarrin()
304 struct hwq *hwq = get_hwq(afu, cmd->hwq_index); in send_cmd_ioarrin()
313 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in send_cmd_ioarrin()
314 if (--hwq->room < 0) { in send_cmd_ioarrin()
315 room = readq_be(&hwq->host_map->cmd_room); in send_cmd_ioarrin()
319 __func__, cmd->rcb.cdb[0], room); in send_cmd_ioarrin()
320 hwq->room = 0; in send_cmd_ioarrin()
324 hwq->room = room - 1; in send_cmd_ioarrin()
327 list_add(&cmd->list, &hwq->pending_cmds); in send_cmd_ioarrin()
328 writeq_be((u64)&cmd->rcb, &hwq->host_map->ioarrin); in send_cmd_ioarrin()
330 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in send_cmd_ioarrin()
332 __func__, cmd, cmd->rcb.data_len, cmd->rcb.data_ea, rc); in send_cmd_ioarrin()
337 * send_cmd_sq() - sends an AFU command via SQ ring
338 * @afu: AFU associated with the host.
346 struct cxlflash_cfg *cfg = afu->parent; in send_cmd_sq()
347 struct device *dev = &cfg->dev->dev; in send_cmd_sq()
348 struct hwq *hwq = get_hwq(afu, cmd->hwq_index); in send_cmd_sq()
353 newval = atomic_dec_if_positive(&hwq->hsq_credits); in send_cmd_sq()
359 cmd->rcb.ioasa = &cmd->sa; in send_cmd_sq()
361 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in send_cmd_sq()
363 *hwq->hsq_curr = cmd->rcb; in send_cmd_sq()
364 if (hwq->hsq_curr < hwq->hsq_end) in send_cmd_sq()
365 hwq->hsq_curr++; in send_cmd_sq()
367 hwq->hsq_curr = hwq->hsq_start; in send_cmd_sq()
369 list_add(&cmd->list, &hwq->pending_cmds); in send_cmd_sq()
370 writeq_be((u64)hwq->hsq_curr, &hwq->host_map->sq_tail); in send_cmd_sq()
372 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in send_cmd_sq()
375 "head=%016llx tail=%016llx\n", __func__, cmd, cmd->rcb.data_len, in send_cmd_sq()
376 cmd->rcb.data_ea, cmd->rcb.ioasa, rc, hwq->hsq_curr, in send_cmd_sq()
377 readq_be(&hwq->host_map->sq_head), in send_cmd_sq()
378 readq_be(&hwq->host_map->sq_tail)); in send_cmd_sq()
383 * wait_resp() - polls for a response or timeout to a sent AFU command
384 * @afu: AFU associated with the host.
387 * Return: 0 on success, -errno on failure
391 struct cxlflash_cfg *cfg = afu->parent; in wait_resp()
392 struct device *dev = &cfg->dev->dev; in wait_resp()
394 ulong timeout = msecs_to_jiffies(cmd->rcb.timeout * 2 * 1000); in wait_resp()
396 timeout = wait_for_completion_timeout(&cmd->cevent, timeout); in wait_resp()
398 rc = -ETIMEDOUT; in wait_resp()
400 if (cmd->cmd_aborted) in wait_resp()
401 rc = -EAGAIN; in wait_resp()
403 if (unlikely(cmd->sa.ioasc != 0)) { in wait_resp()
405 __func__, cmd->rcb.cdb[0], cmd->sa.ioasc); in wait_resp()
406 rc = -EIO; in wait_resp()
413 * cmd_to_target_hwq() - selects a target hardware queue for a SCSI command
414 * @host: SCSI host associated with device.
422 static u32 cmd_to_target_hwq(struct Scsi_Host *host, struct scsi_cmnd *scp, in cmd_to_target_hwq() argument
428 if (afu->num_hwqs == 1) in cmd_to_target_hwq()
431 switch (afu->hwq_mode) { in cmd_to_target_hwq()
433 hwq = afu->hwq_rr_count++ % afu->num_hwqs; in cmd_to_target_hwq()
436 tag = blk_mq_unique_tag(scp->request); in cmd_to_target_hwq()
440 hwq = smp_processor_id() % afu->num_hwqs; in cmd_to_target_hwq()
450 * send_tmf() - sends a Task Management Function (TMF)
451 * @cfg: Internal structure associated with the host.
456 * 0 on success, SCSI_MLQUEUE_HOST_BUSY or -errno on failure
461 struct afu *afu = cfg->afu; in send_tmf()
463 struct device *dev = &cfg->dev->dev; in send_tmf()
471 buf = kzalloc(sizeof(*cmd) + __alignof__(*cmd) - 1, GFP_KERNEL); in send_tmf()
474 rc = -ENOMEM; in send_tmf()
479 INIT_LIST_HEAD(&cmd->queue); in send_tmf()
482 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in send_tmf()
483 if (cfg->tmf_active) in send_tmf()
484 wait_event_interruptible_lock_irq(cfg->tmf_waitq, in send_tmf()
485 !cfg->tmf_active, in send_tmf()
486 cfg->tmf_slock); in send_tmf()
487 cfg->tmf_active = true; in send_tmf()
488 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in send_tmf()
490 cmd->parent = afu; in send_tmf()
491 cmd->cmd_tmf = true; in send_tmf()
492 cmd->hwq_index = hwq->index; in send_tmf()
494 cmd->rcb.ctx_id = hwq->ctx_hndl; in send_tmf()
495 cmd->rcb.msi = SISL_MSI_RRQ_UPDATED; in send_tmf()
496 cmd->rcb.port_sel = CHAN2PORTMASK(sdev->channel); in send_tmf()
497 cmd->rcb.lun_id = lun_to_lunid(sdev->lun); in send_tmf()
498 cmd->rcb.req_flags = (SISL_REQ_FLAGS_PORT_LUN_ID | in send_tmf()
501 memcpy(cmd->rcb.cdb, &tmfcmd, sizeof(tmfcmd)); in send_tmf()
503 rc = afu->send_cmd(afu, cmd); in send_tmf()
505 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in send_tmf()
506 cfg->tmf_active = false; in send_tmf()
507 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in send_tmf()
511 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in send_tmf()
513 to = wait_event_interruptible_lock_irq_timeout(cfg->tmf_waitq, in send_tmf()
514 !cfg->tmf_active, in send_tmf()
515 cfg->tmf_slock, in send_tmf()
519 rc = -ETIMEDOUT; in send_tmf()
521 } else if (cmd->cmd_aborted) { in send_tmf()
523 rc = -EAGAIN; in send_tmf()
524 } else if (cmd->sa.ioasc) { in send_tmf()
526 __func__, cmd->sa.ioasc); in send_tmf()
527 rc = -EIO; in send_tmf()
529 cfg->tmf_active = false; in send_tmf()
530 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in send_tmf()
533 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in send_tmf()
534 list_del(&cmd->list); in send_tmf()
535 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in send_tmf()
543 * cxlflash_driver_info() - information handler for this host driver
544 * @host: SCSI host associated with device.
548 static const char *cxlflash_driver_info(struct Scsi_Host *host) in cxlflash_driver_info() argument
554 * cxlflash_queuecommand() - sends a mid-layer request
555 * @host: SCSI host associated with device.
560 static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp) in cxlflash_queuecommand() argument
562 struct cxlflash_cfg *cfg = shost_priv(host); in cxlflash_queuecommand()
563 struct afu *afu = cfg->afu; in cxlflash_queuecommand()
564 struct device *dev = &cfg->dev->dev; in cxlflash_queuecommand()
567 int hwq_index = cmd_to_target_hwq(host, scp, afu); in cxlflash_queuecommand()
574 "cdb=(%08x-%08x-%08x-%08x)\n", in cxlflash_queuecommand()
575 __func__, scp, host->host_no, scp->device->channel, in cxlflash_queuecommand()
576 scp->device->id, scp->device->lun, in cxlflash_queuecommand()
577 get_unaligned_be32(&((u32 *)scp->cmnd)[0]), in cxlflash_queuecommand()
578 get_unaligned_be32(&((u32 *)scp->cmnd)[1]), in cxlflash_queuecommand()
579 get_unaligned_be32(&((u32 *)scp->cmnd)[2]), in cxlflash_queuecommand()
580 get_unaligned_be32(&((u32 *)scp->cmnd)[3])); in cxlflash_queuecommand()
586 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in cxlflash_queuecommand()
587 if (cfg->tmf_active) { in cxlflash_queuecommand()
588 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cxlflash_queuecommand()
592 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cxlflash_queuecommand()
594 switch (cfg->state) { in cxlflash_queuecommand()
603 scp->result = (DID_NO_CONNECT << 16); in cxlflash_queuecommand()
604 scp->scsi_done(scp); in cxlflash_queuecommand()
608 atomic_inc(&afu->cmds_active); in cxlflash_queuecommand()
613 cmd->rcb.data_len = sg->length; in cxlflash_queuecommand()
614 cmd->rcb.data_ea = (uintptr_t)sg_virt(sg); in cxlflash_queuecommand()
617 cmd->scp = scp; in cxlflash_queuecommand()
618 cmd->parent = afu; in cxlflash_queuecommand()
619 cmd->hwq_index = hwq_index; in cxlflash_queuecommand()
621 cmd->sa.ioasc = 0; in cxlflash_queuecommand()
622 cmd->rcb.ctx_id = hwq->ctx_hndl; in cxlflash_queuecommand()
623 cmd->rcb.msi = SISL_MSI_RRQ_UPDATED; in cxlflash_queuecommand()
624 cmd->rcb.port_sel = CHAN2PORTMASK(scp->device->channel); in cxlflash_queuecommand()
625 cmd->rcb.lun_id = lun_to_lunid(scp->device->lun); in cxlflash_queuecommand()
627 if (scp->sc_data_direction == DMA_TO_DEVICE) in cxlflash_queuecommand()
630 cmd->rcb.req_flags = req_flags; in cxlflash_queuecommand()
631 memcpy(cmd->rcb.cdb, scp->cmnd, sizeof(cmd->rcb.cdb)); in cxlflash_queuecommand()
633 rc = afu->send_cmd(afu, cmd); in cxlflash_queuecommand()
634 atomic_dec(&afu->cmds_active); in cxlflash_queuecommand()
640 * cxlflash_wait_for_pci_err_recovery() - wait for error recovery during probe
641 * @cfg: Internal structure associated with the host.
645 struct pci_dev *pdev = cfg->dev; in cxlflash_wait_for_pci_err_recovery()
648 wait_event_timeout(cfg->reset_waitq, in cxlflash_wait_for_pci_err_recovery()
654 * free_mem() - free memory associated with the AFU
655 * @cfg: Internal structure associated with the host.
659 struct afu *afu = cfg->afu; in free_mem()
661 if (cfg->afu) { in free_mem()
663 cfg->afu = NULL; in free_mem()
668 * cxlflash_reset_sync() - synchronizing point for asynchronous resets
669 * @cfg: Internal structure associated with the host.
673 if (cfg->async_reset_cookie == 0) in cxlflash_reset_sync()
677 async_synchronize_cookie(cfg->async_reset_cookie + 1); in cxlflash_reset_sync()
678 cfg->async_reset_cookie = 0; in cxlflash_reset_sync()
682 * stop_afu() - stops the AFU command timers and unmaps the MMIO space
683 * @cfg: Internal structure associated with the host.
692 struct afu *afu = cfg->afu; in stop_afu()
696 cancel_work_sync(&cfg->work_q); in stop_afu()
701 while (atomic_read(&afu->cmds_active)) in stop_afu()
705 for (i = 0; i < afu->num_hwqs; i++) { in stop_afu()
708 irq_poll_disable(&hwq->irqpoll); in stop_afu()
712 if (likely(afu->afu_map)) { in stop_afu()
713 cfg->ops->psa_unmap(afu->afu_map); in stop_afu()
714 afu->afu_map = NULL; in stop_afu()
720 * term_intr() - disables all AFU interrupts
721 * @cfg: Internal structure associated with the host.
730 struct afu *afu = cfg->afu; in term_intr()
731 struct device *dev = &cfg->dev->dev; in term_intr()
741 if (!hwq->ctx_cookie) { in term_intr()
750 cfg->ops->unmap_afu_irq(hwq->ctx_cookie, 3, hwq); in term_intr()
753 cfg->ops->unmap_afu_irq(hwq->ctx_cookie, 2, hwq); in term_intr()
756 cfg->ops->unmap_afu_irq(hwq->ctx_cookie, 1, hwq); in term_intr()
759 cfg->ops->free_afu_irqs(hwq->ctx_cookie); in term_intr()
768 * term_mc() - terminates the master context
769 * @cfg: Internal structure associated with the host.
776 struct afu *afu = cfg->afu; in term_mc()
777 struct device *dev = &cfg->dev->dev; in term_mc()
788 if (!hwq->ctx_cookie) { in term_mc()
793 WARN_ON(cfg->ops->stop_context(hwq->ctx_cookie)); in term_mc()
795 WARN_ON(cfg->ops->release_context(hwq->ctx_cookie)); in term_mc()
796 hwq->ctx_cookie = NULL; in term_mc()
798 spin_lock_irqsave(&hwq->hrrq_slock, lock_flags); in term_mc()
799 hwq->hrrq_online = false; in term_mc()
800 spin_unlock_irqrestore(&hwq->hrrq_slock, lock_flags); in term_mc()
802 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in term_mc()
804 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in term_mc()
808 * term_afu() - terminates the AFU
809 * @cfg: Internal structure associated with the host.
815 struct device *dev = &cfg->dev->dev; in term_afu()
827 for (k = cfg->afu->num_hwqs - 1; k >= 0; k--) in term_afu()
832 for (k = cfg->afu->num_hwqs - 1; k >= 0; k--) in term_afu()
839 * notify_shutdown() - notifies device of pending shutdown
840 * @cfg: Internal structure associated with the host.
850 struct afu *afu = cfg->afu; in notify_shutdown()
851 struct device *dev = &cfg->dev->dev; in notify_shutdown()
857 ddv = (struct dev_dependent_vals *)cfg->dev_id->driver_data; in notify_shutdown()
858 if (!(ddv->flags & CXLFLASH_NOTIFY_SHUTDOWN)) in notify_shutdown()
861 if (!afu || !afu->afu_map) { in notify_shutdown()
867 for (i = 0; i < cfg->num_fc_ports; i++) { in notify_shutdown()
879 for (i = 0; i < cfg->num_fc_ports; i++) { in notify_shutdown()
888 dev_dbg(dev, "%s: port %d shutdown processing " in notify_shutdown()
898 * cxlflash_get_minor() - gets the first available minor number
909 return -1; in cxlflash_get_minor()
917 * cxlflash_put_minor() - releases the minor number
926 * cxlflash_release_chrdev() - release the character device for the host
927 * @cfg: Internal structure associated with the host.
931 device_unregister(cfg->chardev); in cxlflash_release_chrdev()
932 cfg->chardev = NULL; in cxlflash_release_chrdev()
933 cdev_del(&cfg->cdev); in cxlflash_release_chrdev()
934 cxlflash_put_minor(MINOR(cfg->cdev.dev)); in cxlflash_release_chrdev()
938 * cxlflash_remove() - PCI entry point to tear down host
939 * @pdev: PCI device associated with the host.
947 struct device *dev = &pdev->dev; in cxlflash_remove()
956 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET && in cxlflash_remove()
957 cfg->state != STATE_PROBING); in cxlflash_remove()
958 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in cxlflash_remove()
959 if (cfg->tmf_active) in cxlflash_remove()
960 wait_event_interruptible_lock_irq(cfg->tmf_waitq, in cxlflash_remove()
961 !cfg->tmf_active, in cxlflash_remove()
962 cfg->tmf_slock); in cxlflash_remove()
963 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cxlflash_remove()
968 cfg->state = STATE_FAILTERM; in cxlflash_remove()
971 switch (cfg->init_state) { in cxlflash_remove()
977 scsi_remove_host(cfg->host); in cxlflash_remove()
983 cfg->ops->destroy_afu(cfg->afu_cookie); in cxlflash_remove()
988 scsi_host_put(cfg->host); in cxlflash_remove()
996 * alloc_mem() - allocates the AFU and its command pool
997 * @cfg: Internal structure associated with the host.
1003 * -ENOMEM on failure to allocate memory
1008 struct device *dev = &cfg->dev->dev; in alloc_mem()
1011 cfg->afu = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, in alloc_mem()
1013 if (unlikely(!cfg->afu)) { in alloc_mem()
1016 rc = -ENOMEM; in alloc_mem()
1019 cfg->afu->parent = cfg; in alloc_mem()
1020 cfg->afu->desired_hwqs = CXLFLASH_DEF_HWQS; in alloc_mem()
1021 cfg->afu->afu_map = NULL; in alloc_mem()
1027 * init_pci() - initializes the host as a PCI device
1028 * @cfg: Internal structure associated with the host.
1030 * Return: 0 on success, -errno on failure
1034 struct pci_dev *pdev = cfg->dev; in init_pci()
1035 struct device *dev = &cfg->dev->dev; in init_pci()
1058 * init_scsi() - adds the host to the SCSI stack and kicks off host scan
1059 * @cfg: Internal structure associated with the host.
1061 * Return: 0 on success, -errno on failure
1065 struct pci_dev *pdev = cfg->dev; in init_scsi()
1066 struct device *dev = &cfg->dev->dev; in init_scsi()
1069 rc = scsi_add_host(cfg->host, &pdev->dev); in init_scsi()
1075 scsi_scan_host(cfg->host); in init_scsi()
1083 * set_port_online() - transitions the specified host FC port to online state
1084 * @fc_regs: Top of MMIO region defined for specified port.
1101 * set_port_offline() - transitions the specified host FC port to offline state
1102 * @fc_regs: Top of MMIO region defined for specified port.
1117 * wait_port_online() - waits for the specified host FC port come online
1118 * @fc_regs: Top of MMIO region defined for specified port.
1119 * @delay_us: Number of microseconds to delay between reading port status.
1120 * @nretry: Number of cycles to retry reading port status.
1126 * TRUE (1) when the specified port is online
1127 * FALSE (0) when the specified port fails to come online after timeout
1141 nretry--); in wait_port_online()
1147 * wait_port_offline() - waits for the specified host FC port go offline
1148 * @fc_regs: Top of MMIO region defined for specified port.
1149 * @delay_us: Number of microseconds to delay between reading port status.
1150 * @nretry: Number of cycles to retry reading port status.
1155 * TRUE (1) when the specified port is offline
1156 * FALSE (0) when the specified port fails to go offline after timeout
1170 nretry--); in wait_port_offline()
1176 * afu_set_wwpn() - configures the WWPN for the specified host FC port
1177 * @afu: AFU associated with the host that owns the specified FC port.
1178 * @port: Port number being configured.
1179 * @fc_regs: Top of MMIO region defined for specified port.
1180 * @wwpn: The world-wide-port-number previously discovered for port.
1183 * sequence to configure the WWPN, the port is toggled offline and then back
1188 static void afu_set_wwpn(struct afu *afu, int port, __be64 __iomem *fc_regs, in afu_set_wwpn() argument
1191 struct cxlflash_cfg *cfg = afu->parent; in afu_set_wwpn()
1192 struct device *dev = &cfg->dev->dev; in afu_set_wwpn()
1197 dev_dbg(dev, "%s: wait on port %d to go offline timed out\n", in afu_set_wwpn()
1198 __func__, port); in afu_set_wwpn()
1206 dev_dbg(dev, "%s: wait on port %d to go online timed out\n", in afu_set_wwpn()
1207 __func__, port); in afu_set_wwpn()
1212 * afu_link_reset() - resets the specified host FC port
1213 * @afu: AFU associated with the host that owns the specified FC port.
1214 * @port: Port number being configured.
1215 * @fc_regs: Top of MMIO region defined for specified port.
1218 * reset the port involves toggling it offline and then back online. This
1220 * is made to maintain link with the device by switching to host to use
1221 * the alternate port exclusively while the reset takes place.
1224 static void afu_link_reset(struct afu *afu, int port, __be64 __iomem *fc_regs) in afu_link_reset() argument
1226 struct cxlflash_cfg *cfg = afu->parent; in afu_link_reset()
1227 struct device *dev = &cfg->dev->dev; in afu_link_reset()
1231 port_sel = readq_be(&afu->afu_map->global.regs.afu_port_sel); in afu_link_reset()
1232 port_sel &= ~(1ULL << port); in afu_link_reset()
1233 writeq_be(port_sel, &afu->afu_map->global.regs.afu_port_sel); in afu_link_reset()
1239 dev_err(dev, "%s: wait on port %d to go offline timed out\n", in afu_link_reset()
1240 __func__, port); in afu_link_reset()
1245 dev_err(dev, "%s: wait on port %d to go online timed out\n", in afu_link_reset()
1246 __func__, port); in afu_link_reset()
1248 /* switch back to include this port */ in afu_link_reset()
1249 port_sel |= (1ULL << port); in afu_link_reset()
1250 writeq_be(port_sel, &afu->afu_map->global.regs.afu_port_sel); in afu_link_reset()
1257 * afu_err_intr_init() - clears and initializes the AFU for error interrupts
1258 * @afu: AFU associated with the host.
1262 struct cxlflash_cfg *cfg = afu->parent; in afu_err_intr_init()
1276 writeq_be(-1ULL, &afu->afu_map->global.regs.aintr_mask); in afu_err_intr_init()
1278 reg = ((u64) (((hwq->ctx_hndl << 8) | SISL_MSI_ASYNC_ERROR)) << 40); in afu_err_intr_init()
1280 if (afu->internal_lun) in afu_err_intr_init()
1282 writeq_be(reg, &afu->afu_map->global.regs.afu_ctrl); in afu_err_intr_init()
1284 writeq_be(-1ULL, &afu->afu_map->global.regs.aintr_clear); in afu_err_intr_init()
1287 writeq_be(SISL_ASTATUS_MASK, &afu->afu_map->global.regs.aintr_mask); in afu_err_intr_init()
1290 writeq_be(-1ULL, &afu->afu_map->global.regs.aintr_clear); in afu_err_intr_init()
1296 if (afu->internal_lun) in afu_err_intr_init()
1297 reg |= ((u64)(afu->internal_lun - 1) << SISL_FC_INTERNAL_SHIFT); in afu_err_intr_init()
1301 for (i = 0; i < cfg->num_fc_ports; i++) { in afu_err_intr_init()
1314 for (i = 0; i < afu->num_hwqs; i++) { in afu_err_intr_init()
1317 reg = readq_be(&hwq->host_map->ctx_ctrl); in afu_err_intr_init()
1320 writeq_be(reg, &hwq->host_map->ctx_ctrl); in afu_err_intr_init()
1321 writeq_be(SISL_ISTATUS_MASK, &hwq->host_map->intr_mask); in afu_err_intr_init()
1326 * cxlflash_sync_err_irq() - interrupt handler for synchronous errors
1335 struct cxlflash_cfg *cfg = hwq->afu->parent; in cxlflash_sync_err_irq()
1336 struct device *dev = &cfg->dev->dev; in cxlflash_sync_err_irq()
1340 reg = readq_be(&hwq->host_map->intr_status); in cxlflash_sync_err_irq()
1352 writeq_be(reg_unmasked, &hwq->host_map->intr_clear); in cxlflash_sync_err_irq()
1359 * process_hrrq() - process the read-response queue
1360 * @afu: AFU associated with the host.
1370 struct afu *afu = hwq->afu; in process_hrrq()
1374 bool toggle = hwq->toggle; in process_hrrq()
1377 *hrrq_start = hwq->hrrq_start, in process_hrrq()
1378 *hrrq_end = hwq->hrrq_end, in process_hrrq()
1379 *hrrq_curr = hwq->hrrq_curr; in process_hrrq()
1398 list_add_tail(&cmd->queue, doneq); in process_hrrq()
1408 atomic_inc(&hwq->hsq_credits); in process_hrrq()
1415 hwq->hrrq_curr = hrrq_curr; in process_hrrq()
1416 hwq->toggle = toggle; in process_hrrq()
1422 * process_cmd_doneq() - process a queue of harvested RRQ commands
1438 * cxlflash_irqpoll() - process a queue of harvested RRQ commands
1451 spin_lock_irqsave(&hwq->hrrq_slock, hrrq_flags); in cxlflash_irqpoll()
1457 spin_unlock_irqrestore(&hwq->hrrq_slock, hrrq_flags); in cxlflash_irqpoll()
1464 * cxlflash_rrq_irq() - interrupt handler for read-response queue (normal path)
1473 struct afu *afu = hwq->afu; in cxlflash_rrq_irq()
1478 spin_lock_irqsave(&hwq->hrrq_slock, hrrq_flags); in cxlflash_rrq_irq()
1481 if (!hwq->hrrq_online) { in cxlflash_rrq_irq()
1482 spin_unlock_irqrestore(&hwq->hrrq_slock, hrrq_flags); in cxlflash_rrq_irq()
1487 irq_poll_sched(&hwq->irqpoll); in cxlflash_rrq_irq()
1488 spin_unlock_irqrestore(&hwq->hrrq_slock, hrrq_flags); in cxlflash_rrq_irq()
1492 num_entries = process_hrrq(hwq, &doneq, -1); in cxlflash_rrq_irq()
1493 spin_unlock_irqrestore(&hwq->hrrq_slock, hrrq_flags); in cxlflash_rrq_irq()
1506 * - Order matters here as this array is indexed by bit position.
1508 * - The checkpatch script considers the BUILD_SISL_ASTATUS_FC_PORT macro
1532 * cxlflash_async_err_irq() - interrupt handler for asynchronous errors
1541 struct afu *afu = hwq->afu; in cxlflash_async_err_irq()
1542 struct cxlflash_cfg *cfg = afu->parent; in cxlflash_async_err_irq()
1543 struct device *dev = &cfg->dev->dev; in cxlflash_async_err_irq()
1545 struct sisl_global_map __iomem *global = &afu->afu_map->global; in cxlflash_async_err_irq()
1550 u8 port; in cxlflash_async_err_irq() local
1552 reg = readq_be(&global->regs.aintr_status); in cxlflash_async_err_irq()
1562 writeq_be(reg_unmasked, &global->regs.aintr_clear); in cxlflash_async_err_irq()
1572 if (unlikely(info->status != 1ULL << bit)) { in cxlflash_async_err_irq()
1577 port = info->port; in cxlflash_async_err_irq()
1578 fc_port_regs = get_fc_port_regs(cfg, port); in cxlflash_async_err_irq()
1580 dev_err(dev, "%s: FC Port %d -> %s, fc_status=%016llx\n", in cxlflash_async_err_irq()
1581 __func__, port, info->desc, in cxlflash_async_err_irq()
1588 if (info->action & LINK_RESET) { in cxlflash_async_err_irq()
1589 dev_err(dev, "%s: FC Port %d: resetting link\n", in cxlflash_async_err_irq()
1590 __func__, port); in cxlflash_async_err_irq()
1591 cfg->lr_state = LINK_RESET_REQUIRED; in cxlflash_async_err_irq()
1592 cfg->lr_port = port; in cxlflash_async_err_irq()
1593 schedule_work(&cfg->work_q); in cxlflash_async_err_irq()
1596 if (info->action & CLR_FC_ERROR) { in cxlflash_async_err_irq()
1605 __func__, port, reg); in cxlflash_async_err_irq()
1611 if (info->action & SCAN_HOST) { in cxlflash_async_err_irq()
1612 atomic_inc(&cfg->scan_host_needed); in cxlflash_async_err_irq()
1613 schedule_work(&cfg->work_q); in cxlflash_async_err_irq()
1622 * read_vpd() - obtains the WWPNs from VPD
1623 * @cfg: Internal structure associated with the host.
1626 * Return: 0 on success, -errno on failure
1630 struct device *dev = &cfg->dev->dev; in read_vpd()
1631 struct pci_dev *pdev = cfg->dev; in read_vpd()
1638 cfg->dev_id->driver_data; in read_vpd()
1639 const bool wwpn_vpd_required = ddv->flags & CXLFLASH_WWPN_VPD_REQUIRED; in read_vpd()
1643 vpd_size = cfg->ops->read_adapter_vpd(pdev, vpd_data, sizeof(vpd_data)); in read_vpd()
1647 rc = -ENODEV; in read_vpd()
1655 dev_err(dev, "%s: VPD Read-only data not found\n", __func__); in read_vpd()
1656 rc = -ENODEV; in read_vpd()
1667 ro_size = vpd_size - i; in read_vpd()
1681 * in the VPD - cards requiring WWPN will not have their in read_vpd()
1684 for (k = 0; k < cfg->num_fc_ports; k++) { in read_vpd()
1691 dev_err(dev, "%s: Port %d WWPN not found\n", in read_vpd()
1700 dev_err(dev, "%s: Port %d WWPN incomplete or bad VPD\n", in read_vpd()
1702 rc = -ENODEV; in read_vpd()
1709 dev_err(dev, "%s: WWPN conversion failed for port %d\n", in read_vpd()
1711 rc = -ENODEV; in read_vpd()
1724 * init_pcr() - initialize the provisioning and control registers
1725 * @cfg: Internal structure associated with the host.
1732 struct afu *afu = cfg->afu; in init_pcr()
1739 ctrl_map = &afu->afu_map->ctrls[i].ctrl; in init_pcr()
1742 writeq_be(0, &ctrl_map->rht_start); in init_pcr()
1743 writeq_be(0, &ctrl_map->rht_cnt_id); in init_pcr()
1744 writeq_be(0, &ctrl_map->ctx_cap); in init_pcr()
1748 for (i = 0; i < afu->num_hwqs; i++) { in init_pcr()
1750 cookie = hwq->ctx_cookie; in init_pcr()
1752 hwq->ctx_hndl = (u16) cfg->ops->process_element(cookie); in init_pcr()
1753 hwq->host_map = &afu->afu_map->hosts[hwq->ctx_hndl].host; in init_pcr()
1754 hwq->ctrl_map = &afu->afu_map->ctrls[hwq->ctx_hndl].ctrl; in init_pcr()
1757 writeq_be(SISL_ENDIAN_CTRL, &hwq->host_map->endian_ctrl); in init_pcr()
1762 * init_global() - initialize AFU global registers
1763 * @cfg: Internal structure associated with the host.
1767 struct afu *afu = cfg->afu; in init_global()
1768 struct device *dev = &cfg->dev->dev; in init_global()
1786 for (i = 0; i < afu->num_hwqs; i++) { in init_global()
1788 hmap = hwq->host_map; in init_global()
1790 writeq_be((u64) hwq->hrrq_start, &hmap->rrq_start); in init_global()
1791 writeq_be((u64) hwq->hrrq_end, &hmap->rrq_end); in init_global()
1792 hwq->hrrq_online = true; in init_global()
1795 writeq_be((u64)hwq->hsq_start, &hmap->sq_start); in init_global()
1796 writeq_be((u64)hwq->hsq_end, &hmap->sq_end); in init_global()
1801 reg = readq_be(&afu->afu_map->global.regs.afu_config); in init_global()
1807 writeq_be(reg, &afu->afu_map->global.regs.afu_config); in init_global()
1809 /* Global port select: select either port */ in init_global()
1810 if (afu->internal_lun) { in init_global()
1811 /* Only use port 0 */ in init_global()
1812 writeq_be(PORT0, &afu->afu_map->global.regs.afu_port_sel); in init_global()
1815 writeq_be(PORT_MASK(cfg->num_fc_ports), in init_global()
1816 &afu->afu_map->global.regs.afu_port_sel); in init_global()
1817 num_ports = cfg->num_fc_ports; in init_global()
1840 for (i = 0; i < afu->num_hwqs; i++) { in init_global()
1842 ctx = hwq->ctx_cookie; in init_global()
1844 for (j = 0; j < hwq->num_irqs; j++) { in init_global()
1845 reg = cfg->ops->get_irq_objhndl(ctx, j); in init_global()
1846 writeq_be(reg, &hwq->ctrl_map->lisn_ea[j]); in init_global()
1849 reg = hwq->ctx_hndl; in init_global()
1851 &hwq->ctrl_map->lisn_pasid[0]); in init_global()
1853 &hwq->ctrl_map->lisn_pasid[1]); in init_global()
1857 /* Set up master's own CTX_CAP to allow real mode, host translation */ in init_global()
1860 for (i = 0; i < afu->num_hwqs; i++) { in init_global()
1863 (void)readq_be(&hwq->ctrl_map->mbox_r); /* unlock ctx_cap */ in init_global()
1867 &hwq->ctrl_map->ctx_cap); in init_global()
1871 * Determine write-same unmap support for host by evaluating the unmap in init_global()
1874 * in a context register, the outcome can be assumed to be host-wide. in init_global()
1877 reg = readq_be(&hwq->host_map->ctx_ctrl); in init_global()
1879 cfg->ws_unmap = true; in init_global()
1882 afu->hb = readq_be(&afu->afu_map->global.regs.afu_hb); in init_global()
1888 * start_afu() - initializes and starts the AFU
1889 * @cfg: Internal structure associated with the host.
1893 struct afu *afu = cfg->afu; in start_afu()
1894 struct device *dev = &cfg->dev->dev; in start_afu()
1902 for (i = 0; i < afu->num_hwqs; i++) { in start_afu()
1906 memset(&hwq->rrq_entry, 0, sizeof(hwq->rrq_entry)); in start_afu()
1909 hwq->hrrq_start = &hwq->rrq_entry[0]; in start_afu()
1910 hwq->hrrq_end = &hwq->rrq_entry[NUM_RRQ_ENTRY - 1]; in start_afu()
1911 hwq->hrrq_curr = hwq->hrrq_start; in start_afu()
1912 hwq->toggle = 1; in start_afu()
1915 spin_lock_init(&hwq->hrrq_slock); in start_afu()
1916 spin_lock_init(&hwq->hsq_slock); in start_afu()
1920 memset(&hwq->sq, 0, sizeof(hwq->sq)); in start_afu()
1921 hwq->hsq_start = &hwq->sq[0]; in start_afu()
1922 hwq->hsq_end = &hwq->sq[NUM_SQ_ENTRY - 1]; in start_afu()
1923 hwq->hsq_curr = hwq->hsq_start; in start_afu()
1925 atomic_set(&hwq->hsq_credits, NUM_SQ_ENTRY - 1); in start_afu()
1930 irq_poll_init(&hwq->irqpoll, afu->irqpoll_weight, in start_afu()
1942 * init_intr() - setup interrupt handlers for the master context
1943 * @cfg: Internal structure associated with the host.
1946 * Return: 0 on success, -errno on failure
1951 struct device *dev = &cfg->dev->dev; in init_intr()
1952 void *ctx = hwq->ctx_cookie; in init_intr()
1955 bool is_primary_hwq = (hwq->index == PRIMARY_HWQ); in init_intr()
1956 int num_irqs = hwq->num_irqs; in init_intr()
1958 rc = cfg->ops->allocate_afu_irqs(ctx, num_irqs); in init_intr()
1966 rc = cfg->ops->map_afu_irq(ctx, 1, cxlflash_sync_err_irq, hwq, in init_intr()
1974 rc = cfg->ops->map_afu_irq(ctx, 2, cxlflash_rrq_irq, hwq, in init_intr()
1986 rc = cfg->ops->map_afu_irq(ctx, 3, cxlflash_async_err_irq, hwq, in init_intr()
1998 * init_mc() - create and register as the master context
1999 * @cfg: Internal structure associated with the host.
2002 * Return: 0 on success, -errno on failure
2007 struct device *dev = &cfg->dev->dev; in init_mc()
2008 struct hwq *hwq = get_hwq(cfg->afu, index); in init_mc()
2013 hwq->afu = cfg->afu; in init_mc()
2014 hwq->index = index; in init_mc()
2015 INIT_LIST_HEAD(&hwq->pending_cmds); in init_mc()
2018 ctx = cfg->ops->get_context(cfg->dev, cfg->afu_cookie); in init_mc()
2021 ctx = cfg->ops->dev_context_init(cfg->dev, cfg->afu_cookie); in init_mc()
2025 rc = -ENOMEM; in init_mc()
2029 WARN_ON(hwq->ctx_cookie); in init_mc()
2030 hwq->ctx_cookie = ctx; in init_mc()
2031 hwq->num_irqs = num_irqs; in init_mc()
2034 cfg->ops->set_master(ctx); in init_mc()
2038 rc = cfg->ops->afu_reset(ctx); in init_mc()
2053 rc = cfg->ops->start_context(hwq->ctx_cookie); in init_mc()
2066 cfg->ops->release_context(ctx); in init_mc()
2068 hwq->ctx_cookie = NULL; in init_mc()
2073 * get_num_afu_ports() - determines and configures the number of AFU ports
2074 * @cfg: Internal structure associated with the host.
2077 * port selection mask. The converted value is only valid following an AFU
2078 * reset (explicit or power-on). This routine must be invoked shortly after
2083 * port mask (value read is 0), default to the number of ports originally
2084 * supported by the cxlflash driver (2) before hardware with other port
2089 struct afu *afu = cfg->afu; in get_num_afu_ports()
2090 struct device *dev = &cfg->dev->dev; in get_num_afu_ports()
2094 port_mask = readq_be(&afu->afu_map->global.regs.afu_port_sel); in get_num_afu_ports()
2101 cfg->num_fc_ports = num_fc_ports; in get_num_afu_ports()
2102 cfg->host->max_channel = PORTNUM2CHAN(num_fc_ports); in get_num_afu_ports()
2106 * init_afu() - setup as master context and start AFU
2107 * @cfg: Internal structure associated with the host.
2112 * Return: 0 on success, -errno on failure
2118 struct afu *afu = cfg->afu; in init_afu()
2119 struct device *dev = &cfg->dev->dev; in init_afu()
2123 cfg->ops->perst_reloads_same_image(cfg->afu_cookie, true); in init_afu()
2125 mutex_init(&afu->sync_active); in init_afu()
2126 afu->num_hwqs = afu->desired_hwqs; in init_afu()
2127 for (i = 0; i < afu->num_hwqs; i++) { in init_afu()
2138 afu->afu_map = cfg->ops->psa_map(hwq->ctx_cookie); in init_afu()
2139 if (!afu->afu_map) { in init_afu()
2141 rc = -ENOMEM; in init_afu()
2146 reg = readq(&afu->afu_map->global.regs.afu_version); in init_afu()
2147 memcpy(afu->version, ®, sizeof(reg)); in init_afu()
2148 afu->interface_version = in init_afu()
2149 readq_be(&afu->afu_map->global.regs.interface_version); in init_afu()
2150 if ((afu->interface_version + 1) == 0) { in init_afu()
2152 "interface version %016llx\n", afu->version, in init_afu()
2153 afu->interface_version); in init_afu()
2154 rc = -EINVAL; in init_afu()
2159 afu->send_cmd = send_cmd_sq; in init_afu()
2160 afu->context_reset = context_reset_sq; in init_afu()
2162 afu->send_cmd = send_cmd_ioarrin; in init_afu()
2163 afu->context_reset = context_reset_ioarrin; in init_afu()
2167 afu->version, afu->interface_version); in init_afu()
2177 afu_err_intr_init(cfg->afu); in init_afu()
2178 for (i = 0; i < afu->num_hwqs; i++) { in init_afu()
2181 hwq->room = readq_be(&hwq->host_map->cmd_room); in init_afu()
2191 for (i = afu->num_hwqs - 1; i >= 0; i--) { in init_afu()
2199 * afu_reset() - resets the AFU
2200 * @cfg: Internal structure associated with the host.
2202 * Return: 0 on success, -errno on failure
2206 struct device *dev = &cfg->dev->dev; in afu_reset()
2221 * drain_ioctls() - wait until all currently executing ioctls have completed
2222 * @cfg: Internal structure associated with the host.
2229 down_write(&cfg->ioctl_rwsem); in drain_ioctls()
2230 up_write(&cfg->ioctl_rwsem); in drain_ioctls()
2234 * cxlflash_async_reset_host() - asynchronous host reset handler
2241 struct device *dev = &cfg->dev->dev; in cxlflash_async_reset_host()
2244 if (cfg->state != STATE_RESET) { in cxlflash_async_reset_host()
2246 __func__, cfg->state); in cxlflash_async_reset_host()
2254 cfg->state = STATE_FAILTERM; in cxlflash_async_reset_host()
2256 cfg->state = STATE_NORMAL; in cxlflash_async_reset_host()
2257 wake_up_all(&cfg->reset_waitq); in cxlflash_async_reset_host()
2260 scsi_unblock_requests(cfg->host); in cxlflash_async_reset_host()
2264 * cxlflash_schedule_async_reset() - schedule an asynchronous host reset
2265 * @cfg: Internal structure associated with the host.
2269 struct device *dev = &cfg->dev->dev; in cxlflash_schedule_async_reset()
2271 if (cfg->state != STATE_NORMAL) { in cxlflash_schedule_async_reset()
2273 __func__, cfg->state); in cxlflash_schedule_async_reset()
2277 cfg->state = STATE_RESET; in cxlflash_schedule_async_reset()
2278 scsi_block_requests(cfg->host); in cxlflash_schedule_async_reset()
2279 cfg->async_reset_cookie = async_schedule(cxlflash_async_reset_host, in cxlflash_schedule_async_reset()
2284 * send_afu_cmd() - builds and sends an internal AFU command
2285 * @afu: AFU associated with the host.
2286 * @rcb: Pre-populated IOARCB describing command to send.
2297 * 0 on success, -errno on failure
2301 struct cxlflash_cfg *cfg = afu->parent; in send_afu_cmd()
2302 struct device *dev = &cfg->dev->dev; in send_afu_cmd()
2310 if (cfg->state != STATE_NORMAL) { in send_afu_cmd()
2312 __func__, cfg->state); in send_afu_cmd()
2316 mutex_lock(&afu->sync_active); in send_afu_cmd()
2317 atomic_inc(&afu->cmds_active); in send_afu_cmd()
2318 buf = kmalloc(sizeof(*cmd) + __alignof__(*cmd) - 1, GFP_KERNEL); in send_afu_cmd()
2321 rc = -ENOMEM; in send_afu_cmd()
2329 memcpy(&cmd->rcb, rcb, sizeof(*rcb)); in send_afu_cmd()
2330 INIT_LIST_HEAD(&cmd->queue); in send_afu_cmd()
2331 init_completion(&cmd->cevent); in send_afu_cmd()
2332 cmd->parent = afu; in send_afu_cmd()
2333 cmd->hwq_index = hwq->index; in send_afu_cmd()
2334 cmd->rcb.ctx_id = hwq->ctx_hndl; in send_afu_cmd()
2337 __func__, afu, cmd, cmd->rcb.cdb[0], nretry); in send_afu_cmd()
2339 rc = afu->send_cmd(afu, cmd); in send_afu_cmd()
2341 rc = -ENOBUFS; in send_afu_cmd()
2347 case -ETIMEDOUT: in send_afu_cmd()
2348 rc = afu->context_reset(hwq); in send_afu_cmd()
2351 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in send_afu_cmd()
2352 list_del(&cmd->list); in send_afu_cmd()
2353 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in send_afu_cmd()
2359 case -EAGAIN: in send_afu_cmd()
2367 if (rcb->ioasa) in send_afu_cmd()
2368 *rcb->ioasa = cmd->sa; in send_afu_cmd()
2370 atomic_dec(&afu->cmds_active); in send_afu_cmd()
2371 mutex_unlock(&afu->sync_active); in send_afu_cmd()
2378 * cxlflash_afu_sync() - builds and sends an AFU sync command
2379 * @afu: AFU associated with the host.
2391 * 0 on success, -errno on failure
2395 struct cxlflash_cfg *cfg = afu->parent; in cxlflash_afu_sync()
2396 struct device *dev = &cfg->dev->dev; in cxlflash_afu_sync()
2415 * cxlflash_eh_abort_handler() - abort a SCSI command
2427 struct Scsi_Host *host = scp->device->host; in cxlflash_eh_abort_handler() local
2428 struct cxlflash_cfg *cfg = shost_priv(host); in cxlflash_eh_abort_handler()
2430 struct device *dev = &cfg->dev->dev; in cxlflash_eh_abort_handler()
2431 struct afu *afu = cfg->afu; in cxlflash_eh_abort_handler()
2432 struct hwq *hwq = get_hwq(afu, cmd->hwq_index); in cxlflash_eh_abort_handler()
2435 "cdb=(%08x-%08x-%08x-%08x)\n", __func__, scp, host->host_no, in cxlflash_eh_abort_handler()
2436 scp->device->channel, scp->device->id, scp->device->lun, in cxlflash_eh_abort_handler()
2437 get_unaligned_be32(&((u32 *)scp->cmnd)[0]), in cxlflash_eh_abort_handler()
2438 get_unaligned_be32(&((u32 *)scp->cmnd)[1]), in cxlflash_eh_abort_handler()
2439 get_unaligned_be32(&((u32 *)scp->cmnd)[2]), in cxlflash_eh_abort_handler()
2440 get_unaligned_be32(&((u32 *)scp->cmnd)[3])); in cxlflash_eh_abort_handler()
2443 * Return failed and the mid-layer will invoke host reset handler. in cxlflash_eh_abort_handler()
2445 if (cfg->state != STATE_NORMAL) { in cxlflash_eh_abort_handler()
2447 __func__, cfg->state); in cxlflash_eh_abort_handler()
2451 rc = afu->context_reset(hwq); in cxlflash_eh_abort_handler()
2463 * cxlflash_eh_device_reset_handler() - reset a single LUN
2473 struct scsi_device *sdev = scp->device; in cxlflash_eh_device_reset_handler()
2474 struct Scsi_Host *host = sdev->host; in cxlflash_eh_device_reset_handler() local
2475 struct cxlflash_cfg *cfg = shost_priv(host); in cxlflash_eh_device_reset_handler()
2476 struct device *dev = &cfg->dev->dev; in cxlflash_eh_device_reset_handler()
2480 host->host_no, sdev->channel, sdev->id, sdev->lun); in cxlflash_eh_device_reset_handler()
2482 switch (cfg->state) { in cxlflash_eh_device_reset_handler()
2489 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); in cxlflash_eh_device_reset_handler()
2501 * cxlflash_eh_host_reset_handler() - reset the host adapter
2502 * @scp: SCSI command from stack identifying host.
2505 * during the reset. In such a scenario, the host reset will either yield
2517 struct Scsi_Host *host = scp->device->host; in cxlflash_eh_host_reset_handler() local
2518 struct cxlflash_cfg *cfg = shost_priv(host); in cxlflash_eh_host_reset_handler()
2519 struct device *dev = &cfg->dev->dev; in cxlflash_eh_host_reset_handler()
2521 dev_dbg(dev, "%s: %d\n", __func__, host->host_no); in cxlflash_eh_host_reset_handler()
2523 switch (cfg->state) { in cxlflash_eh_host_reset_handler()
2525 cfg->state = STATE_RESET; in cxlflash_eh_host_reset_handler()
2531 cfg->state = STATE_FAILTERM; in cxlflash_eh_host_reset_handler()
2533 cfg->state = STATE_NORMAL; in cxlflash_eh_host_reset_handler()
2534 wake_up_all(&cfg->reset_waitq); in cxlflash_eh_host_reset_handler()
2538 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); in cxlflash_eh_host_reset_handler()
2539 if (cfg->state == STATE_NORMAL) in cxlflash_eh_host_reset_handler()
2552 * cxlflash_change_queue_depth() - change the queue depth for the device
2567 return sdev->queue_depth; in cxlflash_change_queue_depth()
2571 * cxlflash_show_port_status() - queries and presents the current port status
2572 * @port: Desired port for status reporting.
2573 * @cfg: Internal structure associated with the host.
2574 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2576 * Return: The size of the ASCII string returned in @buf or -EINVAL.
2578 static ssize_t cxlflash_show_port_status(u32 port, in cxlflash_show_port_status() argument
2582 struct device *dev = &cfg->dev->dev; in cxlflash_show_port_status()
2587 WARN_ON(port >= MAX_FC_PORTS); in cxlflash_show_port_status()
2589 if (port >= cfg->num_fc_ports) { in cxlflash_show_port_status()
2590 dev_info(dev, "%s: Port %d not supported on this card.\n", in cxlflash_show_port_status()
2591 __func__, port); in cxlflash_show_port_status()
2592 return -EINVAL; in cxlflash_show_port_status()
2595 fc_port_regs = get_fc_port_regs(cfg, port); in cxlflash_show_port_status()
2610 * port0_show() - queries and presents the current status of port 0
2611 * @dev: Generic device associated with the host owning the port.
2612 * @attr: Device attribute representing the port.
2613 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2627 * port1_show() - queries and presents the current status of port 1
2628 * @dev: Generic device associated with the host owning the port.
2629 * @attr: Device attribute representing the port.
2630 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2644 * port2_show() - queries and presents the current status of port 2
2645 * @dev: Generic device associated with the host owning the port.
2646 * @attr: Device attribute representing the port.
2647 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2661 * port3_show() - queries and presents the current status of port 3
2662 * @dev: Generic device associated with the host owning the port.
2663 * @attr: Device attribute representing the port.
2664 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2678 * lun_mode_show() - presents the current LUN mode of the host
2679 * @dev: Generic device associated with the host.
2689 struct afu *afu = cfg->afu; in lun_mode_show()
2691 return scnprintf(buf, PAGE_SIZE, "%u\n", afu->internal_lun); in lun_mode_show()
2695 * lun_mode_store() - sets the LUN mode of the host
2696 * @dev: Generic device associated with the host.
2722 struct afu *afu = cfg->afu; in lun_mode_store()
2727 if (!rc && (lun_mode < 5) && (lun_mode != afu->internal_lun)) { in lun_mode_store()
2728 afu->internal_lun = lun_mode; in lun_mode_store()
2735 if (afu->internal_lun) in lun_mode_store()
2736 shost->max_channel = 0; in lun_mode_store()
2738 shost->max_channel = PORTNUM2CHAN(cfg->num_fc_ports); in lun_mode_store()
2741 scsi_scan_host(cfg->host); in lun_mode_store()
2748 * ioctl_version_show() - presents the current ioctl version of the host
2749 * @dev: Generic device associated with the host.
2762 bytes += scnprintf(buf + bytes, PAGE_SIZE - bytes, in ioctl_version_show()
2763 "host: %u\n", HT_CXLFLASH_VERSION_0); in ioctl_version_show()
2769 * cxlflash_show_port_lun_table() - queries and presents the port LUN table
2770 * @port: Desired port for status reporting.
2771 * @cfg: Internal structure associated with the host.
2772 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2774 * Return: The size of the ASCII string returned in @buf or -EINVAL.
2776 static ssize_t cxlflash_show_port_lun_table(u32 port, in cxlflash_show_port_lun_table() argument
2780 struct device *dev = &cfg->dev->dev; in cxlflash_show_port_lun_table()
2785 WARN_ON(port >= MAX_FC_PORTS); in cxlflash_show_port_lun_table()
2787 if (port >= cfg->num_fc_ports) { in cxlflash_show_port_lun_table()
2788 dev_info(dev, "%s: Port %d not supported on this card.\n", in cxlflash_show_port_lun_table()
2789 __func__, port); in cxlflash_show_port_lun_table()
2790 return -EINVAL; in cxlflash_show_port_lun_table()
2793 fc_port_luns = get_fc_port_luns(cfg, port); in cxlflash_show_port_lun_table()
2796 bytes += scnprintf(buf + bytes, PAGE_SIZE - bytes, in cxlflash_show_port_lun_table()
2803 * port0_lun_table_show() - presents the current LUN table of port 0
2804 * @dev: Generic device associated with the host owning the port.
2805 * @attr: Device attribute representing the port.
2806 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2820 * port1_lun_table_show() - presents the current LUN table of port 1
2821 * @dev: Generic device associated with the host owning the port.
2822 * @attr: Device attribute representing the port.
2823 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2837 * port2_lun_table_show() - presents the current LUN table of port 2
2838 * @dev: Generic device associated with the host owning the port.
2839 * @attr: Device attribute representing the port.
2840 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2854 * port3_lun_table_show() - presents the current LUN table of port 3
2855 * @dev: Generic device associated with the host owning the port.
2856 * @attr: Device attribute representing the port.
2857 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2871 * irqpoll_weight_show() - presents the current IRQ poll weight for the host
2872 * @dev: Generic device associated with the host.
2885 struct afu *afu = cfg->afu; in irqpoll_weight_show()
2887 return scnprintf(buf, PAGE_SIZE, "%u\n", afu->irqpoll_weight); in irqpoll_weight_show()
2891 * irqpoll_weight_store() - sets the current IRQ poll weight for the host
2892 * @dev: Generic device associated with the host.
2907 struct device *cfgdev = &cfg->dev->dev; in irqpoll_weight_store()
2908 struct afu *afu = cfg->afu; in irqpoll_weight_store()
2915 return -EINVAL; in irqpoll_weight_store()
2920 return -EINVAL; in irqpoll_weight_store()
2923 if (weight == afu->irqpoll_weight) { in irqpoll_weight_store()
2926 return -EINVAL; in irqpoll_weight_store()
2930 for (i = 0; i < afu->num_hwqs; i++) { in irqpoll_weight_store()
2933 irq_poll_disable(&hwq->irqpoll); in irqpoll_weight_store()
2937 afu->irqpoll_weight = weight; in irqpoll_weight_store()
2940 for (i = 0; i < afu->num_hwqs; i++) { in irqpoll_weight_store()
2943 irq_poll_init(&hwq->irqpoll, weight, cxlflash_irqpoll); in irqpoll_weight_store()
2951 * num_hwqs_show() - presents the number of hardware queues for the host
2952 * @dev: Generic device associated with the host.
2963 struct afu *afu = cfg->afu; in num_hwqs_show()
2965 return scnprintf(buf, PAGE_SIZE, "%u\n", afu->num_hwqs); in num_hwqs_show()
2969 * num_hwqs_store() - sets the number of hardware queues for the host
2970 * @dev: Generic device associated with the host.
2987 struct afu *afu = cfg->afu; in num_hwqs_store()
2993 return -EINVAL; in num_hwqs_store()
3002 afu->desired_hwqs = min(num_hwqs, CXLFLASH_MAX_HWQS); in num_hwqs_store()
3003 WARN_ON_ONCE(afu->desired_hwqs == 0); in num_hwqs_store()
3006 switch (cfg->state) { in num_hwqs_store()
3008 cfg->state = STATE_RESET; in num_hwqs_store()
3013 cfg->state = STATE_FAILTERM; in num_hwqs_store()
3015 cfg->state = STATE_NORMAL; in num_hwqs_store()
3016 wake_up_all(&cfg->reset_waitq); in num_hwqs_store()
3019 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); in num_hwqs_store()
3020 if (cfg->state == STATE_NORMAL) in num_hwqs_store()
3026 __func__, cfg->state); in num_hwqs_store()
3036 * hwq_mode_show() - presents the HWQ steering mode for the host
3037 * @dev: Generic device associated with the host.
3048 struct afu *afu = cfg->afu; in hwq_mode_show()
3050 return scnprintf(buf, PAGE_SIZE, "%s\n", hwq_mode_name[afu->hwq_mode]); in hwq_mode_show()
3054 * hwq_mode_store() - sets the HWQ steering mode for the host
3055 * @dev: Generic device associated with the host.
3061 * rr = Round-Robin
3073 struct device *cfgdev = &cfg->dev->dev; in hwq_mode_store()
3074 struct afu *afu = cfg->afu; in hwq_mode_store()
3087 return -EINVAL; in hwq_mode_store()
3090 afu->hwq_mode = mode; in hwq_mode_store()
3096 * mode_show() - presents the current mode of the device
3109 sdev->hostdata ? "superpipe" : "legacy"); in mode_show()
3113 * Host attributes
3157 * Host template
3172 .cmd_size = sizeof(struct afu_cmd) + __alignof__(struct afu_cmd) - 1,
3173 .this_id = -1,
3207 * cxlflash_worker_thread() - work thread handler for the AFU
3208 * @work: Work structure contained within cxlflash associated with host.
3211 * - Link reset which cannot be performed on interrupt context due to
3213 * - Rescan the host
3219 struct afu *afu = cfg->afu; in cxlflash_worker_thread()
3220 struct device *dev = &cfg->dev->dev; in cxlflash_worker_thread()
3222 int port; in cxlflash_worker_thread() local
3227 if (cfg->state != STATE_NORMAL) in cxlflash_worker_thread()
3230 spin_lock_irqsave(cfg->host->host_lock, lock_flags); in cxlflash_worker_thread()
3232 if (cfg->lr_state == LINK_RESET_REQUIRED) { in cxlflash_worker_thread()
3233 port = cfg->lr_port; in cxlflash_worker_thread()
3234 if (port < 0) in cxlflash_worker_thread()
3235 dev_err(dev, "%s: invalid port index %d\n", in cxlflash_worker_thread()
3236 __func__, port); in cxlflash_worker_thread()
3238 spin_unlock_irqrestore(cfg->host->host_lock, in cxlflash_worker_thread()
3242 fc_port_regs = get_fc_port_regs(cfg, port); in cxlflash_worker_thread()
3243 afu_link_reset(afu, port, fc_port_regs); in cxlflash_worker_thread()
3244 spin_lock_irqsave(cfg->host->host_lock, lock_flags); in cxlflash_worker_thread()
3247 cfg->lr_state = LINK_RESET_COMPLETE; in cxlflash_worker_thread()
3250 spin_unlock_irqrestore(cfg->host->host_lock, lock_flags); in cxlflash_worker_thread()
3252 if (atomic_dec_if_positive(&cfg->scan_host_needed) >= 0) in cxlflash_worker_thread()
3253 scsi_scan_host(cfg->host); in cxlflash_worker_thread()
3257 * cxlflash_chr_open() - character device open handler
3263 * Return: 0 on success, -errno on failure
3270 return -EACCES; in cxlflash_chr_open()
3272 cfg = container_of(inode->i_cdev, struct cxlflash_cfg, cdev); in cxlflash_chr_open()
3273 file->private_data = cfg; in cxlflash_chr_open()
3279 * decode_hioctl() - translates encoded host ioctl to easily identifiable string
3280 * @cmd: The host ioctl command to decode.
3282 * Return: A string identifying the decoded host ioctl.
3295 * cxlflash_lun_provision() - host LUN provisioning handler
3296 * @cfg: Internal structure associated with the host.
3299 * Return: 0 on success, -errno on failure
3304 struct afu *afu = cfg->afu; in cxlflash_lun_provision()
3305 struct device *dev = &cfg->dev->dev; in cxlflash_lun_provision()
3309 u16 port = lunprov->port; in cxlflash_lun_provision() local
3310 u16 scmd = lunprov->hdr.subcmd; in cxlflash_lun_provision()
3318 rc = -ENOTSUPP; in cxlflash_lun_provision()
3322 if (port >= cfg->num_fc_ports) { in cxlflash_lun_provision()
3323 rc = -EINVAL; in cxlflash_lun_provision()
3330 size = lunprov->size; in cxlflash_lun_provision()
3336 lun_id = lunprov->lun_id; in cxlflash_lun_provision()
3339 fc_port_regs = get_fc_port_regs(cfg, port); in cxlflash_lun_provision()
3342 lunprov->max_num_luns = reg; in cxlflash_lun_provision()
3344 lunprov->cur_num_luns = reg; in cxlflash_lun_provision()
3346 lunprov->max_cap_port = reg; in cxlflash_lun_provision()
3348 lunprov->cur_cap_port = reg; in cxlflash_lun_provision()
3352 rc = -EINVAL; in cxlflash_lun_provision()
3366 rcb.cdb[2] = port; in cxlflash_lun_provision()
3377 lunprov->lun_id = (u64)asa.lunid_hi << 32 | asa.lunid_lo; in cxlflash_lun_provision()
3378 memcpy(lunprov->wwid, asa.wwid, sizeof(lunprov->wwid)); in cxlflash_lun_provision()
3386 * cxlflash_afu_debug() - host AFU debug handler
3387 * @cfg: Internal structure associated with the host.
3393 * Return: 0 on success, -errno on failure
3398 struct afu *afu = cfg->afu; in cxlflash_afu_debug()
3399 struct device *dev = &cfg->dev->dev; in cxlflash_afu_debug()
3404 void __user *ubuf = (__force void __user *)afu_dbg->data_ea; in cxlflash_afu_debug()
3406 u32 ulen = afu_dbg->data_len; in cxlflash_afu_debug()
3407 bool is_write = afu_dbg->hdr.flags & HT_CXLFLASH_HOST_WRITE; in cxlflash_afu_debug()
3411 rc = -ENOTSUPP; in cxlflash_afu_debug()
3419 rc = -EINVAL; in cxlflash_afu_debug()
3423 buf = kmalloc(ulen + cache_line_size() - 1, GFP_KERNEL); in cxlflash_afu_debug()
3425 rc = -ENOMEM; in cxlflash_afu_debug()
3435 rc = -EFAULT; in cxlflash_afu_debug()
3455 memcpy(&rcb.cdb[4], afu_dbg->afu_subcmd, in cxlflash_afu_debug()
3467 rc = -EFAULT; in cxlflash_afu_debug()
3476 * cxlflash_chr_ioctl() - character device IOCTL handler
3489 * Return: 0 on success, -errno on failure
3496 struct cxlflash_cfg *cfg = file->private_data; in cxlflash_chr_ioctl()
3497 struct device *dev = &cfg->dev->dev; in cxlflash_chr_ioctl()
3518 down_read(&cfg->ioctl_rwsem); in cxlflash_chr_ioctl()
3527 idx = _IOC_NR(HT_CXLFLASH_LUN_PROVISION) - _IOC_NR(cmd); in cxlflash_chr_ioctl()
3536 rc = -EINVAL; in cxlflash_chr_ioctl()
3544 rc = -EFAULT; in cxlflash_chr_ioctl()
3549 if (hdr->version != HT_CXLFLASH_VERSION_0) { in cxlflash_chr_ioctl()
3551 __func__, hdr->version, decode_hioctl(cmd)); in cxlflash_chr_ioctl()
3552 rc = -EINVAL; in cxlflash_chr_ioctl()
3556 if (hdr->rsvd[0] || hdr->rsvd[1] || hdr->return_flags) { in cxlflash_chr_ioctl()
3558 rc = -EINVAL; in cxlflash_chr_ioctl()
3568 rc = -EFAULT; in cxlflash_chr_ioctl()
3574 up_read(&cfg->ioctl_rwsem); in cxlflash_chr_ioctl()
3595 * init_chrdev() - initialize the character device for the host
3596 * @cfg: Internal structure associated with the host.
3598 * Return: 0 on success, -errno on failure
3602 struct device *dev = &cfg->dev->dev; in init_chrdev()
3611 rc = -ENOSPC; in init_chrdev()
3616 cdev_init(&cfg->cdev, &cxlflash_chr_fops); in init_chrdev()
3618 rc = cdev_add(&cfg->cdev, devno, 1); in init_chrdev()
3633 cfg->chardev = char_dev; in init_chrdev()
3638 cdev_del(&cfg->cdev); in init_chrdev()
3645 * cxlflash_probe() - PCI entry point to add host
3646 * @pdev: PCI device associated with the host.
3658 * Return: 0 on success, -errno on failure
3663 struct Scsi_Host *host; in cxlflash_probe() local
3665 struct device *dev = &pdev->dev; in cxlflash_probe()
3670 dev_dbg(&pdev->dev, "%s: Found CXLFLASH with IRQ: %d\n", in cxlflash_probe()
3671 __func__, pdev->irq); in cxlflash_probe()
3673 ddv = (struct dev_dependent_vals *)dev_id->driver_data; in cxlflash_probe()
3674 driver_template.max_sectors = ddv->max_sectors; in cxlflash_probe()
3676 host = scsi_host_alloc(&driver_template, sizeof(struct cxlflash_cfg)); in cxlflash_probe()
3677 if (!host) { in cxlflash_probe()
3679 rc = -ENOMEM; in cxlflash_probe()
3683 host->max_id = CXLFLASH_MAX_NUM_TARGETS_PER_BUS; in cxlflash_probe()
3684 host->max_lun = CXLFLASH_MAX_NUM_LUNS_PER_TARGET; in cxlflash_probe()
3685 host->unique_id = host->host_no; in cxlflash_probe()
3686 host->max_cmd_len = CXLFLASH_MAX_CDB_LEN; in cxlflash_probe()
3688 cfg = shost_priv(host); in cxlflash_probe()
3689 cfg->state = STATE_PROBING; in cxlflash_probe()
3690 cfg->host = host; in cxlflash_probe()
3694 rc = -ENOMEM; in cxlflash_probe()
3695 scsi_host_put(cfg->host); in cxlflash_probe()
3699 cfg->init_state = INIT_STATE_NONE; in cxlflash_probe()
3700 cfg->dev = pdev; in cxlflash_probe()
3701 cfg->cxl_fops = cxlflash_cxl_fops; in cxlflash_probe()
3702 cfg->ops = cxlflash_assign_ops(ddv); in cxlflash_probe()
3703 WARN_ON_ONCE(!cfg->ops); in cxlflash_probe()
3712 cfg->promote_lun_index = 0; in cxlflash_probe()
3715 cfg->last_lun_index[k] = CXLFLASH_NUM_VLUNS/2 - 1; in cxlflash_probe()
3717 cfg->dev_id = (struct pci_device_id *)dev_id; in cxlflash_probe()
3719 init_waitqueue_head(&cfg->tmf_waitq); in cxlflash_probe()
3720 init_waitqueue_head(&cfg->reset_waitq); in cxlflash_probe()
3722 INIT_WORK(&cfg->work_q, cxlflash_worker_thread); in cxlflash_probe()
3723 cfg->lr_state = LINK_RESET_INVALID; in cxlflash_probe()
3724 cfg->lr_port = -1; in cxlflash_probe()
3725 spin_lock_init(&cfg->tmf_slock); in cxlflash_probe()
3726 mutex_init(&cfg->ctx_tbl_list_mutex); in cxlflash_probe()
3727 mutex_init(&cfg->ctx_recovery_mutex); in cxlflash_probe()
3728 init_rwsem(&cfg->ioctl_rwsem); in cxlflash_probe()
3729 INIT_LIST_HEAD(&cfg->ctx_err_recovery); in cxlflash_probe()
3730 INIT_LIST_HEAD(&cfg->lluns); in cxlflash_probe()
3739 cfg->init_state = INIT_STATE_PCI; in cxlflash_probe()
3741 cfg->afu_cookie = cfg->ops->create_afu(pdev); in cxlflash_probe()
3742 if (unlikely(!cfg->afu_cookie)) { in cxlflash_probe()
3744 rc = -ENOMEM; in cxlflash_probe()
3749 if (rc && !wq_has_sleeper(&cfg->reset_waitq)) { in cxlflash_probe()
3753 cfg->init_state = INIT_STATE_AFU; in cxlflash_probe()
3760 cfg->init_state = INIT_STATE_SCSI; in cxlflash_probe()
3767 cfg->init_state = INIT_STATE_CDEV; in cxlflash_probe()
3769 if (wq_has_sleeper(&cfg->reset_waitq)) { in cxlflash_probe()
3770 cfg->state = STATE_PROBED; in cxlflash_probe()
3771 wake_up_all(&cfg->reset_waitq); in cxlflash_probe()
3773 cfg->state = STATE_NORMAL; in cxlflash_probe()
3779 cfg->state = STATE_PROBED; in cxlflash_probe()
3785 * cxlflash_pci_error_detected() - called when a PCI error is detected
3799 struct device *dev = &cfg->dev->dev; in cxlflash_pci_error_detected()
3805 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET && in cxlflash_pci_error_detected()
3806 cfg->state != STATE_PROBING); in cxlflash_pci_error_detected()
3807 if (cfg->state == STATE_FAILTERM) in cxlflash_pci_error_detected()
3810 cfg->state = STATE_RESET; in cxlflash_pci_error_detected()
3811 scsi_block_requests(cfg->host); in cxlflash_pci_error_detected()
3820 cfg->state = STATE_FAILTERM; in cxlflash_pci_error_detected()
3821 wake_up_all(&cfg->reset_waitq); in cxlflash_pci_error_detected()
3822 scsi_unblock_requests(cfg->host); in cxlflash_pci_error_detected()
3831 * cxlflash_pci_slot_reset() - called when PCI slot has been reset
3843 struct device *dev = &cfg->dev->dev; in cxlflash_pci_slot_reset()
3857 * cxlflash_pci_resume() - called when normal operation can resume
3863 struct device *dev = &cfg->dev->dev; in cxlflash_pci_resume()
3867 cfg->state = STATE_NORMAL; in cxlflash_pci_resume()
3868 wake_up_all(&cfg->reset_waitq); in cxlflash_pci_resume()
3869 scsi_unblock_requests(cfg->host); in cxlflash_pci_resume()
3873 * cxlflash_devnode() - provides devtmpfs for devices in the cxlflash class
3885 * cxlflash_class_init() - create character device class
3887 * Return: 0 on success, -errno on failure
3909 cxlflash_class->devnode = cxlflash_devnode; in cxlflash_class_init()
3919 * cxlflash_class_exit() - destroy character device class
3948 * init_cxlflash() - module entry point
3950 * Return: 0 on success, -errno on failure
3974 * exit_cxlflash() - module exit point