Modularization of DFL private feature drivers
Subsystems (3)
Xu Yilun
maintainerv3 cover Modularization of DFL private feature drivers
This patchset makes it possible to develop independent driver modules for DFL private features. It also helps to leverage existing kernel drivers to enable some IP blocks in DFL.
Patch #1: An improvement of feature id definition. The feature id will be used
as the key field for dfl device/driver matching.
Patch #2: Release the dfl mmio regions after enumeration, so that private
feature drivers could request mmio region in their own drivers.
Patch #3: Introduce the dfl bus, then dfl devices could be supported by
independent dfl drivers.
Patch #4: An example of the dfl driver for N3000 nios private feature.
Main changes from v1:
- Add the new Patch #1, to improve the feature id definition.
- Change the dfl bus uevent format.
- Change the dfl device's sysfs name format.
- refactor dfl_dev_add()
- Add the Patch #4 as an example of the dfl driver.
- A lot of minor fixes for comments from Hao and Tom.
Main changes from v2:
- Add the doc for dfl-n3000-nios driver.
- Minor fixes for comments from Tom.
Xu Yilun (4):
fpga: dfl: change data type of feature id to u16
fpga: dfl: map feature mmio resources in their own feature drivers
fpga: dfl: create a dfl bus type to support DFL devices
fpga: dfl: add support for N3000 nios private feature
Documentation/ABI/testing/sysfs-bus-dfl | 15 + .../ABI/testing/sysfs-bus-dfl-devices-n3000-nios | 18 + Documentation/fpga/dfl-n3000-nios.rst | 39 ++ Documentation/fpga/index.rst | 1 + drivers/fpga/Kconfig | 12 + drivers/fpga/Makefile | 2 + drivers/fpga/dfl-fme-perf.c | 2 +- drivers/fpga/dfl-n3000-nios.c | 518 +++++++++++++++++++++ drivers/fpga/dfl-pci.c | 24 +- drivers/fpga/dfl.c | 464 +++++++++++++++--- drivers/fpga/dfl.h | 101 +++- 11 files changed, 1094 insertions(+), 102 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-dfl create mode 100644 Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios create mode 100644 Documentation/fpga/dfl-n3000-nios.rst create mode 100644 drivers/fpga/dfl-n3000-nios.c
Signature · 1 line
2.7.4
Xu Yilun
maintainerPATCH v3 1/4 fpga: dfl: change data type of feature id to u16
The feature id is stored in a 12 bit field in DFH. So a u16 variable is enough for feature id.
This patch changes all feature id related places to fit u16.
---
v3: no change.
--- drivers/fpga/dfl-fme-perf.c | 2 +- drivers/fpga/dfl.c | 29 +++++++++++++++-------------- drivers/fpga/dfl.h | 10 +++++----- 3 files changed, 21 insertions(+), 20 deletions(-)
drivers/fpga/dfl-fme-perf.c +1 -1
@@ -148,7 +148,7 @@ struct fme_perf_priv {struct device *dev;void __iomem *ioaddr;struct pmu pmu; -u64 id; +u16 id;u32 fab_users;u32 fab_port_id;
drivers/fpga/dfl.c +15 -14
@@ -58,7 +58,7 @@ static const char *dfl_pdata_key_strings[DFL_ID_MAX] = {*/ struct dfl_dev_info {const char *name; -u32 dfh_id; +u16 dfh_id;struct idr id;enum dfl_fpga_devt_type devt_type; };
@@ -134,7 +134,7 @@ static enum dfl_id_type feature_dev_id_type(struct platform_device *pdev)return DFL_ID_MAX ; } -static enum dfl_id_type dfh_id_to_type (u32 id) +static enum dfl_id_type dfh_id_to_type (u16 id) {int i;
@@ -454,7 +454,7 @@ struct build_feature_devs_info {* @nr_irqs: number of irqs of this sub feature. */ struct dfl_feature_info { -u64 fid; +u16 fid;struct resource mmio_res;void __iomem *ioaddr;struct list_head node;
@@ -649,7 +649,7 @@ static inline u32 feature_size(void __iomem *start)return ofst ? ofst :4096 ; } -static u64 feature_id (void __iomem *start) +static u16 feature_id (void __iomem *start) {u64 v =readq (start +DFH );u16 id =FIELD_GET (DFH_ID , v);
@@ -667,7 +667,7 @@ static u64 feature_id(void __iomem *start) }static int parse_feature_irqs (struct build_feature_devs_info *binfo, -resource_size_t ofst,u64 fid, +resource_size_t ofst,u16 fid,unsigned int *irq_base,unsigned int *nr_irqs) {void __iomem *base = binfo->ioaddr + ofst;
@@ -713,12 +713,12 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo,return 0 ; } -dev_dbg (binfo->dev,"feature: 0x%llx, irq_base: %u, nr_irqs: %u\n" , +dev_dbg (binfo->dev,"feature: 0x%x, irq_base: %u, nr_irqs: %u\n" , fid, ibase, inr);if (ibase + inr > binfo->nr_irqs) {dev_err (binfo->dev, -"Invalid interrupt number in feature 0x%llx\n" , fid); +"Invalid interrupt number in feature 0x%x\n" , fid);return -EINVAL ; }
@@ -726,7 +726,7 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo, virq = binfo->irq_table[ibase + i];if (virq <0 || virq >NR_IRQS ) {dev_err (binfo->dev, -"Invalid irq table entry for feature 0x%llx\n" , +"Invalid irq table entry for feature 0x%x\n" , fid);return -EINVAL ; }
@@ -748,7 +748,7 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo,static int create_feature_instance (struct build_feature_devs_info *binfo,struct dfl_fpga_enum_dfl *dfl,resource_size_t ofst, -resource_size_t size,u64 fid) +resource_size_t size,u16 fid) {unsigned int irq_base, nr_irqs;struct dfl_feature_info *finfo;
@@ -819,9 +819,10 @@ static int parse_feature_fiu(struct build_feature_devs_info *binfo,struct dfl_fpga_enum_dfl *dfl, resource_size_t ofst) { -u32 id, offset; -u64 v; int ret = 0; +u32 offset; +u16 id; +u64 v; v =readq (dfl->ioaddr + ofst +DFH ); id =FIELD_GET (DFH_ID , v);
@@ -855,8 +856,8 @@ static int parse_feature_private(struct build_feature_devs_info *binfo, resource_size_t ofst) {if (!binfo->feature_dev) { -dev_err (binfo->dev,"the private feature %llx does not belong to any AFU.\n" , - (unsigned long long )feature_id (dfl->ioaddr + ofst)); +dev_err (binfo->dev,"the private feature 0x%x does not belong to any AFU.\n" , +feature_id (dfl->ioaddr + ofst));return -EINVAL ; }
@@ -1424,7 +1425,7 @@ static int do_set_irq_trigger(struct dfl_feature *feature, unsigned int idx,return 0 ; feature->irq_ctx[idx].name = -kasprintf (GFP_KERNEL ,"fpga-irq[%u](%s-%llx)" , idx, +kasprintf (GFP_KERNEL ,"fpga-irq[%u](%s-%x)" , idx,dev_name (&pdev->dev), feature->id);if (!feature->irq_ctx[idx].name)return -ENOMEM ;
drivers/fpga/dfl.h +5 -5
@@ -197,7 +197,7 @@ int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id);* @id: unique dfl private feature id. */ struct dfl_feature_id { -u64 id; +u16 id; };/**
@@ -240,7 +240,7 @@ struct dfl_feature_irq_ctx {*/ struct dfl_feature {struct platform_device *dev; -u64 id; +u16 id;int resource_index;void __iomem *ioaddr;struct dfl_feature_irq_ctx *irq_ctx;
@@ -365,7 +365,7 @@ struct platform_device *dfl_fpga_inode_to_feature_dev(struct inode *inode) (feature) < (pdata)->features + (pdata)->num; (feature)++)static inline -struct dfl_feature *dfl_get_feature_by_id (struct device *dev,u64 id) +struct dfl_feature *dfl_get_feature_by_id (struct device *dev,u16 id) {struct dfl_feature_platform_data *pdata =dev_get_platdata (dev);struct dfl_feature *feature;
@@ -378,7 +378,7 @@ struct dfl_feature *dfl_get_feature_by_id(struct device *dev, u64 id) }static inline -void __iomem *dfl_get_feature_ioaddr_by_id (struct device *dev,u64 id) +void __iomem *dfl_get_feature_ioaddr_by_id (struct device *dev,u16 id) {struct dfl_feature *feature =dfl_get_feature_by_id (dev, id);
@@ -389,7 +389,7 @@ void __iomem *dfl_get_feature_ioaddr_by_id(struct device *dev, u64 id)return NULL ; } -static inline bool is_dfl_feature_present (struct device *dev,u64 id) +static inline bool is_dfl_feature_present (struct device *dev,u16 id) {return !!dfl_get_feature_ioaddr_by_id (dev, id); }
Signature · 1 line
2.7.4
RE: [PATCH v3 1/4] fpga: dfl: change data type of feature id to u16
Quoted 9 lines
Subject: [PATCH v3 1/4] fpga: dfl: change data type of feature id to u16
The feature id is stored in a 12 bit field in DFH. So a u16 variable is enough for feature id.
This patch changes all feature id related places to fit u16.
Signed-off-by Xu Yilun <[email protected]>Reviewed-by Tom Rix <[email protected]>
Thanks
Hao
Xu Yilun
maintainerPATCH v3 2/4 fpga: dfl: map feature mmio resources in their own feature drivers
In reply to Xu YilunThis patch makes preparation for modularization of DFL sub feature drivers.
Currently, if we need to support a new DFL sub feature, an entry should be added to fme/port_feature_drvs[] in dfl-fme/port-main.c. And we need to re-compile the whole DFL modules. That make the DFL drivers hard to be extended.
Another consideration is that DFL may contain some IP blocks which are already supported by kernel, most of them are supported by platform device drivers. We could create platform devices for these IP blocks and get them supported by these drivers.
An important issue is that platform device drivers usually requests mmio resources on probe. But now dfl mmio is mapped in dfl bus driver (e.g. dfl-pci) as a whole region. Then platform device drivers for sub features can't request their own mmio resources again. This is what the patch trying to resolve.
This patch changes the DFL enumeration. DFL bus driver will unmap mmio resources after first step enumeration and pass enumeration info to DFL framework. Then DFL framework will map the mmio resources again, do 2nd step enumeration, and also unmap the mmio resources. In this way, sub feature drivers could then request their own mmio resources as needed.
An exception is that mmio resource of FIU headers are still mapped in dfl bus driver. The FIU headers have some fundamental functions (sriov set, port enable/disable) needed for dfl bus devices and other sub features. They should not be unmapped as long as dfl bus device is alive.
---
v2: delete dfl_binfo_shift() cause no shift is possible for FIU parsing.
Only map bar0 for first phase enumeration in dfl-pci, we can find
all dfl mmio resource info in bar0.
Some minor fixes for comments from Hao & Tom.
v3: no change.
--- drivers/fpga/dfl-pci.c | 24 +++---- drivers/fpga/dfl.c | 185 ++++++++++++++++++++++++++++++++++--------------- drivers/fpga/dfl.h | 7 +- 3 files changed, 140 insertions(+), 76 deletions(-)
drivers/fpga/dfl-pci.c +11 -13
@@ -31,12 +31,12 @@ struct cci_drvdata {struct dfl_fpga_cdev *cdev;/* container device */ }; -static void __iomem *cci_pci_ioremap_bar (struct pci_dev *pcidev,int bar) +static void __iomem *cci_pci_ioremap_bar0 (struct pci_dev *pcidev) { -if (pcim_iomap_regions (pcidev,BIT (bar),DRV_NAME )) +if (pcim_iomap_regions (pcidev,BIT (0 ),DRV_NAME ))return NULL ; -return pcim_iomap_table (pcidev)[bar]; +return pcim_iomap_table (pcidev)[0 ]; }static int cci_pci_alloc_irq (struct pci_dev *pcidev)
@@ -156,8 +156,8 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev) goto irq_free_exit; } -/* start to find Device Feature List from Bar 0 */ - base =cci_pci_ioremap_bar (pcidev,0 ); +/* start to find Device Feature List in Bar 0 */ + base =cci_pci_ioremap_bar0 (pcidev);if (!base) { ret = -ENOMEM ; goto irq_free_exit;
@@ -172,7 +172,7 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev) start =pci_resource_start (pcidev,0 ); len =pci_resource_len (pcidev,0 ); -dfl_fpga_enum_info_add_dfl (info, start, len, base); +dfl_fpga_enum_info_add_dfl (info, start, len);/* * find more Device Feature Lists (e.g. Ports) per information
@@ -196,26 +196,24 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev)*/ bar =FIELD_GET (FME_PORT_OFST_BAR_ID , v); offset =FIELD_GET (FME_PORT_OFST_DFH_OFST , v); - base =cci_pci_ioremap_bar (pcidev, bar); -if (!base) -continue ; - start =pci_resource_start (pcidev, bar) + offset; len =pci_resource_len (pcidev, bar) - offset; -dfl_fpga_enum_info_add_dfl (info, start, len, - base + offset); +dfl_fpga_enum_info_add_dfl (info, start, len); } }else if (dfl_feature_is_port (base)) { start =pci_resource_start (pcidev,0 ); len =pci_resource_len (pcidev,0 ); -dfl_fpga_enum_info_add_dfl (info, start, len, base); +dfl_fpga_enum_info_add_dfl (info, start, len); }else { ret = -ENODEV ; goto irq_free_exit; } +/* release I/O mappings for next step enumeration */ +pcim_iounmap_regions (pcidev,BIT (0 )); +/* start enumeration with prepared enumeration information */ cdev =dfl_fpga_feature_devs_enumerate (info);if (IS_ERR (cdev)) {
drivers/fpga/dfl.c +128 -57
401 lines not on this page · raw message
drivers/fpga/dfl.h +1 -6
@@ -441,22 +441,17 @@ struct dfl_fpga_enum_info {* * @start: base address of this device feature list. * @len: size of this device feature list. -* @ioaddr: mapped base address of this device feature list. * @node: node in list of device feature lists. */ struct dfl_fpga_enum_dfl {resource_size_t start;resource_size_t len; - -void __iomem *ioaddr; -struct list_head node; };struct dfl_fpga_enum_info *dfl_fpga_enum_info_alloc (struct device *dev);int dfl_fpga_enum_info_add_dfl (struct dfl_fpga_enum_info *info, -resource_size_t start,resource_size_t len, -void __iomem *ioaddr); +resource_size_t start,resource_size_t len);int dfl_fpga_enum_info_add_irq (struct dfl_fpga_enum_info *info,unsigned int nr_irqs,int *irq_table);void dfl_fpga_enum_info_free (struct dfl_fpga_enum_info *info);
Signature · 1 line
2.7.4
RE: [PATCH v3 2/4] fpga: dfl: map feature mmio resources in their own feature drivers
Quoted 359 lines
Subject: [PATCH v3 2/4] fpga: dfl: map feature mmio resources in their own feature drivers
This patch makes preparation for modularization of DFL sub feature drivers.
Currently, if we need to support a new DFL sub feature, an entry should be added to fme/port_feature_drvs[] in
dfl-fme/port-main.c. And we need to re-compile the whole DFL modules. That make the DFL drivers hard to be extended.Another consideration is that DFL may contain some IP blocks which are already supported by kernel, most of them are supported by platform device drivers. We could create platform devices for these IP blocks and get them supported by these drivers.
An important issue is that platform device drivers usually requests mmio resources on probe. But now dfl mmio is mapped in dfl bus driver (e.g. dfl-pci) as a whole region. Then platform device drivers for sub features can't request their own mmio resources again. This is what the patch trying to resolve.
This patch changes the DFL enumeration. DFL bus driver will unmap mmio resources after first step enumeration and pass enumeration info to DFL framework. Then DFL framework will map the mmio resources again, do 2nd step enumeration, and also unmap the mmio resources. In this way, sub feature drivers could then request their own mmio resources as needed.
An exception is that mmio resource of FIU headers are still mapped in dfl bus driver. The FIU headers have some fundamental functions (sriov set, port enable/disable) needed for dfl bus devices and other sub features. They should not be unmapped as long as dfl bus device is alive.
Signed-off-by Xu Yilun <[email protected]>Signed-off-by Wu Hao <[email protected]>Signed-off-by Matthew Gerlach <[email protected]>Signed-off-by Russ Weight <[email protected]>Reviewed-by Tom Rix <[email protected]>---
v2: deletedfl_binfo_shift()cause no shift is possible for FIU parsing.
Only map bar0 for first phase enumeration in dfl-pci, we can find
all dfl mmio resource info in bar0.
Some minor fixes for comments from Hao & Tom.
v3: no change.--- drivers/fpga/dfl-pci.c | 24 +++---- drivers/fpga/dfl.c | 185 ++++++++++++++++++++++++++++++++++------------ --- drivers/fpga/dfl.h | 7 +- 3 files changed, 140 insertions(+), 76 deletions(-)drivers/fpga/dfl-pci.c +5
-5@@ -31,12 +31,12 @@ struct cci_drvdata {struct dfl_fpga_cdev *cdev;/* container device */ }; -static void __iomem *cci_pci_ioremap_bar (struct pci_dev *pcidev,int bar) +static void __iomem *cci_pci_ioremap_bar0 (struct pci_dev *pcidev) { -if (pcim_iomap_regions (pcidev,BIT (bar),DRV_NAME )) +if (pcim_iomap_regions (pcidev,BIT (0 ),DRV_NAME ))return NULL ; -return pcim_iomap_table (pcidev)[bar]; +return pcim_iomap_table (pcidev)[0 ]; }static int cci_pci_alloc_irq (struct pci_dev *pcidev)@@ -156,8 +156,8 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev) goto irq_free_exit; } -/* start to find Device Feature List from Bar 0 */ - base =cci_pci_ioremap_bar (pcidev,0 ); +/* start to find Device Feature List in Bar 0 */ + base =cci_pci_ioremap_bar0 (pcidev);if (!base) { ret = -ENOMEM ;drivers/fpga/dfl-pci.c +1
-1goto irq_free_exit;@@ -172,7 +172,7 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev) start =pci_resource_start (pcidev,0 ); len =pci_resource_len (pcidev,0 ); -dfl_fpga_enum_info_add_dfl (info, start, len, base); +dfl_fpga_enum_info_add_dfl (info, start, len);/* drivers/fpga/dfl-pci.c +5
-7* find more Device Feature Lists (e.g. Ports) per information @@ -196,26 +196,24 @@ static int cci_enumerate_feature_devs(structpci_dev *pcidev) */ bar =FIELD_GET (FME_PORT_OFST_BAR_ID , v); offset =FIELD_GET (FME_PORT_OFST_DFH_OFST , v); - base =cci_pci_ioremap_bar (pcidev, bar); -if (!base) -continue ; - start =pci_resource_start (pcidev, bar) + offset; len =pci_resource_len (pcidev, bar) - offset; -dfl_fpga_enum_info_add_dfl (info, start, len, - base + offset); +dfl_fpga_enum_info_add_dfl (info, start, len); } }else if (dfl_feature_is_port (base)) { start =pci_resource_start (pcidev,0 ); len =pci_resource_len (pcidev,0 ); -dfl_fpga_enum_info_add_dfl (info, start, len, base); +dfl_fpga_enum_info_add_dfl (info, start, len); }else { ret = -ENODEV ; goto irq_free_exit; } +/* release I/O mappings for next step enumeration */ +pcim_iounmap_regions (pcidev,BIT (0 )); +/* start enumeration with prepared enumeration information */ cdev =dfl_fpga_feature_devs_enumerate (info);drivers/fpga/dfl-pci.c +0
-0if (IS_ERR (cdev)) {drivers/fpga/dfl.c +2
-0@@ -250,6 +250,8 @@ int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) }EXPORT_SYMBOL_GPL (dfl_fpga_check_port_id); +#define is_header_feature (feature) ((feature)->id == FEATURE_ID_FIU_HEADER) +/** *
dfl_fpga_dev_feature_uinit- uinit for sub features of dfl feature device
* @pdev: feature device.drivers/fpga/dfl.c +14
-0@@ -273,8 +275,22 @@ static int dfl_feature_instance_init(structplatform_device *pdev, struct dfl_feature *feature, struct dfl_feature_driver *drv) { + void __iomem *base;int ret =0 ; +if (!is_header_feature (feature)) { + base =devm_platform_ioremap_resource (pdev, + feature->resource_index); +if (IS_ERR (base)) { +dev_err (&pdev->dev, +"ioremap failed for feature 0x%x!\n" , + feature->id); +return PTR_ERR (base); + } + + feature->ioaddr = base; + } +if (drv->ops->init) { ret = drv->ops->init (pdev, feature);drivers/fpga/dfl.c +3
-1if (ret)@@ -427,7 +443,9 @@ EXPORT_SYMBOL_GPL(dfl_fpga_dev_ops_unregister);* @irq_table: Linux IRQ numbers for all irqs, indexed by local irq index of * this device. * @feature_dev: current feature device. -* @ioaddr: header register region address of feature device in enumeration. +* @ioaddr: header register region address of current FIU in enumeration. +* @start: register resource start of current FIU. +* @len: max register resource length of current FIU. * @sub_features: a sub features linked list for feature device in enumeration.
* @feature_num: number of sub features for feature device in
enumeration.
*/drivers/fpga/dfl.c +3
-4@@ -439,6 +457,8 @@ struct build_feature_devs_info {struct platform_device *feature_dev;void __iomem *ioaddr; +resource_size_t start; +resource_size_t len;struct list_head sub_features;int feature_num; };@@ -484,10 +504,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)struct dfl_feature_platform_data *pdata;struct dfl_feature_info *finfo, *p;enum dfl_id_type type; -int ret, index =0 ; - -if (!fdev) -return 0 ; +int ret, index =0 , res_idx =0 ; type =feature_dev_id_type (fdev);drivers/fpga/dfl.c +18
-4if (WARN_ON_ONCE (type >=DFL_ID_MAX ))@@ -530,16 +547,30 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)/* fill features and resource information for feature dev */ list_for_each_entry_safe (finfo, p, &binfo->sub_features, node) { -struct dfl_feature *feature = &pdata->features[index]; +struct dfl_feature *feature = &pdata->features[index++];struct dfl_feature_irq_ctx *ctx;unsigned int i;/* save resource information for each feature */ feature->dev = fdev; feature->id = finfo->fid; - feature->resource_index = index; - feature->ioaddr = finfo->ioaddr; - fdev->resource[index++] = finfo->mmio_res; + +/* +* map header resource for dfl bus device. Don't add header +* resource to feature devices, or the resource tree will be +* disordered and cause warning on resource release +*/ +if (is_header_feature (feature)) { + feature->resource_index =-1 ; + feature->ioaddr = +devm_ioremap_resource (binfo->dev, + &finfo->mmio_res); +if (IS_ERR (feature->ioaddr)) +return PTR_ERR (feature->ioaddr); + }else { + feature->resource_index = res_idx; + fdev->resource[res_idx++] = finfo->mmio_res; + }if (finfo->nr_irqs) {drivers/fpga/dfl.c +1
-7ctx = devm_kcalloc(binfo->dev, finfo->nr_irqs,@@ -582,19 +613,13 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)static int build_info_create_dev (struct build_feature_devs_info *binfo, -enum dfl_id_type type,void __iomem *ioaddr) +enum dfl_id_type type) {struct platform_device *fdev; -int ret;if (type >=DFL_ID_MAX )return -EINVAL ; -/* we will create a new device, commit current device first */ - ret =build_info_commit_dev (binfo); -if (ret) -return ret; -/* * we use -ENODEV as the initialization indicator which indicates drivers/fpga/dfl.c +1
-1* whether the id need to be reclaimed @@ -605,7 +630,7 @@ build_info_create_dev(struct build_feature_devs_info *binfo, binfo->feature_dev = fdev; binfo->feature_num =0 ; - binfo->ioaddr = ioaddr; +INIT_LIST_HEAD (&binfo->sub_features);drivers/fpga/dfl.c +4
-5fdev->id =dfl_id_alloc (type, &fdev->dev);@@ -747,18 +772,17 @@ static int parse_feature_irqs(structbuild_feature_devs_info *binfo, */ static int create_feature_instance (struct build_feature_devs_info *binfo, -struct dfl_fpga_enum_dfl *dfl,resource_size_t ofst, -resource_size_t size,u16 fid) +resource_size_t ofst,resource_size_t size,u16 fid) {unsigned int irq_base, nr_irqs;struct dfl_feature_info *finfo;int ret;/* read feature size and id if inputs are invalid */ - size = size ? size :feature_size (dfl->ioaddr + ofst); - fid = fid ? fid :feature_id (dfl->ioaddr + ofst); + size = size ? size :feature_size (binfo->ioaddr + ofst); + fid = fid ? fid :feature_id (binfo->ioaddr + ofst); -if (dfl->len - ofst < size) +if (binfo->len - ofst < size)return -EINVAL ;drivers/fpga/dfl.c +1
-2ret =parse_feature_irqs (binfo, ofst, fid, &irq_base, &nr_irqs);@@ -770,12 +794,11 @@ create_feature_instance(struct build_feature_devs_info *binfo, return -ENOMEM ; finfo->fid = fid; - finfo->mmio_res.start = dfl->start + ofst; + finfo->mmio_res.start = binfo->start + ofst; finfo->mmio_res.end = finfo->mmio_res.start + size -1 ; finfo->mmio_res.flags =IORESOURCE_MEM ; finfo->irq_base = irq_base; finfo->nr_irqs = nr_irqs; - finfo->ioaddr = dfl->ioaddr + ofst;list_add_tail (&finfo->node, &binfo->sub_features);drivers/fpga/dfl.c +0
-1binfo->feature_num++;@@ -784,7 +807,6 @@ create_feature_instance(struct build_feature_devs_info *binfo, }static int parse_feature_port_afu (struct build_feature_devs_info *binfo, -struct dfl_fpga_enum_dfl *dfl,resource_size_t ofst) {drivers/fpga/dfl.c +5
-4u64 v =readq (binfo->ioaddr +PORT_HDR_CAP );@@ -792,21 +814,22 @@ static int parse_feature_port_afu(struct build_feature_devs_info *binfo,WARN_ON (!size); -return create_feature_instance (binfo, dfl, ofst, size, FEATURE_ID_AFU); +return create_feature_instance (binfo, ofst, size,FEATURE_ID_AFU ); } +#define is_feature_dev_detected (binfo) (!!(binfo)->feature_dev) +static int parse_feature_afu (struct build_feature_devs_info *binfo, -struct dfl_fpga_enum_dfl *dfl,resource_size_t ofst) { -if (!binfo->feature_dev) { +if (!is_feature_dev_detected (binfo)) { dev_err(binfo->dev, "this AFU does not belong to any FIU.\n");return -EINVAL ; }switch (feature_dev_id_type (binfo->feature_dev)) {case PORT_ID : -return parse_feature_port_afu (binfo, dfl, ofst); +return parse_feature_port_afu (binfo, ofst);drivers/fpga/dfl.c +0
-0default : dev_info(binfo->dev, "AFU belonging to FIU %s is notsupported yet.\n",
drivers/fpga/dfl.c +7
-0binfo->feature_dev->name);@@ -815,8 +838,40 @@ static int parse_feature_afu(structbuild_feature_devs_info *binfo, return 0; } +static int dfl_binfo_prepare (struct build_feature_devs_info *binfo, +resource_size_t start,resource_size_t len) +{ +struct device *dev = binfo->dev; +void __iomem *ioaddr; + +if (!devm_request_mem_region (dev, start, len,dev_name (dev))) {
drivers/fpga/dfl.c static int parse_feature_afu(struct · line 858
Quoted 10 lines
drivers/fpga/dfl.c +10
-0+dev_err (dev,"request region fail, start:%pa, len:%pa\n" , + &start, &len); +return -EBUSY ; + } + + ioaddr =devm_ioremap (dev, start, len); +if (!ioaddr) { +dev_err (dev,"ioremap region fail, start:%pa, len:%pa\n" , + &start, &len); +devm_release_mem_region (dev, start, len);
as it's devm_request_mem_region, do we still need to release it here?
Quoted 91 lines
drivers/fpga/dfl.c +16
-1+return -ENOMEM ; + } + + binfo->start = start; + binfo->len = len; + binfo->ioaddr = ioaddr; + +return 0 ; +} + +static void dfl_binfo_complete (struct build_feature_devs_info *binfo) +{ +devm_iounmap (binfo->dev, binfo->ioaddr); +devm_release_mem_region (binfo->dev, binfo->start, binfo->len); +} +static int parse_feature_fiu (struct build_feature_devs_info *binfo, -struct dfl_fpga_enum_dfl *dfl,resource_size_t ofst) {drivers/fpga/dfl.c +21
-10int ret =0 ;@@ -824,27 +879,39 @@ static int parse_feature_fiu(structbuild_feature_devs_info *binfo, u16 id;u64 v; - v =readq (dfl->ioaddr + ofst +DFH ); +if (is_feature_dev_detected (binfo)) { +dfl_binfo_complete (binfo); + + ret =build_info_commit_dev (binfo); +if (ret) +return ret; + + ret =dfl_binfo_prepare (binfo, binfo->start + ofst, + binfo->len - ofst); +if (ret) +return ret; + } + + v =readq (binfo->ioaddr +DFH ); id =FIELD_GET (DFH_ID , v);/* create platform device for dfl feature dev */ - ret =build_info_create_dev (binfo,dfh_id_to_type (id), - dfl->ioaddr + ofst); + ret =build_info_create_dev (binfo,dfh_id_to_type (id));if (ret)return ret; - ret =create_feature_instance (binfo, dfl, ofst,0 ,0 ); + ret =create_feature_instance (binfo,0 ,0 ,0 );if (ret)return ret;/* * find and parse FIU's child AFU via its NEXT_AFU register. * please note that only Port has valid NEXT_AFU pointer per spec. */ - v =readq (dfl->ioaddr + ofst +NEXT_AFU ); + v =readq (binfo->ioaddr +NEXT_AFU ); offset =FIELD_GET (NEXT_AFU_NEXT_DFH_OFST , v);if (offset) -return parse_feature_afu (binfo, dfl, ofst + offset); +return parse_feature_afu (binfo, offset);dev_dbg (binfo->dev,"No AFUs detected on FIU %d\n" , id);@@ -852,16 +919,15 @@ static int parse_feature_fiu(struct build_feature_devs_info *binfo, }static int parse_feature_private (struct build_feature_devs_info *binfo, -struct dfl_fpga_enum_dfl *dfl,resource_size_t ofst) { -if (!binfo->feature_dev) { +if (!is_feature_dev_detected (binfo)) { dev_err(binfo->dev, "the private feature 0x%x does not belong to any AFU.\n", -feature_id (dfl->ioaddr + ofst)); +feature_id (binfo->ioaddr + ofst));return -EINVAL ; } -return create_feature_instance (binfo, dfl, ofst,0 ,0 ); +return create_feature_instance (binfo, ofst,0 ,0 ); }/**
drivers/fpga/dfl.c static int parse_feature_private(struct · line 938
Quoted 4 lines
drivers/fpga/dfl.c +0
-0@@ -869,24 +935,24 @@ static int parse_feature_private(structbuild_feature_devs_info *binfo, * * @binfo: build feature devices information. * @dfl: device feature list to parse
Remove this line.
Other place looks good to me.
Thanks
Hao
Quoted 148 lines
drivers/fpga/dfl.c +6
-6-* @ofst: offset to feature header on this device feature list +* @ofst: offset to current FIU header */ static int parse_feature (struct build_feature_devs_info *binfo, -struct dfl_fpga_enum_dfl *dfl,resource_size_t ofst) +resource_size_t ofst) {u64 v;u32 type; - v =readq (dfl->ioaddr + ofst +DFH ); + v =readq (binfo->ioaddr + ofst +DFH ); type =FIELD_GET (DFH_TYPE , v);switch (type) {case DFH_TYPE_AFU : -return parse_feature_afu (binfo, dfl, ofst); +return parse_feature_afu (binfo, ofst);case DFH_TYPE_PRIVATE : -return parse_feature_private (binfo, dfl, ofst); +return parse_feature_private (binfo, ofst);case DFH_TYPE_FIU : -return parse_feature_fiu (binfo, dfl, ofst); +return parse_feature_fiu (binfo, ofst);default : dev_info(binfo->dev,drivers/fpga/dfl.c +6
-3"Feature Type %x is not supported.\n", type);@@ -896,14 +962,17 @@ static int parse_feature(struct build_feature_devs_info *binfo, }static int parse_feature_list (struct build_feature_devs_info *binfo, -struct dfl_fpga_enum_dfl *dfl) +resource_size_t start,resource_size_t len) { -void __iomem *start = dfl->ioaddr; -void __iomem *end = dfl->ioaddr + dfl->len; +resource_size_t end = start + len;int ret =0 ;u32 ofst =0 ;u64 v; + ret =dfl_binfo_prepare (binfo, start, len); +if (ret) +return ret; +/* walk through the device feature list via DFH's next DFH pointer. */ for (; start < end; start += ofst) {drivers/fpga/dfl.c +2
-2if (end - start <DFH_SIZE ) {@@ -911,11 +980,11 @@ static int parse_feature_list(struct build_feature_devs_info *binfo, return -EINVAL ; } - ret =parse_feature (binfo, dfl, start - dfl->ioaddr); + ret =parse_feature (binfo, start - binfo->start);if (ret)return ret; - v =readq (start +DFH ); + v =readq (binfo->ioaddr + start - binfo->start +DFH ); ofst =FIELD_GET (DFH_NEXT_HDR_OFST , v);drivers/fpga/dfl.c +6
-1/* stop parsing if EOL(End of List) is set or offset is 0 */ @@ -924,7 +993,12 @@ static int parse_feature_list(structbuild_feature_devs_info *binfo, }/* commit current feature device when reach the end of list */ -return build_info_commit_dev (binfo); +dfl_binfo_complete (binfo ); + +if (is_feature_dev_detected (binfo)) + ret =build_info_commit_dev (binfo); + +return ret; }struct
dfl_fpga_enum_info*dfl_fpga_enum_info_alloc(struct device *dev)drivers/fpga/dfl.c +0
-1@@ -977,7 +1051,6 @@ EXPORT_SYMBOL_GPL(dfl_fpga_enum_info_free);* @info: ptr to dfl_fpga_enum_info * @start: mmio resource address of the device feature list. * @len: mmio resource length of the device feature list. -* @ioaddr: mapped mmio resource address of the device feature list. * * One FPGA device may have one or more Device Feature Lists (DFLs), use this
* function to add information of each DFL to common data structure for
nextdrivers/fpga/dfl.c +2
-4@@ -986,8 +1059,7 @@ EXPORT_SYMBOL_GPL(dfl_fpga_enum_info_free);* Return: 0 on success, negative error code otherwise. */ int dfl_fpga_enum_info_add_dfl (struct dfl_fpga_enum_info *info, -resource_size_t start,resource_size_t len, -void __iomem *ioaddr) +resource_size_t start,resource_size_t len) {struct dfl_fpga_enum_dfl *dfl;@@ -997,7 +1069,6 @@ int dfl_fpga_enum_info_add_dfl(struct dfl_fpga_enum_info *info, dfl->start = start; dfl->len = len; - dfl->ioaddr = ioaddr;list_add_tail (&dfl->node, &info->dfls);@@ -1120,7 +1191,7 @@ dfl_fpga_feature_devs_enumerate(structdfl_fpga_enum_info *info) * Lists. */ list_for_each_entry (dfl, &info->dfls, node) { - ret =parse_feature_list (binfo, dfl); + ret =parse_feature_list (binfo, dfl->start, dfl->len);if (ret) {remove_feature_devs (cdev);drivers/fpga/dfl.c +0
-0build_info_free (binfo);drivers/fpga/dfl.h +1
-7@@ -441,22 +441,17 @@ struct dfl_fpga_enum_info {* * @start: base address of this device feature list. * @len: size of this device feature list. -* @ioaddr: mapped base address of this device feature list. * @node: node in list of device feature lists. */ struct dfl_fpga_enum_dfl {resource_size_t start;resource_size_t len; - -void __iomem *ioaddr; -struct list_head node; };struct dfl_fpga_enum_info *dfl_fpga_enum_info_alloc (struct device *dev);int dfl_fpga_enum_info_add_dfl (struct dfl_fpga_enum_info *info, -resource_size_t start,resource_size_t len, -void __iomem *ioaddr); +resource_size_t start,resource_size_t len);int dfl_fpga_enum_info_add_irq (struct dfl_fpga_enum_info *info,unsigned int nr_irqs,int *irq_table);void dfl_fpga_enum_info_free (struct dfl_fpga_enum_info *info); --2.7.4
Xu Yilun
maintainerRe: [PATCH v3 2/4] fpga: dfl: map feature mmio resources in their own feature drivers
Quoted 14 lines · Hao
Quoted 14 lines
Subject: [PATCH v3 2/4] fpga: dfl: map feature mmio resources in their own feature drivers
drivers/fpga/dfl.c +11
-0+static int dfl_binfo_prepare (struct build_feature_devs_info *binfo, +resource_size_t start,resource_size_t len) +{ +struct device *dev = binfo->dev; +void __iomem *ioaddr; + +if (!devm_request_mem_region (dev, start, len,dev_name (dev))) { +dev_err (dev,"request region fail, start:%pa, len:%pa\n" , +&start, &len); +return -EBUSY ; +}
Quoted 8 lines
drivers/fpga/dfl.c static int parse_feature_afu(struct build_feature_devs_info *binfo, · line 857
Quoted 6 lines
drivers/fpga/dfl.c +6
-0+ +ioaddr =devm_ioremap (dev, start, len); +if (!ioaddr) { +dev_err (dev,"ioremap region fail, start:%pa, len:%pa\n" , +&start, &len); +devm_release_mem_region (dev, start, len);as it's
devm_request_mem_region, do we still need to release it here?
Yes, I could delete it.
Quoted 7 lines
drivers/fpga/dfl.c static int parse_feature_private(struct · line 938
Quoted 5 lines
drivers/fpga/dfl.c +0
-0@@ -869,24 +935,24 @@ static int parse_feature_private(structbuild_feature_devs_info *binfo, * * @binfo: build feature devices information. * @dfl: device feature list to parseRemove this line.
Yes.
Thanks,
Yilun.
Quoted 5 lines
Other place looks good to me.
Thanks
Hao
Xu Yilun
maintainerPATCH v3 3/4 fpga: dfl: create a dfl bus type to support DFL devices
In reply to Xu YilunA new bus type "dfl" is introduced for private features which are not initialized by DFL feature drivers (dfl-fme & dfl-afu drivers). So these private features could be handled by separate driver modules.
DFL feature drivers (dfl-fme, dfl-port) will create DFL devices on enumeration. DFL drivers could be registered on this bus to match these DFL devices. They are matched by dfl type & feature_id.
---
v2: change the bus uevent format.
change the dfl device's sysfs name format.
refactor dfl_dev_add().
minor fixes for comments from Hao and Tom.
v3: no change.
--- Documentation/ABI/testing/sysfs-bus-dfl | 15 ++ drivers/fpga/dfl.c | 254 +++++++++++++++++++++++++++++++- drivers/fpga/dfl.h | 84 +++++++++++ 3 files changed, 345 insertions(+), 8 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-dfl
Documentation/ABI/testing/sysfs-bus-dfl new file +15 -0
@@ -0,0 +1,15 @@ +What: /sys/bus/dfl/devices/.../type +Date: July 2020 +KernelVersion: 5.9 +Contact: Xu Yilun <[email protected]> +Description: Read-only. It returns type of DFL FIU of the device. Now DFL + supports 2 FIU types, 0 for FME, 1 for PORT. + Format: 0x%x + +What: /sys/bus/dfl/devices/.../feature_id +Date: July 2020 +KernelVersion: 5.9 +Contact: Xu Yilun <[email protected]> +Description: Read-only. It returns feature identifier local to its DFL FIU + type. + Format: 0x%x
drivers/fpga/dfl.c +246 -8
299 lines not on this page · raw message
drivers/fpga/dfl.h +84 -0
88 lines not on this page · raw message
Signature · 1 line
2.7.4
RE: [PATCH v3 3/4] fpga: dfl: create a dfl bus type to support DFL devices
Quoted 35 lines
Subject: [PATCH v3 3/4] fpga: dfl: create a dfl bus type to support DFL devices
A new bus type "dfl" is introduced for private features which are not initialized by DFL feature drivers (dfl-fme & dfl-afu drivers). So these private features could be handled by separate driver modules.
DFL feature drivers (dfl-fme, dfl-port) will create DFL devices on enumeration. DFL drivers could be registered on this bus to match these DFL devices. They are matched by dfl type &
feature_id.Signed-off-by Xu Yilun <[email protected]>Signed-off-by Wu Hao <[email protected]>Signed-off-by Matthew Gerlach <[email protected]>Signed-off-by Russ Weight <[email protected]>Reviewed-by Tom Rix <[email protected]>---
v2: change the bus uevent format.
change the dfl device's sysfs name format.
refactordfl_dev_add().
minor fixes for comments from Hao and Tom.
v3: no change.--- Documentation/ABI/testing/sysfs-bus-dfl | 15 ++ drivers/fpga/dfl.c | 254 +++++++++++++++++++++++++++++++- drivers/fpga/dfl.h | 84 +++++++++++ 3 files changed, 345 insertions(+), 8 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-dflDocumentation/ABI/testing/sysfs-bus-dfl new file +0
-0
Documentation/ABI/testing/sysfs-bus-dfl line 1
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-dfl new file +1
-0@@ -0,0 +1,15 @@ +What: /sys/bus/dfl/devices/.../type
So it will be clear, that it's always dfl_dev.X/type here?
Documentation/ABI/testing/sysfs-bus-dfl line 3
Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-dfl new file +2
-0+Date: July 2020 +KernelVersion: 5.9
Same as the other patches.
Documentation/ABI/testing/sysfs-bus-dfl line 9
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-dfl new file +6
-0+Contact: Xu Yilun <[email protected]> +Description: Read-only. It returns type of DFL FIU of the device. Now DFL + supports 2 FIU types, 0 for FME, 1 for PORT. + Format: 0x%x + +What: /sys/bus/dfl/devices/.../feature_id
Same?
Documentation/ABI/testing/sysfs-bus-dfl line 11
Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-dfl new file +2
-0+Date: July 2020 +KernelVersion: 5.9
Ditto
Quoted 72 lines
Documentation/ABI/testing/sysfs-bus-dfl new file +4
-0+Contact: Xu Yilun <[email protected]> +Description: Read-only. It returns feature identifier local to its DFL FIU + type. + Format: 0x%xdrivers/fpga/dfl.c +45
-6@@ -30,12 +30,6 @@ static DEFINE_MUTEX(dfl_id_mutex);* index to dfl_chardevs table. If no chardev support just set devt_type * as one invalid index (DFL_FPGA_DEVT_MAX). */ -enum dfl_id_type { -FME_ID ,/* fme id allocation and mapping */ -PORT_ID ,/* port id allocation and mapping */ -DFL_ID_MAX , -}; -enum dfl_fpga_devt_type {DFL_FPGA_DEVT_FME ,DFL_FPGA_DEVT_PORT ,@@ -250,6 +244,236 @@ int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) }EXPORT_SYMBOL_GPL (dfl_fpga_check_port_id); +static DEFINE_IDA (dfl_device_ida); + +static const struct dfl_device_id * +dfl_match_one_device (const struct dfl_device_id *id,struct dfl_device *ddev) +{ +if (id->type == ddev->type && id->feature_id == ddev->feature_id) +return id; + +return NULL ; +} + +static int dfl_bus_match (struct device *dev,struct device_driver *drv) +{ +struct dfl_device *ddev =to_dfl_dev (dev); +struct dfl_driver *ddrv =to_dfl_drv (drv); +const struct dfl_device_id *id_entry = ddrv->id_table; + +if (id_entry) { +while (id_entry->feature_id) { +if (dfl_match_one_device (id_entry, ddev)) { + ddev->id_entry = id_entry; +return 1 ; + } + id_entry++; + } + } + +return 0 ; +} + +static int dfl_bus_probe (struct device *dev) +{ +struct dfl_device *ddev =to_dfl_dev (dev); +struct dfl_driver *ddrv =to_dfl_drv (dev->driver); + +return ddrv->probe (ddev); +} + +static int dfl_bus_remove (struct device *dev) +{ +struct dfl_device *ddev =to_dfl_dev (dev); +struct dfl_driver *ddrv =to_dfl_drv (dev->driver); + +if (ddrv->remove) + ddrv->remove (ddev);
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device · line 303
Quoted 10 lines
drivers/fpga/dfl.c +10
-0+ +return 0 ; +} + +static int dfl_bus_uevent (struct device *dev,struct kobj_uevent_env *env) +{ +struct dfl_device *ddev =to_dfl_dev (dev); + +return add_uevent_var (env,"MODALIAS=dfl:t%08Xf%04X" , + ddev->type, ddev->feature_id);
Then we only print 12bit of feature_id will be enough? should we make type shorter as well as feature id? And do you think if we should add a new field for dfl version?
Quoted 47 lines
drivers/fpga/dfl.c +46
-0+} + +/* show dfl info fields */ +#define dfl_info_attr (field, format_string) \ +static ssize_t \ +field##_show(struct device *dev, struct device_attribute *attr, \ + char *buf) \ +{ \ +struct dfl_device *ddev =to_dfl_dev (dev); \ + \ +return sprintf (buf, format_string, ddev->field); \ +} \ +static DEVICE_ATTR_RO(field) + +dfl_info_attr(type, "0x%x\n"); +dfl_info_attr(feature_id, "0x%x\n"); + +static struct attribute *dfl_dev_attrs[] = { + &dev_attr_type.attr, + &dev_attr_feature_id.attr, + NULL, +}; + +ATTRIBUTE_GROUPS(dfl_dev); + +static struct bus_type dfl_bus_type = { + .name = "dfl", + .match = dfl_bus_match, + .probe = dfl_bus_probe, + .remove = dfl_bus_remove, + .uevent = dfl_bus_uevent, + .dev_groups = dfl_dev_groups, +}; + +static void release_dfl_dev(struct device *dev) +{ + struct dfl_device *ddev = to_dfl_dev(dev); + + if (ddev->mmio_res.parent) + release_resource(&ddev->mmio_res); + + ida_simple_remove(&dfl_device_ida, ddev->id); + kfree(ddev->irqs); + kfree(ddev); +} +
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 357
Quoted 10 lines
drivers/fpga/dfl.c +10
-0+static struct dfl_device * +dfl_dev_add (struct dfl_feature_platform_data *pdata, +struct dfl_feature *feature) +{ +struct platform_device *pdev = pdata->dev; +struct resource *parent_res; +struct dfl_device *ddev; +int id, i, ret; + + ddev =kzalloc (sizeof (*ddev),GFP_KERNEL );
If we only consider add dfl device during initialization of FME/PORT device, then it should be able to use devm_xx version?
Quoted 40 lines
drivers/fpga/dfl.c +40
-0+if (!ddev) +return ERR_PTR (-ENOMEM ); + + id =ida_simple_get (&dfl_device_ida,0 ,0 ,GFP_KERNEL ); +if (id <0 ) { +dev_err (&pdev->dev,"unable to get id\n" ); +kfree (ddev); +return ERR_PTR (id); + } + +/* freeing resources by put_device() after device_initialize() */ +device_initialize (&ddev->dev); + ddev->dev.parent = &pdev->dev; + ddev->dev.bus = &dfl_bus_type; + ddev->dev.release = release_dfl_dev; + ddev->id = id; + ret =dev_set_name (&ddev->dev,"dfl_dev.%d" , id); +if (ret) + goto put_dev; + + ddev->type =feature_dev_id_type (pdev); + ddev->feature_id = feature->id; + ddev->cdev = pdata->dfl_cdev; + +/* add mmio resource */ + parent_res = &pdev->resource[feature->resource_index]; + ddev->mmio_res.flags =IORESOURCE_MEM ; + ddev->mmio_res.start = parent_res->start; + ddev->mmio_res.end = parent_res->end; + ddev->mmio_res.name =dev_name (&ddev->dev); + ret =insert_resource (parent_res, &ddev->mmio_res); +if (ret) { +dev_err (&pdev->dev,"%s failed to claim resource: %pR\n" , +dev_name (&ddev->dev), &ddev->mmio_res); + goto put_dev; + } + +/* then add irq resource */ +if (feature->nr_irqs) { + ddev->irqs = kcalloc(feature->nr_irqs,
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 407
Quoted 10 lines
drivers/fpga/dfl.c +10
-0+ sizeof(*ddev->irqs), GFP_KERNEL); +if (!ddev->irqs) { + ret = -ENOMEM ; + goto put_dev; + } + +for (i =0 ; i < feature->nr_irqs; i++) + ddev->irqs[i] = feature->irq_ctx[i].irq; + + ddev->num_irqs = feature->nr_irqs;
Do we need to consider using IORESOURCE_IRQ here as well?
Quoted 12 lines
drivers/fpga/dfl.c +12
-0+ } + + ret =device_add (&ddev->dev); +if (ret) + goto put_dev; + +dev_info (&pdev->dev,"add dfl_dev: %s\n" ,dev_name (&ddev->dev)); +return ddev; + +put_dev: +/* calls release_dfl_dev() which does the clean up */ +put_device (&ddev->dev);
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 429
Quoted 10 lines
drivers/fpga/dfl.c +10
-0+return ERR_PTR (ret); +} + +static void dfl_devs_uinit (struct dfl_feature_platform_data *pdata) +{ +struct dfl_device *ddev; +struct dfl_feature *feature; + +dfl_fpga_dev_for_each_feature (pdata, feature) { +if (!feature->ioaddr && feature->priv) {
Maybe we can add a new filed for ddev, then it will simplify the checking. How do you think?
Quoted 11 lines
drivers/fpga/dfl.c +10
-0+ ddev = feature->priv; +device_unregister (&ddev->dev); + feature->priv =NULL ; + } + } +} + +static int dfl_devs_init (struct platform_device *pdev) +{ + struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev-Quoted 1 line
dev);
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 444
Quoted 5 lines
drivers/fpga/dfl.c +5
-0+struct dfl_feature *feature; +struct dfl_device *ddev; + +dfl_fpga_dev_for_each_feature (pdata, feature) { +if (feature->ioaddr || feature->priv)
Why checks priv here?
Quoted 37 lines
drivers/fpga/dfl.c +32
-0+continue ; + + ddev =dfl_dev_add (pdata, feature); +if (IS_ERR (ddev)) { +dfl_devs_uinit (pdata); +return PTR_ERR (ddev); + } + + feature->priv = ddev; + } + +return 0 ; +} + +int __dfl_driver_register (struct dfl_driver *dfl_drv,struct module *owner) +{ +if (!dfl_drv || !dfl_drv->probe || !dfl_drv->id_table) +return -EINVAL ; + + dfl_drv->drv.owner = owner; + dfl_drv->drv.bus = &dfl_bus_type; + +return driver_register (&dfl_drv->drv); +} +EXPORT_SYMBOL (__dfl_driver_register); + +void dfl_driver_unregister (struct dfl_driver *dfl_drv) +{ +driver_unregister (&dfl_drv->drv); +} +EXPORT_SYMBOL (dfl_driver_unregister); +#define is_header_feature (feature) ((feature)->id ==
FEATURE_ID_FIU_HEADER)/**
drivers/fpga/dfl.c void dfl_fpga_dev_feature_uinit(struct · line 490
Quoted 7 lines
drivers/fpga/dfl.c +1
-1@@ -261,12 +485,15 @@ void dfl_fpga_dev_feature_uinit(struct platform_device *pdev)struct dfl_feature_platform_data *pdata =dev_get_platdata (&pdev- >dev);struct dfl_feature *feature; -dfl_fpga_dev_for_each_feature (pdata, feature) +dfl_devs_uinit (pdata);
Then you loop each feature twice, but they can be done in one loop ideally?
Quoted 62 lines
drivers/fpga/dfl.c +3
-0+ +dfl_fpga_dev_for_each_feature (pdata, feature) {if (feature->ops) {if (feature->ops->uinit) feature->ops->uinit (pdev, feature); feature->ops =NULL ; } + } }
EXPORT_SYMBOL_GPL(dfl_fpga_dev_feature_uinit);drivers/fpga/dfl.c +4
-0@@ -347,6 +574,10 @@ int dfl_fpga_dev_feature_init(struct platform_device *pdev, drv++; } + ret =dfl_devs_init (pdev); +if (ret) + goto exit; +return 0 ; exit:drivers/fpga/dfl.c +8
-1dfl_fpga_dev_feature_uinit (pdev);@@ -1284,11 +1515,17 @@ static int __init dfl_fpga_init(void) {int ret; + ret =bus_register (&dfl_bus_type); +if (ret) +return ret; +dfl_ids_init (); ret =dfl_chardev_init (); -if (ret) +if (ret) {dfl_ids_destroy (); +bus_unregister (&dfl_bus_type); + }return ret; }@@ -1626,6 +1863,7 @@ static void __exit dfl_fpga_exit(void) {dfl_chardev_uinit ();dfl_ids_destroy (); +bus_unregister (&dfl_bus_type); }module_init (dfl_fpga_init);drivers/fpga/dfl.h +3
-0@@ -514,4 +514,88 @@ long dfl_feature_ioctl_set_irq(structplatform_device *pdev, struct dfl_feature *feature, unsigned long arg); +/** +* enum dfl_id_type - define the DFL FIU types +*/
drivers/fpga/dfl.h long dfl_feature_ioctl_set_irq(struct · line 530
Quoted 10 lines
drivers/fpga/dfl.h +10
-0+enum dfl_id_type { +FME_ID , +PORT_ID , +DFL_ID_MAX , +}; + +/** +* struct dfl_device_id - dfl device identifier +* @type: Type of DFL FIU of the device. See enum dfl_id_type. +* @feature_id: 16 bits feature identifier local to its DFL FIU type.
Actually 12bits are used.
Quoted 30 lines
drivers/fpga/dfl.h +30
-0+* @driver_data: Driver specific data +*/ +struct dfl_device_id { +unsigned int type; +u16 feature_id; +unsigned long driver_data; +}; + +/** +* struct dfl_device - represent an dfl device on dfl bus +* +* @dev: Generic device interface. +* @id: id of the dfl device +* @type: Type of DFL FIU of the device. See enum dfl_id_type. +* @feature_id: 16 bits feature identifier local to its DFL FIU type. +* @mmio_res: MMIO resource of this dfl device. +* @irqs: List of Linux IRQ numbers of this dfl device. +* @num_irqs: number of IRQs supported by this dfl device. +* @cdev: pointer to DFL FPGA container device this dfl device belongs to. +* @id_entry: matched id entry in dfl driver's id table. +*/ +struct dfl_device { +struct device dev; +int id; +unsigned int type; +u16 feature_id; +struct resource mmio_res; +int *irqs; +unsigned int num_irqs; +struct dfl_fpga_cdev *cdev;
drivers/fpga/dfl.h long dfl_feature_ioctl_set_irq(struct platform_device *pdev, · line 569
Quoted 10 lines
drivers/fpga/dfl.h +10
-0+const struct dfl_device_id *id_entry; +}; + +/** +* struct dfl_driver - represent an dfl device driver +* +* @drv: Driver model structure. +* @id_table: Pointer to table of device IDs the driver is interested in. +* { } member terminated. +* @probe: Callback for device binding.
Please add "Mandatory callback" in the description.
Thanks
Hao
Quoted 34 lines
drivers/fpga/dfl.h +31
-0+* @remove: Callback for device unbinding. +*/ +struct dfl_driver { +struct device_driver drv; +const struct dfl_device_id *id_table; + +int (*probe)(struct dfl_device *dfl_dev); +void (*remove)(struct dfl_device *dfl_dev); +}; + +#define to_dfl_dev (d) container_of(d, struct dfl_device, dev) +#define to_dfl_drv (d) container_of(d, struct dfl_driver, drv) + +/* +* use a macro to avoid include chaining to get THIS_MODULE +*/ +#define dfl_driver_register (drv) \ + __dfl_driver_register(drv, THIS_MODULE) +int __dfl_driver_register (struct dfl_driver *dfl_drv,struct module *owner); +void dfl_driver_unregister (struct dfl_driver *dfl_drv); + +/* +* module_dfl_driver() - Helper macro for drivers that don't do +* anything special in module init/exit. This eliminates a lot of +* boilerplate. Each module may only use this macro once, and +* calling it replaces module_init() and module_exit() +*/ +#define module_dfl_driver (__dfl_driver) \ + module_driver(__dfl_driver, dfl_driver_register, \ + dfl_driver_unregister) +#endif /*
__FPGA_DFL_H*/
--
2.7.4
Xu Yilun
maintainerRe: [PATCH v3 3/4] fpga: dfl: create a dfl bus type to support DFL devices
Quoted 135 lines · Hao
Quoted 35 lines
Subject: [PATCH v3 3/4] fpga: dfl: create a dfl bus type to support DFL devices
A new bus type "dfl" is introduced for private features which are not initialized by DFL feature drivers (dfl-fme & dfl-afu drivers). So these private features could be handled by separate driver modules.
DFL feature drivers (dfl-fme, dfl-port) will create DFL devices on enumeration. DFL drivers could be registered on this bus to match these DFL devices. They are matched by dfl type &
feature_id.Signed-off-by Xu Yilun <[email protected]>Signed-off-by Wu Hao <[email protected]>Signed-off-by Matthew Gerlach <[email protected]>Signed-off-by Russ Weight <[email protected]>Reviewed-by Tom Rix <[email protected]>---
v2: change the bus uevent format.
change the dfl device's sysfs name format.
refactordfl_dev_add().
minor fixes for comments from Hao and Tom.
v3: no change.--- Documentation/ABI/testing/sysfs-bus-dfl | 15 ++ drivers/fpga/dfl.c | 254 +++++++++++++++++++++++++++++++- drivers/fpga/dfl.h | 84 +++++++++++ 3 files changed, 345 insertions(+), 8 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-dflDocumentation/ABI/testing/sysfs-bus-dfl new file +0
-0Documentation/ABI/testing/sysfs-bus-dfl line 1
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-dfl new file +1
-0@@ -0,0 +1,15 @@ +What:/sys/bus/dfl/devices/.../typeSo it will be clear, that it's always dfl_dev.X/type here?
Documentation/ABI/testing/sysfs-bus-dfl line 3
Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-dfl new file +2
-0+Date:July 2020 +KernelVersion:5.9Same as the other patches.
Documentation/ABI/testing/sysfs-bus-dfl
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-dfl new file +6
-0+Contact:Xu Yilun <[email protected]> +Description:Read-only. It returns type of DFL FIU of the device. Now DFL +supports 2 FIU types, 0 for FME, 1 for PORT. +Format: 0x%x + +What:/sys/bus/dfl/devices/.../feature_idSame?
Documentation/ABI/testing/sysfs-bus-dfl line 11
Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-dfl new file +2
-0+Date:July 2020 +KernelVersion:5.9Ditto
Quoted 77 lines
Documentation/ABI/testing/sysfs-bus-dfl new file +4
-0+Contact:Xu Yilun <[email protected]> +Description:Read-only. It returns feature identifier local to its DFL FIU +type. +Format: 0x%xdrivers/fpga/dfl.c +50
-6@@ -30,12 +30,6 @@ static DEFINE_MUTEX(dfl_id_mutex);* index to dfl_chardevs table. If no chardev support just set devt_type * as one invalid index (DFL_FPGA_DEVT_MAX). */ -enum dfl_id_type { -FME_ID ,/* fme id allocation and mapping */ -PORT_ID ,/* port id allocation and mapping */ -DFL_ID_MAX , -}; -enum dfl_fpga_devt_type {DFL_FPGA_DEVT_FME ,DFL_FPGA_DEVT_PORT ,@@ -250,6 +244,236 @@ int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) }EXPORT_SYMBOL_GPL (dfl_fpga_check_port_id); +static DEFINE_IDA (dfl_device_ida); + +static const struct dfl_device_id * +dfl_match_one_device (const struct dfl_device_id *id,struct dfl_device *ddev) +{ +if (id->type == ddev->type && id->feature_id == ddev->feature_id) +return id; + +return NULL ; +} + +static int dfl_bus_match (struct device *dev,struct device_driver *drv) +{ +struct dfl_device *ddev =to_dfl_dev (dev); +struct dfl_driver *ddrv =to_dfl_drv (drv); +const struct dfl_device_id *id_entry = ddrv->id_table; + +if (id_entry) { +while (id_entry->feature_id) { +if (dfl_match_one_device (id_entry, ddev)) { +ddev->id_entry = id_entry; +return 1 ; +} +id_entry++; +} +} + +return 0 ; +} + +static int dfl_bus_probe (struct device *dev) +{ +struct dfl_device *ddev =to_dfl_dev (dev); +struct dfl_driver *ddrv =to_dfl_drv (dev->driver); + +return ddrv->probe (ddev); +} + +static int dfl_bus_remove (struct device *dev) +{ +struct dfl_device *ddev =to_dfl_dev (dev); +struct dfl_driver *ddrv =to_dfl_drv (dev->driver); + +if (ddrv->remove) +ddrv->remove (ddev); + +return 0 ; +} + +static int dfl_bus_uevent (struct device *dev,struct kobj_uevent_env *env)
Quoted 8 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 301
Quoted 5 lines
drivers/fpga/dfl.c +5
-0+{ +struct dfl_device *ddev =to_dfl_dev (dev); + +return add_uevent_var (env,"MODALIAS=dfl:t%08Xf%04X" , + ddev->type, ddev->feature_id);Then we only print 12bit of
feature_idwill be enough? should we make type shorter as well as feature id?
I could envision that we need a struct
struct dfl_feature_id {
u16 id: 12;}
for it.
But it seems more complex and I didn't see the benifit. We don't have to worry about the invalid values cause we parse all the ddev->feature_id in dfl driver, and ensures it will not be larger than 12bit value.
Quoted 1 line
And do you think if we should add a new field for dfl version?
I think it may not be necessary now. If we support dfl v1 in future, we still could try to check uuid first, then fall back to type & feature_id.
Do you have any idea for the potential usage of dfl version.
Quoted 53 lines
Quoted 53 lines
drivers/fpga/dfl.c +51
-0+} + +/* show dfl info fields */ +#define dfl_info_attr (field, format_string)\ +static ssize_t\ +field##_show(struct device *dev, struct device_attribute *attr, \ + char *buf)\ +{\ +struct dfl_device *ddev =to_dfl_dev (dev);\ +\ +return sprintf (buf, format_string, ddev->field);\ +}\ +static DEVICE_ATTR_RO(field) + +dfl_info_attr(type, "0x%x\n"); +dfl_info_attr(feature_id, "0x%x\n"); + +static struct attribute *dfl_dev_attrs[] = { +&dev_attr_type.attr, +&dev_attr_feature_id.attr, +NULL, +}; + +ATTRIBUTE_GROUPS(dfl_dev); + +static struct bus_type dfl_bus_type = { +.name= "dfl", +.match= dfl_bus_match, +.probe= dfl_bus_probe, +.remove= dfl_bus_remove, +.uevent= dfl_bus_uevent, +.dev_groups= dfl_dev_groups, +}; + +static void release_dfl_dev(struct device *dev) +{ +struct dfl_device *ddev = to_dfl_dev(dev); + +if (ddev->mmio_res.parent) +release_resource(&ddev->mmio_res); + +ida_simple_remove(&dfl_device_ida, ddev->id); +kfree(ddev->irqs); +kfree(ddev); +} + +static struct dfl_device * +dfl_dev_add(struct dfl_feature_platform_data *pdata, + struct dfl_feature *feature) +{ +struct platform_device *pdev = pdata->dev;
Quoted 8 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 357
Quoted 5 lines
drivers/fpga/dfl.c +5
-0+struct resource *parent_res; +struct dfl_device *ddev; +int id, i, ret; + +ddev =kzalloc (sizeof (*ddev),GFP_KERNEL );If we only consider add dfl device during initialization of FME/PORT device, then it should be able to use
devm_xxversion?
I think we may keep the flexibility that the fme/port device could try to remove a dfl_device without exiting itself.
Quoted 45 lines
Quoted 45 lines
drivers/fpga/dfl.c +44
-0+if (!ddev) +return ERR_PTR (-ENOMEM ); + +id =ida_simple_get (&dfl_device_ida,0 ,0 ,GFP_KERNEL ); +if (id <0 ) { +dev_err (&pdev->dev,"unable to get id\n" ); +kfree (ddev); +return ERR_PTR (id); +} + +/* freeing resources by put_device() after device_initialize() */ +device_initialize (&ddev->dev); +ddev->dev.parent = &pdev->dev; +ddev->dev.bus = &dfl_bus_type; +ddev->dev.release = release_dfl_dev; +ddev->id = id; +ret =dev_set_name (&ddev->dev,"dfl_dev.%d" , id); +if (ret) +goto put_dev; + +ddev->type =feature_dev_id_type (pdev); +ddev->feature_id = feature->id; +ddev->cdev = pdata->dfl_cdev; + +/* add mmio resource */ +parent_res = &pdev->resource[feature->resource_index]; +ddev->mmio_res.flags =IORESOURCE_MEM ; +ddev->mmio_res.start = parent_res->start; +ddev->mmio_res.end = parent_res->end; +ddev->mmio_res.name =dev_name (&ddev->dev); +ret =insert_resource (parent_res, &ddev->mmio_res); +if (ret) { +dev_err (&pdev->dev,"%s failed to claim resource: %pR\n" , +dev_name (&ddev->dev), &ddev->mmio_res); +goto put_dev; +} + +/* then add irq resource */ +if (feature->nr_irqs) { +ddev->irqs =kcalloc (feature->nr_irqs, +sizeof (*ddev->irqs),GFP_KERNEL ); +if (!ddev->irqs) { +ret = -ENOMEM ; +goto put_dev;
Quoted 8 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 407
Quoted 6 lines
drivers/fpga/dfl.c +6
-0+} + +for (i =0 ; i < feature->nr_irqs; i++) +ddev->irqs[i] = feature->irq_ctx[i].irq; + +ddev->num_irqs = feature->nr_irqs;Do we need to consider using
IORESOURCE_IRQhere as well?
The helper functions for IORESOURCE_IRQ are all for platform_devices, We need to define a set of functions similar to them, I think current implementation is simpler, for dfl bus and drivers.
Quoted 18 lines
Quoted 18 lines
drivers/fpga/dfl.c +17
-0+} + +ret =device_add (&ddev->dev); +if (ret) +goto put_dev; + +dev_info (&pdev->dev,"add dfl_dev: %s\n" ,dev_name (&ddev->dev)); +return ddev; + +put_dev: +/* calls release_dfl_dev() which does the clean up */ +put_device (&ddev->dev); +return ERR_PTR (ret); +} + +static void dfl_devs_uinit (struct dfl_feature_platform_data *pdata) +{
Quoted 8 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 429
Quoted 5 lines
drivers/fpga/dfl.c +5
-0+struct dfl_device *ddev; +struct dfl_feature *feature; + +dfl_fpga_dev_for_each_feature(pdata, feature) { +if (!feature->ioaddr && feature->priv) {Maybe we can add a new filed for ddev, then it will simplify the checking. How do you think?
I think yes. I could do that.
Quoted 11 lines
Quoted 11 lines
drivers/fpga/dfl.c +10
-0+ddev = feature->priv; +device_unregister (&ddev->dev); +feature->priv =NULL ; +} +} +} + +static int dfl_devs_init (struct platform_device *pdev) +{ +struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev-
Quoted 8 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 444
Quoted 6 lines
Quoted 1 line
dev);
drivers/fpga/dfl.c +5
-0+struct dfl_feature *feature; +struct dfl_device *ddev; + +dfl_fpga_dev_for_each_feature(pdata, feature) { +if (feature->ioaddr || feature->priv)Why checks priv here?
I want to make sure the dfl_device is not already created.
Quoted 40 lines
Quoted 40 lines
drivers/fpga/dfl.c +32
-0+continue ; + +ddev =dfl_dev_add (pdata, feature); +if (IS_ERR (ddev)) { +dfl_devs_uinit (pdata); +return PTR_ERR (ddev); +} + +feature->priv = ddev; +} + +return 0 ; +} + +int __dfl_driver_register (struct dfl_driver *dfl_drv,struct module *owner) +{ +if (!dfl_drv || !dfl_drv->probe || !dfl_drv->id_table) +return -EINVAL ; + +dfl_drv->drv.owner = owner; +dfl_drv->drv.bus = &dfl_bus_type; + +return driver_register (&dfl_drv->drv); +} +EXPORT_SYMBOL (__dfl_driver_register); + +void dfl_driver_unregister (struct dfl_driver *dfl_drv) +{ +driver_unregister (&dfl_drv->drv); +} +EXPORT_SYMBOL (dfl_driver_unregister); +#define is_header_feature (feature) ((feature)->id ==
FEATURE_ID_FIU_HEADER)/**
drivers/fpga/dfl.c +0
-0@@ -261,12 +485,15 @@ void dfl_fpga_dev_feature_uinit(struct platform_device *pdev) struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev-
Quoted 7 lines
drivers/fpga/dfl.c void dfl_fpga_dev_feature_uinit(struct platform_device *pdev) · line 488
Quoted 5 lines
drivers/fpga/dfl.c +1
-1>dev);struct dfl_feature *feature; -dfl_fpga_dev_for_each_feature (pdata, feature) +dfl_devs_uinit (pdata);Then you loop each feature twice, but they can be done in one loop ideally?
Yes. But I'd like to remove the dfl_devices first, then the fme/port owned features. Cause the fme/port is the parent, I don't want them to be partially disfunctional before the children are removed.
Quoted 60 lines
Quoted 60 lines
drivers/fpga/dfl.c +3
-0+ +dfl_fpga_dev_for_each_feature(pdata, feature) {if (feature->ops) {if (feature->ops->uinit) feature->ops->uinit (pdev, feature); feature->ops =NULL ; } +} }
EXPORT_SYMBOL_GPL(dfl_fpga_dev_feature_uinit);drivers/fpga/dfl.c +4
-0@@ -347,6 +574,10 @@ int dfl_fpga_dev_feature_init(struct platform_device *pdev, drv++; } +ret =dfl_devs_init (pdev); +if (ret) +goto exit; +return 0 ; exit:
dfl_fpga_dev_feature_uinit(pdev);drivers/fpga/dfl.c +8
-1@@ -1284,11 +1515,17 @@ static int __init dfl_fpga_init(void) {int ret; +ret =bus_register (&dfl_bus_type); +if (ret) +return ret; +dfl_ids_init (); ret =dfl_chardev_init (); -if (ret) +if (ret) {dfl_ids_destroy (); +bus_unregister (&dfl_bus_type); +}return ret; }@@ -1626,6 +1863,7 @@ static void __exit dfl_fpga_exit(void) {dfl_chardev_uinit ();dfl_ids_destroy (); +bus_unregister (&dfl_bus_type); }module_init (dfl_fpga_init);drivers/fpga/dfl.h +0
-0@@ -514,4 +514,88 @@ long dfl_feature_ioctl_set_irq(structplatform_device *pdev, struct dfl_feature *feature, unsigned long arg);
Quoted 15 lines
drivers/fpga/dfl.h long dfl_feature_ioctl_set_irq(struct platform_device *pdev, · line 529
Quoted 13 lines
drivers/fpga/dfl.h +13
-0+/** +* enum dfl_id_type - define the DFL FIU types +*/ +enum dfl_id_type { +FME_ID , +PORT_ID , +DFL_ID_MAX , +}; + +/** +* struct dfl_device_id - dfl device identifier +* @type: Type of DFL FIU of the device. See enum dfl_id_type. +* @feature_id: 16 bits feature identifier local to its DFL FIU type. Actually 12bits are used.
I could add the comments.
Quoted 35 lines
Quoted 35 lines
drivers/fpga/dfl.h +34
-0+* @driver_data: Driver specific data +*/ +struct dfl_device_id { +unsigned int type; +u16 feature_id; +unsigned long driver_data; +}; + +/** +* struct dfl_device - represent an dfl device on dfl bus +* +* @dev: Generic device interface. +* @id: id of the dfl device +* @type: Type of DFL FIU of the device. See enum dfl_id_type. +* @feature_id: 16 bits feature identifier local to its DFL FIU type. +* @mmio_res: MMIO resource of this dfl device. +* @irqs: List of Linux IRQ numbers of this dfl device. +* @num_irqs: number of IRQs supported by this dfl device. +* @cdev: pointer to DFL FPGA container device this dfl device belongs to. +* @id_entry: matched id entry in dfl driver's id table. +*/ +struct dfl_device { +struct device dev; +int id; +unsigned int type; +u16 feature_id; +struct resource mmio_res; +int *irqs; +unsigned int num_irqs; +struct dfl_fpga_cdev *cdev; +const struct dfl_device_id *id_entry; +}; + +/**
Quoted 8 lines
drivers/fpga/dfl.h long dfl_feature_ioctl_set_irq(struct platform_device *pdev, · line 569
Quoted 6 lines
drivers/fpga/dfl.h +6
-0+* struct dfl_driver - represent an dfl device driver +* +* @drv: Driver model structure. +* @id_table: Pointer to table of device IDs the driver is interested in. +* { } member terminated. +* @probe: Callback for device binding. Please add "Mandatory callback" in the description.
Yes.
Quoted 38 lines
Thanks
HaoQuoted 34 lines
drivers/fpga/dfl.h +31
-0+* @remove: Callback for device unbinding. +*/ +struct dfl_driver { +struct device_driver drv; +const struct dfl_device_id *id_table; + +int (*probe)(struct dfl_device *dfl_dev); +void (*remove)(struct dfl_device *dfl_dev); +}; + +#define to_dfl_dev (d) container_of(d, struct dfl_device, dev) +#define to_dfl_drv (d) container_of(d, struct dfl_driver, drv) + +/* +* use a macro to avoid include chaining to get THIS_MODULE +*/ +#define dfl_driver_register (drv) \ +__dfl_driver_register(drv, THIS_MODULE) +int __dfl_driver_register (struct dfl_driver *dfl_drv,struct module *owner); +void dfl_driver_unregister (struct dfl_driver *dfl_drv); + +/* +* module_dfl_driver() - Helper macro for drivers that don't do +* anything special in module init/exit. This eliminates a lot of +* boilerplate. Each module may only use this macro once, and +* calling it replaces module_init() and module_exit() +*/ +#define module_dfl_driver (__dfl_driver) \ +module_driver(__dfl_driver, dfl_driver_register, \ + dfl_driver_unregister) +#endif /*
__FPGA_DFL_H*/
--
2.7.4
RE: [PATCH v3 3/4] fpga: dfl: create a dfl bus type to support DFL devices
Quoted 15 lines
Quoted 1 line
Quoted 1 line
+static int dfl_bus_uevent(struct device *dev, struct
kobj_uevent_env*env)
Quoted 8 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 301
Quoted 5 lines
drivers/fpga/dfl.c +5
-0+{ +struct dfl_device *ddev =to_dfl_dev (dev); + +return add_uevent_var (env,"MODALIAS=dfl:t%08Xf%04X" , + ddev->type, ddev->feature_id);Then we only print 12bit of
feature_idwill be enough? should we make type shorter as well as feature id?I could envision that we need a struct
struct dfl_feature_id { u16 id: 12;
Quoted 7 lines
}
for it.
But it seems more complex and I didn't see the benifit. We don't have to worry about the invalid values cause we parse all the
ddev->feature_idin dfl driver, and ensures it will not be larger than 12bit value.
Ideally type is only 4bits per spec, but looks like it's adding more zero before the type value, and also the feature id. This may not be a real problem, but may look a little wired, isn't it?
Quoted 6 lines
Quoted 2 lines
And do you think if we should add a new field for dfl version?
I think it may not be necessary now. If we support dfl v1 in future, we still could try to check uuid first, then fall back to type &
feature_id.
I think it's all about the uevent and it's user, and for users, they may have to deal with different versions, right? As you mentioned, if the event will be different format for v1 and it's not compatible with v0, anyway we need the version sooner or later, is my understanding correct?
Quoted 20 lines
Do you have any idea for the potential usage of dfl version.
Quoted 7 lines
Quoted 7 lines
drivers/fpga/dfl.c +7
-0+/* then add irq resource */ +if (feature->nr_irqs) { +ddev->irqs =kcalloc (feature->nr_irqs, +sizeof (*ddev->irqs),GFP_KERNEL ); +if (!ddev->irqs) { +ret = -ENOMEM ; +goto put_dev;Quoted 8 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 407
Quoted 6 lines
drivers/fpga/dfl.c +6
-0+} + +for (i =0 ; i < feature->nr_irqs; i++) +ddev->irqs[i] = feature->irq_ctx[i].irq; + +ddev->num_irqs = feature->nr_irqs;Do we need to consider using
IORESOURCE_IRQhere as well?
Quoted 3 lines
The helper functions for
IORESOURCE_IRQare all forplatform_devices, We need to define a set of functions similar to them, I think current implementation is simpler, for dfl bus and drivers.
If some case that it's going to reuse some platform device driver, then dfl_device driver will create platform device, it has to pass the mmio and irq resources to platform device driver, how you plan to do that?
Quoted 12 lines
Quoted 11 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 444
Quoted 9 lines
drivers/fpga/dfl.c +3
-0+static int dfl_devs_init (struct platform_device *pdev) +{ +struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev-Quoted 1 line
dev);
drivers/fpga/dfl.c +5
-0+struct dfl_feature *feature; +struct dfl_device *ddev; + +dfl_fpga_dev_for_each_feature(pdata, feature) { +if (feature->ioaddr || feature->priv)Why checks priv here?
Quoted 1 line
I want to make sure the
dfl_deviceis not already created.
Is that a valid case that we expected? or sounds like error code needs to be returned?
Thanks
Hao
Xu Yilun
maintainerRe: [PATCH v3 3/4] fpga: dfl: create a dfl bus type to support DFL devices
Quoted 19 lines · Hao
Quoted 19 lines
Quoted 1 line
Quoted 1 line
+static int dfl_bus_uevent(struct device *dev, struct
kobj_uevent_env*env)
Quoted 8 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 301
Quoted 5 lines
drivers/fpga/dfl.c +5
-0+{ +struct dfl_device *ddev =to_dfl_dev (dev); + +return add_uevent_var (env,"MODALIAS=dfl:t%08Xf%04X" , + ddev->type, ddev->feature_id);Then we only print 12bit of
feature_idwill be enough? should we make type shorter as well as feature id?I could envision that we need a struct
struct
dfl_feature_id{
u16 id: 12;
}for it.
Quoted 7 lines
Quoted 3 lines
But it seems more complex and I didn't see the benifit. We don't have to worry about the invalid values cause we parse all the
ddev->feature_idin dfl driver, and ensures it will not be larger than 12bit value.Ideally type is only 4bits per spec, but looks like it's adding more zero before the type value, and also the feature id. This may not be a real problem, but may look a little wired, isn't it?
OK, I could change the print.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
And do you think if we should add a new field for dfl version?
Quoted 8 lines
Quoted 3 lines
I think it may not be necessary now. If we support dfl v1 in future, we still could try to check uuid first, then fall back to type &
feature_id.I think it's all about the uevent and it's user, and for users, they may have to deal with different versions, right? As you mentioned, if the event will be different format for v1 and it's not compatible with v0, anyway we need the version sooner or later, is my understanding correct?
The version is not needed for uevent. The different formats of uevents explain themselves (dfl v0 or dfl v1), is it?
If we add the dfl version in uevent then we should also add the version in struct dfl_device_id, and all dfl driver should fill the version info in its id_table. But actually that's redundent work to driver developer.
The version in struct dfl_device may simplify the internal code on how to format the uevent. But considering the only extension of dflv1 I think checking the null uuid is also simply enough.
Quoted 21 lines
Quoted 21 lines
Do you have any idea for the potential usage of dfl version.
Quoted 15 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 407
Quoted 13 lines
drivers/fpga/dfl.c +13
-0+/* then add irq resource */ +if (feature->nr_irqs) { +ddev->irqs =kcalloc (feature->nr_irqs, +sizeof (*ddev->irqs),GFP_KERNEL ); +if (!ddev->irqs) { +ret = -ENOMEM ; +goto put_dev; +} + +for (i =0 ; i < feature->nr_irqs; i++) +ddev->irqs[i] = feature->irq_ctx[i].irq; + +ddev->num_irqs = feature->nr_irqs;Do we need to consider using
IORESOURCE_IRQhere as well?
Quoted 7 lines
Quoted 3 lines
The helper functions for
IORESOURCE_IRQare all forplatform_devices, We need to define a set of functions similar to them, I think current implementation is simpler, for dfl bus and drivers.If some case that it's going to reuse some platform device driver, then
dfl_devicedriver will create platform device, it has to pass the mmio and irq resources to platform device driver, how you plan to do that?
I think even we create struct resource array for dfl_devices, the dfl driver still has to create and fill its pdev resource as needed. There is little chance the driver could just memcpy them. So the dfl driver could fill the irq resources of pdev according to ddev->irqs & num_irqs.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
drivers/fpga/dfl.c int dfl_fpga_check_port_id(struct platform_device *pdev, void *pport_id) · line 444
Quoted 10 lines
drivers/fpga/dfl.c +3
-0+static int dfl_devs_init (struct platform_device *pdev) +{ +struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev-Quoted 1 line
dev);
drivers/fpga/dfl.c +5
-0+struct dfl_feature *feature; +struct dfl_device *ddev; + +dfl_fpga_dev_for_each_feature(pdata, feature) { +if (feature->ioaddr || feature->priv)Why checks priv here?
Quoted 4 lines
Quoted 1 line
I want to make sure the
dfl_deviceis not already created.Is that a valid case that we expected? or sounds like error code needs to be returned?
OK. It is invalid, I could error out in this case.
Quoted 3 lines
Thanks
Hao
Xu Yilun
maintainerPATCH v3 4/4 fpga: dfl: add support for N3000 nios private feature
In reply to Xu YilunThis patch adds support for the nios handshake private feature on Intel N3000 FPGA Card. This private feature provides a handshake interface to FPGA NIOS firmware, which receives retimer configuration command from host and executes via an internal SPI master. When nios finished the configuration, host takes over the ownership of the SPI master to control an Intel MAX10 BMC Chip on the SPI bus.
For NIOS firmware handshake part, this driver requests the retimer configuration for NIOS with parameters from module param, and adds some sysfs nodes for user to query NIOS state.
For SPI part, this driver adds a spi-altera platform device as well as the MAX10 BMC spi slave info. A spi-altera driver will be matched to handle following the SPI work.
---
v3: Add the doc for this driver.
Minor fixes for comments from Tom.
--- .../ABI/testing/sysfs-bus-dfl-devices-n3000-nios | 18 + Documentation/fpga/dfl-n3000-nios.rst | 39 ++ Documentation/fpga/index.rst | 1 + drivers/fpga/Kconfig | 12 + drivers/fpga/Makefile | 2 + drivers/fpga/dfl-n3000-nios.c | 518 +++++++++++++++++++++ 6 files changed, 590 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios create mode 100644 Documentation/fpga/dfl-n3000-nios.rst create mode 100644 drivers/fpga/dfl-n3000-nios.c
Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios new file +18 -0
@@ -0,0 +1,18 @@ +What: /sys/bus/dfl/devices/dfl-fme.X.X/fec_mode +Date: July 2020 +KernelVersion: 5.9 +Contact: Xu Yilun <[email protected]> +Description: Read-only. It returns the FEC mode of the ethernet retimer + configured by NIOS firmware. "rs" for RS FEC mode, "kr" for + KR FEC mode, "no" FOR NO FEC mode. The FEC mode could be set + by module parameters, but it could only be set once after the + board powers up. + Format: string + +What: /sys/bus/dfl/devices/dfl-fme.X.X/nios_fw_version +Date: July 2020 +KernelVersion: 5.9 +Contact: Xu Yilun <[email protected]> +Description: Read-only. It returns the NIOS firmware version in FPGA. Its + format is "major.minor.patch". + Format: %x.%x.%x
Documentation/fpga/dfl-n3000-nios.rst new file +39 -0
@@ -0,0 +1,39 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================================== +DFL N3000 Nios Private Feature Driver +===================================== + +The dfl n3000 nios driver supports for the nios handshake private feature on +Intel N3000 FPGA Card. + +This private feature provides a handshake interface to FPGA NIOS firmware, +which receives the ethernet retimer configuration command from host and +do the configuration via an internal SPI master. When nios finished the +configuration, host takes over the ownership of the SPI master to control an +Intel MAX10 BMC Chip on the SPI bus. + +So the driver does 2 major tasks on probe, requires NIOS firmware to configure +the ethernet retimer by operating the handshake interfaces, and then creates a +spi master platform device with the MAX10 device info in spi_board_info. + +Module Parameters +================= + +The dfl n3000 nios driver supports the following module parameters: + +* fec_mode: string + Require the NIOS firmware to set the FEC mode of the ethernet retimer on + the PAC N3000 FPGA card. The possible values could be: + + - "rs": RS FEC mode (default) + - "kr": KR FEC mode + - "no": NO FEC mode + + The configuration could only be set once after the board powers up, the + firmware will not accept a second configuration afterward. So the fec mode + will not be changed if the module is reloaded with a different param value. + + The configured value of the fec mode could be queried from sysfs node: + + /sys/bus/dfl/devices/dfl-fme.X.X/fec_mode
Documentation/fpga/index.rst +1 -0
@@ -8,6 +8,7 @@ fpga :maxdepth: 1 dfl + dfl-n3000-nios .. only:: subproject and html
drivers/fpga/Kconfig +12 -0
@@ -191,6 +191,18 @@ config FPGA_DFL_AFU to the FPGA infrastructure via a Port. There may be more than one Port/AFU per DFL based FPGA device. +config FPGA_DFL_N3000_NIOS + tristate "FPGA DFL N3000 NIOS Driver" + depends on FPGA_DFL + select REGMAP + help + This is the driver for the nios handshake private feature on Intel + N3000 FPGA Card. This private feature provides a handshake interface + to FPGA NIOS firmware, which receives retimer configuration command + from host and executes via an internal SPI master. When nios finished + the configuration, host takes over the ownership of the SPI master to + control an Intel MAX10 BMC Chip on the SPI bus. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFL
drivers/fpga/Makefile +2 -0
@@ -44,5 +44,7 @@ dfl-fme-objs += dfl-fme-perf.o dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o dfl-afu-objs += dfl-afu-error.o +obj-$(CONFIG_FPGA_DFL_N3000_NIOS) += dfl-n3000-nios.o + # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o
drivers/fpga/dfl-n3000-nios.c new file +518 -0
518 lines not on this page · raw message
Signature · 1 line
2.7.4
RE: [PATCH v3 4/4] fpga: dfl: add support for N3000 nios private feature
Quoted 9 lines
Subject: [PATCH v3 4/4] fpga: dfl: add support for N3000 nios private feature
This patch adds support for the nios handshake private feature on Intel N3000 FPGA Card. This private feature provides a handshake interface to FPGA NIOS firmware, which receives retimer configuration command from host
and executes via an internal SPI master. When nios finished the configuration, host takes over the ownership of the SPI master to control an Intel MAX10 BMC Chip on the SPI bus.
Maybe you can add some more description on what NIOS is here for people to understand this better.
Quoted 37 lines
For NIOS firmware handshake part, this driver requests the retimer configuration for NIOS with parameters from module param, and adds some sysfs nodes for user to query NIOS state.
For SPI part, this driver adds a spi-altera platform device as well as the MAX10 BMC spi slave info. A spi-altera driver will be matched to handle following the SPI work.
Signed-off-by Xu Yilun <[email protected]>Signed-off-by Wu Hao <[email protected]>Signed-off-by Matthew Gerlach <[email protected]>Signed-off-by Russ Weight <[email protected]>Reviewed-by Tom Rix <[email protected]>---
v3: Add the doc for this driver.
Minor fixes for comments from Tom.--- .../ABI/testing/sysfs-bus-dfl-devices-n3000-nios | 18 + Documentation/fpga/dfl-n3000-nios.rst | 39 ++ Documentation/fpga/index.rst | 1 + drivers/fpga/Kconfig | 12 + drivers/fpga/Makefile | 2 + drivers/fpga/dfl-n3000-nios.c | 518 +++++++++++++++++++++ 6 files changed, 590 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-dfl-devices- n3000-nios create mode 100644 Documentation/fpga/dfl-n3000-nios.rst create mode 100644 drivers/fpga/dfl-n3000-nios.cDocumentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios new file +0
-0
Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios line 3
Quoted 3 lines
Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios new file +3
-0@@ -0,0 +1,18 @@ +What: /sys/bus/dfl/devices/dfl-fme.X.X/fec_mode +Date: July 2020 +KernelVersion: 5.9
I don't think we can catch up the 5.9-rc1 at this moment, so 5.10 please.
Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios line 12
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios new file +4
-0+Contact: Xu Yilun <[email protected]> +Description: Read-only. It returns the FEC mode of the ethernet retimer + configured by NIOS firmware. "rs" for RS FEC mode, "kr" for + KR FEC mode, "no" FOR NO FEC mode. The FEC mode couldbe set
Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios new file +5
-0+ by module parameters, but it could only be set once after the + board powers up. + Format: string + +What: /sys/bus/dfl/devices/dfl-fme.X.X/nios_fw_version
I think you have already modified the device name to dfl-dev.X, right?
Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios
Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios new file +2
-0+Date: July 2020 +KernelVersion: 5.9
Ditto.
Quoted 19 lines
Documentation/ABI/testing/sysfs-bus-dfl-devices-n3000-nios new file +4
-0+Contact: Xu Yilun <[email protected]> +Description: Read-only. It returns the NIOS firmware version in FPGA. Its + format is "major.minor.patch". + Format: %x.%x.%xDocumentation/fpga/dfl-n3000-nios.rst new file +7
-0@@ -0,0 +1,39 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================================== +DFL N3000 Nios Private Feature Driver +===================================== + +The dfl n3000 nios driver supports for the nios handshake private featureon
Documentation/fpga/dfl-n3000-nios.rst line 14
Quoted 7 lines
Documentation/fpga/dfl-n3000-nios.rst new file +7
-0+Intel N3000 FPGA Card. + +This private feature provides a handshake interface to FPGA NIOS firmware, +which receives the ethernet retimer configuration command from host and +do the configuration via an internal SPI master. When nios finished the +configuration, host takes over the ownership of the SPI master to control an +Intel MAX10 BMC Chip on the SPI bus.
Maybe it's better to unify the naming - Nios
Quoted 85 lines
Documentation/fpga/dfl-n3000-nios.rst new file +2
-0+ +So the driver does 2 major tasks on probe, requires NIOS firmware toconfigure
+the ethernet retimer by operating the handshake interfaces, and then creates aDocumentation/fpga/dfl-n3000-nios.rst new file +17
-0+spi master platform device with the MAX10 device info in spi_board_info. + +Module Parameters +================= + +The dfl n3000 nios driver supports the following module parameters: + +* fec_mode: string + Require the NIOS firmware to set the FEC mode of the ethernet retimer on + the PAC N3000 FPGA card. The possible values could be: + + - "rs": RS FEC mode (default) + - "kr": KR FEC mode + - "no": NO FEC mode + + The configuration could only be set once after the board powers up, the + firmware will not accept a second configuration afterward. So the fecmode
Documentation/fpga/dfl-n3000-nios.rst new file +5
-0+ will not be changed if the module is reloaded with a different param value. + + The configured value of the fec mode could be queried from sysfs node: + + /sys/bus/dfl/devices/dfl-fme.X.X/fec_modeDocumentation/fpga/index.rst +1
-0@@ -8,6 +8,7 @@ fpga :maxdepth: 1 dfl + dfl-n3000-nios .. only:: subproject and htmldrivers/fpga/Kconfig +7
-0@@ -191,6 +191,18 @@ config FPGA_DFL_AFU to the FPGA infrastructure via a Port. There may be more than one Port/AFU per DFL based FPGA device. +config FPGA_DFL_N3000_NIOS + tristate "FPGA DFL N3000 NIOS Driver" + depends on FPGA_DFL + select REGMAP + help + This is the driver for the nios handshake private feature on Intel + N3000 FPGA Card. This private feature provides a handshakeinterface
drivers/fpga/Kconfig +1
-0+ to FPGA NIOS firmware, which receives retimer configurationcommand
drivers/fpga/Kconfig +1
-0+ from host and executes via an internal SPI master. When niosfinished
drivers/fpga/Kconfig +1
-0+ the configuration, host takes over the ownership of the SPI masterto
drivers/fpga/Kconfig +2
-0+ control an Intel MAX10 BMC Chip on the SPI bus. + config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFLdrivers/fpga/Makefile +2
-0@@ -44,5 +44,7 @@ dfl-fme-objs += dfl-fme-perf.o dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o dfl-afu-objs += dfl-afu-error.o +obj-$(CONFIG_FPGA_DFL_N3000_NIOS) += dfl-n3000-nios.o + # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.odrivers/fpga/dfl-n3000-nios.c new file +0
-0
drivers/fpga/dfl-n3000-nios.c line 3
Quoted 3 lines
drivers/fpga/dfl-n3000-nios.c new file +3
-0@@ -0,0 +1,518 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for DFL N3000 NIOS private feature
Maybe "DFL device driver for Nios private feature on Intel PAC N3000". It must be described clearly to avoid confusing.
Quoted 36 lines
drivers/fpga/dfl-n3000-nios.c new file +26
-0+* +* Copyright (C) 2019-2020 Intel Corporation, Inc. +* +* Authors: +* Wu Hao <[email protected]> +* Xu Yilun <[email protected]> +*/ +#include <linux/bitfield.h> +#include <linux/errno.h> +#include <linux/io.h> +#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/stddef.h> +#include <linux/spi/altera.h> +#include <linux/spi/spi.h> +#include <linux/types.h> + +#include "dfl.h" + +/** +* DOC: fec_mode (string) +* +* Require the NIOS firmware to set the FEC mode of the ethernet retimer on
+ * PAC N3000 FPGA card.
+ *
+ * "rs": RS FEC mode (default)
+ *
+ * "kr": KR FEC mode
+ *
+ * "no": NO FEC mode
+ *
+ * The configuration could only be set once after the board powers up, the
Quoted 8 lines
+ * firmware will not accept a second configuration afterward. So the fec mode
+ * will not be changed if the module is reloaded with a different param value.
+ *
+ * The configured value of thefec_modecould be queried from sysfs node:
+ *
+ */sys/bus/dfl/devices/dfl-fme.X.X/fec_mode
s/dfl-fme.X.X/dfl-dev.X/
drivers/fpga/dfl-n3000-nios.c line 48
Quoted 4 lines
+ */
drivers/fpga/dfl-n3000-nios.c new file +3
-0+static char *fec_mode ="rs" ; +module_param (fec_mode, charp,0444 ); +MODULE_PARM_DESC (child,"FEC mode" );
Why it's child here? This description string doesn't help at all I think. : ( You can put the description from code comments into this description.
Quoted 15 lines
drivers/fpga/dfl-n3000-nios.c new file +15
-0+ +/* N3000 NIOS private feature registers */ +#define NIOS_SPI_PARAM 0x8 +#define PARAM_SHIFT_MODE_MSK BIT_ULL(1) +#define PARAM_SHIFT_MODE_MSB 0 +#define PARAM_SHIFT_MODE_LSB 1 +#define PARAM_DATA_WIDTH GENMASK_ULL(7, 2) +#define PARAM_NUM_CS GENMASK_ULL(13, 8) +#define PARAM_CLK_POL BIT_ULL(14) +#define PARAM_CLK_PHASE BIT_ULL(15) +#define PARAM_PERIPHERAL_ID GENMASK_ULL(47, 32) + +#define NIOS_SPI_CTRL 0x10 +#define CTRL_WR_DATA GENMASK_ULL(31, 0) +#define CTRL_ADDR GENMASK_ULL(44, 32)
drivers/fpga/dfl-n3000-nios.c line 73
Quoted 10 lines
drivers/fpga/dfl-n3000-nios.c new file +10
-0+#define CTRL_CMD_MSK GENMASK_ULL(63, 62) +#define CTRL_CMD_NOP 0 +#define CTRL_CMD_RD 1 +#define CTRL_CMD_WR 2 + +#define NIOS_SPI_STAT 0x18 +#define STAT_RD_DATA GENMASK_ULL(31, 0) +#define STAT_RW_VAL BIT_ULL(32) + +/* nios handshake registers, indirect access */
Ditto
Quoted 5 lines
drivers/fpga/dfl-n3000-nios.c new file +5
-0+#define NIOS_INIT 0x1000 +#define NIOS_INIT_DONE BIT(0) +#define NIOS_INIT_START BIT(1) +/* Mode for PKVL A, link 0, the same below */ +#define REQ_FEC_MODE_A0_MSK GENMASK(9, 8)
drivers/fpga/dfl-n3000-nios.c line 88
Quoted 10 lines
drivers/fpga/dfl-n3000-nios.c new file +10
-0+#define REQ_FEC_MODE_A1_MSK GENMASK(11, 10) +#define REQ_FEC_MODE_A2_MSK GENMASK(13, 12) +#define REQ_FEC_MODE_A3_MSK GENMASK(15, 14) +#define REQ_FEC_MODE_B0_MSK GENMASK(17, 16) +#define REQ_FEC_MODE_B1_MSK GENMASK(19, 18) +#define REQ_FEC_MODE_B2_MSK GENMASK(21, 20) +#define REQ_FEC_MODE_B3_MSK GENMASK(23, 22) +#define REQ_FEC_MODE_NO 0x0 +#define REQ_FEC_MODE_KR 0x1 +#define REQ_FEC_MODE_RS 0x2
What does REQ mean?
Quoted 22 lines
drivers/fpga/dfl-n3000-nios.c new file +22
-0+ +#define NIOS_FW_VERSION 0x1004 +#define NIOS_FW_VERSION_PATCH GENMASK(23, 20) +#define NIOS_FW_VERSION_MINOR GENMASK(27, 24) +#define NIOS_FW_VERSION_MAJOR GENMASK(31, 28) + +#define PKVL_A_MODE_STS 0x1020 +#define PKVL_B_MODE_STS 0x1024 +#define PKVL_MODE_STS_GROUP_MSK GENMASK(15, 8) +#define PKVL_MODE_STS_GROUP_OK 0x0 +#define PKVL_MODE_STS_ID_MSK GENMASK(7, 0) + +#define NS_REGBUS_WAIT_TIMEOUT 10000/* loop count */ +#define NIOS_INIT_TIMEOUT 10000000/* usec */ +#define NIOS_INIT_TIME_INTV 100000/* usec */ + +struct dfl_n3000_nios { +void __iomem *base; +struct regmap *regmap; +struct device *dev; +struct platform_device *altera_spi; +};
drivers/fpga/dfl-n3000-nios.c line 120
Quoted 10 lines
drivers/fpga/dfl-n3000-nios.c new file +10
-0+ +static int n3000_nios_writel (struct dfl_n3000_nios *ns,unsigned int reg, +unsigned int val) +{ +int ret; + + ret =regmap_write (ns->regmap, reg, val); +if (ret) +dev_err (ns->dev,"fail to write reg 0x%x val 0x%x: %d\n" , + reg, val, ret);
Maybe this log printing should be added in regmap implementation side? Then every user can save some code.
Quoted 106 lines
drivers/fpga/dfl-n3000-nios.c new file +87
-0+ +return ret; +} + +static int n3000_nios_readl (struct dfl_n3000_nios *ns,unsigned int reg, +unsigned int *val) +{ +int ret; + + ret =regmap_read (ns->regmap, reg, val); +if (ret) +dev_err (ns->dev,"fail to read reg 0x%x: %d\n" , reg, ret); + +return ret; +} + +static ssize_t nios_fw_version_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct dfl_n3000_nios *ns =dev_get_drvdata (dev); +unsigned int val; +int ret; + + ret =n3000_nios_readl (ns,NIOS_FW_VERSION , &val); +if (ret) +return ret; + +return sprintf (buf,"%x.%x.%x\n" , + (u8 )FIELD_GET (NIOS_FW_VERSION_MAJOR , val), + (u8 )FIELD_GET (NIOS_FW_VERSION_MINOR , val), + (u8 )FIELD_GET (NIOS_FW_VERSION_PATCH , val)); +} +static DEVICE_ATTR_RO (nios_fw_version); + +static ssize_t fec_mode_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct dfl_n3000_nios *ns =dev_get_drvdata (dev); +unsigned int val, mode; +int ret; + + ret =n3000_nios_readl (ns,NIOS_INIT , &val); +if (ret) +return ret; + +/* +* FEC mode should always be the same for all links, as we set them +* in this way. +*/ + mode =FIELD_GET (REQ_FEC_MODE_A0_MSK , val); +if (mode !=FIELD_GET (REQ_FEC_MODE_A1_MSK , val) || + mode !=FIELD_GET (REQ_FEC_MODE_A2_MSK , val) || + mode !=FIELD_GET (REQ_FEC_MODE_A3_MSK , val) || + mode !=FIELD_GET (REQ_FEC_MODE_B0_MSK , val) || + mode !=FIELD_GET (REQ_FEC_MODE_B1_MSK , val) || + mode !=FIELD_GET (REQ_FEC_MODE_B2_MSK , val) || + mode !=FIELD_GET (REQ_FEC_MODE_B3_MSK , val)) +return -EFAULT ; + +switch (mode) { +case REQ_FEC_MODE_NO : +return sprintf (buf,"no\n" ); +case REQ_FEC_MODE_KR : +return sprintf (buf,"kr\n" ); +case REQ_FEC_MODE_RS : +return sprintf (buf,"rs\n" ); + } + +return -EFAULT ; +} +static DEVICE_ATTR_RO (fec_mode); + +static struct attribute *n3000_nios_attrs[] = { + &dev_attr_nios_fw_version.attr, + &dev_attr_fec_mode.attr, +NULL , +}; +ATTRIBUTE_GROUPS (n3000_nios); + +static bool init_error_detected (struct dfl_n3000_nios *ns) +{ +unsigned int val; + +if (n3000_nios_readl (ns,PKVL_A_MODE_STS , &val)) +return true; + + if (FIELD_GET(PKVL_MODE_STS_GROUP_MSK, val) ==
PKVL_MODE_STS_GROUP_OK)drivers/fpga/dfl-n3000-nios.c new file +6
-0+return true; + +if (n3000_nios_readl (ns,PKVL_B_MODE_STS , &val)) +return true; + + if (FIELD_GET(PKVL_MODE_STS_GROUP_MSK, val) ==
PKVL_MODE_STS_GROUP_OK)drivers/fpga/dfl-n3000-nios.c new file +11
-0+return true; + +return false; +} + +static void dump_error_stat (struct dfl_n3000_nios *ns) +{ +unsigned int val; + +if (n3000_nios_readl (ns,PKVL_A_MODE_STS , &val)) { + dev_err(ns->dev, "Could not read register
Quoted 1 line
PKVL_A_MODE_STS\n");
Why similar error log here again?
Quoted 160 lines
drivers/fpga/dfl-n3000-nios.c new file +7
-0+return ; + } + +dev_info (ns->dev,"PKVL_A_MODE_STS %x\n" , val); + +if (n3000_nios_readl (ns,PKVL_B_MODE_STS , &val)) { + dev_err(ns->dev, "Could not read registerPKVL_B_MODE_STS\n");
drivers/fpga/dfl-n3000-nios.c new file +31
-0+return ; + } + +dev_info (ns->dev,"PKVL_B_MODE_STS %x\n" , val); +} + +static int n3000_nios_init_done_check (struct dfl_n3000_nios *ns) +{ +struct device *dev = ns->dev; +unsigned int val, mode; +int ret; + +/* +* this SPI is shared by NIOS core inside FPGA, NIOS will use this SPI +* master to do some one time initialization after power up, and then +* release the control to OS. driver needs to poll on INIT_DONE to +* see when driver could take the control. +* +* Please note that after 3.x.x version, INIT_START is introduced, so +* driver needs to trigger START firstly and then check INIT_DONE. +*/ + + ret =n3000_nios_readl (ns,NIOS_FW_VERSION , &val); +if (ret) +return ret; + +/* +* If NIOS version register is totally uninitialized(== 0x0), then the +* NIOS firmware is missing. So host could take control of SPI master +* safely, but initialization work for NIOS is not done. This is an +* issue of FPGA image. We didn't error out because we need SPI master
drivers/fpga/dfl-n3000-nios.c new file +4
-0+* to reprogram a new image. +*/ +if (val ==0 ) { + dev_warn(dev, "NIOS version reg = 0x%x, skip INIT_DONEcheck, but PKVL may be uninitialized\n",
drivers/fpga/dfl-n3000-nios.c new file +63
-0+ val); +return 0 ; + } + +if (FIELD_GET (NIOS_FW_VERSION_MAJOR , val) >=3 ) { +/* read NIOS_INIT to check if PKVL INIT done or not */ + ret =n3000_nios_readl (ns,NIOS_INIT , &val); +if (ret) +return ret; + +/* check if PKVLs are initialized already */ +if (val &NIOS_INIT_DONE || val &NIOS_INIT_START ) + goto nios_init_done; + +/* configure FEC mode per module param */ + val =NIOS_INIT_START ; + +/* FEC mode will be ignored by hardware in 10G mode */ +if (!strcmp (fec_mode,"no" )) + mode =REQ_FEC_MODE_NO ; +else if (!strcmp (fec_mode,"kr" )) + mode =REQ_FEC_MODE_KR ; +else if (!strcmp (fec_mode,"rs" )) + mode =REQ_FEC_MODE_RS ; +else +return -EINVAL ; + +/* set the same FEC mode for all links */ + val |=FIELD_PREP (REQ_FEC_MODE_A0_MSK , mode) | +FIELD_PREP (REQ_FEC_MODE_A1_MSK , mode) | +FIELD_PREP (REQ_FEC_MODE_A2_MSK , mode) | +FIELD_PREP (REQ_FEC_MODE_A3_MSK , mode) | +FIELD_PREP (REQ_FEC_MODE_B0_MSK , mode) | +FIELD_PREP (REQ_FEC_MODE_B1_MSK , mode) | +FIELD_PREP (REQ_FEC_MODE_B2_MSK , mode) | +FIELD_PREP (REQ_FEC_MODE_B3_MSK , mode); + + ret =n3000_nios_writel (ns,NIOS_INIT , val); +if (ret) +return ret; + } + +nios_init_done: +/* polls on NIOS_INIT_DONE */ + ret =regmap_read_poll_timeout (ns->regmap,NIOS_INIT , val, + val &NIOS_INIT_DONE , +NIOS_INIT_TIME_INTV , +NIOS_INIT_TIMEOUT ); +if (ret) { +dev_err (dev,"NIOS_INIT_DONE %s\n" , + (ret == -ETIMEDOUT ) ?"timed out" :"check error" ); + goto dump_sts; + } + +/* +* after INIT_DONE is detected, it still needs to check if any ERR +* detected. +* We won't error out here even if error detected. Nios will release +* spi controller when INIT_DONE is set, so driver could continue to +* initialize spi controller device. +*/ +if (init_error_detected (ns)) { + dev_warn(dev, "NIOS_INIT_DONE OK, but err found duringinit\n");
drivers/fpga/dfl-n3000-nios.c new file +35
-0+ goto dump_sts; + } +return 0 ; + +dump_sts: +dump_error_stat (ns); + +return ret; +} + +struct spi_board_info m10_n3000_info = { + .modalias ="m10-n3000" , + .max_speed_hz =12500000 , + .bus_num =0 , + .chip_select =0 , +}; + +static int create_altera_spi_controller (struct dfl_n3000_nios *ns) +{ +struct altera_spi_platform_data pdata = {0 }; +struct platform_device_info pdevinfo = {0 }; +void __iomem *base = ns->base; +u64 v; + + v =readq (base +NIOS_SPI_PARAM ); + + pdata.mode_bits =SPI_CS_HIGH ; +if (FIELD_GET (PARAM_CLK_POL , v)) + pdata.mode_bits |=SPI_CPOL ; +if (FIELD_GET (PARAM_CLK_PHASE , v)) + pdata.mode_bits |=SPI_CPHA ; + + pdata.num_chipselect =FIELD_GET (PARAM_NUM_CS , v); + pdata.bits_per_word_mask = + SPI_BPW_RANGE_MASK(1, FIELD_GET(PARAM_DATA_WIDTH,v));
drivers/fpga/dfl-n3000-nios.c new file +15
-0+ + pdata.num_devices =1 ; + pdata.devices = &m10_n3000_info; + +dev_dbg (ns->dev,"%s cs %u bpm 0x%x mode 0x%x\n" , __func__, + pdata.num_chipselect, pdata.bits_per_word_mask, + pdata.mode_bits); + + pdevinfo.name ="subdev_spi_altera" ; + pdevinfo.id =PLATFORM_DEVID_AUTO ; + pdevinfo.parent = ns->dev; + pdevinfo.data = &pdata; + pdevinfo.size_data =sizeof (pdata); + + ns->altera_spi =platform_device_register_full (&pdevinfo);
drivers/fpga/dfl-n3000-nios.c line 389
Quoted 10 lines
drivers/fpga/dfl-n3000-nios.c new file +10
-0+return PTR_ERR_OR_ZERO (ns->altera_spi); +} + +static void destroy_altera_spi_controller (struct dfl_n3000_nios *ns) +{ +platform_device_unregister (ns->altera_spi); +} + +/* ns is the abbreviation of nios_spi */ +static int ns_bus_poll_stat_timeout (void __iomem *base,u64 *v)
Why adding "bus" here? I just see it's polling on register bits, right? It's a little confusing on ns_bus.
Quoted 83 lines
drivers/fpga/dfl-n3000-nios.c new file +7
-0+{ +int loops =NS_REGBUS_WAIT_TIMEOUT ; + +/* +* We don't use the time based timeout here for performance. +* +* The image reprograming engine is on max10 bmc chip, which is the spi
drivers/fpga/dfl-n3000-nios.c new file +2
-0+* device connected to altera spi controller. So the regbus read/write +* is on the critical path of PAC N3000 image reprograming. And usually
drivers/fpga/dfl-n3000-nios.c new file +1
-0+* the state changes in few loops, the time based timeout checking will
drivers/fpga/dfl-n3000-nios.c new file +69
-0+* add too much overhead on it. +* +* Anyway, 10000 times loop is large enough. +*/ +do { + *v =readq (base +NIOS_SPI_STAT ); +if (*v &STAT_RW_VAL ) +break ; +cpu_relax (); + }while (--loops); + +return loops ?0 : -ETIMEDOUT ; +} + +static int ns_bus_reg_write (void *context,unsigned int reg,unsigned int val) +{ +void __iomem *base = context; +u64 v =0 ; + + v |=FIELD_PREP (CTRL_CMD_MSK ,CTRL_CMD_WR ); + v |=FIELD_PREP (CTRL_ADDR , reg); + v |=FIELD_PREP (CTRL_WR_DATA , val); +writeq (v, base +NIOS_SPI_CTRL ); + +return ns_bus_poll_stat_timeout (base, &v); +} + +static int ns_bus_reg_read (void *context,unsigned int reg,unsigned int *val) +{ +void __iomem *base = context; +u64 v =0 ; +int ret; + + v |=FIELD_PREP (CTRL_CMD_MSK ,CTRL_CMD_RD ); + v |=FIELD_PREP (CTRL_ADDR , reg); +writeq (v, base +NIOS_SPI_CTRL ); + + ret =ns_bus_poll_stat_timeout (base, &v); +if (!ret) + *val =FIELD_GET (STAT_RD_DATA , v); + +return ret; +} + +static const struct regmap_config ns_regbus_cfg = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .fast_io = true, + + .reg_write = ns_bus_reg_write, + .reg_read = ns_bus_reg_read, +}; + +static int dfl_n3000_nios_probe (struct dfl_device *dfl_dev) +{ +struct device *dev = &dfl_dev->dev; +struct dfl_n3000_nios *ns; +int ret; + + ns =devm_kzalloc (dev,sizeof (*ns),GFP_KERNEL ); +if (!ns) +return -ENOMEM ; + +dev_set_drvdata (&dfl_dev->dev, ns); + + ns->dev = dev; + + ns->base = devm_ioremap_resource(&dfl_dev->dev, &dfl_dev-Quoted 1 line
mmio_res);
drivers/fpga/dfl-n3000-nios.c line 470
Quoted 2 lines
drivers/fpga/dfl-n3000-nios.c new file +2
-0+if (IS_ERR (ns->base)) { +dev_err (dev,"get mem resource fail!\n" );
devm_ioremap_resource should print some error message, will that be enough?
Quoted 51 lines
drivers/fpga/dfl-n3000-nios.c new file +4
-0+return PTR_ERR (ns->base); + } + + ns->regmap = devm_regmap_init(dev, NULL, ns->base,
&ns_regbus_cfg);drivers/fpga/dfl-n3000-nios.c new file +44
-1+if (IS_ERR (ns->regmap)) +return PTR_ERR (ns->regmap); + + ret =n3000_nios_init_done_check (ns); +if (ret) +return ret; + + ret =create_altera_spi_controller (ns); +if (ret) +dev_err (dev,"altera spi controller create failed: %d\n" , ret); + +return ret; +} + +static void dfl_n3000_nios_remove (struct dfl_device *dfl_dev) +{ +struct dfl_n3000_nios *ns =dev_get_drvdata (&dfl_dev->dev); + +destroy_altera_spi_controller (ns); +} + +#define FME_FEATURE_ID_N3000_NIOS 0xd + +static const struct dfl_device_id dfl_n3000_nios_ids[] = { + {FME_ID ,FME_FEATURE_ID_N3000_NIOS }, + { } +}; + +static struct dfl_driver dfl_n3000_nios_driver = { + .drv = { + .name ="dfl-n3000-nios" , + .dev_groups = n3000_nios_groups, + }, + .id_table = dfl_n3000_nios_ids, + .probe = dfl_n3000_nios_probe, + .remove = dfl_n3000_nios_remove, +}; + +module_dfl_driver (dfl_n3000_nios_driver); + +MODULE_DEVICE_TABLE (dfl, dfl_n3000_nios_ids); +MODULE_DESCRIPTION ("DFL N3000 NIOS driver" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); --2.7.4
Xu Yilun
maintainerRe: [PATCH v3 4/4] fpga: dfl: add support for N3000 nios private feature
Thanks for your quick response, I'm OK with most changes. Some comments inline.
Quoted 11 lines · Hao
Quoted 11 lines
Subject: [PATCH v3 4/4] fpga: dfl: add support for N3000 nios private feature
(quoted diff) +9
-0+#define NIOS_INIT0x1000 +#define NIOS_INIT_DONEBIT(0) +#define NIOS_INIT_STARTBIT(1) +/* Mode for PKVL A, link 0, the same below */ +#define REQ_FEC_MODE_A0_MSKGENMASK(9, 8) +#define REQ_FEC_MODE_A1_MSKGENMASK(11, 10) +#define REQ_FEC_MODE_A2_MSKGENMASK(13, 12) +#define REQ_FEC_MODE_A3_MSKGENMASK(15, 14) +#define REQ_FEC_MODE_B0_MSKGENMASK(17, 16)
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+#define REQ_FEC_MODE_B1_MSKGENMASK(19, 18) +#define REQ_FEC_MODE_B2_MSKGENMASK(21, 20) +#define REQ_FEC_MODE_B3_MSKGENMASK(23, 22) +#define REQ_FEC_MODE_NO0x0 +#define REQ_FEC_MODE_KR0x1 +#define REQ_FEC_MODE_RS0x2What does REQ mean?
It's the abbreviation of REQUEST, on spec these fields names REQUEST_FEC_MODE_X_X
Quoted 5 lines
drivers/fpga/dfl-n3000-nios.c line 389
Quoted 2 lines
drivers/fpga/dfl-n3000-nios.c new file +2
-0+/* ns is the abbreviation of nios_spi */ +static int ns_bus_poll_stat_timeout (void __iomem *base,u64 *v)Why adding "bus" here? I just see it's polling on register bits, right? It's a little confusing on
ns_bus.
It is the polling for regmap read/write, the regmap is also called regbus, so I name ns_bus here.
I could change the name, do you think there is confusing also for ns_bus_reg_read & ns_bus_reg_write?
Thanks,
Yilun.
RE: [PATCH v3 4/4] fpga: dfl: add support for N3000 nios private feature
Quoted 28 lines
Subject: Re: [PATCH v3 4/4] fpga: dfl: add support for N3000 nios private feature
Thanks for your quick response, I'm OK with most changes. Some comments inline.
Quoted 1 line · Hao
Quoted 1 line
Subject: [PATCH v3 4/4] fpga: dfl: add support for N3000 nios private
feature
Quoted 10 lines
Quoted 10 lines
(quoted diff) +9
-0+#define NIOS_INIT0x1000 +#define NIOS_INIT_DONEBIT(0) +#define NIOS_INIT_STARTBIT(1) +/* Mode for PKVL A, link 0, the same below */ +#define REQ_FEC_MODE_A0_MSKGENMASK(9, 8) +#define REQ_FEC_MODE_A1_MSKGENMASK(11, 10) +#define REQ_FEC_MODE_A2_MSKGENMASK(13, 12) +#define REQ_FEC_MODE_A3_MSKGENMASK(15, 14) +#define REQ_FEC_MODE_B0_MSKGENMASK(17, 16)Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+#define REQ_FEC_MODE_B1_MSKGENMASK(19, 18) +#define REQ_FEC_MODE_B2_MSKGENMASK(21, 20) +#define REQ_FEC_MODE_B3_MSKGENMASK(23, 22) +#define REQ_FEC_MODE_NO0x0 +#define REQ_FEC_MODE_KR0x1 +#define REQ_FEC_MODE_RS0x2What does REQ mean?
Quoted 2 lines
It's the abbreviation of REQUEST, on spec these fields names
REQUEST_FEC_MODE_X_X
Ok, got it.
Quoted 7 lines
Quoted 6 lines
drivers/fpga/dfl-n3000-nios.c line 389
Quoted 3 lines
drivers/fpga/dfl-n3000-nios.c new file +2
-0+/* ns is the abbreviation of nios_spi */ +static int ns_bus_poll_stat_timeout (void __iomem *base,u64 *v)Why adding "bus" here? I just see it's polling on register bits, right? It's a little confusing on
ns_bus.
Quoted 5 lines
It is the polling for regmap read/write, the regmap is also called regbus, so I name
ns_bushere.I could change the name, do you think there is confusing also for
ns_bus_reg_read&ns_bus_reg_write?
This regmap is only used to access the SPI master shared with Nios core, right? If we compare nios_spi_bus_reg_read with nios_spi_reg_read, I think nios_spi/ns_reg_read is better,
how do you think?
Thanks
Hao
Quoted 3 lines
Thanks,
Yilun.
Re: [PATCH v3 4/4] fpga: dfl: add support for N3000 nios private feature
In reply to Xu YilunSome minor edits.
I have added definitions for fec, kr, and rs.
Tom
Quoted 5 lines
Documentation/fpga/dfl-n3000-nios.rst new file +2
-0@@ -0,0 +1,39 @@ +.. SPDX-License-Identifier: GPL-2.0 +
Documentation/fpga/dfl-n3000-nios.rst line 12
Quoted 10 lines
Documentation/fpga/dfl-n3000-nios.rst new file +10
-0+===================================== +DFL N3000 Nios Private Feature Driver +===================================== + +The dfl n3000 nios driver supports for the nios handshake private feature on +Intel N3000 FPGA Card. + +This private feature provides a handshake interface to FPGA NIOS firmware, +which receives the ethernet retimer configuration command from host and +do the configuration via an internal SPI master. When nios finished the
does the configuration..
When nios finishes the ..
Documentation/fpga/dfl-n3000-nios.rst line 16
Quoted 4 lines
Documentation/fpga/dfl-n3000-nios.rst new file +4
-0+configuration, host takes over the ownership of the SPI master to control an +Intel MAX10 BMC Chip on the SPI bus. + +So the driver does 2 major tasks on probe, requires NIOS firmware to configure
, uses the NIOS firmware to configure the ethernet retimer, and then ..
Documentation/fpga/dfl-n3000-nios.rst line 26
Quoted 10 lines
Documentation/fpga/dfl-n3000-nios.rst new file +10
-0+the ethernet retimer by operating the handshake interfaces, and then creates a +spi master platform device with the MAX10 device info in spi_board_info. + +Module Parameters +================= + +The dfl n3000 nios driver supports the following module parameters: + +* fec_mode: string + Require the NIOS firmware to set the FEC mode of the ethernet retimer on
the FEC (Forward Error Correction) mode
Documentation/fpga/dfl-n3000-nios.rst line 29
Quoted 3 lines
Documentation/fpga/dfl-n3000-nios.rst new file +3
-0+ the PAC N3000 FPGA card. The possible values could be: + + - "rs": RS FEC mode (default)
- "rs" : Reed Solomon FEC (default)
Documentation/fpga/dfl-n3000-nios.rst line 30
Quoted 1 line
Documentation/fpga/dfl-n3000-nios.rst new file +1
-0+ - "kr": KR FEC mode
- "kr": Fire Code FEC
Documentation/fpga/dfl-n3000-nios.rst line 33
Quoted 3 lines
Documentation/fpga/dfl-n3000-nios.rst new file +3
-0+ - "no": NO FEC mode + + The configuration could only be set once after the board powers up, the
The configuration can only be ..
Documentation/fpga/dfl-n3000-nios.rst line 34
Quoted 1 line
Documentation/fpga/dfl-n3000-nios.rst new file +1
-0+ firmware will not accept a second configuration afterward. So the fec mode
second configuration.
Quoted 5 lines
Documentation/fpga/dfl-n3000-nios.rst new file +5
-0+ will not be changed if the module is reloaded with a different param value. + + The configured value of the fec mode could be queried from sysfs node: + + /sys/bus/dfl/devices/dfl-fme.X.X/fec_mode
Xu Yilun
maintainerRe: [PATCH v3 4/4] fpga: dfl: add support for N3000 nios private feature
Thanks for the word smith. I'll add these changes.
Thanks,
Yilun
Quoted 61 lines · Tom Rix
Some minor edits.
I have added definitions for fec, kr, and rs.
Reviewed-by Tom Rix <[email protected]>Tom
Quoted 5 lines
Documentation/fpga/dfl-n3000-nios.rst new file +2
-0@@ -0,0 +1,39 @@ +.. SPDX-License-Identifier: GPL-2.0 +Documentation/fpga/dfl-n3000-nios.rst line 12
Quoted 10 lines
Documentation/fpga/dfl-n3000-nios.rst new file +10
-0+===================================== +DFL N3000 Nios Private Feature Driver +===================================== + +The dfl n3000 nios driver supports for the nios handshake private feature on +Intel N3000 FPGA Card. + +This private feature provides a handshake interface to FPGA NIOS firmware, +which receives the ethernet retimer configuration command from host and +do the configuration via an internal SPI master. When nios finished thedoes the configuration..
When nios finishes the ..
Documentation/fpga/dfl-n3000-nios.rst line 16
Quoted 4 lines
Documentation/fpga/dfl-n3000-nios.rst new file +4
-0+configuration, host takes over the ownership of the SPI master to control an +Intel MAX10 BMC Chip on the SPI bus. + +So the driver does 2 major tasks on probe, requires NIOS firmware to configure, uses the NIOS firmware to configure the ethernet retimer, and then ..
Documentation/fpga/dfl-n3000-nios.rst line 26
Quoted 10 lines
Documentation/fpga/dfl-n3000-nios.rst new file +10
-0+the ethernet retimer by operating the handshake interfaces, and then creates a +spi master platform device with the MAX10 device info in spi_board_info. + +Module Parameters +================= + +The dfl n3000 nios driver supports the following module parameters: + +* fec_mode: string + Require the NIOS firmware to set the FEC mode of the ethernet retimer onthe FEC (Forward Error Correction) mode
Documentation/fpga/dfl-n3000-nios.rst line 29
Quoted 3 lines
Documentation/fpga/dfl-n3000-nios.rst new file +3
-0+ the PAC N3000 FPGA card. The possible values could be: + + - "rs": RS FEC mode (default)- "rs" : Reed Solomon FEC (default)
Documentation/fpga/dfl-n3000-nios.rst line 30
Quoted 1 line
Documentation/fpga/dfl-n3000-nios.rst new file +1
-0+ - "kr": KR FEC mode- "kr": Fire Code FEC
Documentation/fpga/dfl-n3000-nios.rst line 33
Quoted 3 lines
Documentation/fpga/dfl-n3000-nios.rst new file +3
-0+ - "no": NO FEC mode + + The configuration could only be set once after the board powers up, theThe configuration can only be ..
Documentation/fpga/dfl-n3000-nios.rst line 34
Quoted 1 line
Documentation/fpga/dfl-n3000-nios.rst new file +1
-0+ firmware will not accept a second configuration afterward. So the fec modesecond configuration.
Quoted 5 lines
Documentation/fpga/dfl-n3000-nios.rst new file +5
-0+ will not be changed if the module is reloaded with a different param value. + + The configured value of the fec mode could be queried from sysfs node: + + /sys/bus/dfl/devices/dfl-fme.X.X/fec_mode