Re: device registration callback for usb-serial

2017-08-12 Thread Okash Khawaja
On Fri, Aug 11, 2017 at 11:47:35PM +0200, Samuel Thibault wrote:
> Okash Khawaja, on ven. 11 ao??t 2017 22:38:14 +0100, wrote:
> > On Thu, Aug 10, 2017 at 10:27:31AM +0200, Samuel Thibault wrote:
> > > Oliver Neukum, on jeu. 10 ao??t 2017 10:03:51 +0200, wrote:
> > > > You cannot make assumptions about driver load. Your driver was loaded.
> > > > End of story. Register it with the proper subsystem.
> > > 
> > > The subsystem in question is a line discipline. Registering a line
> > > discipline will not trigger applying it to the serial port, so it's not
> > > enough.
> > > 
> > > Samuel
> > 
> > Okay, it looks like port_probe callback inside usb_serial_driver does
> > this. It gets passed in usb_serial_port which is enough.
> 
> Mmm, but that is called before tty_register_device, is that not a
> problem?
Ah yes. Okay so that won't work.

May be what is needed is something similar to following. It is untested
and intended only to illustrate what is required.

Thanks,
Okash


--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -69,6 +69,9 @@ static int usb_serial_device_probe(struc
goto err_port_remove;
}

+   if (driver->tty_registered)
+   driver->tty_registered(port);
+
usb_autopm_put_interface(port->serial->interface);

dev_info(>serial->dev->dev,
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -225,6 +225,9 @@ struct usb_serial_endpoints {
  * called when the device is unplugged or unbound from the driver.
  * @release: pointer to the driver's release function.  This will be called
  * when the usb_serial data structure is about to be destroyed.
+ * @tty_registered: pointer to the driver's tty_registered callback.
+ * This will be called when the usb serial port has been successfully
+ * registered as a tty device.
  * @usb_driver: pointer to the struct usb_driver that controls this
  * device.  This is necessary to allow dynamic ids to be added to
  * the driver from sysfs.
@@ -268,6 +271,7 @@ struct usb_serial_driver {
void (*release)(struct usb_serial *serial);

int (*port_probe)(struct usb_serial_port *port);
+   void (*tty_registered)(struct usb_serial_port *port);
int (*port_remove)(struct usb_serial_port *port);

int (*suspend)(struct usb_serial *serial, pm_message_t message);
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: device registration callback for usb-serial

2017-08-11 Thread Samuel Thibault
Okash Khawaja, on ven. 11 août 2017 22:38:14 +0100, wrote:
> On Thu, Aug 10, 2017 at 10:27:31AM +0200, Samuel Thibault wrote:
> > Oliver Neukum, on jeu. 10 ao??t 2017 10:03:51 +0200, wrote:
> > > You cannot make assumptions about driver load. Your driver was loaded.
> > > End of story. Register it with the proper subsystem.
> > 
> > The subsystem in question is a line discipline. Registering a line
> > discipline will not trigger applying it to the serial port, so it's not
> > enough.
> > 
> > Samuel
> 
> Okay, it looks like port_probe callback inside usb_serial_driver does
> this. It gets passed in usb_serial_port which is enough.

Mmm, but that is called before tty_register_device, is that not a
problem?

Samuel
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: device registration callback for usb-serial

2017-08-11 Thread Okash Khawaja
On Thu, Aug 10, 2017 at 10:27:31AM +0200, Samuel Thibault wrote:
> Oliver Neukum, on jeu. 10 ao??t 2017 10:03:51 +0200, wrote:
> > You cannot make assumptions about driver load. Your driver was loaded.
> > End of story. Register it with the proper subsystem.
> 
> The subsystem in question is a line discipline. Registering a line
> discipline will not trigger applying it to the serial port, so it's not
> enough.
> 
> Samuel

Okay, it looks like port_probe callback inside usb_serial_driver does
this. It gets passed in usb_serial_port which is enough.

Thanks,
Okash
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: device registration callback for usb-serial

2017-08-10 Thread Samuel Thibault
Oliver Neukum, on jeu. 10 août 2017 10:03:51 +0200, wrote:
> You cannot make assumptions about driver load. Your driver was loaded.
> End of story. Register it with the proper subsystem.

The subsystem in question is a line discipline. Registering a line
discipline will not trigger applying it to the serial port, so it's not
enough.

Samuel
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: device registration callback for usb-serial

2017-08-10 Thread Oliver Neukum
Am Donnerstag, den 10.08.2017, 07:56 +0100 schrieb Okash Khawaja:
> Hi,
> 
> struct usb_serial_device has probe and attach callbacks. After attach
> is invoked, device minor numbers are allocated and then registered with
> driver core. So attach callback doesn't know minor number.
> 
> Can a usb-serial driver know about device minor number as soon as it is
> registered with driver core?

Merely registering a driver does not allocate a minor. And is the order
of device enumeration is unknown at that time, it cannot know a minor
number.

You cannot make assumptions about driver load. Your driver was loaded.
End of story. Register it with the proper subsystem.

Regards
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html