Skip to content

Commit 6619bf9

Browse files
lsgunthjonmason
authored andcommitted
NTB: switchtec_ntb: Implement doorbell registers
Pretty straightforward implementation of doorbell registers. The shift and mask were setup in an earlier patch and this just hooks up the appropriate portion of the IDB register as the local doorbells and the opposite portion of ODB as the peer doorbells. The DB mask is protected by a spinlock to avoid concurrent read-modify-write accesses. Signed-off-by: Logan Gunthorpe <[email protected]> Reviewed-by: Stephen Bates <[email protected]> Reviewed-by: Kurt Schwemmer <[email protected]> Acked-by: Allen Hubbe <[email protected]> Signed-off-by: Jon Mason <[email protected]>
1 parent 0ee28f2 commit 6619bf9

File tree

1 file changed

+85
-4
lines changed

1 file changed

+85
-4
lines changed

drivers/ntb/hw/mscc/ntb_hw_switchtec.c

+85-4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ struct switchtec_ntb {
9898
int db_shift;
9999
int db_peer_shift;
100100

101+
/* synchronize rmw access of db_mask and hw reg */
102+
spinlock_t db_mask_lock;
103+
101104
int nr_direct_mw;
102105
int nr_lut_mw;
103106
int direct_mw_to_bar[MAX_DIRECT_MW];
@@ -338,41 +341,115 @@ static int switchtec_ntb_link_disable(struct ntb_dev *ntb)
338341

339342
static u64 switchtec_ntb_db_valid_mask(struct ntb_dev *ntb)
340343
{
341-
return 0;
344+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
345+
346+
return sndev->db_valid_mask;
342347
}
343348

344349
static int switchtec_ntb_db_vector_count(struct ntb_dev *ntb)
345350
{
346-
return 0;
351+
return 1;
347352
}
348353

349354
static u64 switchtec_ntb_db_vector_mask(struct ntb_dev *ntb, int db_vector)
350355
{
351-
return 0;
356+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
357+
358+
if (db_vector < 0 || db_vector > 1)
359+
return 0;
360+
361+
return sndev->db_valid_mask;
352362
}
353363

354364
static u64 switchtec_ntb_db_read(struct ntb_dev *ntb)
355365
{
356-
return 0;
366+
u64 ret;
367+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
368+
369+
ret = ioread64(&sndev->mmio_self_dbmsg->idb) >> sndev->db_shift;
370+
371+
return ret & sndev->db_valid_mask;
357372
}
358373

359374
static int switchtec_ntb_db_clear(struct ntb_dev *ntb, u64 db_bits)
360375
{
376+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
377+
378+
iowrite64(db_bits << sndev->db_shift, &sndev->mmio_self_dbmsg->idb);
379+
361380
return 0;
362381
}
363382

364383
static int switchtec_ntb_db_set_mask(struct ntb_dev *ntb, u64 db_bits)
365384
{
385+
unsigned long irqflags;
386+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
387+
388+
if (db_bits & ~sndev->db_valid_mask)
389+
return -EINVAL;
390+
391+
spin_lock_irqsave(&sndev->db_mask_lock, irqflags);
392+
393+
sndev->db_mask |= db_bits << sndev->db_shift;
394+
iowrite64(~sndev->db_mask, &sndev->mmio_self_dbmsg->idb_mask);
395+
396+
spin_unlock_irqrestore(&sndev->db_mask_lock, irqflags);
397+
366398
return 0;
367399
}
368400

369401
static int switchtec_ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
370402
{
403+
unsigned long irqflags;
404+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
405+
406+
if (db_bits & ~sndev->db_valid_mask)
407+
return -EINVAL;
408+
409+
spin_lock_irqsave(&sndev->db_mask_lock, irqflags);
410+
411+
sndev->db_mask &= ~(db_bits << sndev->db_shift);
412+
iowrite64(~sndev->db_mask, &sndev->mmio_self_dbmsg->idb_mask);
413+
414+
spin_unlock_irqrestore(&sndev->db_mask_lock, irqflags);
415+
416+
return 0;
417+
}
418+
419+
static u64 switchtec_ntb_db_read_mask(struct ntb_dev *ntb)
420+
{
421+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
422+
423+
return (sndev->db_mask >> sndev->db_shift) & sndev->db_valid_mask;
424+
}
425+
426+
static int switchtec_ntb_peer_db_addr(struct ntb_dev *ntb,
427+
phys_addr_t *db_addr,
428+
resource_size_t *db_size)
429+
{
430+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
431+
unsigned long offset;
432+
433+
offset = (unsigned long)sndev->mmio_self_dbmsg->odb -
434+
(unsigned long)sndev->stdev->mmio;
435+
436+
offset += sndev->db_shift / 8;
437+
438+
if (db_addr)
439+
*db_addr = pci_resource_start(ntb->pdev, 0) + offset;
440+
if (db_size)
441+
*db_size = sizeof(u32);
442+
371443
return 0;
372444
}
373445

374446
static int switchtec_ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits)
375447
{
448+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
449+
450+
iowrite64(db_bits << sndev->db_peer_shift,
451+
&sndev->mmio_self_dbmsg->odb);
452+
376453
return 0;
377454
}
378455

@@ -413,6 +490,8 @@ static const struct ntb_dev_ops switchtec_ntb_ops = {
413490
.db_clear = switchtec_ntb_db_clear,
414491
.db_set_mask = switchtec_ntb_db_set_mask,
415492
.db_clear_mask = switchtec_ntb_db_clear_mask,
493+
.db_read_mask = switchtec_ntb_db_read_mask,
494+
.peer_db_addr = switchtec_ntb_peer_db_addr,
416495
.peer_db_set = switchtec_ntb_peer_db_set,
417496
.spad_count = switchtec_ntb_spad_count,
418497
.spad_read = switchtec_ntb_spad_read,
@@ -685,6 +764,8 @@ static irqreturn_t switchtec_ntb_doorbell_isr(int irq, void *dev)
685764

686765
dev_dbg(&sndev->stdev->dev, "doorbell\n");
687766

767+
ntb_db_event(&sndev->ntb, 0);
768+
688769
return IRQ_HANDLED;
689770
}
690771

0 commit comments

Comments
 (0)