All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC]Is usb port number fixed?
@ 2012-04-20  9:25 Wang YanQing
  2012-04-20  9:37 ` Wang YanQing
  0 siblings, 1 reply; 15+ messages in thread
From: Wang YanQing @ 2012-04-20  9:25 UTC (permalink / raw)
  To: lkml; +Cc: linux-usb

Hi!
when I execute the command below:

"ls /sys/bus/usb/devices/"

I get:
"1-0:1.0 1-1 1-1:1.0 2-0:1.0 2-1 2-1.1 2-1:1.0 2-1.1:1.0 2-1.5 2-1.5:1.0 2-1.5:1.1  usb1  usb2"

the output format is bus-port.port:config.interface
I want to know whether the port number is fixed after I reboot machine time by time.
And if it is fixed, then what make it.

Thanks!

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

* Re: [RFC]Is usb port number fixed?
  2012-04-20  9:25 [RFC]Is usb port number fixed? Wang YanQing
@ 2012-04-20  9:37 ` Wang YanQing
  2012-04-20 15:37   ` Greg KH
  0 siblings, 1 reply; 15+ messages in thread
From: Wang YanQing @ 2012-04-20  9:37 UTC (permalink / raw)
  To: lkml, linux-usb

On Fri, Apr 20, 2012 at 05:25:25PM +0800, Wang YanQing wrote:
> Hi!
> when I execute the command below:
> 
> "ls /sys/bus/usb/devices/"
> 
> I get:
> "1-0:1.0 1-1 1-1:1.0 2-0:1.0 2-1 2-1.1 2-1:1.0 2-1.1:1.0 2-1.5 2-1.5:1.0 2-1.5:1.1  usb1  usb2"
> 
> the output format is bus-port.port:config.interface
> I want to know whether the port number is fixed after I reboot machine time by time.
> And if it is fixed, then what make it.
> 
> Thanks!

Make the question precise.
I assme there are two usb ports in my notebook at left and right separately.
When I plug mouse into 
left usb port, I get 2-1.1:1.0
right usb port, I get 2-1.2:1.0

I want to know whether it is right that no matter how many times I reboot the machine,
the test result above will be the same.And if it will be the same, then why it will be the same.



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

* Re: [RFC]Is usb port number fixed?
  2012-04-20  9:37 ` Wang YanQing
@ 2012-04-20 15:37   ` Greg KH
       [not found]     ` <CAHkwNT=VW8qF-7QRxpiaWkmQm0UFdsbahFLhT-PCc4OMnVs1Gg@mail.gmail.com>
  2012-04-21  0:32     ` Alan Stern
  0 siblings, 2 replies; 15+ messages in thread
From: Greg KH @ 2012-04-20 15:37 UTC (permalink / raw)
  To: Wang YanQing, lkml, linux-usb

On Fri, Apr 20, 2012 at 05:37:38PM +0800, Wang YanQing wrote:
> On Fri, Apr 20, 2012 at 05:25:25PM +0800, Wang YanQing wrote:
> > Hi!
> > when I execute the command below:
> > 
> > "ls /sys/bus/usb/devices/"
> > 
> > I get:
> > "1-0:1.0 1-1 1-1:1.0 2-0:1.0 2-1 2-1.1 2-1:1.0 2-1.1:1.0 2-1.5 2-1.5:1.0 2-1.5:1.1  usb1  usb2"
> > 
> > the output format is bus-port.port:config.interface
> > I want to know whether the port number is fixed after I reboot machine time by time.
> > And if it is fixed, then what make it.
> > 
> > Thanks!
> 
> Make the question precise.
> I assme there are two usb ports in my notebook at left and right separately.
> When I plug mouse into 
> left usb port, I get 2-1.1:1.0
> right usb port, I get 2-1.2:1.0
> 
> I want to know whether it is right that no matter how many times I reboot the machine,

Not always.

> the test result above will be the same.And if it will be the same, then why it will be the same.

You got lucky :)

USB ports on a hub are all enumerated the same, but the root hubs
aren't, and sometimes hubs on the same bus are not as well.

But usually, things do come up in the same way all the time, so
depending on your use case, you can rely on this, but it is recommended
that you look for something else a bit more unique, like a serial number
on a device (if it is present), if you wish to uniquely identify a
device all the time.

good luck,

greg k-h

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

* Re: [RFC]Is usb port number fixed?
       [not found]     ` <CAHkwNT=VW8qF-7QRxpiaWkmQm0UFdsbahFLhT-PCc4OMnVs1Gg@mail.gmail.com>
@ 2012-04-20 16:19       ` Greg KH
  0 siblings, 0 replies; 15+ messages in thread
From: Greg KH @ 2012-04-20 16:19 UTC (permalink / raw)
  To: Anil Nair; +Cc: Wang YanQing, lkml, linux-usb

<Please don't post HTML email, the mailing lists reject your messages
that way>

On Fri, Apr 20, 2012 at 09:39:37PM +0530, Anil Nair wrote:
> 
> 
>     >USB ports on a hub are all enumerated the same, but the root hubs
>     >aren't, and sometimes hubs on the same bus are not as well.
> 
>  
>   Does every device assigned a port number serially, that is in increasing
> order?

Yes.

>   If a USB port number is assigned to a USB device then are other USB devices
> able to use it,
>   if connected USB device is Disconnected?

It can, why?  USB devices don't care about their device number.

>     >But usually, things do come up in the same way all the time, so
>     >depending on your use case, you can rely on this, but it is recommended
>     >that you look for something else a bit more unique, like a serial number
>     >on a device (if it is present), if you wish to uniquely identify a
>     >device all the time.
> 
> 
>   Does the Linux Kernel keeps the history of connected devices? So that next
> time,   the same USB device get assigned the same USB port number.

No.  I think you are confusing port number with the USB device number,
both of which mean nothing to a USB device at all, and they shouldn't to
anyone else.

greg k-h

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

* Re: [RFC]Is usb port number fixed?
  2012-04-20 15:37   ` Greg KH
       [not found]     ` <CAHkwNT=VW8qF-7QRxpiaWkmQm0UFdsbahFLhT-PCc4OMnVs1Gg@mail.gmail.com>
@ 2012-04-21  0:32     ` Alan Stern
  2012-04-21  5:56       ` Wang YanQing
  1 sibling, 1 reply; 15+ messages in thread
From: Alan Stern @ 2012-04-21  0:32 UTC (permalink / raw)
  To: Greg KH; +Cc: Wang YanQing, lkml, linux-usb

On Fri, 20 Apr 2012, Greg KH wrote:

> > Make the question precise.
> > I assme there are two usb ports in my notebook at left and right separately.
> > When I plug mouse into 
> > left usb port, I get 2-1.1:1.0
> > right usb port, I get 2-1.2:1.0
> > 
> > I want to know whether it is right that no matter how many times I reboot the machine,
> 
> Not always.
> 
> > the test result above will be the same.And if it will be the same, then why it will be the same.
> 
> You got lucky :)
> 
> USB ports on a hub are all enumerated the same, but the root hubs
> aren't, and sometimes hubs on the same bus are not as well.
> 
> But usually, things do come up in the same way all the time, so
> depending on your use case, you can rely on this, but it is recommended
> that you look for something else a bit more unique, like a serial number
> on a device (if it is present), if you wish to uniquely identify a
> device all the time.

In this particular case, it is guaranteed that the left USB port will 
always be numbered as X-1.1:1.0 and the right port as X-1.2:1.0, where 
the number X may change from one boot to another.  But the -1.1:1.0 and 
-1.2:1.0 parts will always be the same.

This is because X is the bus number, which is allowed to change.  The 
-1.1:1.0 and -1.2:1.0 values are port, configuration, and interface 
numbers.  They will never change, because they come from the hardware.

Alan Stern


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

* Re: [RFC]Is usb port number fixed?
  2012-04-21  0:32     ` Alan Stern
@ 2012-04-21  5:56       ` Wang YanQing
  2012-04-21 17:23         ` Alan Stern
  0 siblings, 1 reply; 15+ messages in thread
From: Wang YanQing @ 2012-04-21  5:56 UTC (permalink / raw)
  To: Alan Stern; +Cc: Greg KH, lkml, linux-usb

On Fri, Apr 20, 2012 at 08:32:37PM -0400, Alan Stern wrote:
> In this particular case, it is guaranteed that the left USB port will 
> always be numbered as X-1.1:1.0 and the right port as X-1.2:1.0, where 
> the number X may change from one boot to another.  But the -1.1:1.0 and 
> -1.2:1.0 parts will always be the same.
> 
> This is because X is the bus number, which is allowed to change.  The 
> -1.1:1.0 and -1.2:1.0 values are port, configuration, and interface 
> numbers.  They will never change, because they come from the hardware.
Yes, configuration and interface come from the hardware,
but I don't know where the port come from, at least I don't think the port
comes from the same hardware with the configuration and interface, do you 
mean port come from the hub?

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

* Re: [RFC]Is usb port number fixed?
  2012-04-21  5:56       ` Wang YanQing
@ 2012-04-21 17:23         ` Alan Stern
  0 siblings, 0 replies; 15+ messages in thread
From: Alan Stern @ 2012-04-21 17:23 UTC (permalink / raw)
  To: Wang YanQing; +Cc: Greg KH, lkml, linux-usb

On Sat, 21 Apr 2012, Wang YanQing wrote:

> On Fri, Apr 20, 2012 at 08:32:37PM -0400, Alan Stern wrote:
> > In this particular case, it is guaranteed that the left USB port will 
> > always be numbered as X-1.1:1.0 and the right port as X-1.2:1.0, where 
> > the number X may change from one boot to another.  But the -1.1:1.0 and 
> > -1.2:1.0 parts will always be the same.
> > 
> > This is because X is the bus number, which is allowed to change.  The 
> > -1.1:1.0 and -1.2:1.0 values are port, configuration, and interface 
> > numbers.  They will never change, because they come from the hardware.
> Yes, configuration and interface come from the hardware,
> but I don't know where the port come from, at least I don't think the port
> comes from the same hardware with the configuration and interface, do you 
> mean port come from the hub?

Yes, it does.

Alan Stern


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

* Re: [RFC]Is usb port number fixed?
  2012-04-24 14:14         ` Alan Stern
@ 2012-04-24 15:58           ` Wang YanQing
  0 siblings, 0 replies; 15+ messages in thread
From: Wang YanQing @ 2012-04-24 15:58 UTC (permalink / raw)
  To: Alan Stern; +Cc: Anil Nair, Greg KH, lkml, linux-usb

On Tue, Apr 24, 2012 at 10:14:05AM -0400, Alan Stern wrote:
> In drivers/usb/core/hub.c, look through the hub_events() routine.  
> There are several function calls similar to this one:
> 
> 			ret = hub_port_status(hub, i,
> 					&portstatus, &portchange);
> 
> Here i is the port number.  This asks the hub to send back status and 
> change information for port i.  (See also the code for the 
> hub_port_status() and get_port_status() routines.)

Thanks, I get it.

On Tue, Apr 24, 2012 at 07:52:44PM +0530, anil wrote:
> The USB specification Table 11-13 describes the hub descriptor in
> detail.
> The following data structure struct usb_hub_descriptor defined in
> "drivers/usb/core/hub.h" of Linux  Kernel source contains information
> about the hub descriptor,
> 
>                       struct usb_hub_descriptor {
>                             _u8 bDescLength;
>                           _u8 bDescriptorType;
>                              _u8 bNbrPorts;
>                        _le16 wHubCharacteristics;
>                           _u8 bPwrOn2PwrGood;
>                          _u8 bHubContrCurrent;
>                                    }
> 
> The bNbrPorts  member contains information on the number of
> downstream-facing ports the hub supports. The structure which i have
> provided is in reference to Linux Kernel Version 2.6 series for Linux
> Kernel Version 3.0+, Please consult an expert.
>   	Is this information you wanted?
> 

Yes, It is want I wanted.But maybe "11.5.3.1 Labeling" show more footprint.

Thanks, all guys.
All you give me a very good explanation about the sentence below:

"High quality support from experts available instantly over the Internet at
no charge has played a major role in stitching together a huge Linux community"

which come from the <<Essential Linux Device Drivers>>.

Cheers.

Udknight

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

* Re: [RFC]Is usb port number fixed?
  2012-04-24  2:16       ` Wang YanQing
  2012-04-24 14:14         ` Alan Stern
@ 2012-04-24 14:22         ` anil
  1 sibling, 0 replies; 15+ messages in thread
From: anil @ 2012-04-24 14:22 UTC (permalink / raw)
  To: Wang YanQing; +Cc: Alan Stern, Greg KH, lkml, linux-usb

On Tue, 2012-04-24 at 10:16 +0800, Wang YanQing wrote:
> On Mon, Apr 23, 2012 at 11:13:06AM -0400, Alan Stern wrote:
> > The port numbers are determined by the hardware -- each set of wires
> > has its own port number.  The numbers have nothing to do with
> > bandwidth.
> Could you figure out the codes in kernel that read out the port number from
> hub, if there is a piece of codes do that things?

The USB specification Table 11-13 describes the hub descriptor in
detail.
The following data structure struct usb_hub_descriptor defined in
"drivers/usb/core/hub.h" of Linux  Kernel source contains information
about the hub descriptor,

                      struct usb_hub_descriptor {
                            _u8 bDescLength;
                          _u8 bDescriptorType;
                             _u8 bNbrPorts;
                       _le16 wHubCharacteristics;
                          _u8 bPwrOn2PwrGood;
                         _u8 bHubContrCurrent;
                                   }

The bNbrPorts  member contains information on the number of
downstream-facing ports the hub supports. The structure which i have
provided is in reference to Linux Kernel Version 2.6 series for Linux
Kernel Version 3.0+, Please consult an expert.
  	Is this information you wanted?

Regards
Anil Nair
--



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

* Re: [RFC]Is usb port number fixed?
  2012-04-24  2:16       ` Wang YanQing
@ 2012-04-24 14:14         ` Alan Stern
  2012-04-24 15:58           ` Wang YanQing
  2012-04-24 14:22         ` anil
  1 sibling, 1 reply; 15+ messages in thread
From: Alan Stern @ 2012-04-24 14:14 UTC (permalink / raw)
  To: Wang YanQing; +Cc: Anil Nair, Greg KH, lkml, linux-usb

On Tue, 24 Apr 2012, Wang YanQing wrote:

> On Mon, Apr 23, 2012 at 11:13:06AM -0400, Alan Stern wrote:
> > The port numbers are determined by the hardware -- each set of wires
> > has its own port number.  The numbers have nothing to do with
> > bandwidth.
> Could you figure out the codes in kernel that read out the port number from
> hub, if there is a piece of codes do that things?

In drivers/usb/core/hub.c, look through the hub_events() routine.  
There are several function calls similar to this one:

			ret = hub_port_status(hub, i,
					&portstatus, &portchange);

Here i is the port number.  This asks the hub to send back status and 
change information for port i.  (See also the code for the 
hub_port_status() and get_port_status() routines.)

Alan Stern


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

* Re: [RFC]Is usb port number fixed?
  2012-04-23 15:13     ` Alan Stern
  2012-04-24  2:16       ` Wang YanQing
@ 2012-04-24  2:24       ` Wang YanQing
  1 sibling, 0 replies; 15+ messages in thread
From: Wang YanQing @ 2012-04-24  2:24 UTC (permalink / raw)
  To: Alan Stern; +Cc: Anil Nair, Greg KH, lkml, linux-usb

On Mon, Apr 23, 2012 at 11:13:06AM -0400, Alan Stern wrote:
> > Indeed, I never meat the situation lspci output different bus number on the same machine.
> > Any more comment?
> 
> Try unloading ehci-hcd, uhci-hcd, and ohci-hcd, and then reloading them 
> in different orders.  Depending on what sort of hardware you have, the 
> bus numbers will change.
Yes, usb host control live on the pci bus, depend on the usb host control probe order,
and usb bus register order, the usb bus number maybe change,
I make a mistake between the pci bus number and usb bus number.

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

* Re: [RFC]Is usb port number fixed?
  2012-04-23 15:13     ` Alan Stern
@ 2012-04-24  2:16       ` Wang YanQing
  2012-04-24 14:14         ` Alan Stern
  2012-04-24 14:22         ` anil
  2012-04-24  2:24       ` Wang YanQing
  1 sibling, 2 replies; 15+ messages in thread
From: Wang YanQing @ 2012-04-24  2:16 UTC (permalink / raw)
  To: Alan Stern; +Cc: Anil Nair, Greg KH, lkml, linux-usb

On Mon, Apr 23, 2012 at 11:13:06AM -0400, Alan Stern wrote:
> The port numbers are determined by the hardware -- each set of wires
> has its own port number.  The numbers have nothing to do with
> bandwidth.
Could you figure out the codes in kernel that read out the port number from
hub, if there is a piece of codes do that things?

Thanks very much.

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

* Re: [RFC]Is usb port number fixed?
  2012-04-23  1:52   ` Wang YanQing
@ 2012-04-23 15:13     ` Alan Stern
  2012-04-24  2:16       ` Wang YanQing
  2012-04-24  2:24       ` Wang YanQing
  0 siblings, 2 replies; 15+ messages in thread
From: Alan Stern @ 2012-04-23 15:13 UTC (permalink / raw)
  To: Wang YanQing; +Cc: Anil Nair, Greg KH, lkml, linux-usb

On Mon, 23 Apr 2012, Wang YanQing wrote:

> On Sun, Apr 22, 2012 at 08:47:24AM -0400, Alan Stern wrote:
> > On Sun, 22 Apr 2012, Anil Nair wrote:
> > 
> > > The port number comes from root hub managed by the host controller. Its
> > > fixed dynamically during enumeration, and can change.
> > > Please correct me if i am wrong.
> > 
> > You are indeed wrong.  Port numbers are not fixed dynamically and they 
> > cannot change.
> Right?

Right.

> Could you pin out the codes in kernel?

I don't understand the question.  What code in the kernel do you want 
to see?

> > On the other hand, bus numbers _are_ assigned dynamically and they can 
> > (and do) change.
> > 
> Indeed, I never meat the situation lspci output different bus number on the same machine.
> Any more comment?

Try unloading ehci-hcd, uhci-hcd, and ohci-hcd, and then reloading them 
in different orders.  Depending on what sort of hardware you have, the 
bus numbers will change.


On Mon, 23 Apr 2012, Anil Nair wrote:

>   You meant to say port numbers are fixed but bus address changes
> dynamically, also does the host controller
>   fixes the port number?

Yes.

> If USB Bus bandwidth is not available, how does it
> assign port numbers?

The port numbers are determined by the hardware -- each set of wires
has its own port number.  The numbers have nothing to do with
bandwidth.

Alan Stern


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

* Re: [RFC]Is usb port number fixed?
  2012-04-22 12:47 ` Alan Stern
@ 2012-04-23  1:52   ` Wang YanQing
  2012-04-23 15:13     ` Alan Stern
  0 siblings, 1 reply; 15+ messages in thread
From: Wang YanQing @ 2012-04-23  1:52 UTC (permalink / raw)
  To: Alan Stern; +Cc: Anil Nair, Greg KH, lkml, linux-usb

On Sun, Apr 22, 2012 at 08:47:24AM -0400, Alan Stern wrote:
> On Sun, 22 Apr 2012, Anil Nair wrote:
> 
> > The port number comes from root hub managed by the host controller. Its
> > fixed dynamically during enumeration, and can change.
> > Please correct me if i am wrong.
> 
> You are indeed wrong.  Port numbers are not fixed dynamically and they 
> cannot change.
Right?
Could you pin out the codes in kernel?
> 
> On the other hand, bus numbers _are_ assigned dynamically and they can 
> (and do) change.
> 
Indeed, I never meat the situation lspci output different bus number on the same machine.
Any more comment?

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

* Re: [RFC]Is usb port number fixed?
       [not found] <CAHkwNT=DTjdhZmEg+SFGOVi+ZcS-NpHWH8Hh3XV+-BPzHRC7NA@mail.gmail.com>
@ 2012-04-22 12:47 ` Alan Stern
  2012-04-23  1:52   ` Wang YanQing
  0 siblings, 1 reply; 15+ messages in thread
From: Alan Stern @ 2012-04-22 12:47 UTC (permalink / raw)
  To: Anil Nair; +Cc: Wang YanQing, Greg KH, lkml, linux-usb

On Sun, 22 Apr 2012, Anil Nair wrote:

> The port number comes from root hub managed by the host controller. Its
> fixed dynamically during enumeration, and can change.
> Please correct me if i am wrong.

You are indeed wrong.  Port numbers are not fixed dynamically and they 
cannot change.

On the other hand, bus numbers _are_ assigned dynamically and they can 
(and do) change.

Alan Stern


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

end of thread, other threads:[~2012-04-24 15:58 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-20  9:25 [RFC]Is usb port number fixed? Wang YanQing
2012-04-20  9:37 ` Wang YanQing
2012-04-20 15:37   ` Greg KH
     [not found]     ` <CAHkwNT=VW8qF-7QRxpiaWkmQm0UFdsbahFLhT-PCc4OMnVs1Gg@mail.gmail.com>
2012-04-20 16:19       ` Greg KH
2012-04-21  0:32     ` Alan Stern
2012-04-21  5:56       ` Wang YanQing
2012-04-21 17:23         ` Alan Stern
     [not found] <CAHkwNT=DTjdhZmEg+SFGOVi+ZcS-NpHWH8Hh3XV+-BPzHRC7NA@mail.gmail.com>
2012-04-22 12:47 ` Alan Stern
2012-04-23  1:52   ` Wang YanQing
2012-04-23 15:13     ` Alan Stern
2012-04-24  2:16       ` Wang YanQing
2012-04-24 14:14         ` Alan Stern
2012-04-24 15:58           ` Wang YanQing
2012-04-24 14:22         ` anil
2012-04-24  2:24       ` Wang YanQing

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.