Lines Matching +full:hi +full:- +full:fi

1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/io-64-nonatomic-lo-hi.h>
78 u32 device = ioread32(&stdev->mmio_sys_info->device_id); in is_firmware_running()
80 return stdev->pdev->device == device; in is_firmware_running()
89 return ERR_PTR(-ENOMEM); in stuser_create()
91 get_device(&stdev->dev); in stuser_create()
92 stuser->stdev = stdev; in stuser_create()
93 kref_init(&stuser->kref); in stuser_create()
94 INIT_LIST_HEAD(&stuser->list); in stuser_create()
95 init_waitqueue_head(&stuser->cmd_comp); in stuser_create()
96 stuser->event_cnt = atomic_read(&stdev->event_cnt); in stuser_create()
98 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); in stuser_create()
109 dev_dbg(&stuser->stdev->dev, "%s: %p\n", __func__, stuser); in stuser_free()
111 put_device(&stuser->stdev->dev); in stuser_free()
117 kref_put(&stuser->kref, stuser_free); in stuser_put()
133 stuser->state = state; in stuser_set_state()
135 dev_dbg(&stuser->stdev->dev, "stuser state %p -> %s", in stuser_set_state()
149 mmio_dbmsg = (void __iomem *)stdev->mmio_ntb + in flush_wc_buf()
151 ioread32(&mmio_dbmsg->odb); in flush_wc_buf()
160 if (stdev->mrpc_busy) in mrpc_cmd_submit()
163 if (list_empty(&stdev->mrpc_queue)) in mrpc_cmd_submit()
166 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, in mrpc_cmd_submit()
169 if (stdev->dma_mrpc) { in mrpc_cmd_submit()
170 stdev->dma_mrpc->status = SWITCHTEC_MRPC_STATUS_INPROGRESS; in mrpc_cmd_submit()
171 memset(stdev->dma_mrpc->data, 0xFF, SWITCHTEC_MRPC_PAYLOAD_SIZE); in mrpc_cmd_submit()
175 stdev->mrpc_busy = 1; in mrpc_cmd_submit()
176 memcpy_toio(&stdev->mmio_mrpc->input_data, in mrpc_cmd_submit()
177 stuser->data, stuser->data_len); in mrpc_cmd_submit()
179 iowrite32(stuser->cmd, &stdev->mmio_mrpc->cmd); in mrpc_cmd_submit()
181 schedule_delayed_work(&stdev->mrpc_timeout, in mrpc_cmd_submit()
189 struct switchtec_dev *stdev = stuser->stdev; in mrpc_queue_cmd()
191 kref_get(&stuser->kref); in mrpc_queue_cmd()
192 stuser->read_len = sizeof(stuser->data); in mrpc_queue_cmd()
194 stuser->cmd_done = false; in mrpc_queue_cmd()
195 list_add_tail(&stuser->list, &stdev->mrpc_queue); in mrpc_queue_cmd()
206 struct switchtec_user *stuser = list_entry(stdev->mrpc_queue.next, in mrpc_cleanup_cmd()
209 stuser->cmd_done = true; in mrpc_cleanup_cmd()
210 wake_up_interruptible(&stuser->cmd_comp); in mrpc_cleanup_cmd()
211 list_del_init(&stuser->list); in mrpc_cleanup_cmd()
213 stdev->mrpc_busy = 0; in mrpc_cleanup_cmd()
224 if (list_empty(&stdev->mrpc_queue)) in mrpc_complete_cmd()
227 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, in mrpc_complete_cmd()
230 if (stdev->dma_mrpc) in mrpc_complete_cmd()
231 stuser->status = stdev->dma_mrpc->status; in mrpc_complete_cmd()
233 stuser->status = ioread32(&stdev->mmio_mrpc->status); in mrpc_complete_cmd()
235 if (stuser->status == SWITCHTEC_MRPC_STATUS_INPROGRESS) in mrpc_complete_cmd()
239 stuser->return_code = 0; in mrpc_complete_cmd()
241 if (stuser->status != SWITCHTEC_MRPC_STATUS_DONE && in mrpc_complete_cmd()
242 stuser->status != SWITCHTEC_MRPC_STATUS_ERROR) in mrpc_complete_cmd()
245 if (stdev->dma_mrpc) in mrpc_complete_cmd()
246 stuser->return_code = stdev->dma_mrpc->rtn_code; in mrpc_complete_cmd()
248 stuser->return_code = ioread32(&stdev->mmio_mrpc->ret_value); in mrpc_complete_cmd()
249 if (stuser->return_code != 0) in mrpc_complete_cmd()
252 if (stdev->dma_mrpc) in mrpc_complete_cmd()
253 memcpy(stuser->data, &stdev->dma_mrpc->data, in mrpc_complete_cmd()
254 stuser->read_len); in mrpc_complete_cmd()
256 memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data, in mrpc_complete_cmd()
257 stuser->read_len); in mrpc_complete_cmd()
268 dev_dbg(&stdev->dev, "%s\n", __func__); in mrpc_event_work()
270 mutex_lock(&stdev->mrpc_mutex); in mrpc_event_work()
271 cancel_delayed_work(&stdev->mrpc_timeout); in mrpc_event_work()
273 mutex_unlock(&stdev->mrpc_mutex); in mrpc_event_work()
282 if (list_empty(&stdev->mrpc_queue)) in mrpc_error_complete_cmd()
285 stuser = list_entry(stdev->mrpc_queue.next, in mrpc_error_complete_cmd()
300 dev_dbg(&stdev->dev, "%s\n", __func__); in mrpc_timeout_work()
302 mutex_lock(&stdev->mrpc_mutex); in mrpc_timeout_work()
309 if (stdev->dma_mrpc) in mrpc_timeout_work()
310 status = stdev->dma_mrpc->status; in mrpc_timeout_work()
312 status = ioread32(&stdev->mmio_mrpc->status); in mrpc_timeout_work()
314 schedule_delayed_work(&stdev->mrpc_timeout, in mrpc_timeout_work()
321 mutex_unlock(&stdev->mrpc_mutex); in mrpc_timeout_work()
330 ver = ioread32(&stdev->mmio_sys_info->device_version); in device_version_show()
342 ver = ioread32(&stdev->mmio_sys_info->firmware_version); in fw_version_show()
356 for (i = len - 1; i > 0; i--) { in io_string_show()
371 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; \
372 if (stdev->gen == SWITCHTEC_GEN3) \
373 return io_string_show(buf, &si->gen3.field, \
374 sizeof(si->gen3.field)); \
375 else if (stdev->gen == SWITCHTEC_GEN4) \
376 return io_string_show(buf, &si->gen4.field, \
377 sizeof(si->gen4.field)); \
379 return -EOPNOTSUPP; \
392 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; in component_vendor_show()
395 if (stdev->gen != SWITCHTEC_GEN3) in component_vendor_show()
398 return io_string_show(buf, &si->gen3.component_vendor, in component_vendor_show()
399 sizeof(si->gen3.component_vendor)); in component_vendor_show()
407 int id = ioread16(&stdev->mmio_sys_info->gen3.component_id); in component_id_show()
410 if (stdev->gen != SWITCHTEC_GEN3) in component_id_show()
421 int rev = ioread8(&stdev->mmio_sys_info->gen3.component_revision); in component_revision_show()
424 if (stdev->gen != SWITCHTEC_GEN3) in component_revision_show()
436 return sysfs_emit(buf, "%d\n", stdev->partition); in partition_show()
445 return sysfs_emit(buf, "%d\n", stdev->partition_count); in partition_count_show()
470 stdev = container_of(inode->i_cdev, struct switchtec_dev, cdev); in switchtec_dev_open()
476 filp->private_data = stuser; in switchtec_dev_open()
479 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); in switchtec_dev_open()
486 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_release()
495 if (mutex_lock_interruptible(&stdev->mrpc_mutex)) in lock_mutex_and_test_alive()
496 return -EINTR; in lock_mutex_and_test_alive()
498 if (!stdev->alive) { in lock_mutex_and_test_alive()
499 mutex_unlock(&stdev->mrpc_mutex); in lock_mutex_and_test_alive()
500 return -ENODEV; in lock_mutex_and_test_alive()
509 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_write()
510 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_write()
513 if (size < sizeof(stuser->cmd) || in switchtec_dev_write()
514 size > sizeof(stuser->cmd) + sizeof(stuser->data)) in switchtec_dev_write()
515 return -EINVAL; in switchtec_dev_write()
517 stuser->data_len = size - sizeof(stuser->cmd); in switchtec_dev_write()
523 if (stuser->state != MRPC_IDLE) { in switchtec_dev_write()
524 rc = -EBADE; in switchtec_dev_write()
528 rc = copy_from_user(&stuser->cmd, data, sizeof(stuser->cmd)); in switchtec_dev_write()
530 rc = -EFAULT; in switchtec_dev_write()
533 if (((MRPC_CMD_ID(stuser->cmd) == MRPC_GAS_WRITE) || in switchtec_dev_write()
534 (MRPC_CMD_ID(stuser->cmd) == MRPC_GAS_READ)) && in switchtec_dev_write()
536 rc = -EPERM; in switchtec_dev_write()
540 data += sizeof(stuser->cmd); in switchtec_dev_write()
541 rc = copy_from_user(&stuser->data, data, size - sizeof(stuser->cmd)); in switchtec_dev_write()
543 rc = -EFAULT; in switchtec_dev_write()
550 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_write()
561 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_read()
562 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_read()
565 if (size < sizeof(stuser->cmd) || in switchtec_dev_read()
566 size > sizeof(stuser->cmd) + sizeof(stuser->data)) in switchtec_dev_read()
567 return -EINVAL; in switchtec_dev_read()
573 if (stuser->state == MRPC_IDLE) { in switchtec_dev_read()
574 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
575 return -EBADE; in switchtec_dev_read()
578 stuser->read_len = size - sizeof(stuser->return_code); in switchtec_dev_read()
580 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
582 if (filp->f_flags & O_NONBLOCK) { in switchtec_dev_read()
583 if (!stuser->cmd_done) in switchtec_dev_read()
584 return -EAGAIN; in switchtec_dev_read()
586 rc = wait_event_interruptible(stuser->cmd_comp, in switchtec_dev_read()
587 stuser->cmd_done); in switchtec_dev_read()
596 if (stuser->state == MRPC_IO_ERROR) { in switchtec_dev_read()
597 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
598 return -EIO; in switchtec_dev_read()
601 if (stuser->state != MRPC_DONE) { in switchtec_dev_read()
602 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
603 return -EBADE; in switchtec_dev_read()
606 rc = copy_to_user(data, &stuser->return_code, in switchtec_dev_read()
607 sizeof(stuser->return_code)); in switchtec_dev_read()
609 rc = -EFAULT; in switchtec_dev_read()
613 data += sizeof(stuser->return_code); in switchtec_dev_read()
614 rc = copy_to_user(data, &stuser->data, in switchtec_dev_read()
615 size - sizeof(stuser->return_code)); in switchtec_dev_read()
617 rc = -EFAULT; in switchtec_dev_read()
624 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
626 if (stuser->status == SWITCHTEC_MRPC_STATUS_DONE || in switchtec_dev_read()
627 stuser->status == SWITCHTEC_MRPC_STATUS_ERROR) in switchtec_dev_read()
629 else if (stuser->status == SWITCHTEC_MRPC_STATUS_INTERRUPTED) in switchtec_dev_read()
630 return -ENXIO; in switchtec_dev_read()
632 return -EBADMSG; in switchtec_dev_read()
637 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_poll()
638 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_poll()
641 poll_wait(filp, &stuser->cmd_comp, wait); in switchtec_dev_poll()
642 poll_wait(filp, &stdev->event_wq, wait); in switchtec_dev_poll()
647 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_poll()
649 if (stuser->cmd_done) in switchtec_dev_poll()
652 if (stuser->event_cnt != atomic_read(&stdev->event_cnt)) in switchtec_dev_poll()
662 struct flash_info_regs __iomem *fi = stdev->mmio_flash_info; in ioctl_flash_info() local
664 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_info()
665 info.flash_length = ioread32(&fi->gen3.flash_length); in ioctl_flash_info()
667 } else if (stdev->gen == SWITCHTEC_GEN4) { in ioctl_flash_info()
668 info.flash_length = ioread32(&fi->gen4.flash_length); in ioctl_flash_info()
671 return -EOPNOTSUPP; in ioctl_flash_info()
675 return -EFAULT; in ioctl_flash_info()
683 info->address = ioread32(&pi->address); in set_fw_info_part()
684 info->length = ioread32(&pi->length); in set_fw_info_part()
690 struct flash_info_regs_gen3 __iomem *fi = in flash_part_info_gen3() local
691 &stdev->mmio_flash_info->gen3; in flash_part_info_gen3()
692 struct sys_info_regs_gen3 __iomem *si = &stdev->mmio_sys_info->gen3; in flash_part_info_gen3()
693 u32 active_addr = -1; in flash_part_info_gen3()
695 switch (info->flash_partition) { in flash_part_info_gen3()
697 active_addr = ioread32(&fi->active_cfg); in flash_part_info_gen3()
698 set_fw_info_part(info, &fi->cfg0); in flash_part_info_gen3()
699 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN3_CFG0_RUNNING) in flash_part_info_gen3()
700 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
703 active_addr = ioread32(&fi->active_cfg); in flash_part_info_gen3()
704 set_fw_info_part(info, &fi->cfg1); in flash_part_info_gen3()
705 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN3_CFG1_RUNNING) in flash_part_info_gen3()
706 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
709 active_addr = ioread32(&fi->active_img); in flash_part_info_gen3()
710 set_fw_info_part(info, &fi->img0); in flash_part_info_gen3()
711 if (ioread16(&si->img_running) == SWITCHTEC_GEN3_IMG0_RUNNING) in flash_part_info_gen3()
712 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
715 active_addr = ioread32(&fi->active_img); in flash_part_info_gen3()
716 set_fw_info_part(info, &fi->img1); in flash_part_info_gen3()
717 if (ioread16(&si->img_running) == SWITCHTEC_GEN3_IMG1_RUNNING) in flash_part_info_gen3()
718 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
721 set_fw_info_part(info, &fi->nvlog); in flash_part_info_gen3()
724 set_fw_info_part(info, &fi->vendor[0]); in flash_part_info_gen3()
727 set_fw_info_part(info, &fi->vendor[1]); in flash_part_info_gen3()
730 set_fw_info_part(info, &fi->vendor[2]); in flash_part_info_gen3()
733 set_fw_info_part(info, &fi->vendor[3]); in flash_part_info_gen3()
736 set_fw_info_part(info, &fi->vendor[4]); in flash_part_info_gen3()
739 set_fw_info_part(info, &fi->vendor[5]); in flash_part_info_gen3()
742 set_fw_info_part(info, &fi->vendor[6]); in flash_part_info_gen3()
745 set_fw_info_part(info, &fi->vendor[7]); in flash_part_info_gen3()
748 return -EINVAL; in flash_part_info_gen3()
751 if (info->address == active_addr) in flash_part_info_gen3()
752 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen3()
760 struct flash_info_regs_gen4 __iomem *fi = &stdev->mmio_flash_info->gen4; in flash_part_info_gen4() local
761 struct sys_info_regs_gen4 __iomem *si = &stdev->mmio_sys_info->gen4; in flash_part_info_gen4()
762 struct active_partition_info_gen4 __iomem *af = &fi->active_flag; in flash_part_info_gen4()
764 switch (info->flash_partition) { in flash_part_info_gen4()
766 set_fw_info_part(info, &fi->map0); in flash_part_info_gen4()
769 set_fw_info_part(info, &fi->map1); in flash_part_info_gen4()
772 set_fw_info_part(info, &fi->key0); in flash_part_info_gen4()
773 if (ioread8(&af->key) == SWITCHTEC_GEN4_KEY0_ACTIVE) in flash_part_info_gen4()
774 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
775 if (ioread16(&si->key_running) == SWITCHTEC_GEN4_KEY0_RUNNING) in flash_part_info_gen4()
776 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
779 set_fw_info_part(info, &fi->key1); in flash_part_info_gen4()
780 if (ioread8(&af->key) == SWITCHTEC_GEN4_KEY1_ACTIVE) in flash_part_info_gen4()
781 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
782 if (ioread16(&si->key_running) == SWITCHTEC_GEN4_KEY1_RUNNING) in flash_part_info_gen4()
783 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
786 set_fw_info_part(info, &fi->bl2_0); in flash_part_info_gen4()
787 if (ioread8(&af->bl2) == SWITCHTEC_GEN4_BL2_0_ACTIVE) in flash_part_info_gen4()
788 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
789 if (ioread16(&si->bl2_running) == SWITCHTEC_GEN4_BL2_0_RUNNING) in flash_part_info_gen4()
790 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
793 set_fw_info_part(info, &fi->bl2_1); in flash_part_info_gen4()
794 if (ioread8(&af->bl2) == SWITCHTEC_GEN4_BL2_1_ACTIVE) in flash_part_info_gen4()
795 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
796 if (ioread16(&si->bl2_running) == SWITCHTEC_GEN4_BL2_1_RUNNING) in flash_part_info_gen4()
797 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
800 set_fw_info_part(info, &fi->cfg0); in flash_part_info_gen4()
801 if (ioread8(&af->cfg) == SWITCHTEC_GEN4_CFG0_ACTIVE) in flash_part_info_gen4()
802 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
803 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN4_CFG0_RUNNING) in flash_part_info_gen4()
804 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
807 set_fw_info_part(info, &fi->cfg1); in flash_part_info_gen4()
808 if (ioread8(&af->cfg) == SWITCHTEC_GEN4_CFG1_ACTIVE) in flash_part_info_gen4()
809 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
810 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN4_CFG1_RUNNING) in flash_part_info_gen4()
811 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
814 set_fw_info_part(info, &fi->img0); in flash_part_info_gen4()
815 if (ioread8(&af->img) == SWITCHTEC_GEN4_IMG0_ACTIVE) in flash_part_info_gen4()
816 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
817 if (ioread16(&si->img_running) == SWITCHTEC_GEN4_IMG0_RUNNING) in flash_part_info_gen4()
818 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
821 set_fw_info_part(info, &fi->img1); in flash_part_info_gen4()
822 if (ioread8(&af->img) == SWITCHTEC_GEN4_IMG1_ACTIVE) in flash_part_info_gen4()
823 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
824 if (ioread16(&si->img_running) == SWITCHTEC_GEN4_IMG1_RUNNING) in flash_part_info_gen4()
825 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
828 set_fw_info_part(info, &fi->nvlog); in flash_part_info_gen4()
831 set_fw_info_part(info, &fi->vendor[0]); in flash_part_info_gen4()
834 set_fw_info_part(info, &fi->vendor[1]); in flash_part_info_gen4()
837 set_fw_info_part(info, &fi->vendor[2]); in flash_part_info_gen4()
840 set_fw_info_part(info, &fi->vendor[3]); in flash_part_info_gen4()
843 set_fw_info_part(info, &fi->vendor[4]); in flash_part_info_gen4()
846 set_fw_info_part(info, &fi->vendor[5]); in flash_part_info_gen4()
849 set_fw_info_part(info, &fi->vendor[6]); in flash_part_info_gen4()
852 set_fw_info_part(info, &fi->vendor[7]); in flash_part_info_gen4()
855 return -EINVAL; in flash_part_info_gen4()
868 return -EFAULT; in ioctl_flash_part_info()
870 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_part_info()
874 } else if (stdev->gen == SWITCHTEC_GEN4) { in ioctl_flash_part_info()
879 return -EOPNOTSUPP; in ioctl_flash_part_info()
883 return -EFAULT; in ioctl_flash_part_info()
900 return -ENOMEM; in ioctl_event_summary()
902 s->global = ioread32(&stdev->mmio_sw_event->global_summary); in ioctl_event_summary()
903 s->part_bitmap = ioread64(&stdev->mmio_sw_event->part_event_bitmap); in ioctl_event_summary()
904 s->local_part = ioread32(&stdev->mmio_part_cfg->part_event_summary); in ioctl_event_summary()
906 for (i = 0; i < stdev->partition_count; i++) { in ioctl_event_summary()
907 reg = ioread32(&stdev->mmio_part_cfg_all[i].part_event_summary); in ioctl_event_summary()
908 s->part[i] = reg; in ioctl_event_summary()
911 for (i = 0; i < stdev->pff_csr_count; i++) { in ioctl_event_summary()
912 reg = ioread32(&stdev->mmio_pff_csr[i].pff_event_summary); in ioctl_event_summary()
913 s->pff[i] = reg; in ioctl_event_summary()
917 ret = -EFAULT; in ioctl_event_summary()
921 stuser->event_cnt = atomic_read(&stdev->event_cnt); in ioctl_event_summary()
931 return (void __iomem *)stdev->mmio_sw_event + offset; in global_ev_reg()
937 return (void __iomem *)&stdev->mmio_part_cfg_all[index] + offset; in part_ev_reg()
943 return (void __iomem *)&stdev->mmio_pff_csr[index] + offset; in pff_ev_reg()
998 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
1004 index = stdev->partition; in event_hdr_addr()
1005 else if (index < 0 || index >= stdev->partition_count) in event_hdr_addr()
1006 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
1008 if (index < 0 || index >= stdev->pff_csr_count) in event_hdr_addr()
1009 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
1022 reg = event_hdr_addr(stdev, ctl->event_id, ctl->index); in event_ctl()
1028 return -EOPNOTSUPP; in event_ctl()
1030 for (i = 0; i < ARRAY_SIZE(ctl->data); i++) in event_ctl()
1031 ctl->data[i] = ioread32(&reg[i + 1]); in event_ctl()
1033 ctl->occurred = hdr & SWITCHTEC_EVENT_OCCURRED; in event_ctl()
1034 ctl->count = (hdr >> 5) & 0xFF; in event_ctl()
1036 if (!(ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_CLEAR)) in event_ctl()
1038 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL) in event_ctl()
1040 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_POLL) in event_ctl()
1042 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_LOG) in event_ctl()
1044 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_LOG) in event_ctl()
1046 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_CLI) in event_ctl()
1048 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_CLI) in event_ctl()
1050 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_FATAL) in event_ctl()
1052 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_FATAL) in event_ctl()
1055 if (ctl->flags) in event_ctl()
1058 ctl->flags = 0; in event_ctl()
1060 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL; in event_ctl()
1062 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_LOG; in event_ctl()
1064 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_CLI; in event_ctl()
1066 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_FATAL; in event_ctl()
1080 return -EFAULT; in ioctl_event_ctl()
1083 return -EINVAL; in ioctl_event_ctl()
1086 return -EINVAL; in ioctl_event_ctl()
1092 nr_idxs = stdev->partition_count; in ioctl_event_ctl()
1094 nr_idxs = stdev->pff_csr_count; in ioctl_event_ctl()
1096 return -EINVAL; in ioctl_event_ctl()
1102 if (ret < 0 && ret != -EOPNOTSUPP) in ioctl_event_ctl()
1112 return -EFAULT; in ioctl_event_ctl()
1126 return -EFAULT; in ioctl_pff_to_port()
1128 p.port = -1; in ioctl_pff_to_port()
1129 for (part = 0; part < stdev->partition_count; part++) { in ioctl_pff_to_port()
1130 pcfg = &stdev->mmio_part_cfg_all[part]; in ioctl_pff_to_port()
1133 reg = ioread32(&pcfg->usp_pff_inst_id); in ioctl_pff_to_port()
1139 reg = ioread32(&pcfg->vep_pff_inst_id) & 0xFF; in ioctl_pff_to_port()
1145 for (i = 0; i < ARRAY_SIZE(pcfg->dsp_pff_inst_id); i++) { in ioctl_pff_to_port()
1146 reg = ioread32(&pcfg->dsp_pff_inst_id[i]); in ioctl_pff_to_port()
1154 if (p.port != -1) in ioctl_pff_to_port()
1159 return -EFAULT; in ioctl_pff_to_port()
1171 return -EFAULT; in ioctl_port_to_pff()
1174 pcfg = stdev->mmio_part_cfg; in ioctl_port_to_pff()
1175 else if (p.partition < stdev->partition_count) in ioctl_port_to_pff()
1176 pcfg = &stdev->mmio_part_cfg_all[p.partition]; in ioctl_port_to_pff()
1178 return -EINVAL; in ioctl_port_to_pff()
1182 p.pff = ioread32(&pcfg->usp_pff_inst_id); in ioctl_port_to_pff()
1185 p.pff = ioread32(&pcfg->vep_pff_inst_id) & 0xFF; in ioctl_port_to_pff()
1188 if (p.port > ARRAY_SIZE(pcfg->dsp_pff_inst_id)) in ioctl_port_to_pff()
1189 return -EINVAL; in ioctl_port_to_pff()
1191 ARRAY_SIZE(pcfg->dsp_pff_inst_id) + 1); in ioctl_port_to_pff()
1192 p.pff = ioread32(&pcfg->dsp_pff_inst_id[p.port - 1]); in ioctl_port_to_pff()
1197 return -EFAULT; in ioctl_port_to_pff()
1205 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_ioctl()
1206 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_ioctl()
1239 rc = -ENOTTY; in switchtec_dev_ioctl()
1243 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_ioctl()
1264 if (stdev->link_notifier) in link_event_work()
1265 stdev->link_notifier(stdev); in link_event_work()
1275 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in check_link_state_events()
1276 reg = ioread32(&stdev->mmio_pff_csr[idx].link_state_hdr); in check_link_state_events()
1277 dev_dbg(&stdev->dev, "link_state: %d->%08x\n", idx, reg); in check_link_state_events()
1280 if (count != stdev->link_event_count[idx]) { in check_link_state_events()
1282 stdev->link_event_count[idx] = count; in check_link_state_events()
1287 schedule_work(&stdev->link_event_work); in check_link_state_events()
1294 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in enable_link_state_events()
1297 &stdev->mmio_pff_csr[idx].link_state_hdr); in enable_link_state_events()
1303 writeq(stdev->dma_mrpc_dma_addr, &stdev->mmio_mrpc->dma_addr); in enable_dma_mrpc()
1305 iowrite32(SWITCHTEC_DMA_MRPC_EN, &stdev->mmio_mrpc->dma_en); in enable_dma_mrpc()
1312 if (stdev->dma_mrpc) { in stdev_release()
1313 iowrite32(0, &stdev->mmio_mrpc->dma_en); in stdev_release()
1315 writeq(0, &stdev->mmio_mrpc->dma_addr); in stdev_release()
1316 dma_free_coherent(&stdev->pdev->dev, sizeof(*stdev->dma_mrpc), in stdev_release()
1317 stdev->dma_mrpc, stdev->dma_mrpc_dma_addr); in stdev_release()
1326 pci_clear_master(stdev->pdev); in stdev_kill()
1328 cancel_delayed_work_sync(&stdev->mrpc_timeout); in stdev_kill()
1331 mutex_lock(&stdev->mrpc_mutex); in stdev_kill()
1332 stdev->alive = false; in stdev_kill()
1335 list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) { in stdev_kill()
1336 stuser->cmd_done = true; in stdev_kill()
1337 wake_up_interruptible(&stuser->cmd_comp); in stdev_kill()
1338 list_del_init(&stuser->list); in stdev_kill()
1342 mutex_unlock(&stdev->mrpc_mutex); in stdev_kill()
1345 wake_up_interruptible(&stdev->event_wq); in stdev_kill()
1357 dev_to_node(&pdev->dev)); in stdev_create()
1359 return ERR_PTR(-ENOMEM); in stdev_create()
1361 stdev->alive = true; in stdev_create()
1362 stdev->pdev = pdev; in stdev_create()
1363 INIT_LIST_HEAD(&stdev->mrpc_queue); in stdev_create()
1364 mutex_init(&stdev->mrpc_mutex); in stdev_create()
1365 stdev->mrpc_busy = 0; in stdev_create()
1366 INIT_WORK(&stdev->mrpc_work, mrpc_event_work); in stdev_create()
1367 INIT_DELAYED_WORK(&stdev->mrpc_timeout, mrpc_timeout_work); in stdev_create()
1368 INIT_WORK(&stdev->link_event_work, link_event_work); in stdev_create()
1369 init_waitqueue_head(&stdev->event_wq); in stdev_create()
1370 atomic_set(&stdev->event_cnt, 0); in stdev_create()
1372 dev = &stdev->dev; in stdev_create()
1374 dev->class = switchtec_class; in stdev_create()
1375 dev->parent = &pdev->dev; in stdev_create()
1376 dev->groups = switchtec_device_groups; in stdev_create()
1377 dev->release = stdev_release; in stdev_create()
1385 dev->devt = MKDEV(MAJOR(switchtec_devt), minor); in stdev_create()
1388 cdev = &stdev->cdev; in stdev_create()
1390 cdev->owner = THIS_MODULE; in stdev_create()
1395 put_device(&stdev->dev); in stdev_create()
1414 dev_dbg(&stdev->dev, "%s: %d %d %x\n", __func__, eid, idx, hdr); in mask_event()
1427 for (idx = 0; idx < stdev->partition_count; idx++) in mask_all_events()
1430 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in mask_all_events()
1431 if (!stdev->pff_local[idx]) in mask_all_events()
1450 reg = ioread32(&stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1452 dev_dbg(&stdev->dev, "%s: mrpc comp\n", __func__); in switchtec_event_isr()
1454 schedule_work(&stdev->mrpc_work); in switchtec_event_isr()
1455 iowrite32(reg, &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1469 atomic_inc(&stdev->event_cnt); in switchtec_event_isr()
1470 wake_up_interruptible(&stdev->event_wq); in switchtec_event_isr()
1471 dev_dbg(&stdev->dev, "%s: %d events\n", __func__, in switchtec_event_isr()
1487 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_dma_mrpc_isr()
1488 schedule_work(&stdev->mrpc_work); in switchtec_dma_mrpc_isr()
1504 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, nirqs, in switchtec_init_isr()
1510 event_irq = ioread16(&stdev->mmio_part_cfg->vep_vector_number); in switchtec_init_isr()
1512 return -EFAULT; in switchtec_init_isr()
1514 event_irq = pci_irq_vector(stdev->pdev, event_irq); in switchtec_init_isr()
1518 rc = devm_request_irq(&stdev->pdev->dev, event_irq, in switchtec_init_isr()
1525 if (!stdev->dma_mrpc) in switchtec_init_isr()
1528 dma_mrpc_irq = ioread32(&stdev->mmio_mrpc->dma_vector); in switchtec_init_isr()
1530 return -EFAULT; in switchtec_init_isr()
1532 dma_mrpc_irq = pci_irq_vector(stdev->pdev, dma_mrpc_irq); in switchtec_init_isr()
1536 rc = devm_request_irq(&stdev->pdev->dev, dma_mrpc_irq, in switchtec_init_isr()
1547 struct part_cfg_regs __iomem *pcfg = stdev->mmio_part_cfg; in init_pff()
1550 reg = ioread16(&stdev->mmio_pff_csr[i].vendor_id); in init_pff()
1555 stdev->pff_csr_count = i; in init_pff()
1557 reg = ioread32(&pcfg->usp_pff_inst_id); in init_pff()
1558 if (reg < stdev->pff_csr_count) in init_pff()
1559 stdev->pff_local[reg] = 1; in init_pff()
1561 reg = ioread32(&pcfg->vep_pff_inst_id) & 0xFF; in init_pff()
1562 if (reg < stdev->pff_csr_count) in init_pff()
1563 stdev->pff_local[reg] = 1; in init_pff()
1565 for (i = 0; i < ARRAY_SIZE(pcfg->dsp_pff_inst_id); i++) { in init_pff()
1566 reg = ioread32(&pcfg->dsp_pff_inst_id[i]); in init_pff()
1567 if (reg < stdev->pff_csr_count) in init_pff()
1568 stdev->pff_local[reg] = 1; in init_pff()
1584 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in switchtec_init_pci()
1593 if (!devm_request_mem_region(&pdev->dev, res_start, in switchtec_init_pci()
1595 return -EBUSY; in switchtec_init_pci()
1597 stdev->mmio_mrpc = devm_ioremap_wc(&pdev->dev, res_start, in switchtec_init_pci()
1599 if (!stdev->mmio_mrpc) in switchtec_init_pci()
1600 return -ENOMEM; in switchtec_init_pci()
1602 map = devm_ioremap(&pdev->dev, in switchtec_init_pci()
1604 res_len - SWITCHTEC_GAS_TOP_CFG_OFFSET); in switchtec_init_pci()
1606 return -ENOMEM; in switchtec_init_pci()
1608 stdev->mmio = map - SWITCHTEC_GAS_TOP_CFG_OFFSET; in switchtec_init_pci()
1609 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET; in switchtec_init_pci()
1610 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET; in switchtec_init_pci()
1611 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET; in switchtec_init_pci()
1612 stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET; in switchtec_init_pci()
1614 if (stdev->gen == SWITCHTEC_GEN3) in switchtec_init_pci()
1615 part_id = &stdev->mmio_sys_info->gen3.partition_id; in switchtec_init_pci()
1616 else if (stdev->gen == SWITCHTEC_GEN4) in switchtec_init_pci()
1617 part_id = &stdev->mmio_sys_info->gen4.partition_id; in switchtec_init_pci()
1619 return -EOPNOTSUPP; in switchtec_init_pci()
1621 stdev->partition = ioread8(part_id); in switchtec_init_pci()
1622 stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count); in switchtec_init_pci()
1623 stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET; in switchtec_init_pci()
1624 stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[stdev->partition]; in switchtec_init_pci()
1625 stdev->mmio_pff_csr = stdev->mmio + SWITCHTEC_GAS_PFF_CSR_OFFSET; in switchtec_init_pci()
1627 if (stdev->partition_count < 1) in switchtec_init_pci()
1628 stdev->partition_count = 1; in switchtec_init_pci()
1637 if (ioread32(&stdev->mmio_mrpc->dma_ver) == 0) in switchtec_init_pci()
1640 stdev->dma_mrpc = dma_alloc_coherent(&stdev->pdev->dev, in switchtec_init_pci()
1641 sizeof(*stdev->dma_mrpc), in switchtec_init_pci()
1642 &stdev->dma_mrpc_dma_addr, in switchtec_init_pci()
1644 if (stdev->dma_mrpc == NULL) in switchtec_init_pci()
1645 return -ENOMEM; in switchtec_init_pci()
1656 if (pdev->class == (PCI_CLASS_BRIDGE_OTHER << 8)) in switchtec_pci_probe()
1663 stdev->gen = id->driver_data; in switchtec_pci_probe()
1671 dev_err(&stdev->dev, "failed to init isr.\n"); in switchtec_pci_probe()
1677 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_pci_probe()
1680 if (stdev->dma_mrpc) in switchtec_pci_probe()
1683 rc = cdev_device_add(&stdev->cdev, &stdev->dev); in switchtec_pci_probe()
1687 dev_info(&stdev->dev, "Management device registered.\n"); in switchtec_pci_probe()
1694 ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_probe()
1695 put_device(&stdev->dev); in switchtec_pci_probe()
1705 cdev_device_del(&stdev->cdev, &stdev->dev); in switchtec_pci_remove()
1706 ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_remove()
1707 dev_info(&stdev->dev, "unregistered.\n"); in switchtec_pci_remove()
1709 put_device(&stdev->dev); in switchtec_pci_remove()