On Tue, Feb 02, 2021 at 05:56:34PM +0100, Gustavo Pimentel wrote: > Add Synopsys DesignWare xData IP driver. This driver enables/disables > the PCI traffic generator module pertain to the Synopsys DesignWare > prototype. > > Signed-off-by: Gustavo Pimentel <gustavo.pimentel@xxxxxxxxxxxx> > --- > drivers/misc/dw-xdata-pcie.c | 379 +++++++++++++++++++++++++++++++++++++++++++ You are adding sysfs entries but you do not have any Documentation/ABI/ entries for us to be able to properly review this code :( > +static ssize_t sysfs_write_show(struct kobject *kobj, > + struct kobj_attribute *attr, char *buf) > +{ > + struct device *dev = kobj2device(kobj); > + struct pci_dev *pdev = device2pci_dev(dev); > + struct dw_xdata *dw = pci_get_drvdata(pdev); > + u64 rate; > + > + dw_xdata_perf(dw, &rate, true); > + return sprintf(buf, "%llu MB/s\n", rate); sysfs_emit() > +} > + > +static ssize_t sysfs_write_store(struct kobject *kobj, > + struct kobj_attribute *attr, const char *buf, > + size_t count) > +{ > + struct device *dev = kobj2device(kobj); > + struct pci_dev *pdev = device2pci_dev(dev); > + struct dw_xdata *dw = pci_get_drvdata(pdev); > + > + pci_dbg(pdev, "xData: requested write transfer\n"); > + dw_xdata_start(dw, true); > + > + return count; > +} > + > +struct kobj_attribute sysfs_write_attr = __ATTR(write, 0644, > + sysfs_write_show, > + sysfs_write_store); __ATTR_RW() please > + > +static ssize_t sysfs_read_show(struct kobject *kobj, > + struct kobj_attribute *attr, char *buf) > +{ > + struct device *dev = kobj2device(kobj); > + struct pci_dev *pdev = device2pci_dev(dev); > + struct dw_xdata *dw = pci_get_drvdata(pdev); > + u64 rate; > + > + dw_xdata_perf(dw, &rate, false); > + return sprintf(buf, "%llu MB/s\n", rate); sysfs_emit() > +} > + > +static ssize_t sysfs_read_store(struct kobject *kobj, > + struct kobj_attribute *attr, const char *buf, > + size_t count) > +{ > + struct device *dev = kobj2device(kobj); > + struct pci_dev *pdev = device2pci_dev(dev); > + struct dw_xdata *dw = pci_get_drvdata(pdev); > + > + pci_dbg(pdev, "xData: requested read transfer\n"); > + dw_xdata_start(dw, false); > + > + return count; > +} > + > +struct kobj_attribute sysfs_read_attr = __ATTR(read, 0644, > + sysfs_read_show, > + sysfs_read_store); __ATTR_RW() > + > +static ssize_t sysfs_stop_store(struct kobject *kobj, > + struct kobj_attribute *attr, const char *buf, > + size_t count) > +{ > + struct device *dev = kobj2device(kobj); Wait, what??? Why are you creating "raw" kobjects here? This is a device, use device attributes. Use DEVICE_ATTR_RW() for all of the above. Who reviewed this thing??? > + struct pci_dev *pdev = device2pci_dev(dev); > + struct dw_xdata *dw = pci_get_drvdata(pdev); > + > + pci_dbg(pdev, "xData: requested stop any transfer\n"); > + dw_xdata_stop(dw); > + > + return count; > +} > + > +struct kobj_attribute sysfs_stop_attr = __ATTR(stop, 0644, > + NULL, > + sysfs_stop_store); > + > +static int dw_xdata_pcie_probe(struct pci_dev *pdev, > + const struct pci_device_id *pid) > +{ > + const struct dw_xdata_pcie_data *pdata = (void *)pid->driver_data; > + struct device *dev = &pdev->dev; > + struct dw_xdata *dw; > + u64 addr; > + int err; > + > + /* Enable PCI device */ > + err = pcim_enable_device(pdev); > + if (err) { > + pci_err(pdev, "enabling device failed\n"); > + return err; > + } > + > + /* Mapping PCI BAR regions */ > + err = pcim_iomap_regions(pdev, BIT(pdata->rg_bar), pci_name(pdev)); > + if (err) { > + pci_err(pdev, "xData BAR I/O remapping failed\n"); > + return err; > + } > + > + pci_set_master(pdev); > + > + /* Allocate memory */ > + dw = devm_kzalloc(&pdev->dev, sizeof(*dw), GFP_KERNEL); > + if (!dw) > + return -ENOMEM; > + > + /* Data structure initialization */ > + dw->rg_region.vaddr = pcim_iomap_table(pdev)[pdata->rg_bar]; > + if (!dw->rg_region.vaddr) > + return -ENOMEM; > + > + dw->rg_region.vaddr += pdata->rg_off; > + dw->rg_region.paddr = pdev->resource[pdata->rg_bar].start; > + dw->rg_region.paddr += pdata->rg_off; > + dw->rg_region.sz = pdata->rg_sz; > + > + dw->max_wr_len = pcie_get_mps(pdev); > + dw->max_wr_len >>= 2; > + > + dw->max_rd_len = pcie_get_readrq(pdev); > + dw->max_rd_len >>= 2; > + > + dw->pdev = pdev; > + > + writel(0x0, &(__dw_regs(dw)->RAM_addr)); > + writel(0x0, &(__dw_regs(dw)->RAM_port)); > + > + addr = dw->rg_region.paddr + DW_XDATA_EP_MEM_OFFSET; > + writel(lower_32_bits(addr), &(__dw_regs(dw)->addr_lsb)); > + writel(upper_32_bits(addr), &(__dw_regs(dw)->addr_msb)); > + pci_dbg(pdev, "xData: target address = 0x%.16llx\n", addr); > + > + pci_dbg(pdev, "xData: wr_len=%zu, rd_len=%zu\n", > + dw->max_wr_len * 4, dw->max_rd_len * 4); > + > + err = sysfs_create_file(&dev->kobj, &sysfs_write_attr.attr); > + if (err) > + return err; > + > + err = sysfs_create_file(&dev->kobj, &sysfs_read_attr.attr); > + if (err) > + return err; > + > + err = sysfs_create_file(&dev->kobj, &sysfs_stop_attr.attr); > + if (err) > + return err; By manually creating sysfs files, you just raced with userspace and lost horribly. Please never do that, use an attribute group and have the driver core automatically create/remove your files for you. Big hint, if you ever find yourself calling sysfs_* in a driver, you are doing something wrong. thanks, greg k-h