aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLogan Gunthorpe <logang@deltatee.com>2017-08-03 14:19:52 -0400
committerJon Mason <jdmason@kudzu.us>2017-11-18 20:37:12 -0500
commitb9a4acac282eff60cba800bdbc5a3b57c33c10be (patch)
treef2378cf90434a7b25f4fe715203403657ec4b06b
parent6619bf954984e625f5ba46e810ed08054309efab (diff)
NTB: switchtec_ntb: Implement scratchpad registers
Seeing there is no dedicated hardware for this, we simply add these as entries in the shared memory window. Thus, we could support any number of them but 128 seems like enough, for now. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Reviewed-by: Stephen Bates <sbates@raithlin.com> Reviewed-by: Kurt Schwemmer <kurt.schwemmer@microsemi.com> Acked-by: Allen Hubbe <Allen.Hubbe@dell.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
-rw-r--r--drivers/ntb/hw/mscc/ntb_hw_switchtec.c75
1 files changed, 73 insertions, 2 deletions
diff --git a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
index 4a6125d2f305..205bd9481122 100644
--- a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
+++ b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
@@ -67,6 +67,7 @@ struct shared_mw {
67 u32 link_sta; 67 u32 link_sta;
68 u32 partition_id; 68 u32 partition_id;
69 u64 mw_sizes[MAX_MWS]; 69 u64 mw_sizes[MAX_MWS];
70 u32 spad[128];
70}; 71};
71 72
72#define MAX_DIRECT_MW ARRAY_SIZE(((struct ntb_ctrl_regs *)(0))->bar_entry) 73#define MAX_DIRECT_MW ARRAY_SIZE(((struct ntb_ctrl_regs *)(0))->bar_entry)
@@ -455,22 +456,90 @@ static int switchtec_ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits)
455 456
456static int switchtec_ntb_spad_count(struct ntb_dev *ntb) 457static int switchtec_ntb_spad_count(struct ntb_dev *ntb)
457{ 458{
458 return 0; 459 struct switchtec_ntb *sndev = ntb_sndev(ntb);
460
461 return ARRAY_SIZE(sndev->self_shared->spad);
459} 462}
460 463
461static u32 switchtec_ntb_spad_read(struct ntb_dev *ntb, int idx) 464static u32 switchtec_ntb_spad_read(struct ntb_dev *ntb, int idx)
462{ 465{
463 return 0; 466 struct switchtec_ntb *sndev = ntb_sndev(ntb);
467
468 if (idx < 0 || idx >= ARRAY_SIZE(sndev->self_shared->spad))
469 return 0;
470
471 if (!sndev->self_shared)
472 return 0;
473
474 return sndev->self_shared->spad[idx];
464} 475}
465 476
466static int switchtec_ntb_spad_write(struct ntb_dev *ntb, int idx, u32 val) 477static int switchtec_ntb_spad_write(struct ntb_dev *ntb, int idx, u32 val)
467{ 478{
479 struct switchtec_ntb *sndev = ntb_sndev(ntb);
480
481 if (idx < 0 || idx >= ARRAY_SIZE(sndev->self_shared->spad))
482 return -EINVAL;
483
484 if (!sndev->self_shared)
485 return -EIO;
486
487 sndev->self_shared->spad[idx] = val;
488
468 return 0; 489 return 0;
469} 490}
470 491
492static u32 switchtec_ntb_peer_spad_read(struct ntb_dev *ntb, int pidx,
493 int sidx)
494{
495 struct switchtec_ntb *sndev = ntb_sndev(ntb);
496
497 if (pidx != NTB_DEF_PEER_IDX)
498 return -EINVAL;
499
500 if (sidx < 0 || sidx >= ARRAY_SIZE(sndev->peer_shared->spad))
501 return 0;
502
503 if (!sndev->peer_shared)
504 return 0;
505
506 return ioread32(&sndev->peer_shared->spad[sidx]);
507}
508
471static int switchtec_ntb_peer_spad_write(struct ntb_dev *ntb, int pidx, 509static int switchtec_ntb_peer_spad_write(struct ntb_dev *ntb, int pidx,
472 int sidx, u32 val) 510 int sidx, u32 val)
473{ 511{
512 struct switchtec_ntb *sndev = ntb_sndev(ntb);
513
514 if (pidx != NTB_DEF_PEER_IDX)
515 return -EINVAL;
516
517 if (sidx < 0 || sidx >= ARRAY_SIZE(sndev->peer_shared->spad))
518 return -EINVAL;
519
520 if (!sndev->peer_shared)
521 return -EIO;
522
523 iowrite32(val, &sndev->peer_shared->spad[sidx]);
524
525 return 0;
526}
527
528static int switchtec_ntb_peer_spad_addr(struct ntb_dev *ntb, int pidx,
529 int sidx, phys_addr_t *spad_addr)
530{
531 struct switchtec_ntb *sndev = ntb_sndev(ntb);
532 unsigned long offset;
533
534 if (pidx != NTB_DEF_PEER_IDX)
535 return -EINVAL;
536
537 offset = (unsigned long)&sndev->peer_shared->spad[sidx] -
538 (unsigned long)sndev->stdev->mmio;
539
540 if (spad_addr)
541 *spad_addr = pci_resource_start(ntb->pdev, 0) + offset;
542
474 return 0; 543 return 0;
475} 544}
476 545
@@ -496,7 +565,9 @@ static const struct ntb_dev_ops switchtec_ntb_ops = {
496 .spad_count = switchtec_ntb_spad_count, 565 .spad_count = switchtec_ntb_spad_count,
497 .spad_read = switchtec_ntb_spad_read, 566 .spad_read = switchtec_ntb_spad_read,
498 .spad_write = switchtec_ntb_spad_write, 567 .spad_write = switchtec_ntb_spad_write,
568 .peer_spad_read = switchtec_ntb_peer_spad_read,
499 .peer_spad_write = switchtec_ntb_peer_spad_write, 569 .peer_spad_write = switchtec_ntb_peer_spad_write,
570 .peer_spad_addr = switchtec_ntb_peer_spad_addr,
500}; 571};
501 572
502static void switchtec_ntb_init_sndev(struct switchtec_ntb *sndev) 573static void switchtec_ntb_init_sndev(struct switchtec_ntb *sndev)