Skip to contentSkip to conversation

parport: daisy: avoid hardcoded name

PATCH In review Sudip Mukherjee 2 participants 6 messages Oct 16, 2019 – Nov 11, 2019 Parallel port

lore
Share & tools
lore

Sudip Mukherjee

author maintainer
#0 lore raw

PATCH 1/4 parport: daisy: avoid hardcoded name

The daisy device name is hardcoded, define it in the header file and use it in the code.

---
 drivers/parport/probe.c | 2 +-
 include/linux/parport.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/parport/probe.c +1 -1
index e035174ba205..4e2bfeb6b4a6 100644
@@ -257,7 +257,7 @@ static ssize_t parport_read_device_id (struct parport *port, char *buffer,
 ssize_t parport_device_id (int devnum, char *buffer, size_t count)
 {
 	ssize_t retval = -ENXIO;
-	struct pardevice *dev = parport_open (devnum, "Device ID probe");
+	struct pardevice *dev = parport_open(devnum, daisy_dev_name);
 	if (!dev)
 		return -ENXIO;
 
include/linux/parport.h +1 -0
index 397607a0c0eb..13932ce8b37b 100644
@@ -460,6 +460,7 @@ extern size_t parport_ieee1284_epp_read_addr (struct parport *,
 					      void *, size_t, int);
 
 /* IEEE1284.3 functions */
+#define daisy_dev_name "Device ID probe"
 extern int parport_daisy_init (struct parport *port);
 extern void parport_daisy_fini (struct parport *port);
 extern struct pardevice *parport_open (int devnum, const char *name);
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH 2/4 parport: do not check portlist when using device-model

We do not need to maintain a list of ports when we are using the device-model. The base layer is going to maintain the list for us and we can get the list of ports just using bus_for_each_dev().

---
 drivers/parport/share.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/parport/share.c +2 -3
index 7b4ee33c1935..96538b7975e5 100644
@@ -266,9 +266,6 @@ static int port_check(struct device *dev, void *dev_drv)
 int __parport_register_driver(struct parport_driver *drv, struct module *owner,
 			      const char *mod_name)
 {
-	if (list_empty(&portlist))
-		get_lowlevel_driver();
-
 	if (drv->devmodel) {
 		/* using device model */
 		int ret;
@@ -292,6 +289,8 @@ int __parport_register_driver(struct parport_driver *drv, struct module *owner,
 
 		drv->devmodel = false;
 
+		if (list_empty(&portlist))
+			get_lowlevel_driver();
 		mutex_lock(&registration_lock);
 		list_for_each_entry(port, &portlist, list)
 			drv->attach(port);
Signature · 1 line
2.11.0
author maintainer
#2 lore raw

PATCH 3/4 parport: load lowlevel driver if ports not found

In reply to Sudip Mukherjee

Usually all the distro will load the parport low level driver as part of their initialization. But we can get into a situation where all the parallel port drivers are built as module and we unload all the modules at a later time. Then if we just do "modprobe parport" it will only load the parport module and will not load the low level driver which will actually register the ports. So, check the bus if there is any parport registered, if not, load the low level driver.

We can get into the above situation with all distro but only Suse has setup the alias for "parport_lowlevel" and so it only works in Suse. Users of Debian based distro will need to load the lowlevel module manually.

---
 drivers/parport/share.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/parport/share.c +21 -0
index 96538b7975e5..d6920ebeabcd 100644
@@ -230,6 +230,18 @@ static int port_check(struct device *dev, void *dev_drv)
 	return 0;
 }
 
+/*
+ * Iterates through all the devices connected to the bus and return 1
+ * if the device is a parallel port.
+ */
+
+static int port_detect(struct device *dev, void *dev_drv)
+{
+	if (is_parport(dev))
+		return 1;
+	return 0;
+}
+
 /**
  *	parport_register_driver - register a parallel port device driver
  *	@drv: structure describing the driver
@@ -279,6 +291,15 @@ int __parport_register_driver(struct parport_driver *drv, struct module *owner,
 		if (ret)
 			return ret;
 
+		/*
+		 * check if bus has any parallel port registered, if
+		 * none is found then load the lowlevel driver.
+		 */
+		ret = bus_for_each_dev(&parport_bus_type, NULL, NULL,
+				       port_detect);
+		if (!ret)
+			get_lowlevel_driver();
+
 		mutex_lock(&registration_lock);
 		if (drv->match_port)
 			bus_for_each_dev(&parport_bus_type, NULL, drv,
Signature · 1 line
2.11.0
author maintainer
#3 lore raw

PATCH 4/4 parport: daisy: use new parport device model

In reply to Sudip Mukherjee

Modify parport daisy driver to use the new parallel port device model.

Last attempt was '1aec4211204d ("parport: daisy: use new parport device model")' which failed as daisy was also trying to load the low level driver and that resulted in a deadlock.

Cc Michal Kubecek <[email protected]>
Cc Steven Rostedt (VMware) <[email protected]>

---

Steven, Michal,
Can you please test this series in your test environment and verify that I am not breaking anything this time.

 drivers/parport/daisy.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/parport/daisy.c +39 -1
index 5484a46dafda..95b5c3363582 100644
@@ -45,6 +45,7 @@ static struct daisydev {
 static DEFINE_SPINLOCK(topology_lock);
 
 static int numdevs;
+static bool daisy_init_done;
 
 /* Forward-declaration of lower-level functions. */
 static int mux_present(struct parport *port);
@@ -87,6 +88,24 @@ static struct parport *clone_parport(struct parport *real, int muxport)
 	return extra;
 }
 
+static int daisy_drv_probe(struct pardevice *par_dev)
+{
+	struct device_driver *drv = par_dev->dev.driver;
+
+	if (strcmp(drv->name, "daisy_drv"))
+		return -ENODEV;
+	if (strcmp(par_dev->name, daisy_dev_name))
+		return -ENODEV;
+
+	return 0;
+}
+
+static struct parport_driver daisy_driver = {
+	.name = "daisy_drv",
+	.probe = daisy_drv_probe,
+	.devmodel = true,
+};
+
 /* Discover the IEEE1284.3 topology on a port -- muxes and daisy chains.
  * Return value is number of devices actually detected. */
 int parport_daisy_init(struct parport *port)
@@ -98,6 +117,23 @@ int parport_daisy_init(struct parport *port)
 	int i;
 	int last_try = 0;
 
+	if (!daisy_init_done) {
+		/*
+		 * flag should be marked true first as
+		 * parport_register_driver() might try to load the low
+		 * level driver which will lead to announcing new ports
+		 * and which will again come back here at
+		 * parport_daisy_init()
+		 */
+		daisy_init_done = true;
+		i = parport_register_driver(&daisy_driver);
+		if (i) {
+			pr_err("daisy registration failed\n");
+			daisy_init_done = false;
+			return i;
+		}
+	}
+
 again:
 	/* Because this is called before any other devices exist,
 	 * we don't have to claim exclusive access.  */
@@ -213,10 +249,12 @@ void parport_daisy_fini(struct parport *port)
 struct pardevice *parport_open(int devnum, const char *name)
 {
 	struct daisydev *p = topology;
+	struct pardev_cb par_cb;
 	struct parport *port;
 	struct pardevice *dev;
 	int daisy;
 
+	memset(&par_cb, 0, sizeof(par_cb));
 	spin_lock(&topology_lock);
 	while (p && p->devnum != devnum)
 		p = p->next;
@@ -230,7 +268,7 @@ struct pardevice *parport_open(int devnum, const char *name)
 	port = parport_get_port(p->port);
 	spin_unlock(&topology_lock);
 
-	dev = parport_register_device(port, name, NULL, NULL, NULL, 0, NULL);
+	dev = parport_register_dev_model(port, name, &par_cb, devnum);
 	parport_put_port(port);
 	if (!dev)
 		return NULL;
Signature · 1 line
2.11.0
Tested-by on v1 4/4
#4 lore raw

Re: [PATCH 4/4] parport: daisy: use new parport device model

Quoted 6 lines · On Wed, 16 Oct 2019 15:45:40 +0100 Sudip Mukherjee…

Modify parport daisy driver to use the new parallel port device model.

Last attempt was '1aec4211204d ("parport: daisy: use new parport device model")' which failed as daisy was also trying to load the low level driver and that resulted in a deadlock.

Quoted 10 lines
Cc Michal Kubecek <[email protected]>
Cc Steven Rostedt (VMware) <[email protected]>

---

Steven, Michal,
Can you please test this series in your test environment and verify that I am not breaking anything this time.

I checked out 1aec4211204d~1 (just before the broken commit), and applied these four patches. It booted with the config that wouldn't boot with the broken commit.

-- Steve

author maintainer
#5 lore raw

Re: [PATCH 4/4] parport: daisy: use new parport device model

Hi Greg,

Quoted 21 lines · Steven Rostedt
Quoted 6 lines · On Wed, 16 Oct 2019 15:45:40 +0100 Sudip Mukherjee…

Modify parport daisy driver to use the new parallel port device model.

Last attempt was '1aec4211204d ("parport: daisy: use new parport device model")' which failed as daisy was also trying to load the low level driver and that resulted in a deadlock.

Quoted 10 lines
Cc Michal Kubecek <[email protected]>
Cc Steven Rostedt (VMware) <[email protected]>

---

Steven, Michal,
Can you please test this series in your test environment and verify that I am not breaking anything this time.

Quoted 5 lines

I checked out 1aec4211204d~1 (just before the broken commit), and applied these four patches. It booted with the config that wouldn't boot with the broken commit.

A gentle ping on this series.

Signature · 2 lines
Regards
Sudip