Lines Matching +full:ascii +full:- +full:based
1 // SPDX-License-Identifier: GPL-2.0-or-later
41 * process_cmd_err() - command error handler
49 struct afu *afu = cmd->parent; in process_cmd_err()
50 struct cxlflash_cfg *cfg = afu->parent; in process_cmd_err()
51 struct device *dev = &cfg->dev->dev; in process_cmd_err()
55 ioasa = &(cmd->sa); in process_cmd_err()
57 if (ioasa->rc.flags & SISL_RC_FLAGS_UNDERRUN) { in process_cmd_err()
58 resid = ioasa->resid; in process_cmd_err()
64 if (ioasa->rc.flags & SISL_RC_FLAGS_OVERRUN) { in process_cmd_err()
67 scp->result = (DID_ERROR << 16); in process_cmd_err()
72 ioasa->rc.afu_rc, ioasa->rc.scsi_rc, ioasa->rc.fc_rc, in process_cmd_err()
73 ioasa->afu_extra, ioasa->scsi_extra, ioasa->fc_extra); in process_cmd_err()
75 if (ioasa->rc.scsi_rc) { in process_cmd_err()
77 if (ioasa->rc.flags & SISL_RC_FLAGS_SENSE_VALID) { in process_cmd_err()
78 memcpy(scp->sense_buffer, ioasa->sense_data, in process_cmd_err()
80 scp->result = ioasa->rc.scsi_rc; in process_cmd_err()
82 scp->result = ioasa->rc.scsi_rc | (DID_ERROR << 16); in process_cmd_err()
86 * We encountered an error. Set scp->result based on nature in process_cmd_err()
89 if (ioasa->rc.fc_rc) { in process_cmd_err()
91 switch (ioasa->rc.fc_rc) { in process_cmd_err()
93 scp->result = (DID_REQUEUE << 16); in process_cmd_err()
97 if (!(ioasa->rc.flags & SISL_RC_FLAGS_OVERRUN)) { in process_cmd_err()
103 scp->result = (DID_ERROR << 16); in process_cmd_err()
116 scp->result = (DID_ERROR << 16); in process_cmd_err()
121 if (ioasa->rc.afu_rc) { in process_cmd_err()
123 switch (ioasa->rc.afu_rc) { in process_cmd_err()
125 scp->result = (DID_NO_CONNECT << 16); in process_cmd_err()
128 switch (ioasa->afu_extra) { in process_cmd_err()
131 scp->result = (DID_IMM_RETRY << 16); in process_cmd_err()
135 scp->result = (DID_ERROR << 16); in process_cmd_err()
140 scp->result = (DID_ERROR << 16); in process_cmd_err()
143 scp->result = (DID_ERROR << 16); in process_cmd_err()
149 * cmd_complete() - command completion handler
161 struct afu *afu = cmd->parent; in cmd_complete()
162 struct cxlflash_cfg *cfg = afu->parent; in cmd_complete()
163 struct device *dev = &cfg->dev->dev; in cmd_complete()
164 struct hwq *hwq = get_hwq(afu, cmd->hwq_index); in cmd_complete()
166 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in cmd_complete()
167 list_del(&cmd->list); in cmd_complete()
168 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in cmd_complete()
170 if (cmd->scp) { in cmd_complete()
171 scp = cmd->scp; in cmd_complete()
172 if (unlikely(cmd->sa.ioasc)) in cmd_complete()
175 scp->result = (DID_OK << 16); in cmd_complete()
178 __func__, scp, scp->result, cmd->sa.ioasc); in cmd_complete()
180 } else if (cmd->cmd_tmf) { in cmd_complete()
181 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in cmd_complete()
182 cfg->tmf_active = false; in cmd_complete()
183 wake_up_all_locked(&cfg->tmf_waitq); in cmd_complete()
184 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cmd_complete()
186 complete(&cmd->cevent); in cmd_complete()
190 * flush_pending_cmds() - flush all pending commands on this hardware queue
198 struct cxlflash_cfg *cfg = hwq->afu->parent; in flush_pending_cmds()
203 list_for_each_entry_safe(cmd, tmp, &hwq->pending_cmds, list) { in flush_pending_cmds()
205 if (!list_empty(&cmd->queue)) in flush_pending_cmds()
208 list_del(&cmd->list); in flush_pending_cmds()
210 if (cmd->scp) { in flush_pending_cmds()
211 scp = cmd->scp; in flush_pending_cmds()
212 scp->result = (DID_IMM_RETRY << 16); in flush_pending_cmds()
215 cmd->cmd_aborted = true; in flush_pending_cmds()
217 if (cmd->cmd_tmf) { in flush_pending_cmds()
218 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in flush_pending_cmds()
219 cfg->tmf_active = false; in flush_pending_cmds()
220 wake_up_all_locked(&cfg->tmf_waitq); in flush_pending_cmds()
221 spin_unlock_irqrestore(&cfg->tmf_slock, in flush_pending_cmds()
224 complete(&cmd->cevent); in flush_pending_cmds()
230 * context_reset() - reset context via specified register
238 * Return: 0 on success, -errno on failure
242 struct cxlflash_cfg *cfg = hwq->afu->parent; in context_reset()
243 struct device *dev = &cfg->dev->dev; in context_reset()
244 int rc = -ETIMEDOUT; in context_reset()
251 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in context_reset()
268 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in context_reset()
276 * context_reset_ioarrin() - reset context via IOARRIN register
279 * Return: 0 on success, -errno on failure
283 return context_reset(hwq, &hwq->host_map->ioarrin); in context_reset_ioarrin()
287 * context_reset_sq() - reset context via SQ_CONTEXT_RESET register
290 * Return: 0 on success, -errno on failure
294 return context_reset(hwq, &hwq->host_map->sq_ctx_reset); in context_reset_sq()
298 * send_cmd_ioarrin() - sends an AFU command via IOARRIN register
307 struct cxlflash_cfg *cfg = afu->parent; in send_cmd_ioarrin()
308 struct device *dev = &cfg->dev->dev; in send_cmd_ioarrin()
309 struct hwq *hwq = get_hwq(afu, cmd->hwq_index); in send_cmd_ioarrin()
318 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in send_cmd_ioarrin()
319 if (--hwq->room < 0) { in send_cmd_ioarrin()
320 room = readq_be(&hwq->host_map->cmd_room); in send_cmd_ioarrin()
324 __func__, cmd->rcb.cdb[0], room); in send_cmd_ioarrin()
325 hwq->room = 0; in send_cmd_ioarrin()
329 hwq->room = room - 1; in send_cmd_ioarrin()
332 list_add(&cmd->list, &hwq->pending_cmds); in send_cmd_ioarrin()
333 writeq_be((u64)&cmd->rcb, &hwq->host_map->ioarrin); in send_cmd_ioarrin()
335 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in send_cmd_ioarrin()
337 __func__, cmd, cmd->rcb.data_len, cmd->rcb.data_ea, rc); in send_cmd_ioarrin()
342 * send_cmd_sq() - sends an AFU command via SQ ring
351 struct cxlflash_cfg *cfg = afu->parent; in send_cmd_sq()
352 struct device *dev = &cfg->dev->dev; in send_cmd_sq()
353 struct hwq *hwq = get_hwq(afu, cmd->hwq_index); in send_cmd_sq()
358 newval = atomic_dec_if_positive(&hwq->hsq_credits); in send_cmd_sq()
364 cmd->rcb.ioasa = &cmd->sa; in send_cmd_sq()
366 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in send_cmd_sq()
368 *hwq->hsq_curr = cmd->rcb; in send_cmd_sq()
369 if (hwq->hsq_curr < hwq->hsq_end) in send_cmd_sq()
370 hwq->hsq_curr++; in send_cmd_sq()
372 hwq->hsq_curr = hwq->hsq_start; in send_cmd_sq()
374 list_add(&cmd->list, &hwq->pending_cmds); in send_cmd_sq()
375 writeq_be((u64)hwq->hsq_curr, &hwq->host_map->sq_tail); in send_cmd_sq()
377 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in send_cmd_sq()
380 "head=%016llx tail=%016llx\n", __func__, cmd, cmd->rcb.data_len, in send_cmd_sq()
381 cmd->rcb.data_ea, cmd->rcb.ioasa, rc, hwq->hsq_curr, in send_cmd_sq()
382 readq_be(&hwq->host_map->sq_head), in send_cmd_sq()
383 readq_be(&hwq->host_map->sq_tail)); in send_cmd_sq()
388 * wait_resp() - polls for a response or timeout to a sent AFU command
392 * Return: 0 on success, -errno on failure
396 struct cxlflash_cfg *cfg = afu->parent; in wait_resp()
397 struct device *dev = &cfg->dev->dev; in wait_resp()
399 ulong timeout = msecs_to_jiffies(cmd->rcb.timeout * 2 * 1000); in wait_resp()
401 timeout = wait_for_completion_timeout(&cmd->cevent, timeout); in wait_resp()
403 rc = -ETIMEDOUT; in wait_resp()
405 if (cmd->cmd_aborted) in wait_resp()
406 rc = -EAGAIN; in wait_resp()
408 if (unlikely(cmd->sa.ioasc != 0)) { in wait_resp()
410 __func__, cmd->rcb.cdb[0], cmd->sa.ioasc); in wait_resp()
411 rc = -EIO; in wait_resp()
418 * cmd_to_target_hwq() - selects a target hardware queue for a SCSI command
423 * Hashes a command based upon the hardware queue mode.
433 if (afu->num_hwqs == 1) in cmd_to_target_hwq()
436 switch (afu->hwq_mode) { in cmd_to_target_hwq()
438 hwq = afu->hwq_rr_count++ % afu->num_hwqs; in cmd_to_target_hwq()
445 hwq = smp_processor_id() % afu->num_hwqs; in cmd_to_target_hwq()
455 * send_tmf() - sends a Task Management Function (TMF)
461 * 0 on success, SCSI_MLQUEUE_HOST_BUSY or -errno on failure
466 struct afu *afu = cfg->afu; in send_tmf()
468 struct device *dev = &cfg->dev->dev; in send_tmf()
476 buf = kzalloc(sizeof(*cmd) + __alignof__(*cmd) - 1, GFP_KERNEL); in send_tmf()
479 rc = -ENOMEM; in send_tmf()
484 INIT_LIST_HEAD(&cmd->queue); in send_tmf()
487 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in send_tmf()
488 if (cfg->tmf_active) in send_tmf()
489 wait_event_interruptible_lock_irq(cfg->tmf_waitq, in send_tmf()
490 !cfg->tmf_active, in send_tmf()
491 cfg->tmf_slock); in send_tmf()
492 cfg->tmf_active = true; in send_tmf()
493 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in send_tmf()
495 cmd->parent = afu; in send_tmf()
496 cmd->cmd_tmf = true; in send_tmf()
497 cmd->hwq_index = hwq->index; in send_tmf()
499 cmd->rcb.ctx_id = hwq->ctx_hndl; in send_tmf()
500 cmd->rcb.msi = SISL_MSI_RRQ_UPDATED; in send_tmf()
501 cmd->rcb.port_sel = CHAN2PORTMASK(sdev->channel); in send_tmf()
502 cmd->rcb.lun_id = lun_to_lunid(sdev->lun); in send_tmf()
503 cmd->rcb.req_flags = (SISL_REQ_FLAGS_PORT_LUN_ID | in send_tmf()
506 memcpy(cmd->rcb.cdb, &tmfcmd, sizeof(tmfcmd)); in send_tmf()
508 rc = afu->send_cmd(afu, cmd); in send_tmf()
510 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in send_tmf()
511 cfg->tmf_active = false; in send_tmf()
512 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in send_tmf()
516 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in send_tmf()
518 to = wait_event_interruptible_lock_irq_timeout(cfg->tmf_waitq, in send_tmf()
519 !cfg->tmf_active, in send_tmf()
520 cfg->tmf_slock, in send_tmf()
524 rc = -ETIMEDOUT; in send_tmf()
526 } else if (cmd->cmd_aborted) { in send_tmf()
528 rc = -EAGAIN; in send_tmf()
529 } else if (cmd->sa.ioasc) { in send_tmf()
531 __func__, cmd->sa.ioasc); in send_tmf()
532 rc = -EIO; in send_tmf()
534 cfg->tmf_active = false; in send_tmf()
535 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in send_tmf()
538 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in send_tmf()
539 list_del(&cmd->list); in send_tmf()
540 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in send_tmf()
548 * cxlflash_driver_info() - information handler for this host driver
559 * cxlflash_queuecommand() - sends a mid-layer request
568 struct afu *afu = cfg->afu; in cxlflash_queuecommand()
569 struct device *dev = &cfg->dev->dev; in cxlflash_queuecommand()
579 "cdb=(%08x-%08x-%08x-%08x)\n", in cxlflash_queuecommand()
580 __func__, scp, host->host_no, scp->device->channel, in cxlflash_queuecommand()
581 scp->device->id, scp->device->lun, in cxlflash_queuecommand()
582 get_unaligned_be32(&((u32 *)scp->cmnd)[0]), in cxlflash_queuecommand()
583 get_unaligned_be32(&((u32 *)scp->cmnd)[1]), in cxlflash_queuecommand()
584 get_unaligned_be32(&((u32 *)scp->cmnd)[2]), in cxlflash_queuecommand()
585 get_unaligned_be32(&((u32 *)scp->cmnd)[3])); in cxlflash_queuecommand()
591 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in cxlflash_queuecommand()
592 if (cfg->tmf_active) { in cxlflash_queuecommand()
593 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cxlflash_queuecommand()
597 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cxlflash_queuecommand()
599 switch (cfg->state) { in cxlflash_queuecommand()
608 scp->result = (DID_NO_CONNECT << 16); in cxlflash_queuecommand()
613 atomic_inc(&afu->cmds_active); in cxlflash_queuecommand()
618 cmd->rcb.data_len = sg->length; in cxlflash_queuecommand()
619 cmd->rcb.data_ea = (uintptr_t)sg_virt(sg); in cxlflash_queuecommand()
622 cmd->scp = scp; in cxlflash_queuecommand()
623 cmd->parent = afu; in cxlflash_queuecommand()
624 cmd->hwq_index = hwq_index; in cxlflash_queuecommand()
626 cmd->sa.ioasc = 0; in cxlflash_queuecommand()
627 cmd->rcb.ctx_id = hwq->ctx_hndl; in cxlflash_queuecommand()
628 cmd->rcb.msi = SISL_MSI_RRQ_UPDATED; in cxlflash_queuecommand()
629 cmd->rcb.port_sel = CHAN2PORTMASK(scp->device->channel); in cxlflash_queuecommand()
630 cmd->rcb.lun_id = lun_to_lunid(scp->device->lun); in cxlflash_queuecommand()
632 if (scp->sc_data_direction == DMA_TO_DEVICE) in cxlflash_queuecommand()
635 cmd->rcb.req_flags = req_flags; in cxlflash_queuecommand()
636 memcpy(cmd->rcb.cdb, scp->cmnd, sizeof(cmd->rcb.cdb)); in cxlflash_queuecommand()
638 rc = afu->send_cmd(afu, cmd); in cxlflash_queuecommand()
639 atomic_dec(&afu->cmds_active); in cxlflash_queuecommand()
645 * cxlflash_wait_for_pci_err_recovery() - wait for error recovery during probe
650 struct pci_dev *pdev = cfg->dev; in cxlflash_wait_for_pci_err_recovery()
653 wait_event_timeout(cfg->reset_waitq, in cxlflash_wait_for_pci_err_recovery()
659 * free_mem() - free memory associated with the AFU
664 struct afu *afu = cfg->afu; in free_mem()
666 if (cfg->afu) { in free_mem()
668 cfg->afu = NULL; in free_mem()
673 * cxlflash_reset_sync() - synchronizing point for asynchronous resets
678 if (cfg->async_reset_cookie == 0) in cxlflash_reset_sync()
682 async_synchronize_cookie(cfg->async_reset_cookie + 1); in cxlflash_reset_sync()
683 cfg->async_reset_cookie = 0; in cxlflash_reset_sync()
687 * stop_afu() - stops the AFU command timers and unmaps the MMIO space
697 struct afu *afu = cfg->afu; in stop_afu()
701 cancel_work_sync(&cfg->work_q); in stop_afu()
706 while (atomic_read(&afu->cmds_active)) in stop_afu()
710 for (i = 0; i < afu->num_hwqs; i++) { in stop_afu()
713 irq_poll_disable(&hwq->irqpoll); in stop_afu()
717 if (likely(afu->afu_map)) { in stop_afu()
718 cfg->ops->psa_unmap(afu->afu_map); in stop_afu()
719 afu->afu_map = NULL; in stop_afu()
725 * term_intr() - disables all AFU interrupts
735 struct afu *afu = cfg->afu; in term_intr()
736 struct device *dev = &cfg->dev->dev; in term_intr()
746 if (!hwq->ctx_cookie) { in term_intr()
755 cfg->ops->unmap_afu_irq(hwq->ctx_cookie, 3, hwq); in term_intr()
758 cfg->ops->unmap_afu_irq(hwq->ctx_cookie, 2, hwq); in term_intr()
761 cfg->ops->unmap_afu_irq(hwq->ctx_cookie, 1, hwq); in term_intr()
764 cfg->ops->free_afu_irqs(hwq->ctx_cookie); in term_intr()
773 * term_mc() - terminates the master context
781 struct afu *afu = cfg->afu; in term_mc()
782 struct device *dev = &cfg->dev->dev; in term_mc()
793 if (!hwq->ctx_cookie) { in term_mc()
798 WARN_ON(cfg->ops->stop_context(hwq->ctx_cookie)); in term_mc()
800 WARN_ON(cfg->ops->release_context(hwq->ctx_cookie)); in term_mc()
801 hwq->ctx_cookie = NULL; in term_mc()
803 spin_lock_irqsave(&hwq->hrrq_slock, lock_flags); in term_mc()
804 hwq->hrrq_online = false; in term_mc()
805 spin_unlock_irqrestore(&hwq->hrrq_slock, lock_flags); in term_mc()
807 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in term_mc()
809 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in term_mc()
813 * term_afu() - terminates the AFU
820 struct device *dev = &cfg->dev->dev; in term_afu()
832 for (k = cfg->afu->num_hwqs - 1; k >= 0; k--) in term_afu()
837 for (k = cfg->afu->num_hwqs - 1; k >= 0; k--) in term_afu()
844 * notify_shutdown() - notifies device of pending shutdown
855 struct afu *afu = cfg->afu; in notify_shutdown()
856 struct device *dev = &cfg->dev->dev; in notify_shutdown()
862 ddv = (struct dev_dependent_vals *)cfg->dev_id->driver_data; in notify_shutdown()
863 if (!(ddv->flags & CXLFLASH_NOTIFY_SHUTDOWN)) in notify_shutdown()
866 if (!afu || !afu->afu_map) { in notify_shutdown()
872 for (i = 0; i < cfg->num_fc_ports; i++) { in notify_shutdown()
884 for (i = 0; i < cfg->num_fc_ports; i++) { in notify_shutdown()
903 * cxlflash_get_minor() - gets the first available minor number
914 return -1; in cxlflash_get_minor()
922 * cxlflash_put_minor() - releases the minor number
931 * cxlflash_release_chrdev() - release the character device for the host
936 device_unregister(cfg->chardev); in cxlflash_release_chrdev()
937 cfg->chardev = NULL; in cxlflash_release_chrdev()
938 cdev_del(&cfg->cdev); in cxlflash_release_chrdev()
939 cxlflash_put_minor(MINOR(cfg->cdev.dev)); in cxlflash_release_chrdev()
943 * cxlflash_remove() - PCI entry point to tear down host
952 struct device *dev = &pdev->dev; in cxlflash_remove()
961 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET && in cxlflash_remove()
962 cfg->state != STATE_PROBING); in cxlflash_remove()
963 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in cxlflash_remove()
964 if (cfg->tmf_active) in cxlflash_remove()
965 wait_event_interruptible_lock_irq(cfg->tmf_waitq, in cxlflash_remove()
966 !cfg->tmf_active, in cxlflash_remove()
967 cfg->tmf_slock); in cxlflash_remove()
968 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cxlflash_remove()
973 cfg->state = STATE_FAILTERM; in cxlflash_remove()
976 switch (cfg->init_state) { in cxlflash_remove()
982 scsi_remove_host(cfg->host); in cxlflash_remove()
988 cfg->ops->destroy_afu(cfg->afu_cookie); in cxlflash_remove()
993 scsi_host_put(cfg->host); in cxlflash_remove()
1001 * alloc_mem() - allocates the AFU and its command pool
1008 * -ENOMEM on failure to allocate memory
1013 struct device *dev = &cfg->dev->dev; in alloc_mem()
1016 cfg->afu = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, in alloc_mem()
1018 if (unlikely(!cfg->afu)) { in alloc_mem()
1021 rc = -ENOMEM; in alloc_mem()
1024 cfg->afu->parent = cfg; in alloc_mem()
1025 cfg->afu->desired_hwqs = CXLFLASH_DEF_HWQS; in alloc_mem()
1026 cfg->afu->afu_map = NULL; in alloc_mem()
1032 * init_pci() - initializes the host as a PCI device
1035 * Return: 0 on success, -errno on failure
1039 struct pci_dev *pdev = cfg->dev; in init_pci()
1040 struct device *dev = &cfg->dev->dev; in init_pci()
1063 * init_scsi() - adds the host to the SCSI stack and kicks off host scan
1066 * Return: 0 on success, -errno on failure
1070 struct pci_dev *pdev = cfg->dev; in init_scsi()
1071 struct device *dev = &cfg->dev->dev; in init_scsi()
1074 rc = scsi_add_host(cfg->host, &pdev->dev); in init_scsi()
1080 scsi_scan_host(cfg->host); in init_scsi()
1088 * set_port_online() - transitions the specified host FC port to online state
1106 * set_port_offline() - transitions the specified host FC port to offline state
1122 * wait_port_online() - waits for the specified host FC port come online
1146 nretry--); in wait_port_online()
1152 * wait_port_offline() - waits for the specified host FC port go offline
1175 nretry--); in wait_port_offline()
1181 * afu_set_wwpn() - configures the WWPN for the specified host FC port
1185 * @wwpn: The world-wide-port-number previously discovered for port.
1196 struct cxlflash_cfg *cfg = afu->parent; in afu_set_wwpn()
1197 struct device *dev = &cfg->dev->dev; in afu_set_wwpn()
1217 * afu_link_reset() - resets the specified host FC port
1231 struct cxlflash_cfg *cfg = afu->parent; in afu_link_reset()
1232 struct device *dev = &cfg->dev->dev; in afu_link_reset()
1236 port_sel = readq_be(&afu->afu_map->global.regs.afu_port_sel); in afu_link_reset()
1238 writeq_be(port_sel, &afu->afu_map->global.regs.afu_port_sel); in afu_link_reset()
1255 writeq_be(port_sel, &afu->afu_map->global.regs.afu_port_sel); in afu_link_reset()
1262 * afu_err_intr_init() - clears and initializes the AFU for error interrupts
1267 struct cxlflash_cfg *cfg = afu->parent; in afu_err_intr_init()
1281 writeq_be(-1ULL, &afu->afu_map->global.regs.aintr_mask); in afu_err_intr_init()
1283 reg = ((u64) (((hwq->ctx_hndl << 8) | SISL_MSI_ASYNC_ERROR)) << 40); in afu_err_intr_init()
1285 if (afu->internal_lun) in afu_err_intr_init()
1287 writeq_be(reg, &afu->afu_map->global.regs.afu_ctrl); in afu_err_intr_init()
1289 writeq_be(-1ULL, &afu->afu_map->global.regs.aintr_clear); in afu_err_intr_init()
1292 writeq_be(SISL_ASTATUS_MASK, &afu->afu_map->global.regs.aintr_mask); in afu_err_intr_init()
1295 writeq_be(-1ULL, &afu->afu_map->global.regs.aintr_clear); in afu_err_intr_init()
1301 if (afu->internal_lun) in afu_err_intr_init()
1302 reg |= ((u64)(afu->internal_lun - 1) << SISL_FC_INTERNAL_SHIFT); in afu_err_intr_init()
1306 for (i = 0; i < cfg->num_fc_ports; i++) { in afu_err_intr_init()
1319 for (i = 0; i < afu->num_hwqs; i++) { in afu_err_intr_init()
1322 reg = readq_be(&hwq->host_map->ctx_ctrl); in afu_err_intr_init()
1325 writeq_be(reg, &hwq->host_map->ctx_ctrl); in afu_err_intr_init()
1326 writeq_be(SISL_ISTATUS_MASK, &hwq->host_map->intr_mask); in afu_err_intr_init()
1331 * cxlflash_sync_err_irq() - interrupt handler for synchronous errors
1340 struct cxlflash_cfg *cfg = hwq->afu->parent; in cxlflash_sync_err_irq()
1341 struct device *dev = &cfg->dev->dev; in cxlflash_sync_err_irq()
1345 reg = readq_be(&hwq->host_map->intr_status); in cxlflash_sync_err_irq()
1357 writeq_be(reg_unmasked, &hwq->host_map->intr_clear); in cxlflash_sync_err_irq()
1364 * process_hrrq() - process the read-response queue
1375 struct afu *afu = hwq->afu; in process_hrrq()
1379 bool toggle = hwq->toggle; in process_hrrq()
1382 *hrrq_start = hwq->hrrq_start, in process_hrrq()
1383 *hrrq_end = hwq->hrrq_end, in process_hrrq()
1384 *hrrq_curr = hwq->hrrq_curr; in process_hrrq()
1403 list_add_tail(&cmd->queue, doneq); in process_hrrq()
1413 atomic_inc(&hwq->hsq_credits); in process_hrrq()
1420 hwq->hrrq_curr = hrrq_curr; in process_hrrq()
1421 hwq->toggle = toggle; in process_hrrq()
1427 * process_cmd_doneq() - process a queue of harvested RRQ commands
1443 * cxlflash_irqpoll() - process a queue of harvested RRQ commands
1456 spin_lock_irqsave(&hwq->hrrq_slock, hrrq_flags); in cxlflash_irqpoll()
1462 spin_unlock_irqrestore(&hwq->hrrq_slock, hrrq_flags); in cxlflash_irqpoll()
1469 * cxlflash_rrq_irq() - interrupt handler for read-response queue (normal path)
1478 struct afu *afu = hwq->afu; in cxlflash_rrq_irq()
1483 spin_lock_irqsave(&hwq->hrrq_slock, hrrq_flags); in cxlflash_rrq_irq()
1486 if (!hwq->hrrq_online) { in cxlflash_rrq_irq()
1487 spin_unlock_irqrestore(&hwq->hrrq_slock, hrrq_flags); in cxlflash_rrq_irq()
1492 irq_poll_sched(&hwq->irqpoll); in cxlflash_rrq_irq()
1493 spin_unlock_irqrestore(&hwq->hrrq_slock, hrrq_flags); in cxlflash_rrq_irq()
1497 num_entries = process_hrrq(hwq, &doneq, -1); in cxlflash_rrq_irq()
1498 spin_unlock_irqrestore(&hwq->hrrq_slock, hrrq_flags); in cxlflash_rrq_irq()
1511 * - Order matters here as this array is indexed by bit position.
1513 * - The checkpatch script considers the BUILD_SISL_ASTATUS_FC_PORT macro
1537 * cxlflash_async_err_irq() - interrupt handler for asynchronous errors
1546 struct afu *afu = hwq->afu; in cxlflash_async_err_irq()
1547 struct cxlflash_cfg *cfg = afu->parent; in cxlflash_async_err_irq()
1548 struct device *dev = &cfg->dev->dev; in cxlflash_async_err_irq()
1550 struct sisl_global_map __iomem *global = &afu->afu_map->global; in cxlflash_async_err_irq()
1557 reg = readq_be(&global->regs.aintr_status); in cxlflash_async_err_irq()
1567 writeq_be(reg_unmasked, &global->regs.aintr_clear); in cxlflash_async_err_irq()
1577 if (unlikely(info->status != 1ULL << bit)) { in cxlflash_async_err_irq()
1582 port = info->port; in cxlflash_async_err_irq()
1585 dev_err(dev, "%s: FC Port %d -> %s, fc_status=%016llx\n", in cxlflash_async_err_irq()
1586 __func__, port, info->desc, in cxlflash_async_err_irq()
1593 if (info->action & LINK_RESET) { in cxlflash_async_err_irq()
1596 cfg->lr_state = LINK_RESET_REQUIRED; in cxlflash_async_err_irq()
1597 cfg->lr_port = port; in cxlflash_async_err_irq()
1598 schedule_work(&cfg->work_q); in cxlflash_async_err_irq()
1601 if (info->action & CLR_FC_ERROR) { in cxlflash_async_err_irq()
1616 if (info->action & SCAN_HOST) { in cxlflash_async_err_irq()
1617 atomic_inc(&cfg->scan_host_needed); in cxlflash_async_err_irq()
1618 schedule_work(&cfg->work_q); in cxlflash_async_err_irq()
1627 * read_vpd() - obtains the WWPNs from VPD
1631 * Return: 0 on success, -errno on failure
1635 struct device *dev = &cfg->dev->dev; in read_vpd()
1636 struct pci_dev *pdev = cfg->dev; in read_vpd()
1643 cfg->dev_id->driver_data; in read_vpd()
1644 const bool wwpn_vpd_required = ddv->flags & CXLFLASH_WWPN_VPD_REQUIRED; in read_vpd()
1648 vpd_size = cfg->ops->read_adapter_vpd(pdev, vpd_data, sizeof(vpd_data)); in read_vpd()
1652 rc = -ENODEV; in read_vpd()
1659 * no good to us). Convert the ASCII data to an integer in read_vpd()
1661 * because the conversion service requires that the ASCII in read_vpd()
1667 * in the VPD - cards requiring WWPN will not have their in read_vpd()
1670 for (k = 0; k < cfg->num_fc_ports; k++) { in read_vpd()
1673 if (i == -ENOENT) { in read_vpd()
1684 rc = -ENODEV; in read_vpd()
1693 rc = -ENODEV; in read_vpd()
1706 * init_pcr() - initialize the provisioning and control registers
1714 struct afu *afu = cfg->afu; in init_pcr()
1721 ctrl_map = &afu->afu_map->ctrls[i].ctrl; in init_pcr()
1724 writeq_be(0, &ctrl_map->rht_start); in init_pcr()
1725 writeq_be(0, &ctrl_map->rht_cnt_id); in init_pcr()
1726 writeq_be(0, &ctrl_map->ctx_cap); in init_pcr()
1730 for (i = 0; i < afu->num_hwqs; i++) { in init_pcr()
1732 cookie = hwq->ctx_cookie; in init_pcr()
1734 hwq->ctx_hndl = (u16) cfg->ops->process_element(cookie); in init_pcr()
1735 hwq->host_map = &afu->afu_map->hosts[hwq->ctx_hndl].host; in init_pcr()
1736 hwq->ctrl_map = &afu->afu_map->ctrls[hwq->ctx_hndl].ctrl; in init_pcr()
1739 writeq_be(SISL_ENDIAN_CTRL, &hwq->host_map->endian_ctrl); in init_pcr()
1744 * init_global() - initialize AFU global registers
1749 struct afu *afu = cfg->afu; in init_global()
1750 struct device *dev = &cfg->dev->dev; in init_global()
1768 for (i = 0; i < afu->num_hwqs; i++) { in init_global()
1770 hmap = hwq->host_map; in init_global()
1772 writeq_be((u64) hwq->hrrq_start, &hmap->rrq_start); in init_global()
1773 writeq_be((u64) hwq->hrrq_end, &hmap->rrq_end); in init_global()
1774 hwq->hrrq_online = true; in init_global()
1777 writeq_be((u64)hwq->hsq_start, &hmap->sq_start); in init_global()
1778 writeq_be((u64)hwq->hsq_end, &hmap->sq_end); in init_global()
1783 reg = readq_be(&afu->afu_map->global.regs.afu_config); in init_global()
1789 writeq_be(reg, &afu->afu_map->global.regs.afu_config); in init_global()
1792 if (afu->internal_lun) { in init_global()
1794 writeq_be(PORT0, &afu->afu_map->global.regs.afu_port_sel); in init_global()
1797 writeq_be(PORT_MASK(cfg->num_fc_ports), in init_global()
1798 &afu->afu_map->global.regs.afu_port_sel); in init_global()
1799 num_ports = cfg->num_fc_ports; in init_global()
1822 for (i = 0; i < afu->num_hwqs; i++) { in init_global()
1824 ctx = hwq->ctx_cookie; in init_global()
1826 for (j = 0; j < hwq->num_irqs; j++) { in init_global()
1827 reg = cfg->ops->get_irq_objhndl(ctx, j); in init_global()
1828 writeq_be(reg, &hwq->ctrl_map->lisn_ea[j]); in init_global()
1831 reg = hwq->ctx_hndl; in init_global()
1833 &hwq->ctrl_map->lisn_pasid[0]); in init_global()
1835 &hwq->ctrl_map->lisn_pasid[1]); in init_global()
1842 for (i = 0; i < afu->num_hwqs; i++) { in init_global()
1845 (void)readq_be(&hwq->ctrl_map->mbox_r); /* unlock ctx_cap */ in init_global()
1849 &hwq->ctrl_map->ctx_cap); in init_global()
1853 * Determine write-same unmap support for host by evaluating the unmap in init_global()
1856 * in a context register, the outcome can be assumed to be host-wide. in init_global()
1859 reg = readq_be(&hwq->host_map->ctx_ctrl); in init_global()
1861 cfg->ws_unmap = true; in init_global()
1864 afu->hb = readq_be(&afu->afu_map->global.regs.afu_hb); in init_global()
1870 * start_afu() - initializes and starts the AFU
1875 struct afu *afu = cfg->afu; in start_afu()
1876 struct device *dev = &cfg->dev->dev; in start_afu()
1884 for (i = 0; i < afu->num_hwqs; i++) { in start_afu()
1888 memset(&hwq->rrq_entry, 0, sizeof(hwq->rrq_entry)); in start_afu()
1891 hwq->hrrq_start = &hwq->rrq_entry[0]; in start_afu()
1892 hwq->hrrq_end = &hwq->rrq_entry[NUM_RRQ_ENTRY - 1]; in start_afu()
1893 hwq->hrrq_curr = hwq->hrrq_start; in start_afu()
1894 hwq->toggle = 1; in start_afu()
1897 spin_lock_init(&hwq->hrrq_slock); in start_afu()
1898 spin_lock_init(&hwq->hsq_slock); in start_afu()
1902 memset(&hwq->sq, 0, sizeof(hwq->sq)); in start_afu()
1903 hwq->hsq_start = &hwq->sq[0]; in start_afu()
1904 hwq->hsq_end = &hwq->sq[NUM_SQ_ENTRY - 1]; in start_afu()
1905 hwq->hsq_curr = hwq->hsq_start; in start_afu()
1907 atomic_set(&hwq->hsq_credits, NUM_SQ_ENTRY - 1); in start_afu()
1912 irq_poll_init(&hwq->irqpoll, afu->irqpoll_weight, in start_afu()
1924 * init_intr() - setup interrupt handlers for the master context
1928 * Return: 0 on success, -errno on failure
1933 struct device *dev = &cfg->dev->dev; in init_intr()
1934 void *ctx = hwq->ctx_cookie; in init_intr()
1937 bool is_primary_hwq = (hwq->index == PRIMARY_HWQ); in init_intr()
1938 int num_irqs = hwq->num_irqs; in init_intr()
1940 rc = cfg->ops->allocate_afu_irqs(ctx, num_irqs); in init_intr()
1948 rc = cfg->ops->map_afu_irq(ctx, 1, cxlflash_sync_err_irq, hwq, in init_intr()
1956 rc = cfg->ops->map_afu_irq(ctx, 2, cxlflash_rrq_irq, hwq, in init_intr()
1968 rc = cfg->ops->map_afu_irq(ctx, 3, cxlflash_async_err_irq, hwq, in init_intr()
1980 * init_mc() - create and register as the master context
1984 * Return: 0 on success, -errno on failure
1989 struct device *dev = &cfg->dev->dev; in init_mc()
1990 struct hwq *hwq = get_hwq(cfg->afu, index); in init_mc()
1995 hwq->afu = cfg->afu; in init_mc()
1996 hwq->index = index; in init_mc()
1997 INIT_LIST_HEAD(&hwq->pending_cmds); in init_mc()
2000 ctx = cfg->ops->get_context(cfg->dev, cfg->afu_cookie); in init_mc()
2003 ctx = cfg->ops->dev_context_init(cfg->dev, cfg->afu_cookie); in init_mc()
2007 rc = -ENOMEM; in init_mc()
2011 WARN_ON(hwq->ctx_cookie); in init_mc()
2012 hwq->ctx_cookie = ctx; in init_mc()
2013 hwq->num_irqs = num_irqs; in init_mc()
2016 cfg->ops->set_master(ctx); in init_mc()
2020 rc = cfg->ops->afu_reset(ctx); in init_mc()
2035 rc = cfg->ops->start_context(hwq->ctx_cookie); in init_mc()
2048 cfg->ops->release_context(ctx); in init_mc()
2050 hwq->ctx_cookie = NULL; in init_mc()
2055 * get_num_afu_ports() - determines and configures the number of AFU ports
2060 * reset (explicit or power-on). This routine must be invoked shortly after
2071 struct afu *afu = cfg->afu; in get_num_afu_ports()
2072 struct device *dev = &cfg->dev->dev; in get_num_afu_ports()
2076 port_mask = readq_be(&afu->afu_map->global.regs.afu_port_sel); in get_num_afu_ports()
2083 cfg->num_fc_ports = num_fc_ports; in get_num_afu_ports()
2084 cfg->host->max_channel = PORTNUM2CHAN(num_fc_ports); in get_num_afu_ports()
2088 * init_afu() - setup as master context and start AFU
2094 * Return: 0 on success, -errno on failure
2100 struct afu *afu = cfg->afu; in init_afu()
2101 struct device *dev = &cfg->dev->dev; in init_afu()
2105 cfg->ops->perst_reloads_same_image(cfg->afu_cookie, true); in init_afu()
2107 mutex_init(&afu->sync_active); in init_afu()
2108 afu->num_hwqs = afu->desired_hwqs; in init_afu()
2109 for (i = 0; i < afu->num_hwqs; i++) { in init_afu()
2120 afu->afu_map = cfg->ops->psa_map(hwq->ctx_cookie); in init_afu()
2121 if (!afu->afu_map) { in init_afu()
2123 rc = -ENOMEM; in init_afu()
2128 reg = readq(&afu->afu_map->global.regs.afu_version); in init_afu()
2129 memcpy(afu->version, ®, sizeof(reg)); in init_afu()
2130 afu->interface_version = in init_afu()
2131 readq_be(&afu->afu_map->global.regs.interface_version); in init_afu()
2132 if ((afu->interface_version + 1) == 0) { in init_afu()
2134 "interface version %016llx\n", afu->version, in init_afu()
2135 afu->interface_version); in init_afu()
2136 rc = -EINVAL; in init_afu()
2141 afu->send_cmd = send_cmd_sq; in init_afu()
2142 afu->context_reset = context_reset_sq; in init_afu()
2144 afu->send_cmd = send_cmd_ioarrin; in init_afu()
2145 afu->context_reset = context_reset_ioarrin; in init_afu()
2149 afu->version, afu->interface_version); in init_afu()
2159 afu_err_intr_init(cfg->afu); in init_afu()
2160 for (i = 0; i < afu->num_hwqs; i++) { in init_afu()
2163 hwq->room = readq_be(&hwq->host_map->cmd_room); in init_afu()
2173 for (i = afu->num_hwqs - 1; i >= 0; i--) { in init_afu()
2181 * afu_reset() - resets the AFU
2184 * Return: 0 on success, -errno on failure
2188 struct device *dev = &cfg->dev->dev; in afu_reset()
2203 * drain_ioctls() - wait until all currently executing ioctls have completed
2211 down_write(&cfg->ioctl_rwsem); in drain_ioctls()
2212 up_write(&cfg->ioctl_rwsem); in drain_ioctls()
2216 * cxlflash_async_reset_host() - asynchronous host reset handler
2223 struct device *dev = &cfg->dev->dev; in cxlflash_async_reset_host()
2226 if (cfg->state != STATE_RESET) { in cxlflash_async_reset_host()
2228 __func__, cfg->state); in cxlflash_async_reset_host()
2236 cfg->state = STATE_FAILTERM; in cxlflash_async_reset_host()
2238 cfg->state = STATE_NORMAL; in cxlflash_async_reset_host()
2239 wake_up_all(&cfg->reset_waitq); in cxlflash_async_reset_host()
2242 scsi_unblock_requests(cfg->host); in cxlflash_async_reset_host()
2246 * cxlflash_schedule_async_reset() - schedule an asynchronous host reset
2251 struct device *dev = &cfg->dev->dev; in cxlflash_schedule_async_reset()
2253 if (cfg->state != STATE_NORMAL) { in cxlflash_schedule_async_reset()
2255 __func__, cfg->state); in cxlflash_schedule_async_reset()
2259 cfg->state = STATE_RESET; in cxlflash_schedule_async_reset()
2260 scsi_block_requests(cfg->host); in cxlflash_schedule_async_reset()
2261 cfg->async_reset_cookie = async_schedule(cxlflash_async_reset_host, in cxlflash_schedule_async_reset()
2266 * send_afu_cmd() - builds and sends an internal AFU command
2268 * @rcb: Pre-populated IOARCB describing command to send.
2279 * 0 on success, -errno on failure
2283 struct cxlflash_cfg *cfg = afu->parent; in send_afu_cmd()
2284 struct device *dev = &cfg->dev->dev; in send_afu_cmd()
2292 if (cfg->state != STATE_NORMAL) { in send_afu_cmd()
2294 __func__, cfg->state); in send_afu_cmd()
2298 mutex_lock(&afu->sync_active); in send_afu_cmd()
2299 atomic_inc(&afu->cmds_active); in send_afu_cmd()
2300 buf = kmalloc(sizeof(*cmd) + __alignof__(*cmd) - 1, GFP_KERNEL); in send_afu_cmd()
2303 rc = -ENOMEM; in send_afu_cmd()
2311 memcpy(&cmd->rcb, rcb, sizeof(*rcb)); in send_afu_cmd()
2312 INIT_LIST_HEAD(&cmd->queue); in send_afu_cmd()
2313 init_completion(&cmd->cevent); in send_afu_cmd()
2314 cmd->parent = afu; in send_afu_cmd()
2315 cmd->hwq_index = hwq->index; in send_afu_cmd()
2316 cmd->rcb.ctx_id = hwq->ctx_hndl; in send_afu_cmd()
2319 __func__, afu, cmd, cmd->rcb.cdb[0], nretry); in send_afu_cmd()
2321 rc = afu->send_cmd(afu, cmd); in send_afu_cmd()
2323 rc = -ENOBUFS; in send_afu_cmd()
2329 case -ETIMEDOUT: in send_afu_cmd()
2330 rc = afu->context_reset(hwq); in send_afu_cmd()
2333 spin_lock_irqsave(&hwq->hsq_slock, lock_flags); in send_afu_cmd()
2334 list_del(&cmd->list); in send_afu_cmd()
2335 spin_unlock_irqrestore(&hwq->hsq_slock, lock_flags); in send_afu_cmd()
2341 case -EAGAIN: in send_afu_cmd()
2349 if (rcb->ioasa) in send_afu_cmd()
2350 *rcb->ioasa = cmd->sa; in send_afu_cmd()
2352 atomic_dec(&afu->cmds_active); in send_afu_cmd()
2353 mutex_unlock(&afu->sync_active); in send_afu_cmd()
2360 * cxlflash_afu_sync() - builds and sends an AFU sync command
2373 * 0 on success, -errno on failure
2377 struct cxlflash_cfg *cfg = afu->parent; in cxlflash_afu_sync()
2378 struct device *dev = &cfg->dev->dev; in cxlflash_afu_sync()
2397 * cxlflash_eh_abort_handler() - abort a SCSI command
2409 struct Scsi_Host *host = scp->device->host; in cxlflash_eh_abort_handler()
2412 struct device *dev = &cfg->dev->dev; in cxlflash_eh_abort_handler()
2413 struct afu *afu = cfg->afu; in cxlflash_eh_abort_handler()
2414 struct hwq *hwq = get_hwq(afu, cmd->hwq_index); in cxlflash_eh_abort_handler()
2417 "cdb=(%08x-%08x-%08x-%08x)\n", __func__, scp, host->host_no, in cxlflash_eh_abort_handler()
2418 scp->device->channel, scp->device->id, scp->device->lun, in cxlflash_eh_abort_handler()
2419 get_unaligned_be32(&((u32 *)scp->cmnd)[0]), in cxlflash_eh_abort_handler()
2420 get_unaligned_be32(&((u32 *)scp->cmnd)[1]), in cxlflash_eh_abort_handler()
2421 get_unaligned_be32(&((u32 *)scp->cmnd)[2]), in cxlflash_eh_abort_handler()
2422 get_unaligned_be32(&((u32 *)scp->cmnd)[3])); in cxlflash_eh_abort_handler()
2425 * Return failed and the mid-layer will invoke host reset handler. in cxlflash_eh_abort_handler()
2427 if (cfg->state != STATE_NORMAL) { in cxlflash_eh_abort_handler()
2429 __func__, cfg->state); in cxlflash_eh_abort_handler()
2433 rc = afu->context_reset(hwq); in cxlflash_eh_abort_handler()
2445 * cxlflash_eh_device_reset_handler() - reset a single LUN
2455 struct scsi_device *sdev = scp->device; in cxlflash_eh_device_reset_handler()
2456 struct Scsi_Host *host = sdev->host; in cxlflash_eh_device_reset_handler()
2458 struct device *dev = &cfg->dev->dev; in cxlflash_eh_device_reset_handler()
2462 host->host_no, sdev->channel, sdev->id, sdev->lun); in cxlflash_eh_device_reset_handler()
2464 switch (cfg->state) { in cxlflash_eh_device_reset_handler()
2471 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); in cxlflash_eh_device_reset_handler()
2483 * cxlflash_eh_host_reset_handler() - reset the host adapter
2488 * until the EEH recovery is complete or return success or failure based
2499 struct Scsi_Host *host = scp->device->host; in cxlflash_eh_host_reset_handler()
2501 struct device *dev = &cfg->dev->dev; in cxlflash_eh_host_reset_handler()
2503 dev_dbg(dev, "%s: %d\n", __func__, host->host_no); in cxlflash_eh_host_reset_handler()
2505 switch (cfg->state) { in cxlflash_eh_host_reset_handler()
2507 cfg->state = STATE_RESET; in cxlflash_eh_host_reset_handler()
2513 cfg->state = STATE_FAILTERM; in cxlflash_eh_host_reset_handler()
2515 cfg->state = STATE_NORMAL; in cxlflash_eh_host_reset_handler()
2516 wake_up_all(&cfg->reset_waitq); in cxlflash_eh_host_reset_handler()
2520 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); in cxlflash_eh_host_reset_handler()
2521 if (cfg->state == STATE_NORMAL) in cxlflash_eh_host_reset_handler()
2534 * cxlflash_change_queue_depth() - change the queue depth for the device
2549 return sdev->queue_depth; in cxlflash_change_queue_depth()
2553 * cxlflash_show_port_status() - queries and presents the current port status
2556 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2558 * Return: The size of the ASCII string returned in @buf or -EINVAL.
2564 struct device *dev = &cfg->dev->dev; in cxlflash_show_port_status()
2571 if (port >= cfg->num_fc_ports) { in cxlflash_show_port_status()
2574 return -EINVAL; in cxlflash_show_port_status()
2592 * port0_show() - queries and presents the current status of port 0
2595 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2597 * Return: The size of the ASCII string returned in @buf.
2609 * port1_show() - queries and presents the current status of port 1
2612 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2614 * Return: The size of the ASCII string returned in @buf.
2626 * port2_show() - queries and presents the current status of port 2
2629 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2631 * Return: The size of the ASCII string returned in @buf.
2643 * port3_show() - queries and presents the current status of port 3
2646 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2648 * Return: The size of the ASCII string returned in @buf.
2660 * lun_mode_show() - presents the current LUN mode of the host
2663 * @buf: Buffer of length PAGE_SIZE to report back the LUN mode in ASCII.
2665 * Return: The size of the ASCII string returned in @buf.
2671 struct afu *afu = cfg->afu; in lun_mode_show()
2673 return scnprintf(buf, PAGE_SIZE, "%u\n", afu->internal_lun); in lun_mode_show()
2677 * lun_mode_store() - sets the LUN mode of the host
2680 * @buf: Buffer of length PAGE_SIZE containing the LUN mode in ASCII.
2696 * Return: The size of the ASCII string returned in @buf.
2704 struct afu *afu = cfg->afu; in lun_mode_store()
2709 if (!rc && (lun_mode < 5) && (lun_mode != afu->internal_lun)) { in lun_mode_store()
2710 afu->internal_lun = lun_mode; in lun_mode_store()
2717 if (afu->internal_lun) in lun_mode_store()
2718 shost->max_channel = 0; in lun_mode_store()
2720 shost->max_channel = PORTNUM2CHAN(cfg->num_fc_ports); in lun_mode_store()
2723 scsi_scan_host(cfg->host); in lun_mode_store()
2730 * ioctl_version_show() - presents the current ioctl version of the host
2735 * Return: The size of the ASCII string returned in @buf.
2744 bytes += scnprintf(buf + bytes, PAGE_SIZE - bytes, in ioctl_version_show()
2751 * cxlflash_show_port_lun_table() - queries and presents the port LUN table
2754 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2756 * Return: The size of the ASCII string returned in @buf or -EINVAL.
2762 struct device *dev = &cfg->dev->dev; in cxlflash_show_port_lun_table()
2769 if (port >= cfg->num_fc_ports) { in cxlflash_show_port_lun_table()
2772 return -EINVAL; in cxlflash_show_port_lun_table()
2778 bytes += scnprintf(buf + bytes, PAGE_SIZE - bytes, in cxlflash_show_port_lun_table()
2785 * port0_lun_table_show() - presents the current LUN table of port 0
2788 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2790 * Return: The size of the ASCII string returned in @buf.
2802 * port1_lun_table_show() - presents the current LUN table of port 1
2805 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2807 * Return: The size of the ASCII string returned in @buf.
2819 * port2_lun_table_show() - presents the current LUN table of port 2
2822 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2824 * Return: The size of the ASCII string returned in @buf.
2836 * port3_lun_table_show() - presents the current LUN table of port 3
2839 * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
2841 * Return: The size of the ASCII string returned in @buf.
2853 * irqpoll_weight_show() - presents the current IRQ poll weight for the host
2857 * weight in ASCII.
2861 * Return: The size of the ASCII string returned in @buf.
2867 struct afu *afu = cfg->afu; in irqpoll_weight_show()
2869 return scnprintf(buf, PAGE_SIZE, "%u\n", afu->irqpoll_weight); in irqpoll_weight_show()
2873 * irqpoll_weight_store() - sets the current IRQ poll weight for the host
2877 * weight in ASCII.
2882 * Return: The size of the ASCII string returned in @buf.
2889 struct device *cfgdev = &cfg->dev->dev; in irqpoll_weight_store()
2890 struct afu *afu = cfg->afu; in irqpoll_weight_store()
2897 return -EINVAL; in irqpoll_weight_store()
2902 return -EINVAL; in irqpoll_weight_store()
2905 if (weight == afu->irqpoll_weight) { in irqpoll_weight_store()
2908 return -EINVAL; in irqpoll_weight_store()
2912 for (i = 0; i < afu->num_hwqs; i++) { in irqpoll_weight_store()
2915 irq_poll_disable(&hwq->irqpoll); in irqpoll_weight_store()
2919 afu->irqpoll_weight = weight; in irqpoll_weight_store()
2922 for (i = 0; i < afu->num_hwqs; i++) { in irqpoll_weight_store()
2925 irq_poll_init(&hwq->irqpoll, weight, cxlflash_irqpoll); in irqpoll_weight_store()
2933 * num_hwqs_show() - presents the number of hardware queues for the host
2937 * queues in ASCII.
2939 * Return: The size of the ASCII string returned in @buf.
2945 struct afu *afu = cfg->afu; in num_hwqs_show()
2947 return scnprintf(buf, PAGE_SIZE, "%u\n", afu->num_hwqs); in num_hwqs_show()
2951 * num_hwqs_store() - sets the number of hardware queues for the host
2955 * queues in ASCII.
2962 * Return: The size of the ASCII string returned in @buf.
2969 struct afu *afu = cfg->afu; in num_hwqs_store()
2975 return -EINVAL; in num_hwqs_store()
2984 afu->desired_hwqs = min(num_hwqs, CXLFLASH_MAX_HWQS); in num_hwqs_store()
2985 WARN_ON_ONCE(afu->desired_hwqs == 0); in num_hwqs_store()
2988 switch (cfg->state) { in num_hwqs_store()
2990 cfg->state = STATE_RESET; in num_hwqs_store()
2995 cfg->state = STATE_FAILTERM; in num_hwqs_store()
2997 cfg->state = STATE_NORMAL; in num_hwqs_store()
2998 wake_up_all(&cfg->reset_waitq); in num_hwqs_store()
3001 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); in num_hwqs_store()
3002 if (cfg->state == STATE_NORMAL) in num_hwqs_store()
3008 __func__, cfg->state); in num_hwqs_store()
3018 * hwq_mode_show() - presents the HWQ steering mode for the host
3024 * Return: The size of the ASCII string returned in @buf.
3030 struct afu *afu = cfg->afu; in hwq_mode_show()
3032 return scnprintf(buf, PAGE_SIZE, "%s\n", hwq_mode_name[afu->hwq_mode]); in hwq_mode_show()
3036 * hwq_mode_store() - sets the HWQ steering mode for the host
3043 * rr = Round-Robin
3047 * Return: The size of the ASCII string returned in @buf.
3055 struct device *cfgdev = &cfg->dev->dev; in hwq_mode_store()
3056 struct afu *afu = cfg->afu; in hwq_mode_store()
3069 return -EINVAL; in hwq_mode_store()
3072 afu->hwq_mode = mode; in hwq_mode_store()
3078 * mode_show() - presents the current mode of the device
3081 * @buf: Buffer of length PAGE_SIZE to report back the dev mode in ASCII.
3083 * Return: The size of the ASCII string returned in @buf.
3091 sdev->hostdata ? "superpipe" : "legacy"); in mode_show()
3158 .cmd_size = sizeof(struct afu_cmd) + __alignof__(struct afu_cmd) - 1,
3159 .this_id = -1,
3193 * cxlflash_worker_thread() - work thread handler for the AFU
3197 * - Link reset which cannot be performed on interrupt context due to
3199 * - Rescan the host
3205 struct afu *afu = cfg->afu; in cxlflash_worker_thread()
3206 struct device *dev = &cfg->dev->dev; in cxlflash_worker_thread()
3213 if (cfg->state != STATE_NORMAL) in cxlflash_worker_thread()
3216 spin_lock_irqsave(cfg->host->host_lock, lock_flags); in cxlflash_worker_thread()
3218 if (cfg->lr_state == LINK_RESET_REQUIRED) { in cxlflash_worker_thread()
3219 port = cfg->lr_port; in cxlflash_worker_thread()
3224 spin_unlock_irqrestore(cfg->host->host_lock, in cxlflash_worker_thread()
3230 spin_lock_irqsave(cfg->host->host_lock, lock_flags); in cxlflash_worker_thread()
3233 cfg->lr_state = LINK_RESET_COMPLETE; in cxlflash_worker_thread()
3236 spin_unlock_irqrestore(cfg->host->host_lock, lock_flags); in cxlflash_worker_thread()
3238 if (atomic_dec_if_positive(&cfg->scan_host_needed) >= 0) in cxlflash_worker_thread()
3239 scsi_scan_host(cfg->host); in cxlflash_worker_thread()
3243 * cxlflash_chr_open() - character device open handler
3249 * Return: 0 on success, -errno on failure
3256 return -EACCES; in cxlflash_chr_open()
3258 cfg = container_of(inode->i_cdev, struct cxlflash_cfg, cdev); in cxlflash_chr_open()
3259 file->private_data = cfg; in cxlflash_chr_open()
3265 * decode_hioctl() - translates encoded host ioctl to easily identifiable string
3281 * cxlflash_lun_provision() - host LUN provisioning handler
3285 * Return: 0 on success, -errno on failure
3290 struct afu *afu = cfg->afu; in cxlflash_lun_provision()
3291 struct device *dev = &cfg->dev->dev; in cxlflash_lun_provision()
3295 u16 port = lunprov->port; in cxlflash_lun_provision()
3296 u16 scmd = lunprov->hdr.subcmd; in cxlflash_lun_provision()
3304 rc = -ENOTSUPP; in cxlflash_lun_provision()
3308 if (port >= cfg->num_fc_ports) { in cxlflash_lun_provision()
3309 rc = -EINVAL; in cxlflash_lun_provision()
3316 size = lunprov->size; in cxlflash_lun_provision()
3322 lun_id = lunprov->lun_id; in cxlflash_lun_provision()
3328 lunprov->max_num_luns = reg; in cxlflash_lun_provision()
3330 lunprov->cur_num_luns = reg; in cxlflash_lun_provision()
3332 lunprov->max_cap_port = reg; in cxlflash_lun_provision()
3334 lunprov->cur_cap_port = reg; in cxlflash_lun_provision()
3338 rc = -EINVAL; in cxlflash_lun_provision()
3363 lunprov->lun_id = (u64)asa.lunid_hi << 32 | asa.lunid_lo; in cxlflash_lun_provision()
3364 memcpy(lunprov->wwid, asa.wwid, sizeof(lunprov->wwid)); in cxlflash_lun_provision()
3372 * cxlflash_afu_debug() - host AFU debug handler
3379 * Return: 0 on success, -errno on failure
3384 struct afu *afu = cfg->afu; in cxlflash_afu_debug()
3385 struct device *dev = &cfg->dev->dev; in cxlflash_afu_debug()
3390 void __user *ubuf = (__force void __user *)afu_dbg->data_ea; in cxlflash_afu_debug()
3392 u32 ulen = afu_dbg->data_len; in cxlflash_afu_debug()
3393 bool is_write = afu_dbg->hdr.flags & HT_CXLFLASH_HOST_WRITE; in cxlflash_afu_debug()
3397 rc = -ENOTSUPP; in cxlflash_afu_debug()
3405 rc = -EINVAL; in cxlflash_afu_debug()
3409 buf = kmalloc(ulen + cache_line_size() - 1, GFP_KERNEL); in cxlflash_afu_debug()
3411 rc = -ENOMEM; in cxlflash_afu_debug()
3421 rc = -EFAULT; in cxlflash_afu_debug()
3441 memcpy(&rcb.cdb[4], afu_dbg->afu_subcmd, in cxlflash_afu_debug()
3453 rc = -EFAULT; in cxlflash_afu_debug()
3462 * cxlflash_chr_ioctl() - character device IOCTL handler
3475 * Return: 0 on success, -errno on failure
3482 struct cxlflash_cfg *cfg = file->private_data; in cxlflash_chr_ioctl()
3483 struct device *dev = &cfg->dev->dev; in cxlflash_chr_ioctl()
3502 down_read(&cfg->ioctl_rwsem); in cxlflash_chr_ioctl()
3511 idx = _IOC_NR(HT_CXLFLASH_LUN_PROVISION) - _IOC_NR(cmd); in cxlflash_chr_ioctl()
3520 rc = -EINVAL; in cxlflash_chr_ioctl()
3528 rc = -EFAULT; in cxlflash_chr_ioctl()
3533 if (hdr->version != HT_CXLFLASH_VERSION_0) { in cxlflash_chr_ioctl()
3535 __func__, hdr->version, decode_hioctl(cmd)); in cxlflash_chr_ioctl()
3536 rc = -EINVAL; in cxlflash_chr_ioctl()
3540 if (hdr->rsvd[0] || hdr->rsvd[1] || hdr->return_flags) { in cxlflash_chr_ioctl()
3542 rc = -EINVAL; in cxlflash_chr_ioctl()
3552 rc = -EFAULT; in cxlflash_chr_ioctl()
3558 up_read(&cfg->ioctl_rwsem); in cxlflash_chr_ioctl()
3579 * init_chrdev() - initialize the character device for the host
3582 * Return: 0 on success, -errno on failure
3586 struct device *dev = &cfg->dev->dev; in init_chrdev()
3595 rc = -ENOSPC; in init_chrdev()
3600 cdev_init(&cfg->cdev, &cxlflash_chr_fops); in init_chrdev()
3602 rc = cdev_add(&cfg->cdev, devno, 1); in init_chrdev()
3617 cfg->chardev = char_dev; in init_chrdev()
3622 cdev_del(&cfg->cdev); in init_chrdev()
3629 * cxlflash_probe() - PCI entry point to add host
3642 * Return: 0 on success, -errno on failure
3649 struct device *dev = &pdev->dev; in cxlflash_probe()
3654 dev_dbg(&pdev->dev, "%s: Found CXLFLASH with IRQ: %d\n", in cxlflash_probe()
3655 __func__, pdev->irq); in cxlflash_probe()
3657 ddv = (struct dev_dependent_vals *)dev_id->driver_data; in cxlflash_probe()
3658 driver_template.max_sectors = ddv->max_sectors; in cxlflash_probe()
3663 rc = -ENOMEM; in cxlflash_probe()
3667 host->max_id = CXLFLASH_MAX_NUM_TARGETS_PER_BUS; in cxlflash_probe()
3668 host->max_lun = CXLFLASH_MAX_NUM_LUNS_PER_TARGET; in cxlflash_probe()
3669 host->unique_id = host->host_no; in cxlflash_probe()
3670 host->max_cmd_len = CXLFLASH_MAX_CDB_LEN; in cxlflash_probe()
3673 cfg->state = STATE_PROBING; in cxlflash_probe()
3674 cfg->host = host; in cxlflash_probe()
3678 rc = -ENOMEM; in cxlflash_probe()
3679 scsi_host_put(cfg->host); in cxlflash_probe()
3683 cfg->init_state = INIT_STATE_NONE; in cxlflash_probe()
3684 cfg->dev = pdev; in cxlflash_probe()
3685 cfg->cxl_fops = cxlflash_cxl_fops; in cxlflash_probe()
3686 cfg->ops = cxlflash_assign_ops(ddv); in cxlflash_probe()
3687 WARN_ON_ONCE(!cfg->ops); in cxlflash_probe()
3696 cfg->promote_lun_index = 0; in cxlflash_probe()
3699 cfg->last_lun_index[k] = CXLFLASH_NUM_VLUNS/2 - 1; in cxlflash_probe()
3701 cfg->dev_id = (struct pci_device_id *)dev_id; in cxlflash_probe()
3703 init_waitqueue_head(&cfg->tmf_waitq); in cxlflash_probe()
3704 init_waitqueue_head(&cfg->reset_waitq); in cxlflash_probe()
3706 INIT_WORK(&cfg->work_q, cxlflash_worker_thread); in cxlflash_probe()
3707 cfg->lr_state = LINK_RESET_INVALID; in cxlflash_probe()
3708 cfg->lr_port = -1; in cxlflash_probe()
3709 spin_lock_init(&cfg->tmf_slock); in cxlflash_probe()
3710 mutex_init(&cfg->ctx_tbl_list_mutex); in cxlflash_probe()
3711 mutex_init(&cfg->ctx_recovery_mutex); in cxlflash_probe()
3712 init_rwsem(&cfg->ioctl_rwsem); in cxlflash_probe()
3713 INIT_LIST_HEAD(&cfg->ctx_err_recovery); in cxlflash_probe()
3714 INIT_LIST_HEAD(&cfg->lluns); in cxlflash_probe()
3723 cfg->init_state = INIT_STATE_PCI; in cxlflash_probe()
3725 cfg->afu_cookie = cfg->ops->create_afu(pdev); in cxlflash_probe()
3726 if (unlikely(!cfg->afu_cookie)) { in cxlflash_probe()
3728 rc = -ENOMEM; in cxlflash_probe()
3733 if (rc && !wq_has_sleeper(&cfg->reset_waitq)) { in cxlflash_probe()
3737 cfg->init_state = INIT_STATE_AFU; in cxlflash_probe()
3744 cfg->init_state = INIT_STATE_SCSI; in cxlflash_probe()
3751 cfg->init_state = INIT_STATE_CDEV; in cxlflash_probe()
3753 if (wq_has_sleeper(&cfg->reset_waitq)) { in cxlflash_probe()
3754 cfg->state = STATE_PROBED; in cxlflash_probe()
3755 wake_up_all(&cfg->reset_waitq); in cxlflash_probe()
3757 cfg->state = STATE_NORMAL; in cxlflash_probe()
3763 cfg->state = STATE_PROBED; in cxlflash_probe()
3769 * cxlflash_pci_error_detected() - called when a PCI error is detected
3774 * complete and then take action based upon the device state.
3783 struct device *dev = &cfg->dev->dev; in cxlflash_pci_error_detected()
3789 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET && in cxlflash_pci_error_detected()
3790 cfg->state != STATE_PROBING); in cxlflash_pci_error_detected()
3791 if (cfg->state == STATE_FAILTERM) in cxlflash_pci_error_detected()
3794 cfg->state = STATE_RESET; in cxlflash_pci_error_detected()
3795 scsi_block_requests(cfg->host); in cxlflash_pci_error_detected()
3804 cfg->state = STATE_FAILTERM; in cxlflash_pci_error_detected()
3805 wake_up_all(&cfg->reset_waitq); in cxlflash_pci_error_detected()
3806 scsi_unblock_requests(cfg->host); in cxlflash_pci_error_detected()
3815 * cxlflash_pci_slot_reset() - called when PCI slot has been reset
3827 struct device *dev = &cfg->dev->dev; in cxlflash_pci_slot_reset()
3841 * cxlflash_pci_resume() - called when normal operation can resume
3847 struct device *dev = &cfg->dev->dev; in cxlflash_pci_resume()
3851 cfg->state = STATE_NORMAL; in cxlflash_pci_resume()
3852 wake_up_all(&cfg->reset_waitq); in cxlflash_pci_resume()
3853 scsi_unblock_requests(cfg->host); in cxlflash_pci_resume()
3857 * cxlflash_devnode() - provides devtmpfs for devices in the cxlflash class
3869 * cxlflash_class_init() - create character device class
3871 * Return: 0 on success, -errno on failure
3901 * cxlflash_class_exit() - destroy character device class
3930 * init_cxlflash() - module entry point
3932 * Return: 0 on success, -errno on failure
3956 * exit_cxlflash() - module exit point