All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] staging: comedi: ni_routes: Share routing information between boards
@ 2020-02-07 15:13 Ian Abbott
  2020-02-07 15:13 ` [PATCH 1/4] staging: comedi: ni_routes: Refactor ni_find_valid_routes() Ian Abbott
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ian Abbott @ 2020-02-07 15:13 UTC (permalink / raw)
  To: devel; +Cc: Greg Kroah-Hartman, Ian Abbott, Éric Piel, Spencer E . Olson

We do not have or provide routing information for all supported NI
boards.  Some of the boards for which we currently provide routing
information actually have identical routes to similar boards for which
we do provide routing information.  Rather than duplicating the routing
data for such boards (about 7 KiB per board), implement a mechanism to
allow an alternate board name to be specified for routing purposes in
case routing information cannot be found for the actual board name.

Specifically, we do not currently provide routing information for the
PCIe-6251 and PCIe-6259 boards.  Patch 4 allows them to use the routing
information provided for the PCI-6251 and PCI-6259 boards.

1) staging: comedi: ni_routes: Refactor ni_find_valid_routes()
2) staging: comedi: ni_routes: Allow alternate board name for routes
3) staging: comedi: ni_mio_common: Allow alternate board name for routes
4) staging: comedi: ni_pcimio: add routes for NI PCIe-6251 and PCIe-6259

 drivers/staging/comedi/drivers/ni_660x.c       |  2 +-
 drivers/staging/comedi/drivers/ni_mio_common.c |  1 +
 drivers/staging/comedi/drivers/ni_pcimio.c     |  2 +
 drivers/staging/comedi/drivers/ni_routes.c     | 63 +++++++++++++++++++++-----
 drivers/staging/comedi/drivers/ni_routes.h     |  1 +
 drivers/staging/comedi/drivers/ni_stc.h        |  1 +
 6 files changed, 58 insertions(+), 12 deletions(-)

Cc: Éric Piel <piel@delmic.com>
Cc: Spencer E. Olson <olsonse@umich.edu>

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] staging: comedi: ni_routes: Refactor ni_find_valid_routes()
  2020-02-07 15:13 [PATCH 0/4] staging: comedi: ni_routes: Share routing information between boards Ian Abbott
@ 2020-02-07 15:13 ` Ian Abbott
  2020-02-07 15:13 ` [PATCH 2/4] staging: comedi: ni_routes: Allow alternate board name for routes Ian Abbott
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ian Abbott @ 2020-02-07 15:13 UTC (permalink / raw)
  To: devel; +Cc: Greg Kroah-Hartman, Ian Abbott, Éric Piel, Spencer E . Olson

Split out the loops in `ni_find_valid_routes()` into separate functions:

* ni_find_route_values(device_family) to find the list of route values
  for a device family (e.g "ni-mseries"); and
* ni_find_valid_routes(board_name) to find the set of valid routes for a
  board name.

The functions above return `NULL` if the information is not found (as we
do not currently have the routing information available for all
supported boards).

Cc: Éric Piel <piel@delmic.com>
Cc: Spencer E. Olson <olsonse@umich.edu>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers/ni_routes.c | 44 +++++++++++++++++-----
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_routes.c b/drivers/staging/comedi/drivers/ni_routes.c
index 8f398b30f5bf..508f76c5c574 100644
--- a/drivers/staging/comedi/drivers/ni_routes.c
+++ b/drivers/staging/comedi/drivers/ni_routes.c
@@ -50,20 +50,13 @@
 #define RVi(table, src, dest)	((table)[(dest) * NI_NUM_NAMES + (src)])
 
 /*
- * Find the proper route_values and ni_device_routes tables for this particular
- * device.
- *
- * Return: -ENODATA if either was not found; 0 if both were found.
+ * Find the route values for a device family.
  */
-static int ni_find_device_routes(const char *device_family,
-				 const char *board_name,
-				 struct ni_route_tables *tables)
+static const u8 *ni_find_route_values(const char *device_family)
 {
-	const struct ni_device_routes *dr = NULL;
 	const u8 *rv = NULL;
 	int i;
 
-	/* First, find the register_values table for this device family */
 	for (i = 0; ni_all_route_values[i]; ++i) {
 		if (memcmp(ni_all_route_values[i]->family, device_family,
 			   strnlen(device_family, 30)) == 0) {
@@ -71,8 +64,18 @@ static int ni_find_device_routes(const char *device_family,
 			break;
 		}
 	}
+	return rv;
+}
+
+/*
+ * Find the valid routes for a board.
+ */
+static const struct ni_device_routes *
+ni_find_valid_routes(const char *board_name)
+{
+	const struct ni_device_routes *dr = NULL;
+	int i;
 
-	/* Second, find the set of routes valid for this device. */
 	for (i = 0; ni_device_routes_list[i]; ++i) {
 		if (memcmp(ni_device_routes_list[i]->device, board_name,
 			   strnlen(board_name, 30)) == 0) {
@@ -80,6 +83,27 @@ static int ni_find_device_routes(const char *device_family,
 			break;
 		}
 	}
+	return dr;
+}
+
+/*
+ * Find the proper route_values and ni_device_routes tables for this particular
+ * device.
+ *
+ * Return: -ENODATA if either was not found; 0 if both were found.
+ */
+static int ni_find_device_routes(const char *device_family,
+				 const char *board_name,
+				 struct ni_route_tables *tables)
+{
+	const struct ni_device_routes *dr;
+	const u8 *rv;
+
+	/* First, find the register_values table for this device family */
+	rv = ni_find_route_values(device_family);
+
+	/* Second, find the set of routes valid for this device. */
+	dr = ni_find_valid_routes(board_name);
 
 	tables->route_values = rv;
 	tables->valid_routes = dr;
-- 
2.24.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] staging: comedi: ni_routes: Allow alternate board name for routes
  2020-02-07 15:13 [PATCH 0/4] staging: comedi: ni_routes: Share routing information between boards Ian Abbott
  2020-02-07 15:13 ` [PATCH 1/4] staging: comedi: ni_routes: Refactor ni_find_valid_routes() Ian Abbott
@ 2020-02-07 15:13 ` Ian Abbott
  2020-02-07 15:13 ` [PATCH 3/4] staging: comedi: ni_mio_common: " Ian Abbott
  2020-02-07 15:14 ` [PATCH 4/4] staging: comedi: ni_pcimio: add routes for NI PCIe-6251 and PCIe-6259 Ian Abbott
  3 siblings, 0 replies; 5+ messages in thread
From: Ian Abbott @ 2020-02-07 15:13 UTC (permalink / raw)
  To: devel; +Cc: Greg Kroah-Hartman, Ian Abbott, Éric Piel, Spencer E . Olson

We do not have or provide routing information available for all
supported boards.  Some of the boards for which we do not currently
provide routing information actually have identical routes to a similar
board for which we do provide routing information.  To avoid having to
provide duplicate routing information, add an "alternate board name"
parameter (possibly `NULl`) to `ni_assign_device_routes()` and
`ni_find_device_routes()`.  If the routing information cannot be found
for the actual board name, try finding it using the alternate board
name.

Cc: Éric Piel <piel@delmic.com>
Cc: Spencer E. Olson <olsonse@umich.edu>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers/ni_660x.c      |  2 +-
 .../staging/comedi/drivers/ni_mio_common.c    |  2 +-
 drivers/staging/comedi/drivers/ni_routes.c    | 21 +++++++++++++++++--
 drivers/staging/comedi/drivers/ni_routes.h    |  1 +
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
index 4ee9b260eab0..75d5c9c24596 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1035,7 +1035,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
 	ni_660x_init_tio_chips(dev, board->n_chips);
 
 	/* prepare the device for globally-named routes. */
-	if (ni_assign_device_routes("ni_660x", board->name,
+	if (ni_assign_device_routes("ni_660x", board->name, NULL,
 				    &devpriv->routing_tables) < 0) {
 		dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n",
 			 __func__, board->name);
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c
index f98e3ae27bff..a1578868ee96 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5974,7 +5974,7 @@ static int ni_E_init(struct comedi_device *dev,
 						      : "ni_eseries";
 
 	/* prepare the device for globally-named routes. */
-	if (ni_assign_device_routes(dev_family, board->name,
+	if (ni_assign_device_routes(dev_family, board->name, NULL,
 				    &devpriv->routing_tables) < 0) {
 		dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n",
 			 __func__, board->name);
diff --git a/drivers/staging/comedi/drivers/ni_routes.c b/drivers/staging/comedi/drivers/ni_routes.c
index 508f76c5c574..07cb970340db 100644
--- a/drivers/staging/comedi/drivers/ni_routes.c
+++ b/drivers/staging/comedi/drivers/ni_routes.c
@@ -88,12 +88,14 @@ ni_find_valid_routes(const char *board_name)
 
 /*
  * Find the proper route_values and ni_device_routes tables for this particular
- * device.
+ * device.  Possibly try an alternate board name if device routes not found
+ * for the actual board name.
  *
  * Return: -ENODATA if either was not found; 0 if both were found.
  */
 static int ni_find_device_routes(const char *device_family,
 				 const char *board_name,
+				 const char *alt_board_name,
 				 struct ni_route_tables *tables)
 {
 	const struct ni_device_routes *dr;
@@ -104,6 +106,8 @@ static int ni_find_device_routes(const char *device_family,
 
 	/* Second, find the set of routes valid for this device. */
 	dr = ni_find_valid_routes(board_name);
+	if (!dr && alt_board_name)
+		dr = ni_find_valid_routes(alt_board_name);
 
 	tables->route_values = rv;
 	tables->valid_routes = dr;
@@ -117,15 +121,28 @@ static int ni_find_device_routes(const char *device_family,
 /**
  * ni_assign_device_routes() - Assign the proper lookup table for NI signal
  *			       routing to the specified NI device.
+ * @device_family: Device family name (determines route values).
+ * @board_name: Board name (determines set of routes).
+ * @alt_board_name: Optional alternate board name to try on failure.
+ * @tables: Pointer to assigned routing information.
+ *
+ * Finds the route values for the device family and the set of valid routes
+ * for the board.  If valid routes could not be found for the actual board
+ * name and an alternate board name has been specified, try that one.
+ *
+ * On failure, the assigned routing information may be partially filled
+ * (for example, with the route values but not the set of valid routes).
  *
  * Return: -ENODATA if assignment was not successful; 0 if successful.
  */
 int ni_assign_device_routes(const char *device_family,
 			    const char *board_name,
+			    const char *alt_board_name,
 			    struct ni_route_tables *tables)
 {
 	memset(tables, 0, sizeof(struct ni_route_tables));
-	return ni_find_device_routes(device_family, board_name, tables);
+	return ni_find_device_routes(device_family, board_name, alt_board_name,
+				     tables);
 }
 EXPORT_SYMBOL_GPL(ni_assign_device_routes);
 
diff --git a/drivers/staging/comedi/drivers/ni_routes.h b/drivers/staging/comedi/drivers/ni_routes.h
index 3211a16adc6f..b7680fd2afe1 100644
--- a/drivers/staging/comedi/drivers/ni_routes.h
+++ b/drivers/staging/comedi/drivers/ni_routes.h
@@ -76,6 +76,7 @@ struct ni_route_tables {
  */
 int ni_assign_device_routes(const char *device_family,
 			    const char *board_name,
+			    const char *alt_board_name,
 			    struct ni_route_tables *tables);
 
 /*
-- 
2.24.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] staging: comedi: ni_mio_common: Allow alternate board name for routes
  2020-02-07 15:13 [PATCH 0/4] staging: comedi: ni_routes: Share routing information between boards Ian Abbott
  2020-02-07 15:13 ` [PATCH 1/4] staging: comedi: ni_routes: Refactor ni_find_valid_routes() Ian Abbott
  2020-02-07 15:13 ` [PATCH 2/4] staging: comedi: ni_routes: Allow alternate board name for routes Ian Abbott
@ 2020-02-07 15:13 ` Ian Abbott
  2020-02-07 15:14 ` [PATCH 4/4] staging: comedi: ni_pcimio: add routes for NI PCIe-6251 and PCIe-6259 Ian Abbott
  3 siblings, 0 replies; 5+ messages in thread
From: Ian Abbott @ 2020-02-07 15:13 UTC (permalink / raw)
  To: devel; +Cc: Greg Kroah-Hartman, Ian Abbott, Éric Piel, Spencer E . Olson

We do not have or do not provide routing information for all supported
boards.  Some of the boards for which we do not provide routing
information actually have routes that are identical to a similar board
for which we already provide routing information.

To allow boards to share identical routing information, add an
`alt_route_name` member to `struct ni_board_struct`.  This will be
initialized to `NULL` for all boards except those that will use make use
of the identical routing information that has been provided for a
similar board, in which case it will name that board.  Pass the
`alt_route_name` member value to `ni_assign_device_routes()` as the
`alt_board_name` parameter, which it will use if no routing information
could be found for the actual board name.

Cc: Éric Piel <piel@delmic.com>
Cc: Spencer E. Olson <olsonse@umich.edu>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers/ni_mio_common.c | 3 ++-
 drivers/staging/comedi/drivers/ni_stc.h        | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c
index a1578868ee96..b72a40a79930 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5974,7 +5974,8 @@ static int ni_E_init(struct comedi_device *dev,
 						      : "ni_eseries";
 
 	/* prepare the device for globally-named routes. */
-	if (ni_assign_device_routes(dev_family, board->name, NULL,
+	if (ni_assign_device_routes(dev_family, board->name,
+				    board->alt_route_name,
 				    &devpriv->routing_tables) < 0) {
 		dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n",
 			 __func__, board->name);
diff --git a/drivers/staging/comedi/drivers/ni_stc.h b/drivers/staging/comedi/drivers/ni_stc.h
index 35427f8bf8f7..fbc0b753a0f5 100644
--- a/drivers/staging/comedi/drivers/ni_stc.h
+++ b/drivers/staging/comedi/drivers/ni_stc.h
@@ -941,6 +941,7 @@ enum ni_reg_type {
 
 struct ni_board_struct {
 	const char *name;
+	const char *alt_route_name;
 	int device_id;
 	int isapnp_id;
 
-- 
2.24.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] staging: comedi: ni_pcimio: add routes for NI PCIe-6251 and PCIe-6259
  2020-02-07 15:13 [PATCH 0/4] staging: comedi: ni_routes: Share routing information between boards Ian Abbott
                   ` (2 preceding siblings ...)
  2020-02-07 15:13 ` [PATCH 3/4] staging: comedi: ni_mio_common: " Ian Abbott
@ 2020-02-07 15:14 ` Ian Abbott
  3 siblings, 0 replies; 5+ messages in thread
From: Ian Abbott @ 2020-02-07 15:14 UTC (permalink / raw)
  To: devel; +Cc: Greg Kroah-Hartman, Ian Abbott, Éric Piel, Spencer E . Olson

We do not currently provide routing information for NI PCIe-6251 and
PCI-6259 boards, but they are functionally identical to the PCI-6251 and
PCI-6259 boards and can share their routing information.  (This has been
confirmed for the PCIe-6251 by Éric Piel, using the "NI MAX" software
for Windows.  It is hoped that it applies to PCIe-6259, but has not yet
been checked due to lack of hardware.)  Initialize the `alt_route_name`
member of the board information for PCIe-6251 and PCIe-6259 to allow
them to make use of the routing information provided for PCI-6251 and
PCI-6259 respectively.

Cc: Éric Piel <piel@delmic.com>
Cc: Spencer E. Olson <olsonse@umich.edu>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers/ni_pcimio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c
index 14b26fffe049..7c82d5f9778f 100644
--- a/drivers/staging/comedi/drivers/ni_pcimio.c
+++ b/drivers/staging/comedi/drivers/ni_pcimio.c
@@ -888,6 +888,7 @@ static const struct ni_board_struct ni_boards[] = {
 	},
 	[BOARD_PCIE6251] = {
 		.name		= "pcie-6251",
+		.alt_route_name	= "pci-6251",
 		.n_adchan	= 16,
 		.ai_maxdata	= 0xffff,
 		.ai_fifo_depth	= 4095,
@@ -976,6 +977,7 @@ static const struct ni_board_struct ni_boards[] = {
 	},
 	[BOARD_PCIE6259] = {
 		.name		= "pcie-6259",
+		.alt_route_name	= "pci-6259",
 		.n_adchan	= 32,
 		.ai_maxdata	= 0xffff,
 		.ai_fifo_depth	= 4095,
-- 
2.24.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-07 15:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-07 15:13 [PATCH 0/4] staging: comedi: ni_routes: Share routing information between boards Ian Abbott
2020-02-07 15:13 ` [PATCH 1/4] staging: comedi: ni_routes: Refactor ni_find_valid_routes() Ian Abbott
2020-02-07 15:13 ` [PATCH 2/4] staging: comedi: ni_routes: Allow alternate board name for routes Ian Abbott
2020-02-07 15:13 ` [PATCH 3/4] staging: comedi: ni_mio_common: " Ian Abbott
2020-02-07 15:14 ` [PATCH 4/4] staging: comedi: ni_pcimio: add routes for NI PCIe-6251 and PCIe-6259 Ian Abbott

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.