Lines Matching refs:cfg
222 struct cxlflash_cfg *cfg = afu->parent; in cmd_complete() local
247 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in cmd_complete()
248 cfg->tmf_active = false; in cmd_complete()
249 wake_up_all_locked(&cfg->tmf_waitq); in cmd_complete()
250 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cmd_complete()
320 struct cxlflash_cfg *cfg = afu->parent; in send_cmd() local
321 struct device *dev = &cfg->dev->dev; in send_cmd()
371 schedule_work(&cfg->work_q); in send_cmd()
412 struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata; in send_tmf() local
413 struct device *dev = &cfg->dev->dev; in send_tmf()
426 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in send_tmf()
427 if (cfg->tmf_active) in send_tmf()
428 wait_event_interruptible_lock_irq(cfg->tmf_waitq, in send_tmf()
429 !cfg->tmf_active, in send_tmf()
430 cfg->tmf_slock); in send_tmf()
431 cfg->tmf_active = true; in send_tmf()
433 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in send_tmf()
454 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in send_tmf()
455 cfg->tmf_active = false; in send_tmf()
456 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in send_tmf()
460 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in send_tmf()
462 to = wait_event_interruptible_lock_irq_timeout(cfg->tmf_waitq, in send_tmf()
463 !cfg->tmf_active, in send_tmf()
464 cfg->tmf_slock, in send_tmf()
467 cfg->tmf_active = false; in send_tmf()
471 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in send_tmf()
496 struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata; in cxlflash_queuecommand() local
497 struct afu *afu = cfg->afu; in cxlflash_queuecommand()
498 struct device *dev = &cfg->dev->dev; in cxlflash_queuecommand()
520 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in cxlflash_queuecommand()
521 if (cfg->tmf_active) { in cxlflash_queuecommand()
522 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cxlflash_queuecommand()
526 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cxlflash_queuecommand()
528 switch (cfg->state) { in cxlflash_queuecommand()
598 static void cxlflash_wait_for_pci_err_recovery(struct cxlflash_cfg *cfg) in cxlflash_wait_for_pci_err_recovery() argument
600 struct pci_dev *pdev = cfg->dev; in cxlflash_wait_for_pci_err_recovery()
603 wait_event_timeout(cfg->reset_waitq, in cxlflash_wait_for_pci_err_recovery()
612 static void free_mem(struct cxlflash_cfg *cfg) in free_mem() argument
616 struct afu *afu = cfg->afu; in free_mem()
618 if (cfg->afu) { in free_mem()
626 cfg->afu = NULL; in free_mem()
636 static void stop_afu(struct cxlflash_cfg *cfg) in stop_afu() argument
639 struct afu *afu = cfg->afu; in stop_afu()
659 static void term_mc(struct cxlflash_cfg *cfg, enum undo_level level) in term_mc() argument
662 struct afu *afu = cfg->afu; in term_mc()
663 struct device *dev = &cfg->dev->dev; in term_mc()
665 if (!afu || !cfg->mcctx) { in term_mc()
673 rc = cxl_stop_context(cfg->mcctx); in term_mc()
676 cxl_unmap_afu_irq(cfg->mcctx, 3, afu); in term_mc()
678 cxl_unmap_afu_irq(cfg->mcctx, 2, afu); in term_mc()
680 cxl_unmap_afu_irq(cfg->mcctx, 1, afu); in term_mc()
682 cxl_free_afu_irqs(cfg->mcctx); in term_mc()
684 cfg->mcctx = NULL; in term_mc()
694 static void term_afu(struct cxlflash_cfg *cfg) in term_afu() argument
696 term_mc(cfg, UNDO_START); in term_afu()
698 if (cfg->afu) in term_afu()
699 stop_afu(cfg); in term_afu()
712 struct cxlflash_cfg *cfg = pci_get_drvdata(pdev); in cxlflash_remove() local
718 spin_lock_irqsave(&cfg->tmf_slock, lock_flags); in cxlflash_remove()
719 if (cfg->tmf_active) in cxlflash_remove()
720 wait_event_interruptible_lock_irq(cfg->tmf_waitq, in cxlflash_remove()
721 !cfg->tmf_active, in cxlflash_remove()
722 cfg->tmf_slock); in cxlflash_remove()
723 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags); in cxlflash_remove()
725 cfg->state = STATE_FAILTERM; in cxlflash_remove()
726 cxlflash_stop_term_user_contexts(cfg); in cxlflash_remove()
728 switch (cfg->init_state) { in cxlflash_remove()
730 cxlflash_term_local_luns(cfg); in cxlflash_remove()
731 scsi_remove_host(cfg->host); in cxlflash_remove()
734 term_afu(cfg); in cxlflash_remove()
735 cancel_work_sync(&cfg->work_q); in cxlflash_remove()
737 pci_release_regions(cfg->dev); in cxlflash_remove()
740 free_mem(cfg); in cxlflash_remove()
741 scsi_host_put(cfg->host); in cxlflash_remove()
758 static int alloc_mem(struct cxlflash_cfg *cfg) in alloc_mem() argument
763 struct device *dev = &cfg->dev->dev; in alloc_mem()
766 cfg->afu = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, in alloc_mem()
768 if (unlikely(!cfg->afu)) { in alloc_mem()
774 cfg->afu->parent = cfg; in alloc_mem()
775 cfg->afu->afu_map = NULL; in alloc_mem()
785 free_mem(cfg); in alloc_mem()
790 cfg->afu->cmd[i].buf = buf; in alloc_mem()
791 atomic_set(&cfg->afu->cmd[i].free, 1); in alloc_mem()
792 cfg->afu->cmd[i].slot = i; in alloc_mem()
805 static int init_pci(struct cxlflash_cfg *cfg) in init_pci() argument
807 struct pci_dev *pdev = cfg->dev; in init_pci()
810 cfg->cxlflash_regs_pci = pci_resource_start(pdev, 0); in init_pci()
822 cxlflash_wait_for_pci_err_recovery(cfg); in init_pci()
829 cxlflash_wait_for_pci_err_recovery(cfg); in init_pci()
850 cxlflash_wait_for_pci_err_recovery(cfg); in init_pci()
872 cxlflash_wait_for_pci_err_recovery(cfg); in init_pci()
887 static int init_scsi(struct cxlflash_cfg *cfg) in init_scsi() argument
889 struct pci_dev *pdev = cfg->dev; in init_scsi()
892 rc = scsi_add_host(cfg->host, &pdev->dev); in init_scsi()
899 scsi_scan_host(cfg->host); in init_scsi()
1277 struct cxlflash_cfg *cfg = afu->parent; in cxlflash_async_err_irq() local
1278 struct device *dev = &cfg->dev->dev; in cxlflash_async_err_irq()
1317 cfg->lr_state = LINK_RESET_REQUIRED; in cxlflash_async_err_irq()
1318 cfg->lr_port = port; in cxlflash_async_err_irq()
1319 schedule_work(&cfg->work_q); in cxlflash_async_err_irq()
1338 atomic_inc(&cfg->scan_host_needed); in cxlflash_async_err_irq()
1339 schedule_work(&cfg->work_q); in cxlflash_async_err_irq()
1354 static int start_context(struct cxlflash_cfg *cfg) in start_context() argument
1358 rc = cxl_start_context(cfg->mcctx, in start_context()
1359 cfg->afu->work.work_element_descriptor, in start_context()
1373 static int read_vpd(struct cxlflash_cfg *cfg, u64 wwpn[]) in read_vpd() argument
1375 struct pci_dev *dev = cfg->parent_dev; in read_vpd()
1464 static void init_pcr(struct cxlflash_cfg *cfg) in init_pcr() argument
1466 struct afu *afu = cfg->afu; in init_pcr()
1480 afu->ctx_hndl = (u16) cxl_process_element(cfg->mcctx); in init_pcr()
1499 static int init_global(struct cxlflash_cfg *cfg) in init_global() argument
1501 struct afu *afu = cfg->afu; in init_global()
1502 struct device *dev = &cfg->dev->dev; in init_global()
1508 rc = read_vpd(cfg, &wwpn[0]); in init_global()
1583 static int start_afu(struct cxlflash_cfg *cfg) in start_afu() argument
1585 struct afu *afu = cfg->afu; in start_afu()
1599 init_pcr(cfg); in start_afu()
1610 rc = init_global(cfg); in start_afu()
1622 static int init_mc(struct cxlflash_cfg *cfg) in init_mc() argument
1625 struct device *dev = &cfg->dev->dev; in init_mc()
1626 struct afu *afu = cfg->afu; in init_mc()
1630 ctx = cxl_get_context(cfg->dev); in init_mc()
1633 cfg->mcctx = ctx; in init_mc()
1639 rc = cxl_afu_reset(cfg->mcctx); in init_mc()
1688 rc = start_context(cfg); in init_mc()
1698 term_mc(cfg, level); in init_mc()
1711 static int init_afu(struct cxlflash_cfg *cfg) in init_afu() argument
1715 struct afu *afu = cfg->afu; in init_afu()
1716 struct device *dev = &cfg->dev->dev; in init_afu()
1718 cxl_perst_reloads_same_image(cfg->cxl_afu, true); in init_afu()
1720 rc = init_mc(cfg); in init_afu()
1728 afu->afu_map = cxl_psa_map(cfg->mcctx); in init_afu()
1751 rc = start_afu(cfg); in init_afu()
1758 afu_err_intr_init(cfg->afu); in init_afu()
1762 cxlflash_restore_luntable(cfg); in init_afu()
1771 term_mc(cfg, UNDO_START); in init_afu()
1800 struct cxlflash_cfg *cfg = afu->parent; in cxlflash_afu_sync() local
1801 struct device *dev = &cfg->dev->dev; in cxlflash_afu_sync()
1807 if (cfg->state != STATE_NORMAL) { in cxlflash_afu_sync()
1808 pr_debug("%s: Sync not required! (%u)\n", __func__, cfg->state); in cxlflash_afu_sync()
1867 static int afu_reset(struct cxlflash_cfg *cfg) in afu_reset() argument
1874 term_afu(cfg); in afu_reset()
1876 rc = init_afu(cfg); in afu_reset()
1894 struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata; in cxlflash_eh_device_reset_handler() local
1895 struct afu *afu = cfg->afu; in cxlflash_eh_device_reset_handler()
1908 switch (cfg->state) { in cxlflash_eh_device_reset_handler()
1915 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); in cxlflash_eh_device_reset_handler()
1939 struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata; in cxlflash_eh_host_reset_handler() local
1950 switch (cfg->state) { in cxlflash_eh_host_reset_handler()
1952 cfg->state = STATE_RESET; in cxlflash_eh_host_reset_handler()
1953 cxlflash_mark_contexts_error(cfg); in cxlflash_eh_host_reset_handler()
1954 rcr = afu_reset(cfg); in cxlflash_eh_host_reset_handler()
1957 cfg->state = STATE_FAILTERM; in cxlflash_eh_host_reset_handler()
1959 cfg->state = STATE_NORMAL; in cxlflash_eh_host_reset_handler()
1960 wake_up_all(&cfg->reset_waitq); in cxlflash_eh_host_reset_handler()
1963 wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); in cxlflash_eh_host_reset_handler()
1964 if (cfg->state == STATE_NORMAL) in cxlflash_eh_host_reset_handler()
2039 struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata; in port0_show() local
2040 struct afu *afu = cfg->afu; in port0_show()
2058 struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata; in port1_show() local
2059 struct afu *afu = cfg->afu; in port1_show()
2076 struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata; in lun_mode_show() local
2077 struct afu *afu = cfg->afu; in lun_mode_show()
2109 struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata; in lun_mode_store() local
2110 struct afu *afu = cfg->afu; in lun_mode_store()
2117 afu_reset(cfg); in lun_mode_store()
2118 scsi_scan_host(cfg->host); in lun_mode_store()
2178 struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata; in port0_lun_table_show() local
2179 struct afu *afu = cfg->afu; in port0_lun_table_show()
2197 struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata; in port1_lun_table_show() local
2198 struct afu *afu = cfg->afu; in port1_lun_table_show()
2301 struct cxlflash_cfg *cfg = container_of(work, struct cxlflash_cfg, in cxlflash_worker_thread() local
2303 struct afu *afu = cfg->afu; in cxlflash_worker_thread()
2304 struct device *dev = &cfg->dev->dev; in cxlflash_worker_thread()
2310 if (cfg->state != STATE_NORMAL) in cxlflash_worker_thread()
2313 spin_lock_irqsave(cfg->host->host_lock, lock_flags); in cxlflash_worker_thread()
2315 if (cfg->lr_state == LINK_RESET_REQUIRED) { in cxlflash_worker_thread()
2316 port = cfg->lr_port; in cxlflash_worker_thread()
2321 spin_unlock_irqrestore(cfg->host->host_lock, in cxlflash_worker_thread()
2327 spin_lock_irqsave(cfg->host->host_lock, lock_flags); in cxlflash_worker_thread()
2330 cfg->lr_state = LINK_RESET_COMPLETE; in cxlflash_worker_thread()
2338 spin_unlock_irqrestore(cfg->host->host_lock, lock_flags); in cxlflash_worker_thread()
2340 if (atomic_dec_if_positive(&cfg->scan_host_needed) >= 0) in cxlflash_worker_thread()
2341 scsi_scan_host(cfg->host); in cxlflash_worker_thread()
2355 struct cxlflash_cfg *cfg = NULL; in cxlflash_probe() local
2380 cfg = (struct cxlflash_cfg *)host->hostdata; in cxlflash_probe()
2381 cfg->host = host; in cxlflash_probe()
2382 rc = alloc_mem(cfg); in cxlflash_probe()
2387 scsi_host_put(cfg->host); in cxlflash_probe()
2391 cfg->init_state = INIT_STATE_NONE; in cxlflash_probe()
2392 cfg->dev = pdev; in cxlflash_probe()
2393 cfg->cxl_fops = cxlflash_cxl_fops; in cxlflash_probe()
2401 cfg->promote_lun_index = 0; in cxlflash_probe()
2402 cfg->last_lun_index[0] = CXLFLASH_NUM_VLUNS/2 - 1; in cxlflash_probe()
2403 cfg->last_lun_index[1] = CXLFLASH_NUM_VLUNS/2 - 1; in cxlflash_probe()
2405 cfg->dev_id = (struct pci_device_id *)dev_id; in cxlflash_probe()
2407 init_waitqueue_head(&cfg->tmf_waitq); in cxlflash_probe()
2408 init_waitqueue_head(&cfg->reset_waitq); in cxlflash_probe()
2410 INIT_WORK(&cfg->work_q, cxlflash_worker_thread); in cxlflash_probe()
2411 cfg->lr_state = LINK_RESET_INVALID; in cxlflash_probe()
2412 cfg->lr_port = -1; in cxlflash_probe()
2413 spin_lock_init(&cfg->tmf_slock); in cxlflash_probe()
2414 mutex_init(&cfg->ctx_tbl_list_mutex); in cxlflash_probe()
2415 mutex_init(&cfg->ctx_recovery_mutex); in cxlflash_probe()
2416 init_rwsem(&cfg->ioctl_rwsem); in cxlflash_probe()
2417 INIT_LIST_HEAD(&cfg->ctx_err_recovery); in cxlflash_probe()
2418 INIT_LIST_HEAD(&cfg->lluns); in cxlflash_probe()
2420 pci_set_drvdata(pdev, cfg); in cxlflash_probe()
2433 cfg->parent_dev = to_pci_dev(phys_dev); in cxlflash_probe()
2435 cfg->cxl_afu = cxl_pci_to_afu(pdev); in cxlflash_probe()
2437 rc = init_pci(cfg); in cxlflash_probe()
2443 cfg->init_state = INIT_STATE_PCI; in cxlflash_probe()
2445 rc = init_afu(cfg); in cxlflash_probe()
2451 cfg->init_state = INIT_STATE_AFU; in cxlflash_probe()
2453 rc = init_scsi(cfg); in cxlflash_probe()
2459 cfg->init_state = INIT_STATE_SCSI; in cxlflash_probe()
2477 static void drain_ioctls(struct cxlflash_cfg *cfg) in drain_ioctls() argument
2479 down_write(&cfg->ioctl_rwsem); in drain_ioctls()
2480 up_write(&cfg->ioctl_rwsem); in drain_ioctls()
2494 struct cxlflash_cfg *cfg = pci_get_drvdata(pdev); in cxlflash_pci_error_detected() local
2495 struct device *dev = &cfg->dev->dev; in cxlflash_pci_error_detected()
2501 cfg->state = STATE_RESET; in cxlflash_pci_error_detected()
2502 scsi_block_requests(cfg->host); in cxlflash_pci_error_detected()
2503 drain_ioctls(cfg); in cxlflash_pci_error_detected()
2504 rc = cxlflash_mark_contexts_error(cfg); in cxlflash_pci_error_detected()
2508 term_mc(cfg, UNDO_START); in cxlflash_pci_error_detected()
2509 stop_afu(cfg); in cxlflash_pci_error_detected()
2512 cfg->state = STATE_FAILTERM; in cxlflash_pci_error_detected()
2513 wake_up_all(&cfg->reset_waitq); in cxlflash_pci_error_detected()
2514 scsi_unblock_requests(cfg->host); in cxlflash_pci_error_detected()
2534 struct cxlflash_cfg *cfg = pci_get_drvdata(pdev); in cxlflash_pci_slot_reset() local
2535 struct device *dev = &cfg->dev->dev; in cxlflash_pci_slot_reset()
2539 rc = init_afu(cfg); in cxlflash_pci_slot_reset()
2554 struct cxlflash_cfg *cfg = pci_get_drvdata(pdev); in cxlflash_pci_resume() local
2555 struct device *dev = &cfg->dev->dev; in cxlflash_pci_resume()
2559 cfg->state = STATE_NORMAL; in cxlflash_pci_resume()
2560 wake_up_all(&cfg->reset_waitq); in cxlflash_pci_resume()
2561 scsi_unblock_requests(cfg->host); in cxlflash_pci_resume()