Lines Matching refs:stdev
54 struct switchtec_dev *stdev; member
78 static int is_firmware_running(struct switchtec_dev *stdev) in is_firmware_running() argument
80 u32 device = ioread32(&stdev->mmio_sys_info->device_id); in is_firmware_running()
82 return stdev->pdev->device == device; in is_firmware_running()
85 static struct switchtec_user *stuser_create(struct switchtec_dev *stdev) in stuser_create() argument
93 get_device(&stdev->dev); in stuser_create()
94 stuser->stdev = stdev; 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()
137 dev_dbg(&stuser->stdev->dev, "stuser state %p -> %s", in stuser_set_state()
141 static void mrpc_complete_cmd(struct switchtec_dev *stdev);
143 static void flush_wc_buf(struct switchtec_dev *stdev) in flush_wc_buf() argument
151 mmio_dbmsg = (void __iomem *)stdev->mmio_ntb + in flush_wc_buf()
156 static void mrpc_cmd_submit(struct switchtec_dev *stdev) in mrpc_cmd_submit() argument
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()
180 flush_wc_buf(stdev); 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() local
197 list_add_tail(&stuser->list, &stdev->mrpc_queue); in mrpc_queue_cmd()
199 mrpc_cmd_submit(stdev); in mrpc_queue_cmd()
204 static void mrpc_cleanup_cmd(struct switchtec_dev *stdev) in mrpc_cleanup_cmd() argument
208 struct switchtec_user *stuser = list_entry(stdev->mrpc_queue.next, in mrpc_cleanup_cmd()
215 stdev->mrpc_busy = 0; in mrpc_cleanup_cmd()
217 mrpc_cmd_submit(stdev); in mrpc_cleanup_cmd()
220 static void mrpc_complete_cmd(struct switchtec_dev *stdev) in mrpc_complete_cmd() argument
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()
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()
254 if (stdev->dma_mrpc) in mrpc_complete_cmd()
255 memcpy(stuser->data, &stdev->dma_mrpc->data, in mrpc_complete_cmd()
258 memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data, in mrpc_complete_cmd()
261 mrpc_cleanup_cmd(stdev); in mrpc_complete_cmd()
266 struct switchtec_dev *stdev; in mrpc_event_work() local
268 stdev = container_of(work, struct switchtec_dev, mrpc_work); in mrpc_event_work()
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()
274 mrpc_complete_cmd(stdev); in mrpc_event_work()
275 mutex_unlock(&stdev->mrpc_mutex); in mrpc_event_work()
278 static void mrpc_error_complete_cmd(struct switchtec_dev *stdev) in mrpc_error_complete_cmd() argument
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()
292 mrpc_cleanup_cmd(stdev); in mrpc_error_complete_cmd()
297 struct switchtec_dev *stdev; in mrpc_timeout_work() local
300 stdev = container_of(work, struct switchtec_dev, mrpc_timeout.work); in mrpc_timeout_work()
302 dev_dbg(&stdev->dev, "%s\n", __func__); in mrpc_timeout_work()
304 mutex_lock(&stdev->mrpc_mutex); in mrpc_timeout_work()
306 if (!is_firmware_running(stdev)) { in mrpc_timeout_work()
307 mrpc_error_complete_cmd(stdev); 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()
321 mrpc_complete_cmd(stdev); in mrpc_timeout_work()
323 mutex_unlock(&stdev->mrpc_mutex); in mrpc_timeout_work()
329 struct switchtec_dev *stdev = to_stdev(dev); in device_version_show() local
332 ver = ioread32(&stdev->mmio_sys_info->device_version); in device_version_show()
341 struct switchtec_dev *stdev = to_stdev(dev); in fw_version_show() local
344 ver = ioread32(&stdev->mmio_sys_info->firmware_version); in fw_version_show()
372 struct switchtec_dev *stdev = to_stdev(dev); \
373 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; \
374 if (stdev->gen == SWITCHTEC_GEN3) \
377 else if (stdev->gen >= SWITCHTEC_GEN4) \
393 struct switchtec_dev *stdev = to_stdev(dev); in component_vendor_show() local
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()
408 struct switchtec_dev *stdev = to_stdev(dev); in component_id_show() local
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()
422 struct switchtec_dev *stdev = to_stdev(dev); in component_revision_show() local
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()
436 struct switchtec_dev *stdev = to_stdev(dev); in partition_show() local
438 return sysfs_emit(buf, "%d\n", stdev->partition); in partition_show()
445 struct switchtec_dev *stdev = to_stdev(dev); in partition_count_show() local
447 return sysfs_emit(buf, "%d\n", stdev->partition_count); in partition_count_show()
469 struct switchtec_dev *stdev; in switchtec_dev_open() local
472 stdev = container_of(inode->i_cdev, struct switchtec_dev, cdev); in switchtec_dev_open()
474 stuser = stuser_create(stdev); in switchtec_dev_open()
481 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); in switchtec_dev_open()
495 static int lock_mutex_and_test_alive(struct switchtec_dev *stdev) in lock_mutex_and_test_alive() argument
497 if (mutex_lock_interruptible(&stdev->mrpc_mutex)) 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()
512 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_write() local
521 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_write()
552 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_write()
564 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_read() local
571 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_read()
576 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
582 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
594 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_read()
599 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
604 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
611 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
619 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
625 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
639 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_poll() local
643 poll_wait(filp, &stdev->event_wq, wait); in switchtec_dev_poll()
645 if (lock_mutex_and_test_alive(stdev)) in switchtec_dev_poll()
648 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_poll()
653 if (stuser->event_cnt != atomic_read(&stdev->event_cnt)) in switchtec_dev_poll()
659 static int ioctl_flash_info(struct switchtec_dev *stdev, in ioctl_flash_info() argument
663 struct flash_info_regs __iomem *fi = stdev->mmio_flash_info; in ioctl_flash_info()
665 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_info()
668 } else if (stdev->gen >= SWITCHTEC_GEN4) { in ioctl_flash_info()
688 static int flash_part_info_gen3(struct switchtec_dev *stdev, in flash_part_info_gen3() argument
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()
758 static int flash_part_info_gen4(struct switchtec_dev *stdev, in flash_part_info_gen4() argument
761 struct flash_info_regs_gen4 __iomem *fi = &stdev->mmio_flash_info->gen4; in flash_part_info_gen4()
762 struct sys_info_regs_gen4 __iomem *si = &stdev->mmio_sys_info->gen4; in flash_part_info_gen4()
862 static int ioctl_flash_part_info(struct switchtec_dev *stdev, in ioctl_flash_part_info() argument
871 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_part_info()
872 ret = flash_part_info_gen3(stdev, &info); in ioctl_flash_part_info()
875 } else if (stdev->gen >= SWITCHTEC_GEN4) { in ioctl_flash_part_info()
876 ret = flash_part_info_gen4(stdev, &info); in ioctl_flash_part_info()
889 static int ioctl_event_summary(struct switchtec_dev *stdev, in ioctl_event_summary() argument
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()
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()
922 stuser->event_cnt = atomic_read(&stdev->event_cnt); in ioctl_event_summary()
929 static u32 __iomem *global_ev_reg(struct switchtec_dev *stdev, in global_ev_reg() argument
932 return (void __iomem *)stdev->mmio_sw_event + offset; in global_ev_reg()
935 static u32 __iomem *part_ev_reg(struct switchtec_dev *stdev, in part_ev_reg() argument
938 return (void __iomem *)&stdev->mmio_part_cfg_all[index] + offset; in part_ev_reg()
941 static u32 __iomem *pff_ev_reg(struct switchtec_dev *stdev, in pff_ev_reg() argument
944 return (void __iomem *)&stdev->mmio_pff_csr[index] + offset; in pff_ev_reg()
953 u32 __iomem *(*map_reg)(struct switchtec_dev *stdev,
993 static u32 __iomem *event_hdr_addr(struct switchtec_dev *stdev, in event_hdr_addr() argument
1005 index = stdev->partition; in event_hdr_addr()
1006 else if (index < 0 || index >= stdev->partition_count) in event_hdr_addr()
1009 if (index < 0 || index >= stdev->pff_csr_count) in event_hdr_addr()
1013 return event_regs[event_id].map_reg(stdev, off, index); in event_hdr_addr()
1016 static int event_ctl(struct switchtec_dev *stdev, in event_ctl() argument
1023 reg = event_hdr_addr(stdev, ctl->event_id, ctl->index); in event_ctl()
1072 static int ioctl_event_ctl(struct switchtec_dev *stdev, in ioctl_event_ctl() argument
1093 nr_idxs = stdev->partition_count; in ioctl_event_ctl()
1095 nr_idxs = stdev->pff_csr_count; in ioctl_event_ctl()
1102 ret = event_ctl(stdev, &ctl); in ioctl_event_ctl()
1107 ret = event_ctl(stdev, &ctl); in ioctl_event_ctl()
1118 static int ioctl_pff_to_port(struct switchtec_dev *stdev, in ioctl_pff_to_port() argument
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()
1165 static int ioctl_port_to_pff(struct switchtec_dev *stdev, in ioctl_port_to_pff() argument
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()
1207 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_ioctl() local
1211 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_ioctl()
1217 rc = ioctl_flash_info(stdev, argp); in switchtec_dev_ioctl()
1220 rc = ioctl_flash_part_info(stdev, argp); in switchtec_dev_ioctl()
1223 rc = ioctl_event_summary(stdev, stuser, argp, in switchtec_dev_ioctl()
1227 rc = ioctl_event_ctl(stdev, argp); in switchtec_dev_ioctl()
1230 rc = ioctl_pff_to_port(stdev, argp); in switchtec_dev_ioctl()
1233 rc = ioctl_port_to_pff(stdev, argp); in switchtec_dev_ioctl()
1236 rc = ioctl_event_summary(stdev, stuser, argp, in switchtec_dev_ioctl()
1244 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_ioctl()
1261 struct switchtec_dev *stdev; in link_event_work() local
1263 stdev = container_of(work, struct switchtec_dev, link_event_work); in link_event_work()
1265 if (stdev->link_notifier) in link_event_work()
1266 stdev->link_notifier(stdev); in link_event_work()
1269 static void check_link_state_events(struct switchtec_dev *stdev) in check_link_state_events() argument
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()
1291 static void enable_link_state_events(struct switchtec_dev *stdev) in enable_link_state_events() argument
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()
1302 static void enable_dma_mrpc(struct switchtec_dev *stdev) in enable_dma_mrpc() argument
1304 writeq(stdev->dma_mrpc_dma_addr, &stdev->mmio_mrpc->dma_addr); in enable_dma_mrpc()
1305 flush_wc_buf(stdev); in enable_dma_mrpc()
1306 iowrite32(SWITCHTEC_DMA_MRPC_EN, &stdev->mmio_mrpc->dma_en); in enable_dma_mrpc()
1311 struct switchtec_dev *stdev = to_stdev(dev); in stdev_release() local
1313 kfree(stdev); in stdev_release()
1316 static void stdev_kill(struct switchtec_dev *stdev) in stdev_kill() argument
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()
1336 mutex_unlock(&stdev->mrpc_mutex); in stdev_kill()
1339 wake_up_interruptible(&stdev->event_wq); in stdev_kill()
1344 struct switchtec_dev *stdev; in stdev_create() local
1350 stdev = kzalloc_node(sizeof(*stdev), GFP_KERNEL, in stdev_create()
1352 if (!stdev) 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()
1382 cdev = &stdev->cdev; in stdev_create()
1386 return stdev; in stdev_create()
1389 pci_dev_put(stdev->pdev); in stdev_create()
1390 put_device(&stdev->dev); in stdev_create()
1394 static int mask_event(struct switchtec_dev *stdev, int eid, int idx) in mask_event() argument
1400 hdr_reg = event_regs[eid].map_reg(stdev, off, idx); in mask_event()
1409 dev_dbg(&stdev->dev, "%s: %d %d %x\n", __func__, eid, idx, hdr); in mask_event()
1416 static int mask_all_events(struct switchtec_dev *stdev, int eid) in mask_all_events() argument
1422 for (idx = 0; idx < stdev->partition_count; idx++) in mask_all_events()
1423 count += mask_event(stdev, eid, 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()
1429 count += mask_event(stdev, eid, idx); in mask_all_events()
1432 count += mask_event(stdev, eid, 0); in mask_all_events()
1440 struct switchtec_dev *stdev = dev; in switchtec_event_isr() local
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()
1453 check_link_state_events(stdev); in switchtec_event_isr()
1460 event_count += mask_all_events(stdev, eid); 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()
1477 struct switchtec_dev *stdev = dev; in switchtec_dma_mrpc_isr() local
1481 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_dma_mrpc_isr()
1482 schedule_work(&stdev->mrpc_work); in switchtec_dma_mrpc_isr()
1487 static int switchtec_init_isr(struct switchtec_dev *stdev) in switchtec_init_isr() argument
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()
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()
1513 KBUILD_MODNAME, stdev); 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()
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()
1531 KBUILD_MODNAME, stdev); in switchtec_init_isr()
1536 static void init_pff(struct switchtec_dev *stdev) in init_pff() argument
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()
1551 if (reg < stdev->pff_csr_count) in init_pff()
1552 stdev->pff_local[reg] = 1; in init_pff()
1555 if (reg < stdev->pff_csr_count) in init_pff()
1556 stdev->pff_local[reg] = 1; in init_pff()
1560 if (reg < stdev->pff_csr_count) in init_pff()
1561 stdev->pff_local[reg] = 1; in init_pff()
1565 static int switchtec_init_pci(struct switchtec_dev *stdev, in switchtec_init_pci() argument
1590 stdev->mmio_mrpc = devm_ioremap_wc(&pdev->dev, res_start, in switchtec_init_pci()
1592 if (!stdev->mmio_mrpc) 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()
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()
1623 init_pff(stdev); in switchtec_init_pci()
1625 pci_set_drvdata(pdev, stdev); 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()
1643 static void switchtec_exit_pci(struct switchtec_dev *stdev) in switchtec_exit_pci() argument
1645 if (stdev->dma_mrpc) { in switchtec_exit_pci()
1646 iowrite32(0, &stdev->mmio_mrpc->dma_en); in switchtec_exit_pci()
1647 flush_wc_buf(stdev); 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()
1658 struct switchtec_dev *stdev; in switchtec_pci_probe() local
1664 stdev = stdev_create(pdev); in switchtec_pci_probe()
1665 if (IS_ERR(stdev)) in switchtec_pci_probe()
1666 return PTR_ERR(stdev); in switchtec_pci_probe()
1668 stdev->gen = id->driver_data; in switchtec_pci_probe()
1670 rc = switchtec_init_pci(stdev, pdev); in switchtec_pci_probe()
1674 rc = switchtec_init_isr(stdev); 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()
1683 enable_link_state_events(stdev); in switchtec_pci_probe()
1685 if (stdev->dma_mrpc) in switchtec_pci_probe()
1686 enable_dma_mrpc(stdev); 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()
1697 stdev_kill(stdev); in switchtec_pci_probe()
1699 switchtec_exit_pci(stdev); 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()
1708 struct switchtec_dev *stdev = pci_get_drvdata(pdev); in switchtec_pci_remove() local
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()
1715 stdev_kill(stdev); in switchtec_pci_remove()
1716 switchtec_exit_pci(stdev); 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()