Skip to content

Commit e5327a6

Browse files
jbrun3tbjorn-helgaas
authored andcommitted
PCI: endpoint: pci-epf-vntb: Simplify ctrl/SPAD space allocation
When allocating the shared ctrl/SPAD space, epf_ntb_config_spad_bar_alloc() should not try to handle the size quirks for underlying BAR, whether it is fixed size or alignment. This is already handled by pci_epf_alloc_space(). Also, when handling the alignment, this allocates more space than necessary. For example, with a SPAD size of 1024B and a ctrl size of 308B, the space necessary is 1332B. If the alignment is 1MB, epf_ntb_config_spad_bar_alloc() tries to allocate 2MB where 1MB would have been more than enough. Drop the handling of the BAR size quirks and let pci_epf_alloc_space() handle that. Just make sure the 32bits SPAD register are aligned on 32bits. Signed-off-by: Jerome Brunet <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 793908d commit e5327a6

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

drivers/pci/endpoint/functions/pci-epf-vntb.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,9 @@ static void epf_ntb_config_spad_bar_free(struct epf_ntb *ntb)
408408
*/
409409
static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb)
410410
{
411-
size_t align;
412411
enum pci_barno barno;
413412
struct epf_ntb_ctrl *ctrl;
414413
u32 spad_size, ctrl_size;
415-
u64 size;
416414
struct pci_epf *epf = ntb->epf;
417415
struct device *dev = &epf->dev;
418416
u32 spad_count;
@@ -422,31 +420,13 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb)
422420
epf->func_no,
423421
epf->vfunc_no);
424422
barno = ntb->epf_ntb_bar[BAR_CONFIG];
425-
size = epc_features->bar[barno].fixed_size;
426-
align = epc_features->align;
427-
428-
if ((!IS_ALIGNED(size, align)))
429-
return -EINVAL;
430-
431423
spad_count = ntb->spad_count;
432424

433-
ctrl_size = sizeof(struct epf_ntb_ctrl);
425+
ctrl_size = ALIGN(sizeof(struct epf_ntb_ctrl), sizeof(u32));
434426
spad_size = 2 * spad_count * sizeof(u32);
435427

436-
if (!align) {
437-
ctrl_size = roundup_pow_of_two(ctrl_size);
438-
spad_size = roundup_pow_of_two(spad_size);
439-
} else {
440-
ctrl_size = ALIGN(ctrl_size, align);
441-
spad_size = ALIGN(spad_size, align);
442-
}
443-
444-
if (!size)
445-
size = ctrl_size + spad_size;
446-
else if (size < ctrl_size + spad_size)
447-
return -EINVAL;
448-
449-
base = pci_epf_alloc_space(epf, size, barno, epc_features, 0);
428+
base = pci_epf_alloc_space(epf, ctrl_size + spad_size,
429+
barno, epc_features, 0);
450430
if (!base) {
451431
dev_err(dev, "Config/Status/SPAD alloc region fail\n");
452432
return -ENOMEM;

0 commit comments

Comments
 (0)