Lines Matching full:cd
135 struct genwqe_dev *cd; in genwqe_dev_alloc() local
144 cd = kzalloc(sizeof(struct genwqe_dev), GFP_KERNEL); in genwqe_dev_alloc()
145 if (!cd) in genwqe_dev_alloc()
148 cd->card_idx = i; in genwqe_dev_alloc()
149 cd->class_genwqe = &class_genwqe; in genwqe_dev_alloc()
150 cd->debugfs_genwqe = debugfs_genwqe; in genwqe_dev_alloc()
156 cd->use_platform_recovery = CONFIG_GENWQE_PLATFORM_ERROR_RECOVERY; in genwqe_dev_alloc()
158 init_waitqueue_head(&cd->queue_waitq); in genwqe_dev_alloc()
160 spin_lock_init(&cd->file_lock); in genwqe_dev_alloc()
161 INIT_LIST_HEAD(&cd->file_list); in genwqe_dev_alloc()
163 cd->card_state = GENWQE_CARD_UNUSED; in genwqe_dev_alloc()
164 spin_lock_init(&cd->print_lock); in genwqe_dev_alloc()
166 cd->ddcb_software_timeout = GENWQE_DDCB_SOFTWARE_TIMEOUT; in genwqe_dev_alloc()
167 cd->kill_timeout = GENWQE_KILL_TIMEOUT; in genwqe_dev_alloc()
170 cd->vf_jobtimeout_msec[j] = GENWQE_VF_JOBTIMEOUT_MSEC; in genwqe_dev_alloc()
172 genwqe_devices[i] = cd; in genwqe_dev_alloc()
173 return cd; in genwqe_dev_alloc()
176 static void genwqe_dev_free(struct genwqe_dev *cd) in genwqe_dev_free() argument
178 if (!cd) in genwqe_dev_free()
181 genwqe_devices[cd->card_idx] = NULL; in genwqe_dev_free()
182 kfree(cd); in genwqe_dev_free()
187 * @cd: GenWQE device information
194 static int genwqe_bus_reset(struct genwqe_dev *cd) in genwqe_bus_reset() argument
197 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_bus_reset()
200 if (cd->err_inject & GENWQE_INJECT_BUS_RESET_FAILURE) in genwqe_bus_reset()
203 mmio = cd->mmio; in genwqe_bus_reset()
204 cd->mmio = NULL; in genwqe_bus_reset()
227 cd->err_inject &= ~(GENWQE_INJECT_HARDWARE_FAILURE | in genwqe_bus_reset()
238 cd->mmio = pci_iomap(pci_dev, 0, 0); in genwqe_bus_reset()
239 if (cd->mmio == NULL) { in genwqe_bus_reset()
259 bool genwqe_need_err_masking(struct genwqe_dev *cd) in genwqe_need_err_masking() argument
261 return (cd->slu_unitcfg & 0xFFFF0ull) < 0x32170ull; in genwqe_need_err_masking()
264 static void genwqe_tweak_hardware(struct genwqe_dev *cd) in genwqe_tweak_hardware() argument
266 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_tweak_hardware()
269 if (((cd->slu_unitcfg & 0xFFFF0ull) >= 0x32000ull) && in genwqe_tweak_hardware()
270 ((cd->slu_unitcfg & 0xFFFF0ull) <= 0x33250ull)) { in genwqe_tweak_hardware()
273 cd->slu_unitcfg, cd->app_unitcfg); in genwqe_tweak_hardware()
275 __genwqe_writeq(cd, IO_APP_SEC_LEM_DEBUG_OVR, in genwqe_tweak_hardware()
278 __genwqe_writeq(cd, IO_APP_ERR_ACT_MASK, in genwqe_tweak_hardware()
285 * @cd: GenWQE device information
292 int genwqe_recovery_on_fatal_gfir_required(struct genwqe_dev *cd) in genwqe_recovery_on_fatal_gfir_required() argument
294 return (cd->slu_unitcfg & 0xFFFF0ull) >= 0x32170ull; in genwqe_recovery_on_fatal_gfir_required()
297 int genwqe_flash_readback_fails(struct genwqe_dev *cd) in genwqe_flash_readback_fails() argument
299 return (cd->slu_unitcfg & 0xFFFF0ull) < 0x32170ull; in genwqe_flash_readback_fails()
304 * @cd: GenWQE device information
314 static int genwqe_T_psec(struct genwqe_dev *cd) in genwqe_T_psec() argument
319 speed = (u16)((cd->slu_unitcfg >> 28) & 0x0full); in genwqe_T_psec()
328 * @cd: GenWQE device information
336 static bool genwqe_setup_pf_jtimer(struct genwqe_dev *cd) in genwqe_setup_pf_jtimer() argument
338 u32 T = genwqe_T_psec(cd); in genwqe_setup_pf_jtimer()
348 genwqe_write_vreg(cd, IO_SLC_VF_APPJOB_TIMEOUT, in genwqe_setup_pf_jtimer()
355 * @cd: GenWQE device information
357 static bool genwqe_setup_vf_jtimer(struct genwqe_dev *cd) in genwqe_setup_vf_jtimer() argument
359 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_setup_vf_jtimer()
361 u32 T = genwqe_T_psec(cd); in genwqe_setup_vf_jtimer()
371 if (cd->vf_jobtimeout_msec[vf] == 0) in genwqe_setup_vf_jtimer()
374 x = ilog2(cd->vf_jobtimeout_msec[vf] * in genwqe_setup_vf_jtimer()
377 genwqe_write_vreg(cd, IO_SLC_VF_APPJOB_TIMEOUT, in genwqe_setup_vf_jtimer()
383 static int genwqe_ffdc_buffs_alloc(struct genwqe_dev *cd) in genwqe_ffdc_buffs_alloc() argument
390 e = genwqe_ffdc_buff_size(cd, 0); in genwqe_ffdc_buffs_alloc()
393 e = genwqe_ffdc_buff_size(cd, 1); in genwqe_ffdc_buffs_alloc()
396 e = genwqe_ffdc_buff_size(cd, 2); in genwqe_ffdc_buffs_alloc()
404 cd->ffdc[type].entries = e; in genwqe_ffdc_buffs_alloc()
405 cd->ffdc[type].regs = in genwqe_ffdc_buffs_alloc()
416 static void genwqe_ffdc_buffs_free(struct genwqe_dev *cd) in genwqe_ffdc_buffs_free() argument
421 kfree(cd->ffdc[type].regs); in genwqe_ffdc_buffs_free()
422 cd->ffdc[type].regs = NULL; in genwqe_ffdc_buffs_free()
426 static int genwqe_read_ids(struct genwqe_dev *cd) in genwqe_read_ids() argument
430 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_read_ids()
432 cd->slu_unitcfg = __genwqe_readq(cd, IO_SLU_UNITCFG); in genwqe_read_ids()
433 if (cd->slu_unitcfg == IO_ILLEGAL_VALUE) { in genwqe_read_ids()
435 "err: SLUID=%016llx\n", cd->slu_unitcfg); in genwqe_read_ids()
440 slu_id = genwqe_get_slu_id(cd); in genwqe_read_ids()
448 cd->app_unitcfg = __genwqe_readq(cd, IO_APP_UNITCFG); in genwqe_read_ids()
449 if (cd->app_unitcfg == IO_ILLEGAL_VALUE) { in genwqe_read_ids()
451 "err: APPID=%016llx\n", cd->app_unitcfg); in genwqe_read_ids()
455 genwqe_read_app_id(cd, cd->app_name, sizeof(cd->app_name)); in genwqe_read_ids()
465 cd->is_privileged = 0; in genwqe_read_ids()
467 cd->is_privileged = (__genwqe_readq(cd, IO_SLU_BITSTREAM) in genwqe_read_ids()
474 static int genwqe_start(struct genwqe_dev *cd) in genwqe_start() argument
477 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_start()
479 err = genwqe_read_ids(cd); in genwqe_start()
483 if (genwqe_is_privileged(cd)) { in genwqe_start()
485 genwqe_ffdc_buffs_alloc(cd); in genwqe_start()
486 genwqe_stop_traps(cd); in genwqe_start()
489 genwqe_read_ffdc_regs(cd, cd->ffdc[GENWQE_DBG_REGS].regs, in genwqe_start()
490 cd->ffdc[GENWQE_DBG_REGS].entries, 0); in genwqe_start()
492 genwqe_ffdc_buff_read(cd, GENWQE_DBG_UNIT0, in genwqe_start()
493 cd->ffdc[GENWQE_DBG_UNIT0].regs, in genwqe_start()
494 cd->ffdc[GENWQE_DBG_UNIT0].entries); in genwqe_start()
496 genwqe_ffdc_buff_read(cd, GENWQE_DBG_UNIT1, in genwqe_start()
497 cd->ffdc[GENWQE_DBG_UNIT1].regs, in genwqe_start()
498 cd->ffdc[GENWQE_DBG_UNIT1].entries); in genwqe_start()
500 genwqe_ffdc_buff_read(cd, GENWQE_DBG_UNIT2, in genwqe_start()
501 cd->ffdc[GENWQE_DBG_UNIT2].regs, in genwqe_start()
502 cd->ffdc[GENWQE_DBG_UNIT2].entries); in genwqe_start()
504 genwqe_start_traps(cd); in genwqe_start()
506 if (cd->card_state == GENWQE_CARD_FATAL_ERROR) { in genwqe_start()
514 cd->softreset = 0x7Cull; in genwqe_start()
515 __genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, in genwqe_start()
516 cd->softreset); in genwqe_start()
518 err = genwqe_bus_reset(cd); in genwqe_start()
531 err = genwqe_read_ids(cd); in genwqe_start()
537 err = genwqe_setup_service_layer(cd); /* does a reset to the card */ in genwqe_start()
545 if (genwqe_is_privileged(cd)) { /* code is running _after_ reset */ in genwqe_start()
546 genwqe_tweak_hardware(cd); in genwqe_start()
548 genwqe_setup_pf_jtimer(cd); in genwqe_start()
549 genwqe_setup_vf_jtimer(cd); in genwqe_start()
552 err = genwqe_device_create(cd); in genwqe_start()
561 genwqe_release_service_layer(cd); in genwqe_start()
563 if (genwqe_is_privileged(cd)) in genwqe_start()
564 genwqe_ffdc_buffs_free(cd); in genwqe_start()
570 * @cd: GenWQE device information
581 static int genwqe_stop(struct genwqe_dev *cd) in genwqe_stop() argument
583 genwqe_finish_queue(cd); /* no register access */ in genwqe_stop()
584 genwqe_device_remove(cd); /* device removed, procs killed */ in genwqe_stop()
585 genwqe_release_service_layer(cd); /* here genwqe_thread is stopped */ in genwqe_stop()
587 if (genwqe_is_privileged(cd)) { in genwqe_stop()
588 pci_disable_sriov(cd->pci_dev); /* access pci config space */ in genwqe_stop()
589 genwqe_ffdc_buffs_free(cd); in genwqe_stop()
597 * @cd: GenWQE device information
607 static int genwqe_recover_card(struct genwqe_dev *cd, int fatal_err) in genwqe_recover_card() argument
610 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_recover_card()
612 genwqe_stop(cd); in genwqe_recover_card()
619 cd->softreset = 0x70ull; in genwqe_recover_card()
620 __genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, cd->softreset); in genwqe_recover_card()
623 rc = genwqe_bus_reset(cd); in genwqe_recover_card()
630 rc = genwqe_start(cd); in genwqe_recover_card()
639 static int genwqe_health_check_cond(struct genwqe_dev *cd, u64 *gfir) in genwqe_health_check_cond() argument
641 *gfir = __genwqe_readq(cd, IO_SLC_CFGREG_GFIR); in genwqe_health_check_cond()
643 genwqe_recovery_on_fatal_gfir_required(cd); in genwqe_health_check_cond()
648 * @cd: GenWQE device information
656 static u64 genwqe_fir_checking(struct genwqe_dev *cd) in genwqe_fir_checking() argument
661 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_fir_checking()
671 gfir = __genwqe_readq(cd, IO_SLC_CFGREG_GFIR); in genwqe_fir_checking()
693 fir = __genwqe_readq(cd, fir_addr); in genwqe_fir_checking()
703 fec = __genwqe_readq(cd, fec_addr); in genwqe_fir_checking()
716 sfir = __genwqe_readq(cd, sfir_addr); in genwqe_fir_checking()
724 sfec = __genwqe_readq(cd, sfec_addr); in genwqe_fir_checking()
731 gfir = __genwqe_readq(cd, IO_SLC_CFGREG_GFIR); in genwqe_fir_checking()
747 __genwqe_writeq(cd, sfir_addr, sfir); in genwqe_fir_checking()
764 __genwqe_writeq(cd, fir_clr_addr, mask); in genwqe_fir_checking()
772 gfir = __genwqe_readq(cd, IO_SLC_CFGREG_GFIR); in genwqe_fir_checking()
824 static int genwqe_platform_recovery(struct genwqe_dev *cd) in genwqe_platform_recovery() argument
826 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_platform_recovery()
833 cd->err_inject &= ~(GENWQE_INJECT_HARDWARE_FAILURE | in genwqe_platform_recovery()
837 genwqe_stop(cd); in genwqe_platform_recovery()
842 rc = genwqe_start(cd); in genwqe_platform_recovery()
860 * @cd: GenWQE device information
867 static int genwqe_reload_bistream(struct genwqe_dev *cd) in genwqe_reload_bistream() argument
869 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_reload_bistream()
876 genwqe_stop(cd); in genwqe_reload_bistream()
882 __genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, in genwqe_reload_bistream()
883 (cd->softreset & 0xcull) | 0x70ull); in genwqe_reload_bistream()
898 rc = genwqe_start(cd); in genwqe_reload_bistream()
934 struct genwqe_dev *cd = data; in genwqe_health_thread() local
935 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_health_thread()
940 rc = wait_event_interruptible_timeout(cd->health_waitq, in genwqe_health_thread()
941 (genwqe_health_check_cond(cd, &gfir) || in genwqe_health_thread()
954 slu_unitcfg = __genwqe_readq(cd, IO_SLU_UNITCFG); in genwqe_health_thread()
962 app_unitcfg = __genwqe_readq(cd, IO_APP_UNITCFG); in genwqe_health_thread()
970 gfir = __genwqe_readq(cd, IO_SLC_CFGREG_GFIR); in genwqe_health_thread()
979 gfir_masked = genwqe_fir_checking(cd); in genwqe_health_thread()
987 if ((gfir_masked) && !cd->skip_recovery && in genwqe_health_thread()
988 genwqe_recovery_on_fatal_gfir_required(cd)) { in genwqe_health_thread()
990 cd->card_state = GENWQE_CARD_FATAL_ERROR; in genwqe_health_thread()
992 rc = genwqe_recover_card(cd, 0); in genwqe_health_thread()
999 if (cd->card_state == GENWQE_CARD_RELOAD_BITSTREAM) { in genwqe_health_thread()
1001 rc = genwqe_reload_bistream(cd); in genwqe_health_thread()
1006 cd->last_gfir = gfir; in genwqe_health_thread()
1013 if (cd->use_platform_recovery) { in genwqe_health_thread()
1019 readq(cd->mmio + IO_SLC_CFGREG_GFIR); in genwqe_health_thread()
1030 rc = genwqe_platform_recovery(cd); in genwqe_health_thread()
1039 cd->card_state = GENWQE_CARD_FATAL_ERROR; in genwqe_health_thread()
1040 genwqe_stop(cd); in genwqe_health_thread()
1049 static int genwqe_health_check_start(struct genwqe_dev *cd) in genwqe_health_check_start() argument
1057 /* init_waitqueue_head(&cd->health_waitq); */ in genwqe_health_check_start()
1059 cd->health_thread = kthread_run(genwqe_health_thread, cd, in genwqe_health_check_start()
1061 cd->card_idx); in genwqe_health_check_start()
1062 if (IS_ERR(cd->health_thread)) { in genwqe_health_check_start()
1063 rc = PTR_ERR(cd->health_thread); in genwqe_health_check_start()
1064 cd->health_thread = NULL; in genwqe_health_check_start()
1070 static int genwqe_health_thread_running(struct genwqe_dev *cd) in genwqe_health_thread_running() argument
1072 return cd->health_thread != NULL; in genwqe_health_thread_running()
1075 static int genwqe_health_check_stop(struct genwqe_dev *cd) in genwqe_health_check_stop() argument
1077 if (!genwqe_health_thread_running(cd)) in genwqe_health_check_stop()
1080 kthread_stop(cd->health_thread); in genwqe_health_check_stop()
1081 cd->health_thread = NULL; in genwqe_health_check_stop()
1087 * @cd: GenWQE device information
1089 static int genwqe_pci_setup(struct genwqe_dev *cd) in genwqe_pci_setup() argument
1092 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_pci_setup()
1126 cd->mmio_len = pci_resource_len(pci_dev, 0); in genwqe_pci_setup()
1127 cd->mmio = pci_iomap(pci_dev, 0, 0); in genwqe_pci_setup()
1128 if (cd->mmio == NULL) { in genwqe_pci_setup()
1135 cd->num_vfs = pci_sriov_get_totalvfs(pci_dev); in genwqe_pci_setup()
1136 if (cd->num_vfs < 0) in genwqe_pci_setup()
1137 cd->num_vfs = 0; in genwqe_pci_setup()
1139 err = genwqe_read_ids(cd); in genwqe_pci_setup()
1146 pci_iounmap(pci_dev, cd->mmio); in genwqe_pci_setup()
1157 * @cd: GenWQE device information
1159 static void genwqe_pci_remove(struct genwqe_dev *cd) in genwqe_pci_remove() argument
1161 struct pci_dev *pci_dev = cd->pci_dev; in genwqe_pci_remove()
1163 if (cd->mmio) in genwqe_pci_remove()
1164 pci_iounmap(pci_dev, cd->mmio); in genwqe_pci_remove()
1183 struct genwqe_dev *cd; in genwqe_probe() local
1187 cd = genwqe_dev_alloc(); in genwqe_probe()
1188 if (IS_ERR(cd)) { in genwqe_probe()
1190 (int)PTR_ERR(cd)); in genwqe_probe()
1191 return PTR_ERR(cd); in genwqe_probe()
1194 dev_set_drvdata(&pci_dev->dev, cd); in genwqe_probe()
1195 cd->pci_dev = pci_dev; in genwqe_probe()
1197 err = genwqe_pci_setup(cd); in genwqe_probe()
1204 err = genwqe_start(cd); in genwqe_probe()
1211 if (genwqe_is_privileged(cd)) { in genwqe_probe()
1212 err = genwqe_health_check_start(cd); in genwqe_probe()
1223 genwqe_stop(cd); in genwqe_probe()
1225 genwqe_pci_remove(cd); in genwqe_probe()
1227 genwqe_dev_free(cd); in genwqe_probe()
1239 struct genwqe_dev *cd = dev_get_drvdata(&pci_dev->dev); in genwqe_remove() local
1241 genwqe_health_check_stop(cd); in genwqe_remove()
1248 genwqe_stop(cd); in genwqe_remove()
1249 genwqe_pci_remove(cd); in genwqe_remove()
1250 genwqe_dev_free(cd); in genwqe_remove()
1264 struct genwqe_dev *cd; in genwqe_err_error_detected() local
1268 cd = dev_get_drvdata(&pci_dev->dev); in genwqe_err_error_detected()
1269 if (cd == NULL) in genwqe_err_error_detected()
1273 genwqe_health_check_stop(cd); in genwqe_err_error_detected()
1274 genwqe_stop(cd); in genwqe_err_error_detected()
1284 genwqe_pci_remove(cd); in genwqe_err_error_detected()
1292 struct genwqe_dev *cd = dev_get_drvdata(&pci_dev->dev); in genwqe_err_slot_reset() local
1294 rc = genwqe_pci_setup(cd); in genwqe_err_slot_reset()
1312 struct genwqe_dev *cd = dev_get_drvdata(&pci_dev->dev); in genwqe_err_resume() local
1314 rc = genwqe_start(cd); in genwqe_err_resume()
1316 rc = genwqe_health_check_start(cd); in genwqe_err_resume()
1330 struct genwqe_dev *cd = dev_get_drvdata(&dev->dev); in genwqe_sriov_configure() local
1333 genwqe_setup_vf_jtimer(cd); in genwqe_sriov_configure()