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,
394 ret = fn_set(tc->ntb, bits);
399 ret = fn_clear(tc->ntb, bits);
415 struct tool_ctx *tc = filep->private_data;
419 pos = scnprintf(buf, sizeof(buf), "%d\n", ntb_port_number(tc->ntb));
432 struct tool_ctx *tc = peer->tc;
437 ntb_peer_port_number(tc->ntb, peer->pidx));
446 static int tool_init_peers(struct tool_ctx *tc)
450 tc->peer_cnt = ntb_peer_port_count(tc->ntb);
451 tc->peers = devm_kcalloc(&tc->ntb->dev, tc->peer_cnt,
452 sizeof(*tc->peers), GFP_KERNEL);
453 if (tc->peers == NULL)
456 for (pidx = 0; pidx < tc->peer_cnt; pidx++) {
457 tc->peers[pidx].pidx = pidx;
458 tc->peers[pidx].tc = tc;
472 struct tool_ctx *tc = filep->private_data;
481 ret = ntb_link_enable(tc->ntb, NTB_SPEED_AUTO, NTB_WIDTH_AUTO);
483 ret = ntb_link_disable(tc->ntb);
499 struct tool_ctx *tc = peer->tc;
502 if (ntb_link_is_up(tc->ntb, NULL, NULL) & BIT(peer->pidx))
521 struct tool_ctx *tc = peer->tc;
532 if (wait_event_interruptible(tc->link_wq,
533 !!(ntb_link_is_up(tc->ntb, NULL, NULL) & link_msk) == val))
576 static int tool_setup_mw(struct tool_ctx *tc, int pidx, int widx,
580 struct tool_mw *inmw = &tc->peers[pidx].inmws[widx];
587 ret = ntb_mw_get_align(tc->ntb, pidx, widx, &addr_align,
595 inmw->mm_base = dma_alloc_coherent(&tc->ntb->pdev->dev, inmw->size,
605 ret = ntb_mw_set_trans(tc->ntb, pidx, widx, inmw->dma_base, inmw->size);
611 tc->peers[pidx].dbgfs_dir, inmw,
617 dma_free_coherent(&tc->ntb->pdev->dev, inmw->size, inmw->mm_base,
626 static void tool_free_mw(struct tool_ctx *tc, int pidx, int widx)
628 struct tool_mw *inmw = &tc->peers[pidx].inmws[widx];
633 ntb_mw_clear_trans(tc->ntb, pidx, widx);
634 dma_free_coherent(&tc->ntb->pdev->dev, inmw->size,
661 ret = ntb_mw_get_align(inmw->tc->ntb, inmw->pidx, inmw->widx,
672 ntb_peer_port_number(inmw->tc->ntb, inmw->pidx),
717 tool_free_mw(inmw->tc, inmw->pidx, inmw->widx);
719 ret = tool_setup_mw(inmw->tc, inmw->pidx, inmw->widx, val);
811 static int tool_setup_peer_mw(struct tool_ctx *tc, int pidx, int widx,
814 struct tool_mw *outmw = &tc->outmws[widx];
823 ret = ntb_peer_mw_get_addr(tc->ntb, widx, &map_base, &map_size);
827 ret = ntb_peer_mw_set_trans(tc->ntb, pidx, widx, req_addr, req_size);
843 tc->peers[pidx].dbgfs_dir, outmw,
849 ntb_peer_mw_clear_trans(tc->ntb, pidx, widx);
854 static void tool_free_peer_mw(struct tool_ctx *tc, int widx)
856 struct tool_mw *outmw = &tc->outmws[widx];
861 iounmap(tc->outmws[widx].io_base);
862 ntb_peer_mw_clear_trans(tc->ntb, outmw->pidx, widx);
884 ret = ntb_peer_mw_get_addr(outmw->tc->ntb, outmw->widx,
901 ntb_peer_port_number(outmw->tc->ntb, outmw->pidx),
950 tool_free_peer_mw(outmw->tc, outmw->widx);
952 ret = tool_setup_peer_mw(outmw->tc, outmw_wrap->pidx,
965 static int tool_init_mws(struct tool_ctx *tc)
970 tc->outmw_cnt = ntb_peer_mw_count(tc->ntb);
971 tc->outmws = devm_kcalloc(&tc->ntb->dev, tc->outmw_cnt,
972 sizeof(*tc->outmws), GFP_KERNEL);
973 if (tc->outmws == NULL)
976 for (widx = 0; widx < tc->outmw_cnt; widx++) {
977 tc->outmws[widx].widx = widx;
978 tc->outmws[widx].pidx = -1;
979 tc->outmws[widx].tc = tc;
983 for (pidx = 0; pidx < tc->peer_cnt; pidx++) {
984 tc->peers[pidx].inmw_cnt = ntb_mw_count(tc->ntb, pidx);
985 tc->peers[pidx].inmws =
986 devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].inmw_cnt,
987 sizeof(*tc->peers[pidx].inmws), GFP_KERNEL);
988 if (tc->peers[pidx].inmws == NULL)
991 for (widx = 0; widx < tc->peers[pidx].inmw_cnt; widx++) {
992 tc->peers[pidx].inmws[widx].widx = widx;
993 tc->peers[pidx].inmws[widx].pidx = pidx;
994 tc->peers[pidx].inmws[widx].tc = tc;
997 tc->peers[pidx].outmw_cnt = ntb_peer_mw_count(tc->ntb);
998 tc->peers[pidx].outmws =
999 devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
1000 sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
1001 if (tc->peers[pidx].outmws == NULL)
1004 for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
1005 tc->peers[pidx].outmws[widx].pidx = pidx;
1006 tc->peers[pidx].outmws[widx].mw = &tc->outmws[widx];
1013 static void tool_clear_mws(struct tool_ctx *tc)
1018 for (widx = 0; widx < tc->outmw_cnt; widx++)
1019 tool_free_peer_mw(tc, widx);
1022 for (pidx = 0; pidx < tc->peer_cnt; pidx++)
1023 for (widx = 0; widx < tc->peers[pidx].inmw_cnt; widx++)
1024 tool_free_mw(tc, pidx, widx);
1035 struct tool_ctx *tc = filep->private_data;
1037 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->db_read);
1043 struct tool_ctx *tc = filep->private_data;
1045 return tool_fn_write(tc, ubuf, size, offp, tc->ntb->ops->db_set,
1046 tc->ntb->ops->db_clear);
1056 struct tool_ctx *tc = filep->private_data;
1058 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->db_valid_mask);
1068 struct tool_ctx *tc = filep->private_data;
1070 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->db_read_mask);
1076 struct tool_ctx *tc = filep->private_data;
1078 return tool_fn_write(tc, ubuf, size, offp, tc->ntb->ops->db_set_mask,
1079 tc->ntb->ops->db_clear_mask);
1089 struct tool_ctx *tc = filep->private_data;
1091 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->peer_db_read);
1097 struct tool_ctx *tc = filep->private_data;
1099 return tool_fn_write(tc, ubuf, size, offp, tc->ntb->ops->peer_db_set,
1100 tc->ntb->ops->peer_db_clear);
1110 struct tool_ctx *tc = filep->private_data;
1112 return tool_fn_read(tc, ubuf, size, offp,
1113 tc->ntb->ops->peer_db_read_mask);
1120 struct tool_ctx *tc = filep->private_data;
1122 return tool_fn_write(tc, ubuf, size, offp,
1123 tc->ntb->ops->peer_db_set_mask,
1124 tc->ntb->ops->peer_db_clear_mask);
1135 struct tool_ctx *tc = filep->private_data;
1143 if (wait_event_interruptible(tc->db_wq, ntb_db_read(tc->ntb) == val))
1165 if (!spad->tc->ntb->ops->spad_read)
1169 ntb_spad_read(spad->tc->ntb, spad->sidx));
1181 if (!spad->tc->ntb->ops->spad_write) {
1182 dev_dbg(&spad->tc->ntb->dev, "no spad write fn\n");
1190 ret = ntb_spad_write(spad->tc->ntb, spad->sidx, val);
1206 if (!spad->tc->ntb->ops->peer_spad_read)
1210 ntb_peer_spad_read(spad->tc->ntb, spad->pidx, spad->sidx));
1222 if (!spad->tc->ntb->ops->peer_spad_write) {
1223 dev_dbg(&spad->tc->ntb->dev, "no spad write fn\n");
1231 ret = ntb_peer_spad_write(spad->tc->ntb, spad->pidx, spad->sidx, val);
1240 static int tool_init_spads(struct tool_ctx *tc)
1245 tc->inspad_cnt = ntb_spad_count(tc->ntb);
1246 tc->inspads = devm_kcalloc(&tc->ntb->dev, tc->inspad_cnt,
1247 sizeof(*tc->inspads), GFP_KERNEL);
1248 if (tc->inspads == NULL)
1251 for (sidx = 0; sidx < tc->inspad_cnt; sidx++) {
1252 tc->inspads[sidx].sidx = sidx;
1253 tc->inspads[sidx].pidx = -1;
1254 tc->inspads[sidx].tc = tc;
1258 for (pidx = 0; pidx < tc->peer_cnt; pidx++) {
1259 tc->peers[pidx].outspad_cnt = ntb_spad_count(tc->ntb);
1260 tc->peers[pidx].outspads =
1261 devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outspad_cnt,
1262 sizeof(*tc->peers[pidx].outspads), GFP_KERNEL);
1263 if (tc->peers[pidx].outspads == NULL)
1266 for (sidx = 0; sidx < tc->peers[pidx].outspad_cnt; sidx++) {
1267 tc->peers[pidx].outspads[sidx].sidx = sidx;
1268 tc->peers[pidx].outspads[sidx].pidx = pidx;
1269 tc->peers[pidx].outspads[sidx].tc = tc;
1290 data = ntb_msg_read(msg->tc->ntb, &pidx, msg->midx);
1313 ret = ntb_peer_msg_write(msg->tc->ntb, msg->pidx, msg->midx, val);
1325 struct tool_ctx *tc = filep->private_data;
1327 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->msg_read_sts);
1333 struct tool_ctx *tc = filep->private_data;
1335 return tool_fn_write(tc, ubuf, size, offp, NULL,
1336 tc->ntb->ops->msg_clear_sts);
1346 struct tool_ctx *tc = filep->private_data;
1348 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->msg_inbits);
1358 struct tool_ctx *tc = filep->private_data;
1360 return tool_fn_read(tc, ubuf, size, offp, tc->ntb->ops->msg_outbits);
1370 struct tool_ctx *tc = filep->private_data;
1372 return tool_fn_write(tc, ubuf, size, offp,
1373 tc->ntb->ops->msg_set_mask,
1374 tc->ntb->ops->msg_clear_mask);
1385 struct tool_ctx *tc = filep->private_data;
1393 if (wait_event_interruptible(tc->msg_wq,
1394 ntb_msg_read_sts(tc->ntb) == val))
1404 static int tool_init_msgs(struct tool_ctx *tc)
1409 tc->inmsg_cnt = ntb_msg_count(tc->ntb);
1410 tc->inmsgs = devm_kcalloc(&tc->ntb->dev, tc->inmsg_cnt,
1411 sizeof(*tc->inmsgs), GFP_KERNEL);
1412 if (tc->inmsgs == NULL)
1415 for (midx = 0; midx < tc->inmsg_cnt; midx++) {
1416 tc->inmsgs[midx].midx = midx;
1417 tc->inmsgs[midx].pidx = -1;
1418 tc->inmsgs[midx].tc = tc;
1422 for (pidx = 0; pidx < tc->peer_cnt; pidx++) {
1423 tc->peers[pidx].outmsg_cnt = ntb_msg_count(tc->ntb);
1424 tc->peers[pidx].outmsgs =
1425 devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmsg_cnt,
1426 sizeof(*tc->peers[pidx].outmsgs), GFP_KERNEL);
1427 if (tc->peers[pidx].outmsgs == NULL)
1430 for (midx = 0; midx < tc->peers[pidx].outmsg_cnt; midx++) {
1431 tc->peers[pidx].outmsgs[midx].midx = midx;
1432 tc->peers[pidx].outmsgs[midx].pidx = pidx;
1433 tc->peers[pidx].outmsgs[midx].tc = tc;
1447 struct tool_ctx *tc;
1449 tc = devm_kzalloc(&ntb->dev, sizeof(*tc), GFP_KERNEL);
1450 if (tc == NULL)
1453 tc->ntb = ntb;
1454 init_waitqueue_head(&tc->link_wq);
1455 init_waitqueue_head(&tc->db_wq);
1456 init_waitqueue_head(&tc->msg_wq);
1464 return tc;
1467 static void tool_clear_data(struct tool_ctx *tc)
1469 wake_up(&tc->link_wq);
1470 wake_up(&tc->db_wq);
1471 wake_up(&tc->msg_wq);
1474 static int tool_init_ntb(struct tool_ctx *tc)
1476 return ntb_set_ctx(tc->ntb, tc, &tool_ops);
1479 static void tool_clear_ntb(struct tool_ctx *tc)
1481 ntb_clear_ctx(tc->ntb);
1482 ntb_link_disable(tc->ntb);
1485 static void tool_setup_dbgfs(struct tool_ctx *tc)
1492 tc->dbgfs_dir = NULL;
1496 tc->dbgfs_dir = debugfs_create_dir(dev_name(&tc->ntb->dev),
1498 if (!tc->dbgfs_dir)
1501 debugfs_create_file("port", 0600, tc->dbgfs_dir,
1502 tc, &tool_port_fops);
1504 debugfs_create_file("link", 0600, tc->dbgfs_dir,
1505 tc, &tool_link_fops);
1507 debugfs_create_file("db", 0600, tc->dbgfs_dir,
1508 tc, &tool_db_fops);
1510 debugfs_create_file("db_valid_mask", 0600, tc->dbgfs_dir,
1511 tc, &tool_db_valid_mask_fops);
1513 debugfs_create_file("db_mask", 0600, tc->dbgfs_dir,
1514 tc, &tool_db_mask_fops);
1516 debugfs_create_file("db_event", 0600, tc->dbgfs_dir,
1517 tc, &tool_db_event_fops);
1519 debugfs_create_file("peer_db", 0600, tc->dbgfs_dir,
1520 tc, &tool_peer_db_fops);
1522 debugfs_create_file("peer_db_mask", 0600, tc->dbgfs_dir,
1523 tc, &tool_peer_db_mask_fops);
1525 if (tc->inspad_cnt != 0) {
1526 for (sidx = 0; sidx < tc->inspad_cnt; sidx++) {
1529 debugfs_create_file(buf, 0600, tc->dbgfs_dir,
1530 &tc->inspads[sidx], &tool_spad_fops);
1534 if (tc->inmsg_cnt != 0) {
1535 for (midx = 0; midx < tc->inmsg_cnt; midx++) {
1537 debugfs_create_file(buf, 0600, tc->dbgfs_dir,
1538 &tc->inmsgs[midx], &tool_inmsg_fops);
1541 debugfs_create_file("msg_sts", 0600, tc->dbgfs_dir,
1542 tc, &tool_msg_sts_fops);
1544 debugfs_create_file("msg_inbits", 0600, tc->dbgfs_dir,
1545 tc, &tool_msg_inbits_fops);
1547 debugfs_create_file("msg_outbits", 0600, tc->dbgfs_dir,
1548 tc, &tool_msg_outbits_fops);
1550 debugfs_create_file("msg_mask", 0600, tc->dbgfs_dir,
1551 tc, &tool_msg_mask_fops);
1553 debugfs_create_file("msg_event", 0600, tc->dbgfs_dir,
1554 tc, &tool_msg_event_fops);
1557 for (pidx = 0; pidx < tc->peer_cnt; pidx++) {
1559 tc->peers[pidx].dbgfs_dir =
1560 debugfs_create_dir(buf, tc->dbgfs_dir);
1563 tc->peers[pidx].dbgfs_dir,
1564 &tc->peers[pidx], &tool_peer_port_fops);
1567 tc->peers[pidx].dbgfs_dir,
1568 &tc->peers[pidx], &tool_peer_link_fops);
1571 tc->peers[pidx].dbgfs_dir,
1572 &tc->peers[pidx], &tool_peer_link_event_fops);
1574 for (widx = 0; widx < tc->peers[pidx].inmw_cnt; widx++) {
1577 tc->peers[pidx].dbgfs_dir,
1578 &tc->peers[pidx].inmws[widx],
1582 for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
1585 tc->peers[pidx].dbgfs_dir,
1586 &tc->peers[pidx].outmws[widx],
1590 for (sidx = 0; sidx < tc->peers[pidx].outspad_cnt; sidx++) {
1594 tc->peers[pidx].dbgfs_dir,
1595 &tc->peers[pidx].outspads[sidx],
1599 for (midx = 0; midx < tc->peers[pidx].outmsg_cnt; midx++) {
1602 tc->peers[pidx].dbgfs_dir,
1603 &tc->peers[pidx].outmsgs[midx],
1609 static void tool_clear_dbgfs(struct tool_ctx *tc)
1611 debugfs_remove_recursive(tc->dbgfs_dir);
1616 struct tool_ctx *tc;
1619 tc = tool_create_data(ntb);
1620 if (IS_ERR(tc))
1621 return PTR_ERR(tc);
1623 ret = tool_init_peers(tc);
1627 ret = tool_init_mws(tc);
1631 ret = tool_init_spads(tc);
1635 ret = tool_init_msgs(tc);
1639 ret = tool_init_ntb(tc);
1643 tool_setup_dbgfs(tc);
1648 tool_clear_mws(tc);
1651 tool_clear_data(tc);
1658 struct tool_ctx *tc = ntb->ctx;
1660 tool_clear_dbgfs(tc);
1662 tool_clear_ntb(tc);
1664 tool_clear_mws(tc);
1666 tool_clear_data(tc);