Lines Matching +full:hi +full:- +full:fi
1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/io-64-nonatomic-lo-hi.h>
80 u32 device = ioread32(&stdev->mmio_sys_info->device_id); in is_firmware_running()
82 return stdev->pdev->device == device; in is_firmware_running()
91 return ERR_PTR(-ENOMEM); in stuser_create()
93 get_device(&stdev->dev); in stuser_create()
94 stuser->stdev = stdev; in stuser_create()
95 kref_init(&stuser->kref); in stuser_create()
96 INIT_LIST_HEAD(&stuser->list); in stuser_create()
97 init_waitqueue_head(&stuser->cmd_comp); in stuser_create()
98 stuser->event_cnt = atomic_read(&stdev->event_cnt); in stuser_create()
100 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); in stuser_create()
111 dev_dbg(&stuser->stdev->dev, "%s: %p\n", __func__, stuser); in stuser_free()
113 put_device(&stuser->stdev->dev); in stuser_free()
119 kref_put(&stuser->kref, stuser_free); in stuser_put()
135 stuser->state = state; in stuser_set_state()
137 dev_dbg(&stuser->stdev->dev, "stuser state %p -> %s", in stuser_set_state()
151 mmio_dbmsg = (void __iomem *)stdev->mmio_ntb + in flush_wc_buf()
153 ioread32(&mmio_dbmsg->odb); in flush_wc_buf()
162 if (stdev->mrpc_busy) in mrpc_cmd_submit()
165 if (list_empty(&stdev->mrpc_queue)) in mrpc_cmd_submit()
168 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, in mrpc_cmd_submit()
171 if (stdev->dma_mrpc) { in mrpc_cmd_submit()
172 stdev->dma_mrpc->status = SWITCHTEC_MRPC_STATUS_INPROGRESS; in mrpc_cmd_submit()
173 memset(stdev->dma_mrpc->data, 0xFF, SWITCHTEC_MRPC_PAYLOAD_SIZE); in mrpc_cmd_submit()
177 stdev->mrpc_busy = 1; in mrpc_cmd_submit()
178 memcpy_toio(&stdev->mmio_mrpc->input_data, in mrpc_cmd_submit()
179 stuser->data, stuser->data_len); in mrpc_cmd_submit()
181 iowrite32(stuser->cmd, &stdev->mmio_mrpc->cmd); in mrpc_cmd_submit()
183 schedule_delayed_work(&stdev->mrpc_timeout, in mrpc_cmd_submit()
191 struct switchtec_dev *stdev = stuser->stdev; in mrpc_queue_cmd()
193 kref_get(&stuser->kref); in mrpc_queue_cmd()
194 stuser->read_len = sizeof(stuser->data); in mrpc_queue_cmd()
196 stuser->cmd_done = false; in mrpc_queue_cmd()
197 list_add_tail(&stuser->list, &stdev->mrpc_queue); in mrpc_queue_cmd()
208 struct switchtec_user *stuser = list_entry(stdev->mrpc_queue.next, in mrpc_cleanup_cmd()
211 stuser->cmd_done = true; in mrpc_cleanup_cmd()
212 wake_up_interruptible(&stuser->cmd_comp); in mrpc_cleanup_cmd()
213 list_del_init(&stuser->list); in mrpc_cleanup_cmd()
215 stdev->mrpc_busy = 0; in mrpc_cleanup_cmd()
226 if (list_empty(&stdev->mrpc_queue)) in mrpc_complete_cmd()
229 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, in mrpc_complete_cmd()
232 if (stdev->dma_mrpc) in mrpc_complete_cmd()
233 stuser->status = stdev->dma_mrpc->status; in mrpc_complete_cmd()
235 stuser->status = ioread32(&stdev->mmio_mrpc->status); in mrpc_complete_cmd()
237 if (stuser->status == SWITCHTEC_MRPC_STATUS_INPROGRESS) in mrpc_complete_cmd()
241 stuser->return_code = 0; in mrpc_complete_cmd()
243 if (stuser->status != SWITCHTEC_MRPC_STATUS_DONE && in mrpc_complete_cmd()
244 stuser->status != SWITCHTEC_MRPC_STATUS_ERROR) in mrpc_complete_cmd()
247 if (stdev->dma_mrpc) in mrpc_complete_cmd()
248 stuser->return_code = stdev->dma_mrpc->rtn_code; in mrpc_complete_cmd()
250 stuser->return_code = ioread32(&stdev->mmio_mrpc->ret_value); in mrpc_complete_cmd()
251 if (stuser->return_code != 0) in mrpc_complete_cmd()
254 if (stdev->dma_mrpc) in mrpc_complete_cmd()
255 memcpy(stuser->data, &stdev->dma_mrpc->data, in mrpc_complete_cmd()
256 stuser->read_len); in mrpc_complete_cmd()
258 memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data, in mrpc_complete_cmd()
259 stuser->read_len); in mrpc_complete_cmd()
270 dev_dbg(&stdev->dev, "%s\n", __func__); in mrpc_event_work()
272 mutex_lock(&stdev->mrpc_mutex); in mrpc_event_work()
273 cancel_delayed_work(&stdev->mrpc_timeout); in mrpc_event_work()
275 mutex_unlock(&stdev->mrpc_mutex); in mrpc_event_work()
284 if (list_empty(&stdev->mrpc_queue)) in mrpc_error_complete_cmd()
287 stuser = list_entry(stdev->mrpc_queue.next, in mrpc_error_complete_cmd()
302 dev_dbg(&stdev->dev, "%s\n", __func__); in mrpc_timeout_work()
304 mutex_lock(&stdev->mrpc_mutex); in mrpc_timeout_work()
311 if (stdev->dma_mrpc) in mrpc_timeout_work()
312 status = stdev->dma_mrpc->status; in mrpc_timeout_work()
314 status = ioread32(&stdev->mmio_mrpc->status); in mrpc_timeout_work()
316 schedule_delayed_work(&stdev->mrpc_timeout, in mrpc_timeout_work()
323 mutex_unlock(&stdev->mrpc_mutex); in mrpc_timeout_work()
332 ver = ioread32(&stdev->mmio_sys_info->device_version); in device_version_show()
344 ver = ioread32(&stdev->mmio_sys_info->firmware_version); in fw_version_show()
358 for (i = len - 1; i > 0; i--) { in io_string_show()
373 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; \
374 if (stdev->gen == SWITCHTEC_GEN3) \
375 return io_string_show(buf, &si->gen3.field, \
376 sizeof(si->gen3.field)); \
377 else if (stdev->gen >= SWITCHTEC_GEN4) \
378 return io_string_show(buf, &si->gen4.field, \
379 sizeof(si->gen4.field)); \
381 return -EOPNOTSUPP; \
394 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; in component_vendor_show()
397 if (stdev->gen != SWITCHTEC_GEN3) in component_vendor_show()
400 return io_string_show(buf, &si->gen3.component_vendor, in component_vendor_show()
401 sizeof(si->gen3.component_vendor)); in component_vendor_show()
409 int id = ioread16(&stdev->mmio_sys_info->gen3.component_id); in component_id_show()
412 if (stdev->gen != SWITCHTEC_GEN3) in component_id_show()
423 int rev = ioread8(&stdev->mmio_sys_info->gen3.component_revision); in component_revision_show()
426 if (stdev->gen != SWITCHTEC_GEN3) in component_revision_show()
438 return sysfs_emit(buf, "%d\n", stdev->partition); in partition_show()
447 return sysfs_emit(buf, "%d\n", stdev->partition_count); in partition_count_show()
472 stdev = container_of(inode->i_cdev, struct switchtec_dev, cdev); in switchtec_dev_open()
478 filp->private_data = stuser; in switchtec_dev_open()
481 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); in switchtec_dev_open()
488 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_release()
497 if (mutex_lock_interruptible(&stdev->mrpc_mutex)) in lock_mutex_and_test_alive()
498 return -EINTR; in lock_mutex_and_test_alive()
500 if (!stdev->alive) { in lock_mutex_and_test_alive()
501 mutex_unlock(&stdev->mrpc_mutex); in lock_mutex_and_test_alive()
502 return -ENODEV; in lock_mutex_and_test_alive()
511 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_write()
512 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_write()
515 if (size < sizeof(stuser->cmd) || in switchtec_dev_write()
516 size > sizeof(stuser->cmd) + sizeof(stuser->data)) in switchtec_dev_write()
517 return -EINVAL; in switchtec_dev_write()
519 stuser->data_len = size - sizeof(stuser->cmd); in switchtec_dev_write()
525 if (stuser->state != MRPC_IDLE) { in switchtec_dev_write()
526 rc = -EBADE; in switchtec_dev_write()
530 rc = copy_from_user(&stuser->cmd, data, sizeof(stuser->cmd)); in switchtec_dev_write()
532 rc = -EFAULT; in switchtec_dev_write()
535 if (((MRPC_CMD_ID(stuser->cmd) == MRPC_GAS_WRITE) || in switchtec_dev_write()
536 (MRPC_CMD_ID(stuser->cmd) == MRPC_GAS_READ)) && in switchtec_dev_write()
538 rc = -EPERM; in switchtec_dev_write()
542 data += sizeof(stuser->cmd); in switchtec_dev_write()
543 rc = copy_from_user(&stuser->data, data, size - sizeof(stuser->cmd)); in switchtec_dev_write()
545 rc = -EFAULT; in switchtec_dev_write()
552 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_write()
563 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_read()
564 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_read()
567 if (size < sizeof(stuser->cmd) || in switchtec_dev_read()
568 size > sizeof(stuser->cmd) + sizeof(stuser->data)) in switchtec_dev_read()
569 return -EINVAL; in switchtec_dev_read()
575 if (stuser->state == MRPC_IDLE) { in switchtec_dev_read()
576 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
577 return -EBADE; in switchtec_dev_read()
580 stuser->read_len = size - sizeof(stuser->return_code); in switchtec_dev_read()
582 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
584 if (filp->f_flags & O_NONBLOCK) { in switchtec_dev_read()
585 if (!stuser->cmd_done) in switchtec_dev_read()
586 return -EAGAIN; in switchtec_dev_read()
588 rc = wait_event_interruptible(stuser->cmd_comp, in switchtec_dev_read()
589 stuser->cmd_done); in switchtec_dev_read()
598 if (stuser->state == MRPC_IO_ERROR) { in switchtec_dev_read()
599 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
600 return -EIO; in switchtec_dev_read()
603 if (stuser->state != MRPC_DONE) { in switchtec_dev_read()
604 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
605 return -EBADE; in switchtec_dev_read()
608 rc = copy_to_user(data, &stuser->return_code, in switchtec_dev_read()
609 sizeof(stuser->return_code)); in switchtec_dev_read()
611 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
612 return -EFAULT; in switchtec_dev_read()
615 data += sizeof(stuser->return_code); in switchtec_dev_read()
616 rc = copy_to_user(data, &stuser->data, in switchtec_dev_read()
617 size - sizeof(stuser->return_code)); in switchtec_dev_read()
619 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
620 return -EFAULT; in switchtec_dev_read()
625 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
627 if (stuser->status == SWITCHTEC_MRPC_STATUS_DONE || in switchtec_dev_read()
628 stuser->status == SWITCHTEC_MRPC_STATUS_ERROR) in switchtec_dev_read()
630 else if (stuser->status == SWITCHTEC_MRPC_STATUS_INTERRUPTED) in switchtec_dev_read()
631 return -ENXIO; in switchtec_dev_read()
633 return -EBADMSG; in switchtec_dev_read()
638 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_poll()
639 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_poll()
642 poll_wait(filp, &stuser->cmd_comp, wait); in switchtec_dev_poll()
643 poll_wait(filp, &stdev->event_wq, wait); in switchtec_dev_poll()
648 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_poll()
650 if (stuser->cmd_done) in switchtec_dev_poll()
653 if (stuser->event_cnt != atomic_read(&stdev->event_cnt)) in switchtec_dev_poll()
663 struct flash_info_regs __iomem *fi = stdev->mmio_flash_info; in ioctl_flash_info() local
665 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_info()
666 info.flash_length = ioread32(&fi->gen3.flash_length); in ioctl_flash_info()
668 } else if (stdev->gen >= SWITCHTEC_GEN4) { in ioctl_flash_info()
669 info.flash_length = ioread32(&fi->gen4.flash_length); in ioctl_flash_info()
672 return -EOPNOTSUPP; in ioctl_flash_info()
676 return -EFAULT; in ioctl_flash_info()
684 info->address = ioread32(&pi->address); in set_fw_info_part()
685 info->length = ioread32(&pi->length); in set_fw_info_part()
691 struct flash_info_regs_gen3 __iomem *fi = in flash_part_info_gen3() local
692 &stdev->mmio_flash_info->gen3; in flash_part_info_gen3()
693 struct sys_info_regs_gen3 __iomem *si = &stdev->mmio_sys_info->gen3; in flash_part_info_gen3()
694 u32 active_addr = -1; in flash_part_info_gen3()
696 switch (info->flash_partition) { in flash_part_info_gen3()
698 active_addr = ioread32(&fi->active_cfg); in flash_part_info_gen3()
699 set_fw_info_part(info, &fi->cfg0); in flash_part_info_gen3()
700 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN3_CFG0_RUNNING) in flash_part_info_gen3()
701 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
704 active_addr = ioread32(&fi->active_cfg); in flash_part_info_gen3()
705 set_fw_info_part(info, &fi->cfg1); in flash_part_info_gen3()
706 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN3_CFG1_RUNNING) in flash_part_info_gen3()
707 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
710 active_addr = ioread32(&fi->active_img); in flash_part_info_gen3()
711 set_fw_info_part(info, &fi->img0); in flash_part_info_gen3()
712 if (ioread16(&si->img_running) == SWITCHTEC_GEN3_IMG0_RUNNING) in flash_part_info_gen3()
713 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
716 active_addr = ioread32(&fi->active_img); in flash_part_info_gen3()
717 set_fw_info_part(info, &fi->img1); in flash_part_info_gen3()
718 if (ioread16(&si->img_running) == SWITCHTEC_GEN3_IMG1_RUNNING) in flash_part_info_gen3()
719 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
722 set_fw_info_part(info, &fi->nvlog); in flash_part_info_gen3()
725 set_fw_info_part(info, &fi->vendor[0]); in flash_part_info_gen3()
728 set_fw_info_part(info, &fi->vendor[1]); in flash_part_info_gen3()
731 set_fw_info_part(info, &fi->vendor[2]); in flash_part_info_gen3()
734 set_fw_info_part(info, &fi->vendor[3]); in flash_part_info_gen3()
737 set_fw_info_part(info, &fi->vendor[4]); in flash_part_info_gen3()
740 set_fw_info_part(info, &fi->vendor[5]); in flash_part_info_gen3()
743 set_fw_info_part(info, &fi->vendor[6]); in flash_part_info_gen3()
746 set_fw_info_part(info, &fi->vendor[7]); in flash_part_info_gen3()
749 return -EINVAL; in flash_part_info_gen3()
752 if (info->address == active_addr) in flash_part_info_gen3()
753 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen3()
761 struct flash_info_regs_gen4 __iomem *fi = &stdev->mmio_flash_info->gen4; in flash_part_info_gen4() local
762 struct sys_info_regs_gen4 __iomem *si = &stdev->mmio_sys_info->gen4; in flash_part_info_gen4()
763 struct active_partition_info_gen4 __iomem *af = &fi->active_flag; in flash_part_info_gen4()
765 switch (info->flash_partition) { in flash_part_info_gen4()
767 set_fw_info_part(info, &fi->map0); in flash_part_info_gen4()
770 set_fw_info_part(info, &fi->map1); in flash_part_info_gen4()
773 set_fw_info_part(info, &fi->key0); in flash_part_info_gen4()
774 if (ioread8(&af->key) == SWITCHTEC_GEN4_KEY0_ACTIVE) in flash_part_info_gen4()
775 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
776 if (ioread16(&si->key_running) == SWITCHTEC_GEN4_KEY0_RUNNING) in flash_part_info_gen4()
777 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
780 set_fw_info_part(info, &fi->key1); in flash_part_info_gen4()
781 if (ioread8(&af->key) == SWITCHTEC_GEN4_KEY1_ACTIVE) in flash_part_info_gen4()
782 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
783 if (ioread16(&si->key_running) == SWITCHTEC_GEN4_KEY1_RUNNING) in flash_part_info_gen4()
784 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
787 set_fw_info_part(info, &fi->bl2_0); in flash_part_info_gen4()
788 if (ioread8(&af->bl2) == SWITCHTEC_GEN4_BL2_0_ACTIVE) in flash_part_info_gen4()
789 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
790 if (ioread16(&si->bl2_running) == SWITCHTEC_GEN4_BL2_0_RUNNING) in flash_part_info_gen4()
791 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
794 set_fw_info_part(info, &fi->bl2_1); in flash_part_info_gen4()
795 if (ioread8(&af->bl2) == SWITCHTEC_GEN4_BL2_1_ACTIVE) in flash_part_info_gen4()
796 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
797 if (ioread16(&si->bl2_running) == SWITCHTEC_GEN4_BL2_1_RUNNING) in flash_part_info_gen4()
798 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
801 set_fw_info_part(info, &fi->cfg0); in flash_part_info_gen4()
802 if (ioread8(&af->cfg) == SWITCHTEC_GEN4_CFG0_ACTIVE) in flash_part_info_gen4()
803 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
804 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN4_CFG0_RUNNING) in flash_part_info_gen4()
805 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
808 set_fw_info_part(info, &fi->cfg1); in flash_part_info_gen4()
809 if (ioread8(&af->cfg) == SWITCHTEC_GEN4_CFG1_ACTIVE) in flash_part_info_gen4()
810 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
811 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN4_CFG1_RUNNING) in flash_part_info_gen4()
812 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
815 set_fw_info_part(info, &fi->img0); in flash_part_info_gen4()
816 if (ioread8(&af->img) == SWITCHTEC_GEN4_IMG0_ACTIVE) in flash_part_info_gen4()
817 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
818 if (ioread16(&si->img_running) == SWITCHTEC_GEN4_IMG0_RUNNING) in flash_part_info_gen4()
819 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
822 set_fw_info_part(info, &fi->img1); in flash_part_info_gen4()
823 if (ioread8(&af->img) == SWITCHTEC_GEN4_IMG1_ACTIVE) in flash_part_info_gen4()
824 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
825 if (ioread16(&si->img_running) == SWITCHTEC_GEN4_IMG1_RUNNING) in flash_part_info_gen4()
826 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
829 set_fw_info_part(info, &fi->nvlog); in flash_part_info_gen4()
832 set_fw_info_part(info, &fi->vendor[0]); in flash_part_info_gen4()
835 set_fw_info_part(info, &fi->vendor[1]); in flash_part_info_gen4()
838 set_fw_info_part(info, &fi->vendor[2]); in flash_part_info_gen4()
841 set_fw_info_part(info, &fi->vendor[3]); in flash_part_info_gen4()
844 set_fw_info_part(info, &fi->vendor[4]); in flash_part_info_gen4()
847 set_fw_info_part(info, &fi->vendor[5]); in flash_part_info_gen4()
850 set_fw_info_part(info, &fi->vendor[6]); in flash_part_info_gen4()
853 set_fw_info_part(info, &fi->vendor[7]); in flash_part_info_gen4()
856 return -EINVAL; in flash_part_info_gen4()
869 return -EFAULT; in ioctl_flash_part_info()
871 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_part_info()
875 } else if (stdev->gen >= SWITCHTEC_GEN4) { in ioctl_flash_part_info()
880 return -EOPNOTSUPP; in ioctl_flash_part_info()
884 return -EFAULT; in ioctl_flash_part_info()
901 return -ENOMEM; in ioctl_event_summary()
903 s->global = ioread32(&stdev->mmio_sw_event->global_summary); in ioctl_event_summary()
904 s->part_bitmap = ioread64(&stdev->mmio_sw_event->part_event_bitmap); in ioctl_event_summary()
905 s->local_part = ioread32(&stdev->mmio_part_cfg->part_event_summary); in ioctl_event_summary()
907 for (i = 0; i < stdev->partition_count; i++) { in ioctl_event_summary()
908 reg = ioread32(&stdev->mmio_part_cfg_all[i].part_event_summary); in ioctl_event_summary()
909 s->part[i] = reg; in ioctl_event_summary()
912 for (i = 0; i < stdev->pff_csr_count; i++) { in ioctl_event_summary()
913 reg = ioread32(&stdev->mmio_pff_csr[i].pff_event_summary); in ioctl_event_summary()
914 s->pff[i] = reg; in ioctl_event_summary()
918 ret = -EFAULT; in ioctl_event_summary()
922 stuser->event_cnt = atomic_read(&stdev->event_cnt); in ioctl_event_summary()
932 return (void __iomem *)stdev->mmio_sw_event + offset; in global_ev_reg()
938 return (void __iomem *)&stdev->mmio_part_cfg_all[index] + offset; in part_ev_reg()
944 return (void __iomem *)&stdev->mmio_pff_csr[index] + offset; in pff_ev_reg()
999 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
1005 index = stdev->partition; in event_hdr_addr()
1006 else if (index < 0 || index >= stdev->partition_count) in event_hdr_addr()
1007 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
1009 if (index < 0 || index >= stdev->pff_csr_count) in event_hdr_addr()
1010 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
1023 reg = event_hdr_addr(stdev, ctl->event_id, ctl->index); in event_ctl()
1029 return -EOPNOTSUPP; in event_ctl()
1031 for (i = 0; i < ARRAY_SIZE(ctl->data); i++) in event_ctl()
1032 ctl->data[i] = ioread32(®[i + 1]); in event_ctl()
1034 ctl->occurred = hdr & SWITCHTEC_EVENT_OCCURRED; in event_ctl()
1035 ctl->count = (hdr >> 5) & 0xFF; in event_ctl()
1037 if (!(ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_CLEAR)) in event_ctl()
1039 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL) in event_ctl()
1041 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_POLL) in event_ctl()
1043 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_LOG) in event_ctl()
1045 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_LOG) in event_ctl()
1047 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_CLI) in event_ctl()
1049 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_CLI) in event_ctl()
1051 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_FATAL) in event_ctl()
1053 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_FATAL) in event_ctl()
1056 if (ctl->flags) in event_ctl()
1059 ctl->flags = 0; in event_ctl()
1061 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL; in event_ctl()
1063 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_LOG; in event_ctl()
1065 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_CLI; in event_ctl()
1067 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_FATAL; in event_ctl()
1081 return -EFAULT; in ioctl_event_ctl()
1084 return -EINVAL; in ioctl_event_ctl()
1087 return -EINVAL; in ioctl_event_ctl()
1093 nr_idxs = stdev->partition_count; in ioctl_event_ctl()
1095 nr_idxs = stdev->pff_csr_count; in ioctl_event_ctl()
1097 return -EINVAL; in ioctl_event_ctl()
1103 if (ret < 0 && ret != -EOPNOTSUPP) in ioctl_event_ctl()
1113 return -EFAULT; in ioctl_event_ctl()
1127 return -EFAULT; in ioctl_pff_to_port()
1129 p.port = -1; in ioctl_pff_to_port()
1130 for (part = 0; part < stdev->partition_count; part++) { in ioctl_pff_to_port()
1131 pcfg = &stdev->mmio_part_cfg_all[part]; in ioctl_pff_to_port()
1134 reg = ioread32(&pcfg->usp_pff_inst_id); in ioctl_pff_to_port()
1140 reg = ioread32(&pcfg->vep_pff_inst_id) & 0xFF; in ioctl_pff_to_port()
1146 for (i = 0; i < ARRAY_SIZE(pcfg->dsp_pff_inst_id); i++) { in ioctl_pff_to_port()
1147 reg = ioread32(&pcfg->dsp_pff_inst_id[i]); in ioctl_pff_to_port()
1155 if (p.port != -1) in ioctl_pff_to_port()
1160 return -EFAULT; in ioctl_pff_to_port()
1172 return -EFAULT; in ioctl_port_to_pff()
1175 pcfg = stdev->mmio_part_cfg; in ioctl_port_to_pff()
1176 else if (p.partition < stdev->partition_count) in ioctl_port_to_pff()
1177 pcfg = &stdev->mmio_part_cfg_all[p.partition]; in ioctl_port_to_pff()
1179 return -EINVAL; in ioctl_port_to_pff()
1183 p.pff = ioread32(&pcfg->usp_pff_inst_id); in ioctl_port_to_pff()
1186 p.pff = ioread32(&pcfg->vep_pff_inst_id) & 0xFF; in ioctl_port_to_pff()
1189 if (p.port > ARRAY_SIZE(pcfg->dsp_pff_inst_id)) in ioctl_port_to_pff()
1190 return -EINVAL; in ioctl_port_to_pff()
1192 ARRAY_SIZE(pcfg->dsp_pff_inst_id) + 1); in ioctl_port_to_pff()
1193 p.pff = ioread32(&pcfg->dsp_pff_inst_id[p.port - 1]); in ioctl_port_to_pff()
1198 return -EFAULT; in ioctl_port_to_pff()
1206 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_ioctl()
1207 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_ioctl()
1240 rc = -ENOTTY; in switchtec_dev_ioctl()
1244 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_ioctl()
1265 if (stdev->link_notifier) in link_event_work()
1266 stdev->link_notifier(stdev); in link_event_work()
1276 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in check_link_state_events()
1277 reg = ioread32(&stdev->mmio_pff_csr[idx].link_state_hdr); in check_link_state_events()
1278 dev_dbg(&stdev->dev, "link_state: %d->%08x\n", idx, reg); in check_link_state_events()
1281 if (count != stdev->link_event_count[idx]) { in check_link_state_events()
1283 stdev->link_event_count[idx] = count; in check_link_state_events()
1288 schedule_work(&stdev->link_event_work); in check_link_state_events()
1295 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in enable_link_state_events()
1298 &stdev->mmio_pff_csr[idx].link_state_hdr); in enable_link_state_events()
1304 writeq(stdev->dma_mrpc_dma_addr, &stdev->mmio_mrpc->dma_addr); in enable_dma_mrpc()
1306 iowrite32(SWITCHTEC_DMA_MRPC_EN, &stdev->mmio_mrpc->dma_en); in enable_dma_mrpc()
1320 pci_clear_master(stdev->pdev); in stdev_kill()
1322 cancel_delayed_work_sync(&stdev->mrpc_timeout); in stdev_kill()
1325 mutex_lock(&stdev->mrpc_mutex); in stdev_kill()
1326 stdev->alive = false; in stdev_kill()
1329 list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) { in stdev_kill()
1330 stuser->cmd_done = true; in stdev_kill()
1331 wake_up_interruptible(&stuser->cmd_comp); in stdev_kill()
1332 list_del_init(&stuser->list); in stdev_kill()
1336 mutex_unlock(&stdev->mrpc_mutex); in stdev_kill()
1339 wake_up_interruptible(&stdev->event_wq); in stdev_kill()
1351 dev_to_node(&pdev->dev)); in stdev_create()
1353 return ERR_PTR(-ENOMEM); in stdev_create()
1355 stdev->alive = true; in stdev_create()
1356 stdev->pdev = pci_dev_get(pdev); in stdev_create()
1357 INIT_LIST_HEAD(&stdev->mrpc_queue); in stdev_create()
1358 mutex_init(&stdev->mrpc_mutex); in stdev_create()
1359 stdev->mrpc_busy = 0; in stdev_create()
1360 INIT_WORK(&stdev->mrpc_work, mrpc_event_work); in stdev_create()
1361 INIT_DELAYED_WORK(&stdev->mrpc_timeout, mrpc_timeout_work); in stdev_create()
1362 INIT_WORK(&stdev->link_event_work, link_event_work); in stdev_create()
1363 init_waitqueue_head(&stdev->event_wq); in stdev_create()
1364 atomic_set(&stdev->event_cnt, 0); in stdev_create()
1366 dev = &stdev->dev; in stdev_create()
1368 dev->class = &switchtec_class; in stdev_create()
1369 dev->parent = &pdev->dev; in stdev_create()
1370 dev->groups = switchtec_device_groups; in stdev_create()
1371 dev->release = stdev_release; in stdev_create()
1379 dev->devt = MKDEV(MAJOR(switchtec_devt), minor); in stdev_create()
1382 cdev = &stdev->cdev; in stdev_create()
1384 cdev->owner = THIS_MODULE; in stdev_create()
1389 pci_dev_put(stdev->pdev); in stdev_create()
1390 put_device(&stdev->dev); in stdev_create()
1409 dev_dbg(&stdev->dev, "%s: %d %d %x\n", __func__, eid, idx, hdr); in mask_event()
1422 for (idx = 0; idx < stdev->partition_count; idx++) in mask_all_events()
1425 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in mask_all_events()
1426 if (!stdev->pff_local[idx]) in mask_all_events()
1445 reg = ioread32(&stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1447 dev_dbg(&stdev->dev, "%s: mrpc comp\n", __func__); in switchtec_event_isr()
1449 schedule_work(&stdev->mrpc_work); in switchtec_event_isr()
1450 iowrite32(reg, &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1464 atomic_inc(&stdev->event_cnt); in switchtec_event_isr()
1465 wake_up_interruptible(&stdev->event_wq); in switchtec_event_isr()
1466 dev_dbg(&stdev->dev, "%s: %d events\n", __func__, in switchtec_event_isr()
1481 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_dma_mrpc_isr()
1482 schedule_work(&stdev->mrpc_work); in switchtec_dma_mrpc_isr()
1497 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, nirqs, in switchtec_init_isr()
1503 event_irq = ioread16(&stdev->mmio_part_cfg->vep_vector_number); in switchtec_init_isr()
1505 return -EFAULT; in switchtec_init_isr()
1507 event_irq = pci_irq_vector(stdev->pdev, event_irq); in switchtec_init_isr()
1511 rc = devm_request_irq(&stdev->pdev->dev, event_irq, in switchtec_init_isr()
1518 if (!stdev->dma_mrpc) in switchtec_init_isr()
1521 dma_mrpc_irq = ioread32(&stdev->mmio_mrpc->dma_vector); in switchtec_init_isr()
1523 return -EFAULT; in switchtec_init_isr()
1525 dma_mrpc_irq = pci_irq_vector(stdev->pdev, dma_mrpc_irq); in switchtec_init_isr()
1529 rc = devm_request_irq(&stdev->pdev->dev, dma_mrpc_irq, in switchtec_init_isr()
1540 struct part_cfg_regs __iomem *pcfg = stdev->mmio_part_cfg; in init_pff()
1543 reg = ioread16(&stdev->mmio_pff_csr[i].vendor_id); in init_pff()
1548 stdev->pff_csr_count = i; in init_pff()
1550 reg = ioread32(&pcfg->usp_pff_inst_id); in init_pff()
1551 if (reg < stdev->pff_csr_count) in init_pff()
1552 stdev->pff_local[reg] = 1; in init_pff()
1554 reg = ioread32(&pcfg->vep_pff_inst_id) & 0xFF; in init_pff()
1555 if (reg < stdev->pff_csr_count) in init_pff()
1556 stdev->pff_local[reg] = 1; in init_pff()
1558 for (i = 0; i < ARRAY_SIZE(pcfg->dsp_pff_inst_id); i++) { in init_pff()
1559 reg = ioread32(&pcfg->dsp_pff_inst_id[i]); in init_pff()
1560 if (reg < stdev->pff_csr_count) in init_pff()
1561 stdev->pff_local[reg] = 1; in init_pff()
1577 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in switchtec_init_pci()
1586 if (!devm_request_mem_region(&pdev->dev, res_start, in switchtec_init_pci()
1588 return -EBUSY; in switchtec_init_pci()
1590 stdev->mmio_mrpc = devm_ioremap_wc(&pdev->dev, res_start, in switchtec_init_pci()
1592 if (!stdev->mmio_mrpc) in switchtec_init_pci()
1593 return -ENOMEM; in switchtec_init_pci()
1595 map = devm_ioremap(&pdev->dev, in switchtec_init_pci()
1597 res_len - SWITCHTEC_GAS_TOP_CFG_OFFSET); in switchtec_init_pci()
1599 return -ENOMEM; in switchtec_init_pci()
1601 stdev->mmio = map - SWITCHTEC_GAS_TOP_CFG_OFFSET; in switchtec_init_pci()
1602 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET; in switchtec_init_pci()
1603 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET; in switchtec_init_pci()
1604 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET; in switchtec_init_pci()
1605 stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET; in switchtec_init_pci()
1607 if (stdev->gen == SWITCHTEC_GEN3) in switchtec_init_pci()
1608 part_id = &stdev->mmio_sys_info->gen3.partition_id; in switchtec_init_pci()
1609 else if (stdev->gen >= SWITCHTEC_GEN4) in switchtec_init_pci()
1610 part_id = &stdev->mmio_sys_info->gen4.partition_id; in switchtec_init_pci()
1612 return -EOPNOTSUPP; in switchtec_init_pci()
1614 stdev->partition = ioread8(part_id); in switchtec_init_pci()
1615 stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count); in switchtec_init_pci()
1616 stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET; in switchtec_init_pci()
1617 stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[stdev->partition]; in switchtec_init_pci()
1618 stdev->mmio_pff_csr = stdev->mmio + SWITCHTEC_GAS_PFF_CSR_OFFSET; in switchtec_init_pci()
1620 if (stdev->partition_count < 1) in switchtec_init_pci()
1621 stdev->partition_count = 1; in switchtec_init_pci()
1630 if (ioread32(&stdev->mmio_mrpc->dma_ver) == 0) in switchtec_init_pci()
1633 stdev->dma_mrpc = dma_alloc_coherent(&stdev->pdev->dev, in switchtec_init_pci()
1634 sizeof(*stdev->dma_mrpc), in switchtec_init_pci()
1635 &stdev->dma_mrpc_dma_addr, in switchtec_init_pci()
1637 if (stdev->dma_mrpc == NULL) in switchtec_init_pci()
1638 return -ENOMEM; in switchtec_init_pci()
1645 if (stdev->dma_mrpc) { in switchtec_exit_pci()
1646 iowrite32(0, &stdev->mmio_mrpc->dma_en); in switchtec_exit_pci()
1648 writeq(0, &stdev->mmio_mrpc->dma_addr); in switchtec_exit_pci()
1649 dma_free_coherent(&stdev->pdev->dev, sizeof(*stdev->dma_mrpc), in switchtec_exit_pci()
1650 stdev->dma_mrpc, stdev->dma_mrpc_dma_addr); in switchtec_exit_pci()
1651 stdev->dma_mrpc = NULL; in switchtec_exit_pci()
1661 if (pdev->class == (PCI_CLASS_BRIDGE_OTHER << 8)) in switchtec_pci_probe()
1668 stdev->gen = id->driver_data; in switchtec_pci_probe()
1676 dev_err(&stdev->dev, "failed to init isr.\n"); in switchtec_pci_probe()
1682 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_pci_probe()
1685 if (stdev->dma_mrpc) in switchtec_pci_probe()
1688 rc = cdev_device_add(&stdev->cdev, &stdev->dev); in switchtec_pci_probe()
1692 dev_info(&stdev->dev, "Management device registered.\n"); in switchtec_pci_probe()
1701 ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_probe()
1702 put_device(&stdev->dev); in switchtec_pci_probe()
1712 cdev_device_del(&stdev->cdev, &stdev->dev); in switchtec_pci_remove()
1713 ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_remove()
1714 dev_info(&stdev->dev, "unregistered.\n"); in switchtec_pci_remove()
1717 pci_dev_put(stdev->pdev); in switchtec_pci_remove()
1718 stdev->pdev = NULL; in switchtec_pci_remove()
1719 put_device(&stdev->dev); in switchtec_pci_remove()