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

1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/io-64-nonatomic-lo-hi.h>
75 return ERR_PTR(-ENOMEM); in stuser_create()
77 get_device(&stdev->dev); in stuser_create()
78 stuser->stdev = stdev; in stuser_create()
79 kref_init(&stuser->kref); in stuser_create()
80 INIT_LIST_HEAD(&stuser->list); in stuser_create()
81 init_waitqueue_head(&stuser->cmd_comp); in stuser_create()
82 stuser->event_cnt = atomic_read(&stdev->event_cnt); in stuser_create()
84 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); in stuser_create()
95 dev_dbg(&stuser->stdev->dev, "%s: %p\n", __func__, stuser); in stuser_free()
97 put_device(&stuser->stdev->dev); in stuser_free()
103 kref_put(&stuser->kref, stuser_free); in stuser_put()
118 stuser->state = state; in stuser_set_state()
120 dev_dbg(&stuser->stdev->dev, "stuser state %p -> %s", in stuser_set_state()
134 mmio_dbmsg = (void __iomem *)stdev->mmio_ntb + in flush_wc_buf()
136 ioread32(&mmio_dbmsg->odb); in flush_wc_buf()
145 if (stdev->mrpc_busy) in mrpc_cmd_submit()
148 if (list_empty(&stdev->mrpc_queue)) in mrpc_cmd_submit()
151 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, in mrpc_cmd_submit()
154 if (stdev->dma_mrpc) { in mrpc_cmd_submit()
155 stdev->dma_mrpc->status = SWITCHTEC_MRPC_STATUS_INPROGRESS; in mrpc_cmd_submit()
156 memset(stdev->dma_mrpc->data, 0xFF, SWITCHTEC_MRPC_PAYLOAD_SIZE); in mrpc_cmd_submit()
160 stdev->mrpc_busy = 1; in mrpc_cmd_submit()
161 memcpy_toio(&stdev->mmio_mrpc->input_data, in mrpc_cmd_submit()
162 stuser->data, stuser->data_len); in mrpc_cmd_submit()
164 iowrite32(stuser->cmd, &stdev->mmio_mrpc->cmd); in mrpc_cmd_submit()
166 schedule_delayed_work(&stdev->mrpc_timeout, in mrpc_cmd_submit()
174 struct switchtec_dev *stdev = stuser->stdev; in mrpc_queue_cmd()
176 kref_get(&stuser->kref); in mrpc_queue_cmd()
177 stuser->read_len = sizeof(stuser->data); in mrpc_queue_cmd()
179 stuser->cmd_done = false; in mrpc_queue_cmd()
180 list_add_tail(&stuser->list, &stdev->mrpc_queue); in mrpc_queue_cmd()
192 if (list_empty(&stdev->mrpc_queue)) in mrpc_complete_cmd()
195 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, in mrpc_complete_cmd()
198 if (stdev->dma_mrpc) in mrpc_complete_cmd()
199 stuser->status = stdev->dma_mrpc->status; in mrpc_complete_cmd()
201 stuser->status = ioread32(&stdev->mmio_mrpc->status); in mrpc_complete_cmd()
203 if (stuser->status == SWITCHTEC_MRPC_STATUS_INPROGRESS) in mrpc_complete_cmd()
207 stuser->return_code = 0; in mrpc_complete_cmd()
209 if (stuser->status != SWITCHTEC_MRPC_STATUS_DONE) in mrpc_complete_cmd()
212 if (stdev->dma_mrpc) in mrpc_complete_cmd()
213 stuser->return_code = stdev->dma_mrpc->rtn_code; in mrpc_complete_cmd()
215 stuser->return_code = ioread32(&stdev->mmio_mrpc->ret_value); in mrpc_complete_cmd()
216 if (stuser->return_code != 0) in mrpc_complete_cmd()
219 if (stdev->dma_mrpc) in mrpc_complete_cmd()
220 memcpy(stuser->data, &stdev->dma_mrpc->data, in mrpc_complete_cmd()
221 stuser->read_len); in mrpc_complete_cmd()
223 memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data, in mrpc_complete_cmd()
224 stuser->read_len); in mrpc_complete_cmd()
226 stuser->cmd_done = true; in mrpc_complete_cmd()
227 wake_up_interruptible(&stuser->cmd_comp); in mrpc_complete_cmd()
228 list_del_init(&stuser->list); in mrpc_complete_cmd()
230 stdev->mrpc_busy = 0; in mrpc_complete_cmd()
241 dev_dbg(&stdev->dev, "%s\n", __func__); in mrpc_event_work()
243 mutex_lock(&stdev->mrpc_mutex); in mrpc_event_work()
244 cancel_delayed_work(&stdev->mrpc_timeout); in mrpc_event_work()
246 mutex_unlock(&stdev->mrpc_mutex); in mrpc_event_work()
256 dev_dbg(&stdev->dev, "%s\n", __func__); in mrpc_timeout_work()
258 mutex_lock(&stdev->mrpc_mutex); in mrpc_timeout_work()
260 if (stdev->dma_mrpc) in mrpc_timeout_work()
261 status = stdev->dma_mrpc->status; in mrpc_timeout_work()
263 status = ioread32(&stdev->mmio_mrpc->status); in mrpc_timeout_work()
265 schedule_delayed_work(&stdev->mrpc_timeout, in mrpc_timeout_work()
272 mutex_unlock(&stdev->mrpc_mutex); in mrpc_timeout_work()
281 ver = ioread32(&stdev->mmio_sys_info->device_version); in device_version_show()
293 ver = ioread32(&stdev->mmio_sys_info->firmware_version); in fw_version_show()
307 for (i = len - 1; i > 0; i--) { in io_string_show()
322 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; \
323 if (stdev->gen == SWITCHTEC_GEN3) \
324 return io_string_show(buf, &si->gen3.field, \
325 sizeof(si->gen3.field)); \
326 else if (stdev->gen == SWITCHTEC_GEN4) \
327 return io_string_show(buf, &si->gen4.field, \
328 sizeof(si->gen4.field)); \
330 return -ENOTSUPP; \
343 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; in component_vendor_show()
346 if (stdev->gen != SWITCHTEC_GEN3) in component_vendor_show()
349 return io_string_show(buf, &si->gen3.component_vendor, in component_vendor_show()
350 sizeof(si->gen3.component_vendor)); in component_vendor_show()
358 int id = ioread16(&stdev->mmio_sys_info->gen3.component_id); in component_id_show()
361 if (stdev->gen != SWITCHTEC_GEN3) in component_id_show()
372 int rev = ioread8(&stdev->mmio_sys_info->gen3.component_revision); in component_revision_show()
375 if (stdev->gen != SWITCHTEC_GEN3) in component_revision_show()
387 return sprintf(buf, "%d\n", stdev->partition); in partition_show()
396 return sprintf(buf, "%d\n", stdev->partition_count); in partition_count_show()
421 stdev = container_of(inode->i_cdev, struct switchtec_dev, cdev); in switchtec_dev_open()
427 filp->private_data = stuser; in switchtec_dev_open()
430 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); in switchtec_dev_open()
437 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_release()
446 if (mutex_lock_interruptible(&stdev->mrpc_mutex)) in lock_mutex_and_test_alive()
447 return -EINTR; in lock_mutex_and_test_alive()
449 if (!stdev->alive) { in lock_mutex_and_test_alive()
450 mutex_unlock(&stdev->mrpc_mutex); in lock_mutex_and_test_alive()
451 return -ENODEV; in lock_mutex_and_test_alive()
460 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_write()
461 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_write()
464 if (size < sizeof(stuser->cmd) || in switchtec_dev_write()
465 size > sizeof(stuser->cmd) + sizeof(stuser->data)) in switchtec_dev_write()
466 return -EINVAL; in switchtec_dev_write()
468 stuser->data_len = size - sizeof(stuser->cmd); in switchtec_dev_write()
474 if (stuser->state != MRPC_IDLE) { in switchtec_dev_write()
475 rc = -EBADE; in switchtec_dev_write()
479 rc = copy_from_user(&stuser->cmd, data, sizeof(stuser->cmd)); in switchtec_dev_write()
481 rc = -EFAULT; in switchtec_dev_write()
484 if (((MRPC_CMD_ID(stuser->cmd) == MRPC_GAS_WRITE) || in switchtec_dev_write()
485 (MRPC_CMD_ID(stuser->cmd) == MRPC_GAS_READ)) && in switchtec_dev_write()
487 rc = -EPERM; in switchtec_dev_write()
491 data += sizeof(stuser->cmd); in switchtec_dev_write()
492 rc = copy_from_user(&stuser->data, data, size - sizeof(stuser->cmd)); in switchtec_dev_write()
494 rc = -EFAULT; in switchtec_dev_write()
501 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_write()
512 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_read()
513 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_read()
516 if (size < sizeof(stuser->cmd) || in switchtec_dev_read()
517 size > sizeof(stuser->cmd) + sizeof(stuser->data)) in switchtec_dev_read()
518 return -EINVAL; in switchtec_dev_read()
524 if (stuser->state == MRPC_IDLE) { in switchtec_dev_read()
525 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
526 return -EBADE; in switchtec_dev_read()
529 stuser->read_len = size - sizeof(stuser->return_code); in switchtec_dev_read()
531 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
533 if (filp->f_flags & O_NONBLOCK) { in switchtec_dev_read()
534 if (!stuser->cmd_done) in switchtec_dev_read()
535 return -EAGAIN; in switchtec_dev_read()
537 rc = wait_event_interruptible(stuser->cmd_comp, in switchtec_dev_read()
538 stuser->cmd_done); in switchtec_dev_read()
547 if (stuser->state != MRPC_DONE) { in switchtec_dev_read()
548 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
549 return -EBADE; in switchtec_dev_read()
552 rc = copy_to_user(data, &stuser->return_code, in switchtec_dev_read()
553 sizeof(stuser->return_code)); in switchtec_dev_read()
555 rc = -EFAULT; in switchtec_dev_read()
559 data += sizeof(stuser->return_code); in switchtec_dev_read()
560 rc = copy_to_user(data, &stuser->data, in switchtec_dev_read()
561 size - sizeof(stuser->return_code)); in switchtec_dev_read()
563 rc = -EFAULT; in switchtec_dev_read()
570 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
572 if (stuser->status == SWITCHTEC_MRPC_STATUS_DONE) in switchtec_dev_read()
574 else if (stuser->status == SWITCHTEC_MRPC_STATUS_INTERRUPTED) in switchtec_dev_read()
575 return -ENXIO; in switchtec_dev_read()
577 return -EBADMSG; in switchtec_dev_read()
582 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_poll()
583 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_poll()
586 poll_wait(filp, &stuser->cmd_comp, wait); in switchtec_dev_poll()
587 poll_wait(filp, &stdev->event_wq, wait); in switchtec_dev_poll()
592 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_poll()
594 if (stuser->cmd_done) in switchtec_dev_poll()
597 if (stuser->event_cnt != atomic_read(&stdev->event_cnt)) in switchtec_dev_poll()
607 struct flash_info_regs __iomem *fi = stdev->mmio_flash_info; in ioctl_flash_info() local
609 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_info()
610 info.flash_length = ioread32(&fi->gen3.flash_length); in ioctl_flash_info()
612 } else if (stdev->gen == SWITCHTEC_GEN4) { in ioctl_flash_info()
613 info.flash_length = ioread32(&fi->gen4.flash_length); in ioctl_flash_info()
616 return -ENOTSUPP; in ioctl_flash_info()
620 return -EFAULT; in ioctl_flash_info()
628 info->address = ioread32(&pi->address); in set_fw_info_part()
629 info->length = ioread32(&pi->length); in set_fw_info_part()
635 struct flash_info_regs_gen3 __iomem *fi = in flash_part_info_gen3() local
636 &stdev->mmio_flash_info->gen3; in flash_part_info_gen3()
637 struct sys_info_regs_gen3 __iomem *si = &stdev->mmio_sys_info->gen3; in flash_part_info_gen3()
638 u32 active_addr = -1; in flash_part_info_gen3()
640 switch (info->flash_partition) { in flash_part_info_gen3()
642 active_addr = ioread32(&fi->active_cfg); in flash_part_info_gen3()
643 set_fw_info_part(info, &fi->cfg0); in flash_part_info_gen3()
644 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN3_CFG0_RUNNING) in flash_part_info_gen3()
645 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
648 active_addr = ioread32(&fi->active_cfg); in flash_part_info_gen3()
649 set_fw_info_part(info, &fi->cfg1); in flash_part_info_gen3()
650 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN3_CFG1_RUNNING) in flash_part_info_gen3()
651 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
654 active_addr = ioread32(&fi->active_img); in flash_part_info_gen3()
655 set_fw_info_part(info, &fi->img0); in flash_part_info_gen3()
656 if (ioread16(&si->img_running) == SWITCHTEC_GEN3_IMG0_RUNNING) in flash_part_info_gen3()
657 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
660 active_addr = ioread32(&fi->active_img); in flash_part_info_gen3()
661 set_fw_info_part(info, &fi->img1); in flash_part_info_gen3()
662 if (ioread16(&si->img_running) == SWITCHTEC_GEN3_IMG1_RUNNING) in flash_part_info_gen3()
663 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen3()
666 set_fw_info_part(info, &fi->nvlog); in flash_part_info_gen3()
669 set_fw_info_part(info, &fi->vendor[0]); in flash_part_info_gen3()
672 set_fw_info_part(info, &fi->vendor[1]); in flash_part_info_gen3()
675 set_fw_info_part(info, &fi->vendor[2]); in flash_part_info_gen3()
678 set_fw_info_part(info, &fi->vendor[3]); in flash_part_info_gen3()
681 set_fw_info_part(info, &fi->vendor[4]); in flash_part_info_gen3()
684 set_fw_info_part(info, &fi->vendor[5]); in flash_part_info_gen3()
687 set_fw_info_part(info, &fi->vendor[6]); in flash_part_info_gen3()
690 set_fw_info_part(info, &fi->vendor[7]); in flash_part_info_gen3()
693 return -EINVAL; in flash_part_info_gen3()
696 if (info->address == active_addr) in flash_part_info_gen3()
697 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen3()
705 struct flash_info_regs_gen4 __iomem *fi = &stdev->mmio_flash_info->gen4; in flash_part_info_gen4() local
706 struct sys_info_regs_gen4 __iomem *si = &stdev->mmio_sys_info->gen4; in flash_part_info_gen4()
707 struct active_partition_info_gen4 __iomem *af = &fi->active_flag; in flash_part_info_gen4()
709 switch (info->flash_partition) { in flash_part_info_gen4()
711 set_fw_info_part(info, &fi->map0); in flash_part_info_gen4()
714 set_fw_info_part(info, &fi->map1); in flash_part_info_gen4()
717 set_fw_info_part(info, &fi->key0); in flash_part_info_gen4()
718 if (ioread8(&af->key) == SWITCHTEC_GEN4_KEY0_ACTIVE) in flash_part_info_gen4()
719 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
720 if (ioread16(&si->key_running) == SWITCHTEC_GEN4_KEY0_RUNNING) in flash_part_info_gen4()
721 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
724 set_fw_info_part(info, &fi->key1); in flash_part_info_gen4()
725 if (ioread8(&af->key) == SWITCHTEC_GEN4_KEY1_ACTIVE) in flash_part_info_gen4()
726 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
727 if (ioread16(&si->key_running) == SWITCHTEC_GEN4_KEY1_RUNNING) in flash_part_info_gen4()
728 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
731 set_fw_info_part(info, &fi->bl2_0); in flash_part_info_gen4()
732 if (ioread8(&af->bl2) == SWITCHTEC_GEN4_BL2_0_ACTIVE) in flash_part_info_gen4()
733 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
734 if (ioread16(&si->bl2_running) == SWITCHTEC_GEN4_BL2_0_RUNNING) in flash_part_info_gen4()
735 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
738 set_fw_info_part(info, &fi->bl2_1); in flash_part_info_gen4()
739 if (ioread8(&af->bl2) == SWITCHTEC_GEN4_BL2_1_ACTIVE) in flash_part_info_gen4()
740 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
741 if (ioread16(&si->bl2_running) == SWITCHTEC_GEN4_BL2_1_RUNNING) in flash_part_info_gen4()
742 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
745 set_fw_info_part(info, &fi->cfg0); in flash_part_info_gen4()
746 if (ioread8(&af->cfg) == SWITCHTEC_GEN4_CFG0_ACTIVE) in flash_part_info_gen4()
747 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
748 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN4_CFG0_RUNNING) in flash_part_info_gen4()
749 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
752 set_fw_info_part(info, &fi->cfg1); in flash_part_info_gen4()
753 if (ioread8(&af->cfg) == SWITCHTEC_GEN4_CFG1_ACTIVE) in flash_part_info_gen4()
754 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
755 if (ioread16(&si->cfg_running) == SWITCHTEC_GEN4_CFG1_RUNNING) in flash_part_info_gen4()
756 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
759 set_fw_info_part(info, &fi->img0); in flash_part_info_gen4()
760 if (ioread8(&af->img) == SWITCHTEC_GEN4_IMG0_ACTIVE) in flash_part_info_gen4()
761 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
762 if (ioread16(&si->img_running) == SWITCHTEC_GEN4_IMG0_RUNNING) in flash_part_info_gen4()
763 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
766 set_fw_info_part(info, &fi->img1); in flash_part_info_gen4()
767 if (ioread8(&af->img) == SWITCHTEC_GEN4_IMG1_ACTIVE) in flash_part_info_gen4()
768 info->active |= SWITCHTEC_IOCTL_PART_ACTIVE; in flash_part_info_gen4()
769 if (ioread16(&si->img_running) == SWITCHTEC_GEN4_IMG1_RUNNING) in flash_part_info_gen4()
770 info->active |= SWITCHTEC_IOCTL_PART_RUNNING; in flash_part_info_gen4()
773 set_fw_info_part(info, &fi->nvlog); in flash_part_info_gen4()
776 set_fw_info_part(info, &fi->vendor[0]); in flash_part_info_gen4()
779 set_fw_info_part(info, &fi->vendor[1]); in flash_part_info_gen4()
782 set_fw_info_part(info, &fi->vendor[2]); in flash_part_info_gen4()
785 set_fw_info_part(info, &fi->vendor[3]); in flash_part_info_gen4()
788 set_fw_info_part(info, &fi->vendor[4]); in flash_part_info_gen4()
791 set_fw_info_part(info, &fi->vendor[5]); in flash_part_info_gen4()
794 set_fw_info_part(info, &fi->vendor[6]); in flash_part_info_gen4()
797 set_fw_info_part(info, &fi->vendor[7]); in flash_part_info_gen4()
800 return -EINVAL; in flash_part_info_gen4()
813 return -EFAULT; in ioctl_flash_part_info()
815 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_part_info()
819 } else if (stdev->gen == SWITCHTEC_GEN4) { in ioctl_flash_part_info()
824 return -ENOTSUPP; in ioctl_flash_part_info()
828 return -EFAULT; in ioctl_flash_part_info()
845 return -ENOMEM; in ioctl_event_summary()
847 s->global = ioread32(&stdev->mmio_sw_event->global_summary); in ioctl_event_summary()
848 s->part_bitmap = ioread64(&stdev->mmio_sw_event->part_event_bitmap); in ioctl_event_summary()
849 s->local_part = ioread32(&stdev->mmio_part_cfg->part_event_summary); in ioctl_event_summary()
851 for (i = 0; i < stdev->partition_count; i++) { in ioctl_event_summary()
852 reg = ioread32(&stdev->mmio_part_cfg_all[i].part_event_summary); in ioctl_event_summary()
853 s->part[i] = reg; in ioctl_event_summary()
856 for (i = 0; i < stdev->pff_csr_count; i++) { in ioctl_event_summary()
857 reg = ioread32(&stdev->mmio_pff_csr[i].pff_event_summary); in ioctl_event_summary()
858 s->pff[i] = reg; in ioctl_event_summary()
862 ret = -EFAULT; in ioctl_event_summary()
866 stuser->event_cnt = atomic_read(&stdev->event_cnt); in ioctl_event_summary()
876 return (void __iomem *)stdev->mmio_sw_event + offset; in global_ev_reg()
882 return (void __iomem *)&stdev->mmio_part_cfg_all[index] + offset; in part_ev_reg()
888 return (void __iomem *)&stdev->mmio_pff_csr[index] + offset; in pff_ev_reg()
943 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
949 index = stdev->partition; in event_hdr_addr()
950 else if (index < 0 || index >= stdev->partition_count) in event_hdr_addr()
951 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
953 if (index < 0 || index >= stdev->pff_csr_count) in event_hdr_addr()
954 return (u32 __iomem *)ERR_PTR(-EINVAL); in event_hdr_addr()
967 reg = event_hdr_addr(stdev, ctl->event_id, ctl->index); in event_ctl()
972 for (i = 0; i < ARRAY_SIZE(ctl->data); i++) in event_ctl()
973 ctl->data[i] = ioread32(&reg[i + 1]); in event_ctl()
975 ctl->occurred = hdr & SWITCHTEC_EVENT_OCCURRED; in event_ctl()
976 ctl->count = (hdr >> 5) & 0xFF; in event_ctl()
978 if (!(ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_CLEAR)) in event_ctl()
980 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL) in event_ctl()
982 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_POLL) in event_ctl()
984 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_LOG) in event_ctl()
986 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_LOG) in event_ctl()
988 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_CLI) in event_ctl()
990 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_CLI) in event_ctl()
992 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_EN_FATAL) in event_ctl()
994 if (ctl->flags & SWITCHTEC_IOCTL_EVENT_FLAG_DIS_FATAL) in event_ctl()
997 if (ctl->flags) in event_ctl()
1000 ctl->flags = 0; in event_ctl()
1002 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL; in event_ctl()
1004 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_LOG; in event_ctl()
1006 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_CLI; in event_ctl()
1008 ctl->flags |= SWITCHTEC_IOCTL_EVENT_FLAG_EN_FATAL; in event_ctl()
1022 return -EFAULT; in ioctl_event_ctl()
1025 return -EINVAL; in ioctl_event_ctl()
1028 return -EINVAL; in ioctl_event_ctl()
1034 nr_idxs = stdev->partition_count; in ioctl_event_ctl()
1036 nr_idxs = stdev->pff_csr_count; in ioctl_event_ctl()
1038 return -EINVAL; in ioctl_event_ctl()
1054 return -EFAULT; in ioctl_event_ctl()
1068 return -EFAULT; in ioctl_pff_to_port()
1070 p.port = -1; in ioctl_pff_to_port()
1071 for (part = 0; part < stdev->partition_count; part++) { in ioctl_pff_to_port()
1072 pcfg = &stdev->mmio_part_cfg_all[part]; in ioctl_pff_to_port()
1075 reg = ioread32(&pcfg->usp_pff_inst_id); in ioctl_pff_to_port()
1081 reg = ioread32(&pcfg->vep_pff_inst_id); in ioctl_pff_to_port()
1087 for (i = 0; i < ARRAY_SIZE(pcfg->dsp_pff_inst_id); i++) { in ioctl_pff_to_port()
1088 reg = ioread32(&pcfg->dsp_pff_inst_id[i]); in ioctl_pff_to_port()
1096 if (p.port != -1) in ioctl_pff_to_port()
1101 return -EFAULT; in ioctl_pff_to_port()
1113 return -EFAULT; in ioctl_port_to_pff()
1116 pcfg = stdev->mmio_part_cfg; in ioctl_port_to_pff()
1117 else if (p.partition < stdev->partition_count) in ioctl_port_to_pff()
1118 pcfg = &stdev->mmio_part_cfg_all[p.partition]; in ioctl_port_to_pff()
1120 return -EINVAL; in ioctl_port_to_pff()
1124 p.pff = ioread32(&pcfg->usp_pff_inst_id); in ioctl_port_to_pff()
1127 p.pff = ioread32(&pcfg->vep_pff_inst_id); in ioctl_port_to_pff()
1130 if (p.port > ARRAY_SIZE(pcfg->dsp_pff_inst_id)) in ioctl_port_to_pff()
1131 return -EINVAL; in ioctl_port_to_pff()
1133 ARRAY_SIZE(pcfg->dsp_pff_inst_id) + 1); in ioctl_port_to_pff()
1134 p.pff = ioread32(&pcfg->dsp_pff_inst_id[p.port - 1]); in ioctl_port_to_pff()
1139 return -EFAULT; in ioctl_port_to_pff()
1147 struct switchtec_user *stuser = filp->private_data; in switchtec_dev_ioctl()
1148 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_ioctl()
1181 rc = -ENOTTY; in switchtec_dev_ioctl()
1185 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_ioctl()
1206 if (stdev->link_notifier) in link_event_work()
1207 stdev->link_notifier(stdev); in link_event_work()
1217 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in check_link_state_events()
1218 reg = ioread32(&stdev->mmio_pff_csr[idx].link_state_hdr); in check_link_state_events()
1219 dev_dbg(&stdev->dev, "link_state: %d->%08x\n", idx, reg); in check_link_state_events()
1222 if (count != stdev->link_event_count[idx]) { in check_link_state_events()
1224 stdev->link_event_count[idx] = count; in check_link_state_events()
1229 schedule_work(&stdev->link_event_work); in check_link_state_events()
1236 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in enable_link_state_events()
1239 &stdev->mmio_pff_csr[idx].link_state_hdr); in enable_link_state_events()
1245 writeq(stdev->dma_mrpc_dma_addr, &stdev->mmio_mrpc->dma_addr); in enable_dma_mrpc()
1247 iowrite32(SWITCHTEC_DMA_MRPC_EN, &stdev->mmio_mrpc->dma_en); in enable_dma_mrpc()
1254 if (stdev->dma_mrpc) { in stdev_release()
1255 iowrite32(0, &stdev->mmio_mrpc->dma_en); in stdev_release()
1257 writeq(0, &stdev->mmio_mrpc->dma_addr); in stdev_release()
1258 dma_free_coherent(&stdev->pdev->dev, sizeof(*stdev->dma_mrpc), in stdev_release()
1259 stdev->dma_mrpc, stdev->dma_mrpc_dma_addr); in stdev_release()
1268 pci_clear_master(stdev->pdev); in stdev_kill()
1270 cancel_delayed_work_sync(&stdev->mrpc_timeout); in stdev_kill()
1273 mutex_lock(&stdev->mrpc_mutex); in stdev_kill()
1274 stdev->alive = false; in stdev_kill()
1277 list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) { in stdev_kill()
1278 stuser->cmd_done = true; in stdev_kill()
1279 wake_up_interruptible(&stuser->cmd_comp); in stdev_kill()
1280 list_del_init(&stuser->list); in stdev_kill()
1284 mutex_unlock(&stdev->mrpc_mutex); in stdev_kill()
1287 wake_up_interruptible(&stdev->event_wq); in stdev_kill()
1299 dev_to_node(&pdev->dev)); in stdev_create()
1301 return ERR_PTR(-ENOMEM); in stdev_create()
1303 stdev->alive = true; in stdev_create()
1304 stdev->pdev = pdev; in stdev_create()
1305 INIT_LIST_HEAD(&stdev->mrpc_queue); in stdev_create()
1306 mutex_init(&stdev->mrpc_mutex); in stdev_create()
1307 stdev->mrpc_busy = 0; in stdev_create()
1308 INIT_WORK(&stdev->mrpc_work, mrpc_event_work); in stdev_create()
1309 INIT_DELAYED_WORK(&stdev->mrpc_timeout, mrpc_timeout_work); in stdev_create()
1310 INIT_WORK(&stdev->link_event_work, link_event_work); in stdev_create()
1311 init_waitqueue_head(&stdev->event_wq); in stdev_create()
1312 atomic_set(&stdev->event_cnt, 0); in stdev_create()
1314 dev = &stdev->dev; in stdev_create()
1316 dev->class = switchtec_class; in stdev_create()
1317 dev->parent = &pdev->dev; in stdev_create()
1318 dev->groups = switchtec_device_groups; in stdev_create()
1319 dev->release = stdev_release; in stdev_create()
1328 dev->devt = MKDEV(MAJOR(switchtec_devt), minor); in stdev_create()
1331 cdev = &stdev->cdev; in stdev_create()
1333 cdev->owner = THIS_MODULE; in stdev_create()
1338 put_device(&stdev->dev); in stdev_create()
1354 dev_dbg(&stdev->dev, "%s: %d %d %x\n", __func__, eid, idx, hdr); in mask_event()
1367 for (idx = 0; idx < stdev->partition_count; idx++) in mask_all_events()
1370 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in mask_all_events()
1371 if (!stdev->pff_local[idx]) in mask_all_events()
1390 reg = ioread32(&stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1392 dev_dbg(&stdev->dev, "%s: mrpc comp\n", __func__); in switchtec_event_isr()
1394 schedule_work(&stdev->mrpc_work); in switchtec_event_isr()
1395 iowrite32(reg, &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1409 atomic_inc(&stdev->event_cnt); in switchtec_event_isr()
1410 wake_up_interruptible(&stdev->event_wq); in switchtec_event_isr()
1411 dev_dbg(&stdev->dev, "%s: %d events\n", __func__, in switchtec_event_isr()
1427 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_dma_mrpc_isr()
1428 schedule_work(&stdev->mrpc_work); in switchtec_dma_mrpc_isr()
1444 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, nirqs, in switchtec_init_isr()
1450 event_irq = ioread16(&stdev->mmio_part_cfg->vep_vector_number); in switchtec_init_isr()
1452 return -EFAULT; in switchtec_init_isr()
1454 event_irq = pci_irq_vector(stdev->pdev, event_irq); in switchtec_init_isr()
1458 rc = devm_request_irq(&stdev->pdev->dev, event_irq, in switchtec_init_isr()
1465 if (!stdev->dma_mrpc) in switchtec_init_isr()
1468 dma_mrpc_irq = ioread32(&stdev->mmio_mrpc->dma_vector); in switchtec_init_isr()
1470 return -EFAULT; in switchtec_init_isr()
1472 dma_mrpc_irq = pci_irq_vector(stdev->pdev, dma_mrpc_irq); in switchtec_init_isr()
1476 rc = devm_request_irq(&stdev->pdev->dev, dma_mrpc_irq, in switchtec_init_isr()
1487 struct part_cfg_regs __iomem *pcfg = stdev->mmio_part_cfg; in init_pff()
1490 reg = ioread16(&stdev->mmio_pff_csr[i].vendor_id); in init_pff()
1495 stdev->pff_csr_count = i; in init_pff()
1497 reg = ioread32(&pcfg->usp_pff_inst_id); in init_pff()
1498 if (reg < stdev->pff_csr_count) in init_pff()
1499 stdev->pff_local[reg] = 1; in init_pff()
1501 reg = ioread32(&pcfg->vep_pff_inst_id); in init_pff()
1502 if (reg < stdev->pff_csr_count) in init_pff()
1503 stdev->pff_local[reg] = 1; in init_pff()
1505 for (i = 0; i < ARRAY_SIZE(pcfg->dsp_pff_inst_id); i++) { in init_pff()
1506 reg = ioread32(&pcfg->dsp_pff_inst_id[i]); in init_pff()
1507 if (reg < stdev->pff_csr_count) in init_pff()
1508 stdev->pff_local[reg] = 1; in init_pff()
1524 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in switchtec_init_pci()
1533 if (!devm_request_mem_region(&pdev->dev, res_start, in switchtec_init_pci()
1535 return -EBUSY; in switchtec_init_pci()
1537 stdev->mmio_mrpc = devm_ioremap_wc(&pdev->dev, res_start, in switchtec_init_pci()
1539 if (!stdev->mmio_mrpc) in switchtec_init_pci()
1540 return -ENOMEM; in switchtec_init_pci()
1542 map = devm_ioremap(&pdev->dev, in switchtec_init_pci()
1544 res_len - SWITCHTEC_GAS_TOP_CFG_OFFSET); in switchtec_init_pci()
1546 return -ENOMEM; in switchtec_init_pci()
1548 stdev->mmio = map - SWITCHTEC_GAS_TOP_CFG_OFFSET; in switchtec_init_pci()
1549 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET; in switchtec_init_pci()
1550 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET; in switchtec_init_pci()
1551 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET; in switchtec_init_pci()
1552 stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET; in switchtec_init_pci()
1554 if (stdev->gen == SWITCHTEC_GEN3) in switchtec_init_pci()
1555 part_id = &stdev->mmio_sys_info->gen3.partition_id; in switchtec_init_pci()
1556 else if (stdev->gen == SWITCHTEC_GEN4) in switchtec_init_pci()
1557 part_id = &stdev->mmio_sys_info->gen4.partition_id; in switchtec_init_pci()
1559 return -ENOTSUPP; in switchtec_init_pci()
1561 stdev->partition = ioread8(part_id); in switchtec_init_pci()
1562 stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count); in switchtec_init_pci()
1563 stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET; in switchtec_init_pci()
1564 stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[stdev->partition]; in switchtec_init_pci()
1565 stdev->mmio_pff_csr = stdev->mmio + SWITCHTEC_GAS_PFF_CSR_OFFSET; in switchtec_init_pci()
1567 if (stdev->partition_count < 1) in switchtec_init_pci()
1568 stdev->partition_count = 1; in switchtec_init_pci()
1577 if (ioread32(&stdev->mmio_mrpc->dma_ver) == 0) in switchtec_init_pci()
1580 stdev->dma_mrpc = dma_alloc_coherent(&stdev->pdev->dev, in switchtec_init_pci()
1581 sizeof(*stdev->dma_mrpc), in switchtec_init_pci()
1582 &stdev->dma_mrpc_dma_addr, in switchtec_init_pci()
1584 if (stdev->dma_mrpc == NULL) in switchtec_init_pci()
1585 return -ENOMEM; in switchtec_init_pci()
1596 if (pdev->class == (PCI_CLASS_BRIDGE_OTHER << 8)) in switchtec_pci_probe()
1603 stdev->gen = id->driver_data; in switchtec_pci_probe()
1611 dev_err(&stdev->dev, "failed to init isr.\n"); in switchtec_pci_probe()
1617 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_pci_probe()
1620 if (stdev->dma_mrpc) in switchtec_pci_probe()
1623 rc = cdev_device_add(&stdev->cdev, &stdev->dev); in switchtec_pci_probe()
1627 dev_info(&stdev->dev, "Management device registered.\n"); in switchtec_pci_probe()
1634 ida_simple_remove(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_probe()
1635 put_device(&stdev->dev); in switchtec_pci_probe()
1645 cdev_device_del(&stdev->cdev, &stdev->dev); in switchtec_pci_remove()
1646 ida_simple_remove(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_remove()
1647 dev_info(&stdev->dev, "unregistered.\n"); in switchtec_pci_remove()
1649 put_device(&stdev->dev); in switchtec_pci_remove()