Lines Matching refs:stdev
42 struct switchtec_dev *stdev; member
59 static struct switchtec_user *stuser_create(struct switchtec_dev *stdev) in stuser_create() argument
67 get_device(&stdev->dev); in stuser_create()
68 stuser->stdev = stdev; in stuser_create()
72 stuser->event_cnt = atomic_read(&stdev->event_cnt); in stuser_create()
74 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); in stuser_create()
85 dev_dbg(&stuser->stdev->dev, "%s: %p\n", __func__, stuser); in stuser_free()
87 put_device(&stuser->stdev->dev); in stuser_free()
110 dev_dbg(&stuser->stdev->dev, "stuser state %p -> %s", in stuser_set_state()
114 static void mrpc_complete_cmd(struct switchtec_dev *stdev);
116 static void mrpc_cmd_submit(struct switchtec_dev *stdev) in mrpc_cmd_submit() argument
122 if (stdev->mrpc_busy) in mrpc_cmd_submit()
125 if (list_empty(&stdev->mrpc_queue)) in mrpc_cmd_submit()
128 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, in mrpc_cmd_submit()
132 stdev->mrpc_busy = 1; in mrpc_cmd_submit()
133 memcpy_toio(&stdev->mmio_mrpc->input_data, in mrpc_cmd_submit()
135 iowrite32(stuser->cmd, &stdev->mmio_mrpc->cmd); in mrpc_cmd_submit()
137 stuser->status = ioread32(&stdev->mmio_mrpc->status); in mrpc_cmd_submit()
139 mrpc_complete_cmd(stdev); in mrpc_cmd_submit()
141 schedule_delayed_work(&stdev->mrpc_timeout, in mrpc_cmd_submit()
149 struct switchtec_dev *stdev = stuser->stdev; in mrpc_queue_cmd() local
155 list_add_tail(&stuser->list, &stdev->mrpc_queue); in mrpc_queue_cmd()
157 mrpc_cmd_submit(stdev); in mrpc_queue_cmd()
162 static void mrpc_complete_cmd(struct switchtec_dev *stdev) in mrpc_complete_cmd() argument
167 if (list_empty(&stdev->mrpc_queue)) in mrpc_complete_cmd()
170 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user, in mrpc_complete_cmd()
173 stuser->status = ioread32(&stdev->mmio_mrpc->status); in mrpc_complete_cmd()
183 stuser->return_code = ioread32(&stdev->mmio_mrpc->ret_value); in mrpc_complete_cmd()
187 memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data, in mrpc_complete_cmd()
194 stdev->mrpc_busy = 0; in mrpc_complete_cmd()
196 mrpc_cmd_submit(stdev); in mrpc_complete_cmd()
201 struct switchtec_dev *stdev; in mrpc_event_work() local
203 stdev = container_of(work, struct switchtec_dev, mrpc_work); in mrpc_event_work()
205 dev_dbg(&stdev->dev, "%s\n", __func__); in mrpc_event_work()
207 mutex_lock(&stdev->mrpc_mutex); in mrpc_event_work()
208 cancel_delayed_work(&stdev->mrpc_timeout); in mrpc_event_work()
209 mrpc_complete_cmd(stdev); in mrpc_event_work()
210 mutex_unlock(&stdev->mrpc_mutex); in mrpc_event_work()
215 struct switchtec_dev *stdev; in mrpc_timeout_work() local
218 stdev = container_of(work, struct switchtec_dev, mrpc_timeout.work); in mrpc_timeout_work()
220 dev_dbg(&stdev->dev, "%s\n", __func__); in mrpc_timeout_work()
222 mutex_lock(&stdev->mrpc_mutex); in mrpc_timeout_work()
224 status = ioread32(&stdev->mmio_mrpc->status); in mrpc_timeout_work()
226 schedule_delayed_work(&stdev->mrpc_timeout, in mrpc_timeout_work()
231 mrpc_complete_cmd(stdev); in mrpc_timeout_work()
234 mutex_unlock(&stdev->mrpc_mutex); in mrpc_timeout_work()
240 struct switchtec_dev *stdev = to_stdev(dev); in device_version_show() local
243 ver = ioread32(&stdev->mmio_sys_info->device_version); in device_version_show()
252 struct switchtec_dev *stdev = to_stdev(dev); in fw_version_show() local
255 ver = ioread32(&stdev->mmio_sys_info->firmware_version); in fw_version_show()
283 struct switchtec_dev *stdev = to_stdev(dev); \
284 return io_string_show(buf, &stdev->mmio_sys_info->field, \
285 sizeof(stdev->mmio_sys_info->field)); \
298 struct switchtec_dev *stdev = to_stdev(dev); in component_id_show() local
299 int id = ioread16(&stdev->mmio_sys_info->component_id); in component_id_show()
308 struct switchtec_dev *stdev = to_stdev(dev); in component_revision_show() local
309 int rev = ioread8(&stdev->mmio_sys_info->component_revision); in component_revision_show()
318 struct switchtec_dev *stdev = to_stdev(dev); in partition_show() local
320 return sprintf(buf, "%d\n", stdev->partition); in partition_show()
327 struct switchtec_dev *stdev = to_stdev(dev); in partition_count_show() local
329 return sprintf(buf, "%d\n", stdev->partition_count); in partition_count_show()
351 struct switchtec_dev *stdev; in switchtec_dev_open() local
354 stdev = container_of(inode->i_cdev, struct switchtec_dev, cdev); in switchtec_dev_open()
356 stuser = stuser_create(stdev); in switchtec_dev_open()
363 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); in switchtec_dev_open()
377 static int lock_mutex_and_test_alive(struct switchtec_dev *stdev) in lock_mutex_and_test_alive() argument
379 if (mutex_lock_interruptible(&stdev->mrpc_mutex)) in lock_mutex_and_test_alive()
382 if (!stdev->alive) { in lock_mutex_and_test_alive()
383 mutex_unlock(&stdev->mrpc_mutex); in lock_mutex_and_test_alive()
394 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_write() local
403 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_write()
428 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_write()
440 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_read() local
447 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_read()
452 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
458 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
469 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_read()
474 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
496 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
509 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_poll() local
513 poll_wait(filp, &stdev->event_wq, wait); in switchtec_dev_poll()
515 if (lock_mutex_and_test_alive(stdev)) in switchtec_dev_poll()
518 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_poll()
523 if (stuser->event_cnt != atomic_read(&stdev->event_cnt)) in switchtec_dev_poll()
529 static int ioctl_flash_info(struct switchtec_dev *stdev, in ioctl_flash_info() argument
533 struct flash_info_regs __iomem *fi = stdev->mmio_flash_info; in ioctl_flash_info()
551 static int ioctl_flash_part_info(struct switchtec_dev *stdev, in ioctl_flash_part_info() argument
555 struct flash_info_regs __iomem *fi = stdev->mmio_flash_info; in ioctl_flash_part_info()
556 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; in ioctl_flash_part_info()
627 static int ioctl_event_summary(struct switchtec_dev *stdev, in ioctl_event_summary() argument
635 s.global = ioread32(&stdev->mmio_sw_event->global_summary); in ioctl_event_summary()
636 s.part_bitmap = ioread32(&stdev->mmio_sw_event->part_event_bitmap); in ioctl_event_summary()
637 s.local_part = ioread32(&stdev->mmio_part_cfg->part_event_summary); in ioctl_event_summary()
639 for (i = 0; i < stdev->partition_count; i++) { in ioctl_event_summary()
640 reg = ioread32(&stdev->mmio_part_cfg_all[i].part_event_summary); in ioctl_event_summary()
645 reg = ioread16(&stdev->mmio_pff_csr[i].vendor_id); in ioctl_event_summary()
649 reg = ioread32(&stdev->mmio_pff_csr[i].pff_event_summary); in ioctl_event_summary()
656 stuser->event_cnt = atomic_read(&stdev->event_cnt); in ioctl_event_summary()
661 static u32 __iomem *global_ev_reg(struct switchtec_dev *stdev, in global_ev_reg() argument
664 return (void __iomem *)stdev->mmio_sw_event + offset; in global_ev_reg()
667 static u32 __iomem *part_ev_reg(struct switchtec_dev *stdev, in part_ev_reg() argument
670 return (void __iomem *)&stdev->mmio_part_cfg_all[index] + offset; in part_ev_reg()
673 static u32 __iomem *pff_ev_reg(struct switchtec_dev *stdev, in pff_ev_reg() argument
676 return (void __iomem *)&stdev->mmio_pff_csr[index] + offset; in pff_ev_reg()
685 u32 __iomem *(*map_reg)(struct switchtec_dev *stdev,
722 static u32 __iomem *event_hdr_addr(struct switchtec_dev *stdev, in event_hdr_addr() argument
734 index = stdev->partition; in event_hdr_addr()
735 else if (index < 0 || index >= stdev->partition_count) in event_hdr_addr()
738 if (index < 0 || index >= stdev->pff_csr_count) in event_hdr_addr()
742 return event_regs[event_id].map_reg(stdev, off, index); in event_hdr_addr()
745 static int event_ctl(struct switchtec_dev *stdev, in event_ctl() argument
752 reg = event_hdr_addr(stdev, ctl->event_id, ctl->index); in event_ctl()
798 static int ioctl_event_ctl(struct switchtec_dev *stdev, in ioctl_event_ctl() argument
818 nr_idxs = stdev->partition_count; in ioctl_event_ctl()
820 nr_idxs = stdev->pff_csr_count; in ioctl_event_ctl()
825 ret = event_ctl(stdev, &ctl); in ioctl_event_ctl()
830 ret = event_ctl(stdev, &ctl); in ioctl_event_ctl()
841 static int ioctl_pff_to_port(struct switchtec_dev *stdev, in ioctl_pff_to_port() argument
853 for (part = 0; part < stdev->partition_count; part++) { in ioctl_pff_to_port()
854 pcfg = &stdev->mmio_part_cfg_all[part]; in ioctl_pff_to_port()
888 static int ioctl_port_to_pff(struct switchtec_dev *stdev, in ioctl_port_to_pff() argument
898 pcfg = stdev->mmio_part_cfg; in ioctl_port_to_pff()
899 else if (p.partition < stdev->partition_count) in ioctl_port_to_pff()
900 pcfg = &stdev->mmio_part_cfg_all[p.partition]; in ioctl_port_to_pff()
930 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_ioctl() local
934 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_ioctl()
940 rc = ioctl_flash_info(stdev, argp); in switchtec_dev_ioctl()
943 rc = ioctl_flash_part_info(stdev, argp); in switchtec_dev_ioctl()
946 rc = ioctl_event_summary(stdev, stuser, argp); in switchtec_dev_ioctl()
949 rc = ioctl_event_ctl(stdev, argp); in switchtec_dev_ioctl()
952 rc = ioctl_pff_to_port(stdev, argp); in switchtec_dev_ioctl()
955 rc = ioctl_port_to_pff(stdev, argp); in switchtec_dev_ioctl()
962 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_ioctl()
979 struct switchtec_dev *stdev; in link_event_work() local
981 stdev = container_of(work, struct switchtec_dev, link_event_work); in link_event_work()
983 if (stdev->link_notifier) in link_event_work()
984 stdev->link_notifier(stdev); in link_event_work()
987 static void check_link_state_events(struct switchtec_dev *stdev) in check_link_state_events() argument
994 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in check_link_state_events()
995 reg = ioread32(&stdev->mmio_pff_csr[idx].link_state_hdr); in check_link_state_events()
996 dev_dbg(&stdev->dev, "link_state: %d->%08x\n", idx, reg); in check_link_state_events()
999 if (count != stdev->link_event_count[idx]) { in check_link_state_events()
1001 stdev->link_event_count[idx] = count; in check_link_state_events()
1006 schedule_work(&stdev->link_event_work); in check_link_state_events()
1009 static void enable_link_state_events(struct switchtec_dev *stdev) in enable_link_state_events() argument
1013 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in enable_link_state_events()
1016 &stdev->mmio_pff_csr[idx].link_state_hdr); in enable_link_state_events()
1022 struct switchtec_dev *stdev = to_stdev(dev); in stdev_release() local
1024 kfree(stdev); in stdev_release()
1027 static void stdev_kill(struct switchtec_dev *stdev) in stdev_kill() argument
1031 pci_clear_master(stdev->pdev); in stdev_kill()
1033 cancel_delayed_work_sync(&stdev->mrpc_timeout); in stdev_kill()
1036 mutex_lock(&stdev->mrpc_mutex); in stdev_kill()
1037 stdev->alive = false; in stdev_kill()
1040 list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) { in stdev_kill()
1046 mutex_unlock(&stdev->mrpc_mutex); in stdev_kill()
1049 wake_up_interruptible(&stdev->event_wq); in stdev_kill()
1054 struct switchtec_dev *stdev; in stdev_create() local
1060 stdev = kzalloc_node(sizeof(*stdev), GFP_KERNEL, in stdev_create()
1062 if (!stdev) in stdev_create()
1065 stdev->alive = true; in stdev_create()
1066 stdev->pdev = pdev; in stdev_create()
1067 INIT_LIST_HEAD(&stdev->mrpc_queue); in stdev_create()
1068 mutex_init(&stdev->mrpc_mutex); in stdev_create()
1069 stdev->mrpc_busy = 0; in stdev_create()
1070 INIT_WORK(&stdev->mrpc_work, mrpc_event_work); in stdev_create()
1071 INIT_DELAYED_WORK(&stdev->mrpc_timeout, mrpc_timeout_work); in stdev_create()
1072 INIT_WORK(&stdev->link_event_work, link_event_work); in stdev_create()
1073 init_waitqueue_head(&stdev->event_wq); in stdev_create()
1074 atomic_set(&stdev->event_cnt, 0); in stdev_create()
1076 dev = &stdev->dev; in stdev_create()
1093 cdev = &stdev->cdev; in stdev_create()
1097 return stdev; in stdev_create()
1100 put_device(&stdev->dev); in stdev_create()
1104 static int mask_event(struct switchtec_dev *stdev, int eid, int idx) in mask_event() argument
1110 hdr_reg = event_regs[eid].map_reg(stdev, off, idx); in mask_event()
1119 dev_dbg(&stdev->dev, "%s: %d %d %x\n", __func__, eid, idx, hdr); in mask_event()
1126 static int mask_all_events(struct switchtec_dev *stdev, int eid) in mask_all_events() argument
1132 for (idx = 0; idx < stdev->partition_count; idx++) in mask_all_events()
1133 count += mask_event(stdev, eid, idx); in mask_all_events()
1135 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in mask_all_events()
1136 if (!stdev->pff_local[idx]) in mask_all_events()
1139 count += mask_event(stdev, eid, idx); in mask_all_events()
1142 count += mask_event(stdev, eid, 0); in mask_all_events()
1150 struct switchtec_dev *stdev = dev; in switchtec_event_isr() local
1155 reg = ioread32(&stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1157 dev_dbg(&stdev->dev, "%s: mrpc comp\n", __func__); in switchtec_event_isr()
1159 schedule_work(&stdev->mrpc_work); in switchtec_event_isr()
1160 iowrite32(reg, &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1163 check_link_state_events(stdev); in switchtec_event_isr()
1166 event_count += mask_all_events(stdev, eid); in switchtec_event_isr()
1169 atomic_inc(&stdev->event_cnt); in switchtec_event_isr()
1170 wake_up_interruptible(&stdev->event_wq); in switchtec_event_isr()
1171 dev_dbg(&stdev->dev, "%s: %d events\n", __func__, in switchtec_event_isr()
1179 static int switchtec_init_isr(struct switchtec_dev *stdev) in switchtec_init_isr() argument
1184 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, 4, in switchtec_init_isr()
1189 event_irq = ioread32(&stdev->mmio_part_cfg->vep_vector_number); in switchtec_init_isr()
1193 event_irq = pci_irq_vector(stdev->pdev, event_irq); in switchtec_init_isr()
1197 return devm_request_irq(&stdev->pdev->dev, event_irq, in switchtec_init_isr()
1199 KBUILD_MODNAME, stdev); in switchtec_init_isr()
1202 static void init_pff(struct switchtec_dev *stdev) in init_pff() argument
1206 struct part_cfg_regs *pcfg = stdev->mmio_part_cfg; in init_pff()
1209 reg = ioread16(&stdev->mmio_pff_csr[i].vendor_id); in init_pff()
1214 stdev->pff_csr_count = i; in init_pff()
1218 stdev->pff_local[reg] = 1; in init_pff()
1222 stdev->pff_local[reg] = 1; in init_pff()
1227 stdev->pff_local[reg] = 1; in init_pff()
1231 static int switchtec_init_pci(struct switchtec_dev *stdev, in switchtec_init_pci() argument
1246 stdev->mmio = pcim_iomap_table(pdev)[0]; in switchtec_init_pci()
1247 stdev->mmio_mrpc = stdev->mmio + SWITCHTEC_GAS_MRPC_OFFSET; in switchtec_init_pci()
1248 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET; in switchtec_init_pci()
1249 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET; in switchtec_init_pci()
1250 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET; in switchtec_init_pci()
1251 stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET; in switchtec_init_pci()
1252 stdev->partition = ioread8(&stdev->mmio_sys_info->partition_id); in switchtec_init_pci()
1253 stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count); in switchtec_init_pci()
1254 stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET; in switchtec_init_pci()
1255 stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[stdev->partition]; in switchtec_init_pci()
1256 stdev->mmio_pff_csr = stdev->mmio + SWITCHTEC_GAS_PFF_CSR_OFFSET; in switchtec_init_pci()
1258 if (stdev->partition_count < 1) in switchtec_init_pci()
1259 stdev->partition_count = 1; in switchtec_init_pci()
1261 init_pff(stdev); in switchtec_init_pci()
1263 pci_set_drvdata(pdev, stdev); in switchtec_init_pci()
1271 struct switchtec_dev *stdev; in switchtec_pci_probe() local
1277 stdev = stdev_create(pdev); in switchtec_pci_probe()
1278 if (IS_ERR(stdev)) in switchtec_pci_probe()
1279 return PTR_ERR(stdev); in switchtec_pci_probe()
1281 rc = switchtec_init_pci(stdev, pdev); in switchtec_pci_probe()
1285 rc = switchtec_init_isr(stdev); in switchtec_pci_probe()
1287 dev_err(&stdev->dev, "failed to init isr.\n"); in switchtec_pci_probe()
1293 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_pci_probe()
1294 enable_link_state_events(stdev); in switchtec_pci_probe()
1296 rc = cdev_device_add(&stdev->cdev, &stdev->dev); in switchtec_pci_probe()
1300 dev_info(&stdev->dev, "Management device registered.\n"); in switchtec_pci_probe()
1305 stdev_kill(stdev); in switchtec_pci_probe()
1307 ida_simple_remove(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_probe()
1308 put_device(&stdev->dev); in switchtec_pci_probe()
1314 struct switchtec_dev *stdev = pci_get_drvdata(pdev); in switchtec_pci_remove() local
1318 cdev_device_del(&stdev->cdev, &stdev->dev); in switchtec_pci_remove()
1319 ida_simple_remove(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_remove()
1320 dev_info(&stdev->dev, "unregistered.\n"); in switchtec_pci_remove()
1322 stdev_kill(stdev); in switchtec_pci_remove()
1323 put_device(&stdev->dev); in switchtec_pci_remove()