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 guard(mutex)(&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()
277 static void mrpc_error_complete_cmd(struct switchtec_dev *stdev) in mrpc_error_complete_cmd() argument
283 if (list_empty(&stdev->mrpc_queue)) in mrpc_error_complete_cmd()
286 stuser = list_entry(stdev->mrpc_queue.next, in mrpc_error_complete_cmd()
291 mrpc_cleanup_cmd(stdev); in mrpc_error_complete_cmd()
296 struct switchtec_dev *stdev; in mrpc_timeout_work() local
299 stdev = container_of(work, struct switchtec_dev, mrpc_timeout.work); in mrpc_timeout_work()
301 dev_dbg(&stdev->dev, "%s\n", __func__); in mrpc_timeout_work()
303 mutex_lock(&stdev->mrpc_mutex); in mrpc_timeout_work()
305 if (!is_firmware_running(stdev)) { in mrpc_timeout_work()
306 mrpc_error_complete_cmd(stdev); in mrpc_timeout_work()
310 if (stdev->dma_mrpc) in mrpc_timeout_work()
311 status = stdev->dma_mrpc->status; in mrpc_timeout_work()
313 status = ioread32(&stdev->mmio_mrpc->status); in mrpc_timeout_work()
315 schedule_delayed_work(&stdev->mrpc_timeout, in mrpc_timeout_work()
320 mrpc_complete_cmd(stdev); in mrpc_timeout_work()
322 mutex_unlock(&stdev->mrpc_mutex); in mrpc_timeout_work()
328 struct switchtec_dev *stdev = to_stdev(dev); in device_version_show() local
331 ver = ioread32(&stdev->mmio_sys_info->device_version); in device_version_show()
340 struct switchtec_dev *stdev = to_stdev(dev); in fw_version_show() local
343 ver = ioread32(&stdev->mmio_sys_info->firmware_version); in fw_version_show()
371 struct switchtec_dev *stdev = to_stdev(dev); \
372 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; \
373 if (stdev->gen == SWITCHTEC_GEN3) \
376 else if (stdev->gen >= SWITCHTEC_GEN4) \
392 struct switchtec_dev *stdev = to_stdev(dev); in component_vendor_show() local
393 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; in component_vendor_show()
396 if (stdev->gen != SWITCHTEC_GEN3) in component_vendor_show()
407 struct switchtec_dev *stdev = to_stdev(dev); in component_id_show() local
408 int id = ioread16(&stdev->mmio_sys_info->gen3.component_id); in component_id_show()
411 if (stdev->gen != SWITCHTEC_GEN3) in component_id_show()
421 struct switchtec_dev *stdev = to_stdev(dev); in component_revision_show() local
422 int rev = ioread8(&stdev->mmio_sys_info->gen3.component_revision); in component_revision_show()
425 if (stdev->gen != SWITCHTEC_GEN3) in component_revision_show()
435 struct switchtec_dev *stdev = to_stdev(dev); in partition_show() local
437 return sysfs_emit(buf, "%d\n", stdev->partition); in partition_show()
444 struct switchtec_dev *stdev = to_stdev(dev); in partition_count_show() local
446 return sysfs_emit(buf, "%d\n", stdev->partition_count); in partition_count_show()
468 struct switchtec_dev *stdev; in switchtec_dev_open() local
471 stdev = container_of(inode->i_cdev, struct switchtec_dev, cdev); in switchtec_dev_open()
473 stuser = stuser_create(stdev); in switchtec_dev_open()
480 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); in switchtec_dev_open()
494 static int lock_mutex_and_test_alive(struct switchtec_dev *stdev) in lock_mutex_and_test_alive() argument
496 if (mutex_lock_interruptible(&stdev->mrpc_mutex)) in lock_mutex_and_test_alive()
499 if (!stdev->alive) { in lock_mutex_and_test_alive()
500 mutex_unlock(&stdev->mrpc_mutex); in lock_mutex_and_test_alive()
511 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_write() local
520 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_write()
551 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_write()
563 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_read() local
570 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_read()
575 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
581 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
593 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_read()
598 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
603 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
610 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
618 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
624 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_read()
638 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_poll() local
642 poll_wait(filp, &stdev->event_wq, wait); in switchtec_dev_poll()
644 if (lock_mutex_and_test_alive(stdev)) in switchtec_dev_poll()
647 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_poll()
652 if (stuser->event_cnt != atomic_read(&stdev->event_cnt)) in switchtec_dev_poll()
658 static int ioctl_flash_info(struct switchtec_dev *stdev, in ioctl_flash_info() argument
662 struct flash_info_regs __iomem *fi = stdev->mmio_flash_info; in ioctl_flash_info()
664 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_info()
667 } else if (stdev->gen >= SWITCHTEC_GEN4) { in ioctl_flash_info()
687 static int flash_part_info_gen3(struct switchtec_dev *stdev, in flash_part_info_gen3() argument
691 &stdev->mmio_flash_info->gen3; in flash_part_info_gen3()
692 struct sys_info_regs_gen3 __iomem *si = &stdev->mmio_sys_info->gen3; in flash_part_info_gen3()
757 static int flash_part_info_gen4(struct switchtec_dev *stdev, in flash_part_info_gen4() argument
760 struct flash_info_regs_gen4 __iomem *fi = &stdev->mmio_flash_info->gen4; in flash_part_info_gen4()
761 struct sys_info_regs_gen4 __iomem *si = &stdev->mmio_sys_info->gen4; in flash_part_info_gen4()
861 static int ioctl_flash_part_info(struct switchtec_dev *stdev, in ioctl_flash_part_info() argument
870 if (stdev->gen == SWITCHTEC_GEN3) { in ioctl_flash_part_info()
871 ret = flash_part_info_gen3(stdev, &info); in ioctl_flash_part_info()
874 } else if (stdev->gen >= SWITCHTEC_GEN4) { in ioctl_flash_part_info()
875 ret = flash_part_info_gen4(stdev, &info); in ioctl_flash_part_info()
888 static int ioctl_event_summary(struct switchtec_dev *stdev, in ioctl_event_summary() argument
902 s->global = ioread32(&stdev->mmio_sw_event->global_summary); in ioctl_event_summary()
903 s->part_bitmap = ioread64(&stdev->mmio_sw_event->part_event_bitmap); in ioctl_event_summary()
904 s->local_part = ioread32(&stdev->mmio_part_cfg->part_event_summary); in ioctl_event_summary()
906 for (i = 0; i < stdev->partition_count; i++) { in ioctl_event_summary()
907 reg = ioread32(&stdev->mmio_part_cfg_all[i].part_event_summary); in ioctl_event_summary()
911 for (i = 0; i < stdev->pff_csr_count; i++) { in ioctl_event_summary()
912 reg = ioread32(&stdev->mmio_pff_csr[i].pff_event_summary); in ioctl_event_summary()
921 stuser->event_cnt = atomic_read(&stdev->event_cnt); in ioctl_event_summary()
928 static u32 __iomem *global_ev_reg(struct switchtec_dev *stdev, in global_ev_reg() argument
931 return (void __iomem *)stdev->mmio_sw_event + offset; in global_ev_reg()
934 static u32 __iomem *part_ev_reg(struct switchtec_dev *stdev, in part_ev_reg() argument
937 return (void __iomem *)&stdev->mmio_part_cfg_all[index] + offset; in part_ev_reg()
940 static u32 __iomem *pff_ev_reg(struct switchtec_dev *stdev, in pff_ev_reg() argument
943 return (void __iomem *)&stdev->mmio_pff_csr[index] + offset; in pff_ev_reg()
952 u32 __iomem *(*map_reg)(struct switchtec_dev *stdev,
992 static u32 __iomem *event_hdr_addr(struct switchtec_dev *stdev, in event_hdr_addr() argument
1004 index = stdev->partition; in event_hdr_addr()
1005 else if (index < 0 || index >= stdev->partition_count) in event_hdr_addr()
1008 if (index < 0 || index >= stdev->pff_csr_count) in event_hdr_addr()
1012 return event_regs[event_id].map_reg(stdev, off, index); in event_hdr_addr()
1015 static int event_ctl(struct switchtec_dev *stdev, in event_ctl() argument
1022 reg = event_hdr_addr(stdev, ctl->event_id, ctl->index); in event_ctl()
1071 static int ioctl_event_ctl(struct switchtec_dev *stdev, in ioctl_event_ctl() argument
1092 nr_idxs = stdev->partition_count; in ioctl_event_ctl()
1094 nr_idxs = stdev->pff_csr_count; in ioctl_event_ctl()
1101 ret = event_ctl(stdev, &ctl); in ioctl_event_ctl()
1106 ret = event_ctl(stdev, &ctl); in ioctl_event_ctl()
1117 static int ioctl_pff_to_port(struct switchtec_dev *stdev, in ioctl_pff_to_port() argument
1129 for (part = 0; part < stdev->partition_count; part++) { in ioctl_pff_to_port()
1130 pcfg = &stdev->mmio_part_cfg_all[part]; in ioctl_pff_to_port()
1164 static int ioctl_port_to_pff(struct switchtec_dev *stdev, in ioctl_port_to_pff() argument
1174 pcfg = stdev->mmio_part_cfg; in ioctl_port_to_pff()
1175 else if (p.partition < stdev->partition_count) in ioctl_port_to_pff()
1176 pcfg = &stdev->mmio_part_cfg_all[p.partition]; in ioctl_port_to_pff()
1206 struct switchtec_dev *stdev = stuser->stdev; in switchtec_dev_ioctl() local
1210 rc = lock_mutex_and_test_alive(stdev); in switchtec_dev_ioctl()
1216 rc = ioctl_flash_info(stdev, argp); in switchtec_dev_ioctl()
1219 rc = ioctl_flash_part_info(stdev, argp); in switchtec_dev_ioctl()
1222 rc = ioctl_event_summary(stdev, stuser, argp, in switchtec_dev_ioctl()
1226 rc = ioctl_event_ctl(stdev, argp); in switchtec_dev_ioctl()
1229 rc = ioctl_pff_to_port(stdev, argp); in switchtec_dev_ioctl()
1232 rc = ioctl_port_to_pff(stdev, argp); in switchtec_dev_ioctl()
1235 rc = ioctl_event_summary(stdev, stuser, argp, in switchtec_dev_ioctl()
1243 mutex_unlock(&stdev->mrpc_mutex); in switchtec_dev_ioctl()
1260 struct switchtec_dev *stdev; in link_event_work() local
1262 stdev = container_of(work, struct switchtec_dev, link_event_work); in link_event_work()
1264 if (stdev->link_notifier) in link_event_work()
1265 stdev->link_notifier(stdev); in link_event_work()
1268 static void check_link_state_events(struct switchtec_dev *stdev) in check_link_state_events() argument
1275 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in check_link_state_events()
1276 reg = ioread32(&stdev->mmio_pff_csr[idx].link_state_hdr); in check_link_state_events()
1277 dev_dbg(&stdev->dev, "link_state: %d->%08x\n", idx, reg); in check_link_state_events()
1280 if (count != stdev->link_event_count[idx]) { in check_link_state_events()
1282 stdev->link_event_count[idx] = count; in check_link_state_events()
1287 schedule_work(&stdev->link_event_work); in check_link_state_events()
1290 static void enable_link_state_events(struct switchtec_dev *stdev) in enable_link_state_events() argument
1294 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in enable_link_state_events()
1297 &stdev->mmio_pff_csr[idx].link_state_hdr); in enable_link_state_events()
1301 static void enable_dma_mrpc(struct switchtec_dev *stdev) in enable_dma_mrpc() argument
1303 writeq(stdev->dma_mrpc_dma_addr, &stdev->mmio_mrpc->dma_addr); in enable_dma_mrpc()
1304 flush_wc_buf(stdev); in enable_dma_mrpc()
1305 iowrite32(SWITCHTEC_DMA_MRPC_EN, &stdev->mmio_mrpc->dma_en); in enable_dma_mrpc()
1310 struct switchtec_dev *stdev = to_stdev(dev); in stdev_release() local
1312 kfree(stdev); in stdev_release()
1315 static void stdev_kill(struct switchtec_dev *stdev) in stdev_kill() argument
1319 pci_clear_master(stdev->pdev); in stdev_kill()
1321 cancel_delayed_work_sync(&stdev->mrpc_timeout); in stdev_kill()
1324 scoped_guard (mutex, &stdev->mrpc_mutex) { in stdev_kill()
1325 stdev->alive = false; in stdev_kill()
1328 list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) { in stdev_kill()
1338 wake_up_interruptible(&stdev->event_wq); in stdev_kill()
1343 struct switchtec_dev *stdev; in stdev_create() local
1349 stdev = kzalloc_node(sizeof(*stdev), GFP_KERNEL, in stdev_create()
1351 if (!stdev) in stdev_create()
1354 stdev->alive = true; in stdev_create()
1355 stdev->pdev = pci_dev_get(pdev); in stdev_create()
1356 INIT_LIST_HEAD(&stdev->mrpc_queue); in stdev_create()
1357 mutex_init(&stdev->mrpc_mutex); in stdev_create()
1358 stdev->mrpc_busy = 0; in stdev_create()
1359 INIT_WORK(&stdev->mrpc_work, mrpc_event_work); in stdev_create()
1360 INIT_DELAYED_WORK(&stdev->mrpc_timeout, mrpc_timeout_work); in stdev_create()
1361 INIT_WORK(&stdev->link_event_work, link_event_work); in stdev_create()
1362 init_waitqueue_head(&stdev->event_wq); in stdev_create()
1363 atomic_set(&stdev->event_cnt, 0); in stdev_create()
1365 dev = &stdev->dev; in stdev_create()
1381 cdev = &stdev->cdev; in stdev_create()
1385 return stdev; in stdev_create()
1388 pci_dev_put(stdev->pdev); in stdev_create()
1389 put_device(&stdev->dev); in stdev_create()
1393 static int mask_event(struct switchtec_dev *stdev, int eid, int idx) in mask_event() argument
1399 hdr_reg = event_regs[eid].map_reg(stdev, off, idx); in mask_event()
1408 dev_dbg(&stdev->dev, "%s: %d %d %x\n", __func__, eid, idx, hdr); in mask_event()
1415 static int mask_all_events(struct switchtec_dev *stdev, int eid) in mask_all_events() argument
1421 for (idx = 0; idx < stdev->partition_count; idx++) in mask_all_events()
1422 count += mask_event(stdev, eid, idx); in mask_all_events()
1424 for (idx = 0; idx < stdev->pff_csr_count; idx++) { in mask_all_events()
1425 if (!stdev->pff_local[idx]) in mask_all_events()
1428 count += mask_event(stdev, eid, idx); in mask_all_events()
1431 count += mask_event(stdev, eid, 0); in mask_all_events()
1439 struct switchtec_dev *stdev = dev; in switchtec_event_isr() local
1444 reg = ioread32(&stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1446 dev_dbg(&stdev->dev, "%s: mrpc comp\n", __func__); in switchtec_event_isr()
1448 schedule_work(&stdev->mrpc_work); in switchtec_event_isr()
1449 iowrite32(reg, &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_event_isr()
1452 check_link_state_events(stdev); in switchtec_event_isr()
1459 event_count += mask_all_events(stdev, eid); in switchtec_event_isr()
1463 atomic_inc(&stdev->event_cnt); in switchtec_event_isr()
1464 wake_up_interruptible(&stdev->event_wq); in switchtec_event_isr()
1465 dev_dbg(&stdev->dev, "%s: %d events\n", __func__, in switchtec_event_isr()
1476 struct switchtec_dev *stdev = dev; in switchtec_dma_mrpc_isr() local
1480 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_dma_mrpc_isr()
1481 schedule_work(&stdev->mrpc_work); in switchtec_dma_mrpc_isr()
1486 static int switchtec_init_isr(struct switchtec_dev *stdev) in switchtec_init_isr() argument
1496 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, nirqs, in switchtec_init_isr()
1502 event_irq = ioread16(&stdev->mmio_part_cfg->vep_vector_number); in switchtec_init_isr()
1506 event_irq = pci_irq_vector(stdev->pdev, event_irq); in switchtec_init_isr()
1510 rc = devm_request_irq(&stdev->pdev->dev, event_irq, in switchtec_init_isr()
1512 KBUILD_MODNAME, stdev); in switchtec_init_isr()
1517 if (!stdev->dma_mrpc) in switchtec_init_isr()
1520 dma_mrpc_irq = ioread32(&stdev->mmio_mrpc->dma_vector); in switchtec_init_isr()
1524 dma_mrpc_irq = pci_irq_vector(stdev->pdev, dma_mrpc_irq); in switchtec_init_isr()
1528 rc = devm_request_irq(&stdev->pdev->dev, dma_mrpc_irq, in switchtec_init_isr()
1530 KBUILD_MODNAME, stdev); in switchtec_init_isr()
1535 static void init_pff(struct switchtec_dev *stdev) in init_pff() argument
1539 struct part_cfg_regs __iomem *pcfg = stdev->mmio_part_cfg; in init_pff()
1542 reg = ioread16(&stdev->mmio_pff_csr[i].vendor_id); in init_pff()
1547 stdev->pff_csr_count = i; in init_pff()
1550 if (reg < stdev->pff_csr_count) in init_pff()
1551 stdev->pff_local[reg] = 1; in init_pff()
1554 if (reg < stdev->pff_csr_count) in init_pff()
1555 stdev->pff_local[reg] = 1; in init_pff()
1559 if (reg < stdev->pff_csr_count) in init_pff()
1560 stdev->pff_local[reg] = 1; in init_pff()
1564 static int switchtec_init_pci(struct switchtec_dev *stdev, in switchtec_init_pci() argument
1589 stdev->mmio_mrpc = devm_ioremap_wc(&pdev->dev, res_start, in switchtec_init_pci()
1591 if (!stdev->mmio_mrpc) in switchtec_init_pci()
1600 stdev->mmio = map - SWITCHTEC_GAS_TOP_CFG_OFFSET; in switchtec_init_pci()
1601 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET; in switchtec_init_pci()
1602 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET; in switchtec_init_pci()
1603 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET; in switchtec_init_pci()
1604 stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET; in switchtec_init_pci()
1606 if (stdev->gen == SWITCHTEC_GEN3) in switchtec_init_pci()
1607 part_id = &stdev->mmio_sys_info->gen3.partition_id; in switchtec_init_pci()
1608 else if (stdev->gen >= SWITCHTEC_GEN4) in switchtec_init_pci()
1609 part_id = &stdev->mmio_sys_info->gen4.partition_id; in switchtec_init_pci()
1613 stdev->partition = ioread8(part_id); in switchtec_init_pci()
1614 stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count); in switchtec_init_pci()
1615 stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET; in switchtec_init_pci()
1616 stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[stdev->partition]; in switchtec_init_pci()
1617 stdev->mmio_pff_csr = stdev->mmio + SWITCHTEC_GAS_PFF_CSR_OFFSET; in switchtec_init_pci()
1619 if (stdev->partition_count < 1) in switchtec_init_pci()
1620 stdev->partition_count = 1; in switchtec_init_pci()
1622 init_pff(stdev); in switchtec_init_pci()
1624 pci_set_drvdata(pdev, stdev); in switchtec_init_pci()
1629 if (ioread32(&stdev->mmio_mrpc->dma_ver) == 0) in switchtec_init_pci()
1632 stdev->dma_mrpc = dma_alloc_coherent(&stdev->pdev->dev, in switchtec_init_pci()
1633 sizeof(*stdev->dma_mrpc), in switchtec_init_pci()
1634 &stdev->dma_mrpc_dma_addr, in switchtec_init_pci()
1636 if (stdev->dma_mrpc == NULL) in switchtec_init_pci()
1642 static void switchtec_exit_pci(struct switchtec_dev *stdev) in switchtec_exit_pci() argument
1644 if (stdev->dma_mrpc) { in switchtec_exit_pci()
1645 iowrite32(0, &stdev->mmio_mrpc->dma_en); in switchtec_exit_pci()
1646 flush_wc_buf(stdev); in switchtec_exit_pci()
1647 writeq(0, &stdev->mmio_mrpc->dma_addr); in switchtec_exit_pci()
1648 dma_free_coherent(&stdev->pdev->dev, sizeof(*stdev->dma_mrpc), in switchtec_exit_pci()
1649 stdev->dma_mrpc, stdev->dma_mrpc_dma_addr); in switchtec_exit_pci()
1650 stdev->dma_mrpc = NULL; in switchtec_exit_pci()
1657 struct switchtec_dev *stdev; in switchtec_pci_probe() local
1663 stdev = stdev_create(pdev); in switchtec_pci_probe()
1664 if (IS_ERR(stdev)) in switchtec_pci_probe()
1665 return PTR_ERR(stdev); in switchtec_pci_probe()
1667 stdev->gen = id->driver_data; in switchtec_pci_probe()
1669 rc = switchtec_init_pci(stdev, pdev); in switchtec_pci_probe()
1673 rc = switchtec_init_isr(stdev); in switchtec_pci_probe()
1675 dev_err(&stdev->dev, "failed to init isr.\n"); in switchtec_pci_probe()
1681 &stdev->mmio_part_cfg->mrpc_comp_hdr); in switchtec_pci_probe()
1682 enable_link_state_events(stdev); in switchtec_pci_probe()
1684 if (stdev->dma_mrpc) in switchtec_pci_probe()
1685 enable_dma_mrpc(stdev); in switchtec_pci_probe()
1687 rc = cdev_device_add(&stdev->cdev, &stdev->dev); in switchtec_pci_probe()
1691 dev_info(&stdev->dev, "Management device registered.\n"); in switchtec_pci_probe()
1696 stdev_kill(stdev); in switchtec_pci_probe()
1698 switchtec_exit_pci(stdev); in switchtec_pci_probe()
1700 ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_probe()
1701 put_device(&stdev->dev); in switchtec_pci_probe()
1707 struct switchtec_dev *stdev = pci_get_drvdata(pdev); in switchtec_pci_remove() local
1711 cdev_device_del(&stdev->cdev, &stdev->dev); in switchtec_pci_remove()
1712 ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt)); in switchtec_pci_remove()
1713 dev_info(&stdev->dev, "unregistered.\n"); in switchtec_pci_remove()
1714 stdev_kill(stdev); in switchtec_pci_remove()
1715 switchtec_exit_pci(stdev); in switchtec_pci_remove()
1716 pci_dev_put(stdev->pdev); in switchtec_pci_remove()
1717 stdev->pdev = NULL; in switchtec_pci_remove()
1718 put_device(&stdev->dev); in switchtec_pci_remove()