From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Wed, 03 Dec 2008 23:54:31 +0000 Subject: Re: Udev rule for HSDPA modem Message-Id: <1228348471.6977.22.camel@nga> MIME-Version: 1 Content-Type: multipart/mixed; boundary="=-+9DRyvManvyfdBSx/y6c" List-Id: References: In-Reply-To: To: linux-hotplug@vger.kernel.org --=-+9DRyvManvyfdBSx/y6c Content-Type: text/plain Content-Transfer-Encoding: 7bit On Wed, 2008-12-03 at 15:10 -0800, Greg KH wrote: > On Wed, Dec 03, 2008 at 04:11:29PM +0100, Kay Sievers wrote: > > On Wed, 2008-12-03 at 13:12 +0100, Kay Sievers wrote: > > > On Wed, Dec 3, 2008 at 10:27, Kay Sievers wrote: > > > > On Wed, Dec 3, 2008 at 07:45, Greg KH wrote: > > > >> On Sun, Nov 30, 2008 at 06:21:11AM +0100, Kay Sievers wrote: > > > >>> On Sat, Nov 29, 2008 at 18:37, Greg KH wrote: > > > >>> > On Sat, Nov 29, 2008 at 10:00:59AM +0200, Jar wrote: > > > >>> >> Greg KH wrote: > > > >>> >>> HAL contains a list of these modems and a mapping of each port to what > > > >>> >>> it does based on the specific device. > > > >>> >>> Try using that instead of udev specific rules for your accessed to the > > > >>> >>> modem, it will work much better. > > > >>> >> > > > >>> >> Thanks for your reply! Does HAL require that I have desktop installed, this > > > >>> >> is my home "server" machine without X? Do you have any starting point or > > > >>> >> where to learn more how to do this with HAL. > > > >>> > > > > >>> > I do not think HAL requires X. Try asking on your distro mailing list > > > >>> > for how they have incorporated HAL into the releases you are using. > > > >>> > > > >>> It might get pretty complicated to use D-Bus/HAL for simple setups, > > > >>> and rather static configurations like this. NetworkManager handles > > > >>> that, and we will even get modem-probing soon, but in cases like this > > > >>> it might be easier to have a simple - not very flexible - but working > > > >>> solution. > > > >>> > > > >>> Maybe we can have an "index" sysfs file at the serial device, which > > > >>> carries the instance number, per usb device? This would allow us to > > > >>> create persistent links which do not depend on the kernel device > > > >>> enumeration across multiple device. > > > >>> > > > >>> We did the same for v4l devices recently: > > > >>> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=539a7555b31e65e66fb84c881d07d2bf18c974d0 > > > >>> > > > >>> Greg, what do you think? > > > >> > > > >> Don't we already have something like this today (the "ports" on an > > > >> individual usb-serial device)? Or do we just need to export that a bit > > > >> better? > > > > > > > > Yeah, maybe that works already. I don't have such a device. > > > > > > Ok, I found one. You mean "port_number", right? But unfortunately it > > > looks pretty useless in this case. :) > > > > > > $ grep . /sys/bus/usb-serial/devices/*/port_number > > > /sys/bus/usb-serial/devices/ttyUSB1/port_number:0 > > > /sys/bus/usb-serial/devices/ttyUSB2/port_number:0 > > > > > > They would only be not "0" if the serial lines would be on the same > > > usb interface? > > > > > > We would need a per-device enumeration, but that's nothing the > > > usb-serial stuff knows/cares about if we have different usb > > > interfaces, right? > > > > Greg, do you have a usb multi-port serial card? Can you possibly give > > this a try, and show us "tree /dev/serial"? > > > > I have this here now for my "simple" devices: > > /dev/serial > > `-- by-id > > |-- usb-067b_2303-serial-if00-port0 -> ../../ttyUSB0 > > |-- usb-HUAWEI_Technology_HUAWEI_Mobile-serial-if00-port0 -> ../../ttyUSB1 > > `-- usb-HUAWEI_Technology_HUAWEI_Mobile-serial-if01-port0 -> ../../ttyUSB2 > > > > If we can make that work as expected, I'll look into by-path/, so we can > > have identical devices properly identified, if needed. Then we can check > > how we should finally name all that, and possibly add that stuff to the > > default rule set. > > > This looks good, here's the output using udev 133 and the rules and a > few usb-serial devices plugged into the system at the same time: > > $ tree /dev/serial/ > /dev/serial/ > `-- by-id > |-- usb-Inside_Out_Networks_Edgeport > | |-- 4_04-01-006467-serial-if00-port0 -> ../../../ttyUSB0 > | |-- 4_04-01-006467-serial-if00-port1 -> ../../../ttyUSB1 > | |-- 4_04-01-006467-serial-if00-port2 -> ../../../ttyUSB2 > | `-- 4_04-01-006467-serial-if00-port3 -> ../../../ttyUSB3 > |-- usb-Keyspan__a_division_of_InnoSys_Inc._USB_4-port_Serial_Adapter-serial-if00-port0 -> ../../ttyUSB8 > |-- usb-Keyspan__a_division_of_InnoSys_Inc._USB_4-port_Serial_Adapter-serial-if00-port1 -> ../../ttyUSB9 > |-- usb-Keyspan__a_division_of_InnoSys_Inc._USB_4-port_Serial_Adapter-serial-if00-port2 -> ../../ttyUSB10 > |-- usb-Keyspan__a_division_of_InnoSys_Inc._USB_4-port_Serial_Adapter-serial-if00-port3 -> ../../ttyUSB11 > |-- usb-Prolific_Technology_Inc._USB-Serial_Controller-serial-if00-port0 -> ../../ttyUSB7 > |-- usb-Sierra_Wireless__Incorporated_AirCard-serial-if00-port0 -> ../../ttyUSB4 > |-- usb-Sierra_Wireless__Incorporated_AirCard-serial-if00-port1 -> ../../ttyUSB5 > `-- usb-Sierra_Wireless__Incorporated_AirCard-serial-if00-port2 -> ../../ttyUSB6 > > I'm not so sure about the long names, but it is unique :) Yeah, it looks really strange with your devices. Why put people poetry in the device strings? :) But it seems to work, which is great. Here is a new version of the serial.rules and a /lib/udev/path_id which needs to be replaced. Can you try that again on your "collection"? :) Thanks, Kay --=-+9DRyvManvyfdBSx/y6c Content-Description: Content-Type: application/x-shellscript Content-Disposition: inline; filename="path_id" Content-Transfer-Encoding: 7bit #!/bin/sh # provide the shortest possible unique hardware path to a device # for the Linux Persistent Device Naming scheme # # Copyright (C) 2005-2006 SUSE Linux Products GmbH # Author: # Hannes Reinecke # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation version 2 of the License. SYSFS=/sys RESULT=1 TYPE= OPWD="`pwd`" full_sysfs_path= full_sysfs_device_path= if [ -z "$DEVPATH" -a -z "$1" ] ; then exit 1 fi if [ -z "$DEVPATH" ] ; then case "$1" in $SYSFS/*) DEVPATH="${1#$SYSFS}" ;; *) DEVPATH=$1 ;; esac fi if [ ! -e $SYSFS$DEVPATH/dev ] ; then exit 1 fi case "$DEVPATH" in /devices/*) cd "$SYSFS$DEVPATH/subsystem"; TYPE="`pwd -P`" cd "$OPWD" TYPE="${TYPE##*/}" ;; /class/*) TYPE="${DEVPATH#/class/}" TYPE="${TYPE%%/*}" ;; /block/*) TYPE=block ;; *) exit 1 ;; esac get_port_offset () { local type offset port type=$1 offset=$2 for i in $type[0-9]* ; do : i $i port="${i#$type}" if [ "$port" -lt "$offset" ] ; then offset=$port ; fi done echo $offset } handle_pci () { local DEV=$1 cd -P $1 DEV=${PWD} pci_id=${DEV##*/} host_dev_path=$DEV # cciss devices don't have a separate sysfs node for blk_link in block*; do if [ -L "$blk_link" ]; then case "$blk_link" in *cciss*) d=cciss-${blk_link#*cciss\!} ;; esac fi done while [ ! -z "$host_dev_path" ] ; do case "$host_dev_path" in */pci[0-9]*) host_dev_path=${host_dev_path%/*} ;; *) break ;; esac done if [ "$d" ]; then d="pci-$pci_id-$d" else d="pci-$pci_id" fi D="$host_dev_path" RESULT=0 } handle_platform () { local DEV=$1 cd -P $1 DEV=${PWD} platform_id=${DEV##*/} host_dev_path=$DEV while [ ! -z "$host_dev_path" ] ; do case "$host_dev_path" in */platform*) host_dev_path=${host_dev_path%/*} ;; *) break ;; esac done if [ "$d" ]; then d="platform-$platform_id-$d" else d="platform-$platform_id" fi D="$host_dev_path" RESULT=0 } handle_serio () { local DEV=$1 cd -P $1 DEV=${PWD} serio_id=${DEV##*/serio} host_dev_path=$DEV while [ ! -z "$host_dev_path" ] ; do case "$host_dev_path" in */serio*) host_dev_path=${host_dev_path%/*} ;; *) break ;; esac done if [ "$d" ]; then d="serio-$serio_id-$d" else d="serio-$serio_id" fi D="$host_dev_path" RESULT=0 } handle_ide () { : handle_ide $* local DEV=$1 local port idedev idecontroller # IDE : DEV $DEV port=${DEV##*/} idedev=${DEV%/*} idecontroller=${idedev%/*} # port info if the controller has more than one interface port="${port#ide}" : port $port d $d : idedev $idedev kernel_port $port case "${port#*.}" in 0) channel=0 ;; 1) channel=1 ;; *) echo "Error: $idedev is neither master or slave" >&2 ;; esac cd $idecontroller offset="`get_port_offset ide ${port%.*}`" cd "$OPWD" : port offset $offset port=$((${port%.*} - $offset)) if [ "$d" ] ; then d="ide-${port}:$channel-$d" else d="ide-${port}:$channel" fi D=$idecontroller RESULT=0 } handle_scsi () { : handle_scsi $* local DEV=$1 local cil controller_port controller_dev # SCSI device cil="${DEV##*/}" cil="${cil#*:}" target_dev=${DEV%/*} target_id=${target_dev##*/target} cd "$target_dev" target_num=0 for tid in ${target_id}* ; do target_num=$(( $target_num + 1 )) done controller_port=${target_dev%/*} controller_dev="${controller_port%/*}" : controller_dev $controller_dev : controller_port $controller_port # a host controller may have more than one interface/port controller_port="${controller_port##*/host}" # cd "$controller_dev" controller_offset=$(get_port_offset host $controller_port) cd "$OPWD" controller_port=$(( $controller_port - $controller_offset)) scsi_id="scsi-${controller_port}:${cil}" if [ "$d" ] ; then d="${scsi_id}-$d" else d="$scsi_id" fi D="$controller_dev" RESULT=0 } handle_firewire () { : handle_firewire $* local DEV=$1 if [ -f "$D/ieee1394_id" ] ; then read ieee1394_id < $D/ieee1394_id fi if [ -z "$ieee1394_id" ] ; then : no IEEE1394 ID RESULT=1 return fi fw_host_dev=${DEV%/fw-host*} # IEEE1394 devices are always endpoints d="ieee1394-0x$ieee1394_id" D="$fw_host_dev" RESULT=0 } handle_fc () { : handle_fc $* local DEV=$1 local cil controller_port controller_dev # SCSI-FC device fc_tgt_hcil="${DEV##*/}" fc_tgt_lun="${fc_tgt_hcil##*:}" fc_tgt_path="${DEV%/*}" fc_tgt_num="${fc_tgt_path##*/}" fc_tgt_dev="${fc_tgt_path}/fc_transport/${fc_tgt_num}" if [ -e "$fc_tgt_dev/port_name" ]; then read wwpn < $fc_tgt_dev/port_name fi if [ -z "$wwpn" ] ; then : no WWPN D= RESULT=1 return fi # Linux currently knows about 32bit luns tmp_lun3=$(printf "%04x" $(($fc_tgt_lun & 0xFFFF))) tmp_lun2=$(printf "%04x" $(( ($fc_tgt_lun >> 16) & 0xFFFF))) tmp_lun1="0000" tmp_lun0="0000" if (($fc_tgt_lun == 0)) ; then lun="0x0000000000000000" else lun="0x${tmp_lun3}${tmp_lun2}${tmp_lun1}${tmp_lun0}" fi controller_dev="${fc_tgt_path%/host[0-9]*}" # FC devices are always endpoints d="fc-${wwpn}:${lun}" D="$controller_dev" RESULT=0 } handle_sas () { : handle_sas $* local DEV=$1 local cil adapter controller_dev # SAS device sas_host_path="${DEV%%/port*}" sas_phy_path="${DEV#*/host*/}" sas_phy_path="${sas_phy_path%%/target*}" sas_phy_id="${sas_phy_path%%/*}" sas_phy_id="${sas_phy_id##*port-}" sas_port_id="${sas_phy_path%%/end_device*}" sas_port_id="${sas_port_id##*port-}" sas_end_id="${sas_phy_path##*end_device-}" sas_phy_dev="/sys/class/sas_phy/phy-${sas_phy_id}" if [ -e "$sas_phy_dev/sas_address" ]; then read phy_address < $sas_phy_dev/sas_address read phy_id < $sas_phy_dev/phy_identifier fi if [ -z "$phy_address" ] ; then : no initiator address D= RESULT=1 return fi sas_port_dev="/sys/class/sas_port/port-${sas_port_id}" if [ -e "$sas_port_dev/num_phys" ] ; then read phy_port < $sas_port_dev/num_phys fi if [ -z "$phy_port" ] ; then : no initiator address D= RESULT=1 return fi sas_phy_address="$phy_address:$phy_port:$phy_id" sas_end_dev="/sys/class/sas_device/end_device-${sas_end_id}" if [ -e "$sas_end_dev/sas_address" ]; then read end_address < $sas_end_dev/sas_address read end_id < $sas_end_dev/phy_identifier fi if [ -z "$end_address" ] ; then : no initiator address D= RESULT=1 return fi sas_end_address="$end_address:$end_id" controller_dev="${sas_host_path%/host[0-9]*}" # SAS devices are always endpoints d="sas-${sas_phy_address}-${sas_end_address}" D="$controller_dev" RESULT=0 } handle_iscsi() { local DEV=$1 local iscsi_session_dir local iscsi_session iscsi_session_path local iscsi_connection iscsi_connection_path local iscsi_scsi_lun # iSCSI device iscsi_session_dir="${DEV%%/target*}" iscsi_session="${iscsi_session_dir##*/}" iscsi_session_path=/sys/class/iscsi_session/${iscsi_session} if [ ! -d "$iscsi_session_path" ] ; then : no iSCSI session path RESULT=1 return fi # Currently we're not doing MC/S for conn in ${iscsi_session_dir}/connection* ; do iscsi_conn_num=${conn##*:} if [ "$iscsi_conn_num" = '0' ] ; then iscsi_connection=$(basename $conn) fi done if [ -z "$iscsi_connection" ] ; then : no iSCSI connection found RESULT=1 return fi iscsi_connection_path=/sys/class/iscsi_connection/${iscsi_connection} if [ ! -d "$iscsi_connection_path" ] ; then : no iSCSI connection path RESULT=1 return fi if [ -e "${iscsi_session_path}/targetname" ]; then read iscsi_tgtname < ${iscsi_session_path}/targetname fi if [ -z "$iscsi_tgtname" ] ; then : No iSCSI Targetname RESULT=1 return fi if [ -e "${iscsi_connection_path}/persistent_address" ] ; then read iscsi_address < ${iscsi_connection_path}/persistent_address fi if [ -z "$iscsi_address" ] ; then : No iSCSI Target address RESULT=1 return fi if [ -e "${iscsi_connection_path}/persistent_port" ] ; then read iscsi_port < ${iscsi_connection_path}/persistent_port fi iscsi_scsi_lun="${DEV##*:}" d="ip-${iscsi_address}:${iscsi_port}-iscsi-${iscsi_tgtname}-lun-${iscsi_scsi_lun}" RESULT=0 } handle_usb () { : handle_usb $* local DEV=$1 cd -P $1 DEV=${PWD} port_id=${DEV##*/} port_num=${port_id#*-} host_dev_path=$DEV while [ ! -z "$host_dev_path" ] ; do case "$host_dev_path" in */usb*) usb_host_path=$host_dev_path host_dev_path="${host_dev_path%/*}" ;; *) break ;; esac done : host_dev_path $host_dev_path usb_host_num=${usb_host_path##*/usb} cd "$host_dev_path" usb_host_offset=$(get_port_offset usb $usb_host_num) usb_host_port=$(($usb_host_num - $usb_host_offset)) cd "$OPWD" if [ "$d" ] ; then d="usb-$usb_host_port:$port_num-${d}" else d="usb-$usb_host_port:$port_num" fi D="$host_dev_path" RESULT=0 } handle_device () { full_sysfs_path="$SYSFS$DEVPATH" case "$DEVPATH" in /devices/*) full_sysfs_path="${full_sysfs_path%/*}" # skip parent device of the same subsystem if [ -L $full_sysfs_path/subsystem ]; then cd "$full_sysfs_path/subsystem"; subsys="`pwd -P`" cd "$OPWD" subsys="${subsys##*/}" if [ "$subsys" = "$TYPE" ]; then : skip same subsystem parent full_sysfs_path="${full_sysfs_path%/*}" fi fi # skip subsystem directory subsys="${full_sysfs_path##*/}" if [ "$subsys" = "$TYPE" ]; then : skip subsystem directory full_sysfs_path="${full_sysfs_path%/*}" fi cd $full_sysfs_path ;; *) # old sysfs layout if [ ! -L $full_sysfs_path/device ]; then full_sysfs_path="${full_sysfs_path%/*}" : full_sysfs_path "$full_sysfs_path" if [ ! -L $full_sysfs_path/device -o ! -f $full_sysfs_path/dev ]; then return fi fi if [ -L $full_sysfs_path/device/device ]; then cd $full_sysfs_path/device/device else cd $full_sysfs_path/device fi ;; esac full_sysfs_device_path="`pwd -P`" cd "$OPWD" D=$full_sysfs_device_path while [ ! -z "$D" ] ; do case "$D" in */ide[0-9]/[0-9].[0-9]*|*/ide[0-9][0-9]/[0-9][0-9].[0-9]*) handle_ide "$D" ;; */css0/*) if [ -r $full_sysfs_device_path/wwpn ]; then read wwpn < $full_sysfs_device_path/wwpn fi if [ -r $full_sysfs_device_path/fcp_lun ]; then read lun < $full_sysfs_device_path/fcp_lun fi if [ -r $full_sysfs_device_path/hba_id ]; then read bus_id < $full_sysfs_device_path/hba_id fi if [ "$bus_id" -a "$wwpn" -a "$lun" ]; then # S/390 zfcp adapter d="ccw-$bus_id-zfcp-$wwpn:$lun" RESULT=0 else # DASD devices bus="ccw" adapter=${D##*/} d="$bus-$adapter" RESULT=0 fi D= ;; */rport-[0-9]*:[0-9]*-[0-9]*/*) handle_fc "$D" ;; */end_device-[0-9]*:[0-9]*:[0-9]*/*) handle_sas "$D" ;; */fw-host[0-9]*/*) handle_firewire "$D" ;; */session[0-9]*/*) handle_iscsi "$D" D= ;; */host[0-9]*/[0-9]*:[0-9]*:[0-9]*:[0-9]*) handle_scsi "$D" ;; */ttyUSB*) D=${D%/ttyUSB*} ;; */usb[0-9]*/[0-9]*/*) handle_usb "$D" ;; */pci[0-9]*:[0-9]*) handle_pci "$D" ;; */serio[0-9]*) handle_serio "$D" ;; */platform/*) handle_platform "$D" ;; */devices) D= ;; *) : not handled RESULT=1 return ;; esac done if [ "$TYPE" = "scsi_tape" ] ; then devname=${full_sysfs_path##*/} rewind="${devname%%st*}" mode="${devname##*st}" case "$mode" in *l) mode="l" ;; *m) mode="m" ;; *a) mode="a" ;; *) mode="" ;; esac if [ "$d" ]; then d="$d-${rewind}st${mode}" fi fi } handle_device if [ -z "$d" ]; then exit 1 fi echo "ID_PATH=$d" exit 0 --=-+9DRyvManvyfdBSx/y6c Content-Description: Content-Disposition: inline; filename="60-persistent-serial.rules" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit # do not edit this file, it will be overwritten on update ACTION!="add|change", GOTO="persistent_serial_end" SUBSYSTEM!="tty", GOTO="persistent_serial_end" KERNEL!="ttyUSB[0-9]*", GOTO="persistent_serial_end" SUBSYSTEMS=="usb-serial", ENV{ID_PORT}="$attr{port_number}" ENV{ID_PORT}=="", GOTO="persistent_serial_end" IMPORT="path_id" ENV{ID_PATH}=="?*", SYMLINK+="serial/by-path/$env{ID_PATH}-port$env{ID_PORT}" IMPORT="usb_id --export" ENV{ID_SERIAL}=="", GOTO="persistent_serial_end" SUBSYSTEMS=="usb", ENV{ID_IFACE}="$attr{bInterfaceNumber}" ENV{ID_IFACE}=="", GOTO="persistent_serial_end" SYMLINK+="serial/by-id/$env{ID_BUS}-$env{ID_SERIAL}-if$env{ID_IFACE}-port$env{ID_PORT}" LABEL="persistent_serial_end" --=-+9DRyvManvyfdBSx/y6c--