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 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
610 return -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 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
618 return -EFAULT; in switchtec_dev_read()
623 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
625 if (stuser->status == SWITCHTEC_MRPC_STATUS_DONE || in switchtec_dev_read()
626 stuser->status == SWITCHTEC_MRPC_STATUS_ERROR) in switchtec_dev_read()
628 else if (stuser->status == SWITCHTEC_MRPC_STATUS_INTERRUPTED) in switchtec_dev_read()
629 return -ENXIO; in switchtec_dev_read()
631 return -EBADMSG; in switchtec_dev_read()
636 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_poll()
637 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_poll()
640 poll_wait(filp, &stuser->cmd_comp, wait); in switchtec_dev_poll()
641 poll_wait(filp, &stdev->event_wq, wait); in switchtec_dev_poll()
646 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_poll()
648 if (stuser->cmd_done) in switchtec_dev_poll()
651 if (stuser->event_cnt != atomic_read(&stdev->event_cnt)) in switchtec_dev_poll()
661 struct flash_info_regs __iomem *fi = stdev->mmio_flash_info; in ioctl_flash_info() local
663 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_info()
664 info.flash_length = ioread32(&fi->gen3.flash_length); in ioctl_flash_info()
666 } else if (stdev->gen >= SWITCHTEC_GEN4) { in ioctl_flash_info()
667 info.flash_length = ioread32(&fi->gen4.flash_length); in ioctl_flash_info()
670 return -EOPNOTSUPP; in ioctl_flash_info()
674 return -EFAULT; in ioctl_flash_info()
682 info->address = ioread32(&pi->address); in set_fw_info_part()
683 info->length = ioread32(&pi->length); in set_fw_info_part()
689 struct flash_info_regs_gen3 __iomem *fi = in flash_part_info_gen3() local
690 &stdev->mmio_flash_info->gen3; in flash_part_info_gen3()
691 struct sys_info_regs_gen3 __iomem *si = &stdev->mmio_sys_info->gen3; in flash_part_info_gen3()
692 u32 active_addr = -1; in flash_part_info_gen3()
694 switch (info->flash_partition) { in flash_part_info_gen3()
696 active_addr = ioread32(&fi->active_cfg); in flash_part_info_gen3()
697 set_fw_info_part(info, &fi->cfg0); in flash_part_info_gen3()
698 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN3_CFG0_RUNNING) in flash_part_info_gen3()
699 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
702 active_addr = ioread32(&fi->active_cfg); in flash_part_info_gen3()
703 set_fw_info_part(info, &fi->cfg1); in flash_part_info_gen3()
704 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN3_CFG1_RUNNING) in flash_part_info_gen3()
705 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
708 active_addr = ioread32(&fi->active_img); in flash_part_info_gen3()
709 set_fw_info_part(info, &fi->img0); in flash_part_info_gen3()
710 if (ioread16(&si->img_running) == SWITCHTEC_GEN3_IMG0_RUNNING) in flash_part_info_gen3()
711 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
714 active_addr = ioread32(&fi->active_img); in flash_part_info_gen3()
715 set_fw_info_part(info, &fi->img1); in flash_part_info_gen3()
716 if (ioread16(&si->img_running) == SWITCHTEC_GEN3_IMG1_RUNNING) in flash_part_info_gen3()
717 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
720 set_fw_info_part(info, &fi->nvlog); in flash_part_info_gen3()
723 set_fw_info_part(info, &fi->vendor[0]); in flash_part_info_gen3()
726 set_fw_info_part(info, &fi->vendor[1]); in flash_part_info_gen3()
729 set_fw_info_part(info, &fi->vendor[2]); in flash_part_info_gen3()
732 set_fw_info_part(info, &fi->vendor[3]); in flash_part_info_gen3()
735 set_fw_info_part(info, &fi->vendor[4]); in flash_part_info_gen3()
738 set_fw_info_part(info, &fi->vendor[5]); in flash_part_info_gen3()
741 set_fw_info_part(info, &fi->vendor[6]); in flash_part_info_gen3()
744 set_fw_info_part(info, &fi->vendor[7]); in flash_part_info_gen3()
747 return -EINVAL; in flash_part_info_gen3()
750 if (info->address == active_addr) in flash_part_info_gen3()
751 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen3()
759 struct flash_info_regs_gen4 __iomem *fi = &stdev->mmio_flash_info->gen4; in flash_part_info_gen4() local
760 struct sys_info_regs_gen4 __iomem *si = &stdev->mmio_sys_info->gen4; in flash_part_info_gen4()
761 struct active_partition_info_gen4 __iomem *af = &fi->active_flag; in flash_part_info_gen4()
763 switch (info->flash_partition) { in flash_part_info_gen4()
765 set_fw_info_part(info, &fi->map0); in flash_part_info_gen4()
768 set_fw_info_part(info, &fi->map1); in flash_part_info_gen4()
771 set_fw_info_part(info, &fi->key0); in flash_part_info_gen4()
772 if (ioread8(&af->key) == SWITCHTEC_GEN4_KEY0_ACTIVE) in flash_part_info_gen4()
773 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
774 if (ioread16(&si->key_running) == SWITCHTEC_GEN4_KEY0_RUNNING) in flash_part_info_gen4()
775 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
778 set_fw_info_part(info, &fi->key1); in flash_part_info_gen4()
779 if (ioread8(&af->key) == SWITCHTEC_GEN4_KEY1_ACTIVE) in flash_part_info_gen4()
780 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
781 if (ioread16(&si->key_running) == SWITCHTEC_GEN4_KEY1_RUNNING) in flash_part_info_gen4()
782 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
785 set_fw_info_part(info, &fi->bl2_0); in flash_part_info_gen4()
786 if (ioread8(&af->bl2) == SWITCHTEC_GEN4_BL2_0_ACTIVE) in flash_part_info_gen4()
787 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
788 if (ioread16(&si->bl2_running) == SWITCHTEC_GEN4_BL2_0_RUNNING) in flash_part_info_gen4()
789 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
792 set_fw_info_part(info, &fi->bl2_1); in flash_part_info_gen4()
793 if (ioread8(&af->bl2) == SWITCHTEC_GEN4_BL2_1_ACTIVE) in flash_part_info_gen4()
794 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
795 if (ioread16(&si->bl2_running) == SWITCHTEC_GEN4_BL2_1_RUNNING) in flash_part_info_gen4()
796 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
799 set_fw_info_part(info, &fi->cfg0); in flash_part_info_gen4()
800 if (ioread8(&af->cfg) == SWITCHTEC_GEN4_CFG0_ACTIVE) in flash_part_info_gen4()
801 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
802 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN4_CFG0_RUNNING) in flash_part_info_gen4()
803 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
806 set_fw_info_part(info, &fi->cfg1); in flash_part_info_gen4()
807 if (ioread8(&af->cfg) == SWITCHTEC_GEN4_CFG1_ACTIVE) in flash_part_info_gen4()
808 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
809 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN4_CFG1_RUNNING) in flash_part_info_gen4()
810 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
813 set_fw_info_part(info, &fi->img0); in flash_part_info_gen4()
814 if (ioread8(&af->img) == SWITCHTEC_GEN4_IMG0_ACTIVE) in flash_part_info_gen4()
815 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
816 if (ioread16(&si->img_running) == SWITCHTEC_GEN4_IMG0_RUNNING) in flash_part_info_gen4()
817 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
820 set_fw_info_part(info, &fi->img1); in flash_part_info_gen4()
821 if (ioread8(&af->img) == SWITCHTEC_GEN4_IMG1_ACTIVE) in flash_part_info_gen4()
822 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
823 if (ioread16(&si->img_running) == SWITCHTEC_GEN4_IMG1_RUNNING) in flash_part_info_gen4()
824 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
827 set_fw_info_part(info, &fi->nvlog); in flash_part_info_gen4()
830 set_fw_info_part(info, &fi->vendor[0]); in flash_part_info_gen4()
833 set_fw_info_part(info, &fi->vendor[1]); in flash_part_info_gen4()
836 set_fw_info_part(info, &fi->vendor[2]); in flash_part_info_gen4()
839 set_fw_info_part(info, &fi->vendor[3]); in flash_part_info_gen4()
842 set_fw_info_part(info, &fi->vendor[4]); in flash_part_info_gen4()
845 set_fw_info_part(info, &fi->vendor[5]); in flash_part_info_gen4()
848 set_fw_info_part(info, &fi->vendor[6]); in flash_part_info_gen4()
851 set_fw_info_part(info, &fi->vendor[7]); in flash_part_info_gen4()
854 return -EINVAL; in flash_part_info_gen4()
867 return -EFAULT; in ioctl_flash_part_info()
869 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_part_info()
873 } else if (stdev->gen >= SWITCHTEC_GEN4) { in ioctl_flash_part_info()
878 return -EOPNOTSUPP; in ioctl_flash_part_info()
882 return -EFAULT; in ioctl_flash_part_info()
899 return -ENOMEM; in ioctl_event_summary()
901 s->global = ioread32(&stdev->mmio_sw_event->global_summary); in ioctl_event_summary()
902 s->part_bitmap = ioread64(&stdev->mmio_sw_event->part_event_bitmap); in ioctl_event_summary()
903 s->local_part = ioread32(&stdev->mmio_part_cfg->part_event_summary); in ioctl_event_summary()
905 for (i = 0; i < stdev->partition_count; i++) { in ioctl_event_summary()
906 reg = ioread32(&stdev->mmio_part_cfg_all[i].part_event_summary); in ioctl_event_summary()
907 s->part[i] = reg; in ioctl_event_summary()
910 for (i = 0; i < stdev->pff_csr_count; i++) { in ioctl_event_summary()
911 reg = ioread32(&stdev->mmio_pff_csr[i].pff_event_summary); in ioctl_event_summary()
912 s->pff[i] = reg; in ioctl_event_summary()
916 ret = -EFAULT; in ioctl_event_summary()
920 stuser->event_cnt = atomic_read(&stdev->event_cnt); in ioctl_event_summary()
930 return (void __iomem *)stdev->mmio_sw_event + offset; in global_ev_reg()
936 return (void __iomem *)&stdev->mmio_part_cfg_all[index] + offset; in part_ev_reg()
942 return (void __iomem *)&stdev->mmio_pff_csr[index] + offset; in pff_ev_reg()
997 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
1003 index = stdev->partition; in event_hdr_addr()
1004 else if (index < 0 || index >= stdev->partition_count) in event_hdr_addr()
1005 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
1007 if (index < 0 || index >= stdev->pff_csr_count) in event_hdr_addr()
1008 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
1021 reg = event_hdr_addr(stdev, ctl->event_id, ctl->index); in event_ctl()
1027 return -EOPNOTSUPP; in event_ctl()
1029 for (i = 0; i < ARRAY_SIZE(ctl->data); i++) in event_ctl()
1030 ctl->data[i] = ioread32(&reg[i + 1]); in event_ctl()
1032 ctl->occurred = hdr & SWITCHTEC_EVENT_OCCURRED; in event_ctl()
1033 ctl->count = (hdr >> 5) & 0xFF; in event_ctl()
1035 if (!(ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_CLEAR)) in event_ctl()
1037 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL) in event_ctl()
1039 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_POLL) in event_ctl()
1041 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_LOG) in event_ctl()
1043 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_LOG) in event_ctl()
1045 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_CLI) in event_ctl()
1047 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_CLI) in event_ctl()
1049 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_FATAL) in event_ctl()
1051 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_FATAL) in event_ctl()
1054 if (ctl->flags) in event_ctl()
1057 ctl->flags = 0; in event_ctl()
1059 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL; in event_ctl()
1061 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_LOG; in event_ctl()
1063 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_CLI; in event_ctl()
1065 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_FATAL; in event_ctl()
1079 return -EFAULT; in ioctl_event_ctl()
1082 return -EINVAL; in ioctl_event_ctl()
1085 return -EINVAL; in ioctl_event_ctl()
1091 nr_idxs = stdev->partition_count; in ioctl_event_ctl()
1093 nr_idxs = stdev->pff_csr_count; in ioctl_event_ctl()
1095 return -EINVAL; in ioctl_event_ctl()
1101 if (ret < 0 && ret != -EOPNOTSUPP) in ioctl_event_ctl()
1111 return -EFAULT; in ioctl_event_ctl()
1125 return -EFAULT; in ioctl_pff_to_port()
1127 p.port = -1; in ioctl_pff_to_port()
1128 for (part = 0; part < stdev->partition_count; part++) { in ioctl_pff_to_port()
1129 pcfg = &stdev->mmio_part_cfg_all[part]; in ioctl_pff_to_port()
1132 reg = ioread32(&pcfg->usp_pff_inst_id); in ioctl_pff_to_port()
1138 reg = ioread32(&pcfg->vep_pff_inst_id) & 0xFF; in ioctl_pff_to_port()
1144 for (i = 0; i < ARRAY_SIZE(pcfg->dsp_pff_inst_id); i++) { in ioctl_pff_to_port()
1145 reg = ioread32(&pcfg->dsp_pff_inst_id[i]); in ioctl_pff_to_port()
1153 if (p.port != -1) in ioctl_pff_to_port()
1158 return -EFAULT; in ioctl_pff_to_port()
1170 return -EFAULT; in ioctl_port_to_pff()
1173 pcfg = stdev->mmio_part_cfg; in ioctl_port_to_pff()
1174 else if (p.partition < stdev->partition_count) in ioctl_port_to_pff()
1175 pcfg = &stdev->mmio_part_cfg_all[p.partition]; in ioctl_port_to_pff()
1177 return -EINVAL; in ioctl_port_to_pff()
1181 p.pff = ioread32(&pcfg->usp_pff_inst_id); in ioctl_port_to_pff()
1184 p.pff = ioread32(&pcfg->vep_pff_inst_id) & 0xFF; in ioctl_port_to_pff()
1187 if (p.port > ARRAY_SIZE(pcfg->dsp_pff_inst_id)) in ioctl_port_to_pff()
1188 return -EINVAL; in ioctl_port_to_pff()
1190 ARRAY_SIZE(pcfg->dsp_pff_inst_id) + 1); in ioctl_port_to_pff()
1191 p.pff = ioread32(&pcfg->dsp_pff_inst_id[p.port - 1]); in ioctl_port_to_pff()
1196 return -EFAULT; in ioctl_port_to_pff()
1204 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_ioctl()
1205 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_ioctl()
1238 rc = -ENOTTY; in switchtec_dev_ioctl()
1242 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_ioctl()
1263 if (stdev->link_notifier) in link_event_work()
1264 stdev->link_notifier(stdev); in link_event_work()
1274 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in check_link_state_events()
1275 reg = ioread32(&stdev->mmio_pff_csr[idx].link_state_hdr); in check_link_state_events()
1276 dev_dbg(&stdev->dev, "link_state: %d->%08x\n", idx, reg); in check_link_state_events()
1279 if (count != stdev->link_event_count[idx]) { in check_link_state_events()
1281 stdev->link_event_count[idx] = count; in check_link_state_events()
1286 schedule_work(&stdev->link_event_work); in check_link_state_events()
1293 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in enable_link_state_events()
1296 &stdev->mmio_pff_csr[idx].link_state_hdr); in enable_link_state_events()
1302 writeq(stdev->dma_mrpc_dma_addr, &stdev->mmio_mrpc->dma_addr); in enable_dma_mrpc()
1304 iowrite32(SWITCHTEC_DMA_MRPC_EN, &stdev->mmio_mrpc->dma_en); in enable_dma_mrpc()
1318 pci_clear_master(stdev->pdev); in stdev_kill()
1320 cancel_delayed_work_sync(&stdev->mrpc_timeout); in stdev_kill()
1323 mutex_lock(&stdev->mrpc_mutex); in stdev_kill()
1324 stdev->alive = false; in stdev_kill()
1327 list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) { in stdev_kill()
1328 stuser->cmd_done = true; in stdev_kill()
1329 wake_up_interruptible(&stuser->cmd_comp); in stdev_kill()
1330 list_del_init(&stuser->list); in stdev_kill()
1334 mutex_unlock(&stdev->mrpc_mutex); in stdev_kill()
1337 wake_up_interruptible(&stdev->event_wq); in stdev_kill()
1349 dev_to_node(&pdev->dev)); in stdev_create()
1351 return ERR_PTR(-ENOMEM); in stdev_create()
1353 stdev->alive = true; in stdev_create()
1354 stdev->pdev = pci_dev_get(pdev); in stdev_create()
1355 INIT_LIST_HEAD(&stdev->mrpc_queue); in stdev_create()
1356 mutex_init(&stdev->mrpc_mutex); in stdev_create()
1357 stdev->mrpc_busy = 0; in stdev_create()
1358 INIT_WORK(&stdev->mrpc_work, mrpc_event_work); in stdev_create()
1359 INIT_DELAYED_WORK(&stdev->mrpc_timeout, mrpc_timeout_work); in stdev_create()
1360 INIT_WORK(&stdev->link_event_work, link_event_work); in stdev_create()
1361 init_waitqueue_head(&stdev->event_wq); in stdev_create()
1362 atomic_set(&stdev->event_cnt, 0); in stdev_create()
1364 dev = &stdev->dev; in stdev_create()
1366 dev->class = switchtec_class; in stdev_create()
1367 dev->parent = &pdev->dev; in stdev_create()
1368 dev->groups = switchtec_device_groups; in stdev_create()
1369 dev->release = stdev_release; in stdev_create()
1377 dev->devt = MKDEV(MAJOR(switchtec_devt), minor); in stdev_create()
1380 cdev = &stdev->cdev; in stdev_create()
1382 cdev->owner = THIS_MODULE; in stdev_create()
1387 pci_dev_put(stdev->pdev); in stdev_create()
1388 put_device(&stdev->dev); in stdev_create()
1407 dev_dbg(&stdev->dev, "%s: %d %d %x\n", __func__, eid, idx, hdr); in mask_event()
1420 for (idx = 0; idx < stdev->partition_count; idx++) in mask_all_events()
1423 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in mask_all_events()
1424 if (!stdev->pff_local[idx]) in mask_all_events()
1443 reg = ioread32(&stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1445 dev_dbg(&stdev->dev, "%s: mrpc comp\n", __func__); in switchtec_event_isr()
1447 schedule_work(&stdev->mrpc_work); in switchtec_event_isr()
1448 iowrite32(reg, &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1462 atomic_inc(&stdev->event_cnt); in switchtec_event_isr()
1463 wake_up_interruptible(&stdev->event_wq); in switchtec_event_isr()
1464 dev_dbg(&stdev->dev, "%s: %d events\n", __func__, in switchtec_event_isr()
1479 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_dma_mrpc_isr()
1480 schedule_work(&stdev->mrpc_work); in switchtec_dma_mrpc_isr()
1495 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, nirqs, in switchtec_init_isr()
1501 event_irq = ioread16(&stdev->mmio_part_cfg->vep_vector_number); in switchtec_init_isr()
1503 return -EFAULT; in switchtec_init_isr()
1505 event_irq = pci_irq_vector(stdev->pdev, event_irq); in switchtec_init_isr()
1509 rc = devm_request_irq(&stdev->pdev->dev, event_irq, in switchtec_init_isr()
1516 if (!stdev->dma_mrpc) in switchtec_init_isr()
1519 dma_mrpc_irq = ioread32(&stdev->mmio_mrpc->dma_vector); in switchtec_init_isr()
1521 return -EFAULT; in switchtec_init_isr()
1523 dma_mrpc_irq = pci_irq_vector(stdev->pdev, dma_mrpc_irq); in switchtec_init_isr()
1527 rc = devm_request_irq(&stdev->pdev->dev, dma_mrpc_irq, in switchtec_init_isr()
1538 struct part_cfg_regs __iomem *pcfg = stdev->mmio_part_cfg; in init_pff()
1541 reg = ioread16(&stdev->mmio_pff_csr[i].vendor_id); in init_pff()
1546 stdev->pff_csr_count = i; in init_pff()
1548 reg = ioread32(&pcfg->usp_pff_inst_id); in init_pff()
1549 if (reg < stdev->pff_csr_count) in init_pff()
1550 stdev->pff_local[reg] = 1; in init_pff()
1552 reg = ioread32(&pcfg->vep_pff_inst_id) & 0xFF; in init_pff()
1553 if (reg < stdev->pff_csr_count) in init_pff()
1554 stdev->pff_local[reg] = 1; in init_pff()
1556 for (i = 0; i < ARRAY_SIZE(pcfg->dsp_pff_inst_id); i++) { in init_pff()
1557 reg = ioread32(&pcfg->dsp_pff_inst_id[i]); in init_pff()
1558 if (reg < stdev->pff_csr_count) in init_pff()
1559 stdev->pff_local[reg] = 1; in init_pff()
1575 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in switchtec_init_pci()
1584 if (!devm_request_mem_region(&pdev->dev, res_start, in switchtec_init_pci()
1586 return -EBUSY; in switchtec_init_pci()
1588 stdev->mmio_mrpc = devm_ioremap_wc(&pdev->dev, res_start, in switchtec_init_pci()
1590 if (!stdev->mmio_mrpc) in switchtec_init_pci()
1591 return -ENOMEM; in switchtec_init_pci()
1593 map = devm_ioremap(&pdev->dev, in switchtec_init_pci()
1595 res_len - SWITCHTEC_GAS_TOP_CFG_OFFSET); in switchtec_init_pci()
1597 return -ENOMEM; in switchtec_init_pci()
1599 stdev->mmio = map - SWITCHTEC_GAS_TOP_CFG_OFFSET; in switchtec_init_pci()
1600 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET; in switchtec_init_pci()
1601 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET; in switchtec_init_pci()
1602 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET; in switchtec_init_pci()
1603 stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET; in switchtec_init_pci()
1605 if (stdev->gen == SWITCHTEC_GEN3) in switchtec_init_pci()
1606 part_id = &stdev->mmio_sys_info->gen3.partition_id; in switchtec_init_pci()
1607 else if (stdev->gen >= SWITCHTEC_GEN4) in switchtec_init_pci()
1608 part_id = &stdev->mmio_sys_info->gen4.partition_id; in switchtec_init_pci()
1610 return -EOPNOTSUPP; in switchtec_init_pci()
1612 stdev->partition = ioread8(part_id); in switchtec_init_pci()
1613 stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count); in switchtec_init_pci()
1614 stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET; in switchtec_init_pci()
1615 stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[stdev->partition]; in switchtec_init_pci()
1616 stdev->mmio_pff_csr = stdev->mmio + SWITCHTEC_GAS_PFF_CSR_OFFSET; in switchtec_init_pci()
1618 if (stdev->partition_count < 1) in switchtec_init_pci()
1619 stdev->partition_count = 1; in switchtec_init_pci()
1628 if (ioread32(&stdev->mmio_mrpc->dma_ver) == 0) in switchtec_init_pci()
1631 stdev->dma_mrpc = dma_alloc_coherent(&stdev->pdev->dev, in switchtec_init_pci()
1632 sizeof(*stdev->dma_mrpc), in switchtec_init_pci()
1633 &stdev->dma_mrpc_dma_addr, in switchtec_init_pci()
1635 if (stdev->dma_mrpc == NULL) in switchtec_init_pci()
1636 return -ENOMEM; in switchtec_init_pci()
1643 if (stdev->dma_mrpc) { in switchtec_exit_pci()
1644 iowrite32(0, &stdev->mmio_mrpc->dma_en); in switchtec_exit_pci()
1646 writeq(0, &stdev->mmio_mrpc->dma_addr); in switchtec_exit_pci()
1647 dma_free_coherent(&stdev->pdev->dev, sizeof(*stdev->dma_mrpc), in switchtec_exit_pci()
1648 stdev->dma_mrpc, stdev->dma_mrpc_dma_addr); in switchtec_exit_pci()
1649 stdev->dma_mrpc = NULL; in switchtec_exit_pci()
1659 if (pdev->class == (PCI_CLASS_BRIDGE_OTHER << 8)) in switchtec_pci_probe()
1666 stdev->gen = id->driver_data; in switchtec_pci_probe()
1674 dev_err(&stdev->dev, "failed to init isr.\n"); in switchtec_pci_probe()
1680 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_pci_probe()
1683 if (stdev->dma_mrpc) in switchtec_pci_probe()
1686 rc = cdev_device_add(&stdev->cdev, &stdev->dev); in switchtec_pci_probe()
1690 dev_info(&stdev->dev, "Management device registered.\n"); in switchtec_pci_probe()
1699 ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_probe()
1700 put_device(&stdev->dev); in switchtec_pci_probe()
1710 cdev_device_del(&stdev->cdev, &stdev->dev); in switchtec_pci_remove()
1711 ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_remove()
1712 dev_info(&stdev->dev, "unregistered.\n"); in switchtec_pci_remove()
1715 pci_dev_put(stdev->pdev); in switchtec_pci_remove()
1716 stdev->pdev = NULL; in switchtec_pci_remove()
1717 put_device(&stdev->dev); in switchtec_pci_remove()