Skip to content

Commit e75d5ae

Browse files
nxpfranklijonmason
authored andcommitted
NTB: epf: Allow more flexibility in the memory BAR map method
Support the below BAR configuration methods for epf NTB. BAR 0: config and scratchpad BAR 2: doorbell BAR 4: memory map windows Set difference BAR number information into struct ntb_epf_data. So difference VID/PID can choose different BAR configurations. There are difference BAR map method between epf NTB and epf vNTB Endpoint function. Signed-off-by: Frank Li <[email protected]> Signed-off-by: Jon Mason <[email protected]>
1 parent 4284c88 commit e75d5ae

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

drivers/ntb/hw/epf/ntb_hw_epf.c

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
#define NTB_EPF_MIN_DB_COUNT 3
4747
#define NTB_EPF_MAX_DB_COUNT 31
48-
#define NTB_EPF_MW_OFFSET 2
4948

5049
#define NTB_EPF_COMMAND_TIMEOUT 1000 /* 1 Sec */
5150

@@ -67,6 +66,7 @@ struct ntb_epf_dev {
6766
enum pci_barno ctrl_reg_bar;
6867
enum pci_barno peer_spad_reg_bar;
6968
enum pci_barno db_reg_bar;
69+
enum pci_barno mw_bar;
7070

7171
unsigned int mw_count;
7272
unsigned int spad_count;
@@ -92,6 +92,8 @@ struct ntb_epf_data {
9292
enum pci_barno peer_spad_reg_bar;
9393
/* BAR that contains Doorbell region and Memory window '1' */
9494
enum pci_barno db_reg_bar;
95+
/* BAR that contains memory windows*/
96+
enum pci_barno mw_bar;
9597
};
9698

9799
static int ntb_epf_send_command(struct ntb_epf_dev *ndev, u32 command,
@@ -411,7 +413,7 @@ static int ntb_epf_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx,
411413
return -EINVAL;
412414
}
413415

414-
bar = idx + NTB_EPF_MW_OFFSET;
416+
bar = idx + ndev->mw_bar;
415417

416418
mw_size = pci_resource_len(ntb->pdev, bar);
417419

@@ -453,7 +455,7 @@ static int ntb_epf_peer_mw_get_addr(struct ntb_dev *ntb, int idx,
453455
if (idx == 0)
454456
offset = readl(ndev->ctrl_reg + NTB_EPF_MW1_OFFSET);
455457

456-
bar = idx + NTB_EPF_MW_OFFSET;
458+
bar = idx + ndev->mw_bar;
457459

458460
if (base)
459461
*base = pci_resource_start(ndev->ntb.pdev, bar) + offset;
@@ -565,6 +567,7 @@ static int ntb_epf_init_pci(struct ntb_epf_dev *ndev,
565567
struct pci_dev *pdev)
566568
{
567569
struct device *dev = ndev->dev;
570+
size_t spad_sz, spad_off;
568571
int ret;
569572

570573
pci_set_drvdata(pdev, ndev);
@@ -599,10 +602,16 @@ static int ntb_epf_init_pci(struct ntb_epf_dev *ndev,
599602
goto err_dma_mask;
600603
}
601604

602-
ndev->peer_spad_reg = pci_iomap(pdev, ndev->peer_spad_reg_bar, 0);
603-
if (!ndev->peer_spad_reg) {
604-
ret = -EIO;
605-
goto err_dma_mask;
605+
if (ndev->peer_spad_reg_bar) {
606+
ndev->peer_spad_reg = pci_iomap(pdev, ndev->peer_spad_reg_bar, 0);
607+
if (!ndev->peer_spad_reg) {
608+
ret = -EIO;
609+
goto err_dma_mask;
610+
}
611+
} else {
612+
spad_sz = 4 * readl(ndev->ctrl_reg + NTB_EPF_SPAD_COUNT);
613+
spad_off = readl(ndev->ctrl_reg + NTB_EPF_SPAD_OFFSET);
614+
ndev->peer_spad_reg = ndev->ctrl_reg + spad_off + spad_sz;
606615
}
607616

608617
ndev->db_reg = pci_iomap(pdev, ndev->db_reg_bar, 0);
@@ -657,6 +666,7 @@ static int ntb_epf_pci_probe(struct pci_dev *pdev,
657666
enum pci_barno peer_spad_reg_bar = BAR_1;
658667
enum pci_barno ctrl_reg_bar = BAR_0;
659668
enum pci_barno db_reg_bar = BAR_2;
669+
enum pci_barno mw_bar = BAR_2;
660670
struct device *dev = &pdev->dev;
661671
struct ntb_epf_data *data;
662672
struct ntb_epf_dev *ndev;
@@ -671,17 +681,16 @@ static int ntb_epf_pci_probe(struct pci_dev *pdev,
671681

672682
data = (struct ntb_epf_data *)id->driver_data;
673683
if (data) {
674-
if (data->peer_spad_reg_bar)
675-
peer_spad_reg_bar = data->peer_spad_reg_bar;
676-
if (data->ctrl_reg_bar)
677-
ctrl_reg_bar = data->ctrl_reg_bar;
678-
if (data->db_reg_bar)
679-
db_reg_bar = data->db_reg_bar;
684+
peer_spad_reg_bar = data->peer_spad_reg_bar;
685+
ctrl_reg_bar = data->ctrl_reg_bar;
686+
db_reg_bar = data->db_reg_bar;
687+
mw_bar = data->mw_bar;
680688
}
681689

682690
ndev->peer_spad_reg_bar = peer_spad_reg_bar;
683691
ndev->ctrl_reg_bar = ctrl_reg_bar;
684692
ndev->db_reg_bar = db_reg_bar;
693+
ndev->mw_bar = mw_bar;
685694
ndev->dev = dev;
686695

687696
ntb_epf_init_struct(ndev, pdev);
@@ -729,6 +738,14 @@ static const struct ntb_epf_data j721e_data = {
729738
.ctrl_reg_bar = BAR_0,
730739
.peer_spad_reg_bar = BAR_1,
731740
.db_reg_bar = BAR_2,
741+
.mw_bar = BAR_2,
742+
};
743+
744+
static const struct ntb_epf_data mx8_data = {
745+
.ctrl_reg_bar = BAR_0,
746+
.peer_spad_reg_bar = BAR_0,
747+
.db_reg_bar = BAR_2,
748+
.mw_bar = BAR_4,
732749
};
733750

734751
static const struct pci_device_id ntb_epf_pci_tbl[] = {
@@ -737,6 +754,11 @@ static const struct pci_device_id ntb_epf_pci_tbl[] = {
737754
.class = PCI_CLASS_MEMORY_RAM << 8, .class_mask = 0xffff00,
738755
.driver_data = (kernel_ulong_t)&j721e_data,
739756
},
757+
{
758+
PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, 0x0809),
759+
.class = PCI_CLASS_MEMORY_RAM << 8, .class_mask = 0xffff00,
760+
.driver_data = (kernel_ulong_t)&mx8_data,
761+
},
740762
{ },
741763
};
742764

0 commit comments

Comments
 (0)