Lines Matching refs:tc
208 struct tool_ctx *tc;
233 struct tool_ctx *tc;
239 struct tool_ctx *tc;
244 struct tool_ctx *tc;
291 struct tool_ctx *tc = ctx;
296 up = ntb_link_is_up(tc->ntb, &speed, &width);
298 dev_dbg(&tc->ntb->dev, "link is %s speed %d width %d\n",
301 wake_up(&tc->link_wq);
306 struct tool_ctx *tc = ctx;
309 db_mask = ntb_db_vector_mask(tc->ntb, vec);
310 db_bits = ntb_db_read(tc->ntb);
312 dev_dbg(&tc->ntb->dev, "doorbell vec %d mask %#llx bits %#llx\n",
315 wake_up(&tc->db_wq);
320 struct tool_ctx *tc = ctx;
323 msg_sts = ntb_msg_read_sts(tc->ntb);
325 dev_dbg(&tc->ntb->dev, "message bits %#llx\n", msg_sts);
327 wake_up(&tc->msg_wq);
341 static ssize_t tool_fn_read(struct tool_ctx *tc, char __user *ubuf,
354 pos = scnprintf(buf, buf_size, "%#llx\n", fn_read(tc->ntb));
359 static ssize_t tool_fn_write(struct tool_ctx *tc,
387 ret = fn_set(tc->ntb, bits);
392 ret = fn_clear(tc->ntb, bits);
408 struct tool_ctx *tc = filep->private_data;
412 pos = scnprintf(buf, sizeof(buf), "%d\n", ntb_port_number(tc->ntb));
425 struct tool_ctx *tc = peer->tc;
430 ntb_peer_port_number(tc->ntb, peer->pidx));
439 static int tool_init_peers(struct tool_ctx *tc)
443 tc->peer_cnt = ntb_peer_port_count(tc->ntb);
444 tc->peers = devm_kcalloc(&tc->ntb->dev, tc->peer_cnt,
445 sizeof(*tc->peers), GFP_KERNEL);
446 if (tc->peers == NULL)
449 for (pidx = 0; pidx < tc->peer_cnt; pidx++) {
450 tc->peers[pidx].pidx = pidx;
451 tc->peers[pidx].tc = tc;
465 struct tool_ctx *tc = filep->private_data;
474 ret = ntb_link_enable(tc->ntb, NTB_SPEED_AUTO, NTB_WIDTH_AUTO);
476 ret = ntb_link_disable(tc->ntb);
492 struct tool_ctx *tc = peer->tc;
495 if (ntb_link_is_up(tc->ntb, NULL, NULL) & BIT(peer->pidx))
514 struct tool_ctx *tc = peer->tc;
525 if (wait_event_interruptible(tc->link_wq,
526 !!(ntb_link_is_up(tc->ntb, NULL, NULL) & link_msk) == val))
569 static int tool_setup_mw(struct tool_ctx *tc, int pidx, int widx,
573 struct tool_mw *inmw = &tc->peers[pidx].inmws[widx];
580 ret = ntb_mw_get_align(tc->ntb, pidx, widx, &addr_align,
588 inmw->mm_base = dma_alloc_coherent(&tc->ntb->pdev->dev, inmw->size,
598 ret = ntb_mw_set_trans(tc->ntb, pidx, widx, inmw->dma_base, inmw->size);
604 tc->peers[pidx].dbgfs_dir, inmw,
610 dma_free_coherent(&tc->ntb->pdev->dev, inmw->size, inmw->mm_base,
619 static void tool_free_mw(struct tool_ctx *tc, int pidx, int widx)
621 struct tool_mw *inmw = &tc->peers[pidx].inmws[widx];
626 ntb_mw_clear_trans(tc->ntb, pidx, widx);
627 dma_free_coherent(&tc->ntb->pdev->dev, inmw->size,
654 ret = ntb_mw_get_align(inmw->tc->ntb, inmw->pidx, inmw->widx,
665 ntb_peer_port_number(inmw->tc->ntb, inmw->pidx),
710 tool_free_mw(inmw->tc, inmw->pidx, inmw->widx);
712 ret = tool_setup_mw(inmw->tc, inmw->pidx, inmw->widx, val);
804 static int tool_setup_peer_mw(struct tool_ctx *tc, int pidx, int widx,
807 struct tool_mw *outmw = &tc->outmws[widx];
816 ret = ntb_peer_mw_get_addr(tc->ntb, widx, &map_base, &map_size);
820 ret = ntb_peer_mw_set_trans(tc->ntb, pidx, widx, req_addr, req_size);
836 tc->peers[pidx].dbgfs_dir, outmw,
842 ntb_peer_mw_clear_trans(tc->ntb, pidx, widx);
847 static void tool_free_peer_mw(struct tool_ctx *tc, int widx)
849 struct tool_mw *outmw = &tc->outmws[widx];
854 iounmap(tc->outmws[widx].io_base);
855 ntb_peer_mw_clear_trans(tc->ntb, outmw->pidx, widx);
877 ret = ntb_peer_mw_get_addr(outmw->tc->ntb, outmw->widx,
894 ntb_peer_port_number(outmw->tc->ntb, outmw->pidx),
943 tool_free_peer_mw(outmw->tc, outmw->widx);
945 ret = tool_setup_peer_mw(outmw->tc, outmw_wrap->pidx,
958 static int tool_init_mws(struct tool_ctx *tc)
963 tc->outmw_cnt = ntb_peer_mw_count(tc->ntb);
964 tc->outmws = devm_kcalloc(&tc->ntb->dev, tc->outmw_cnt,
965 sizeof(*tc->outmws), GFP_KERNEL);
966 if (tc->outmws == NULL)
969 for (widx = 0; widx < tc->outmw_cnt; widx++) {
970 tc->outmws[widx].widx = widx;
971 tc->outmws[widx].pidx = -1;
972 tc->outmws[widx].tc = tc;
976 for (pidx = 0; pidx < tc->peer_cnt; pidx++) {
977 tc->peers[pidx].inmw_cnt = ntb_mw_count(tc->ntb, pidx);
978 tc->peers[pidx].inmws =
979 devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].inmw_cnt,
980 sizeof(*tc->peers[pidx].inmws), GFP_KERNEL);
981 if (tc->peers[pidx].inmws == NULL)
984 for (widx = 0; widx < tc->peers[pidx].inmw_cnt; widx++) {
985 tc->peers[pidx].inmws[widx].widx = widx;
986 tc->peers[pidx].inmws[widx].pidx = pidx;
987 tc->peers[pidx].inmws[widx].tc = tc;
990 tc->peers[pidx].outmw_cnt = ntb_peer_mw_count(tc->ntb);
991 tc->peers[pidx].outmws =
992 devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
993 sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
994 if (tc->peers[pidx].outmws == NULL)
997 for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
998 tc->peers[pidx].outmws[widx].pidx = pidx;
999 tc->peers[pidx].outmws[widx].mw = &tc->outmws[widx];
1006 static void tool_clear_mws(struct tool_ctx *tc)
1011 for (widx = 0; widx < tc->outmw_cnt; widx++)
1012 tool_free_peer_mw(tc, widx);
1015 for (pidx = 0; pidx < tc->peer_cnt; pidx++)
1016 for (widx = 0; widx < tc->peers[pidx].inmw_cnt; widx++)
1017 tool_free_mw(tc, pidx, widx);
1028 struct tool_ctx *tc = filep->private_data;
1030 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->db_read);
1036 struct tool_ctx *tc = filep->private_data;
1038 return tool_fn_write(tc, ubuf, size, offp, tc->ntb->ops->db_set,
1039 tc->ntb->ops->db_clear);
1049 struct tool_ctx *tc = filep->private_data;
1051 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->db_valid_mask);
1061 struct tool_ctx *tc = filep->private_data;
1063 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->db_read_mask);
1069 struct tool_ctx *tc = filep->private_data;
1071 return tool_fn_write(tc, ubuf, size, offp, tc->ntb->ops->db_set_mask,
1072 tc->ntb->ops->db_clear_mask);
1082 struct tool_ctx *tc = filep->private_data;
1084 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->peer_db_read);
1090 struct tool_ctx *tc = filep->private_data;
1092 return tool_fn_write(tc, ubuf, size, offp, tc->ntb->ops->peer_db_set,
1093 tc->ntb->ops->peer_db_clear);
1103 struct tool_ctx *tc = filep->private_data;
1105 return tool_fn_read(tc, ubuf, size, offp,
1106 tc->ntb->ops->peer_db_read_mask);
1113 struct tool_ctx *tc = filep->private_data;
1115 return tool_fn_write(tc, ubuf, size, offp,
1116 tc->ntb->ops->peer_db_set_mask,
1117 tc->ntb->ops->peer_db_clear_mask);
1128 struct tool_ctx *tc = filep->private_data;
1136 if (wait_event_interruptible(tc->db_wq, ntb_db_read(tc->ntb) == val))
1158 if (!spad->tc->ntb->ops->spad_read)
1162 ntb_spad_read(spad->tc->ntb, spad->sidx));
1174 if (!spad->tc->ntb->ops->spad_write) {
1175 dev_dbg(&spad->tc->ntb->dev, "no spad write fn\n");
1183 ret = ntb_spad_write(spad->tc->ntb, spad->sidx, val);
1199 if (!spad->tc->ntb->ops->peer_spad_read)
1203 ntb_peer_spad_read(spad->tc->ntb, spad->pidx, spad->sidx));
1215 if (!spad->tc->ntb->ops->peer_spad_write) {
1216 dev_dbg(&spad->tc->ntb->dev, "no spad write fn\n");
1224 ret = ntb_peer_spad_write(spad->tc->ntb, spad->pidx, spad->sidx, val);
1233 static int tool_init_spads(struct tool_ctx *tc)
1238 tc->inspad_cnt = ntb_spad_count(tc->ntb);
1239 tc->inspads = devm_kcalloc(&tc->ntb->dev, tc->inspad_cnt,
1240 sizeof(*tc->inspads), GFP_KERNEL);
1241 if (tc->inspads == NULL)
1244 for (sidx = 0; sidx < tc->inspad_cnt; sidx++) {
1245 tc->inspads[sidx].sidx = sidx;
1246 tc->inspads[sidx].pidx = -1;
1247 tc->inspads[sidx].tc = tc;
1251 for (pidx = 0; pidx < tc->peer_cnt; pidx++) {
1252 tc->peers[pidx].outspad_cnt = ntb_spad_count(tc->ntb);
1253 tc->peers[pidx].outspads =
1254 devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outspad_cnt,
1255 sizeof(*tc->peers[pidx].outspads), GFP_KERNEL);
1256 if (tc->peers[pidx].outspads == NULL)
1259 for (sidx = 0; sidx < tc->peers[pidx].outspad_cnt; sidx++) {
1260 tc->peers[pidx].outspads[sidx].sidx = sidx;
1261 tc->peers[pidx].outspads[sidx].pidx = pidx;
1262 tc->peers[pidx].outspads[sidx].tc = tc;
1283 data = ntb_msg_read(msg->tc->ntb, &pidx, msg->midx);
1306 ret = ntb_peer_msg_write(msg->tc->ntb, msg->pidx, msg->midx, val);
1318 struct tool_ctx *tc = filep->private_data;
1320 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->msg_read_sts);
1326 struct tool_ctx *tc = filep->private_data;
1328 return tool_fn_write(tc, ubuf, size, offp, NULL,
1329 tc->ntb->ops->msg_clear_sts);
1339 struct tool_ctx *tc = filep->private_data;
1341 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->msg_inbits);
1351 struct tool_ctx *tc = filep->private_data;
1353 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->msg_outbits);
1363 struct tool_ctx *tc = filep->private_data;
1365 return tool_fn_write(tc, ubuf, size, offp,
1366 tc->ntb->ops->msg_set_mask,
1367 tc->ntb->ops->msg_clear_mask);
1378 struct tool_ctx *tc = filep->private_data;
1386 if (wait_event_interruptible(tc->msg_wq,
1387 ntb_msg_read_sts(tc->ntb) == val))
1397 static int tool_init_msgs(struct tool_ctx *tc)
1402 tc->inmsg_cnt = ntb_msg_count(tc->ntb);
1403 tc->inmsgs = devm_kcalloc(&tc->ntb->dev, tc->inmsg_cnt,
1404 sizeof(*tc->inmsgs), GFP_KERNEL);
1405 if (tc->inmsgs == NULL)
1408 for (midx = 0; midx < tc->inmsg_cnt; midx++) {
1409 tc->inmsgs[midx].midx = midx;
1410 tc->inmsgs[midx].pidx = -1;
1411 tc->inmsgs[midx].tc = tc;
1415 for (pidx = 0; pidx < tc->peer_cnt; pidx++) {
1416 tc->peers[pidx].outmsg_cnt = ntb_msg_count(tc->ntb);
1417 tc->peers[pidx].outmsgs =
1418 devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmsg_cnt,
1419 sizeof(*tc->peers[pidx].outmsgs), GFP_KERNEL);
1420 if (tc->peers[pidx].outmsgs == NULL)
1423 for (midx = 0; midx < tc->peers[pidx].outmsg_cnt; midx++) {
1424 tc->peers[pidx].outmsgs[midx].midx = midx;
1425 tc->peers[pidx].outmsgs[midx].pidx = pidx;
1426 tc->peers[pidx].outmsgs[midx].tc = tc;
1440 struct tool_ctx *tc;
1442 tc = devm_kzalloc(&ntb->dev, sizeof(*tc), GFP_KERNEL);
1443 if (tc == NULL)
1446 tc->ntb = ntb;
1447 init_waitqueue_head(&tc->link_wq);
1448 init_waitqueue_head(&tc->db_wq);
1449 init_waitqueue_head(&tc->msg_wq);
1457 return tc;
1460 static void tool_clear_data(struct tool_ctx *tc)
1462 wake_up(&tc->link_wq);
1463 wake_up(&tc->db_wq);
1464 wake_up(&tc->msg_wq);
1467 static int tool_init_ntb(struct tool_ctx *tc)
1469 return ntb_set_ctx(tc->ntb, tc, &tool_ops);
1472 static void tool_clear_ntb(struct tool_ctx *tc)
1474 ntb_clear_ctx(tc->ntb);
1475 ntb_link_disable(tc->ntb);
1478 static void tool_setup_dbgfs(struct tool_ctx *tc)
1485 tc->dbgfs_dir = NULL;
1489 tc->dbgfs_dir = debugfs_create_dir(dev_name(&tc->ntb->dev),
1492 debugfs_create_file("port", 0600, tc->dbgfs_dir,
1493 tc, &tool_port_fops);
1495 debugfs_create_file("link", 0600, tc->dbgfs_dir,
1496 tc, &tool_link_fops);
1498 debugfs_create_file("db", 0600, tc->dbgfs_dir,
1499 tc, &tool_db_fops);
1501 debugfs_create_file("db_valid_mask", 0600, tc->dbgfs_dir,
1502 tc, &tool_db_valid_mask_fops);
1504 debugfs_create_file("db_mask", 0600, tc->dbgfs_dir,
1505 tc, &tool_db_mask_fops);
1507 debugfs_create_file("db_event", 0600, tc->dbgfs_dir,
1508 tc, &tool_db_event_fops);
1510 debugfs_create_file("peer_db", 0600, tc->dbgfs_dir,
1511 tc, &tool_peer_db_fops);
1513 debugfs_create_file("peer_db_mask", 0600, tc->dbgfs_dir,
1514 tc, &tool_peer_db_mask_fops);
1516 if (tc->inspad_cnt != 0) {
1517 for (sidx = 0; sidx < tc->inspad_cnt; sidx++) {
1520 debugfs_create_file(buf, 0600, tc->dbgfs_dir,
1521 &tc->inspads[sidx], &tool_spad_fops);
1525 if (tc->inmsg_cnt != 0) {
1526 for (midx = 0; midx < tc->inmsg_cnt; midx++) {
1528 debugfs_create_file(buf, 0600, tc->dbgfs_dir,
1529 &tc->inmsgs[midx], &tool_inmsg_fops);
1532 debugfs_create_file("msg_sts", 0600, tc->dbgfs_dir,
1533 tc, &tool_msg_sts_fops);
1535 debugfs_create_file("msg_inbits", 0600, tc->dbgfs_dir,
1536 tc, &tool_msg_inbits_fops);
1538 debugfs_create_file("msg_outbits", 0600, tc->dbgfs_dir,
1539 tc, &tool_msg_outbits_fops);
1541 debugfs_create_file("msg_mask", 0600, tc->dbgfs_dir,
1542 tc, &tool_msg_mask_fops);
1544 debugfs_create_file("msg_event", 0600, tc->dbgfs_dir,
1545 tc, &tool_msg_event_fops);
1548 for (pidx = 0; pidx < tc->peer_cnt; pidx++) {
1550 tc->peers[pidx].dbgfs_dir =
1551 debugfs_create_dir(buf, tc->dbgfs_dir);
1554 tc->peers[pidx].dbgfs_dir,
1555 &tc->peers[pidx], &tool_peer_port_fops);
1558 tc->peers[pidx].dbgfs_dir,
1559 &tc->peers[pidx], &tool_peer_link_fops);
1562 tc->peers[pidx].dbgfs_dir,
1563 &tc->peers[pidx], &tool_peer_link_event_fops);
1565 for (widx = 0; widx < tc->peers[pidx].inmw_cnt; widx++) {
1568 tc->peers[pidx].dbgfs_dir,
1569 &tc->peers[pidx].inmws[widx],
1573 for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
1576 tc->peers[pidx].dbgfs_dir,
1577 &tc->peers[pidx].outmws[widx],
1581 for (sidx = 0; sidx < tc->peers[pidx].outspad_cnt; sidx++) {
1585 tc->peers[pidx].dbgfs_dir,
1586 &tc->peers[pidx].outspads[sidx],
1590 for (midx = 0; midx < tc->peers[pidx].outmsg_cnt; midx++) {
1593 tc->peers[pidx].dbgfs_dir,
1594 &tc->peers[pidx].outmsgs[midx],
1600 static void tool_clear_dbgfs(struct tool_ctx *tc)
1602 debugfs_remove_recursive(tc->dbgfs_dir);
1607 struct tool_ctx *tc;
1610 tc = tool_create_data(ntb);
1611 if (IS_ERR(tc))
1612 return PTR_ERR(tc);
1614 ret = tool_init_peers(tc);
1618 ret = tool_init_mws(tc);
1622 ret = tool_init_spads(tc);
1626 ret = tool_init_msgs(tc);
1630 ret = tool_init_ntb(tc);
1634 tool_setup_dbgfs(tc);
1639 tool_clear_mws(tc);
1642 tool_clear_data(tc);
1649 struct tool_ctx *tc = ntb->ctx;
1651 tool_clear_dbgfs(tc);
1653 tool_clear_ntb(tc);
1655 tool_clear_mws(tc);
1657 tool_clear_data(tc);