Lines Matching refs:stdev

52 	struct switchtec_dev *stdev;
76 static int is_firmware_running(struct switchtec_dev *stdev)
78 u32 device = ioread32(&stdev->mmio_sys_info->device_id);
80 return stdev->pdev->device == device;
83 static struct switchtec_user *stuser_create(struct switchtec_dev *stdev)
91 get_device(&stdev->dev);
92 stuser->stdev = stdev;
96 stuser->event_cnt = atomic_read(&stdev->event_cnt);
98 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser);
109 dev_dbg(&stuser->stdev->dev, "%s: %p\n", __func__, stuser);
111 put_device(&stuser->stdev->dev);
135 dev_dbg(&stuser->stdev->dev, "stuser state %p -> %s",
139 static void mrpc_complete_cmd(struct switchtec_dev *stdev);
141 static void flush_wc_buf(struct switchtec_dev *stdev)
149 mmio_dbmsg = (void __iomem *)stdev->mmio_ntb +
154 static void mrpc_cmd_submit(struct switchtec_dev *stdev)
160 if (stdev->mrpc_busy)
163 if (list_empty(&stdev->mrpc_queue))
166 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user,
169 if (stdev->dma_mrpc) {
170 stdev->dma_mrpc->status = SWITCHTEC_MRPC_STATUS_INPROGRESS;
171 memset(stdev->dma_mrpc->data, 0xFF, SWITCHTEC_MRPC_PAYLOAD_SIZE);
175 stdev->mrpc_busy = 1;
176 memcpy_toio(&stdev->mmio_mrpc->input_data,
178 flush_wc_buf(stdev);
179 iowrite32(stuser->cmd, &stdev->mmio_mrpc->cmd);
181 schedule_delayed_work(&stdev->mrpc_timeout,
189 struct switchtec_dev *stdev = stuser->stdev;
195 list_add_tail(&stuser->list, &stdev->mrpc_queue);
197 mrpc_cmd_submit(stdev);
202 static void mrpc_cleanup_cmd(struct switchtec_dev *stdev)
206 struct switchtec_user *stuser = list_entry(stdev->mrpc_queue.next,
213 stdev->mrpc_busy = 0;
215 mrpc_cmd_submit(stdev);
218 static void mrpc_complete_cmd(struct switchtec_dev *stdev)
224 if (list_empty(&stdev->mrpc_queue))
227 stuser = list_entry(stdev->mrpc_queue.next, struct switchtec_user,
230 if (stdev->dma_mrpc)
231 stuser->status = stdev->dma_mrpc->status;
233 stuser->status = ioread32(&stdev->mmio_mrpc->status);
245 if (stdev->dma_mrpc)
246 stuser->return_code = stdev->dma_mrpc->rtn_code;
248 stuser->return_code = ioread32(&stdev->mmio_mrpc->ret_value);
252 if (stdev->dma_mrpc)
253 memcpy(stuser->data, &stdev->dma_mrpc->data,
256 memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data,
259 mrpc_cleanup_cmd(stdev);
264 struct switchtec_dev *stdev;
266 stdev = container_of(work, struct switchtec_dev, mrpc_work);
268 dev_dbg(&stdev->dev, "%s\n", __func__);
270 mutex_lock(&stdev->mrpc_mutex);
271 cancel_delayed_work(&stdev->mrpc_timeout);
272 mrpc_complete_cmd(stdev);
273 mutex_unlock(&stdev->mrpc_mutex);
276 static void mrpc_error_complete_cmd(struct switchtec_dev *stdev)
282 if (list_empty(&stdev->mrpc_queue))
285 stuser = list_entry(stdev->mrpc_queue.next,
290 mrpc_cleanup_cmd(stdev);
295 struct switchtec_dev *stdev;
298 stdev = container_of(work, struct switchtec_dev, mrpc_timeout.work);
300 dev_dbg(&stdev->dev, "%s\n", __func__);
302 mutex_lock(&stdev->mrpc_mutex);
304 if (!is_firmware_running(stdev)) {
305 mrpc_error_complete_cmd(stdev);
309 if (stdev->dma_mrpc)
310 status = stdev->dma_mrpc->status;
312 status = ioread32(&stdev->mmio_mrpc->status);
314 schedule_delayed_work(&stdev->mrpc_timeout,
319 mrpc_complete_cmd(stdev);
321 mutex_unlock(&stdev->mrpc_mutex);
327 struct switchtec_dev *stdev = to_stdev(dev);
330 ver = ioread32(&stdev->mmio_sys_info->device_version);
339 struct switchtec_dev *stdev = to_stdev(dev);
342 ver = ioread32(&stdev->mmio_sys_info->firmware_version);
370 struct switchtec_dev *stdev = to_stdev(dev); \
371 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; \
372 if (stdev->gen == SWITCHTEC_GEN3) \
375 else if (stdev->gen >= SWITCHTEC_GEN4) \
391 struct switchtec_dev *stdev = to_stdev(dev);
392 struct sys_info_regs __iomem *si = stdev->mmio_sys_info;
395 if (stdev->gen != SWITCHTEC_GEN3)
406 struct switchtec_dev *stdev = to_stdev(dev);
407 int id = ioread16(&stdev->mmio_sys_info->gen3.component_id);
410 if (stdev->gen != SWITCHTEC_GEN3)
420 struct switchtec_dev *stdev = to_stdev(dev);
421 int rev = ioread8(&stdev->mmio_sys_info->gen3.component_revision);
424 if (stdev->gen != SWITCHTEC_GEN3)
434 struct switchtec_dev *stdev = to_stdev(dev);
436 return sysfs_emit(buf, "%d\n", stdev->partition);
443 struct switchtec_dev *stdev = to_stdev(dev);
445 return sysfs_emit(buf, "%d\n", stdev->partition_count);
467 struct switchtec_dev *stdev;
470 stdev = container_of(inode->i_cdev, struct switchtec_dev, cdev);
472 stuser = stuser_create(stdev);
479 dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser);
493 static int lock_mutex_and_test_alive(struct switchtec_dev *stdev)
495 if (mutex_lock_interruptible(&stdev->mrpc_mutex))
498 if (!stdev->alive) {
499 mutex_unlock(&stdev->mrpc_mutex);
510 struct switchtec_dev *stdev = stuser->stdev;
519 rc = lock_mutex_and_test_alive(stdev);
550 mutex_unlock(&stdev->mrpc_mutex);
562 struct switchtec_dev *stdev = stuser->stdev;
569 rc = lock_mutex_and_test_alive(stdev);
574 mutex_unlock(&stdev->mrpc_mutex);
580 mutex_unlock(&stdev->mrpc_mutex);
592 rc = lock_mutex_and_test_alive(stdev);
597 mutex_unlock(&stdev->mrpc_mutex);
602 mutex_unlock(&stdev->mrpc_mutex);
609 mutex_unlock(&stdev->mrpc_mutex);
617 mutex_unlock(&stdev->mrpc_mutex);
623 mutex_unlock(&stdev->mrpc_mutex);
637 struct switchtec_dev *stdev = stuser->stdev;
641 poll_wait(filp, &stdev->event_wq, wait);
643 if (lock_mutex_and_test_alive(stdev))
646 mutex_unlock(&stdev->mrpc_mutex);
651 if (stuser->event_cnt != atomic_read(&stdev->event_cnt))
657 static int ioctl_flash_info(struct switchtec_dev *stdev,
661 struct flash_info_regs __iomem *fi = stdev->mmio_flash_info;
663 if (stdev->gen == SWITCHTEC_GEN3) {
666 } else if (stdev->gen >= SWITCHTEC_GEN4) {
686 static int flash_part_info_gen3(struct switchtec_dev *stdev,
690 &stdev->mmio_flash_info->gen3;
691 struct sys_info_regs_gen3 __iomem *si = &stdev->mmio_sys_info->gen3;
756 static int flash_part_info_gen4(struct switchtec_dev *stdev,
759 struct flash_info_regs_gen4 __iomem *fi = &stdev->mmio_flash_info->gen4;
760 struct sys_info_regs_gen4 __iomem *si = &stdev->mmio_sys_info->gen4;
860 static int ioctl_flash_part_info(struct switchtec_dev *stdev,
869 if (stdev->gen == SWITCHTEC_GEN3) {
870 ret = flash_part_info_gen3(stdev, &info);
873 } else if (stdev->gen >= SWITCHTEC_GEN4) {
874 ret = flash_part_info_gen4(stdev, &info);
887 static int ioctl_event_summary(struct switchtec_dev *stdev,
901 s->global = ioread32(&stdev->mmio_sw_event->global_summary);
902 s->part_bitmap = ioread64(&stdev->mmio_sw_event->part_event_bitmap);
903 s->local_part = ioread32(&stdev->mmio_part_cfg->part_event_summary);
905 for (i = 0; i < stdev->partition_count; i++) {
906 reg = ioread32(&stdev->mmio_part_cfg_all[i].part_event_summary);
910 for (i = 0; i < stdev->pff_csr_count; i++) {
911 reg = ioread32(&stdev->mmio_pff_csr[i].pff_event_summary);
920 stuser->event_cnt = atomic_read(&stdev->event_cnt);
927 static u32 __iomem *global_ev_reg(struct switchtec_dev *stdev,
930 return (void __iomem *)stdev->mmio_sw_event + offset;
933 static u32 __iomem *part_ev_reg(struct switchtec_dev *stdev,
936 return (void __iomem *)&stdev->mmio_part_cfg_all[index] + offset;
939 static u32 __iomem *pff_ev_reg(struct switchtec_dev *stdev,
942 return (void __iomem *)&stdev->mmio_pff_csr[index] + offset;
951 u32 __iomem *(*map_reg)(struct switchtec_dev *stdev,
991 static u32 __iomem *event_hdr_addr(struct switchtec_dev *stdev,
1003 index = stdev->partition;
1004 else if (index < 0 || index >= stdev->partition_count)
1007 if (index < 0 || index >= stdev->pff_csr_count)
1011 return event_regs[event_id].map_reg(stdev, off, index);
1014 static int event_ctl(struct switchtec_dev *stdev,
1021 reg = event_hdr_addr(stdev, ctl->event_id, ctl->index);
1070 static int ioctl_event_ctl(struct switchtec_dev *stdev,
1091 nr_idxs = stdev->partition_count;
1093 nr_idxs = stdev->pff_csr_count;
1100 ret = event_ctl(stdev, &ctl);
1105 ret = event_ctl(stdev, &ctl);
1116 static int ioctl_pff_to_port(struct switchtec_dev *stdev,
1128 for (part = 0; part < stdev->partition_count; part++) {
1129 pcfg = &stdev->mmio_part_cfg_all[part];
1163 static int ioctl_port_to_pff(struct switchtec_dev *stdev,
1173 pcfg = stdev->mmio_part_cfg;
1174 else if (p.partition < stdev->partition_count)
1175 pcfg = &stdev->mmio_part_cfg_all[p.partition];
1205 struct switchtec_dev *stdev = stuser->stdev;
1209 rc = lock_mutex_and_test_alive(stdev);
1215 rc = ioctl_flash_info(stdev, argp);
1218 rc = ioctl_flash_part_info(stdev, argp);
1221 rc = ioctl_event_summary(stdev, stuser, argp,
1225 rc = ioctl_event_ctl(stdev, argp);
1228 rc = ioctl_pff_to_port(stdev, argp);
1231 rc = ioctl_port_to_pff(stdev, argp);
1234 rc = ioctl_event_summary(stdev, stuser, argp,
1242 mutex_unlock(&stdev->mrpc_mutex);
1259 struct switchtec_dev *stdev;
1261 stdev = container_of(work, struct switchtec_dev, link_event_work);
1263 if (stdev->link_notifier)
1264 stdev->link_notifier(stdev);
1267 static void check_link_state_events(struct switchtec_dev *stdev)
1274 for (idx = 0; idx < stdev->pff_csr_count; idx++) {
1275 reg = ioread32(&stdev->mmio_pff_csr[idx].link_state_hdr);
1276 dev_dbg(&stdev->dev, "link_state: %d->%08x\n", idx, reg);
1279 if (count != stdev->link_event_count[idx]) {
1281 stdev->link_event_count[idx] = count;
1286 schedule_work(&stdev->link_event_work);
1289 static void enable_link_state_events(struct switchtec_dev *stdev)
1293 for (idx = 0; idx < stdev->pff_csr_count; idx++) {
1296 &stdev->mmio_pff_csr[idx].link_state_hdr);
1300 static void enable_dma_mrpc(struct switchtec_dev *stdev)
1302 writeq(stdev->dma_mrpc_dma_addr, &stdev->mmio_mrpc->dma_addr);
1303 flush_wc_buf(stdev);
1304 iowrite32(SWITCHTEC_DMA_MRPC_EN, &stdev->mmio_mrpc->dma_en);
1309 struct switchtec_dev *stdev = to_stdev(dev);
1311 kfree(stdev);
1314 static void stdev_kill(struct switchtec_dev *stdev)
1318 pci_clear_master(stdev->pdev);
1320 cancel_delayed_work_sync(&stdev->mrpc_timeout);
1323 mutex_lock(&stdev->mrpc_mutex);
1324 stdev->alive = false;
1327 list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) {
1334 mutex_unlock(&stdev->mrpc_mutex);
1337 wake_up_interruptible(&stdev->event_wq);
1342 struct switchtec_dev *stdev;
1348 stdev = kzalloc_node(sizeof(*stdev), GFP_KERNEL,
1350 if (!stdev)
1353 stdev->alive = true;
1354 stdev->pdev = pci_dev_get(pdev);
1355 INIT_LIST_HEAD(&stdev->mrpc_queue);
1356 mutex_init(&stdev->mrpc_mutex);
1357 stdev->mrpc_busy = 0;
1358 INIT_WORK(&stdev->mrpc_work, mrpc_event_work);
1359 INIT_DELAYED_WORK(&stdev->mrpc_timeout, mrpc_timeout_work);
1360 INIT_WORK(&stdev->link_event_work, link_event_work);
1361 init_waitqueue_head(&stdev->event_wq);
1362 atomic_set(&stdev->event_cnt, 0);
1364 dev = &stdev->dev;
1380 cdev = &stdev->cdev;
1384 return stdev;
1387 pci_dev_put(stdev->pdev);
1388 put_device(&stdev->dev);
1392 static int mask_event(struct switchtec_dev *stdev, int eid, int idx)
1398 hdr_reg = event_regs[eid].map_reg(stdev, off, idx);
1407 dev_dbg(&stdev->dev, "%s: %d %d %x\n", __func__, eid, idx, hdr);
1414 static int mask_all_events(struct switchtec_dev *stdev, int eid)
1420 for (idx = 0; idx < stdev->partition_count; idx++)
1421 count += mask_event(stdev, eid, idx);
1423 for (idx = 0; idx < stdev->pff_csr_count; idx++) {
1424 if (!stdev->pff_local[idx])
1427 count += mask_event(stdev, eid, idx);
1430 count += mask_event(stdev, eid, 0);
1438 struct switchtec_dev *stdev = dev;
1443 reg = ioread32(&stdev->mmio_part_cfg->mrpc_comp_hdr);
1445 dev_dbg(&stdev->dev, "%s: mrpc comp\n", __func__);
1447 schedule_work(&stdev->mrpc_work);
1448 iowrite32(reg, &stdev->mmio_part_cfg->mrpc_comp_hdr);
1451 check_link_state_events(stdev);
1458 event_count += mask_all_events(stdev, eid);
1462 atomic_inc(&stdev->event_cnt);
1463 wake_up_interruptible(&stdev->event_wq);
1464 dev_dbg(&stdev->dev, "%s: %d events\n", __func__,
1475 struct switchtec_dev *stdev = dev;
1479 &stdev->mmio_part_cfg->mrpc_comp_hdr);
1480 schedule_work(&stdev->mrpc_work);
1485 static int switchtec_init_isr(struct switchtec_dev *stdev)
1495 nvecs = pci_alloc_irq_vectors(stdev->pdev, 1, nirqs,
1501 event_irq = ioread16(&stdev->mmio_part_cfg->vep_vector_number);
1505 event_irq = pci_irq_vector(stdev->pdev, event_irq);
1509 rc = devm_request_irq(&stdev->pdev->dev, event_irq,
1511 KBUILD_MODNAME, stdev);
1516 if (!stdev->dma_mrpc)
1519 dma_mrpc_irq = ioread32(&stdev->mmio_mrpc->dma_vector);
1523 dma_mrpc_irq = pci_irq_vector(stdev->pdev, dma_mrpc_irq);
1527 rc = devm_request_irq(&stdev->pdev->dev, dma_mrpc_irq,
1529 KBUILD_MODNAME, stdev);
1534 static void init_pff(struct switchtec_dev *stdev)
1538 struct part_cfg_regs __iomem *pcfg = stdev->mmio_part_cfg;
1541 reg = ioread16(&stdev->mmio_pff_csr[i].vendor_id);
1546 stdev->pff_csr_count = i;
1549 if (reg < stdev->pff_csr_count)
1550 stdev->pff_local[reg] = 1;
1553 if (reg < stdev->pff_csr_count)
1554 stdev->pff_local[reg] = 1;
1558 if (reg < stdev->pff_csr_count)
1559 stdev->pff_local[reg] = 1;
1563 static int switchtec_init_pci(struct switchtec_dev *stdev,
1588 stdev->mmio_mrpc = devm_ioremap_wc(&pdev->dev, res_start,
1590 if (!stdev->mmio_mrpc)
1599 stdev->mmio = map - SWITCHTEC_GAS_TOP_CFG_OFFSET;
1600 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET;
1601 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET;
1602 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET;
1603 stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET;
1605 if (stdev->gen == SWITCHTEC_GEN3)
1606 part_id = &stdev->mmio_sys_info->gen3.partition_id;
1607 else if (stdev->gen >= SWITCHTEC_GEN4)
1608 part_id = &stdev->mmio_sys_info->gen4.partition_id;
1612 stdev->partition = ioread8(part_id);
1613 stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count);
1614 stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET;
1615 stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[stdev->partition];
1616 stdev->mmio_pff_csr = stdev->mmio + SWITCHTEC_GAS_PFF_CSR_OFFSET;
1618 if (stdev->partition_count < 1)
1619 stdev->partition_count = 1;
1621 init_pff(stdev);
1623 pci_set_drvdata(pdev, stdev);
1628 if (ioread32(&stdev->mmio_mrpc->dma_ver) == 0)
1631 stdev->dma_mrpc = dma_alloc_coherent(&stdev->pdev->dev,
1632 sizeof(*stdev->dma_mrpc),
1633 &stdev->dma_mrpc_dma_addr,
1635 if (stdev->dma_mrpc == NULL)
1641 static void switchtec_exit_pci(struct switchtec_dev *stdev)
1643 if (stdev->dma_mrpc) {
1644 iowrite32(0, &stdev->mmio_mrpc->dma_en);
1645 flush_wc_buf(stdev);
1646 writeq(0, &stdev->mmio_mrpc->dma_addr);
1647 dma_free_coherent(&stdev->pdev->dev, sizeof(*stdev->dma_mrpc),
1648 stdev->dma_mrpc, stdev->dma_mrpc_dma_addr);
1649 stdev->dma_mrpc = NULL;
1656 struct switchtec_dev *stdev;
1662 stdev = stdev_create(pdev);
1663 if (IS_ERR(stdev))
1664 return PTR_ERR(stdev);
1666 stdev->gen = id->driver_data;
1668 rc = switchtec_init_pci(stdev, pdev);
1672 rc = switchtec_init_isr(stdev);
1674 dev_err(&stdev->dev, "failed to init isr.\n");
1680 &stdev->mmio_part_cfg->mrpc_comp_hdr);
1681 enable_link_state_events(stdev);
1683 if (stdev->dma_mrpc)
1684 enable_dma_mrpc(stdev);
1686 rc = cdev_device_add(&stdev->cdev, &stdev->dev);
1690 dev_info(&stdev->dev, "Management device registered.\n");
1695 stdev_kill(stdev);
1697 switchtec_exit_pci(stdev);
1699 ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt));
1700 put_device(&stdev->dev);
1706 struct switchtec_dev *stdev = pci_get_drvdata(pdev);
1710 cdev_device_del(&stdev->cdev, &stdev->dev);
1711 ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt));
1712 dev_info(&stdev->dev, "unregistered.\n");
1713 stdev_kill(stdev);
1714 switchtec_exit_pci(stdev);
1715 pci_dev_put(stdev->pdev);
1716 stdev->pdev = NULL;
1717 put_device(&stdev->dev);