xpp: perl_modules: Remove /proc/xpp usage

* All references to old /proc/xpp interface were removed.
* Everything is now done via sysfs

Information has been available from /sys/bus/astribanks since before
Dahdi-linux 2.2 .

Signed-off-by: Oron Peled <oron.peled@xorcom.com>
Acked-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>

git-svn-id: http://svn.astersk.org/svn/dahdi/tools/trunk@10492 17933a7a-c749-41c5-a318-cba88f637d49
This commit is contained in:
Oron Peled 2012-03-15 20:30:41 +00:00 committed by Tzafrir Cohen
parent 971a45a807
commit 6027d2d1d1
7 changed files with 26 additions and 180 deletions

View File

@ -34,7 +34,6 @@ hardware and loaded Dahdi devices.
our $virt_base; our $virt_base;
our $proc_dahdi_base; our $proc_dahdi_base;
our $proc_xpp_base;
our $proc_usb_base; our $proc_usb_base;
our $sys_base; our $sys_base;

View File

@ -32,7 +32,6 @@ BEGIN {
$Dahdi::virt_base = ''; $Dahdi::virt_base = '';
} }
$Dahdi::proc_dahdi_base = "$Dahdi::virt_base/proc/dahdi"; $Dahdi::proc_dahdi_base = "$Dahdi::virt_base/proc/dahdi";
$Dahdi::proc_xpp_base = "$Dahdi::virt_base/proc/xpp";
$Dahdi::proc_usb_base = "$Dahdi::virt_base/proc/bus/usb"; $Dahdi::proc_usb_base = "$Dahdi::virt_base/proc/bus/usb";
$Dahdi::sys_base = "$Dahdi::virt_base/sys"; $Dahdi::sys_base = "$Dahdi::virt_base/sys";
} }

View File

@ -104,7 +104,7 @@ sub by_xpporder {
=head1 xbuses([sort_order]) =head1 xbuses([sort_order])
Scans system (/proc and /sys) and returns a list of Astribank (Xbus) Scans system (via /sys) and returns a list of Astribank (Xbus)
objects. The optional parameter sort_order is the order in which objects. The optional parameter sort_order is the order in which
the Astribanks will be returns: the Astribanks will be returns:
@ -249,53 +249,17 @@ sub xpd_of_span($) {
Gets (and optionally sets) the internal Astribanks synchronization Gets (and optionally sets) the internal Astribanks synchronization
source. When used to set sync source, returns the original sync source. source. When used to set sync source, returns the original sync source.
A synchronization source is a value valid writing into /proc/xpp/sync . A synchronization source is a value valid writing into
/sys/bus/astribanks/drivers/xppdrv/sync
For more information read that file and see README.Astribank . For more information read that file and see README.Astribank .
=cut =cut
sub sync_via_proc {
my $newsync = shift;
my $result;
my $newapi = 0;
my $proc_base = $Dahdi::proc_xpp_base;
my $file = "$proc_base/sync";
return '' unless -f $file;
# First query
open(F, "$file") or die "Failed to open $file for reading: $!";
while(<F>) {
chomp;
/SYNC=/ and $newapi = 1;
s/#.*//;
if(/\S/) { # First non-comment line
s/^SYNC=\D*// if $newapi;
$result = $_;
last;
}
}
close F;
if(defined($newsync)) { # Now change
$newsync =~ s/.*/\U$&/;
if($newsync =~ /^(\d+)$/) {
$newsync = ($newapi)? "SYNC=$1" : "$1 0";
} elsif($newsync ne 'DAHDI') {
die "Bad sync parameter '$newsync'";
}
open(F, ">$file") or die "Failed to open $file for writing: $!";
print F $newsync;
close(F) or die "Failed in closing $file: $!";
}
return $result;
}
sub sync { sub sync {
my ($newsync) = @_; my ($newsync) = @_;
my $result; my $result;
my $file = "$sysfs_ab_driver/sync"; my $file = "$sysfs_ab_driver/sync";
if(! -f $file) { # Old /proc interface die "Missing '$file'\n" unless -f $file;
return sync_via_proc(@_);
}
open(F, "$file") or die "Failed to open $file for reading: $!"; open(F, "$file") or die "Failed to open $file for reading: $!";
$result = <F>; $result = <F>;
close F; close F;

View File

@ -42,7 +42,6 @@ sub blink($$) {
sub create_all($$) { sub create_all($$) {
my $pack = shift or die "Wasn't called as a class method\n"; my $pack = shift or die "Wasn't called as a class method\n";
my $xpd = shift || die; my $xpd = shift || die;
my $procdir = shift || die;
local $/ = "\n"; local $/ = "\n";
my @lines; my @lines;
for(my $i = 0; $i < $xpd->{CHANNELS}; $i++) { for(my $i = 0; $i < $xpd->{CHANNELS}; $i++) {
@ -52,37 +51,14 @@ sub create_all($$) {
$xpd->{LINES} = \@lines; $xpd->{LINES} = \@lines;
if($xpd->type eq 'FXO') { if($xpd->type eq 'FXO') {
my $battery = $xpd->xpd_getattr("fxo_battery"); my $battery = $xpd->xpd_getattr("fxo_battery");
if(defined $battery) { die "Missing '$battery' attribute\n" unless defined $battery;
my @batt = split(/\s+/, $battery); my @batt = split(/\s+/, $battery);
foreach my $l (@lines) { foreach my $l (@lines) {
die unless @batt; die unless @batt;
my $state = shift @batt; my $state = shift @batt;
$l->{BATTERY} = ($state eq '+') ? 1 : 0; $l->{BATTERY} = ($state eq '+') ? 1 : 0;
}
} else {
# Fallback to old interface
my ($infofile) = glob "$procdir/*_info";
die "Failed globbing '$procdir/*_info'" unless defined $infofile;
open(F, "$infofile") || die "Failed opening '$infofile': $!";
my $battery_info = 0;
while (<F>) {
chomp;
$battery_info = 1 if /^Battery:/;
if($battery_info && s/^\s*on\s*:\s*//) {
my @batt = split;
foreach my $l (@lines) {
die unless @batt;
my $state = shift @batt;
$l->{BATTERY} = ($state eq '+') ? 1 : 0;
}
$battery_info = 0;
die if @batt;
}
}
close F;
} }
} }
close F;
} }

View File

@ -51,12 +51,6 @@ sub xbus_attr_path($$) {
my ($busnum, @attr) = @_; my ($busnum, @attr) = @_;
foreach my $attr (@attr) { foreach my $attr (@attr) {
my $file = sprintf "$Dahdi::Xpp::sysfs_astribanks/xbus-%02d/$attr", $busnum; my $file = sprintf "$Dahdi::Xpp::sysfs_astribanks/xbus-%02d/$attr", $busnum;
unless(-f $file) {
my $procfile = sprintf "$Dahdi::proc_xpp_base/XBUS-%02d/$attr", $busnum;
warn "$0: warning - OLD DRIVER: missing '$file'. Fall back to '$procfile'\n"
unless $file_warned{$attr}++;
$file = $procfile;
}
next unless -f $file; next unless -f $file;
return $file; return $file;
} }
@ -109,21 +103,6 @@ sub transport_type($$) {
return $xbus->{TRANSPORT_TYPE}; return $xbus->{TRANSPORT_TYPE};
} }
sub read_xpdnames_old($) {
my $xbus_num = shift || die;
my $pat = sprintf "$Dahdi::proc_xpp_base/XBUS-%02d/XPD-[0-9][0-9]", $xbus_num;
my @xpdnames;
#print STDERR "read_xpdnames_old($xbus_num): $pat\n";
foreach (glob $pat) {
die "Bad /proc entry: '$_'" unless /^.*XPD-([0-9])([0-9])$/;
my $name = sprintf("%02d:%1d:%1d", $xbus_num, $1, $2);
#print STDERR "\t> $_ ($name)\n";
push(@xpdnames, $name);
}
return @xpdnames;
}
sub read_xpdnames($) { sub read_xpdnames($) {
my $xbus_num = shift || die; my $xbus_num = shift || die;
my $xbus_dir = "$Dahdi::Xpp::sysfs_astribanks/xbus-$xbus_num"; my $xbus_dir = "$Dahdi::Xpp::sysfs_astribanks/xbus-$xbus_num";
@ -141,8 +120,6 @@ sub read_xpdnames($) {
return @xpdnames; return @xpdnames;
} }
my $warned_notransport = 0;
sub new($$) { sub new($$) {
my $pack = shift or die "Wasn't called as a class method\n"; my $pack = shift or die "Wasn't called as a class method\n";
my $num = shift; my $num = shift;
@ -164,17 +141,11 @@ sub new($$) {
} }
my @xpdnames; my @xpdnames;
my @xpds; my @xpds;
if(-e $transport) { die "OLD DRIVER: missing '$transport'\n" unless -e $transport;
@xpdnames = read_xpdnames($num); @xpdnames = read_xpdnames($num);
} else {
@xpdnames = read_xpdnames_old($num);
warn "$0: warning - OLD DRIVER: missing '$transport'. Fall back to /proc\n"
unless $warned_notransport++;
}
foreach my $xpdstr (@xpdnames) { foreach my $xpdstr (@xpdnames) {
my ($busnum, $unit, $subunit) = split(/:/, $xpdstr); my ($busnum, $unit, $subunit) = split(/:/, $xpdstr);
my $procdir = "$Dahdi::proc_xpp_base/XBUS-$busnum/XPD-$unit$subunit"; my $xpd = Dahdi::Xpp::Xpd->new($self, $unit, $subunit, "$xbus_dir/$xpdstr");
my $xpd = Dahdi::Xpp::Xpd->new($self, $unit, $subunit, $procdir, "$xbus_dir/$xpdstr");
push(@xpds, $xpd); push(@xpds, $xpd);
} }
@{$self->{XPDS}} = sort { $a->id <=> $b->id } @xpds; @{$self->{XPDS}} = sort { $a->id <=> $b->id } @xpds;

View File

@ -52,11 +52,6 @@ Applicable only to digital (BRI/PRI) modules and always 0 for others.
Textual name: E.g. C<XPD-10>. Textual name: E.g. C<XPD-10>.
=head1 dir
The ProcFS directory with information about the XPD. e.g.
C</proc/xpp/XBUS-00/XPD-10>.
=head1 sysfs_dir =head1 sysfs_dir
The SysFS directory with information about the module. E.g. The SysFS directory with information about the module. E.g.
@ -112,65 +107,12 @@ sub xpd_attr_path($@) {
foreach my $attr (@attr) { foreach my $attr (@attr) {
my $file = sprintf "$Dahdi::Xpp::sysfs_xpds/%02d:%1d:%1d/$attr", my $file = sprintf "$Dahdi::Xpp::sysfs_xpds/%02d:%1d:%1d/$attr",
$busnum, $unitnum, $subunitnum; $busnum, $unitnum, $subunitnum;
unless(-f $file) {
my $procfile = sprintf "/proc/xpp/XBUS-%02d/XPD-%1d%1d/$attr",
$busnum, $unitnum, $subunitnum;
warn "$0: warning - OLD DRIVER: missing '$file'. Fall back to /proc\n"
unless $file_warned{$attr}++;
$file = $procfile;
}
next unless -f $file; next unless -f $file;
return $file; return $file;
} }
return undef; return undef;
} }
# Backward compat plug for old /proc interface...
sub xpd_old_gettype($) {
my $xpd = shift || die;
my $summary = "/proc/xpp/" . $xpd->fqn . "/summary";
open(F, $summary) or die "Failed to open '$summary': $!";
my $head = <F>;
close F;
chomp $head;
$head =~ s/^XPD-\d+\s+\(//;
$head =~ s/,.*//;
return $head;
}
sub xpd_old_getspan($) {
my $xpd = shift || die;
my $dahdi_registration = "/proc/xpp/" . $xpd->fqn . "/dahdi_registration";
open(F, $dahdi_registration) or die "Failed to open '$dahdi_registration': $!";
my $head = <F>;
close F;
chomp $head;
return $head;
}
sub xpd_old_getoffhook($) {
my $xpd = shift || die;
my $summary = "/proc/xpp/" . $xpd->fqn . "/summary";
my $channels;
local $/ = "\n";
open(F, "$summary") || die "Failed opening $summary: $!\n";
my $head = <F>;
chomp $head; # "XPD-00 (BRI_TE ,card present, span 3)"
my $offhook;
while(<F>) {
chomp;
if(s/^\s*offhook\s*:\s*//) {
s/\s*$//;
$offhook = $_;
$offhook || die "No channels in '$summary'";
last;
}
}
close F;
return $offhook;
}
my %attr_missing_warned; # Prevent duplicate warnings my %attr_missing_warned; # Prevent duplicate warnings
sub xpd_driver_getattr($$) { sub xpd_driver_getattr($$) {
@ -198,10 +140,6 @@ sub xpd_getattr($$) {
$attr = lc($attr); $attr = lc($attr);
my $file = $xpd->xpd_attr_path(lc($attr)); my $file = $xpd->xpd_attr_path(lc($attr));
# Handle special cases for backward compat
return xpd_old_gettype($xpd) if $attr eq 'type' and !defined $file;
return xpd_old_getspan($xpd) if $attr eq 'span' and !defined $file;
return xpd_old_getoffhook($xpd) if $attr eq 'offhook' and !defined $file;
if(!defined($file)) { if(!defined($file)) {
warn "$0: xpd_getattr($attr) -- Missing attribute.\n" if warn "$0: xpd_getattr($attr) -- Missing attribute.\n" if
$attr_missing_warned{$attr}; $attr_missing_warned{$attr};
@ -284,7 +222,6 @@ sub new($$$$$) {
my $xbus = shift || die; my $xbus = shift || die;
my $unit = shift; # May be zero my $unit = shift; # May be zero
my $subunit = shift; # May be zero my $subunit = shift; # May be zero
my $procdir = shift || die;
my $sysfsdir = shift || die; my $sysfsdir = shift || die;
my $self = { my $self = {
XBUS => $xbus, XBUS => $xbus,
@ -292,7 +229,6 @@ sub new($$$$$) {
FQN => $xbus->name . "/" . "XPD-$unit$subunit", FQN => $xbus->name . "/" . "XPD-$unit$subunit",
UNIT => $unit, UNIT => $unit,
SUBUNIT => $subunit, SUBUNIT => $subunit,
DIR => $procdir,
SYSFS_DIR => $sysfsdir, SYSFS_DIR => $sysfsdir,
}; };
bless $self, $pack; bless $self, $pack;
@ -319,7 +255,7 @@ sub new($$$$$) {
} }
} }
$self->{IS_DIGITAL} = ( $self->{IS_BRI} || $self->{IS_PRI} ); $self->{IS_DIGITAL} = ( $self->{IS_BRI} || $self->{IS_PRI} );
Dahdi::Xpp::Line->create_all($self, $procdir); Dahdi::Xpp::Line->create_all($self);
return $self; return $self;
} }

View File

@ -212,12 +212,13 @@ I<dahdi>) through the value of XPP_SYNC in /etc/dahdi/init.conf .
=over =over
=item /proc/xpp/sync =item /sys/bus/astribanks/drivers/xppdrv/sync
(Deprecated: no longer supported) xpp_sync is essentially a nicer interface to
xpp_sync is essentially a nicer interface to /proc/xpp/sync . That file C</sys/bus/astribanks/drivers/xppdrv/sync>. That file
shows the current xpp sync master (and in what format you need to write shows the current xpp sync master.
to it to set the master).
Writing to it, force XPP drivers to use a different sync master
=back =back